/* Administration — modèle Dreamode (fiches clients hors ligne) */
:root {
  --bg: #f5f6fa; --surface: #ffffff; --fg: #1d2330; --muted: #687086; --line: #e3e6ee;
  --accent: #4b3fd8; --accent-soft: #ecebff; --ok: #1f9d63; --wait: #c98a06; --bad: #d23b4d;
  --radius: 14px; --shadow: 0 1px 2px rgba(16, 20, 40, .05), 0 6px 20px rgba(16, 20, 40, .05);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1117; --surface: #171a22; --fg: #eceef4; --muted: #9aa1b4; --line: #2a2f3c;
    --accent: #8f86ff; --accent-soft: #23214a; --ok: #3ccf8e; --wait: #f0b23a; --bad: #ff6b7c;
    --shadow: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1117; --surface: #171a22; --fg: #eceef4; --muted: #9aa1b4; --line: #2a2f3c;
  --accent: #8f86ff; --accent-soft: #23214a; --ok: #3ccf8e; --wait: #f0b23a; --bad: #ff6b7c;
  --shadow: none; color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--fg);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
h1, h2, h3 { line-height: 1.25; }
.muted { color: var(--muted); }
button, input, select, textarea { font: inherit; color: inherit; }

/* Boutons et champs */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 40px; padding: 8px 16px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--surface); cursor: pointer; font-weight: 600; white-space: nowrap;
}
.btn:hover { border-color: var(--accent); }
a.btn { text-decoration: none; color: inherit; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { color: var(--bad); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
input, select, textarea {
  width: 100%; min-height: 42px; padding: 9px 12px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--surface);
}
textarea { min-height: 96px; resize: vertical; }
input[type=radio], input[type=checkbox] { width: auto; min-height: 0; margin: 0 4px 0 0; accent-color: var(--accent); }
input:focus, select:focus, textarea:focus, .btn:focus-visible, .nav a:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px; border-color: var(--accent);
}
label { display: block; font-weight: 600; font-size: 13px; margin: 12px 0 6px; }
.form-error { color: var(--bad); min-height: 1.2em; margin: 8px 0 0; font-size: 14px; }
.field-error { color: var(--bad); font-size: 12px; margin-top: 4px; }

/* Connexion */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card {
  width: min(400px, 100%); background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 28px; box-shadow: var(--shadow);
}
.login-card h1 { font-size: 22px; margin: 12px 0 4px; }
.login-card .btn { width: 100%; margin-top: 16px; }
.tenant-list { list-style: none; padding: 0; margin: 16px 0 0; display: grid; gap: 8px; }
.tenant-list button { width: 100%; text-align: left; justify-content: flex-start; }

/* Structure */
.shell { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.side {
  background: var(--surface); border-right: 1px solid var(--line); padding: 20px 14px;
  position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; padding: 0 8px 20px; overflow-wrap: anywhere; }
.nav { display: grid; gap: 2px; }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 10px;
  color: var(--muted); text-decoration: none; font-weight: 600;
}
.nav a svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.nav a:hover { color: var(--fg); background: var(--bg); }
.nav a[aria-current="page"] { color: var(--accent); background: var(--accent-soft); }
.main { min-width: 0; padding: 0 28px 40px; }
.top {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 18px 0; position: sticky; top: 0; background: var(--bg); z-index: 5;
}
.top h1 { margin: 0; font-size: 22px; }
.top-actions { display: flex; align-items: center; gap: 10px; }

.menu { position: relative; }
.menu summary {
  list-style: none; width: 36px; height: 36px; border-radius: 50%; background: var(--accent-soft); color: var(--accent);
  display: grid; place-items: center; font-weight: 700; cursor: pointer;
}
.menu summary::-webkit-details-marker { display: none; }
.menu-pop {
  position: absolute; right: 0; top: 44px; width: 290px; background: var(--surface); border: 1px solid var(--line);
  border-radius: 12px; box-shadow: var(--shadow); padding: 8px; display: grid; z-index: 20;
}
.menu-pop p { margin: 6px 10px 8px; font-size: 13px; }
.menu-pop button { text-align: left; border: 0; background: none; padding: 10px; border-radius: 8px; cursor: pointer; }
.menu-pop button:hover { background: var(--bg); }
.menu-pop .danger { color: var(--bad); }

/* Liste */
.toolbar { display: flex; gap: 10px; margin-bottom: 14px; }
.toolbar input { flex: 1; }
.offline-note {
  margin: 0 0 14px; padding: 10px 14px; border-radius: 10px;
  background: color-mix(in srgb, var(--wait) 14%, transparent); font-size: 14px;
}
.cards { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px;
  box-shadow: var(--shadow); cursor: pointer; display: grid; gap: 4px; min-width: 0;
  text-align: left; width: 100%;
}
.card:hover { border-color: var(--accent); }
.card-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.card strong { font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card .meta { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tag { font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: var(--bg); color: var(--muted); flex: none; }
.tag.pending { background: color-mix(in srgb, var(--wait) 18%, transparent); color: var(--wait); }
.tag.conflict, .tag.error { background: color-mix(in srgb, var(--bad) 16%, transparent); color: var(--bad); }
.tag.client { background: color-mix(in srgb, var(--ok) 16%, transparent); color: var(--ok); }
.empty { color: var(--muted); text-align: center; padding: 40px 0; }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; margin-bottom: 14px; }
.panel h2 { margin: 0 0 4px; font-size: 17px; }
.row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.row input { width: auto; flex: 1 1 220px; }
.log { list-style: none; padding: 0; margin: 12px 0 0; display: grid; gap: 6px; }
.log li { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); flex-wrap: wrap; }
.log small { color: var(--muted); }

/* Fiche */
.sheet {
  width: min(620px, calc(100vw - 24px)); max-height: calc(100vh - 32px); padding: 0; border: 1px solid var(--line);
  border-radius: 18px; background: var(--surface); color: var(--fg);
}
.sheet::backdrop { background: rgba(10, 12, 20, .5); }
.sheet form { padding: 20px 22px; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; }
.sheet-head h2 { margin: 0; font-size: 19px; }
.icon-btn { border: 0; background: none; font-size: 26px; line-height: 1; color: var(--muted); cursor: pointer; padding: 4px 8px; }
.fields { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.fields .wide { grid-column: 1 / -1; }
.sheet-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 18px; align-items: center; }
.grow { flex: 1; }
.history { margin-top: 16px; border-top: 1px solid var(--line); padding-top: 12px; }
.history h3 { font-size: 15px; margin: 0 0 8px; }
.history ol { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.history li { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; font-size: 13px; }
.history .hv-top { display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.history .hv-data { color: var(--muted); margin: 4px 0 6px; overflow-wrap: anywhere; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px); opacity: 0;
  background: var(--fg); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-weight: 600;
  transition: .2s; pointer-events: none; max-width: calc(100vw - 32px); z-index: 50;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* Téléphone */
@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; }
  .side {
    position: fixed; top: auto; bottom: 0; left: 0; right: 0; height: auto; z-index: 10;
    border-right: 0; border-top: 1px solid var(--line); padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
  }
  .brand { display: none; }
  .nav { grid-auto-flow: column; grid-auto-columns: 1fr; }
  .nav a { flex-direction: column; gap: 2px; font-size: 11px; padding: 6px 4px; }
  .main { padding: 0 16px 96px; }
  .top h1 { font-size: 19px; }
  .toolbar { flex-direction: column; }
  .fields { grid-template-columns: 1fr; }
  .sheet-actions .btn.ghost { padding: 8px 10px; }
}
