:root {
  --bg: #0f1115;
  --surface: #181b22;
  --surface-2: #20242d;
  --border: #2a2f3a;
  --text: #e6e8ec;
  --muted: #8b93a1;
  --primary: #3b82f6;
  --primary-hover: #2f6fe0;
  --danger: #ef4444;
  --success: #22c55e;
  --warning: #f59e0b;
  --radius: 10px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}
.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 13px; }

/* ---- Buttons ---- */
.btn {
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  padding: 8px 14px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 14px;
  transition: background .15s, border-color .15s;
}
.btn:hover { background: #283041; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn-ghost { background: transparent; }
.btn-danger { background: transparent; border-color: var(--danger); color: var(--danger); }
.btn-danger:hover { background: rgba(239,68,68,.12); }
.btn-block { width: 100%; }
.btn-sm { padding: 5px 10px; font-size: 13px; }
.btn-icon { padding: 5px 9px; font-size: 13px; line-height: 1; min-width: 30px; margin-left: 3px; }
.data-table td.cell-brand { max-width: 170px; overflow: hidden; text-overflow: ellipsis; }

/* ---- Login ---- */
.login-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px;
}
.login-card {
  width: 100%; max-width: 360px; background: var(--surface);
  border: 1px solid var(--border); border-radius: 16px; padding: 32px 28px;
  display: flex; flex-direction: column; gap: 12px; text-align: center;
}
.login-logo { font-size: 44px; }
.login-card h1 { font-size: 20px; }
.login-card input {
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 11px 13px; color: var(--text); font-size: 15px;
}
.login-card input:focus { outline: none; border-color: var(--primary); }
.login-card .btn { margin-top: 4px; }

.error-box { color: var(--danger); background: rgba(239,68,68,.1); border: 1px solid rgba(239,68,68,.3);
  border-radius: var(--radius); padding: 9px; font-size: 13px; }

/* ---- Topbar ---- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 20px; height: 56px; background: var(--surface);
  border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 10;
}
.topbar-left { display: flex; align-items: center; gap: 24px; }
.brand { font-weight: 600; }
.topbar-right { display: flex; align-items: center; gap: 14px; }
.who { color: var(--muted); font-size: 13px; }

.tabs { display: flex; gap: 4px; }
.tab {
  background: transparent; border: none; color: var(--muted);
  padding: 8px 14px; border-radius: var(--radius); cursor: pointer; font-size: 14px;
}
.tab:hover { color: var(--text); background: var(--surface-2); }
.tab.active { color: #fff; background: var(--primary); }

/* ---- Viewer banner ---- */
.viewer-banner {
  background: rgba(245,158,11,.12); border-bottom: 1px solid rgba(245,158,11,.35);
  color: var(--warning); padding: 9px 20px; font-size: 13px; text-align: center;
}

/* ---- Password generator row ---- */
.pass-row { display: flex; gap: 8px; align-items: center; }
.pass-row input {
  flex: 1; background: var(--surface-2); border: 1px solid var(--border); color: var(--text);
  border-radius: 8px; padding: 9px 11px; font-size: 15px; letter-spacing: .04em; font-family: ui-monospace, monospace;
}
.pass-row input:focus { outline: none; border-color: var(--primary); }

/* ---- Password cell in Доступи ---- */
.pass-cell { display: inline-flex; align-items: center; gap: 8px; }
.pass-mask {
  cursor: pointer; user-select: none; font-family: ui-monospace, monospace;
  letter-spacing: .08em; padding: 2px 8px; border-radius: 6px;
  background: var(--surface-2); border: 1px solid var(--border); min-width: 84px; display: inline-block;
}
.pass-mask:hover { border-color: var(--primary); }
.pass-static {
  font-family: ui-monospace, monospace; letter-spacing: .08em; color: var(--muted);
  padding: 2px 8px; border-radius: 6px; background: var(--surface-2); border: 1px solid var(--border);
  user-select: none;
}

/* ---- Content ---- */
.content { padding: 24px; max-width: 1400px; margin: 0 auto; }
.panel-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; gap: 12px; }
.panel-head h2 { font-size: 18px; }

/* ---- Table ---- */
.table-scroll { overflow: auto; max-height: calc(100vh - 210px); border: 1px solid var(--border); border-radius: var(--radius); }
.data-table { width: 100%; border-collapse: collapse; min-width: 720px; }
.data-table th, .data-table td { padding: 9px 10px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
.data-table th {
  background: var(--surface); color: var(--muted); font-weight: 500; font-size: 12px;
  text-transform: uppercase; letter-spacing: .03em;
  position: sticky; top: 0; z-index: 5; box-shadow: inset 0 -1px 0 var(--border);
}
.data-table tbody tr:hover { background: var(--surface); }
.data-table td.actions { text-align: right; }
.data-table .empty { text-align: center; color: var(--muted); padding: 30px; }

.tag { display: inline-block; padding: 2px 9px; border-radius: 20px; font-size: 12px; background: var(--surface-2); border: 1px solid var(--border); }
.tag-none { color: var(--warning); border-color: rgba(245,158,11,.4); }

.mileage-val { font-variant-numeric: tabular-nums; font-weight: 600; }

/* ---- ТО toolbar / status ---- */
.toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 14px; flex-wrap: wrap; }
.toolbar-search {
  flex: 1; min-width: 220px; background: var(--surface-2); border: 1px solid var(--border);
  color: var(--text); border-radius: var(--radius); padding: 9px 12px; font-size: 14px;
}
.toolbar-search:focus { outline: none; border-color: var(--primary); }
.toolbar-select {
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text);
  border-radius: var(--radius); padding: 9px 12px; font-size: 14px;
}
.toolbar-select:focus { outline: none; border-color: var(--primary); }
.legend { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12px; }
.legend-dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; margin-left: 6px; }
.dot-soon { background: var(--warning); }
.dot-due { background: var(--danger); }

.row-soon { background: rgba(245,158,11,.10); box-shadow: inset 3px 0 0 var(--warning); }
.row-soon:hover { background: rgba(245,158,11,.16); }
.row-due { background: rgba(239,68,68,.12); box-shadow: inset 3px 0 0 var(--danger); }
.row-due:hover { background: rgba(239,68,68,.18); }
.rem-soon { color: var(--warning); font-weight: 600; }
.rem-due { color: var(--danger); font-weight: 600; }
.rem-ok { color: var(--success); font-weight: 600; }
.to-preview {
  padding: 11px 13px; border-radius: var(--radius); font-size: 14px;
  background: var(--surface-2); border: 1px solid var(--border); text-align: center;
}
.btn-ok { background: var(--success); border-color: var(--success); color: #08210f; font-weight: 600; }
.btn-ok:hover { background: #1aa64f; border-color: #1aa64f; }

.clickable-row { cursor: pointer; }

/* ---- Subdivision: submitted / pending rows ---- */
.row-submitted { background: rgba(34,197,94,.09); box-shadow: inset 3px 0 0 var(--success); }
.row-pending { box-shadow: inset 3px 0 0 var(--warning); }
.badge-done {
  display: inline-block; background: var(--success); color: #08210f; font-weight: 700;
  width: 18px; height: 18px; line-height: 18px; text-align: center; border-radius: 50%; font-size: 12px;
}
.rel-time { color: var(--muted); font-size: 13px; }
.row-submitted .rel-time { color: var(--success); }

/* ---- Vehicle details / timeline ---- */
.veh-summary { display: flex; flex-direction: column; gap: 6px; font-size: 14px; }
.veh-summary .muted { display: inline-block; min-width: 130px; }
.timeline { display: flex; flex-direction: column; gap: 2px; max-height: 46vh; overflow-y: auto; overflow-x: hidden; padding-right: 6px; }
.timeline::-webkit-scrollbar { width: 9px; }
.timeline::-webkit-scrollbar-track { background: transparent; }
.timeline::-webkit-scrollbar-thumb { background: var(--border); border-radius: 8px; border: 2px solid var(--surface); }
.timeline::-webkit-scrollbar-thumb:hover { background: #3a4150; }
.tl-item { display: flex; gap: 11px; padding: 9px 4px; border-bottom: 1px solid var(--border); }
.tl-item:last-child { border-bottom: none; }
.tl-icon { font-size: 16px; line-height: 1.4; width: 22px; text-align: center; flex-shrink: 0; }
.tl-body { display: flex; flex-direction: column; gap: 2px; }
.tl-val { color: var(--text); font-variant-numeric: tabular-nums; }
.tl-meta { font-size: 12px; color: var(--muted); }

.form-sep {
  margin: 6px 0 -2px; padding-top: 12px; border-top: 1px solid var(--border);
  color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em;
}

/* ---- Subdivision window banner ---- */
.window-banner { grid-column: 1 / -1; padding: 11px 14px; border-radius: var(--radius); font-size: 14px; border: 1px solid var(--border); }
.window-banner.open { color: var(--success); background: rgba(34,197,94,.10); border-color: rgba(34,197,94,.35); }
.window-banner.closed { color: var(--warning); background: rgba(245,158,11,.10); border-color: rgba(245,158,11,.35); }

/* inline select in table */
.inline-select {
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text);
  border-radius: 8px; padding: 5px 7px; font-size: 13px; max-width: 150px;
}
.inline-select:focus { outline: none; border-color: var(--primary); }

/* ---- Cards (subdivision view) ---- */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; }
.car-card { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 18px; }
.car-card h3 { font-size: 16px; margin-bottom: 4px; }
.car-card .plate { display: inline-block; background: var(--surface-2); border: 1px solid var(--border); border-radius: 6px; padding: 2px 8px; font-weight: 600; letter-spacing: .05em; margin: 6px 0; }
.car-card .vin { color: var(--muted); font-size: 12px; word-break: break-all; }
.car-card .mileage-row { display: flex; align-items: center; gap: 8px; margin-top: 14px; }
.car-card .mileage-row input { flex: 1; background: var(--surface-2); border: 1px solid var(--border); color: var(--text); border-radius: 8px; padding: 9px 11px; font-size: 15px; font-variant-numeric: tabular-nums; }
.car-card .mileage-row input:focus { outline: none; border-color: var(--primary); }
.car-card .current { font-size: 12px; color: var(--muted); margin-top: 8px; }

/* поле вводу пробігу в таблиці підрозділу — єдиний input-group */
.mileage-row {
  display: inline-flex; align-items: stretch;
  border: 1.5px solid var(--border); border-radius: 11px; overflow: hidden;
  background: var(--surface-2); transition: border-color .15s, box-shadow .15s; width: max-content;
}
.mileage-row:hover { border-color: #3a4150; }
.mileage-row:focus-within { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(59,130,246,.22); }
.mileage-row input {
  border: none; outline: none; background: transparent; color: var(--text);
  width: 96px; padding: 9px 2px 9px 13px; font-size: 15px; font-weight: 700;
  font-variant-numeric: tabular-nums; letter-spacing: .4px; text-align: left;
}
.mileage-row input::placeholder { color: var(--muted); font-weight: 400; letter-spacing: 0; }
.mileage-unit {
  display: flex; align-items: center; padding: 0 12px 0 2px;
  color: var(--muted); font-size: 13px; font-weight: 500; user-select: none;
}
.mileage-row .btn {
  border: none; border-left: 1.5px solid var(--border); border-radius: 0;
  font-weight: 600; padding-left: 16px; padding-right: 16px; box-shadow: none;
}
.mileage-row .btn:hover { filter: brightness(1.1); }

/* ---- Modal ---- */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 20px; }
.modal { background: var(--surface); border: 1px solid var(--border); border-radius: 16px; width: 100%; max-width: 480px; max-height: 90vh; overflow: auto; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 20px; border-bottom: 1px solid var(--border); }
.modal-head h3 { font-size: 17px; }
.modal-body { padding: 20px; display: flex; flex-direction: column; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field label { font-size: 13px; color: var(--muted); }
.field input, .field select, .field textarea {
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text);
  border-radius: 8px; padding: 9px 11px; font-size: 14px; font-family: inherit;
}
.field input:focus, .field select:focus, .field textarea:focus { outline: none; border-color: var(--primary); }
.field-row { display: flex; gap: 12px; }
.field-row .field { flex: 1; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 6px; }

/* ---- Toast ---- */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text);
  padding: 12px 18px; border-radius: var(--radius); z-index: 100; box-shadow: 0 8px 24px rgba(0,0,0,.4);
}
.toast.success { border-color: rgba(34,197,94,.5); }
.toast.error { border-color: rgba(239,68,68,.5); }

/* ---- Інтро / завантаження ---- */
.intro-overlay {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(8, 10, 14, .92); backdrop-filter: blur(6px);
  display: flex; align-items: center; justify-content: center;
  animation: intro-fade .35s ease;
}
@keyframes intro-fade { from { opacity: 0; } to { opacity: 1; } }
.intro-box { display: flex; flex-direction: column; align-items: center; gap: 22px; }
.intro-video {
  width: min(50vw, 720px); height: auto; max-height: 64vh;
  border-radius: 18px; box-shadow: 0 20px 60px rgba(0,0,0,.55);
  background: #000; object-fit: contain;
}
.intro-foot { display: flex; align-items: center; gap: 12px; color: var(--text); }
.intro-text { font-size: 15px; letter-spacing: .02em; color: var(--muted); }
.intro-spinner {
  width: 26px; height: 26px; border-radius: 50%;
  border: 3px solid rgba(255,255,255,.18); border-top-color: var(--primary);
  animation: intro-spin .8s linear infinite;
}
@keyframes intro-spin { to { transform: rotate(360deg); } }
@media (max-width: 640px) {
  .intro-video { width: 86vw; }
}

@media (max-width: 640px) {
  .tabs { display: none; }
  .content { padding: 14px; }
}
