/* Sovereign — tableau de bord. Sombre premium par défaut, thème clair en option. */
:root {
  --bg: #0b0b10;
  --bg-2: #111118;
  --surface: #16161f;
  --surface-2: #1d1d28;
  --line: #2a2a38;
  --text: #ecebf2;
  --muted: #9a98a8;
  --gold: #d9b45a;
  --gold-2: #f0d48a;
  --gold-soft: rgba(217, 180, 90, .12);
  --green: #4fc98a;
  --red: #f0646e;
  --orange: #f2a65a;
  --blue: #6aa8ff;
  --shadow: 0 10px 30px rgba(0, 0, 0, .35);
  --radius: 14px;
  --sidebar: 248px;
  color-scheme: dark;
}
:root[data-theme="light"] {
  --bg: #f6f4ef;
  --bg-2: #efece4;
  --surface: #ffffff;
  --surface-2: #f8f6f1;
  --line: #e4dfd3;
  --text: #1d1b22;
  --muted: #6d6a76;
  --gold: #a87e1f;
  --gold-2: #8a6514;
  --gold-soft: rgba(168, 126, 31, .1);
  --shadow: 0 8px 24px rgba(40, 30, 10, .08);
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--gold); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; color: inherit; }

/* ---------------------------------------------------------------- démarrage et connexion */
.boot { min-height: 100vh; display: grid; place-items: center; }
.boot-logo, .logo {
  font-family: "Cormorant Garamond", Georgia, serif;
  letter-spacing: .28em;
  color: var(--gold);
  font-weight: 700;
}
.boot-logo { font-size: 28px; animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .4; } }

.login {
  min-height: 100vh; display: grid; place-items: center; padding: 16px;
  background: radial-gradient(1200px 600px at 50% -10%, var(--gold-soft), transparent 60%), var(--bg);
}
.login-card {
  width: 100%; max-width: 400px; text-align: center; padding: 40px 28px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 20px; box-shadow: var(--shadow);
}
.login-card .logo { font-size: 30px; margin-bottom: 4px; }
.login-card p { color: var(--muted); margin: 8px 0 28px; }
.btn-discord {
  display: inline-flex; align-items: center; justify-content: center; gap: 10px; width: 100%;
  padding: 13px 18px; border-radius: 12px; background: #5865f2; color: #fff; font-weight: 600; border: 0;
}
.btn-discord:hover { background: #4752c4; text-decoration: none; }
.login-error { margin-top: 16px; color: var(--red); font-size: 14px; }

/* ---------------------------------------------------------------- structure */
.shell { display: grid; grid-template-columns: var(--sidebar) 1fr; min-height: 100vh; }
.sidebar {
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
  background: var(--bg-2); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; padding: 22px 14px;
}
.sidebar .logo { font-size: 22px; padding: 0 10px 2px; }
.sidebar .tagline { color: var(--muted); font-size: 12px; padding: 0 10px 22px; letter-spacing: .04em; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a {
  display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 10px;
  color: var(--muted); font-weight: 500; text-decoration: none;
}
.nav a svg { width: 18px; height: 18px; flex: none; }
.nav a:hover { background: var(--surface); color: var(--text); }
.nav a.active { background: var(--gold-soft); color: var(--gold); }
.nav .count {
  margin-left: auto; background: var(--gold); color: #1a1408; font-size: 11px; font-weight: 700;
  border-radius: 999px; padding: 1px 7px;
}
.sidebar-foot { margin-top: auto; padding-top: 18px; border-top: 1px solid var(--line); }
.user { display: flex; align-items: center; gap: 10px; padding: 8px 10px; }
.avatar {
  width: 34px; height: 34px; border-radius: 50%; background: var(--surface-2); flex: none;
  display: grid; place-items: center; font-weight: 700; color: var(--gold); overflow: hidden;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.user .name { font-weight: 600; font-size: 14px; }
.user .role { color: var(--muted); font-size: 12px; }
.foot-actions { display: flex; gap: 6px; padding: 8px 4px 0; }

.main { min-width: 0; padding: 28px 32px 48px; }
.topbar { display: none; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 22px; }
.page-head h1 { margin: 0; font-size: 26px; font-weight: 700; letter-spacing: -.01em; }
.page-head .sub { color: var(--muted); margin-top: 2px; }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------------------------------------------------------------- composants */
.grid { display: grid; gap: 16px; }
.kpis { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); margin-bottom: 16px; }
.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.cols-3 { grid-template-columns: 2fr 1fr; }
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px 18px 16px; min-width: 0;
}
.card h2 { font-size: 15px; margin: 0 0 14px; font-weight: 600; display: flex; align-items: center; gap: 8px; }
.card h2 .hint { margin-left: auto; color: var(--muted); font-weight: 400; font-size: 13px; }
.kpi .label { color: var(--muted); font-size: 13px; }
.kpi .value { font-size: 28px; font-weight: 700; letter-spacing: -.02em; margin-top: 4px; }
.kpi .value.gold { color: var(--gold); }
.kpi .delta { font-size: 12px; color: var(--muted); margin-top: 2px; }
.kpi .delta.bad { color: var(--red); }
.kpi .delta.good { color: var(--green); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 14px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--surface-2); color: var(--text); cursor: pointer; font-weight: 500; font-size: 14px;
  white-space: nowrap; text-decoration: none;
}
.btn:hover { border-color: var(--gold); text-decoration: none; }
.btn.primary { background: var(--gold); border-color: var(--gold); color: #1a1408; }
.btn.primary:hover { background: var(--gold-2); }
.btn.danger { color: var(--red); }
.btn.small { padding: 4px 10px; font-size: 13px; border-radius: 8px; }
.btn.icon-only { padding: 3px 7px; }
.secret { display: inline-flex; align-items: center; gap: 4px; white-space: nowrap; }
.secret code { font-family: ui-monospace, Consolas, monospace; font-size: 13px; background: var(--gold-soft); border: 1px solid var(--line); border-radius: 6px; padding: 2px 6px; min-width: 88px; }
.btn.icon { padding: 7px; }
.btn svg { width: 16px; height: 16px; }

.pill {
  display: inline-flex; align-items: center; gap: 4px; padding: 2px 9px; border-radius: 999px;
  font-size: 12px; font-weight: 600; background: var(--surface-2); color: var(--muted); white-space: nowrap;
}
.pill.green { background: rgba(79, 201, 138, .14); color: var(--green); }
.pill.red { background: rgba(240, 100, 110, .14); color: var(--red); }
.pill.orange { background: rgba(242, 166, 90, .15); color: var(--orange); }
.pill.gold { background: var(--gold-soft); color: var(--gold); }
.pill.blue { background: rgba(106, 168, 255, .14); color: var(--blue); }
.muted { color: var(--muted); }
.empty { color: var(--muted); padding: 14px 0; text-align: center; font-size: 14px; }
.strike { text-decoration: line-through; opacity: .6; }

.list { display: flex; flex-direction: column; }
.list-item { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-top: 1px solid var(--line); min-width: 0; }
.list-item:first-child { border-top: 0; padding-top: 2px; }
.list-item .grow { flex: 1; min-width: 0; }
.list-item .title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-item .meta { color: var(--muted); font-size: 13px; }

.feed-item { padding: 9px 0; border-top: 1px solid var(--line); font-size: 14px; overflow-wrap: anywhere; }
.feed-item:first-child { border-top: 0; padding-top: 0; }
.feed-item time { color: var(--muted); font-size: 12px; display: block; }

/* Tableaux : deviennent des cartes sur mobile */
.table-wrap { overflow-x: auto; margin: 0 -18px; padding: 0 18px; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; color: var(--muted); font-weight: 500; font-size: 12px; text-transform: uppercase; letter-spacing: .05em;
     padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 11px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--surface-2); }

.rank { font-weight: 700; color: var(--muted); width: 28px; }
.rank.top { color: var(--gold); }
.progress { height: 6px; background: var(--surface-2); border-radius: 999px; overflow: hidden; min-width: 70px; }
.progress span { display: block; height: 100%; background: var(--gold); border-radius: 999px; }
.progress span.ok { background: var(--green); }

/* Graphique en barres */
.chart { display: flex; align-items: flex-end; gap: 6px; height: 180px; padding-top: 10px; }
.chart .bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; min-width: 0; height: 100%; justify-content: flex-end; }
.chart .bar { width: 100%; max-width: 34px; background: linear-gradient(180deg, var(--gold-2), var(--gold)); border-radius: 6px 6px 2px 2px; min-height: 2px; }
.chart .bar.zero { background: var(--surface-2); }
.chart .bar-label { font-size: 11px; color: var(--muted); white-space: nowrap; }

/* Planning */
.week-nav { display: flex; align-items: center; gap: 8px; }
.planning { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 10px; }
.day { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; min-width: 0; }
.day.today { border-color: var(--gold); box-shadow: 0 0 0 1px var(--gold) inset; }
.day h3 { margin: 0 0 10px; font-size: 14px; }
.slot { padding: 8px 0; border-top: 1px dashed var(--line); }
.slot:first-of-type { border-top: 0; padding-top: 0; }
.slot .hours { font-size: 11px; color: var(--muted); font-weight: 600; letter-spacing: .03em; margin-bottom: 4px; }
.chips { display: flex; flex-wrap: wrap; gap: 4px; }
.chip { font-size: 12px; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--line); white-space: nowrap;
        max-width: 100%; overflow: hidden; text-overflow: ellipsis; cursor: pointer; }
.chip.active { border-color: var(--green); color: var(--green); }
.chip.done { opacity: .75; }
.chip.absent { border-color: var(--red); color: var(--red); }
.chip.excused { border-color: var(--orange); color: var(--orange); }
.chip.late { border-style: dashed; border-color: var(--orange); }
.legend { display: flex; gap: 12px; flex-wrap: wrap; font-size: 12px; color: var(--muted); margin-top: 12px; }

/* Fiche VA */
.profile { display: flex; align-items: center; gap: 16px; }
.profile .avatar { width: 56px; height: 56px; font-size: 22px; }
.badges { display: flex; flex-wrap: wrap; gap: 8px; }
.badge { background: var(--gold-soft); color: var(--gold); border-radius: 10px; padding: 6px 10px; font-size: 13px; font-weight: 600; }
.badge small { display: block; color: var(--muted); font-weight: 400; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin: 6px 0 16px; overflow-x: auto; scrollbar-width: none; }
.tabs button { background: none; border: 0; padding: 10px 14px; color: var(--muted); cursor: pointer; font-weight: 500;
               border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs button.active { color: var(--gold); border-bottom-color: var(--gold); }

/* Filtres et formulaires */
.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.input, select.input, textarea.input {
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; min-width: 0;
}
.input:focus { outline: 2px solid var(--gold-soft); border-color: var(--gold); }
textarea.input { width: 100%; min-height: 90px; resize: vertical; }

.modal-back { position: fixed; inset: 0; background: rgba(0, 0, 0, .55); display: grid; place-items: center; padding: 16px; z-index: 50; }
.modal { width: 100%; max-width: 440px; background: var(--surface); border: 1px solid var(--line); border-radius: 18px; padding: 22px; box-shadow: var(--shadow); }
.modal h3 { margin: 0 0 16px; }
.modal label { display: block; font-size: 13px; color: var(--muted); margin: 12px 0 5px; }
.modal .input { width: 100%; }
.modal .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }
.modal .error { color: var(--red); font-size: 13px; margin-top: 10px; min-height: 1em; }

#toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px); opacity: 0; pointer-events: none;
  background: var(--surface); border: 1px solid var(--gold); color: var(--text); padding: 10px 16px; border-radius: 12px;
  box-shadow: var(--shadow); transition: .25s; z-index: 60; max-width: calc(100% - 32px);
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.error { border-color: var(--red); }

.drawer-back { display: none; }

/* ---------------------------------------------------------------- écrans moyens */
@media (max-width: 1280px) {
  .planning { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}
@media (max-width: 1100px) {
  .cols-3 { grid-template-columns: 1fr; }
  .main { padding: 24px; }
}

/* ---------------------------------------------------------------- mobile */
@media (max-width: 860px) {
  .shell { display: block; }
  .sidebar {
    position: fixed; z-index: 40; left: 0; top: 0; bottom: 0; width: 280px; height: auto;
    transform: translateX(-100%); transition: transform .25s ease; box-shadow: var(--shadow);
    padding-top: max(22px, env(safe-area-inset-top));
  }
  .menu-open .sidebar { transform: none; }
  .menu-open .drawer-back { display: block; position: fixed; inset: 0; background: rgba(0, 0, 0, .5); z-index: 30; }
  .topbar {
    display: flex; align-items: center; gap: 12px; position: sticky; top: 0; z-index: 20;
    padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top));
    background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--line);
  }
  .topbar .logo { font-size: 18px; }
  .topbar .title { margin-left: auto; color: var(--muted); font-size: 14px; }
  .main { padding: 18px 16px 40px; }
  .page-head h1 { font-size: 22px; }
  .cols-2 { grid-template-columns: 1fr; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .kpi .value { font-size: 22px; }
  .card { padding: 16px 14px 14px; }
  .planning { grid-template-columns: 1fr; }
  .chart { height: 140px; gap: 3px; }
  .chart .bar-label { display: none; }
  .chart .bar-col:nth-child(7n + 1) .bar-label, .chart .bar-col:last-child .bar-label { display: block; }

  /* Tableaux -> cartes */
  .table-wrap { margin: 0; padding: 0; overflow: visible; }
  table.responsive thead { display: none; }
  table.responsive, table.responsive tbody, table.responsive tr, table.responsive td { display: block; width: 100%; }
  table.responsive tr { border: 1px solid var(--line); border-radius: 12px; padding: 6px 12px; margin-bottom: 10px; background: var(--surface-2); }
  table.responsive td { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 7px 0;
                        border-bottom: 1px dashed var(--line); text-align: right; }
  table.responsive td:last-child { border-bottom: 0; }
  table.responsive td::before { content: attr(data-label); color: var(--muted); font-size: 12px; text-align: left; flex: none; }
  table.responsive td.primary { font-weight: 700; font-size: 15px; justify-content: flex-start; text-align: left; }
  table.responsive td.primary::before { display: none; }
  table.responsive td[data-label=""]::before { display: none; }
  table.responsive td.num { text-align: right; }
}
@media (max-width: 340px) {
  .kpis { grid-template-columns: 1fr; }
}
