/* 5abir.ma — Dashboard admin + login (thème futuriste sombre) */
:root {
  color-scheme: dark;
  --bg: #060a18; --panel: #0d1430; --panel-2: #121a3c; --line: rgba(148, 163, 255, .12); --line-2: rgba(148, 163, 255, .22);
  --text: #eef1ff; --text-2: #b8bfdc; --muted: #7d85a8;
  --indigo: #6c7cf0; --cyan: #37d2e6;
  --s1: #3987e5; --s2: #d95926;              /* séries charts (palette validée, mode sombre) */
  --good: #0ca30c; --warn: #fab219; --crit: #d03b3b; --good-t: #4ade80; --crit-t: #f87171;
  --grid: rgba(255, 255, 255, .07); --axis: rgba(255, 255, 255, .18);
  --r: 16px;
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  background:
    radial-gradient(900px 500px at 85% -10%, rgba(55, 210, 230, .12), transparent 60%),
    radial-gradient(800px 600px at -10% 110%, rgba(108, 124, 240, .16), transparent 60%),
    var(--bg);
  color: var(--text); font-family: 'Inter', system-ui, 'Segoe UI', sans-serif; font-size: 14px;
}
body::before {
  content: ''; position: fixed; inset: 0; pointer-events: none; z-index: 0;
  background-image: linear-gradient(rgba(255,255,255,.025) 1px, transparent 1px), linear-gradient(90deg, rgba(255,255,255,.025) 1px, transparent 1px);
  background-size: 32px 32px;
  -webkit-mask-image: radial-gradient(ellipse at 70% 0%, #000 0%, transparent 70%); mask-image: radial-gradient(ellipse at 70% 0%, #000 0%, transparent 70%);
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: inherit; }
.ar { font-family: 'Cairo', sans-serif; direction: rtl; unicode-bidi: isolate; }

/* ---------- Boutons & champs ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 8px; border: 1px solid var(--line-2); background: rgba(255,255,255,.04);
  padding: 9px 14px; border-radius: 10px; cursor: pointer; font-weight: 600; font-size: 13.5px; text-decoration: none; white-space: nowrap;
}
.btn:hover { background: rgba(255,255,255,.08); }
.btn.primary { border: 0; color: #fff; background: linear-gradient(135deg, var(--indigo), #4f9df0 60%, var(--cyan)); box-shadow: 0 6px 20px -8px rgba(55, 210, 230, .6); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--crit-t); border-color: rgba(208, 59, 59, .4); }
.btn.sm { padding: 6px 10px; font-size: 12.5px; border-radius: 8px; }
.btn:disabled { opacity: .5; cursor: progress; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 12px; font-weight: 600; color: var(--text-2); }
.input, .field input, .field select, .field textarea, select.input {
  width: 100%; background: rgba(6, 10, 24, .6); border: 1px solid var(--line-2); border-radius: 10px; padding: 10px 12px; outline: none;
}
.input:focus, .field input:focus, .field select:focus { border-color: var(--cyan); box-shadow: 0 0 0 3px rgba(55, 210, 230, .15); }
select option { background: var(--panel); }

/* ---------- Login ---------- */
.login-wrap { position: relative; z-index: 1; min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.login {
  width: 100%; max-width: 400px; padding: 30px 28px; border-radius: 22px; background: rgba(13, 20, 48, .82);
  border: 1px solid var(--line-2); box-shadow: 0 30px 80px -30px rgba(0, 0, 0, .8), inset 0 1px 0 rgba(255,255,255,.06);
  backdrop-filter: blur(12px);
}
.login .brand { margin-bottom: 22px; }
.login h1 { font-family: 'Sora', sans-serif; font-size: 22px; margin: 0 0 4px; }
.login p.sub { color: var(--muted); margin: 0 0 20px; font-size: 13px; }
.login form { display: flex; flex-direction: column; gap: 14px; }
.login .btn.primary { justify-content: center; padding: 12px; font-size: 14.5px; margin-top: 4px; }
.err { color: var(--crit-t); font-size: 13px; min-height: 18px; }

.brand { display: flex; align-items: center; gap: 10px; font-family: 'Inter', sans-serif; font-weight: 800; font-size: 17px; letter-spacing: .4px; }
.brand img { width: 36px; height: 36px; background: #fff; border-radius: 10px; padding: 4px; }
.brand b { color: var(--cyan); }
.brand small { display: block; font-size: 10px; letter-spacing: 2px; color: var(--muted); font-weight: 700; }

/* ---------- Layout dashboard ---------- */
.shell { position: relative; z-index: 1; display: grid; grid-template-columns: 250px minmax(0, 1fr); min-height: 100vh; }
.side {
  position: sticky; top: 0; height: 100vh; height: 100dvh; overflow-y: auto; display: flex; flex-direction: column; gap: 6px; padding: 20px 14px;
  background: linear-gradient(180deg, rgba(13, 20, 48, .95), rgba(8, 12, 30, .95)); border-right: 1px solid var(--line);
}
.side .brand { padding: 4px 8px 20px; }
.nav-t { font-size: 10px; letter-spacing: 2px; color: var(--muted); font-weight: 700; padding: 10px 12px 4px; }
.nav button, .nav a {
  position: relative; width: 100%; display: flex; align-items: center; gap: 12px; padding: 11px 12px; border: 0; background: none;
  border-radius: 11px; cursor: pointer; color: var(--text-2); font-weight: 600; font-size: 14px; text-align: left; text-decoration: none;
}
.nav svg { width: 18px; height: 18px; flex-shrink: 0; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.nav button:hover, .nav a:hover { background: rgba(255,255,255,.04); color: var(--text); }
.nav button.on { color: #fff; background: linear-gradient(90deg, rgba(108, 124, 240, .28), rgba(55, 210, 230, .06)); box-shadow: inset 0 0 0 1px rgba(108, 124, 240, .3); }
.nav button.on::before { content: ''; position: absolute; left: -14px; top: 9px; bottom: 9px; width: 3px; border-radius: 0 3px 3px 0; background: linear-gradient(var(--indigo), var(--cyan)); box-shadow: 0 0 12px var(--cyan); }
.nav button.on svg { stroke: var(--cyan); }
.side .me { margin-top: auto; display: flex; align-items: center; gap: 10px; padding: 12px; border-radius: 12px; background: rgba(255,255,255,.03); border: 1px solid var(--line); }
.avatar { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; font-weight: 800; font-size: 13px; flex-shrink: 0; color: #fff; background: linear-gradient(135deg, var(--indigo), var(--cyan)); }
.me div { flex: 1; min-width: 0; }
.me b { display: block; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.me > div span { font-size: 11px; color: var(--muted); }
.me button { border: 0; background: none; cursor: pointer; color: var(--muted); padding: 4px; }
.me button:hover { color: var(--crit-t); }
.me svg { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.main { padding: 26px 30px 40px; min-width: 0; }
.top { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-bottom: 22px; flex-wrap: wrap; }
.top h1 { font-family: 'Sora', sans-serif; font-size: 24px; margin: 0; letter-spacing: -.3px; }
.top p { margin: 3px 0 0; color: var(--muted); font-size: 13px; }
.top .actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.burger { display: none; border: 1px solid var(--line-2); background: rgba(255,255,255,.04); border-radius: 10px; padding: 8px; cursor: pointer; }
.burger svg { width: 20px; height: 20px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; }

/* ---------- Cartes ---------- */
.card {
  background: linear-gradient(180deg, rgba(18, 26, 60, .78), rgba(13, 20, 48, .78)); border: 1px solid var(--line);
  border-radius: var(--r); padding: 18px 20px; box-shadow: inset 0 1px 0 rgba(255,255,255,.04);
}
.card h3 { margin: 0; font-size: 14.5px; font-weight: 700; }
.card .hd { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; margin-bottom: 14px; }
.card .hd span { color: var(--muted); font-size: 12px; }
.grid { display: grid; gap: 16px; }
.grid > * { min-width: 0; } /* bla hadi, tableau kaydfe3 card w kaykhrj men l'écran */
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3-1 { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
.mt { margin-top: 16px; }

.kpi { position: relative; overflow: hidden; }
.kpi::after { content: ''; position: absolute; right: -40px; top: -40px; width: 120px; height: 120px; border-radius: 50%; background: radial-gradient(circle, rgba(55, 210, 230, .16), transparent 70%); }
.kpi .l { color: var(--text-2); font-size: 12.5px; font-weight: 600; display: flex; align-items: center; gap: 8px; }
.kpi .l i { width: 26px; height: 26px; border-radius: 8px; display: grid; place-items: center; background: rgba(108, 124, 240, .16); }
.kpi .l svg { width: 15px; height: 15px; stroke: var(--cyan); fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.kpi .v { font-family: 'Sora', sans-serif; font-size: clamp(19px, 1.6vw + 12px, 28px); font-weight: 700; margin-top: 10px; letter-spacing: -.5px; white-space: nowrap; }
.kpi .v small { font-size: 14px; color: var(--text-2); font-weight: 600; margin-left: 4px; }
.kpi .s { font-size: 12px; color: var(--muted); margin-top: 4px; }
.delta { font-weight: 700; }
.delta.up { color: var(--good-t); } .delta.down { color: var(--crit-t); }

/* ---------- Charts ---------- */
.chart { position: relative; width: 100%; }
.chart svg { display: block; width: 100%; overflow: visible; }
.chart .gl { stroke: var(--grid); stroke-width: 1; }
.chart .bl { stroke: var(--axis); stroke-width: 1; }
.chart text { fill: var(--muted); font-size: 11px; font-family: 'Inter', sans-serif; font-variant-numeric: tabular-nums; }
.chart text.val { fill: var(--text); font-weight: 700; }
.chart text.lab { fill: var(--text-2); font-size: 12px; font-weight: 600; }
.chart .hit { fill: transparent; cursor: default; }
.chart .hit:hover { fill: rgba(255,255,255,.035); }
.legend { display: flex; gap: 16px; font-size: 12px; color: var(--text-2); font-weight: 600; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 10px; height: 10px; border-radius: 3px; }
.tip {
  position: absolute; pointer-events: none; z-index: 5; min-width: 130px; padding: 9px 11px; border-radius: 10px; font-size: 12px;
  background: rgba(6, 10, 24, .96); border: 1px solid var(--line-2); box-shadow: 0 10px 30px -10px #000; transform: translate(-50%, calc(-100% - 10px));
}
.tip b { display: block; margin-bottom: 4px; font-size: 12.5px; }
.tip div { display: flex; justify-content: space-between; gap: 14px; color: var(--text-2); }
.tip div span:last-child { color: var(--text); font-weight: 700; font-variant-numeric: tabular-nums; }
.tip i { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 6px; }
.empty-c { color: var(--muted); text-align: center; padding: 30px 0; font-size: 13px; }

/* ---------- Tableaux ---------- */
.tbl-wrap { overflow-x: auto; margin: 0 -20px; padding: 0 20px; }
.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl th { text-align: left; font-size: 11px; letter-spacing: 1px; text-transform: uppercase; color: var(--muted); font-weight: 700; padding: 10px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.tbl td { padding: 11px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl tbody tr:hover td { background: rgba(255,255,255,.025); }
.tbl .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tbl tfoot td { font-weight: 800; border-top: 1px solid var(--line-2); border-bottom: 0; }
.tbl .muted { color: var(--muted); font-size: 12px; }
.tbl .acts { display: flex; gap: 6px; justify-content: flex-end; }
.who { display: flex; align-items: center; gap: 10px; }
.who .avatar { width: 30px; height: 30px; font-size: 11.5px; border-radius: 9px; }

.badge { display: inline-flex; align-items: center; gap: 6px; font-size: 11.5px; font-weight: 700; padding: 3px 9px; border-radius: 999px; background: rgba(255,255,255,.06); border: 1px solid var(--line); white-space: nowrap; }
.badge i { width: 7px; height: 7px; border-radius: 50%; }
.badge.admin { color: #c7ceff; border-color: rgba(108, 124, 240, .4); background: rgba(108, 124, 240, .14); }
.st-good i { background: var(--good); } .st-warn i { background: var(--warn); } .st-crit i { background: var(--crit); } .st-off i { background: var(--muted); }

.filters { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; }
.filters .input { width: auto; flex: 1 1 180px; }
.filters .grow { flex: 3 1 260px; }
.sum-line { display: flex; gap: 18px; color: var(--text-2); font-size: 13px; margin-bottom: 10px; flex-wrap: wrap; }
.sum-line b { color: var(--text); }

/* ---------- Modal ---------- */
dialog {
  border: 1px solid var(--line-2); border-radius: 20px; padding: 0; width: min(520px, calc(100vw - 32px)); color: var(--text);
  background: linear-gradient(180deg, #121a3c, #0d1430); box-shadow: 0 40px 100px -30px #000;
}
dialog::backdrop { background: rgba(3, 6, 16, .7); backdrop-filter: blur(4px); }
dialog form { padding: 22px 22px 18px; display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
dialog h2 { grid-column: 1 / -1; margin: 0 0 4px; font-family: 'Sora', sans-serif; font-size: 18px; }
dialog .full { grid-column: 1 / -1; }
dialog .foot { grid-column: 1 / -1; display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }
.check { flex-direction: row; align-items: center; gap: 8px; }
.check input { width: auto; }

.exp-form { display: grid; grid-template-columns: 150px 1fr 140px 2fr auto; gap: 10px; align-items: end; }
.cat-bars { display: flex; flex-direction: column; gap: 10px; }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--panel-2); border: 1px solid var(--line-2); padding: 10px 16px; border-radius: 12px; font-weight: 600; z-index: 20; box-shadow: 0 10px 30px -10px #000; }

/* Tableau → cartes ila ma dkhelch (ui.js kayzid .stacked) */
.tbl.measure { width: auto; }
.tbl.measure th, .tbl.measure td { white-space: nowrap; }
.tbl.stacked thead { display: none; }
.tbl.stacked, .tbl.stacked tbody, .tbl.stacked tfoot, .tbl.stacked tr, .tbl.stacked td { display: block; width: 100%; }
.tbl.stacked tr { border: 1px solid var(--line); border-radius: 12px; padding: 2px 14px; margin-bottom: 10px; background: rgba(255,255,255,.025); }
/* Tablette: cartes f joj colonnes (wla ktr) ila kant blasa */
.tbl.stacked tbody { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 10px; }
.tbl.stacked tbody tr { margin-bottom: 0; }
.tbl.stacked tfoot tr { margin-top: 10px; }
.tbl.stacked td { display: flex; justify-content: space-between; align-items: center; gap: 14px; padding: 9px 0; border-bottom: 1px dashed var(--line); text-align: right; }
.tbl.stacked td::before { content: attr(data-label); flex-shrink: 0; color: var(--muted); font-size: 10.5px; font-weight: 700; letter-spacing: .8px; text-transform: uppercase; text-align: left; }
.tbl.stacked td[data-label=""]::before { content: none; }
.tbl.stacked td[data-label=""] .cv { width: 100%; }
.tbl.stacked td .cv { min-width: 0; overflow-wrap: anywhere; }
.tbl.stacked td { padding: 7px 0; }
/* Colonne lowla = ras dyal carte (bla label) */
.tbl.stacked td:first-child { justify-content: flex-start; text-align: left; font-weight: 700; font-size: 14px; padding: 11px 0 9px; }
.tbl.stacked td:first-child::before { content: none; }
.tbl.stacked td:first-child .cv .muted { display: inline; margin-left: 8px; font-weight: 600; }
.tbl.stacked td:first-child .who { justify-content: flex-start; text-align: left; }
.tbl.stacked td:last-child { border-bottom: 0; }
.tbl.stacked td[data-label=""] .acts .btn { flex: 1 1 auto; justify-content: center; padding: 9px 10px; }
.tbl.stacked td[data-label=""] .acts .btn.danger { flex: 0 0 auto; }
.tbl.stacked tbody tr:hover td { background: none; }
.tbl.stacked tfoot tr { background: rgba(108, 124, 240, .1); border-color: rgba(108, 124, 240, .3); }
.tbl.stacked tfoot td { border-top: 0; }
.tbl.stacked .acts { justify-content: flex-end; flex-wrap: wrap; }

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
  .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .g3-1, .g2 { grid-template-columns: 1fr; }
  .exp-form { grid-template-columns: 1fr 1fr; }
  .exp-form .desc { grid-column: 1 / -1; }
}
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: fixed; left: 0; top: 0; bottom: 0; width: 260px; z-index: 30; transform: translateX(-100%); transition: transform .2s; }
  .side.open { transform: none; box-shadow: 0 0 0 100vmax rgba(3, 6, 16, .6); background: #0b1128; }
  .burger { display: inline-grid; }
  .main { padding: 16px 16px 40px; }
  .top h1 { font-size: 20px; }
}
@media (max-width: 640px) {
  /* iPhone kayzoomi ila police dyal champ < 16px */
  .input, .field input, .field select, .field textarea, select.input { font-size: 16px; }
  .top { margin-bottom: 16px; }
  .top > div:first-child { flex: 1; min-width: 0; }
  .top .actions { width: 100%; }
  .top .actions > .btn, .top .actions > select { flex: 1 1 auto; justify-content: center; }
  .top .actions > .design-switch { flex: 1 1 100%; }
  .top .actions > .design-switch button { flex: 1; }
  .filters .input { flex: 1 1 100%; }
  .kpi::after { display: none; }
}
@media (max-width: 520px) {
  .g4 { grid-template-columns: 1fr 1fr; gap: 10px; }
  .kpi .l { font-size: 11.5px; }
  .kpi .l i { display: none; }
  .card { padding: 14px; }
  .card .hd { flex-wrap: wrap; }
  .tbl-wrap { margin: 0 -14px; padding: 0 14px; }
  dialog form { grid-template-columns: 1fr; }
  .exp-form { grid-template-columns: 1fr; }
}
