/* =============================================================
   FAMILLEGES — feuille de styles
   Charte : bleu institutionnel #003366, thème clair / sombre
   ============================================================= */

:root {
  --brand:          #003366;
  --brand-600:      #00447f;
  --brand-400:      #17609e;
  --brand-200:      #cfe0f0;
  --accent:         #c8952a;

  --ok:             #1c7c54;
  --ok-bg:          #e4f3ec;
  --warn:           #b06a00;
  --warn-bg:        #fdf0dc;
  --danger:         #a4262c;
  --danger-bg:      #fbe6e7;
  --info:           #17609e;
  --info-bg:        #e6eff8;

  --bg:             #f4f6f9;
  --surface:        #ffffff;
  --surface-2:      #fafbfd;
  --border:         #dde3ec;
  --border-strong:  #c3ccd9;
  --text:           #1b2432;
  --text-muted:     #5d6b80;
  --text-faint:     #8894a6;
  --shadow:         0 1px 2px rgba(16,32,64,.06), 0 4px 16px rgba(16,32,64,.06);
  --shadow-lg:      0 8px 40px rgba(10,25,50,.22);

  --radius:         10px;
  --radius-sm:      7px;
  --sidebar-w:      248px;
  --topbar-h:       58px;
  --font: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
}

[data-theme="dark"] {
  --brand:          #0b2f57;
  --brand-600:      #12406f;
  --brand-400:      #4a90d9;
  --brand-200:      #24405f;
  --accent:         #e0ad46;

  --ok:             #5ec48f;
  --ok-bg:          #143227;
  --warn:           #e0a24a;
  --warn-bg:        #382b12;
  --danger:         #f08a8f;
  --danger-bg:      #3b1c1e;
  --info:           #7fb6ea;
  --info-bg:        #16293f;

  --bg:             #10151d;
  --surface:        #171e28;
  --surface-2:      #1c2531;
  --border:         #2a3442;
  --border-strong:  #3a4657;
  --text:           #e6ebf2;
  --text-muted:     #a3b0c2;
  --text-faint:     #7c8a9e;
  --shadow:         0 1px 2px rgba(0,0,0,.4), 0 4px 16px rgba(0,0,0,.3);
  --shadow-lg:      0 8px 40px rgba(0,0,0,.55);
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--brand-400); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- Utilitaires ------------------------------------- */
.hidden { display: none !important; }
.muted  { color: var(--text-muted); }
.faint  { color: var(--text-faint); }
.right  { text-align: right; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }
.mono   { font-variant-numeric: tabular-nums; }
.row    { display: flex; gap: 12px; align-items: center; }
.row-wrap { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.stack  { display: flex; flex-direction: column; gap: 4px; }

.skip-link {
  position: absolute; left: -999px; top: 0; z-index: 100;
  background: var(--surface); color: var(--text); padding: 10px 16px;
}
.skip-link:focus { left: 8px; top: 8px; }

/* ---------- Barre supérieure -------------------------------- */
.topbar {
  position: fixed; inset: 0 0 auto 0; height: var(--topbar-h); z-index: 40;
  background: var(--brand); color: #fff;
  display: flex; align-items: center; gap: 14px; padding: 0 16px;
  box-shadow: 0 1px 0 rgba(0,0,0,.15);
}
.topbar .brand { display: flex; align-items: center; gap: 10px; font-weight: 600; letter-spacing: .2px; }
.topbar .brand .logo {
  width: 32px; height: 32px; border-radius: 8px; flex: none;
  background: #fff; color: var(--brand);
  display: grid; place-items: center; font-weight: 800; font-size: 15px;
}
.topbar .brand small { display: block; font-weight: 400; font-size: 11px; opacity: .8; letter-spacing: .3px; }
.topbar .tb-actions { display: flex; align-items: center; gap: 8px; margin-left: auto; }

.icon-btn {
  background: rgba(255,255,255,.1); border: 1px solid rgba(255,255,255,.18);
  color: #fff; height: 34px; min-width: 34px; padding: 0 10px;
  border-radius: var(--radius-sm); cursor: pointer; font-size: 14px;
  display: inline-flex; align-items: center; gap: 7px;
}
.icon-btn:hover { background: rgba(255,255,255,.2); }
.icon-btn.small { height: 28px; font-size: 13px; }

.menu-toggle { display: none; }

/* ---------- Menu utilisateur -------------------------------- */
.user-menu { position: relative; }
.user-menu .avatar {
  width: 30px; height: 30px; border-radius: 50%; background: var(--accent); color: #2a1e00;
  display: grid; place-items: center; font-weight: 700; font-size: 12px; flex: none;
}
.dropdown {
  position: absolute; right: 0; top: calc(100% + 8px); min-width: 235px; z-index: 60;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-lg);
  padding: 6px; overflow: hidden;
}
.dropdown .dd-head { padding: 10px 12px 12px; border-bottom: 1px solid var(--border); margin-bottom: 6px; }
.dropdown button, .dropdown a {
  display: flex; width: 100%; align-items: center; gap: 9px; text-align: left;
  background: none; border: 0; color: var(--text); padding: 9px 12px;
  border-radius: var(--radius-sm); cursor: pointer; font: inherit; text-decoration: none;
}
.dropdown button:hover, .dropdown a:hover { background: var(--surface-2); }
.dropdown .sep { height: 1px; background: var(--border); margin: 6px 0; }
.theme-choice { display: flex; gap: 4px; padding: 4px 8px 8px; }
.theme-choice button {
  flex: 1; justify-content: center; border: 1px solid var(--border); font-size: 12.5px; padding: 6px 4px;
}
.theme-choice button.active { background: var(--brand); color: #fff; border-color: var(--brand); }

/* ---------- Menu latéral ------------------------------------ */
.sidebar {
  position: fixed; top: var(--topbar-h); bottom: 0; left: 0; width: var(--sidebar-w); z-index: 30;
  background: var(--surface); border-right: 1px solid var(--border);
  padding: 14px 10px; overflow-y: auto;
}
.nav-group { margin-bottom: 18px; }
.nav-group h4 {
  margin: 0 0 6px; padding: 0 10px; font-size: 10.5px; font-weight: 700;
  letter-spacing: .9px; text-transform: uppercase; color: var(--text-faint);
}
.nav-item {
  display: flex; align-items: center; gap: 11px; width: 100%;
  padding: 9px 11px; border-radius: var(--radius-sm); border: 0; background: none;
  color: var(--text); font: inherit; cursor: pointer; text-align: left; margin-bottom: 1px;
}
.nav-item:hover { background: var(--surface-2); text-decoration: none; }
.nav-item.active { background: var(--brand); color: #fff; font-weight: 600; }
.nav-item .ico { width: 18px; text-align: center; flex: none; font-size: 15px; }
.nav-item .badge {
  margin-left: auto; background: var(--danger); color: #fff; border-radius: 20px;
  font-size: 11px; font-weight: 700; padding: 1px 7px; min-width: 20px; text-align: center;
}
.nav-item.active .badge { background: rgba(255,255,255,.25); }

/* ---------- Contenu ----------------------------------------- */
.content {
  margin: var(--topbar-h) 0 0 var(--sidebar-w);
  padding: 22px 26px 60px;
  min-height: calc(100vh - var(--topbar-h));
}
.page-head {
  display: flex; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 18px;
}
.page-head h1 { margin: 0; font-size: 22px; font-weight: 600; letter-spacing: -.2px; }
.page-head p  { margin: 3px 0 0; color: var(--text-muted); font-size: 13.5px; }
.page-head .actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- Cartes ------------------------------------------ */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 18px;
}
.card > header {
  padding: 13px 16px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 10px;
}
.card > header h3 { margin: 0; font-size: 14.5px; font-weight: 600; }
.card > .body { padding: 16px; }
.card > .body.flush { padding: 0; }

.grid { display: grid; gap: 16px; }
.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)); }

/* ---------- Indicateurs ------------------------------------- */
.kpi {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 15px 16px; box-shadow: var(--shadow); position: relative; overflow: hidden;
}
.kpi::before {
  content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--brand-400);
}
.kpi.ok::before     { background: var(--ok); }
.kpi.warn::before   { background: var(--warn); }
.kpi.danger::before { background: var(--danger); }
.kpi .label { font-size: 12px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .6px; font-weight: 600; }
.kpi .value { font-size: 25px; font-weight: 650; margin: 5px 0 2px; letter-spacing: -.5px; font-variant-numeric: tabular-nums; }
.kpi .sub   { font-size: 12.5px; color: var(--text-muted); }

/* ---------- Tableaux ---------------------------------------- */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.data th {
  text-align: left; padding: 10px 14px; background: var(--surface-2);
  border-bottom: 1px solid var(--border); font-weight: 600; font-size: 11.5px;
  text-transform: uppercase; letter-spacing: .5px; color: var(--text-muted); white-space: nowrap;
}
table.data th.sortable { cursor: pointer; user-select: none; }
table.data th.sortable:hover { color: var(--text); }
table.data td { padding: 10px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.data tbody tr:hover { background: var(--surface-2); }
table.data tbody tr.clickable { cursor: pointer; }
table.data td.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
table.data .actions-cell { text-align: right; white-space: nowrap; }
table.data tfoot td { padding: 11px 14px; font-weight: 600; background: var(--surface-2); border-top: 2px solid var(--border-strong); }

.empty { padding: 44px 20px; text-align: center; color: var(--text-muted); }
.empty .big { font-size: 30px; margin-bottom: 8px; opacity: .5; }

/* ---------- Étiquettes -------------------------------------- */
.tag {
  display: inline-block; padding: 2px 9px; border-radius: 20px; font-size: 11.5px;
  font-weight: 600; background: var(--info-bg); color: var(--info); white-space: nowrap;
}
.tag.ok     { background: var(--ok-bg);     color: var(--ok); }
.tag.warn   { background: var(--warn-bg);   color: var(--warn); }
.tag.danger { background: var(--danger-bg); color: var(--danger); }
.tag.neutral{ background: var(--surface-2); color: var(--text-muted); border: 1px solid var(--border); }

/* ---------- Boutons ----------------------------------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 8px 15px; border-radius: var(--radius-sm); border: 1px solid var(--border-strong);
  background: var(--surface); color: var(--text); font: inherit; font-size: 13.5px;
  font-weight: 500; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-600); }
.btn.danger  { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.ghost   { background: none; border-color: transparent; color: var(--text-muted); padding: 6px 9px; }
.btn.ghost:hover { background: var(--surface-2); color: var(--text); }
.btn.sm { padding: 5px 10px; font-size: 12.5px; }

/* ---------- Formulaires ------------------------------------- */
.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 14px; }
.field > label { font-size: 12.5px; font-weight: 600; color: var(--text-muted); }
.field .hint { font-size: 11.5px; color: var(--text-faint); }
input[type=text], input[type=password], input[type=number], input[type=date],
input[type=email], input[type=tel], input[type=search], select, textarea {
  width: 100%; padding: 8px 11px; font: inherit; font-size: 14px;
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text);
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--brand-400); outline-offset: -1px; border-color: var(--brand-400);
}
textarea { min-height: 78px; resize: vertical; }
.check { display: flex; align-items: center; gap: 9px; margin-bottom: 14px; }
.check input { width: 17px; height: 17px; accent-color: var(--brand); }
.check label { font-size: 14px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 0 16px; }
.form-grid .full { grid-column: 1 / -1; }
fieldset.form-section { border: 0; padding: 0; margin: 0 0 6px; }
fieldset.form-section > legend {
  font-size: 11.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .7px;
  color: var(--brand-400); padding: 0; margin-bottom: 10px;
  border-bottom: 1px solid var(--border); width: 100%; padding-bottom: 6px;
}

.toolbar {
  display: flex; gap: 9px; align-items: center; flex-wrap: wrap;
  padding: 12px 16px; border-bottom: 1px solid var(--border); background: var(--surface-2);
}
.toolbar input[type=search], .toolbar select { width: auto; min-width: 155px; }
.toolbar .grow { flex: 1; min-width: 190px; }

/* ---------- Fenêtre modale ---------------------------------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(9,18,32,.55); z-index: 80;
  display: flex; align-items: flex-start; justify-content: center; padding: 40px 16px; overflow-y: auto;
  backdrop-filter: blur(2px);
}
.modal {
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow-lg);
  width: 100%; max-width: 720px; border: 1px solid var(--border);
}
.modal.wide { max-width: 940px; }
.modal.narrow { max-width: 440px; }
.modal > header {
  padding: 15px 20px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 12px;
}
.modal > header h3 { margin: 0; font-size: 16.5px; font-weight: 600; }
.modal > .body { padding: 20px; max-height: calc(100vh - 220px); overflow-y: auto; }
.modal > footer {
  padding: 13px 20px; border-top: 1px solid var(--border);
  display: flex; gap: 9px; justify-content: flex-end; background: var(--surface-2);
  border-radius: 0 0 var(--radius) var(--radius);
}

/* ---------- Notifications ----------------------------------- */
#toasts { position: fixed; bottom: 20px; right: 20px; z-index: 100; display: flex; flex-direction: column; gap: 9px; }
.toast {
  background: var(--surface); border: 1px solid var(--border); border-left: 3px solid var(--brand-400);
  border-radius: var(--radius-sm); box-shadow: var(--shadow-lg); padding: 11px 16px;
  min-width: 250px; max-width: 380px; font-size: 13.5px; animation: slideIn .18s ease;
}
.toast.ok    { border-left-color: var(--ok); }
.toast.error { border-left-color: var(--danger); }
@keyframes slideIn { from { transform: translateX(16px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------- Échéances --------------------------------------- */
.deadline {
  display: flex; align-items: center; gap: 13px; padding: 11px 16px; border-bottom: 1px solid var(--border);
}
.deadline:last-child { border-bottom: 0; }
.deadline .when {
  flex: none; width: 74px; text-align: center; border-radius: var(--radius-sm);
  padding: 6px 4px; font-size: 11.5px; font-weight: 700; line-height: 1.25;
  background: var(--info-bg); color: var(--info);
}
.deadline.depasse  .when { background: var(--danger-bg); color: var(--danger); }
.deadline.critique .when { background: var(--danger-bg); color: var(--danger); }
.deadline.proche   .when { background: var(--warn-bg);   color: var(--warn); }
.deadline .what { flex: 1; min-width: 0; }
.deadline .what strong { font-weight: 600; font-size: 14px; }
.deadline .what div { font-size: 12.5px; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; }

/* ---------- Graphiques -------------------------------------- */
.bars { display: flex; align-items: flex-end; gap: 5px; height: 190px; padding: 8px 0 0; }
.bars .month { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 5px; min-width: 0; }
.bars .pair { flex: 1; width: 100%; display: flex; gap: 2px; align-items: flex-end; justify-content: center; }
.bars .bar { width: 45%; border-radius: 3px 3px 0 0; min-height: 2px; transition: height .3s; }
.bars .bar.rev { background: var(--ok); }
.bars .bar.dep { background: var(--brand-400); }
.bars .lbl { font-size: 10.5px; color: var(--text-faint); }
.legend { display: flex; gap: 16px; font-size: 12.5px; color: var(--text-muted); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 11px; height: 11px; border-radius: 3px; display: inline-block; }

.dist-row { display: flex; align-items: center; gap: 11px; margin-bottom: 9px; font-size: 13px; }
.dist-row .nm { width: 130px; flex: none; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dist-row .track { flex: 1; height: 9px; background: var(--surface-2); border-radius: 5px; overflow: hidden; border: 1px solid var(--border); }
.dist-row .fill { height: 100%; background: var(--brand-400); border-radius: 5px; }
.dist-row .val { width: 96px; text-align: right; font-variant-numeric: tabular-nums; flex: none; }

/* ---------- Fiche détaillée --------------------------------- */
.detail-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 14px 20px; }
.detail-grid .item .k { font-size: 11.5px; text-transform: uppercase; letter-spacing: .5px; color: var(--text-faint); font-weight: 600; }
.detail-grid .item .v { font-size: 14.5px; margin-top: 2px; }
.tabs { display: flex; gap: 3px; border-bottom: 1px solid var(--border); padding: 0 16px; overflow-x: auto; }
.tabs button {
  background: none; border: 0; border-bottom: 2px solid transparent; padding: 11px 13px;
  font: inherit; font-size: 13.5px; color: var(--text-muted); cursor: pointer; white-space: nowrap;
}
.tabs button.active { color: var(--brand-400); border-bottom-color: var(--brand-400); font-weight: 600; }

/* ---------- Page de connexion ------------------------------- */
.login-page {
  min-height: 100vh; display: grid; place-items: center; padding: 24px;
  background: linear-gradient(150deg, var(--brand) 0%, #001d3d 100%);
}
[data-theme="dark"] .login-page { background: linear-gradient(150deg, #0b2f57 0%, #070d16 100%); }
.login-card {
  background: var(--surface); border-radius: 14px; box-shadow: var(--shadow-lg);
  width: 100%; max-width: 400px; padding: 34px 32px 28px; border: 1px solid var(--border);
}
.login-card .logo-big {
  width: 62px; height: 62px; border-radius: 15px; background: var(--brand); color: #fff;
  display: grid; place-items: center; font-size: 26px; font-weight: 800; margin: 0 auto 16px;
}
.login-card h1 { text-align: center; font-size: 20px; margin: 0 0 4px; font-weight: 600; }
.login-card .sub { text-align: center; color: var(--text-muted); font-size: 13.5px; margin: 0 0 24px; }
.login-card .btn { width: 100%; padding: 11px; font-size: 15px; margin-top: 4px; }
.login-error {
  background: var(--danger-bg); color: var(--danger); border-radius: var(--radius-sm);
  padding: 10px 13px; font-size: 13.5px; margin-bottom: 16px; border: 1px solid var(--danger);
}
.login-foot { text-align: center; margin-top: 20px; font-size: 12px; color: var(--text-faint); }
.login-theme { display: flex; justify-content: center; gap: 5px; margin-top: 18px; }
.login-theme button {
  background: none; border: 1px solid var(--border); color: var(--text-muted);
  padding: 4px 11px; border-radius: 20px; font-size: 12px; cursor: pointer;
}
.login-theme button.active { background: var(--brand); color: #fff; border-color: var(--brand); }

/* ---------- Impression -------------------------------------- */
@media print {
  .topbar, .sidebar, .page-head .actions, .toolbar, #toasts, .no-print { display: none !important; }
  .content { margin: 0; padding: 0; }
  .card { box-shadow: none; break-inside: avoid; border-color: #ccc; }
  body { background: #fff; font-size: 11pt; }
}

/* ---------- Adaptatif --------------------------------------- */
@media (max-width: 1080px) {
  .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: 860px) {
  .menu-toggle { display: inline-flex; }
  .sidebar { transform: translateX(-100%); transition: transform .2s; box-shadow: var(--shadow-lg); }
  body.nav-open .sidebar { transform: none; }
  .content { margin-left: 0; padding: 16px 14px 50px; }
  .grid.cols-2, .grid.cols-3, .grid.cols-4 { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .topbar .brand small { display: none; }
  .modal > .body { max-height: calc(100vh - 170px); }
}
