/*
  Styles of the management panel. Hebrew, right-to-left, phone first.
  No inline styles are possible (Content-Security-Policy), so pages are built from these classes:

  Page          .page-head (.page-title .page-subtitle .page-actions) · .section-title · .tabs > .tab(.active)
  Layout        .grid (.grid-2 .grid-3 .grid-stats) · .stack · .row
  Card          .card (.card-head .card-title .card-note .card-link .card-foot) · .card-danger
  Numbers       .stat (.stat-label .stat-value .stat-sub .stat-link) · .delta.delta-up / .delta-down
  Tables        .table-wrap > table.table (+ .table-stack: rows become cards on a phone; give every
                <td> a data-label="כותרת") · .table-compact · td.num · td.actions · td.center
  Forms         .form · .field (.field-label .input .field-error .field-help) · .check · .form-actions
                .form-row (fields side by side) · .filters (a row of filter fields above a list)
  Buttons       .btn (+ .btn-primary .btn-danger .btn-ghost .btn-sm .btn-block) · .inline-form
  Messages      .flash (.flash-ok .flash-error .flash-warn) · .badge (.badge-ok -warn -error -info -muted)
  Lists         .empty (.empty-text .empty-hint) · .pagination · .dl (definition list of label / value)
  Bits          .plate · .thumb · .muted · .small · .strong · .nowrap · .num · .sr-only · [dir=ltr]
*/

:root {
  --bg: #f3f5f8;
  --surface: #ffffff;
  --surface-2: #f7f9fb;
  --border: #e2e7ee;
  --border-strong: #c5ced9;
  --text: #17202e;
  --text-2: #4a5567;
  --text-3: #6d7889;
  --accent: #2468c9;
  --accent-strong: #1a4f9e;
  --accent-soft: #e9f1fc;
  --on-accent: #ffffff;
  --ok: #17753a;
  --ok-soft: #e5f4ea;
  --warn: #8a5300;
  --warn-soft: #fff3d9;
  --error: #b3261e;
  --error-soft: #fdeceb;
  --plate: #ffd43b;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(23, 32, 46, .05), 0 1px 3px rgba(23, 32, 46, .07);
  --shadow-lg: 0 10px 30px rgba(23, 32, 46, .18);
  --gap: 16px;
  --nav-width: 232px;
  --topbar-height: 56px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans Hebrew", "Heebo", "Arimo", Arial, sans-serif;
}

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

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
}

h1, h2, h3, p, ul, ol, dl, dd, figure { margin: 0; }
ul, ol { padding: 0; list-style: none; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
img, svg { max-width: 100%; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }

.sr-only {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.skip-link { position: absolute; inset-inline-start: 8px; top: -60px; z-index: 100; padding: 8px 12px;
  background: var(--surface); border-radius: var(--radius-sm); box-shadow: var(--shadow-lg); }
.skip-link:focus { top: 8px; }

.muted { color: var(--text-3); }
.small { font-size: 13px; }
.strong { font-weight: 600; }
.nowrap { white-space: nowrap; }
.center { text-align: center; }
.text-start { text-align: start; }
[dir="ltr"] { unicode-bidi: isolate; }
.icon { flex: none; vertical-align: -4px; }

/* ------------------------------------------------------------------ frame */
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 12px;
  height: var(--topbar-height); padding: 0 16px;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand {
  font-size: 17px; font-weight: 700; color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0;
}
.brand:hover { text-decoration: none; color: var(--accent); }
.topbar-user { margin-inline-start: auto; display: flex; align-items: center; gap: 4px; min-width: 0; }
.user-chip {
  display: flex; align-items: center; gap: 8px; min-width: 0;
  padding: 4px 10px; border-radius: var(--radius-sm); color: var(--text);
}
.user-chip:hover { background: var(--surface-2); text-decoration: none; }
.user-chip .icon { color: var(--text-3); }
.user-chip-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.25; }
.user-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 22ch; }
.user-role { font-size: 12px; color: var(--text-3); white-space: nowrap; }
.logout-btn { gap: 6px; }

.nav-toggle {
  display: none; align-items: center; justify-content: center;
  width: 40px; height: 40px; margin-inline-start: -8px;
  border: 0; border-radius: var(--radius-sm); background: none; color: var(--text); cursor: pointer;
}
.nav-toggle:hover { background: var(--surface-2); }

.shell { display: flex; align-items: flex-start; }
.sidenav {
  position: sticky; top: var(--topbar-height); flex: none;
  width: var(--nav-width); height: calc(100vh - var(--topbar-height)); overflow-y: auto;
  padding: 12px; background: var(--surface); border-inline-end: 1px solid var(--border);
}
.nav-list { display: flex; flex-direction: column; gap: 2px; }
.nav-link {
  display: flex; align-items: center; gap: 12px;
  min-height: 42px; padding: 8px 12px; border-radius: var(--radius-sm);
  color: var(--text-2); font-weight: 500;
}
.nav-link:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav-link.active { background: var(--accent-soft); color: var(--accent-strong); font-weight: 600; }
.nav-label { flex: 1; min-width: 0; }
.nav-badge {
  min-width: 22px; padding: 1px 7px; border-radius: 999px;
  background: var(--warn-soft); color: var(--warn); font-size: 12px; font-weight: 700; text-align: center;
}
.nav-backdrop { display: none; }

.main { flex: 1; min-width: 0; padding: 24px; }
.main-inner { max-width: 1180px; margin-inline: auto; }
.main-inner > * + *, .public > * + * { margin-top: var(--gap); }

.public {
  min-height: 100vh; padding: 24px 16px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
}
.public > * { width: 100%; max-width: 400px; }

/* ------------------------------------------------------------------- page */
.page-head { display: flex; flex-wrap: wrap; align-items: center; gap: 12px 16px; }
.page-head-text { flex: 1; min-width: 200px; }
.page-title { font-size: 24px; line-height: 1.25; font-weight: 700; }
.page-subtitle { color: var(--text-3); }
.page-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.section-title { font-size: 14px; font-weight: 600; color: var(--text-2); margin-top: 24px !important; }
.sub-title { font-size: 15px; font-weight: 600; }

.tabs { display: flex; gap: 4px; overflow-x: auto; border-bottom: 1px solid var(--border); }
.tab {
  padding: 10px 14px; margin-bottom: -1px; border-bottom: 2px solid transparent;
  color: var(--text-2); font-weight: 500; white-space: nowrap;
}
.tab:hover { color: var(--text); text-decoration: none; }
.tab.active { color: var(--accent-strong); border-bottom-color: var(--accent); font-weight: 600; }

/* ----------------------------------------------------------------- layout */
.grid { display: grid; gap: var(--gap); grid-template-columns: minmax(0, 1fr); }
.grid-stats { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.stack { display: flex; flex-direction: column; gap: var(--gap); min-width: 0; }
.row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px; min-width: 0;
}
.card > * + * { margin-top: 12px; }
.card-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 12px; }
.card-title { font-size: 16px; font-weight: 700; }
.card-note { color: var(--text-3); font-size: 13px; }
.card-link { font-size: 13px; font-weight: 600; }
.card-foot { font-size: 13px; }
.card-danger { border-color: #efc9c6; }

/* ---------------------------------------------------------------- numbers */
.stat > * + * { margin-top: 4px; }
.stat-label { color: var(--text-2); font-size: 13px; font-weight: 500; }
.stat-value { font-size: 30px; line-height: 1.2; font-weight: 700; letter-spacing: -.01em; }
.stat-sub { color: var(--text-3); font-size: 13px; }
.stat-delta { font-size: 13px; }
.stat-link { display: inline-block; font-size: 13px; font-weight: 600; }
.stat-warn { border-color: #f0d9a8; background: #fffbf1; }
.delta { font-weight: 700; white-space: nowrap; }
.delta-up { color: var(--ok); }
.delta-down { color: var(--error); }

/* ----------------------------------------------------------------- tables */
.table-wrap { overflow-x: auto; margin-inline: -16px; padding-inline: 16px; }
.table { width: 100%; border-collapse: collapse; }
.table th {
  padding: 8px 12px; text-align: start; white-space: nowrap;
  color: var(--text-3); font-size: 12.5px; font-weight: 600; border-bottom: 1px solid var(--border);
}
.table td { padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: var(--surface-2); }
.table th:first-child, .table td:first-child { padding-inline-start: 4px; }
.table th:last-child, .table td:last-child { padding-inline-end: 4px; }
.table-compact td { padding-block: 7px; }
.table .num, .num { text-align: end; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table .center { text-align: center; }
.table .actions { text-align: end; white-space: nowrap; }
.table .actions > * + * { margin-inline-start: 6px; }
.matrix .yes { color: var(--ok); }
.matrix .no { color: var(--text-3); }
.detail-list { display: flex; flex-wrap: wrap; gap: 2px 14px; font-size: 13px; }

/* ------------------------------------------------------------------ forms */
.form { display: flex; flex-direction: column; gap: 14px; max-width: 520px; }
.form-row { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.form-inline { flex-direction: row; flex-wrap: wrap; align-items: flex-end; max-width: none; }
.form-inline .field { flex: 1; min-width: 180px; }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field-label { font-size: 13.5px; font-weight: 600; color: var(--text-2); }
.req { color: var(--error); }
.input, input[type="text"], input[type="search"], input[type="number"], input[type="password"], input[type="email"],
input[type="tel"], input[type="date"], input[type="time"], input[type="month"], input[type="url"], input[type="file"],
select, textarea {
  width: 100%; min-height: 42px; padding: 8px 12px;
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text);
  font: inherit; font-size: 16px;   /* 16px keeps phones from zooming into the field */
}
textarea { min-height: 84px; resize: vertical; }
select { padding-inline-end: 8px; }
.input:focus, input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--accent-soft); outline-offset: 0; border-color: var(--accent);
}
.input:disabled, input:disabled, select:disabled, textarea:disabled { background: var(--surface-2); color: var(--text-3); }
.has-error .input, .input[aria-invalid="true"] { border-color: var(--error); }
.field-error { color: var(--error); font-size: 13px; font-weight: 600; }
.field-help { color: var(--text-3); font-size: 13px; }
.check { display: flex; align-items: center; gap: 10px; min-height: 32px; font-weight: 500; cursor: pointer; }
.check input, input[type="checkbox"], input[type="radio"] { width: 18px; height: 18px; flex: none; accent-color: var(--accent); }
.form-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.inline-form { display: inline-flex; margin: 0; }
.filters { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 10px 12px; }
.filters .field { flex: 0 1 220px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 42px; padding: 8px 16px;
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text);
  font: inherit; font-weight: 600; line-height: 1.2; white-space: nowrap; cursor: pointer;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn .icon { width: 18px; height: 18px; vertical-align: middle; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn-primary:hover { background: var(--accent-strong); border-color: var(--accent-strong); }
.btn-danger { border-color: #e2a8a4; color: var(--error); }
.btn-danger:hover { background: var(--error-soft); }
.btn-ghost { border-color: transparent; background: none; color: var(--text-2); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-sm { min-height: 34px; padding: 5px 12px; font-size: 13.5px; }
.btn-block { width: 100%; }
.btn:disabled, .btn.is-disabled { opacity: .5; cursor: default; pointer-events: none; }
.btn.is-busy { opacity: .7; pointer-events: none; }

/* --------------------------------------------------------------- messages */
.flashes { display: flex; flex-direction: column; gap: 8px; }
.flash {
  display: flex; align-items: flex-start; gap: 12px; padding: 10px 14px;
  border: 1px solid; border-radius: var(--radius-sm); font-weight: 500;
}
.flash-text { flex: 1; min-width: 0; }
.flash-ok { background: var(--ok-soft); border-color: #b9dfc6; color: #0f5a2b; }
.flash-error { background: var(--error-soft); border-color: #f1c1bd; color: #8c1d18; }
.flash-warn { background: var(--warn-soft); border-color: #f0d9a8; color: #6b4000; }
.flash-close {
  flex: none; width: 24px; height: 24px; margin-inline-end: -4px;
  border: 0; border-radius: 6px; background: none; color: inherit; font-size: 20px; line-height: 1; cursor: pointer;
}
.flash-close:hover { background: rgba(0, 0, 0, .07); }
html:not(.js) .flash-close { display: none; }

.badge {
  display: inline-block; padding: 2px 9px; border-radius: 999px;
  font-size: 12.5px; font-weight: 600; white-space: nowrap;
  background: #edf0f4; color: var(--text-2);
}
.badge-ok { background: var(--ok-soft); color: var(--ok); }
.badge-warn { background: var(--warn-soft); color: var(--warn); }
.badge-error { background: var(--error-soft); color: var(--error); }
.badge-info { background: var(--accent-soft); color: var(--accent-strong); }

.empty { padding: 28px 16px; text-align: center; }
.empty > * + * { margin-top: 6px; }
.empty-text { font-weight: 600; color: var(--text-2); }
.empty-hint { color: var(--text-3); font-size: 13.5px; }
.empty-action { margin-top: 14px; }

.pagination { display: flex; align-items: center; justify-content: center; gap: 12px; padding-top: 4px; }
.pagination-status { color: var(--text-2); font-size: 13.5px; }

.dl > div {
  display: flex; flex-wrap: wrap; justify-content: space-between; gap: 2px 16px;
  padding: 8px 0; border-bottom: 1px solid var(--border);
}
.dl > div:last-child { border-bottom: 0; }
.dl dt { color: var(--text-3); }
.dl dd { font-weight: 500; text-align: end; min-width: 0; overflow-wrap: anywhere; }
.role-notes > div { padding: 6px 0; }
.role-notes dt { font-weight: 700; }
.role-notes dd { color: var(--text-2); }

/* ------------------------------------------------------------------- bits */
.plate {
  display: inline-block; padding: 1px 8px; border: 1px solid rgba(0, 0, 0, .35); border-radius: 5px;
  background: var(--plate); color: #111; font-weight: 700; font-variant-numeric: tabular-nums;
  letter-spacing: .02em; white-space: nowrap;
}
.thumb {
  flex: none; width: 64px; height: 48px; border-radius: 6px; object-fit: cover;
  background: var(--surface-2); border: 1px solid var(--border);
}
.thumb-empty { display: inline-flex; align-items: center; justify-content: center; color: var(--border-strong); }

.wash-list > li + li { border-top: 1px solid var(--border); }
.wash-row { display: flex; align-items: center; gap: 12px; padding: 10px 4px; color: inherit; border-radius: var(--radius-sm); }
.wash-row:hover { background: var(--surface-2); text-decoration: none; }
.wash-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.wash-line { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.wash-line.muted { white-space: normal; font-size: 13.5px; }
.wash-vehicle { font-weight: 500; }
.wash-side { flex: none; display: flex; flex-direction: column; align-items: flex-end; gap: 2px; }

/* ------------------------------------------------------------------ chart */
.chart { display: grid; grid-template-columns: auto minmax(0, 1fr); column-gap: 8px; }
.chart-y {
  display: flex; flex-direction: column; justify-content: space-between; height: 160px;
  color: var(--text-3); font-size: 11.5px; font-variant-numeric: tabular-nums; text-align: end;
}
.chart-y span { height: 0; line-height: 0; }
.chart-main { min-width: 0; }
.chart-svg { display: block; width: 100%; height: 160px; overflow: visible; }
.chart-grid { stroke: var(--border); stroke-width: 1; vector-effect: non-scaling-stroke; shape-rendering: crispEdges; }
.chart-base { stroke: var(--border-strong); }
.chart-bar { fill: var(--accent); }
.chart-hit { fill: transparent; }
.chart-slot { outline: none; cursor: default; }
.chart-slot:hover .chart-bar, .chart-slot:focus .chart-bar { fill: var(--accent-strong); }
.chart-slot:hover .chart-hit, .chart-slot:focus .chart-hit { fill: var(--accent-soft); }
.chart-x {
  display: grid; grid-template-columns: repeat(30, minmax(0, 1fr)); margin-top: 6px; height: 16px;
  color: var(--text-3); font-size: 11.5px; font-variant-numeric: tabular-nums;
}
.chart-x span { display: flex; justify-content: center; white-space: nowrap; }
.chart-data summary { cursor: pointer; color: var(--text-2); font-size: 13px; font-weight: 600; }
.chart-data[open] summary { margin-bottom: 8px; }
.chart-tip {
  position: fixed; z-index: 50; top: 0; left: 0; pointer-events: none;
  padding: 6px 10px; border-radius: var(--radius-sm);
  background: var(--text); color: #fff; box-shadow: var(--shadow-lg);
  font-size: 13px; line-height: 1.35; text-align: center; white-space: nowrap;
}
.chart-tip strong { display: block; font-size: 14px; }
.chart-tip span { display: block; opacity: .8; }

/* ---------------------------------------------------- sign-in and errors */
.auth-card { padding: 28px 24px; }
.auth-card > * + * { margin-top: 18px; }
.auth-brand { text-align: center; }
.auth-logo {
  display: inline-flex; align-items: center; justify-content: center; width: 52px; height: 52px;
  border-radius: 50%; background: var(--accent-soft); color: var(--accent);
}
.auth-logo .icon { width: 26px; height: 26px; vertical-align: middle; }
.auth-title { margin-top: 10px; font-size: 22px; font-weight: 700; }
.auth-subtitle { color: var(--text-3); }
.auth-card .form { max-width: none; }

.error-page { padding: 36px 24px; text-align: center; max-width: 520px; margin-inline: auto; }
.error-page > * + * { margin-top: 10px; }
.error-code { font-size: 56px; line-height: 1; font-weight: 800; color: var(--border-strong); }
.error-title { font-size: 22px; font-weight: 700; }
.error-message { color: var(--text-2); }
.error-actions { margin-top: 20px; }
.lookup-result > * + * { margin-top: 8px; }

/* --------------------------------------------------------------- desktop */
@media (min-width: 900px) {
  .grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: start; }
  .grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); align-items: start; }
}

/* ----------------------------------------------------------------- phone */
@media (max-width: 899px) {
  .main { padding: 16px 12px 32px; }
  .page-title { font-size: 21px; }
  .nav-toggle { display: inline-flex; }
  .topbar-user { flex: none; }
  .user-chip { padding-inline: 6px; }
  .user-role { display: none; }
  .user-name { max-width: 9ch; }
  .logout-text { display: none; }
  .btn { min-height: 44px; }
  .btn-sm { min-height: 38px; }

  /* without JavaScript the menu simply sits on top of the page */
  .shell { display: block; }
  .sidenav { position: static; width: auto; height: auto; border-inline-end: 0; border-bottom: 1px solid var(--border); }
  .nav-list { flex-direction: row; flex-wrap: wrap; }
  html:not(.js) .nav-toggle { display: none; }

  /* with JavaScript it is a drawer opened by the menu button */
  .js .sidenav {
    position: fixed; z-index: 40; top: var(--topbar-height); bottom: 0; inset-inline-start: 0;
    width: min(82vw, 300px); height: auto; border-bottom: 0; border-inline-end: 1px solid var(--border);
    box-shadow: var(--shadow-lg); visibility: hidden; transform: translateX(100%);
    transition: transform .18s ease, visibility .18s;
  }
  .js .nav-list { flex-direction: column; flex-wrap: nowrap; }
  .js .nav-link { min-height: 48px; font-size: 16px; }
  .js.nav-open .sidenav { visibility: visible; transform: none; }
  .js.nav-open .nav-backdrop {
    display: block; position: fixed; z-index: 35; inset: var(--topbar-height) 0 0 0; background: rgba(23, 32, 46, .4);
  }
}

@media (max-width: 720px) {
  .stat-value { font-size: 26px; }

  /* tables marked .table-stack turn into a list of cards */
  .table-stack thead { display: none; }
  .table-stack, .table-stack tbody, .table-stack tr, .table-stack td { display: block; width: 100%; }
  .table-stack tr { padding: 10px 0; border-bottom: 1px solid var(--border); }
  .table-stack tbody tr:last-child { border-bottom: 0; }
  .table-stack tbody tr:hover { background: none; }
  .table-stack td {
    display: flex; justify-content: space-between; align-items: baseline; gap: 16px;
    padding: 3px 4px; border: 0; text-align: end; white-space: normal;
  }
  .table-stack td::before {
    content: attr(data-label); flex: none; color: var(--text-3); font-size: 13px; font-weight: 500; text-align: start;
  }
  .table-stack td:not([data-label])::before { content: none; }
  .table-stack td.actions { justify-content: flex-start; padding-top: 8px; }
  .table-stack td:empty { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .js .sidenav { transition: none; }
}

@media print {
  .topbar, .sidenav, .nav-backdrop, .flashes, .page-actions, .btn, .pagination { display: none !important; }
  body { background: #fff; }
  .main { padding: 0; }
  .card { box-shadow: none; break-inside: avoid; }
}
