/* DooRod styles — "Soft modern SaaS".
   Off-white ground, one teal accent, generous rounding, shadows instead of
   heavy borders. One stylesheet, no framework, no web fonts: the app has to
   open fast on a phone in a garage, served off a Raspberry Pi.

   Two rules hold the whole thing together:
   1. Every control is sized from --control-h, so a button standing next to an
      input or a select lines up with it exactly.
   2. Controls that sit together share a size class. `.btn.small` belongs next
      to `.btn.small`, never next to a full-size button. */

:root {
  /* --- ground and ink --------------------------------------------------- */
  /* Neutrals carry a slight blue-green bias so they sit under the teal
     accent rather than fighting it. */
  --bg: #f7f8f9;
  --card: #ffffff;
  --ink: #16232b;
  --ink-soft: #3c4a53;
  --muted: #75838c;
  --line: #e6eaed;
  --line-strong: #d5dbe0;

  /* --- accent ----------------------------------------------------------- */
  --brand: #0f8f86;
  --brand-dark: #0b6f68;
  --brand-soft: #e5f6f1;
  --brand-ring: #b6e3dc;

  /* --- semantic (status), deliberately not the accent ------------------- */
  --ok: #0f8f6a;
  --ok-bg: #e5f6f1;
  --warn: #b8760c;
  --warn-bg: #fdf3e0;
  --bad: #c33a3a;
  --bad-bg: #fbeaea;
  --info: #2f6dbb;
  --info-bg: #e8f0fb;

  /* --- shape and depth -------------------------------------------------- */
  --radius: 14px;
  --radius-sm: 10px;
  --radius-xs: 8px;
  --shadow-sm: 0 1px 2px rgba(16, 35, 43, .05);
  --shadow: 0 1px 2px rgba(16, 35, 43, .04), 0 8px 24px rgba(16, 35, 43, .06);
  --shadow-lg: 0 12px 40px rgba(16, 35, 43, .14);

  /* --- control sizing: change here, every control follows --------------- */
  --control-h: 40px;
  --control-h-sm: 32px;
  --control-pad: 0 12px;
  --control-pad-sm: 0 10px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans Thai",
    "Sarabun", Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--brand-dark); text-decoration: none; }
a:hover { text-decoration: underline; }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }

/* --- layout --------------------------------------------------------------- */
.topbar {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; gap: 12px;
  padding: 10px 18px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
}
.topbar a { color: var(--ink); }
.brand { font-weight: 800; font-size: 18px; letter-spacing: -.015em; color: var(--ink); }
.brand small {
  display: block; font-weight: 500; font-size: 11px; color: var(--muted);
  letter-spacing: 0;
}
.topbar .spacer { flex: 1; }
/* Icon links in the bar are controls too: same box as the bell beside them. */
.topbar > a[title] {
  display: inline-flex; align-items: center; justify-content: center;
  width: var(--control-h-sm); height: var(--control-h-sm);
  border-radius: var(--radius-xs); font-size: 17px; color: var(--ink-soft);
}
.topbar > a[title]:hover { background: var(--bg); text-decoration: none; }
/* The language switch is a control in that same row -- match the bell. */
.topbar select {
  height: var(--control-h-sm); padding: var(--control-pad-sm); font-size: 13px;
}

.nav {
  display: flex; gap: 2px; overflow-x: auto;
  background: var(--card); border-bottom: 1px solid var(--line);
  padding: 0 10px; position: sticky; top: 60px; z-index: 30;
}
.nav a {
  padding: 13px 14px; color: var(--muted); font-weight: 600; font-size: 14px;
  white-space: nowrap; border-bottom: 2px solid transparent;
}
.nav a.active { color: var(--brand-dark); border-bottom-color: var(--brand); }
.nav a:hover { text-decoration: none; color: var(--ink); }

.wrap { max-width: 1180px; margin: 0 auto; padding: 22px 18px 48px; }

/* --- cards and tables ----------------------------------------------------- */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 18px;
  margin-bottom: 18px;
}
.card h2, .card h3 {
  margin: 0 0 14px; font-size: 16px; font-weight: 700; letter-spacing: -.01em;
}
.card-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; margin-bottom: 14px; flex-wrap: wrap;
}
.card-head h2, .card-head h3 { margin: 0; }

.grid { display: grid; gap: 14px; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.grid-4 { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }

.stat {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow-sm);
}
.stat .n {
  font-size: 28px; font-weight: 750; line-height: 1.05; letter-spacing: -.025em;
  font-variant-numeric: tabular-nums;
}
.stat .l { color: var(--muted); font-size: 13px; margin-top: 3px; }
.stat.bad .n { color: var(--bad); }
.stat.warn .n { color: var(--warn); }
.stat.ok .n { color: var(--ok); }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 11px 10px; border-bottom: 1px solid var(--line); }
th {
  color: var(--muted); font-weight: 700; font-size: 11px;
  text-transform: uppercase; letter-spacing: .06em;
}
tbody tr:hover td { background: #fafbfb; }
tr:last-child td { border-bottom: none; }
.table-scroll { overflow-x: auto; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

/* --- badges and dots ------------------------------------------------------ */
.badge {
  display: inline-block; padding: 3px 9px; border-radius: 999px;
  font-size: 12px; font-weight: 700; background: var(--bg); color: var(--ink-soft);
  border: 1px solid var(--line);
}
.badge.overdue { background: var(--bad-bg); color: var(--bad); border-color: transparent; }
.badge.due_soon { background: var(--warn-bg); color: var(--warn); border-color: transparent; }
.badge.ok { background: var(--ok-bg); color: var(--ok); border-color: transparent; }
.badge.info { background: var(--info-bg); color: var(--info); border-color: transparent; }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.dot.overdue { background: var(--bad); }
.dot.due_soon { background: var(--warn); }
.dot.ok, .dot.unknown { background: var(--line-strong); }

/* --- forms ---------------------------------------------------------------- */
/* Inputs, selects and buttons all resolve to --control-h, which is what keeps
   a row of mixed controls on one baseline. */
label {
  display: block; font-size: 12.5px; color: var(--muted); margin-bottom: 5px;
  font-weight: 600;
}
input, select, textarea {
  width: 100%; height: var(--control-h); padding: var(--control-pad);
  border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  font: inherit; font-size: 14px; background: var(--card); color: var(--ink);
}
textarea { height: auto; padding: 10px 12px; line-height: 1.5; }
input[type="file"] { padding: 7px 10px; }
input[type="checkbox"] { height: auto; width: auto; }
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-ring);
}
input::placeholder { color: #9aa6ad; }
.field { margin-bottom: 14px; }
fieldset {
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; margin: 0 0 18px; background: #fcfdfd;
}
legend { font-weight: 700; font-size: 13px; padding: 0 8px; color: var(--ink-soft); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: var(--control-h); padding: var(--control-pad);
  border-radius: var(--radius-sm); border: 1px solid transparent;
  background: var(--brand); color: #fff;
  font: inherit; font-size: 14px; font-weight: 700; cursor: pointer;
  white-space: nowrap; text-align: center;
}
.btn:hover { background: var(--brand-dark); text-decoration: none; color: #fff; }
.btn:active { transform: translateY(1px); }
.btn.secondary {
  background: var(--card); color: var(--ink); border-color: var(--line-strong);
}
.btn.secondary:hover { background: var(--bg); color: var(--ink); }
.btn.danger { background: var(--bad); }
.btn.danger:hover { background: #a52f2f; }
/* Small is a matched set: height, padding and type all step down together. */
.btn.small { height: var(--control-h-sm); padding: var(--control-pad-sm); font-size: 13px; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
/* A form used only as a button wrapper must not add its own box, or the button
   beside it sits a few pixels off. */
.btn-row form, .card-head form { display: inline-flex; margin: 0; }
/* Controls inside a head row match the small buttons they sit next to. */
.card-head select, .card-head input {
  height: var(--control-h-sm); font-size: 13px; padding: var(--control-pad-sm);
  width: auto;
}
/* A lone button under a form field lines up with the field above it. */
.field .btn { width: 100%; }
/* A form that exists only to hold one button: no box, no spacing of its own,
   so the button sits level with whatever control is beside it. */
.inline-form { display: inline-flex; margin: 0; }
.inline-form.gap { gap: 6px; margin-top: 6px; }
.mark-all { margin: 10px 14px; }
/* Pinned remark on a vehicle: a note, not a status, so it borrows the warning
   colours without claiming to be an alert. */
.notice.pinned { background: var(--warn-bg); color: var(--warn); }
/* Selects used as instant filters shrink to their content instead of
   stretching across a table cell. */
td select, .filter-inline select { width: auto; }

.muted { color: var(--muted); }
.small { font-size: 13px; }
.right { text-align: right; }
.empty { color: var(--muted); padding: 28px; text-align: center; }
.error {
  background: var(--bad-bg); color: var(--bad); padding: 11px 13px;
  border-radius: var(--radius-sm); margin-bottom: 14px; font-weight: 600;
}
.notice {
  background: var(--ok-bg); color: var(--ok); padding: 11px 13px;
  border-radius: var(--radius-sm); margin-bottom: 14px; font-weight: 600;
}

/* --- notification bell ---------------------------------------------------- */
.bell {
  position: relative; background: none; border: none; cursor: pointer;
  color: var(--ink-soft); font-size: 18px;
  width: var(--control-h-sm); height: var(--control-h-sm);
  border-radius: var(--radius-xs);
}
.bell:hover { background: var(--bg); }
.bell .count {
  position: absolute; top: -3px; right: -3px; background: var(--bad); color: #fff;
  border-radius: 999px; font-size: 11px; padding: 0 5px; font-weight: 700;
  min-width: 17px; line-height: 17px;
}
.dropdown {
  position: absolute; right: 12px; top: 58px; width: min(390px, 94vw);
  background: var(--card); color: var(--ink); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow-lg); z-index: 50;
  max-height: 70vh; overflow-y: auto;
}
.dropdown .item {
  padding: 11px 14px; border-bottom: 1px solid var(--line); display: block;
  color: var(--ink);
}
.dropdown .item:hover { background: var(--bg); text-decoration: none; }
.dropdown .item.unread { background: var(--brand-soft); }
.dropdown .head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 14px; border-bottom: 1px solid var(--line); font-weight: 700;
}

/* --- global search -------------------------------------------------------- */
.searchbox { position: relative; flex: 1; max-width: 520px; }
.searchbox input {
  height: var(--control-h-sm); background: var(--bg);
  border-color: transparent; font-size: 13.5px;
}
.searchbox input:focus { background: var(--card); }
.suggest {
  display: none; position: absolute; left: 0; right: 0; top: 40px;
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow-lg); z-index: 60;
  max-height: 60vh; overflow-y: auto;
}
.suggest .item {
  display: block; padding: 9px 13px; color: var(--ink);
  border-bottom: 1px solid var(--line);
}
.suggest .item:hover { background: var(--bg); text-decoration: none; }

/* --- AI bar --------------------------------------------------------------- */
/* Sits under the nav on every screen. The three controls are one set: the
   input, the AI button and the camera button all share --control-h. */
.aibar { display: flex; gap: 8px; margin-bottom: 18px; align-items: center; }
.aibar input { flex: 1; box-shadow: var(--shadow-sm); }
.ai-result { margin-top: 12px; }
.ai-fields { margin-bottom: 10px; }
.ai-fields .field { margin-bottom: 10px; }
.ai-fields label { font-size: 12px; }
.ai-photo, .ai-photo-wait {
  display: flex; align-items: center; gap: 14px; margin-bottom: 12px;
}
.ai-photo img, .ai-photo-wait img {
  width: 96px; height: 96px; object-fit: cover; border-radius: var(--radius-sm);
  border: 1px solid var(--line);
}
.ai-photo-wait img { opacity: .7; }
#ai-photo-btn { font-size: 16px; padding: 0 13px; }

/* --- vehicle cards -------------------------------------------------------- */
.vcards {
  display: grid; gap: 14px;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
}
.vcard {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow-sm);
  transition: box-shadow .15s ease, transform .15s ease;
}
.vcard:hover { box-shadow: var(--shadow); transform: translateY(-1px); }
.vcard img, .vcard .noimg {
  width: 100%; height: 150px; object-fit: cover; display: block; background: var(--bg);
}
.vcard .noimg {
  display: flex; align-items: center; justify-content: center;
  color: var(--line-strong); font-size: 34px;
}
.vcard .body { padding: 12px 14px 14px; }
.vcard .plate { font-weight: 750; font-size: 16px; letter-spacing: -.01em; }

/* --- galleries, upload preview, lightbox ---------------------------------- */
.gallery, .preview-strip {
  display: grid; gap: 12px;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
}
.gallery figure, .preview-strip figure { margin: 0; }
.gallery img, .preview-strip img {
  width: 100%; height: 120px; object-fit: cover; border-radius: var(--radius-sm);
  border: 1px solid var(--line); background: var(--bg);
}
.thumb { position: relative; }
.thumb a { display: block; position: relative; }
.thumb .zoom {
  position: absolute; right: 7px; bottom: 7px; opacity: 0;
  background: rgba(16, 35, 43, .7); color: #fff; border-radius: var(--radius-xs);
  padding: 2px 7px; font-size: 12px; transition: opacity .12s;
}
.thumb:hover .zoom { opacity: 1; }
.thumb.pending img { border-style: dashed; opacity: .85; }
.thumb figcaption {
  margin-top: 5px; display: flex; align-items: center; gap: 5px; flex-wrap: wrap;
}
.thumb figcaption form { display: inline-flex; margin: 0; }
/* The two icon buttons under a thumbnail are a matched pair. */
.thumb-star, .thumb-x {
  border: none; cursor: pointer; border-radius: var(--radius-xs);
  font-size: 11px; line-height: 1; padding: 5px 8px; height: 24px;
  font-weight: 700;
}
.thumb-star { background: var(--warn-bg); color: var(--warn); }
.thumb-x { background: var(--bad-bg); color: var(--bad); }
.thumb-star:hover { background: #f8e7c4; }
.thumb-x:hover { background: #f6d9d9; }
.filetile {
  display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 5px; height: 120px; border-radius: var(--radius-sm);
  background: var(--bg); color: var(--ink-soft); font-size: 26px;
  border: 1px solid var(--line);
}
.upload-form { margin-bottom: 14px; }
.upload-form .preview-strip:empty { display: none; }

.lightbox {
  display: none; position: fixed; inset: 0; z-index: 200;
  background: rgba(10, 20, 25, .93); align-items: center; justify-content: center;
  padding: 24px;
}
.lightbox.open { display: flex; }
.lightbox img {
  max-width: 92vw; max-height: 84vh; object-fit: contain;
  border-radius: var(--radius-sm);
}
.lightbox .lb-caption {
  position: absolute; bottom: 16px; left: 0; right: 0; text-align: center;
  color: #e6eaed; font-size: 13px; padding: 0 16px;
}
.lightbox .lb-close, .lightbox .lb-nav {
  position: absolute; background: rgba(255, 255, 255, .14); color: #fff;
  border: none; border-radius: 999px; cursor: pointer; line-height: 1;
}
.lightbox .lb-close { top: 18px; right: 18px; font-size: 18px; padding: 10px 14px; }
.lightbox .lb-nav {
  top: 50%; transform: translateY(-50%); font-size: 32px; padding: 8px 18px;
}
.lightbox .lb-prev { left: 14px; }
.lightbox .lb-next { right: 14px; }
.lightbox .lb-close:hover, .lightbox .lb-nav:hover { background: rgba(255, 255, 255, .28); }

/* --- tabs and disclosures ------------------------------------------------- */
.tabs {
  display: flex; gap: 2px; overflow-x: auto; margin-bottom: 18px;
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 5px;
}
.tabs button {
  background: none; border: none; padding: 0 14px; cursor: pointer;
  font: inherit; font-size: 14px; font-weight: 600; color: var(--muted);
  white-space: nowrap; border-radius: var(--radius-sm); height: var(--control-h);
}
.tabs button:hover { background: var(--bg); color: var(--ink); }
.tabs button.active { background: var(--brand-soft); color: var(--brand-dark); }
.tabpane { display: none; }
.tabpane.active { display: block; }

details.inline { margin-bottom: 14px; }
details.inline > summary {
  cursor: pointer; font-weight: 700; color: var(--brand-dark); padding: 8px 0;
  font-size: 14px; list-style: none;
}
details.inline > summary::-webkit-details-marker { display: none; }
details.inline > summary::before { content: "▸ "; color: var(--muted); }
details.inline[open] > summary::before { content: "▾ "; }

/* --- phone ---------------------------------------------------------------- */
@media (max-width: 640px) {
  .wrap { padding: 14px 12px 40px; }
  .card { padding: 14px; }
  .hide-sm { display: none; }
  .topbar { padding: 8px 12px; gap: 8px; }
  .brand small { display: none; }
  .nav { top: 56px; }
  .searchbox { max-width: none; }
  .stat .n { font-size: 24px; }
  /* Full-width controls stack cleanly instead of half-wrapping. */
  .btn-row .btn { flex: 1 1 auto; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
  .vcard:hover { transform: none; }
}

@media print {
  .topbar, .nav, .aibar, .btn, .tabs, .dropdown, .upload-form { display: none; }
  .card { box-shadow: none; border-color: #ccc; page-break-inside: avoid; }
  .tabpane { display: block !important; }
}
