:root {
  --bg: #0A0A0A;
  --surface: #161616;
  --surface-2: #1f1f1f;
  --border: #2a2a2a;
  --gold: #D4AF37;
  --yellow: #FFC928;
  --ivory: #F5F0E1;
  --muted: #a39d8c;
  --danger: #e5484d;
  --ok: #3ccf7a;
  --radius: 10px;
  --font: "Segoe UI", Tahoma, "Noto Sans Arabic", "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--ivory);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.45;
  min-height: 100vh;
}
[hidden] { display: none !important; }
h1, h2, h3 { color: var(--gold); font-weight: 600; margin: 0 0 12px; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1.05rem; }
a { color: var(--yellow); }
code { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 0.85em; word-break: break-all; }
p { margin: 0 0 10px; }

/* ---------- top bar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--gold);
  position: sticky; top: 0; z-index: 20;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark { width: 44px; height: 44px; border-radius: 50%; display: block; }
.brand-name { font-weight: 700; color: var(--gold); letter-spacing: 0.02em; }
.brand-sub { color: var(--muted); font-size: 0.85rem; }
.topbar-right { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.user-info { display: flex; align-items: center; gap: 8px; }
.user-phone { font-size: 0.9rem; color: var(--ivory); }
.top-tools { display: flex; gap: 6px; }

main { padding: 16px; max-width: 1280px; margin: 0 auto; }

/* ---------- tabs ---------- */
.tabs {
  display: flex; gap: 4px; overflow-x: auto; border-bottom: 1px solid var(--border); margin-bottom: 16px;
  scrollbar-width: thin;
}
.tab {
  padding: 10px 14px; color: var(--muted); text-decoration: none; white-space: nowrap;
  border-bottom: 2px solid transparent; font-weight: 500;
}
.tab:hover { color: var(--ivory); }
.tab.active { color: var(--gold); border-bottom-color: var(--gold); }

/* ---------- cards and layout ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; margin-bottom: 16px;
}
.auth-card { max-width: 420px; margin: 40px auto; background: var(--surface); border: 1px solid var(--gold); border-radius: var(--radius); padding: 24px; }
.auth-card .btn { width: 100%; margin-top: 8px; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row > input, .row > select { flex: 1 1 140px; min-width: 0; }
.row.wrap { flex-wrap: wrap; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.toolbar { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; margin-bottom: 16px; }
.toolbar .field { margin: 0; min-width: 160px; }
.actions { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.empty, .hint { color: var(--muted); font-size: 0.9rem; }
.error { color: var(--danger); font-size: 0.9rem; }

/* ---------- forms ---------- */
.form { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; align-items: start; }
.form .full { grid-column: 1 / -1; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field-label { font-size: 0.82rem; color: var(--muted); }
.field-check { flex-direction: row; align-items: center; gap: 8px; padding-top: 22px; }
.field-check .field-label { color: var(--ivory); font-size: 0.95rem; }
input, select, textarea {
  width: 100%; background: var(--bg); color: var(--ivory); border: 1px solid var(--border); border-radius: 8px;
  padding: 9px 10px; font: inherit; min-height: 40px;
}
input[type="checkbox"] { width: 20px; height: 20px; min-height: 0; accent-color: var(--gold); }
input[type="file"] { padding: 6px; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--gold); box-shadow: 0 0 0 2px rgba(212, 175, 55, 0.25); }
input[readonly] { color: var(--muted); }
input:disabled, select:disabled, button:disabled { opacity: 0.55; cursor: not-allowed; }
.bilingual { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.check-group { display: flex; flex-wrap: wrap; gap: 10px; }
.check { display: inline-flex; align-items: center; gap: 6px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 6px; }
.chip { display: inline-flex; align-items: center; gap: 4px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px; padding: 3px 10px; font-size: 0.85rem; }
.chip-x { background: none; border: 0; color: var(--muted); cursor: pointer; font-size: 1rem; padding: 0 2px; }
.chip-x:hover { color: var(--danger); }
.upload { display: flex; flex-direction: column; gap: 4px; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 40px;
  padding: 8px 14px; border-radius: 8px; border: 1px solid var(--gold); background: transparent; color: var(--gold);
  font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: rgba(212, 175, 55, 0.12); }
.btn-primary { background: linear-gradient(135deg, var(--gold), var(--yellow)); color: #000; border-color: transparent; }
.btn-primary:hover { filter: brightness(1.08); background: linear-gradient(135deg, var(--gold), var(--yellow)); }
.btn-danger { color: var(--danger); border-color: var(--danger); }
.btn-danger:hover { background: rgba(229, 72, 77, 0.12); }
.btn-ghost { border-color: var(--border); color: var(--ivory); }
.btn-small { min-height: 32px; padding: 4px 10px; font-size: 0.85rem; }
.btn-icon { min-width: 40px; padding: 4px 8px; }

/* ---------- pills ---------- */
.pill { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 0.75rem; font-weight: 600; border: 1px solid var(--border); background: var(--surface-2); color: var(--ivory); margin-inline-start: 4px; }
.pill-booked { color: var(--yellow); border-color: var(--yellow); }
.pill-arrived { color: #5bc0eb; border-color: #5bc0eb; }
.pill-completed, .pill-active { color: var(--ok); border-color: var(--ok); }
.pill-cancelled, .pill-noShow, .pill-expired { color: var(--muted); }
.pill-pending { color: var(--gold); border-color: var(--gold); }
.pill-warn { color: var(--danger); border-color: var(--danger); }
.pill-role { color: var(--gold); border-color: var(--gold); }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
.table th, .table td { padding: 8px 10px; border-bottom: 1px solid var(--border); text-align: start; vertical-align: middle; }
.table th { color: var(--muted); font-weight: 500; font-size: 0.8rem; white-space: nowrap; }
.table tr.ending-soon td { background: rgba(229, 72, 77, 0.08); }
.table tr.me td { background: rgba(212, 175, 55, 0.08); }
.table.hours input[type="time"] { min-width: 110px; }
/* Date and time pickers keep their digits in reading order even on the Arabic (RTL) page;
   Android Chrome otherwise scrambles the segments ("142026/11/"). */
input[type="date"], input[type="time"], input[type="datetime-local"] { direction: ltr; text-align: start; unicode-bidi: isolate; font-variant-numeric: tabular-nums; }
[dir="rtl"] input[type="date"], [dir="rtl"] input[type="time"] { text-align: end; }
/* dateField(): a button showing dd/mm/yyyy, the native picker sits invisibly behind it */
.date-pick { position: relative; display: inline-block; }
.date-pick-btn { font: inherit; display: inline-flex; align-items: center; gap: 8px; padding: 8px 12px; min-width: 150px; justify-content: space-between; background: var(--surface-2); color: var(--ivory); border: 1px solid var(--border); border-radius: 8px; cursor: pointer; }
.date-pick-btn:hover { border-color: var(--gold); }
.date-pick-text { direction: ltr; unicode-bidi: isolate; font-variant-numeric: tabular-nums; letter-spacing: 0.02em; }
.date-native { font: inherit; padding: 8px 12px; min-width: 150px; min-height: 40px; background: var(--surface-2); color: var(--ivory); border: 1px solid var(--border); border-radius: 8px; color-scheme: dark; -webkit-appearance: none; appearance: none; direction: ltr; }
.date-pick-input { position: absolute; inset-inline-start: 0; bottom: 0; width: 1px; height: 1px; opacity: 0; pointer-events: none; border: 0; padding: 0; }
.tel { color: var(--yellow); text-decoration: none; direction: ltr; unicode-bidi: embed; }

/* ---------- appointments ---------- */
.slot-head { display: flex; justify-content: space-between; align-items: center; padding: 6px 10px; margin-top: 10px; background: var(--surface-2); border-radius: 8px; color: var(--gold); }
.slot-head.full { color: var(--danger); }
.apt-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 10px 6px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.apt-main { flex: 1 1 240px; min-width: 0; }
.apt-sub { color: var(--muted); font-size: 0.88rem; }
.apt-row.status-cancelled, .apt-row.status-noShow { opacity: 0.55; }
.apt-row.status-completed .apt-name strong { color: var(--ok); }

/* ---------- reports ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px; }
.stat { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; }
.stat-value { font-size: 1.4rem; font-weight: 700; color: var(--gold); word-break: break-word; }
.stat-label { color: var(--muted); font-size: 0.82rem; margin-top: 4px; }
.stat-sub { color: var(--muted); font-size: 0.78rem; margin-top: 2px; }
.table tfoot td { border-top: 2px solid var(--gold); color: var(--gold); }

/* ---------- media ---------- */
.media-list { display: flex; flex-wrap: wrap; gap: 10px; }
.media-item { display: flex; flex-direction: column; gap: 6px; max-width: 220px; }
.media-item img, .media-item video { width: 100%; max-height: 160px; object-fit: cover; border-radius: 8px; border: 1px solid var(--border); background: #000; }

/* ---------- modal and toast ---------- */
.overlay { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.7); display: flex; align-items: flex-start; justify-content: center; padding: 24px 12px; overflow-y: auto; z-index: 50; }
.modal { background: var(--surface); border: 1px solid var(--gold); border-radius: var(--radius); width: 100%; max-width: 520px; display: flex; flex-direction: column; max-height: calc(100vh - 48px); }
.modal-wide { max-width: 860px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.modal-head h3 { margin: 0; }
.modal-body { padding: 16px; overflow-y: auto; }
.modal-foot { display: flex; gap: 8px; justify-content: flex-end; padding: 12px 16px; border-top: 1px solid var(--border); flex-wrap: wrap; }
.toast {
  position: fixed; bottom: 20px; inset-inline-start: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--surface-2); color: var(--ivory); border: 1px solid var(--gold); border-radius: 10px;
  padding: 10px 16px; opacity: 0; pointer-events: none; transition: opacity 0.2s, transform 0.2s; z-index: 60; max-width: 90vw;
}
[dir="rtl"] .toast { transform: translateX(50%) translateY(20px); }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
[dir="rtl"] .toast.show { transform: translateX(50%) translateY(0); }
.toast-error { border-color: var(--danger); }
.toast-ok { border-color: var(--ok); }

/* ---------- phone ---------- */
@media (max-width: 720px) {
  main { padding: 10px; }
  .grid-2 { grid-template-columns: 1fr; }
  .bilingual { grid-template-columns: 1fr; }
  .toolbar .field { min-width: 0; flex: 1 1 140px; }
  .modal { max-height: calc(100vh - 24px); }
  .overlay { padding: 12px 6px; }
  .topbar { padding: 8px 10px; }
  .brand-sub { display: none; }
  .apt-row .actions { width: 100%; }
}

/* calendar: one block per hour, stacked down the page, the current hour marked;
   the cars of the hour sit side by side as plate chips, details open below on tap */
.day-grid { display: flex; flex-direction: column; gap: 10px; padding: 4px 0 10px; }
.slot-col { display: flex; flex-direction: column; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); }
.slot-col.is-now { border-color: var(--gold); box-shadow: 0 0 0 1px var(--gold) inset; }
.slot-col .slot-head { margin-top: 0; border-radius: 9px 9px 0 0; gap: 8px; padding: 8px 10px; flex-wrap: wrap; }
.slot-col .slot-head .actions { display: flex; gap: 6px; flex-wrap: wrap; }
.slot-col .apt-row { padding: 8px 10px; }
.slot-col .apt-row:last-child { border-bottom: 0; }
.slot-col .slot-empty { padding: 8px 10px; }
.slot-chips { display: flex; flex-wrap: wrap; gap: 6px; padding: 8px 10px; }
.plate-chip { font: inherit; font-size: 0.9rem; font-weight: 700; padding: 5px 10px; border-radius: 999px; cursor: pointer; background: var(--surface-2); color: var(--ivory); border: 1.5px solid var(--border); line-height: 1.2; }
.plate-chip:hover { filter: brightness(1.15); }
.plate-chip.active { background: var(--gold); color: #000; border-color: var(--gold); }
.chip-plate { unicode-bidi: embed; letter-spacing: 0.03em; }
.plate-chip-booked { border-color: var(--yellow); }
.plate-chip-arrived { border-color: #5bc0eb; }
.plate-chip-completed { border-color: var(--ok); color: var(--ok); }
.plate-chip-cancelled, .plate-chip-noShow { border-color: var(--border); color: var(--muted); text-decoration: line-through; }
.plate-chip-dropin { border-color: var(--yellow); border-style: dashed; }
.plate-chip-dropin-booked { border-color: var(--yellow); border-style: dotted; }
.plate-chip-member-wash { border-color: var(--ok); border-style: dashed; }
.plate-chip.active.plate-chip-completed, .plate-chip.active.plate-chip-cancelled, .plate-chip.active.plate-chip-noShow { color: #000; text-decoration: none; }
.slot-detail:empty { display: none; }
.slot-detail { border-top: 1px solid var(--border); }
@media (max-width: 720px) {
  .slot-col .slot-head { flex-direction: column; align-items: stretch; }
  .slot-col .slot-head .actions .btn { flex: 1 1 auto; }
}

.week-strip { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; margin-bottom: 16px; }
.day-btn { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 4px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; color: var(--ivory); cursor: pointer; font: inherit; }
.day-btn:hover { border-color: var(--gold); }
.day-btn.active { border-color: var(--gold); background: rgba(212, 175, 55, 0.12); }
.day-btn.is-today .day-num { color: var(--yellow); }
.day-dow { font-size: 0.75rem; color: var(--muted); }
.day-num { font-size: 1.2rem; font-weight: 700; }
.day-counts { font-size: 0.75rem; color: var(--muted); direction: ltr; }
.card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.card-head h2 { margin: 0; }
.slot-empty { color: var(--muted); font-size: 0.85rem; padding: 4px 10px 8px; margin: 0; }
.walkin-row { border-inline-start: 3px solid var(--yellow); padding-inline-start: 10px; }
.walkin-member { border-inline-start-color: var(--ok); }
.pill-dropin { color: var(--yellow); border-color: var(--yellow); }
.form-wide { grid-column: 1 / -1; }
@media (max-width: 600px) {
  .week-strip { gap: 3px; }
  .day-btn { padding: 6px 2px; }
  .day-num { font-size: 1rem; }
}

.media-grid { display: flex; flex-wrap: wrap; gap: 12px; margin: 8px 0; }

/* Extras and staff note on a booking */
.apt-extras { color: var(--gold, #e6c200); }
.apt-note { font-style: italic; }
.extras-editor .row { align-items: flex-end; flex-wrap: wrap; gap: 0.5rem; }
.extras-line { justify-content: space-between; align-items: center; padding: 0.25rem 0.5rem; border: 1px solid var(--border); border-radius: 8px; }

.history-row td { opacity: 0.6; background: var(--surface-2); }
.known-customer { padding: 8px 10px; border: 1px dashed var(--border); border-radius: 8px; }
.known-customer .apt-row { padding: 6px 0; }
