/* ==========================================================
   Diffusion — bureaux de change
   Encre bleu-nuit + bleu Majorelle ; l'ambre est réservé aux taux.
   ========================================================== */
:root {
  --ink: #171A3D;
  --ink-2: #23275A;
  --majorelle: #3D3FC4;
  --majorelle-d: #2F31A3;
  --majorelle-soft: #ECECFB;
  --amber: #F2A516;
  --amber-soft: #FFF4DC;
  --paper: #F3F4F8;
  --surface: #FFFFFF;
  --line: #E1E3EC;
  --line-2: #CDD0DD;
  --text: #1E2138;
  --muted: #696D86;
  --ok: #17885A;
  --ok-soft: #E3F4EC;
  --danger: #C93B3B;
  --danger-soft: #FBE9E9;

  --f-display: "Bahnschrift", "DIN Alternate", "Roboto Condensed", "Arial Narrow", sans-serif;
  --f-text: "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", sans-serif;

  --r-sm: 6px;
  --r-md: 10px;
  --r-lg: 16px;
  --side-w: 248px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--text);
  font: 15px/1.5 var(--f-text);
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { font-family: var(--f-display); font-weight: 600; margin: 0; letter-spacing: -0.01em; }
button, input, select, textarea { font: inherit; color: inherit; }
svg { width: 20px; height: 20px; flex: none; }
:focus-visible { outline: 2px solid var(--majorelle); outline-offset: 2px; }

/* ---------- Champs ---------- */
.field { display: grid; gap: 6px; font-size: 13px; font-weight: 600; color: var(--muted); }
.field > span { font-weight: 600; }
input:not([type="checkbox"]):not([type="radio"]), textarea, select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line-2);
  border-radius: var(--r-sm);
  background: var(--surface);
  font-size: 15px;
  font-weight: 400;
  color: var(--text);
  transition: border-color .15s, box-shadow .15s;
}
textarea { resize: vertical; min-height: 120px; line-height: 1.5; }
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--majorelle); box-shadow: 0 0 0 3px var(--majorelle-soft); }
input::placeholder, textarea::placeholder { color: #A2A5B8; }

.check { display: flex; align-items: center; gap: 10px; font-size: 14px; cursor: pointer; }
.check input, .toggle input { accent-color: var(--majorelle); width: 18px; height: 18px; margin: 0; }

.form-error { color: var(--danger); font-size: 14px; margin: 0; min-height: 0; }
.form-error:empty { display: none; }

/* ---------- Boutons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 18px;
  border: 1px solid var(--line-2);
  border-radius: var(--r-sm);
  background: var(--surface);
  font-weight: 600; font-size: 14px;
  cursor: pointer;
  transition: background .15s, border-color .15s, transform .05s;
  white-space: nowrap;
}
.btn:hover { background: var(--paper); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; transform: none; }
.btn-primary { background: var(--majorelle); border-color: var(--majorelle); color: #fff; }
.btn-primary:hover { background: var(--majorelle-d); }
.btn-amber { background: var(--amber); border-color: var(--amber); color: var(--ink); }
.btn-amber:hover { background: #DD9408; }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { background: #AF2F2F; }
.btn-quiet { background: transparent; border-color: transparent; color: var(--muted); }
.btn-quiet:hover { background: var(--line); color: var(--text); }
.btn-small { padding: 6px 12px; font-size: 13px; }
.btn-block { width: 100%; padding: 12px; font-size: 15px; }
.icon-btn {
  display: grid; place-items: center; width: 34px; height: 34px;
  border: none; border-radius: var(--r-sm); background: transparent; color: inherit; cursor: pointer; opacity: .7;
}
.icon-btn:hover { opacity: 1; background: rgba(255,255,255,.1); }

/* ---------- Marque ---------- */
.brand { display: flex; align-items: center; gap: 10px; font-family: var(--f-display); font-size: 20px; font-weight: 600; }
.mark {
  width: 30px; height: 30px; border-radius: 8px; background: var(--majorelle) url("/icon.svg") center/cover;
}
.brand-lg { font-size: 28px; }
.brand-lg .mark { width: 40px; height: 40px; border-radius: 10px; }

/* ---------- Connexion ---------- */
.login {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 1.1fr 1fr;
  background: var(--surface);
}
.login-board {
  background: var(--ink);
  display: flex; flex-direction: column; justify-content: center; gap: 4px;
  padding: 48px clamp(32px, 6vw, 96px);
}
.board-row {
  display: grid; grid-template-columns: 1fr auto auto; gap: clamp(12px, 4vw, 56px); align-items: baseline;
  padding: 18px 0; border-bottom: 1px solid rgba(255,255,255,.08);
  font-family: var(--f-display);
}
.board-row span { color: rgba(255,255,255,.55); font-size: clamp(16px, 2.6vw, 34px); letter-spacing: .04em; }
.board-row b { color: var(--amber); font-size: clamp(24px, 5vw, 72px); font-weight: 600; font-variant-numeric: tabular-nums; text-shadow: 0 0 24px rgba(242,165,22,.35); }
.login-form { align-self: center; justify-self: center; width: min(380px, 100% - 48px); display: grid; gap: 16px; padding: 48px 0; }
.login-lead { margin: -6px 0 12px; color: var(--muted); }

/* ---------- Coquille ---------- */
.shell { display: grid; grid-template-columns: var(--side-w) 1fr; min-height: 100vh; }
.side {
  position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column; gap: 28px;
  padding: 22px 16px;
  background: var(--ink); color: #fff;
}
.side .brand { padding: 0 8px; }
.nav { display: grid; gap: 2px; }
.nav button {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px; border: none; border-radius: var(--r-sm);
  background: transparent; color: rgba(255,255,255,.7);
  font-size: 15px; font-weight: 500; text-align: left; cursor: pointer;
  transition: background .15s, color .15s;
}
.nav button:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav button.on { background: var(--majorelle); color: #fff; }

.side-offices h2 { font-family: var(--f-text); font-size: 12px; font-weight: 600; color: rgba(255,255,255,.45); padding: 0 12px 8px; letter-spacing: .02em; }
.presence { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.presence li { display: flex; align-items: center; gap: 10px; padding: 7px 12px; font-size: 14px; border-radius: var(--r-sm); }
.presence li small { margin-left: auto; font-size: 12px; opacity: .55; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: #7B7F99; flex: none; }
.dot.on { background: #3DDC97; box-shadow: 0 0 0 3px rgba(61,220,151,.18); }

.side-user {
  margin-top: auto;
  display: flex; align-items: center; gap: 8px;
  padding: 12px 8px 0; border-top: 1px solid rgba(255,255,255,.08);
}
.avatar {
  width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; flex: none;
  background: var(--ink-2); color: var(--amber); font-family: var(--f-display); font-weight: 600; font-size: 14px;
}
.who { display: grid; min-width: 0; flex: 1; line-height: 1.25; }
.who strong { font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.who span { font-size: 12px; opacity: .55; }

.main { padding: 40px clamp(20px, 4vw, 56px) 64px; min-width: 0; }
.presence-strip { display: none; }

.view { display: none; max-width: 1040px; }
.view.on { display: block; animation: enter .25s ease-out; }
@keyframes enter { from { opacity: 0; transform: translateY(6px); } }
.view-head { margin-bottom: 28px; max-width: 62ch; }
.view-head h1 { font-size: 34px; line-height: 1.1; }
.view-head p { margin: 8px 0 0; color: var(--muted); }
.stack { display: grid; gap: 20px; }
.actions { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.hint { color: var(--muted); font-size: 13px; }

/* ---------- Destinataires ---------- */
.targets { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.targets-label { font-size: 13px; font-weight: 600; color: var(--muted); width: 100%; margin-bottom: 2px; }
.chip-toggle { position: relative; cursor: pointer; }
.chip-toggle input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.chip-toggle span {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 8px 14px; border-radius: 999px;
  border: 1px solid var(--line-2); background: var(--surface);
  font-size: 14px; font-weight: 500; transition: all .15s; user-select: none;
}
.chip-toggle:hover span { border-color: var(--majorelle); }
.chip-toggle input:checked + span { background: var(--majorelle-soft); border-color: var(--majorelle); color: var(--majorelle-d); font-weight: 600; }
.chip-toggle input:focus-visible + span { outline: 2px solid var(--majorelle); outline-offset: 2px; }
.chip-toggle.all input:checked + span { background: var(--majorelle); color: #fff; }
.chip-toggle .dot { background: #B4B7C9; }
.chip-toggle .dot.on { background: var(--ok); box-shadow: none; }
.chip-toggle.all input:checked + span .dot { display: none; }

/* ---------- Segmented ---------- */
.segmented { display: inline-flex; padding: 3px; background: var(--line); border-radius: var(--r-sm); gap: 2px; width: max-content; }
.segmented label { position: relative; cursor: pointer; }
.segmented input { position: absolute; opacity: 0; }
.segmented span, .segmented button {
  display: block; padding: 7px 16px; border-radius: 4px; border: none; background: transparent;
  font-size: 14px; font-weight: 500; color: var(--muted); cursor: pointer;
}
.segmented input:checked + span, .segmented button.on { background: var(--surface); color: var(--text); font-weight: 600; box-shadow: 0 1px 2px rgba(23,26,61,.12); }
.segmented input[value="urgent"]:checked + span { background: var(--danger); color: #fff; }
.segmented input:focus-visible + span { outline: 2px solid var(--majorelle); }

/* ---------- Composer + aperçu ---------- */
.compose { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 40px; align-items: start; }
.preview { position: sticky; top: 32px; }
.preview-cap { font-size: 13px; color: var(--muted); margin: 0 0 10px; }
.alert-card { background: var(--surface); border-radius: var(--r-md); overflow: hidden; border: 1px solid var(--line); box-shadow: 0 12px 32px -12px rgba(23,26,61,.25); }
.alert-bar { background: var(--majorelle); color: #fff; padding: 10px 16px; font-family: var(--f-display); font-size: 15px; font-weight: 600; }
.alert-card.urgent .alert-bar { background: var(--danger); }
.alert-body { padding: 16px; }
.alert-title { display: block; font-family: var(--f-display); font-size: 20px; line-height: 1.2; word-break: break-word; }
.alert-text { margin: 8px 0 0; white-space: pre-wrap; color: #3B3F5C; word-break: break-word; }
.alert-text:empty { display: none; }
.alert-foot { padding: 0 16px 16px; }
.fake-btn { display: inline-block; padding: 8px 16px; border-radius: var(--r-sm); background: var(--ok); color: #fff; font-weight: 600; font-size: 14px; }

/* ---------- Tableau de cours ---------- */
.board { background: var(--ink); border-radius: var(--r-lg); padding: 8px 8px 12px; color: #fff; }
.board-head, .rate-row { display: grid; grid-template-columns: minmax(150px, 1.3fr) 1fr 1fr; gap: 12px; align-items: center; }
.board-head { padding: 12px 16px 8px; font-size: 12px; font-weight: 600; color: rgba(255,255,255,.45); }
.board-head span:not(:first-child) { text-align: right; padding-right: 14px; }
.rate-row { padding: 6px 8px 6px 16px; border-radius: var(--r-md); transition: background .15s; position: relative; }
.rate-row + .rate-row { margin-top: 2px; }
.rate-row:hover { background: rgba(255,255,255,.04); }
.rate-row.changed { background: rgba(242,165,22,.12); }
.rate-row.changed::before { content: ""; position: absolute; left: 0; top: 10px; bottom: 10px; width: 3px; border-radius: 2px; background: var(--amber); }
.cur { display: flex; align-items: baseline; gap: 10px; min-width: 0; }
.cur b { font-family: var(--f-display); font-size: 22px; font-weight: 600; letter-spacing: .03em; }
.cur small { font-size: 12px; color: rgba(255,255,255,.5); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rate-cell { position: relative; }
.board input.rate-in {
  background: rgba(255,255,255,.05); border: 1px solid transparent; color: var(--amber);
  font-family: var(--f-display); font-size: 24px; font-weight: 600; text-align: right; font-variant-numeric: tabular-nums;
  padding: 6px 12px; border-radius: var(--r-sm);
}
.board input.rate-in::placeholder { color: rgba(255,255,255,.2); }
.board input.rate-in:hover { border-color: rgba(255,255,255,.12); }
.board input.rate-in:focus { background: rgba(255,255,255,.09); border-color: var(--amber); box-shadow: 0 0 0 3px rgba(242,165,22,.2); }
.was { position: absolute; right: 14px; bottom: -14px; font-size: 11px; color: rgba(255,255,255,.45); pointer-events: none; }
.rate-row.changed { padding-bottom: 16px; }
.rate-row .warn { grid-column: 1 / -1; font-size: 12px; color: var(--amber); padding-left: 0; margin-top: 2px; }
.rate-row .warn:empty { display: none; }
.board-empty { padding: 24px 16px; color: rgba(255,255,255,.55); }

/* ---------- Suivi ---------- */
.timeline { list-style: none; margin: 0 0 20px; padding: 0; display: grid; gap: 12px; }
.entry {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md);
  padding: 16px 18px; display: grid; grid-template-columns: 40px 1fr; gap: 4px 14px;
}
.entry-icon { grid-row: span 3; width: 40px; height: 40px; border-radius: 10px; display: grid; place-items: center; background: var(--majorelle-soft); color: var(--majorelle); }
.entry.rate .entry-icon { background: var(--amber-soft); color: #A96B00; }
.entry.urgent .entry-icon { background: var(--danger-soft); color: var(--danger); }
.entry-top { display: flex; justify-content: space-between; gap: 12px; align-items: baseline; flex-wrap: wrap; }
.entry-title { font-weight: 600; font-size: 16px; word-break: break-word; }
.entry-meta { font-size: 13px; color: var(--muted); white-space: nowrap; }
.entry-body { margin: 0; color: #3B3F5C; white-space: pre-wrap; font-size: 14px; word-break: break-word; }
.entry-rates { display: flex; flex-wrap: wrap; gap: 6px 18px; font-size: 14px; font-variant-numeric: tabular-nums; }
.entry-rates b { font-family: var(--f-display); font-weight: 600; margin-right: 6px; }
.entry-rates span { color: var(--muted); }
.receipts { grid-column: 2; display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.receipt { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px; font-size: 12.5px; background: var(--paper); color: var(--muted); border: 1px solid var(--line); }
.receipt::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: #B4B7C9; }
.receipt.seen { background: var(--majorelle-soft); border-color: transparent; color: var(--majorelle-d); }
.receipt.seen::before { background: var(--majorelle); }
.receipt.done { background: var(--ok-soft); border-color: transparent; color: var(--ok); }
.receipt.done::before { background: var(--ok); }
.empty { padding: 48px 24px; text-align: center; color: var(--muted); background: var(--surface); border: 1px dashed var(--line-2); border-radius: var(--r-md); }

/* ---------- Réglages ---------- */
.segmented-tabs { margin-bottom: 24px; }
.sub-intro { color: var(--muted); margin: 0 0 16px; max-width: 62ch; }
.rows { list-style: none; margin: 0 0 16px; padding: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); }
.rows > li { display: flex; align-items: center; gap: 16px; padding: 14px 18px; flex-wrap: wrap; }
.rows > li + li { border-top: 1px solid var(--line); }
.rows-tight > li { padding: 10px 18px; }
.row-main { flex: 1; min-width: 180px; display: grid; gap: 2px; }
.row-main strong { font-size: 15px; }
.row-main span { font-size: 13px; color: var(--muted); }
.row-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.muted-row { opacity: .55; }
.code-pill {
  font-family: var(--f-display); font-size: 17px; font-weight: 600; letter-spacing: .08em;
  padding: 6px 12px; background: var(--paper); border: 1px dashed var(--line-2); border-radius: var(--r-sm);
  cursor: pointer; user-select: all;
}
.code-pill:hover { border-color: var(--majorelle); color: var(--majorelle); }
.toggle { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); cursor: pointer; }
.cur-code { font-family: var(--f-display); font-size: 18px; font-weight: 600; width: 48px; }
.rows input.cur-name { max-width: 240px; padding: 6px 10px; }
.rows select { width: auto; padding: 6px 10px; }
.order-btns { display: flex; gap: 2px; }
.order-btns .icon-btn { width: 28px; height: 28px; color: var(--muted); opacity: 1; font-size: 14px; }
.order-btns .icon-btn:hover { background: var(--paper); color: var(--text); }
.order-btns .icon-btn:disabled { opacity: .3; cursor: default; }

.inline-add { display: flex; gap: 8px; flex-wrap: wrap; }
.inline-add input { flex: 1 1 200px; width: auto; }
.inline-add .w-code { flex: 0 0 120px; text-transform: uppercase; }
.inline-add select { width: auto; }
.add-panel summary { list-style: none; width: max-content; }
.add-panel summary::-webkit-details-marker { display: none; }
.add-panel[open] summary { display: none; }
.grid-form { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; align-items: end; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); padding: 20px; }
.grid-form .form-error, .grid-form > button { grid-column: 1 / -1; justify-self: start; }

/* ---------- Dialogue ---------- */
.dialog { border: none; border-radius: var(--r-lg); padding: 0; width: min(460px, calc(100% - 32px)); box-shadow: 0 24px 64px -16px rgba(23,26,61,.45); color: var(--text); }
.dialog::backdrop { background: rgba(23,26,61,.45); }
.dialog form { padding: 24px; display: grid; gap: 16px; }
.dialog h2 { font-size: 22px; }
#dialog-body { display: grid; gap: 14px; color: #3B3F5C; }
#dialog-body p { margin: 0; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }
.summary-rates { background: var(--ink); color: #fff; border-radius: var(--r-md); padding: 8px 14px; display: grid; }
.summary-rates div { display: grid; grid-template-columns: 1fr auto auto; gap: 18px; padding: 6px 0; font-variant-numeric: tabular-nums; }
.summary-rates div + div { border-top: 1px solid rgba(255,255,255,.08); }
.summary-rates b { font-family: var(--f-display); font-weight: 600; }
.summary-rates span { color: var(--amber); font-family: var(--f-display); font-size: 17px; text-align: right; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 28px; transform: translate(-50%, 20px);
  background: var(--ink); color: #fff; padding: 12px 20px; border-radius: var(--r-md);
  font-weight: 500; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 50;
  box-shadow: 0 12px 32px -8px rgba(23,26,61,.5);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.err { background: var(--danger); }

/* ---------- Mobile ---------- */
@media (max-width: 980px) {
  .compose { grid-template-columns: 1fr; }
  .preview { position: static; }
}
@media (max-width: 820px) {
  .login { grid-template-columns: 1fr; }
  .login-board { padding: 32px 24px; }
  .board-row { padding: 10px 0; }

  .shell { grid-template-columns: 1fr; }
  .side {
    position: fixed; inset: auto 0 0 0; height: auto; z-index: 20;
    flex-direction: row; padding: 6px 8px calc(6px + env(safe-area-inset-bottom)); gap: 0;
  }
  .side .brand, .side-offices, .side-user { display: none; }
  .nav { grid-auto-flow: column; grid-auto-columns: 1fr; width: 100%; }
  .nav button { flex-direction: column; gap: 3px; font-size: 11.5px; padding: 8px 4px; }
  .main { padding: 20px 16px 110px; }
  .presence-strip { display: flex; gap: 6px; overflow-x: auto; margin: 0 0 20px; padding-bottom: 4px; }
  .presence-strip li { background: var(--surface); border: 1px solid var(--line); padding: 6px 12px; border-radius: 999px; white-space: nowrap; font-size: 13px; }
  .presence-strip small { display: none; }
  .view-head h1 { font-size: 28px; }

  .board-head { display: none; }
  .rate-row { grid-template-columns: 1fr 1fr; padding: 10px 10px 10px 14px; }
  .rate-row .cur { grid-column: 1 / -1; }
  .rate-row.changed { padding-bottom: 20px; }
  .board input.rate-in { font-size: 21px; }
  .entry { grid-template-columns: 1fr; }
  .entry-icon { display: none; }
  .receipts { grid-column: 1; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
