/* Dofus Crafts — sobre, sombre, froid. Un seul accent (bleu = champs modifiables et actions).
   Vert = gains · rouge = pertes et erreurs · orange = avertissements · gris foncé = secondaire. */

:root {
  color-scheme: dark;
  --bg: #0d1117;
  --panel: #141a22;
  --panel-2: #19212b;
  --line: #263140;
  --line-2: #1d2733;
  --text: #d6dde8;
  --muted: #8f9bad;
  --dim: #6a7688;
  --accent: #4f8cff;
  --accent-bg: rgba(79, 140, 255, 0.12);
  --field-bg: #0f1620;
  --field-line: #2b4166;
  --good: #3dbb85;
  --good-bg: rgba(61, 187, 133, 0.12);
  --bad: #ef6a62;
  --bad-bg: rgba(239, 106, 98, 0.12);
  --warn: #e3a23a;
  --warn-bg: rgba(227, 162, 58, 0.13);
  --grey-bg: #222c39;
  --radius: 6px;
  --gutter: 16px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  min-height: 100vh;
}
h1, h2, h3 { margin: 0 0 8px; font-weight: 600; line-height: 1.25; }
h1 { font-size: 1.45rem; }
h2 { font-size: 1.1rem; }
h3 { font-size: 0.98rem; color: var(--muted); font-weight: 600; }
p { margin: 0 0 10px; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.muted { color: var(--muted); }
.dim { color: var(--dim); }
.small { font-size: 0.85rem; }
.pad { padding: var(--gutter); }
.num, td.num, th.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.good { color: var(--good); }
.bad { color: var(--bad); }
.warn { color: var(--warn); }
[hidden] { display: none !important; }

/* ---------- Barre du haut ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 14px;
  padding: 0 var(--gutter);
  padding-top: env(safe-area-inset-top);
  background: rgba(13, 17, 23, 0.96);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(6px);
}
.brand { color: var(--text); font-weight: 700; letter-spacing: 0.01em; padding: 12px 0; white-space: nowrap; }
.brand:hover { text-decoration: none; }
#nav { display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; flex: 1; }
#nav::-webkit-scrollbar { display: none; }
#nav a {
  color: var(--muted); padding: 13px 11px; white-space: nowrap; border-bottom: 2px solid transparent; font-size: 0.93rem;
}
#nav a:hover { color: var(--text); text-decoration: none; }
#nav a.active { color: var(--text); border-bottom-color: var(--accent); }

main { max-width: 1180px; margin: 0 auto; padding: var(--gutter); outline: none; }
.page-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 8px 16px; margin-bottom: 12px; }
.page-head p { margin: 0; }

/* ---------- Cartes et grilles ---------- */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 14px; min-width: 0; }
.card > h2:first-child, .card > h3:first-child { margin-top: 0; }
.card-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.card-head h2, .card-head h3 { margin: 0; }
.grid { display: grid; gap: 14px; }
.grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid > .card { margin-bottom: 0; }
.grid:not(:last-child) { margin-bottom: 14px; }
.card h3 { margin-top: 14px; }
.row { display: flex; flex-wrap: wrap; gap: 10px; align-items: end; }
.row.center { align-items: center; }
.stack > * + * { margin-top: 10px; }
.spacer { flex: 1; }

.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; min-width: 0; }
.kpi .label { color: var(--muted); font-size: 0.82rem; margin-bottom: 4px; }
.kpi .value { font-size: 1.45rem; font-weight: 650; font-variant-numeric: tabular-nums; line-height: 1.15; overflow-wrap: anywhere; }
.kpi .sub { color: var(--dim); font-size: 0.82rem; margin-top: 3px; }
.kpi.good .value { color: var(--good); }
.kpi.bad .value { color: var(--bad); }
.kpi.warn .value { color: var(--warn); }

/* ---------- Champs : bleu = modifiable ---------- */
label { display: flex; flex-direction: column; gap: 4px; font-size: 0.85rem; color: var(--muted); min-width: 0; }
.field, select.field, textarea.field {
  background: var(--field-bg); color: var(--accent); border: 1px solid var(--field-line); border-radius: var(--radius);
  padding: 8px 10px; font: inherit; min-height: 38px; min-width: 0; width: 100%;
}
input.field[inputmode='numeric'] { text-align: right; font-variant-numeric: tabular-nums; }
.field::placeholder { color: var(--dim); }
.field:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent); }
.field.invalid { border-color: var(--bad); color: var(--bad); }
.field.invalid:focus { outline-color: var(--bad); }
.field[readonly], .field:disabled { color: var(--muted); border-color: var(--line); }
select.field { color: var(--accent); }
.field-msg { color: var(--bad); font-size: 0.8rem; min-height: 0; }
.check { flex-direction: row; align-items: center; gap: 8px; color: var(--text); font-size: 0.92rem; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); }
.w-sm { width: 110px; }
.w-md { width: 170px; }
.grow { flex: 1 1 200px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  background: var(--panel-2); color: var(--text); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 8px 13px; font: inherit; cursor: pointer; min-height: 38px; white-space: nowrap;
}
.btn:hover { background: #202a37; text-decoration: none; }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #07101f; font-weight: 600; }
.btn.primary:hover { background: #6aa0ff; }
.btn.danger { color: var(--bad); border-color: rgba(239, 106, 98, 0.45); }
.btn.danger:hover { background: var(--bad-bg); }
.btn.small { min-height: 32px; padding: 4px 10px; font-size: 0.88rem; }
.btn.ghost { background: transparent; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  background: var(--panel-2); color: var(--muted); border: 1px solid var(--line); border-radius: 999px;
  padding: 4px 11px; font: inherit; font-size: 0.88rem; cursor: pointer; min-height: 32px;
}
.chip:hover { color: var(--text); }
.chip.on { background: var(--accent-bg); border-color: var(--accent); color: var(--accent); }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.seg button { background: transparent; color: var(--muted); border: 0; padding: 7px 13px; font: inherit; cursor: pointer; min-height: 36px; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button.on { background: var(--accent-bg); color: var(--accent); }

/* ---------- Badges et messages ---------- */
.badge { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 0.78rem; background: var(--grey-bg); color: var(--muted); white-space: nowrap; }
.badge.ok { background: var(--good-bg); color: var(--good); }
.badge.orange { background: var(--warn-bg); color: var(--warn); }
.badge.red { background: var(--bad-bg); color: var(--bad); }
.badge.blue { background: var(--accent-bg); color: var(--accent); }
.msg { border-radius: var(--radius); padding: 9px 12px; margin: 0 0 10px; font-size: 0.92rem; border: 1px solid transparent; }
.msg.error { background: var(--bad-bg); color: var(--bad); border-color: rgba(239, 106, 98, 0.35); }
.msg.warn { background: var(--warn-bg); color: var(--warn); border-color: rgba(227, 162, 58, 0.35); }
.msg.good { background: var(--good-bg); color: var(--good); border-color: rgba(61, 187, 133, 0.35); }
.msg.info { background: var(--grey-bg); color: var(--muted); }
.alerts { display: grid; gap: 6px; margin-bottom: 14px; }
.alert { display: flex; gap: 10px; align-items: baseline; border-radius: var(--radius); padding: 8px 12px; font-size: 0.92rem; border-left: 3px solid; }
.alert.red { background: var(--bad-bg); border-color: var(--bad); }
.alert.orange { background: var(--warn-bg); border-color: var(--warn); }
.alert.ok { background: var(--good-bg); border-color: var(--good); }
.alert a { margin-left: auto; white-space: nowrap; }

/* ---------- Tableaux ---------- */
.table-wrap { overflow-x: auto; margin: 0 -2px; }
table { width: 100%; border-collapse: collapse; font-size: 0.93rem; }
th, td { padding: 8px 10px; text-align: left; border-bottom: 1px solid var(--line-2); vertical-align: middle; }
th { color: var(--muted); font-weight: 600; font-size: 0.82rem; white-space: nowrap; }
tbody tr:hover { background: rgba(255, 255, 255, 0.015); }
tfoot td { border-top: 1px solid var(--line); border-bottom: 0; font-weight: 600; }
th button.sort { background: none; border: 0; color: inherit; font: inherit; cursor: pointer; padding: 0; }
th button.sort:hover { color: var(--text); }
th.sorted { color: var(--accent); }
td .sub { display: block; color: var(--dim); font-size: 0.8rem; }
td.best { box-shadow: inset 0 -2px 0 var(--good); }
td .na { color: var(--dim); font-style: italic; }
.price-cell { white-space: nowrap; text-align: right; font-variant-numeric: tabular-nums; }
.price-cell .best-tag { display: inline-block; margin-left: 6px; color: var(--good); font-size: 0.72rem; }
tr.unavailable td { color: var(--dim); }
details > summary { cursor: pointer; color: var(--muted); font-size: 0.88rem; }
details[open] > summary { margin-bottom: 6px; }
details.cmp { padding: 2px 0; }
.cmp-line { font-size: 0.85rem; color: var(--muted); padding: 1px 0; }

/* ---------- Suggestions de noms ---------- */
.ac { position: relative; }
.suggest { position: absolute; z-index: 30; left: 0; right: 0; top: calc(100% + 2px); margin: 0; padding: 4px; list-style: none; background: var(--panel-2); border: 1px solid var(--field-line); border-radius: var(--radius); box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5); max-height: 280px; overflow: auto; }
.suggest li { padding: 8px 10px; border-radius: 4px; cursor: pointer; color: var(--text); }
.suggest li:hover, .suggest li.on { background: var(--accent-bg); color: var(--accent); }

/* ---------- Fenêtres, notifications, info-bulle ---------- */
dialog {
  background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 10px; padding: 0;
  width: min(760px, calc(100vw - 24px)); max-height: calc(100vh - 32px);
}
dialog::backdrop { background: rgba(3, 6, 10, 0.7); }
dialog .dlg-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; border-bottom: 1px solid var(--line); }
dialog .dlg-head h2 { margin: 0; }
dialog .dlg-body { padding: 14px 16px; overflow: auto; max-height: calc(100vh - 160px); }
dialog .dlg-foot { padding: 12px 16px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
#toasts { position: fixed; z-index: 60; bottom: calc(14px + env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%); display: grid; gap: 8px; width: min(440px, calc(100vw - 24px)); pointer-events: none; }
.toast { background: var(--panel-2); border: 1px solid var(--line); border-left: 3px solid var(--good); border-radius: var(--radius); padding: 10px 14px; box-shadow: 0 6px 24px rgba(0, 0, 0, 0.45); pointer-events: auto; }
.toast.error { border-left-color: var(--bad); }
.tooltip { position: fixed; z-index: 70; background: #0a0e14; border: 1px solid var(--line); border-radius: 5px; padding: 5px 9px; font-size: 0.82rem; pointer-events: none; max-width: 260px; white-space: pre-line; box-shadow: 0 4px 16px rgba(0, 0, 0, 0.5); }

/* ---------- Graphiques ---------- */
.chart { width: 100%; }
.chart svg { display: block; max-width: 100%; overflow: visible; }
.chart text { fill: var(--muted); font-size: 11px; font-family: inherit; }
.chart .grid-line { stroke: var(--line-2); stroke-width: 1; }
.chart .axis { stroke: var(--line); stroke-width: 1; }
.chart .bar { transition: opacity 0.12s; }
.chart .bar:hover, .chart .bar.hl { opacity: 0.8; }
.chart .pt { cursor: default; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 0.82rem; color: var(--muted); margin-top: 6px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 5px; vertical-align: -1px; }
.stackbar { display: flex; height: 22px; border-radius: 4px; overflow: hidden; background: var(--grey-bg); }
.stackbar span { display: block; height: 100%; }

/* ---------- Connexion ---------- */
.login-body { display: grid; place-items: center; padding: var(--gutter); }
.login-card { width: min(380px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 22px; }
.login-card form { display: grid; gap: 12px; margin-top: 12px; }

/* ---------- Téléphone ---------- */
@media (max-width: 900px) {
  .grid.cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid.cols-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 720px) {
  :root { --gutter: 12px; }
  .grid.cols-2, .grid.cols-3 { grid-template-columns: minmax(0, 1fr); }
  .kpi .value { font-size: 1.2rem; }
  h1 { font-size: 1.25rem; }
  .brand { display: none; }
  .w-sm, .w-md { width: 100%; }
  .row > .field, .row > label { flex: 1 1 140px; }

  /* tableaux en cartes */
  table.rtable, table.rtable tbody, table.rtable tr, table.rtable td { display: block; width: 100%; }
  table.rtable thead { display: none; }
  table.rtable tr { border: 1px solid var(--line-2); border-radius: var(--radius); padding: 6px 10px; margin-bottom: 10px; background: var(--panel); }
  table.rtable td { border: 0; padding: 4px 0; display: flex; justify-content: space-between; gap: 12px; text-align: right; align-items: baseline; }
  table.rtable td::before { content: attr(data-label); color: var(--muted); font-size: 0.82rem; text-align: left; flex: 0 0 auto; }
  table.rtable td.title { font-weight: 600; justify-content: flex-start; text-align: left; font-size: 1rem; }
  table.rtable td.title::before { display: none; }
  table.rtable td .pc { text-align: right; }
  table.rtable td.actions { justify-content: flex-start; flex-wrap: wrap; gap: 6px; }
  table.rtable td.actions::before { display: none; }
  table.rtable td.nolabel::before { display: none; }
  table.rtable tfoot tr { background: transparent; border-style: dashed; }
  .table-wrap { margin: 0; }
}
