:root {
  --bg: #060b1a;
  --bg-2: #0a1228;
  --surface: #0e1834;
  --surface-2: #13204a;
  --border: #1e2d5a;
  --text: #e8eefc;
  --muted: #8a9bc4;
  --primary: #1468ff;
  --primary-2: #0b52d6;
  --cyan: #12c8ff;
  --ok: #22c58b;
  --warn: #f5a524;
  --danger: #ff4d6a;
  --radius: 14px;
  --shadow: 0 10px 30px rgba(0, 0, 0, .35);
  font-family: 'Poppins', system-ui, -apple-system, 'Segoe UI', sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: radial-gradient(1200px 600px at 70% -10%, #0c1f55 0%, transparent 60%), var(--bg);
  color: var(--text);
  display: flex;
  font-size: 14px;
  line-height: 1.5;
}
a { color: var(--cyan); text-decoration: none; }
h1, h2, h3 { margin: 0; font-weight: 600; }
h1 { font-size: 24px; }
h2 { font-size: 17px; }
h3 { font-size: 15px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.nowrap { white-space: nowrap; }
[hidden] { display: none !important; }

/* ---------- Sidebar ---------- */
.sidebar {
  width: 240px; flex-shrink: 0; height: 100vh; position: sticky; top: 0;
  background: linear-gradient(180deg, #070e24, #050a18);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column; padding: 18px 14px;
}
.brand img { width: 100%; border-radius: 10px; display: block; }
.sidebar nav { display: flex; flex-direction: column; gap: 4px; margin-top: 22px; }
.sidebar nav a {
  color: var(--muted); padding: 10px 12px; border-radius: 10px; display: flex; gap: 10px; align-items: center; font-weight: 500;
}
.sidebar nav a:hover { background: var(--surface); color: var(--text); }
.sidebar nav a.active { background: linear-gradient(90deg, rgba(20,104,255,.25), rgba(18,200,255,.08)); color: #fff; box-shadow: inset 3px 0 0 var(--cyan); }
.ico { width: 20px; text-align: center; }
.side-foot { margin-top: auto; color: var(--muted); font-size: 11px; text-align: center; }

main { flex: 1; min-width: 0; }
.view { padding: 28px 32px 60px; max-width: 1280px; margin: 0 auto; }

/* ---------- Barre compteurs en cours ---------- */
.running-bar {
  position: sticky; top: 0; z-index: 20;
  background: linear-gradient(90deg, #0b3fae, #0a7fd1);
  padding: 8px 32px; display: flex; gap: 10px; flex-wrap: wrap; align-items: center;
  box-shadow: var(--shadow);
}
.running-chip {
  display: inline-flex; align-items: center; gap: 10px; background: rgba(0,0,0,.25);
  padding: 4px 6px 4px 12px; border-radius: 999px; font-weight: 500;
}
.running-chip .clock { font-variant-numeric: tabular-nums; font-weight: 600; }
.running-chip.over { background: rgba(255, 77, 106, .45); }
.dot { width: 9px; height: 9px; border-radius: 50%; background: #ff4d6a; box-shadow: 0 0 0 0 rgba(255,77,106,.7); animation: pulse 1.4s infinite; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(255,77,106,.7);} 70% { box-shadow: 0 0 0 8px rgba(255,77,106,0);} 100% { box-shadow: 0 0 0 0 rgba(255,77,106,0);} }

/* ---------- Mise en page ---------- */
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 22px; }
.page-head .sub { color: var(--muted); margin-top: 2px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.section { margin-top: 28px; }
.section > .section-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; gap: 10px; flex-wrap: wrap; }

.card {
  background: linear-gradient(180deg, var(--surface), var(--bg-2));
  border: 1px solid var(--border); border-radius: var(--radius); padding: 18px;
}
.grid { display: grid; gap: 14px; }
.stats { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.stat .label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .05em; }
.stat .value { font-size: 26px; font-weight: 600; margin-top: 4px; font-variant-numeric: tabular-nums; }
.stat .hint { color: var(--muted); font-size: 12px; }
.stat .value.danger { color: var(--danger); }

.client-grid { grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); }
.client-card { display: flex; flex-direction: column; gap: 12px; transition: border-color .2s; }
.client-card:hover { border-color: #2c4590; }
.client-card.is-running { border-color: var(--cyan); box-shadow: 0 0 0 1px var(--cyan), 0 0 24px rgba(18,200,255,.15); }
.client-card .top { display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; }
.client-card .name { font-weight: 600; font-size: 15px; color: var(--text); }
.client-card .figures { display: flex; justify-content: space-between; font-size: 13px; font-variant-numeric: tabular-nums; }

/* ---------- Jauge ---------- */
.gauge { height: 10px; background: #0a1430; border-radius: 999px; overflow: hidden; border: 1px solid var(--border); }
.gauge > span { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--primary), var(--cyan)); border-radius: 999px; transition: width .6s ease; }
.gauge.warn > span { background: linear-gradient(90deg, #d98a0b, var(--warn)); }
.gauge.over > span { background: linear-gradient(90deg, #d9304d, var(--danger)); }
.gauge.big { height: 16px; }

/* ---------- Badges ---------- */
.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 11px; font-weight: 600; background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); white-space: nowrap; }
.badge.blue { background: rgba(20,104,255,.18); color: #7fb0ff; border-color: rgba(20,104,255,.4); }
.badge.cyan { background: rgba(18,200,255,.14); color: var(--cyan); border-color: rgba(18,200,255,.35); }
.badge.ok { background: rgba(34,197,139,.14); color: var(--ok); border-color: rgba(34,197,139,.35); }
.badge.warn { background: rgba(245,165,36,.14); color: var(--warn); border-color: rgba(245,165,36,.35); }
.badge.danger { background: rgba(255,77,106,.14); color: var(--danger); border-color: rgba(255,77,106,.35); }

/* ---------- Boutons ---------- */
.btn {
  font: inherit; font-weight: 500; cursor: pointer; border-radius: 10px; padding: 8px 14px;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
  display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
}
.btn:hover { border-color: #3a5bb5; }
.btn.primary { background: linear-gradient(135deg, var(--primary), #1a8cff); border-color: transparent; color: #fff; }
.btn.primary:hover { filter: brightness(1.1); }
.btn.start { background: linear-gradient(135deg, #10a873, var(--ok)); border-color: transparent; color: #04140d; font-weight: 600; }
.btn.stop { background: linear-gradient(135deg, #d9304d, var(--danger)); border-color: transparent; color: #fff; font-weight: 600; }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); }
.btn.sm { padding: 4px 10px; font-size: 12px; border-radius: 8px; }
.btn.lg { padding: 12px 22px; font-size: 16px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.icon-btn { background: none; border: none; color: var(--muted); cursor: pointer; padding: 4px 6px; border-radius: 6px; font-size: 14px; }
.icon-btn:hover { color: var(--text); background: var(--surface-2); }

/* ---------- Tableaux ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { color: var(--muted); font-weight: 500; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
tbody tr:hover { background: rgba(20,104,255,.05); }
tr.clickable { cursor: pointer; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.empty { text-align: center; color: var(--muted); padding: 30px 10px; }

/* ---------- Formulaires ---------- */
input, select, textarea {
  font: inherit; color: var(--text); background: #091330; border: 1px solid var(--border);
  border-radius: 10px; padding: 9px 12px; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(20,104,255,.25); }
input[type=checkbox] { width: auto; accent-color: var(--primary); }
textarea { min-height: 80px; resize: vertical; }
label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
label.check { flex-direction: row; align-items: center; gap: 8px; color: var(--text); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-grid .full { grid-column: 1 / -1; }
.search { width: 240px; max-width: 100%; }
::-webkit-calendar-picker-indicator { filter: invert(.8); }

/* ---------- Modale ---------- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(2,6,18,.7); backdrop-filter: blur(3px); display: flex; align-items: center; justify-content: center; z-index: 100; padding: 16px; }
.modal { width: 100%; max-width: 620px; max-height: 90vh; overflow: auto; background: var(--surface); border: 1px solid var(--border); border-radius: 18px; box-shadow: var(--shadow); }
.modal header { padding: 18px 22px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }
.modal .body { padding: 20px 22px; }
.modal footer { padding: 14px 22px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; }
.modal .error { color: var(--danger); margin-top: 10px; }

/* ---------- Toasts ---------- */
.toasts { position: fixed; bottom: 20px; right: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 200; }
.toast { background: var(--surface-2); border: 1px solid var(--border); border-left: 4px solid var(--cyan); padding: 12px 16px; border-radius: 10px; box-shadow: var(--shadow); max-width: 360px; animation: slide .25s ease; }
.toast.error { border-left-color: var(--danger); }
.toast.warn { border-left-color: var(--warn); }
@keyframes slide { from { transform: translateY(10px); opacity: 0; } }

/* ---------- Fiche client ---------- */
.client-head { display: grid; grid-template-columns: 1.4fr 1fr; gap: 14px; }
.info-list { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; font-size: 13px; }
.info-list dt { color: var(--muted); }
.info-list dd { margin: 0; word-break: break-word; }
.timer-box { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; text-align: center; }
.timer-box .clock { font-size: 44px; font-weight: 600; font-variant-numeric: tabular-nums; letter-spacing: .02em; }
.timer-box.running .clock { color: var(--cyan); text-shadow: 0 0 20px rgba(18,200,255,.45); }
.month-nav { display: flex; align-items: center; gap: 6px; }
.month-nav .label { min-width: 150px; text-align: center; font-weight: 600; text-transform: capitalize; }
.usage-figures { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; margin-top: 14px; }
.usage-figures .label { color: var(--muted); font-size: 12px; }
.usage-figures .value { font-size: 20px; font-weight: 600; font-variant-numeric: tabular-nums; }

.history { display: flex; align-items: flex-end; gap: 8px; height: 150px; padding-top: 10px; }
.history .col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; height: 100%; justify-content: flex-end; min-width: 0; }
.history .bar-area { position: relative; width: 100%; max-width: 34px; flex: 1; display: flex; align-items: flex-end; }
.history .bar { width: 100%; background: linear-gradient(180deg, var(--cyan), var(--primary)); border-radius: 6px 6px 2px 2px; min-height: 2px; }
.history .bar.over { background: linear-gradient(180deg, var(--danger), #a3243a); }
.history .quota { position: absolute; left: -3px; right: -3px; border-top: 2px dashed var(--muted); }
.history .m { font-size: 11px; color: var(--muted); text-transform: capitalize; }
.history .col.current .m { color: var(--cyan); font-weight: 600; }

/* ---------- Rapport (compte rendu) ---------- */
.report { background: #fff; color: #10183a; border-radius: 12px; overflow: hidden; max-width: 900px; margin: 0 auto; }
.report-head { background: #060b1a; padding: 20px 28px; display: flex; justify-content: space-between; align-items: center; gap: 20px; }
.report-head img { height: 70px; }
.report-head .doc { color: #fff; text-align: right; }
.report-head .doc .t { font-size: 18px; font-weight: 600; }
.report-head .doc .m { color: var(--cyan); text-transform: capitalize; }
.report-body { padding: 24px 28px; }
.report-body h3 { color: #0b3fae; margin: 22px 0 8px; font-size: 14px; text-transform: uppercase; letter-spacing: .05em; }
.report .parties { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; font-size: 13px; }
.report .parties .who { font-weight: 600; font-size: 14px; }
.report table th { color: #4a5a85; border-bottom: 2px solid #d7def0; }
.report table td { border-bottom: 1px solid #e6ebf6; }
.report tbody tr:hover { background: none; }
.report .summary { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.report .summary div { background: #f2f5fc; border-radius: 10px; padding: 10px 12px; }
.report .summary .l { font-size: 11px; color: #5a6a95; text-transform: uppercase; }
.report .summary .v { font-size: 18px; font-weight: 600; }
.report .summary .over { color: #d9304d; }
.report .legal { font-size: 11px; color: #5a6a95; margin-top: 24px; border-top: 1px solid #e6ebf6; padding-top: 12px; }

/* ---------- Connexion ---------- */
body.login-page { align-items: center; justify-content: center; min-height: 100vh; padding: 16px; }
.login-card { width: 100%; max-width: 400px; display: flex; flex-direction: column; gap: 14px; padding: 28px; }
.login-card h1 { font-size: 20px; text-align: center; }
.login-card > p { text-align: center; margin: 0 0 6px; }
.login-logo { width: 100%; border-radius: 10px; }
.login-alert { background: rgba(255,77,106,.12); border: 1px solid rgba(255,77,106,.4); color: #ffb3c0; padding: 10px 12px; border-radius: 10px; font-size: 13px; }
.side-user { margin-top: auto; display: flex; flex-direction: column; gap: 8px; align-items: stretch; font-size: 12px; color: var(--muted); text-align: center; word-break: break-all; }
.side-user + .side-foot { margin-top: 10px; }

/* ---------- Responsive ---------- */
@media (max-width: 860px) {
  body { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: static; flex-direction: row; align-items: center; padding: 10px 12px; gap: 12px; overflow-x: auto; }
  .brand img { width: 120px; }
  .sidebar nav { flex-direction: row; margin: 0; }
  .sidebar nav a { padding: 8px 10px; font-size: 13px; }
  .side-foot, #user-email { display: none; }
  .side-user { margin: 0 0 0 auto; }
  .view { padding: 20px 16px 50px; }
  .running-bar { padding: 8px 16px; }
  .client-head, .form-grid, .report .parties { grid-template-columns: 1fr; }
  .report .summary { grid-template-columns: 1fr 1fr; }
  .timer-box .clock { font-size: 36px; }
}

/* ---------- Impression ---------- */
@media print {
  body { background: #fff; display: block; }
  .sidebar, .running-bar, .no-print, .toasts { display: none !important; }
  .view { padding: 0; max-width: none; }
  .report { border-radius: 0; max-width: none; }
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
