/* =====================================================================
   Evidență Șoferi — stil
   ===================================================================== */

:root {
  --bg: #f3f5f9;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --text: #0f172a;
  --muted: #64748b;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-soft: #eff6ff;
  --on-primary: #ffffff;

  --danger: #dc2626;
  --danger-text: #b91c1c;
  --danger-soft: #fef2f2;
  --danger-border: #fecaca;
  --warn: #d97706;
  --warn-text: #92400e;
  --warn-soft: #fffbeb;
  --warn-border: #fde68a;
  --ok: #16a34a;
  --ok-text: #166534;
  --ok-soft: #f0fdf4;
  --ok-border: #bbf7d0;

  --dauna-text: #be123c;
  --dauna-soft: #ffe4e6;
  --datorie-text: #4338ca;
  --datorie-soft: #e0e7ff;
  --mentiune-text: #0f766e;
  --mentiune-soft: #ccfbf1;

  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgb(15 23 42 / 0.05), 0 2px 8px rgb(15 23 42 / 0.05);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1120;
    --surface: #111827;
    --surface-2: #0f172a;
    --border: #1f2a3c;
    --border-strong: #334155;
    --text: #e5e7eb;
    --muted: #94a3b8;
    --primary: #3b82f6;
    --primary-hover: #60a5fa;
    --primary-soft: #172554;

    --danger-text: #fca5a5;
    --danger-soft: #2a1215;
    --danger-border: #7f1d1d;
    --warn-text: #fcd34d;
    --warn-soft: #271c08;
    --warn-border: #78350f;
    --ok-text: #86efac;
    --ok-soft: #0c2414;
    --ok-border: #14532d;

    --dauna-text: #fda4af;
    --dauna-soft: #3b0d18;
    --datorie-text: #a5b4fc;
    --datorie-soft: #1e1b4b;
    --mentiune-text: #5eead4;
    --mentiune-soft: #042f2e;

    --shadow: 0 1px 2px rgb(0 0 0 / 0.4);
    color-scheme: dark;
  }
}

/* ---------- Bază ---------- */

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 var(--font);
  min-height: 100vh;
}

h1, h2 { margin: 0; line-height: 1.25; }
h1 { font-size: 1.6rem; font-weight: 700; letter-spacing: -0.01em; }
h2 { font-size: 1.1rem; font-weight: 650; }

a { color: var(--primary); }
p { margin: 0; }

[hidden] { display: none !important; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.muted { color: var(--muted); }
.small { font-size: 0.85em; }
.strong { font-weight: 600; }
.nowrap { white-space: nowrap; }
.upper { text-transform: uppercase; }

/* Ascunde conținutul până când autentificarea este verificată */
body.is-loading main { visibility: hidden; }
body.is-loading::after {
  content: "";
  position: fixed; top: 50%; left: 50%;
  width: 36px; height: 36px; margin: -18px 0 0 -18px;
  border: 3px solid var(--border-strong); border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Antet + meniu ---------- */

.topbar {
  position: sticky; top: 0; z-index: 20;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.topbar-inner, .tabs-inner {
  max-width: 1200px; margin: 0 auto; padding: 0 16px;
}
.topbar-inner {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  height: 56px;
}
.brand {
  display: flex; align-items: center; gap: 10px;
  font-weight: 700; font-size: 1.05rem; color: var(--text); text-decoration: none;
}
.topbar-actions { display: flex; gap: 4px; }

.tabs { border-top: 1px solid var(--border); }
.tabs-inner {
  display: flex; gap: 2px;
  overflow-x: auto; scrollbar-width: none;
}
.tabs-inner::-webkit-scrollbar { display: none; }
.tabs a {
  position: relative;
  display: flex; align-items: center; gap: 6px;
  padding: 12px 14px;
  color: var(--muted); text-decoration: none; font-weight: 550; white-space: nowrap;
  border-bottom: 2px solid transparent;
}
.tabs a:hover { color: var(--text); }
.tabs a.active { color: var(--primary); border-bottom-color: var(--primary); }

.nav-badge {
  min-width: 20px; height: 20px; padding: 0 6px;
  border-radius: 10px;
  background: var(--warn); color: #fff;
  font-size: 0.75rem; font-weight: 700; line-height: 20px; text-align: center;
}
.nav-badge-danger { background: var(--danger); }

/* ---------- Layout ---------- */

.container {
  max-width: 1200px; margin: 0 auto;
  padding: 24px 16px 48px;
  display: flex; flex-direction: column; gap: 20px;
}

.page-head {
  display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap;
}
.page-head p { margin-top: 4px; max-width: 70ch; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  display: flex; flex-direction: column; gap: 16px;
  min-width: 0;
}

.total-box {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 8px 14px; white-space: nowrap;
}

/* ---------- Butoane ---------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 40px; padding: 8px 16px;
  border: 1px solid transparent; border-radius: var(--radius-sm);
  font: inherit; font-weight: 600; text-decoration: none; white-space: nowrap;
  cursor: pointer;
  transition: background-color 0.15s, border-color 0.15s, color 0.15s;
}
.btn:disabled { opacity: 0.6; cursor: default; }
.btn-sm { min-height: 32px; padding: 4px 10px; font-size: 0.875rem; }
.btn-primary { background: var(--primary); color: var(--on-primary); }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-ghost { background: transparent; color: var(--text); border-color: var(--border); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-2); border-color: var(--border-strong); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { filter: brightness(0.92); }
.btn-danger-ghost { background: transparent; color: var(--danger-text); border-color: var(--danger-border); }
.btn-danger-ghost:hover:not(:disabled) { background: var(--danger-soft); }
.btn.is-busy { position: relative; color: transparent !important; }
.btn.is-busy::after {
  content: ""; position: absolute; width: 16px; height: 16px;
  border: 2px solid currentColor; border-color: var(--muted); border-top-color: transparent;
  border-radius: 50%; animation: spin 0.7s linear infinite;
}
.btn-row { display: flex; flex-wrap: wrap; gap: 6px; }

/* ---------- Formulare ---------- */

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px 16px;
}
.subgrid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px 16px;
  padding: 14px; border: 1px dashed var(--border-strong); border-radius: var(--radius-sm);
  background: var(--surface-2);
}
.span-all { grid-column: 1 / -1; }

.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > span { font-size: 0.875rem; font-weight: 600; }
.req { color: var(--danger); font-weight: 700; }

input, select, textarea {
  width: 100%;
  min-height: 40px;
  padding: 8px 12px;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  font: inherit;
}
textarea { resize: vertical; min-height: 64px; }
input:focus, select:focus, textarea:focus, .btn:focus-visible, .chip:focus-visible, .keypad button:focus-visible {
  outline: 2px solid var(--primary); outline-offset: 1px; border-color: var(--primary);
}
select:disabled, input:disabled { background: var(--surface-2); color: var(--muted); }
input.upper::placeholder { text-transform: none; }

.list-picker { display: flex; flex-direction: column; gap: 8px; }

.form-actions { display: flex; gap: 8px; justify-content: flex-end; }
.form-error {
  padding: 10px 12px; border-radius: var(--radius-sm);
  background: var(--danger-soft); color: var(--danger-text); border: 1px solid var(--danger-border);
  font-size: 0.9rem;
}
.hint {
  padding: 10px 12px; border-radius: var(--radius-sm);
  background: var(--warn-soft); color: var(--warn-text); border: 1px solid var(--warn-border);
}

/* ---------- Bara de filtre ---------- */

.toolbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
}
.toolbar-filters { display: flex; gap: 8px; flex-wrap: wrap; flex: 1 1 360px; justify-content: flex-end; }
.toolbar-filters select { width: auto; min-width: 160px; flex: 0 1 220px; }
.toolbar-filters input { flex: 1 1 200px; max-width: 320px; }

.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  min-height: 36px; padding: 6px 12px;
  border: 1px solid var(--border-strong); border-radius: 999px;
  background: var(--surface); color: var(--text);
  font: inherit; font-weight: 550; cursor: pointer;
}
.chip .count {
  min-width: 22px; padding: 0 6px; border-radius: 999px;
  background: var(--surface-2); color: var(--muted); font-size: 0.8rem; text-align: center;
}
.chip.active { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.chip.active .count { background: rgb(255 255 255 / 0.22); color: var(--on-primary); }

/* ---------- Alerte + statistici ---------- */

.alert {
  padding: 14px 16px; border-radius: var(--radius);
  font-weight: 600; border: 1px solid;
}
.alert-danger { background: var(--danger-soft); color: var(--danger-text); border-color: var(--danger-border); }
.alert-warn { background: var(--warn-soft); color: var(--warn-text); border-color: var(--warn-border); }
.alert-ok { background: var(--ok-soft); color: var(--ok-text); border-color: var(--ok-border); }

.stats {
  display: grid; gap: 12px;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}
.stat {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px 16px;
  display: flex; flex-direction: column; gap: 4px;
  border-left: 4px solid var(--border-strong);
}
.stat-label { color: var(--muted); font-size: 0.85rem; font-weight: 550; }
.stat strong { font-size: 1.5rem; font-variant-numeric: tabular-nums; }
.stat-overdue { border-left-color: var(--danger); }
.stat-overdue strong { color: var(--danger-text); }
.stat-soon { border-left-color: var(--warn); }
.stat-soon strong { color: var(--warn-text); }

/* ---------- Tabele ---------- */

.table-wrap { overflow-x: auto; margin: 0 -20px; padding: 0 20px; }
.table { width: 100%; border-collapse: collapse; }
.table th {
  text-align: left; font-size: 0.78rem; font-weight: 650; text-transform: uppercase; letter-spacing: 0.03em;
  color: var(--muted);
  padding: 8px 10px; border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.th-hint { text-transform: none; letter-spacing: 0; font-weight: 500; }
.table td { padding: 12px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: var(--surface-2); }
.num, .table th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table th.actions, .table td.actions { text-align: right; width: 1%; white-space: nowrap; }
.table td.actions .btn-row { justify-content: flex-end; flex-wrap: nowrap; }
.notes { white-space: pre-wrap; overflow-wrap: anywhere; min-width: 160px; max-width: 360px; }

.entries-table tbody tr { box-shadow: inset 4px 0 0 transparent; }
.entries-table tr.row-overdue { box-shadow: inset 4px 0 0 var(--danger); }
.entries-table tr.row-today, .entries-table tr.row-soon { box-shadow: inset 4px 0 0 var(--warn); }
.entries-table tr.row-later { box-shadow: inset 4px 0 0 var(--ok); }

.due { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; white-space: nowrap; }

.pill, .badge, .tag {
  display: inline-block; padding: 2px 8px; border-radius: 999px;
  font-size: 0.78rem; font-weight: 650; white-space: nowrap; line-height: 1.5;
}
.pill-overdue { background: var(--danger-soft); color: var(--danger-text); }
.pill-today, .pill-soon { background: var(--warn-soft); color: var(--warn-text); }
.pill-later { background: var(--ok-soft); color: var(--ok-text); }

.badge-dauna { background: var(--dauna-soft); color: var(--dauna-text); }
.badge-datorie { background: var(--datorie-soft); color: var(--datorie-text); }
.badge-mentiune { background: var(--mentiune-soft); color: var(--mentiune-text); }

.tag { background: var(--primary-soft); color: var(--primary); border-radius: 6px; margin-bottom: 2px; }
.tag-muted { background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); font-weight: 550; }

.plate {
  display: inline-block;
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
  font-weight: 700; letter-spacing: 0.04em;
  padding: 1px 6px; border: 1.5px solid var(--border-strong); border-radius: 4px;
  background: var(--surface); white-space: nowrap;
}

.vchips { display: flex; flex-wrap: wrap; gap: 6px; }
.vchip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 4px 3px 8px;
  border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface-2);
}
.vchip .plate { border: 0; padding: 0; background: none; }
.vchip-x {
  width: 24px; height: 24px; border: 0; border-radius: 6px;
  background: transparent; color: var(--muted); font-size: 1.1rem; line-height: 1; cursor: pointer;
}
.vchip-x:hover { background: var(--danger-soft); color: var(--danger-text); }

.inline-select { min-width: 180px; min-height: 34px; padding: 4px 8px; }

.empty { padding: 28px 8px; text-align: center; color: var(--muted); }
.empty.error { color: var(--danger-text); }

.legend { display: flex; flex-wrap: wrap; gap: 16px; color: var(--muted); font-size: 0.875rem; }
.legend-item { display: inline-flex; align-items: center; gap: 6px; }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.dot-overdue { background: var(--danger); }
.dot-soon { background: var(--warn); }
.dot-later { background: var(--ok); }

/* ---------- Tabele pe ecrane mici: carduri ---------- */

@media (max-width: 760px) {
  h1 { font-size: 1.35rem; }
  .card { padding: 16px; }
  .table-wrap { margin: 0; padding: 0; overflow: visible; }
  .table thead { display: none; }
  .table, .table tbody, .table tr, .table td { display: block; width: 100%; }
  .table tr {
    border: 1px solid var(--border); border-radius: var(--radius-sm);
    padding: 6px 12px; margin-bottom: 10px; background: var(--surface);
  }
  .table tbody tr:hover { background: var(--surface); }
  /* Eticheta în stânga (absolut), conținutul curge normal, aliniat la dreapta */
  .table td {
    position: relative;
    min-height: 38px;
    padding: 9px 0 9px 38%;
    border-bottom: 1px dashed var(--border);
    text-align: right;
    overflow-wrap: anywhere;
  }
  .table td::before {
    content: attr(data-label);
    position: absolute; left: 0; top: 10px; width: 36%;
    text-align: left;
    font-size: 0.72rem; font-weight: 650; text-transform: uppercase; letter-spacing: 0.03em; color: var(--muted);
  }
  .table td.actions { padding-left: 0; border-bottom: 0; }
  .table td.actions::before { content: none; }
  .table td.actions .btn-row { justify-content: flex-end; flex-wrap: wrap; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .stat { padding: 12px; }
  .stat strong { font-size: 1.2rem; }
  .table tbody tr:last-child td { border-bottom: 1px dashed var(--border); }
  .table tbody tr td:last-child { border-bottom: 0; }
  .num { text-align: right; }
  .notes { max-width: none; min-width: 0; }
  .due { align-items: flex-end; }
  .vchips { justify-content: flex-end; }
  .entries-table tr.row-overdue { box-shadow: inset 4px 0 0 var(--danger); }
  .inline-select { min-width: 0; }
  .toolbar-filters { flex-basis: 100%; }
  .toolbar-filters select, .toolbar-filters input { flex: 1 1 100%; max-width: none; }
  .topbar-actions .btn { padding: 4px 8px; }
  .brand span { font-size: 0.95rem; }
}

/* ---------- Dialoguri ---------- */

.dialog {
  width: min(480px, calc(100vw - 32px));
  padding: 0; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); color: var(--text);
  box-shadow: 0 20px 50px rgb(0 0 0 / 0.25);
}
.dialog::backdrop { background: rgb(15 23 42 / 0.5); }
.dialog form { display: flex; flex-direction: column; gap: 16px; padding: 20px; }
.dialog-body { display: flex; flex-direction: column; gap: 14px; }
.dialog-message { color: var(--muted); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }

/* ---------- Notificări ---------- */

#toasts {
  position: fixed; z-index: 100;
  left: 50%; bottom: 20px; transform: translateX(-50%);
  display: flex; flex-direction: column; gap: 8px; align-items: center;
  width: min(440px, calc(100vw - 32px));
  pointer-events: none;
}
.toast {
  width: 100%;
  padding: 12px 16px; border-radius: var(--radius-sm);
  background: #0f172a; color: #fff; font-weight: 550;
  box-shadow: 0 8px 24px rgb(0 0 0 / 0.25);
  border-left: 4px solid var(--ok);
  animation: toast-in 0.2s ease-out;
  transition: opacity 0.4s, transform 0.4s;
}
.toast-error { border-left-color: var(--danger); }
.toast.hide { opacity: 0; transform: translateY(8px); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

.fatal { max-width: 520px; margin: 40px auto; text-align: center; }
.fatal .form-actions { justify-content: center; }

/* ---------- Autentificare (PIN) ---------- */

.login-page {
  display: grid; place-items: center; padding: 24px 16px;
  background:
    radial-gradient(1200px 600px at 50% -10%, var(--primary-soft), transparent 60%),
    var(--bg);
}
.login-card {
  width: min(360px, 100%);
  background: var(--surface); border: 1px solid var(--border); border-radius: 20px;
  box-shadow: 0 10px 40px rgb(15 23 42 / 0.1);
  padding: 32px 24px 24px;
  display: flex; flex-direction: column; align-items: center; gap: 6px; text-align: center;
}
.login-logo { margin-bottom: 8px; }
.login-card h1 { font-size: 1.4rem; }
#pin-form { width: 100%; display: flex; flex-direction: column; align-items: center; gap: 16px; margin-top: 16px; }

.pin-dots { display: flex; gap: 14px; }
.pin-dots i {
  width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid var(--border-strong); background: transparent;
  transition: background-color 0.12s, border-color 0.12s, transform 0.12s;
}
.pin-dots i.filled { background: var(--primary); border-color: var(--primary); transform: scale(1.08); }
#pin-form.is-busy .pin-dots i { animation: pulse 0.8s ease-in-out infinite alternate; }
@keyframes pulse { to { opacity: 0.35; } }

.keypad {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; width: 100%;
}
.keypad button {
  height: 60px; border-radius: 14px;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
  font: 600 1.4rem/1 var(--font); cursor: pointer;
  transition: background-color 0.1s, transform 0.05s;
  touch-action: manipulation;            /* fără zoom la atingeri rapide */
  -webkit-tap-highlight-color: transparent;
  user-select: none; -webkit-user-select: none;
}
.keypad button:hover { background: var(--primary-soft); }
.keypad button:active { transform: scale(0.96); }
.keypad .key-muted { font-size: 1.1rem; color: var(--muted); }

.btn-block { width: 100%; min-height: 48px; }

.passkey-box { width: 100%; display: flex; flex-direction: column; gap: 12px; }
.sep { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 0.85rem; }
.sep::before, .sep::after { content: ""; flex: 1; height: 1px; background: var(--border); }

.fp-icon {
  width: 22px; height: 22px; flex: 0 0 auto;
  fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round;
}
.fp-icon-lg { width: 56px; height: 56px; color: var(--primary); stroke-width: 1.4; }

.passkey-offer {
  width: 100%; margin-top: 12px;
  display: flex; flex-direction: column; align-items: center; gap: 10px;
}
.passkey-offer h2 { font-size: 1.2rem; }
.passkey-offer p { margin-bottom: 6px; }

/* ---------- Setări ---------- */

.dialog-inner { display: flex; flex-direction: column; gap: 18px; padding: 20px; }
.settings-section {
  display: flex; flex-direction: column; gap: 10px;
  padding-top: 16px; border-top: 1px solid var(--border);
}
.settings-section h3 { margin: 0; font-size: 1rem; }
.device-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.device-list li {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface-2);
}

.shake { animation: shake 0.35s; }
@keyframes shake {
  20%, 60% { transform: translateX(-8px); }
  40%, 80% { transform: translateX(8px); }
}
