@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;450;500;600;700&display=swap');

:root {
  --bg: #f7f7f8;
  --surface: #ffffff;
  --border: #e5e5e7;
  --border-hover: #d4d4d8;
  --text: #18181b;
  --text-2: #52525b;
  --text-3: #8b8b94;
  --accent: #18181b;
  --ok-bg: #f0f6f1; --ok-fg: #2c6b42;
  --warn-bg: #fdf6ec; --warn-fg: #8a5a12;
  --r: 10px;
  --shadow: 0 1px 2px rgba(16,17,20,.05);
  --sidebar: 236px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px; line-height: 1.5; -webkit-font-smoothing: antialiased;
  font-feature-settings: "cv05" 1;
}
a { color: inherit; text-decoration: none; }
h1 { font-size: 21px; font-weight: 600; margin: 0; letter-spacing: -0.02em; }
h2 { font-size: 15px; font-weight: 600; margin: 0; letter-spacing: -0.01em; }
.sub { color: var(--text-2); font-size: 13px; }
.dim { color: var(--text-3); }
.num { font-variant-numeric: tabular-nums; }

/* ------------------------------ shell ------------------------------ */

.app { display: flex; min-height: 100vh; }

.side {
  width: var(--sidebar); flex: none; background: var(--surface);
  border-right: 1px solid var(--border); display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
}
.brand {
  padding: 20px 20px 16px; font-weight: 600; font-size: 15px; letter-spacing: -0.01em;
  display: flex; align-items: center; gap: 9px;
}
.brand small { font-weight: 400; color: var(--text-3); font-size: 12px; }
.side nav { padding: 4px 12px; display: flex; flex-direction: column; gap: 1px; }
.side nav a {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px;
  border-radius: 7px; color: var(--text-2); font-size: 13.5px; font-weight: 450;
}
.side nav a:hover { background: var(--bg); color: var(--text); }
.side nav a[aria-current] { background: var(--bg); color: var(--text); font-weight: 550; }
.side nav .badge {
  margin-left: auto; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 20px;
  background: var(--accent); color: #fff; font-size: 11px; font-weight: 600;
  display: inline-flex; align-items: center; justify-content: center;
}
.side-foot {
  margin-top: auto; padding: 16px 20px; border-top: 1px solid var(--border);
  font-size: 12px; color: var(--text-3); display: flex; flex-direction: column; gap: 5px;
}
.side-foot b { font-weight: 500; color: var(--text-2); display: block; }

.main { flex: 1; min-width: 0; }
.topbar {
  height: 60px; background: var(--surface); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 16px; padding: 0 28px; position: sticky; top: 0; z-index: 10;
}
.topbar .back { color: var(--text-3); font-size: 13px; }
.topbar .back:hover { color: var(--text); }
.topbar .right { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.content { padding: 26px 28px 80px; max-width: 1060px; }
.content.wide { max-width: 1280px; }

/* ------------------------------ cards ------------------------------ */

.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r); box-shadow: var(--shadow);
}
.card + .card { margin-top: 16px; }
.card-h {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 18px; border-bottom: 1px solid var(--border);
}
.card-h h2 { margin-right: auto; }
.card-b { padding: 18px; }
.card-b.tight { padding: 0; }

.grid2 { display: grid; grid-template-columns: 1fr 300px; gap: 16px; align-items: start; }

/* ------------------------------ queue ------------------------------ */

.item { display: block; padding: 16px 18px; border-bottom: 1px solid var(--border); }
.item:last-child { border-bottom: 0; }
.item:hover { background: #fafafa; }
.item-top { display: flex; align-items: baseline; gap: 10px; margin-bottom: 3px; }
.item-top .who { font-weight: 550; }
.item-top .when { margin-left: auto; color: var(--text-3); font-size: 12px; flex: none; }
.item-sub { color: var(--text-2); font-size: 13px; margin-bottom: 10px; }
.item-foot { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.item-amount { font-weight: 600; font-variant-numeric: tabular-nums; }

.new-dot {
  width: 7px; height: 7px; border-radius: 50%; background: var(--accent);
  display: inline-block; flex: none;
}

/* ------------------------------ bits ------------------------------ */

.pill {
  display: inline-flex; align-items: center; padding: 2px 8px; border-radius: 6px;
  font-size: 11.5px; font-weight: 550; background: var(--bg); color: var(--text-2);
  border: 1px solid var(--border); white-space: nowrap;
}
.pill.ok { background: var(--ok-bg); color: var(--ok-fg); border-color: #d3e6da; }
.pill.warn { background: var(--warn-bg); color: var(--warn-fg); border-color: #efdfc4; }
.pill.solid { background: var(--accent); color: #fff; border-color: var(--accent); }

button, .btn {
  font: inherit; font-size: 13px; font-weight: 500; padding: 7px 13px; border-radius: 7px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  cursor: pointer; display: inline-flex; align-items: center; gap: 7px; line-height: 1.4;
  transition: background .12s, border-color .12s;
}
button:hover, .btn:hover { border-color: var(--border-hover); background: #fbfbfc; }
.btn.primary, button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover, button.primary:hover { background: #2b2b31; border-color: #2b2b31; }
.btn.sm, button.sm { padding: 4px 9px; font-size: 12px; }
button:disabled { opacity: .45; cursor: default; }
button.link { border: 0; background: none; padding: 0; color: var(--text-3); font-size: 13px; }
button.link:hover { color: var(--text); background: none; }
:where(a,button,input,select,textarea):focus-visible { outline: 2px solid #18181b; outline-offset: 2px; }

/* ------------------------------ table ------------------------------ */

.tw { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
thead th {
  text-align: left; font-weight: 500; font-size: 12px; color: var(--text-3);
  padding: 10px 14px; border-bottom: 1px solid var(--border); white-space: nowrap;
}
th.r, td.r { text-align: right; font-variant-numeric: tabular-nums; }
td.r.dim { white-space: nowrap; }
tbody td { padding: 11px 14px; border-bottom: 1px solid var(--border); }
tbody tr:last-child td { border-bottom: 0; }
tbody tr.click:hover { background: #fafafa; cursor: pointer; }
td .t { font-weight: 500; }
td .d { color: var(--text-3); font-size: 12.5px; margin-top: 1px; }
code, .code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; color: var(--text-2); }

/* ------------------------------ forms ------------------------------ */

label.f { display: block; margin-bottom: 14px; }
label.f > span { display: block; margin-bottom: 5px; font-size: 12.5px; color: var(--text-2); font-weight: 500; }
input[type=text], input[type=password], input[type=number], select, textarea {
  width: 100%; font: inherit; font-size: 13.5px; color: var(--text); background: var(--surface);
  padding: 8px 11px; border: 1px solid var(--border); border-radius: 7px;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: #a1a1aa; }
textarea { resize: vertical; min-height: 128px; line-height: 1.6; }
input[type=number] { text-align: right; font-variant-numeric: tabular-nums; }

/* ------------------------------ misc ------------------------------ */

.banner { padding: 11px 15px; border-radius: 8px; font-size: 13px; margin-bottom: 16px; border: 1px solid; }
.banner.ok { background: var(--ok-bg); color: var(--ok-fg); border-color: #d3e6da; }
.banner.warn { background: var(--warn-bg); color: var(--warn-fg); border-color: #efdfc4; }

.empty { padding: 64px 24px; text-align: center; color: var(--text-3); }
.empty strong { display: block; color: var(--text); font-weight: 550; font-size: 15px; margin-bottom: 4px; }

.mail { font-size: 13.5px; line-height: 1.7; white-space: pre-wrap; color: var(--text-2); }

.kv { display: flex; justify-content: space-between; gap: 14px; padding: 7px 0; font-size: 13px; }
.kv + .kv { border-top: 1px solid var(--border); }
.kv dt { color: var(--text-2); }
.kv dd { margin: 0; font-variant-numeric: tabular-nums; text-align: right; font-weight: 450; }

.totals { margin: 14px 18px 2px auto; width: 280px; }
.totals .kv:last-child { border-top: 1px solid var(--text); padding-top: 10px; margin-top: 4px; }
.totals .kv:last-child dt { color: var(--text); font-weight: 550; }
.totals .kv:last-child dd { font-size: 17px; font-weight: 600; }

.miss { margin: 0; padding-left: 17px; font-size: 13px; color: var(--text-2); }
.miss li + li { margin-top: 3px; }

.gauge { height: 4px; border-radius: 4px; background: var(--bg); overflow: hidden; margin-top: 6px; }
.gauge i { display: block; height: 100%; background: var(--accent); }

.toast {
  position: fixed; right: 20px; bottom: 20px; z-index: 50;
  background: var(--accent); color: #fff; padding: 11px 16px; border-radius: 9px;
  font-size: 13px; box-shadow: 0 8px 24px rgba(0,0,0,.16); display: flex; gap: 14px; align-items: center;
}
.toast a { text-decoration: underline; font-weight: 500; }

/* ------------------------------ login ------------------------------ */

.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: var(--bg); }
.login { width: 100%; max-width: 340px; }
.login .brand { padding: 0 0 18px; }

/* ------------------------------ responsive ------------------------------ */

@media (max-width: 860px) {
  .app { flex-direction: column; }
  .side {
    width: 100%; height: auto; position: static; flex-direction: row; align-items: center;
    border-right: 0; border-bottom: 1px solid var(--border); overflow-x: auto; gap: 4px;
  }
  .brand { padding: 14px 16px; white-space: nowrap; }
  .brand small { display: none; }
  .side nav { flex-direction: row; padding: 0 8px 0 0; }
  .side nav a { white-space: nowrap; }
  .side-foot { display: none; }
  .topbar { padding: 0 16px; height: 54px; }
  .content { padding: 18px 16px 60px; }
  .grid2 { grid-template-columns: 1fr; }
  .totals { width: 100%; margin-left: 0; padding: 0 18px; }
  .toast { left: 16px; right: 16px; bottom: 16px; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* ------------------------- traitement en cours ------------------------- */

.pill.busy { background: #f3f4f6; color: var(--text-2); border-color: var(--border); gap: 6px; }
.spin {
  width: 9px; height: 9px; border-radius: 50%;
  border: 1.5px solid var(--text-3); border-top-color: transparent;
  display: inline-block; animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spin { animation: none; border-top-color: var(--text-3); opacity: .5; } }

/* ------------------------------- modale ------------------------------- */

dialog {
  border: 1px solid var(--border); border-radius: 12px; padding: 22px;
  width: min(460px, calc(100vw - 32px)); box-shadow: 0 16px 48px rgba(16,17,20,.18);
  color: var(--text);
}
dialog::backdrop { background: rgba(16,17,20,.32); }
dialog h2 { margin-bottom: 3px; }
dialog .sub { margin: 0 0 16px; }
.modal-x { position: absolute; top: 14px; right: 14px; }
.modal-x button { padding: 4px 9px; font-size: 12px; }
.modal-list { display: flex; flex-direction: column; gap: 6px; }
.modal-list form { display: block; }
.modal-item {
  width: 100%; text-align: left; padding: 11px 13px; border-radius: 8px;
  display: block; border: 1px solid var(--border); background: var(--surface);
}
.modal-item:hover { background: var(--bg); border-color: var(--border-hover); }
.modal-item b { display: block; font-weight: 550; font-size: 13.5px; }
.modal-item em { display: block; font-style: normal; color: var(--text-3); font-size: 12.5px; margin-top: 1px; }
