/*
 * The signed-in app shell (templates/base.html): sidebar, top bar, cards,
 * tables, forms, badges and flashes. Colours and sizes come from the tokens
 * in vinhaus.css, so this file works in both themes unchanged.
 */

html, body { height: 100%; margin: 0; }
body { font-size: 14px; line-height: 1.5; }
html[data-fontsize="small"]   { font-size: 12px !important; }
html[data-fontsize="default"] { font-size: 14px !important; }
html[data-fontsize="large"]   { font-size: 16px !important; }
body, h1, h2, h3, h4, h5, h6, p, ul, ol, figure, blockquote { margin: 0; }
ul, ol { padding: 0; }
a { color: var(--text); text-decoration: none; }

/* ── Layout ── */
.app { display: flex; height: 100vh; height: 100dvh; overflow: hidden; }
.main { flex: 1; display: flex; flex-direction: column; overflow: hidden; min-width: 0; }
.content {
  flex: 1; overflow-y: auto; padding: var(--s-5);
  display: flex; flex-direction: column;
  position: relative; isolation: isolate;
}
/* The faint engineering grid from the public pages, fading out behind the
   top of the page. It is absolutely placed, so it scrolls with the content. */
.content::before {
  content: ''; position: absolute; left: 0; right: 0; top: 0; height: 340px;
  z-index: -1; pointer-events: none;
  background:
    linear-gradient(var(--grid-line) 1px, transparent 1px) 0 0 / var(--grid-size) var(--grid-size),
    linear-gradient(90deg, var(--grid-line) 1px, transparent 1px) 0 0 / var(--grid-size) var(--grid-size);
  -webkit-mask-image: linear-gradient(to bottom, #000, transparent);
          mask-image: linear-gradient(to bottom, #000, transparent);
}

/* ── Sidebar ── */
.sidebar {
  --sidebar-w: 232px;
  width: var(--sidebar-w); background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  flex-shrink: 0; overflow-y: auto; overflow-x: hidden;
}
.sidebar-header { padding: 18px 16px 14px; border-bottom: 1px solid var(--border); }
.sidebar-brand { font-family: var(--font-head); font-size: 2.3rem; letter-spacing: 5px; line-height: 1; color: var(--white); }
.sidebar-brand span { color: var(--red); }

/* Vehicle switcher */
.vehicle-switcher { position: relative; padding: 12px; border-bottom: 1px solid var(--border); }
.vs-trigger {
  display: flex; align-items: center; justify-content: space-between;
  width: 100%; min-height: 38px; background: var(--surface2);
  border: 1px solid var(--border); color: var(--white);
  border-radius: var(--r-sm); padding: 8px 10px; font-size: 0.85rem; font-weight: 600;
  cursor: pointer; user-select: none; transition: border-color 0.15s;
}
.vs-trigger:hover { border-color: var(--border-strong); }
.vs-trigger.open { border-color: var(--red); border-radius: var(--r-sm) var(--r-sm) 0 0; }
.vs-trigger-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; text-align: left; }
.vs-trigger svg { flex-shrink: 0; margin-left: 6px; color: var(--muted); transition: transform 0.2s; }
.vs-trigger.open svg { transform: rotate(180deg); }
.vs-dropdown {
  position: absolute; left: 12px; right: 12px; z-index: 200;
  background: var(--surface2); border: 1px solid var(--red);
  border-top: none; border-radius: 0 0 var(--r-sm) var(--r-sm);
  overflow: hidden; display: none; box-shadow: var(--shadow);
}
.vs-dropdown.open { display: block; }
.vs-option {
  display: block; padding: 10px 12px; font-size: 0.85rem;
  color: var(--text); cursor: pointer; transition: background 0.12s;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.vs-option:hover { background: var(--red-tint); color: var(--white); }
.vs-option.active { color: var(--red-text); font-weight: 600; }
.vs-option.is-empty { color: var(--muted); cursor: default; }
.vehicle-add-btn {
  display: inline-flex; align-items: center; gap: 6px;
  color: var(--muted); font-size: 0.8rem; margin-top: 8px;
  padding: 4px 2px; transition: color 0.2s;
}
.vehicle-add-btn:hover { color: var(--red-text); }

/* Nav */
.nav-section { padding: 12px 12px 4px; }
.nav-section-bottom { margin-top: auto; padding-bottom: 12px; }
.nav-section-label {
  font-size: 0.68rem; letter-spacing: 1.5px; text-transform: uppercase;
  color: var(--subtle); font-weight: 600; padding: 0 4px; margin: 6px 0 4px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.sidebar-link {
  display: flex; align-items: center; gap: 10px;
  min-height: 38px; padding: 5px 8px; border-radius: var(--r-sm); color: var(--muted);
  font-size: 0.86rem; font-weight: 500;
  transition: background 0.15s, color 0.15s; margin-bottom: 1px;
}
.sidebar-link:hover { background: var(--surface2); color: var(--text); }
.sidebar-link.active { background: var(--surface2); color: var(--white); font-weight: 600; }
.nav-icon {
  width: 28px; height: 28px; border-radius: 7px;
  background: var(--surface3);
  display: flex; align-items: center; justify-content: center;
  font-size: 0.85rem; flex-shrink: 0; transition: background 0.15s;
}
.sidebar-link.active .nav-icon { background: var(--red); color: var(--on-accent); }
.sidebar-user { padding: 8px 12px 0; font-size: 0.72rem; color: var(--subtle); word-break: break-all; }

/* Expiry badges in the sidebar */
.expiry-badge { margin-left: auto; font-size: 0.68rem; font-weight: 700; padding: 1px 7px; border-radius: var(--r-pill); }
.expiry-ok   { background: var(--good-tint); color: var(--good); }
.expiry-warn { background: var(--warn-tint); color: var(--warn); }
.expiry-bad  { background: var(--bad-tint);  color: var(--bad); }

.sidebar-overlay { display: none; position: fixed; inset: 0; background: var(--overlay); z-index: 99; }
.sidebar-overlay.show { display: block; }

/* ── Top bar ── */
.topbar {
  min-height: 60px; background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 8px 24px; flex-shrink: 0; position: relative;
}
.topbar-start { display: flex; align-items: center; gap: 12px; min-width: 0; }
.topbar-heading { min-width: 0; }
.topbar-title { display: block; font-family: var(--font-head); font-weight: 400; font-size: 1.6rem; letter-spacing: 1px; color: var(--white); line-height: 1.05; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar-sub { font-size: 0.75rem; color: var(--muted); line-height: 1.3; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar-center { position: absolute; left: 50%; transform: translateX(-50%); }
.topbar-actions { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }

/* Theme and text-size switch */
.prefs { display: flex; align-items: center; border: 1px solid var(--border); border-radius: var(--r-sm); overflow: hidden; }
.prefs button {
  display: flex; align-items: center; gap: 6px;
  background: none; border: none; cursor: pointer; color: var(--muted);
  font-size: 0.78rem; font-weight: 600; padding: 6px 12px; min-height: 34px;
  transition: color 0.15s, background 0.15s;
}
.prefs button + button { border-left: 1px solid var(--border); }
.prefs button:hover { background: var(--surface2); color: var(--text); }
.prefs i { font-size: 1rem; }
.icon-btn {
  display: none; align-items: center; justify-content: center;
  width: 40px; height: 40px; border-radius: var(--r-sm);
  background: none; border: 1px solid var(--border); color: var(--muted);
  font-size: 1.05rem; cursor: pointer;
}
.icon-btn:hover { color: var(--text); background: var(--surface2); }
.hamburger { display: none; background: none; border: none; color: var(--white); font-size: 1.5rem; cursor: pointer; width: 40px; height: 40px; margin-left: -8px; }
.mobile-logo-bar { display: none; }
.topbar-logo { font-family: var(--font-head); font-size: 2rem; letter-spacing: 5px; line-height: 1; color: var(--white); }
.topbar-logo span { color: var(--red); }

/* ── Buttons ── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 36px; padding: 8px 16px; border-radius: var(--r-sm);
  font-size: 0.85rem; font-weight: 600; line-height: 1.2; white-space: nowrap;
  cursor: pointer; border: 1px solid transparent; text-decoration: none;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.btn-red   { background: var(--red); color: var(--on-accent); }
.btn-red:hover { background: var(--red-dark); color: var(--on-accent); }
.btn-ghost { background: var(--surface2); color: var(--text); border-color: var(--border); }
.btn-ghost:hover { background: var(--surface3); color: var(--white); }
.btn-sm { min-height: 30px; padding: 5px 11px; font-size: 0.78rem; }
.btn[disabled], .btn.disabled { opacity: 0.5; pointer-events: none; }

/* ── Cards ── */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-md); padding: 20px; min-width: 0;
}
.card-title { font-size: 0.7rem; text-transform: uppercase; letter-spacing: 1.5px; font-weight: 600; color: var(--muted); margin-bottom: 6px; }
/* Big figures (days left, totals, counts) read like a spec sheet. */
.card-value { font-family: var(--font-head); font-weight: 400; font-size: 2.4rem; letter-spacing: 0.5px; line-height: 1; color: var(--white); }
.card-value small { font-family: var(--font-body); font-size: 0.8rem; font-weight: 600; letter-spacing: 0; color: var(--muted); margin-left: 4px; }
.card-sub   { font-size: 0.78rem; color: var(--muted); margin-top: 2px; }

/* ── Grids ── */
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; }

/* ── Status badges ── */
.badge {
  display: inline-block; padding: 2px 9px; border-radius: var(--r-pill);
  font-size: 0.72rem; font-weight: 600; white-space: nowrap;
}
.badge-green  { background: var(--good-tint); color: var(--good); }
.badge-yellow { background: var(--warn-tint); color: var(--warn); }
.badge-red    { background: var(--bad-tint);  color: var(--bad); }
.badge-blue   { background: var(--info-tint); color: var(--info); }
.badge-grey   { background: var(--surface3);  color: var(--muted); }

/* ── Tables ── */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; }
th { font-size: 0.68rem; text-transform: uppercase; letter-spacing: 1px; font-weight: 600; color: var(--muted); padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
td { padding: 12px; border-bottom: 1px solid var(--border); font-size: 0.86rem; color: var(--text); }
tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: var(--surface2); }

/* ── Forms ── */
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.form-grid.cols-1 { grid-template-columns: 1fr; }
.form-group { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.form-group.span-2 { grid-column: span 2; }
label { font-size: 0.78rem; font-weight: 600; color: var(--muted); }
input, select, textarea {
  background: var(--surface2); border: 1px solid var(--border);
  color: var(--white); border-radius: var(--r-sm); padding: 9px 12px;
  font-size: 0.9rem; font-family: inherit; width: 100%; min-height: 40px;
  transition: border-color 0.15s, box-shadow 0.15s;
}
input::placeholder, textarea::placeholder { color: var(--subtle); }
input:hover, select:hover, textarea:hover { border-color: var(--border-strong); }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--red); box-shadow: 0 0 0 3px var(--red-tint); }
textarea { resize: vertical; min-height: 96px; line-height: 1.5; }
input[type="date"], input[type="datetime-local"] { height: 42px; max-height: 42px; -webkit-appearance: none; appearance: none; line-height: 1; }
input[type="radio"], input[type="checkbox"] { width: auto; min-height: 0; padding: 0; background: none; border: none; accent-color: var(--red); }
input[type="file"] { padding: 7px; }
.radio-row { display: flex; flex-wrap: wrap; gap: 16px; }
.radio-row label { display: flex; align-items: center; gap: 6px; cursor: pointer; font-size: 0.86rem; color: var(--text); font-weight: 400; }
.reminder-prefs { margin-bottom: 16px; }
.reminder-prefs .card-sub { margin: 0 0 14px; }
.reminder-prefs .radio-row { flex-direction: column; gap: 10px; margin-bottom: 16px; }
.form-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 8px; }

/* ── Flash messages ── */
.flash { padding: 11px 16px; border-radius: var(--r-sm); font-size: 0.86rem; margin-bottom: 16px; border: 1px solid transparent; }
.flash-success { background: var(--good-tint); color: var(--good); border-color: color-mix(in srgb, var(--good) 30%, transparent); }
.flash-warning { background: var(--warn-tint); color: var(--warn); border-color: color-mix(in srgb, var(--warn) 30%, transparent); }
.flash-danger  { background: var(--bad-tint);  color: var(--bad);  border-color: color-mix(in srgb, var(--bad) 30%, transparent); }
.flash-info    { background: var(--info-tint); color: var(--info); border-color: color-mix(in srgb, var(--info) 30%, transparent); }

.demo-banner {
  display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 8px;
  background: var(--red-tint); border: 1px solid var(--red-line); border-radius: var(--r-sm);
  padding: 10px 16px; margin-bottom: 16px;
}
.demo-banner span { font-size: 0.86rem; color: var(--red-text); font-weight: 600; }

/* ── Custom select ── */
.cs-wrap { position: relative; }
.cs-trigger {
  display: flex; align-items: center; justify-content: space-between;
  width: 100%; min-height: 40px; background: var(--surface2);
  border: 1px solid var(--border); color: var(--white);
  border-radius: var(--r-sm); padding: 8px 12px; font-size: 0.9rem;
  cursor: pointer; user-select: none; transition: border-color 0.15s;
}
.cs-trigger:hover { border-color: var(--border-strong); }
.cs-trigger.open { border-color: var(--red); border-radius: var(--r-sm) var(--r-sm) 0 0; }
.cs-trigger-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.cs-arrow { flex-shrink: 0; margin-left: 8px; color: var(--muted); transition: transform 0.2s; display: flex; align-items: center; }
.cs-trigger.open .cs-arrow { transform: rotate(180deg); }
.cs-dropdown {
  position: absolute; left: 0; right: 0; z-index: 300;
  background: var(--surface2); border: 1px solid var(--red);
  border-top: none; border-radius: 0 0 var(--r-sm) var(--r-sm);
  display: none; box-shadow: var(--shadow);
  max-height: 260px; overflow-y: auto;
}
.cs-dropdown.open { display: block; }
.cs-option { padding: 10px 12px; font-size: 0.9rem; color: var(--text); cursor: pointer; transition: background 0.12s; }
.cs-option:hover { background: var(--red-tint); color: var(--white); }
.cs-option.active { color: var(--red-text); font-weight: 600; }

/* ── Empty state ── */
.empty { text-align: center; padding: 48px 24px; color: var(--muted); border: 1px dashed var(--border-strong); border-radius: var(--r-md); }
.card .empty { border: 0; }
.empty i { font-size: 2.4rem; margin-bottom: 12px; display: block; color: var(--subtle); }
.empty p { margin-bottom: 16px; }

/* ── Section header ── */
.section-header { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 12px; margin-bottom: 20px; }
.section-header h1 { font-family: var(--font-head); font-weight: 400; font-size: 1.9rem; letter-spacing: 1px; line-height: 1; color: var(--white); }

/* ── Footer ── */
.app-footer {
  margin-top: auto; padding: 20px 0 4px; border-top: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 8px 16px;
  font-size: 0.75rem; color: var(--subtle);
}
.app-footer nav { display: flex; gap: 16px; flex-wrap: wrap; }
.app-footer a { color: var(--muted); }
.app-footer a:hover { color: var(--white); }
.content > .app-footer { margin-top: auto; }

/* ── Phones ── */
@media (max-width: 768px) {
  .sidebar { position: fixed; left: -100%; top: 0; bottom: 0; z-index: 100; transition: left 0.25s var(--ease); box-shadow: var(--shadow); }
  .sidebar.open { left: 0; }
  .hamburger { display: flex; align-items: center; justify-content: center; }
  .icon-btn { display: inline-flex; }
  .mobile-logo-bar {
    display: flex; align-items: center; justify-content: center; height: 48px;
    background: var(--surface); border-bottom: 1px solid var(--border); flex-shrink: 0;
  }
  .topbar { padding: 8px 14px; min-height: 56px; }
  .topbar-title { font-size: 1.35rem; }
  .card-value { font-size: 2rem; }
  .topbar-center { display: none; }
  .topbar-actions { gap: 6px; }
  .topbar-actions .btn { padding: 7px 11px; min-height: 40px; }
  .topbar-actions .btn .hide-mobile { display: none; }
  .grid-2, .grid-3, .grid-4 { grid-template-columns: minmax(0, 1fr); }
  .form-grid { grid-template-columns: minmax(0, 1fr); }
  .form-group.span-2 { grid-column: span 1; }
  .content { padding: 16px; }
  .card { padding: 16px; }

  /* Tables become stacked rows on a phone: each cell shows its column
     name (from data-label, filled in by base.html) above the value. */
  table.stack thead { display: none; }
  table.stack, table.stack tbody, table.stack tr, table.stack td { display: block; width: 100%; }
  table.stack tr { padding: 12px 0; border-bottom: 1px solid var(--border); }
  table.stack tr:last-child { border-bottom: none; }
  table.stack td { border: none; padding: 3px 0; display: flex; justify-content: space-between; gap: 16px; text-align: right; }
  table.stack td::before { content: attr(data-label); color: var(--muted); font-size: 0.72rem; text-transform: uppercase; letter-spacing: 1px; font-weight: 600; text-align: left; flex-shrink: 0; padding-top: 2px; }
  table.stack td[data-label=""]::before { content: none; }
  table.stack td:first-child { font-weight: 600; color: var(--white); }
  tbody tr:hover td { background: none; }
}

@media (pointer: coarse) {
  .btn { min-height: var(--touch); }
  .btn-sm { min-height: 36px; }
  .sidebar-link { min-height: var(--touch); }
}

/* Account: plan picker */
.acc-plans { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.acc-plan { background: var(--surface2); border: 1px solid var(--border); border-radius: var(--r-sm); padding: 14px 12px; text-align: center; display: flex; flex-direction: column; }
.acc-plan.is-popular { border-color: var(--red); }
.acc-plan-name { display: flex; align-items: center; justify-content: center; gap: 6px; flex-wrap: wrap; font-size: 0.68rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 1px; margin-bottom: 6px; }
.acc-plan-name .pill { font-size: 0.6rem; padding: 1px 7px; }
.acc-plan-price { font-family: var(--font-head); font-size: 2rem; line-height: 1; color: var(--white); }
.acc-plan-sub { font-size: 0.68rem; color: var(--muted); margin: 2px 0 8px; }
.acc-plan-note { font-size: 0.72rem; color: var(--text); margin-bottom: 12px; flex: 1; }
.acc-plan-btn { width: 100%; }
@media (max-width: 480px) { .acc-plans { grid-template-columns: minmax(0, 1fr); } .acc-plan { flex-direction: row; flex-wrap: wrap; align-items: baseline; text-align: left; gap: 0 10px; } .acc-plan-name { justify-content: flex-start; width: 100%; } .acc-plan-note { flex: 1 1 100%; margin-bottom: 10px; } .acc-plan form { width: 100%; } }

/* Garage vehicle cards: photo, or the plate on a drawing grid */
.gv-cover { height: 130px; overflow: hidden; background: var(--surface2); display: flex; align-items: center; justify-content: center; border-bottom: 1px solid var(--border); }
.gv-cover img { width: 100%; height: 100%; object-fit: cover; }
.gv-cover-plate {
  background:
    radial-gradient(ellipse 70% 80% at 50% 50%, var(--glow), transparent 70%),
    linear-gradient(var(--grid-line) 1px, transparent 1px) 0 0 / 24px 24px,
    linear-gradient(90deg, var(--grid-line) 1px, transparent 1px) 0 0 / 24px 24px,
    var(--surface2);
}
.gv-plate { font-size: 1.9rem; letter-spacing: 4px; padding: 6px 16px; box-shadow: 0 10px 24px -12px rgba(0,0,0,0.6); }
.gv-make { font-family: var(--font-head); font-size: 2rem; letter-spacing: 2px; color: var(--muted); }
.gv-name { font-family: var(--font-head); font-size: 1.5rem; letter-spacing: 0.5px; line-height: 1.05; color: var(--white); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Registration entry, styled as a UK number plate */
.reg-input {
  max-width: 320px;
  flex: 1; min-width: 160px; min-height: 48px;
  background: var(--plate); color: var(--plate-ink);
  border: 2px solid var(--plate-ink); border-radius: 6px;
  font-family: var(--font-head); font-size: 1.6rem; letter-spacing: 4px;
  text-align: center; text-transform: uppercase; padding: 6px 12px;
}
.reg-input::placeholder { color: color-mix(in srgb, var(--plate-ink) 45%, transparent); }
.reg-input:hover { border-color: var(--plate-ink); }
.reg-input:focus { border-color: var(--plate-ink); box-shadow: 0 0 0 3px var(--red-tint); }

/* Admin error log: scheduled jobs */
.job-health { margin-bottom: 20px; }
.job-health .num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.job-health .job-error { color: var(--muted); font-size: 0.8rem; }
.job-empty { color: var(--muted); font-size: 0.85rem; }
