/* SMR Gestion Atelier — charte : marine #0F1F3D, or #E8A020, vert #27AE60, rouge #E24B4A */
:root {
  --navy: #0F1F3D; --navy-2: #1d3361; --gold: #E8A020; --gold-d: #c98612;
  --green: #27AE60; --red: #E24B4A; --orange-bg: #FFF3E0; --orange: #B45F06;
  --gray: #969696; --line: #e3e6ec; --bg: #f4f6f9; --text: #1f2937; --radius: 10px;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif; background: var(--bg); color: var(--text); font-size: 15px; line-height: 1.45; }
a { color: var(--navy-2); }
h1 { font-size: 1.45rem; margin: .2rem 0 1rem; color: var(--navy); }
h2 { font-size: 1.1rem; margin: 1.2rem 0 .6rem; color: var(--navy); }
code { background: #eef1f6; padding: 1px 5px; border-radius: 4px; }
.muted { color: #6b7280; font-size: .9em; }
.inline { display: inline; }
.hidden { display: none !important; }

/* ---- Barre du haut ---- */
.topbar { background: var(--navy); color: #fff; display: flex; align-items: center; gap: 1rem; padding: .5rem 1rem; position: sticky; top: 0; z-index: 50; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: .6rem; color: #fff; text-decoration: none; font-weight: 600; }
.logo-img { height: 36px; display: block; }
.logo-txt { font-weight: 900; letter-spacing: 1px; font-size: 1.3rem; color: #fff; border-bottom: 3px solid var(--red); line-height: 1.1; }
.brand-name { opacity: .85; font-weight: 500; }
.mainnav { display: flex; gap: .25rem; flex: 1; overflow-x: auto; scrollbar-width: none; }
.mainnav a { color: #dfe6f3; text-decoration: none; padding: .45rem .75rem; border-radius: 8px; white-space: nowrap; }
.mainnav a:hover { background: var(--navy-2); }
.mainnav a.on { background: var(--gold); color: var(--navy); font-weight: 600; }
.userbox { display: flex; align-items: center; gap: .6rem; font-size: .9rem; }
.userbox a { color: #fff; }
.link-btn { background: none; border: 0; color: #c9d3e6; cursor: pointer; font: inherit; text-decoration: underline; padding: 0; }
@media (max-width: 760px) {
  .topbar { gap: .4rem; padding: .5rem .6rem; }
  .brand-name { display: none; }
  .mainnav { order: 3; flex-basis: 100%; }
  .userbox { margin-left: auto; }
}

.container { max-width: 1280px; margin: 0 auto; padding: 1rem; }
@media (max-width: 760px) { .container { padding: .7rem; } }

/* ---- Messages ---- */
.flash { padding: .7rem 1rem; border-radius: 8px; margin-bottom: .8rem; }
.flash-ok { background: #e7f6ee; color: #17663c; border: 1px solid #bfe6cf; }
.flash-err { background: #fdecec; color: #9b2120; border: 1px solid #f5c2c1; }
.flash-info { background: #eef3fb; color: var(--navy); border: 1px solid #cdd9ee; }

/* ---- Cartes & formulaires ---- */
.card { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.1rem; margin-bottom: 1rem; }
.card.narrow { max-width: 480px; margin: 0 auto 1rem; }
.center-page { display: flex; align-items: flex-start; justify-content: center; padding: 6vh 1rem; min-height: 100vh; }
.center-page .card { width: 100%; }
.login-brand { background: var(--navy); color: #fff; border-radius: 8px; padding: 1rem; display: flex; align-items: center; gap: .8rem; margin-bottom: 1rem; font-weight: 600; }

label { display: block; font-size: .82rem; color: #555; font-weight: 600; margin-bottom: .7rem; }
input[type=text], input[type=password], input[type=date], input[type=number], input[type=email], input[type=search], input:not([type]), select, textarea {
  display: block; width: 100%; margin-top: .25rem; padding: .55rem .65rem; border: 1px solid #cfd5df; border-radius: 8px; font: inherit; font-size: .95rem; font-weight: 400; color: var(--text); background: #fff;
}
textarea { min-height: 90px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--gold); outline-offset: 0; border-color: var(--gold); }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 0 1rem; }
.grid .span-all { grid-column: 1 / -1; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: .35rem; padding: .55rem 1rem; border-radius: 8px; border: 1px solid transparent; font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; line-height: 1.2; white-space: nowrap; }
.btn-gold { background: var(--gold); color: var(--navy); }
.btn-gold:hover { background: var(--gold-d); }
.btn-navy { background: var(--navy); color: #fff; }
.btn-navy:hover { background: var(--navy-2); }
.btn-ghost { background: #fff; color: var(--navy); border-color: #cfd5df; }
.btn-ghost:hover { border-color: var(--navy); }
.btn-red { background: var(--red); color: #fff; }
.btn-green { background: var(--green); color: #fff; }
.btn-sm { padding: .3rem .6rem; font-size: .85rem; }
.btn-block { width: 100%; }
.btn[disabled] { opacity: .45; cursor: not-allowed; }
.icon-btn { background: none; border: 0; cursor: pointer; font-size: 1.05rem; padding: .2rem .35rem; border-radius: 6px; }
.icon-btn:hover { background: #eef1f6; }
.actions { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }

/* ---- Tableau de bord ---- */
.toolbar { display: flex; gap: .6rem; flex-wrap: wrap; align-items: center; margin-bottom: 1rem; }
.toolbar form.search { flex: 1; min-width: 220px; display: flex; gap: .4rem; }
.toolbar form.search input { margin: 0; }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: .7rem; margin-bottom: 1rem; }
.tile { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: .8rem .9rem; text-decoration: none; color: var(--navy); display: block; border-top: 4px solid var(--navy); transition: transform .08s; }
.tile:hover { transform: translateY(-1px); box-shadow: 0 2px 8px rgba(15,31,61,.08); }
.tile .n { font-size: 1.8rem; font-weight: 800; line-height: 1.1; }
.tile .l { font-size: .85rem; color: #4b5563; }
.tile.on { background: var(--navy); color: #fff; }
.tile.on .l { color: #dfe6f3; }
.tile.t-gold { border-top-color: var(--gold); }
.tile.t-green { border-top-color: var(--green); }
.tile.t-red { border-top-color: var(--red); }
.tile.t-orange { border-top-color: var(--orange); }

/* ---- Tableaux / listes ---- */
.table-wrap { overflow-x: auto; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); }
table.list { width: 100%; border-collapse: collapse; }
table.list th, table.list td { padding: .55rem .7rem; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
table.list th { background: #f8f9fb; font-size: .8rem; color: #4b5563; text-transform: uppercase; letter-spacing: .02em; white-space: nowrap; }
table.list th a { color: inherit; text-decoration: none; }
table.list tr:last-child td { border-bottom: 0; }
table.list tbody tr.clickable { cursor: pointer; }
table.list tbody tr.clickable:hover { background: #fbf6ec; }
table.list td.num { font-weight: 700; white-space: nowrap; }
table.list input, table.list select { margin: 0; }
.empty { padding: 1.5rem; text-align: center; color: #6b7280; }

/* Cartes d'affaires sur mobile */
@media (max-width: 760px) {
  table.responsive thead { display: none; }
  table.responsive, table.responsive tbody, table.responsive tr, table.responsive td { display: block; width: 100%; }
  table.responsive tr { border-bottom: 1px solid var(--line); padding: .5rem .7rem; }
  table.responsive td { border: 0; padding: .1rem 0; }
  table.responsive td[data-l]::before { content: attr(data-l) " : "; color: var(--gray); font-size: .8rem; }
}

/* ---- Badges ---- */
.badge { display: inline-block; padding: .18rem .55rem; border-radius: 999px; font-size: .78rem; font-weight: 600; white-space: nowrap; }
.st-navy { background: #e6ebf5; color: var(--navy); }
.st-gold { background: #fbefd8; color: #8a5a00; }
.st-ok { background: #e3f5ea; color: #1b7a43; }
.st-red { background: #fde6e6; color: #a8211f; }
.st-orange { background: var(--orange-bg); color: var(--orange); }
.b-orange { background: var(--orange-bg); color: var(--orange); }
.b-green { background: #e3f5ea; color: #1b7a43; }
.b-gray { background: #eef0f3; color: #4b5563; }
.devis-ok { color: var(--green); font-weight: 600; font-size: .85rem; }
.devis-ko { color: var(--orange); font-weight: 600; font-size: .85rem; }

/* ---- Fiche affaire ---- */
.fiche-head { display: flex; gap: 1rem; align-items: center; flex-wrap: wrap; background: var(--navy); color: #fff; padding: .9rem 1.1rem; border-radius: var(--radius); margin-bottom: 1rem; }
.fiche-head h1 { color: #fff; margin: 0; font-size: 1.5rem; }
.fiche-head .client { color: #dfe6f3; }
.fiche-head .spacer { flex: 1; }
.statut-box { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.statut-box select { width: auto; margin: 0; background: #fff; border: 2px solid var(--gold); font-weight: 700; padding: .4rem .5rem; }
.statut-box select.st-ok { color: var(--green); }
.statut-box select.st-gold { color: #b07700; }
.statut-box select.st-red { color: var(--red); }

.tabs { display: flex; gap: .3rem; border-bottom: 2px solid var(--line); margin-bottom: 1rem; overflow-x: auto; }
.tabs button { background: none; border: 0; padding: .65rem 1rem; font: inherit; font-weight: 600; color: #6b7280; cursor: pointer; border-bottom: 3px solid transparent; margin-bottom: -2px; white-space: nowrap; }
.tabs button.on { color: var(--navy); border-bottom-color: var(--gold); }
.tab-panel { display: none; }
.tab-panel.on { display: block; }

.photos { display: grid; grid-template-columns: repeat(3, 1fr); gap: .8rem; }
@media (max-width: 600px) { .photos { grid-template-columns: 1fr 1fr; } }
.photo-slot { border: 1px dashed #c8ced8; border-radius: 8px; padding: .5rem; text-align: center; background: #fafbfc; }
.photo-slot .ph { aspect-ratio: 4/3; background: #eef1f6; border-radius: 6px; display: flex; align-items: center; justify-content: center; overflow: hidden; color: var(--gray); font-size: .85rem; }
.photo-slot img { width: 100%; height: 100%; object-fit: cover; }
.photo-slot .t { font-weight: 600; font-size: .85rem; margin: .35rem 0; color: var(--navy); }
.photo-slot .actions { justify-content: center; }
.file-label { position: relative; overflow: hidden; margin: 0 !important; }
.file-label input[type=file] { position: absolute; inset: 0; opacity: 0; cursor: pointer; }

.lines-table td { padding: .35rem .4rem; }
.lines-table input, .lines-table select { padding: .4rem .5rem; }
.qte { width: 90px; }
.sticky-actions { position: sticky; bottom: 0; background: rgba(244,246,249,.95); padding: .7rem 0; display: flex; gap: .5rem; flex-wrap: wrap; z-index: 5; }

.hist { list-style: none; margin: 0; padding: 0; }
.hist li { padding: .5rem 0; border-bottom: 1px solid var(--line); font-size: .9rem; }
.hist .when { color: var(--gray); font-size: .8rem; }

/* ---- Modale ---- */
.modal { position: fixed; inset: 0; background: rgba(15,31,61,.45); display: flex; align-items: center; justify-content: center; z-index: 100; padding: 1rem; }
.modal .card { max-width: 440px; width: 100%; margin: 0; }

.filters { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 0 .8rem; align-items: end; }
.paliers { display: flex; gap: .4rem; flex-wrap: wrap; margin-bottom: .8rem; }
.paliers .btn.on { background: var(--navy); color: #fff; }
.save-state { font-size: .8rem; margin-left: .3rem; }
.save-state.ok { color: var(--green); }
.save-state.err { color: var(--red); }

/* ---- Ajustements téléphone ---- */
@media (max-width: 760px) {
  .tiles { grid-template-columns: repeat(3, 1fr); gap: .45rem; }
  .tile { padding: .5rem .55rem; border-top-width: 3px; }
  .tile .n { font-size: 1.3rem; }
  .tile .l { font-size: .72rem; line-height: 1.25; }
  .toolbar form.search { min-width: 100%; }
  .lines-table thead { display: none; }
  .lines-table, .lines-table tbody, .lines-table tr, .lines-table td { display: block; width: 100%; }
  .lines-table tr { position: relative; padding: .5rem 2.2rem .5rem .5rem; border-bottom: 1px solid var(--line); }
  .lines-table td { border: 0; padding: .15rem 0; }
  .lines-table td:last-child { position: absolute; top: .4rem; right: .2rem; width: auto; }
  .lines-table .qte { width: 100%; }
  .fiche-head h1 { font-size: 1.25rem; }
}
