/* CODA CRM : barre blanche et menus texte, onglets arrondis, accueil en grille d'icones (style valide pour la box). */
:root {
  --bg: #f4f6fa; --surface: #ffffff; --surface-2: #eef2f8; --line: #dde3ec;
  --fg: #1a2333; --muted: #5d6879; --brand: #1e437d; --brand-soft: #e3ebf7; --on-brand: #ffffff;
  --ok: #1f7a4d; --ok-soft: #e1f3e9; --warn: #a15c00; --warn-soft: #fbefdc;
  --bad: #b3261e; --bad-soft: #fbe4e2; --mail: #0b6aa8; --mail-soft: #e0f0fa;
  --shadow: 0 10px 30px rgba(20, 30, 50, .18);
  --font: "Atkinson Hyperlegible", "Segoe UI", system-ui, sans-serif;
  --mono: ui-monospace, "Cascadia Mono", Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f141c; --surface: #171e29; --surface-2: #1f2835; --line: #2c3746;
    --fg: #e6ebf2; --muted: #9aa6b8; --brand: #8fb3ec; --brand-soft: #1f3253; --on-brand: #0f141c;
    --ok: #5fcf95; --ok-soft: #173326; --warn: #f0b562; --warn-soft: #3a2a12;
    --bad: #f08a82; --bad-soft: #3d1b19; --mail: #6cc0f2; --mail-soft: #12304a;
    --shadow: 0 10px 30px rgba(0, 0, 0, .5);
    color-scheme: dark;
  }
}

* { box-sizing: border-box }
html, body { margin: 0 }
body { background: var(--bg); color: var(--fg); font-family: var(--font); font-size: 15px; line-height: 1.45 }
button, input, select, textarea { font: inherit; color: inherit }
button { cursor: pointer }
a { color: var(--brand) }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, [tabindex]:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px }
.num { font-variant-numeric: tabular-nums }
.muted { color: var(--muted) }
.small { font-size: 13px }
[hidden] { display: none !important }

/* Barre */
header.bar { position: sticky; top: 0; z-index: 20; background: var(--surface); border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 18px; flex-wrap: wrap; padding: 10px 16px }
.logo { font-weight: 700; letter-spacing: .02em; color: var(--brand); font-size: 17px; white-space: nowrap; background: none; border: 0; padding: 0 }
.logo span { color: var(--fg); font-weight: 400 }
nav.menus { display: flex; gap: 2px; flex-wrap: wrap; flex: 1; min-width: 0 }
nav.menus button { background: none; border: 0; padding: 6px 10px; border-radius: 8px; color: var(--muted); position: relative }
nav.menus button:hover { background: var(--surface-2); color: var(--fg) }
nav.menus button.on { color: var(--brand); font-weight: 700 }
nav.menus .badge { position: absolute; top: 0; right: 0; min-width: 16px; height: 16px; border-radius: 8px; background: var(--mail); color: var(--on-brand); font-size: 10.5px; line-height: 16px; padding: 0 4px; font-weight: 700 }
.search-btn { display: flex; align-items: center; gap: 8px; border: 1px solid var(--line); border-radius: 8px; padding: 5px 10px; color: var(--muted); background: var(--bg); min-width: 0 }
.search-btn kbd, kbd { font-family: var(--mono); font-size: 11px; border: 1px solid var(--line); border-radius: 4px; padding: 0 4px }
.user-btn { background: none; border: 0; color: var(--muted); font-size: 13.5px }

.tabs { display: flex; gap: 6px; overflow-x: auto; padding: 10px 16px 0 }
.tab { display: flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--surface-2); border-radius: 10px 10px 0 0; padding: 5px 8px 5px 12px; white-space: nowrap; color: var(--muted); font-size: 14px; max-width: 260px }
.tab .t { overflow: hidden; text-overflow: ellipsis; background: none; border: 0; padding: 0; color: inherit; font-weight: inherit }
.tab.on { background: var(--surface); color: var(--fg); font-weight: 700 }
.tab .x { background: none; border: 0; color: var(--muted); padding: 0 4px; border-radius: 4px; line-height: 1; font-size: 16px }
.tab .x:hover { background: var(--line) }

main { padding: 20px 16px 48px; max-width: 1320px; margin: 0 auto }
h1 { font-size: 24px; margin: 0 0 4px; text-wrap: balance }
h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 0 0 10px; font-weight: 700 }
h3 { font-size: 16px; margin: 0 }
.sub { color: var(--muted); margin: 0 0 18px }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 16px; min-width: 0 }
.stack { display: grid; gap: 16px; align-content: start; min-width: 0 }
.row-between { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap }
.empty { color: var(--muted); padding: 18px 4px; text-align: center }
.loading { color: var(--muted); padding: 30px; text-align: center }

/* Accueil */
.home { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr); gap: 24px }
.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px 18px; margin-bottom: 22px }
.tile { display: flex; gap: 12px; align-items: flex-start; text-align: left; background: none; border: 0; padding: 10px; border-radius: 10px }
.tile:hover:not([disabled]) { background: var(--surface) }
.tile[disabled] { opacity: .6; cursor: default }
.ico { flex: none; width: 40px; height: 40px; border-radius: 10px; background: var(--brand-soft); color: var(--brand); display: grid; place-items: center }
.ico svg, .fi svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round }
.tile b { display: block } .tile small { color: var(--muted); font-size: 13px }
.list { list-style: none; margin: 0; padding: 0 }
.list > li { display: flex; gap: 10px; align-items: baseline; padding: 9px 0; border-top: 1px solid var(--line) }
.list > li:first-child { border-top: 0 }
.list > li .end { margin-left: auto; color: var(--muted); font-size: 13px; white-space: nowrap; text-align: right }
.list > li .grow { min-width: 0; overflow-wrap: anywhere }
.list > li.link { cursor: pointer } .list > li.link:hover .grow b { text-decoration: underline }
.notice { border-radius: 10px; padding: 10px 12px; font-size: 14px; margin-bottom: 14px }
.notice.warn { background: var(--warn-soft); color: var(--warn) }
.notice.bad { background: var(--bad-soft); color: var(--bad) }
.notice.ok { background: var(--ok-soft); color: var(--ok) }
.notice.info { background: var(--mail-soft); color: var(--mail) }

/* Etiquettes */
.chip { display: inline-block; font-size: 12px; border-radius: 999px; padding: 1px 9px; font-weight: 700; white-space: nowrap; vertical-align: 1px }
.c-brand { background: var(--brand-soft); color: var(--brand) } .c-ok { background: var(--ok-soft); color: var(--ok) }
.c-warn { background: var(--warn-soft); color: var(--warn) } .c-bad { background: var(--bad-soft); color: var(--bad) }
.c-mail { background: var(--mail-soft); color: var(--mail) } .c-grey { background: var(--surface-2); color: var(--muted) }

/* Tableaux */
.tw { overflow-x: auto }
table { width: 100%; border-collapse: collapse; font-size: 14px }
th { text-align: left; color: var(--muted); font-weight: 700; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap }
td { padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: top }
tr:last-child td { border-bottom: 0 }
tr.link { cursor: pointer } tr.link:hover td { background: var(--surface-2) }
td.r, th.r { text-align: right }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 14px }
.toolbar .spacer { flex: 1 }
.btn { border: 1px solid var(--line); background: var(--surface); border-radius: 8px; padding: 6px 12px; font-size: 14px; white-space: nowrap }
.btn:hover { border-color: var(--muted) }
.btn.pri { background: var(--brand); border-color: var(--brand); color: var(--on-brand); font-weight: 700 }
.btn.danger { color: var(--bad) }
.btn.small { padding: 3px 9px; font-size: 13px }
.btn[disabled] { opacity: .55; cursor: default }
.filter { border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 3px 11px; font-size: 13px; color: var(--muted) }
.filter.on { border-color: var(--brand); color: var(--brand); font-weight: 700 }
.input, input[type=text], input[type=email], input[type=search], input[type=number], input[type=date], input[type=time], input[type=datetime-local], input[type=password], select, textarea {
  border: 1px solid var(--line); background: var(--surface); border-radius: 8px; padding: 6px 10px; width: 100%; min-width: 0 }
textarea { resize: vertical; min-height: 70px }
.toolbar input[type=search] { width: min(320px, 100%) }

/* Fiches */
.fiche { display: grid; grid-template-columns: minmax(0, 320px) minmax(0, 1fr); gap: 20px }
.kv { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 6px 12px; font-size: 14px; margin: 0 }
.kv dt { color: var(--muted) } .kv dd { margin: 0; overflow-wrap: anywhere; white-space: pre-line }
.person { display: flex; gap: 10px; align-items: center; padding: 8px 0; border-top: 1px solid var(--line); cursor: pointer }
.person:first-of-type { border-top: 0 }
.person:hover b { text-decoration: underline }
.av { width: 34px; height: 34px; border-radius: 50%; background: var(--brand-soft); color: var(--brand); display: grid; place-items: center; font-weight: 700; font-size: 13px; flex: none }
.person small { display: block; color: var(--muted); font-size: 12.5px; overflow-wrap: anywhere }
.subtabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 14px; overflow-x: auto }
.subtabs button { background: none; border: 0; border-bottom: 2px solid transparent; padding: 8px 12px; color: var(--muted); white-space: nowrap }
.subtabs button.on { color: var(--brand); border-bottom-color: var(--brand); font-weight: 700 }
.subtabs button[disabled] { opacity: .55; cursor: default }
.compose { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; align-items: center }
.compose .spacer { flex: 1 }
.feed { list-style: none; margin: 0; padding: 0 }
.feed > li { display: grid; grid-template-columns: 34px minmax(0, 1fr); gap: 12px; padding: 12px 0; border-top: 1px solid var(--line) }
.feed > li:first-child { border-top: 0 }
.fi { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center }
.fi svg { width: 17px; height: 17px }
.meta { font-size: 13px; color: var(--muted); display: flex; gap: 8px; flex-wrap: wrap; align-items: center }
.feed p { margin: 4px 0 0; white-space: pre-line; overflow-wrap: anywhere }
.quote { margin-top: 6px; padding: 8px 12px; border-left: 3px solid var(--mail); background: var(--mail-soft); border-radius: 0 8px 8px 0; font-size: 14px; white-space: pre-line; overflow-wrap: anywhere }
.mailbody { white-space: pre-wrap; overflow-wrap: anywhere; font-size: 14px; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 12px; max-height: 60vh; overflow: auto }
.linkish { background: none; border: 0; padding: 0; color: var(--brand); text-decoration: underline; font-size: inherit }
.actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px }
.files { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px }
.file { display: inline-flex; gap: 6px; align-items: center; border: 1px solid var(--line); border-radius: 8px; padding: 2px 8px; font-size: 13px; background: var(--surface) }
.file button { background: none; border: 0; padding: 0; color: var(--muted) }

/* Pipeline */
.kanban { display: grid; grid-template-columns: repeat(6, minmax(200px, 1fr)); gap: 10px; overflow-x: auto; padding-bottom: 6px }
.col { background: var(--surface-2); border-radius: 12px; padding: 10px; min-width: 0; min-height: 120px; transition: background .12s }
.col.over { background: var(--brand-soft) }
.col > header { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 8px; gap: 6px }
.col > header b { font-size: 14px } .col > header span { color: var(--muted); font-size: 12.5px }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 10px; margin-bottom: 8px; font-size: 13.5px; cursor: grab }
.card.dragging { opacity: .5 }
.card b { display: block; font-size: 14px }
.card .row { display: flex; justify-content: space-between; color: var(--muted); margin-top: 6px; gap: 6px }
.card .late { color: var(--bad); font-weight: 700 }
.card.won { border-color: var(--ok) } .card.lost { border-color: var(--bad) }
.card select { margin-top: 6px; font-size: 12.5px; padding: 2px 6px; display: none }
@media (hover: none) { .card select { display: block } }

/* Devis */
.devis { display: grid; grid-template-columns: minmax(0, 1.55fr) minmax(0, 1fr); gap: 20px; align-items: start }
.lines td { padding: 4px 4px; vertical-align: middle }
.lines td:first-child { width: 100%; min-width: 220px }
.lines td.num { white-space: nowrap }
.lines input, .lines select, .lines textarea { padding: 4px 6px; font-size: 13.5px }
.lines .w-qty { width: 58px } .lines .w-price { width: 92px } .lines .w-pct { width: 52px } .lines .w-unit { width: 56px }
.lines tr.section input.desig { font-weight: 700 }
.lines tr.text input.desig { font-style: italic }
.lines .tools { white-space: nowrap }
.lines .tools button { background: none; border: 0; color: var(--muted); padding: 2px 4px }
.lines textarea.desc { min-height: 30px; margin-top: 3px; font-size: 12.5px }
.totals { margin-left: auto; width: min(320px, 100%); font-size: 14px }
.totals div { display: flex; justify-content: space-between; padding: 3px 0 }
.totals .ttc { border-top: 2px solid var(--fg); font-weight: 700; font-size: 16px; margin-top: 4px; padding-top: 6px }
.pdf { width: 100%; height: 78vh; border: 1px solid var(--line); border-radius: 8px; background: var(--surface) }

/* Parametres */
.settings { display: grid; grid-template-columns: minmax(0, 220px) minmax(0, 1fr); gap: 20px; align-items: start }
.side { display: grid; gap: 2px }
.side button { text-align: left; background: none; border: 0; padding: 8px 12px; border-radius: 8px; color: var(--muted) }
.side button.on { background: var(--surface); color: var(--brand); font-weight: 700 }
.opt { display: flex; gap: 10px; align-items: flex-start; padding: 9px 0; border-top: 1px solid var(--line); font-size: 14px }
.opt:first-of-type { border-top: 0 }
.opt input[type=checkbox] { margin-top: 4px }
.opt small { display: block; color: var(--muted) }
.status { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; padding: 12px; border-radius: 10px; margin-bottom: 12px; font-size: 14px }
.status.ok { background: var(--ok-soft); color: var(--ok) } .status.off { background: var(--surface-2); color: var(--muted) } .status.bad { background: var(--bad-soft); color: var(--bad) }
.code { font-family: var(--mono); font-size: 26px; letter-spacing: .12em; font-weight: 700; color: var(--brand) }
.steps { margin: 0; padding-left: 20px } .steps li { margin: 6px 0 }

/* Formulaires et dialogues */
dialog { border: 0; border-radius: 14px; padding: 0; background: var(--surface); color: var(--fg); box-shadow: var(--shadow); width: min(680px, calc(100vw - 24px)); max-height: calc(100vh - 32px) }
dialog.wide { width: min(980px, calc(100vw - 24px)) }
dialog::backdrop { background: rgba(10, 16, 28, .45) }
dialog form, dialog .dlg { display: flex; flex-direction: column; max-height: calc(100vh - 32px) }
dialog header { padding: 16px 18px 6px; display: flex; justify-content: space-between; gap: 10px; align-items: center }
dialog header h3 { font-size: 18px }
dialog .body { padding: 8px 18px 12px; overflow: auto }
dialog footer { padding: 12px 18px 16px; display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; border-top: 1px solid var(--line) }
dialog footer .spacer { flex: 1 }
.fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px 14px }
.field { display: grid; gap: 4px; min-width: 0; align-content: start }
.field.full { grid-column: 1 / -1 }
.field > span { font-size: 13px; color: var(--muted); font-weight: 700 }
.field > small { color: var(--muted); font-size: 12.5px }
.field.check { display: flex; gap: 8px; align-items: flex-start }
.field.check > span { font-weight: 400; color: var(--fg); font-size: 14px }
.form-error { color: var(--bad); font-size: 14px; margin: 0 18px }
.repeat { display: grid; gap: 6px }
.repeat .item { display: flex; gap: 6px; align-items: center }
.repeat .item > * { min-width: 0 }

/* Palette Ctrl+K */
.palette { position: fixed; inset: 0; background: rgba(10, 16, 28, .45); z-index: 50; display: flex; justify-content: center; align-items: flex-start; padding: 12vh 16px 16px }
.palette .box { background: var(--surface); border-radius: 14px; width: min(620px, 100%); box-shadow: var(--shadow); overflow: hidden }
.palette input { border: 0; border-bottom: 1px solid var(--line); border-radius: 0; padding: 14px 16px; font-size: 17px }
.palette ul { list-style: none; margin: 0; padding: 6px; max-height: 50vh; overflow: auto }
.palette li { display: flex; gap: 10px; align-items: baseline; padding: 8px 10px; border-radius: 8px; cursor: pointer }
.palette li.sel { background: var(--brand-soft) }
.palette li small { color: var(--muted); margin-left: auto; text-align: right }

/* Messages */
.toasts { position: fixed; right: 16px; bottom: 16px; z-index: 60; display: grid; gap: 8px; max-width: min(420px, calc(100vw - 32px)) }
.toast { background: var(--fg); color: var(--bg); padding: 10px 14px; border-radius: 10px; box-shadow: var(--shadow); font-size: 14px }
.toast.bad { background: var(--bad); color: #fff }

@media (max-width: 960px) {
  .home, .fiche, .devis, .settings { grid-template-columns: minmax(0, 1fr) }
  .side { display: flex; flex-wrap: wrap }
}
@media (max-width: 760px) {
  header.bar { gap: 6px 12px; padding-bottom: 4px }
  nav.menus { order: 3; flex: 1 1 100%; flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none }
  nav.menus button { white-space: nowrap }
  .search-btn { margin-left: auto }
  header.bar { position: static }
}
@media (max-width: 600px) {
  .grid, .fields { grid-template-columns: minmax(0, 1fr) }
  .search-btn span { display: none }
  main { padding-top: 14px }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important } }
