
:root {
  --navy: #1c2b4a;
  --navy-2: #14203a;
  --navy-deep: #0f1a30;
  --ink: #1b2230;
  --muted: #5c6675;
  --line: #e4e7ec;
  --bg: #ffffff;
  --bg-soft: #f6f7f9;
  --bg-cream: #faf8f4;
  --gold: #b08a46;
  --gold-light: #c9a35f;
  --gold-ink: #8a6a2f;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow-sm: 0 2px 10px rgba(20, 32, 58, 0.06);
  --shadow: 0 18px 44px rgba(15, 26, 48, 0.14);
  --maxw: 1180px;
  --serif: "Cormorant Garamond", Georgia, "Times New Roman", serif;
  --sans: "Manrope", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;

  /* Back-compat aliases: a couple of views set inline styles against the
     old token names (var(--cream), var(--ok)) — kept pointed at the new
     palette rather than touched view-by-view. */
  --cream: var(--bg-cream);
  --ok: #3f6b52;
  --danger: #a3403a;
  --gray: var(--muted);
  --border: var(--line);
  --max-width: var(--maxw);
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  font-family: var(--sans);
  font-size: 15px;
  color: var(--ink);
  background: var(--bg-cream);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 {
  font-family: var(--serif);
  font-weight: 700;
  color: var(--navy);
  margin: 0.3em 0 0.35em;
  line-height: 1.2;
}
h1 { font-size: 2rem; }
h2 { font-size: 1.5rem; }
h3 { font-size: 1.2rem; font-weight: 600; }

/* Short gold rule under a page's top-level heading. */
main > h1:first-child,
main > h1:first-of-type {
  padding-bottom: 12px;
  margin-bottom: 20px;
  border-bottom: 3px solid var(--gold);
  display: inline-block;
}

p { margin: 0.6em 0; }

a { color: var(--navy); }
a:hover { color: var(--navy-2); }

/* ---------- Header / nav ---------- */

header.app-header {
  background: var(--navy);
  padding: 14px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  box-shadow: var(--shadow-sm);
}

header.app-header .brand {
  font-family: var(--serif);
  color: #fff;
  font-weight: 700;
  font-size: 1.3rem;
  letter-spacing: 0.01em;
  text-decoration: none;
}

header.app-header nav {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px;
}

header.app-header nav a {
  color: rgba(255, 255, 255, 0.82);
  text-decoration: none;
  margin-left: 6px;
  font-size: 0.92rem;
  font-weight: 500;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  min-height: 44px;
  display: inline-flex;
  align-items: center;
}
header.app-header nav a:hover { color: #fff; background: rgba(255, 255, 255, 0.08); }
/* "Log out" is a POST form (CSRF-protected) styled to read like the other nav links. */
header.app-header nav form.nav-logout { display: inline; margin: 0; }
header.app-header nav form.nav-logout button {
  background: none; border: 0; cursor: pointer; font: inherit;
  color: rgba(255, 255, 255, 0.82); margin-left: 6px; font-size: 0.92rem; font-weight: 500;
  padding: 8px 10px; border-radius: var(--radius-sm); min-height: 44px;
}
header.app-header nav form.nav-logout button:hover { color: #fff; background: rgba(255, 255, 255, 0.08); }
header.app-header nav a.active { color: #fff; }
header.app-header nav a.active::before {
  content: "";
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--gold-light);
  margin-right: 7px;
}

/* ---------- Layout ---------- */

main {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 20px 16px 48px;
}

.card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 16px;
  background: var(--bg);
  box-shadow: var(--shadow-sm);
}

.muted { color: var(--muted); font-size: 0.9rem; }

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 12px 20px;
  min-height: 44px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--navy);
  background: var(--navy);
  color: #fff;
  font-family: var(--sans);
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
  text-decoration: none;
  text-align: center;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}
.btn:hover { background: var(--navy-2); border-color: var(--navy-2); }
.btn.secondary { background: transparent; color: var(--navy); border: 1px solid var(--navy); }
.btn.secondary:hover { background: var(--bg-soft); }
.btn.danger { background: transparent; color: var(--danger); border-color: var(--danger); }
.btn.danger:hover { background: #fbeceb; }
.btn.gold { background: var(--gold); border-color: var(--gold); color: #fff; }
.btn.gold:hover { background: var(--gold-ink); border-color: var(--gold-ink); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ---------- Forms ---------- */

label { display: block; margin: 14px 0 6px; font-weight: 600; font-size: 0.9rem; color: var(--ink); }
label[style*="font-weight:normal"] { font-weight: 400; }

input[type=text], input[type=email], input[type=number], input[type=date], textarea, select {
  width: 100%;
  padding: 12px 14px;
  min-height: 48px;
  font-family: var(--sans);
  font-size: 1rem;
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
}
input:focus, textarea:focus, select:focus, button:focus-visible, a.btn:focus-visible {
  outline: 2px solid var(--gold-light);
  outline-offset: 1px;
}
textarea { min-height: 90px; padding-top: 12px; }
input[type=checkbox] { width: 20px; height: 20px; vertical-align: middle; margin-right: 8px; }

/* Native file input is visually hidden (kept in the tab order and fully
   functional — a <label for=...> click on its dropzone still opens the
   camera/file picker) in favor of the styled .dropzone label that follows
   it in markup; input:focus-visible + .dropzone gives it a visible focus
   ring since the input itself is off-screen. */
input[type=file].sr-only:focus-visible + .dropzone {
  outline: 2px solid var(--gold-light);
  outline-offset: 2px;
}

.dropzone {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 48px;
  padding: 14px;
  border: 2px dashed var(--line);
  border-radius: var(--radius-sm);
  background: var(--bg-soft);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 0.92rem;
  cursor: pointer;
}
.dropzone:hover { border-color: var(--gold-light); background: #f4f0e6; }
.dropzone-icon { font-size: 1.25rem; line-height: 1; flex: none; }
/* Text + filename stack vertically in one column, rather than sharing a
   row — at phone widths a filename next to "Take a photo / choose file"
   had nowhere to go but an awkward two-line wrap fighting for space. */
.dropzone-body { display: flex; flex-direction: column; gap: 2px; min-width: 0; flex: 1; }
.dropzone-text { font-weight: 600; }
.dropzone-filename {
  color: var(--muted);
  font-size: 0.82rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* 6-digit login code: large, spaced, numeric-styled entry. */
#code {
  font-family: var(--sans);
  font-size: 1.7rem;
  font-weight: 600;
  letter-spacing: 0.5em;
  text-align: center;
  padding-left: 0.6em; /* re-center the glyphs against the trailing letter-spacing */
}

.error { color: var(--danger); font-size: 0.88rem; margin-top: 6px; }
.notice {
  background: var(--bg-cream);
  border: 1px solid var(--gold-light);
  color: var(--gold-ink);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  margin-bottom: 14px;
}
.notice.success { background: #eef4ef; border-color: #bcd6c2; color: #2f5240; }

/* ---------- Tables (stack into cards on narrow screens) ---------- */

table { border-collapse: collapse; width: 100%; margin: 14px 0; font-size: 0.9rem; }
th, td { border-bottom: 1px solid var(--line); padding: 10px 10px; text-align: left; }
th { background: transparent; color: var(--navy); font-family: var(--serif); font-weight: 700; font-size: 1rem; border-bottom: 2px solid var(--line); }

@media (max-width: 640px) {
  table.stack, table:not(.no-stack) {
    border: 0;
  }
  table.stack thead, table:not(.no-stack) thead {
    display: none;
  }
  table.stack tr, table:not(.no-stack) tr {
    display: block;
    background: var(--bg);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    margin-bottom: 12px;
    padding: 6px 4px;
  }
  table.stack td, table:not(.no-stack) td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    border-bottom: 1px solid var(--bg-soft);
    padding: 8px 10px;
    text-align: right;
    /* A long unbroken value — a raw JSON audit blob, a user-agent string,
       a UUID — has no spaces for the browser's default word-wrap to break
       on, so without this it forces the cell (and the whole page) wider
       than the viewport instead of wrapping. min-width:0 lets this flex
       item actually shrink below its content's reported min-content size
       in the first place; overflow-wrap/word-break do the wrapping once
       it has. */
    min-width: 0;
    overflow-wrap: anywhere;
    word-break: break-word;
  }
  table.stack td:last-child, table:not(.no-stack) td:last-child { border-bottom: 0; }
  table.stack td::before, table:not(.no-stack) td::before {
    content: attr(data-label);
    font-weight: 600;
    color: var(--muted);
    text-align: left;
    margin-right: auto;
  }
}

/* ---------- Status pills ---------- */

.badge {
  display: inline-block;
  padding: 4px 11px;
  border-radius: 999px;
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}
.badge.confirmed { background: #e4e9f3; color: var(--navy); }
.badge.requested { background: var(--bg-cream); color: var(--gold-ink); border: 1px solid var(--gold-light); }
.badge.booked { background: #e4e9f3; color: var(--navy); }
.badge.declined, .badge.cancelled { background: var(--bg-soft); color: var(--muted); }
.badge.completed { background: #e7ede8; color: #3f6b52; }
.badge.maintenance, .badge.unavailable { background: #f4e8e1; color: #7a3e2a; }

/* ---------- Calendar ---------- */

/* minmax(0,1fr), not a bare 1fr: a grid track's default min-width is
   "auto" (its content's min-content size), so 7 equal tracks with any
   wide-enough content (an uppercase status pill, in particular) refuse to
   shrink below that content and blow out the grid — and with it the page
   — past the viewport on a narrow phone. minmax(0,1fr) removes that floor
   so tracks actually share the row's width; min-width:0 + overflow:hidden
   on each cell is the matching belt-and-suspenders in case anything
   inside still tries to report an intrinsic width wider than its track. */
.cal-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 4px; }
.cal-day {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  min-height: 52px;
  min-width: 0;
  padding: 4px;
  font-size: 0.74rem;
  position: relative;
  overflow: hidden;
  background: var(--bg);
}
.cal-day .num { font-weight: 700; color: var(--muted); font-size: 0.78rem; }
.cal-day.today { border-color: var(--gold); border-width: 2px; box-shadow: 0 0 0 1px var(--gold) inset; }
.cal-day.booked { background: #e9edf5; border-color: #cdd6e6; }
.cal-day.own { background: #f7eedd; border-color: var(--gold-light); }
.cal-day.own.today { box-shadow: 0 0 0 1px var(--gold) inset, 0 0 0 3px rgba(176, 138, 70, 0.18); }

/* The full status pill (cal-badge) inside a cell — shown ≥481px. */
.cal-day .cal-badge { display: block; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* A free day's "+" — a subtle corner mark, not a button. */
.cal-day a.add {
  position: absolute;
  bottom: 3px;
  right: 5px;
  color: var(--gold-light);
  text-decoration: none;
  font-weight: 400;
  font-size: 0.95em;
  opacity: 0.7;
  line-height: 1;
}
.cal-day a.add:hover { opacity: 1; }

.cal-dow { font-size: 0.68rem; text-align: center; color: var(--muted); font-weight: 700; text-transform: uppercase; padding: 4px 0; }

/* ≤480px: swap the full pill for a compact colored bar along the cell's
   bottom edge — a day number plus a status pill's worth of uppercase text
   is too much for a ~48px-wide cell to hold without truncation or overflow.
   Booked (someone else, navy) is solid; an own confirmed/completed booking
   (gold) is solid; an own still-*requested* booking is a gold outline only
   — not yet on the books, so it reads lighter than a confirmed one. */
@media (max-width: 480px) {
  .cal-day .cal-badge { display: none; }
  .cal-day.own, .cal-day.booked { padding-bottom: 8px; }
  .cal-day.own::after, .cal-day.booked::after {
    content: "";
    position: absolute;
    left: 4px;
    right: 4px;
    bottom: 3px;
    height: 4px;
    border-radius: 2px;
    background: var(--gold);
  }
  .cal-day.booked::after { background: var(--navy); }
  .cal-day.own[data-own-status="requested"]::after {
    background: transparent;
    border: 1.5px solid var(--gold);
    height: 2px;
  }
}

.cal-legend { display: flex; flex-wrap: wrap; gap: 14px; margin: 10px 0 18px; font-size: 0.82rem; color: var(--muted); }
.cal-legend-item { display: inline-flex; align-items: center; gap: 6px; }
.cal-legend-swatch { width: 14px; height: 14px; border-radius: 4px; display: inline-block; flex: none; }
.cal-legend-booked { background: var(--navy); }
.cal-legend-own-confirmed { background: var(--gold); }
.cal-legend-own-requested { background: transparent; border: 1.5px solid var(--gold); }

@media (min-width: 640px) {
  .cal-day { min-height: 90px; padding: 6px; font-size: 0.8rem; }
}

/* ---------- KPI cards (owner dashboard) ---------- */

.kpi-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 20px; }
.kpi-card {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 16px;
}
.kpi-card .kpi-num { font-family: var(--serif); font-size: 2.1rem; font-weight: 700; color: var(--navy); line-height: 1; }
.kpi-card .kpi-label { color: var(--muted); font-size: 0.82rem; margin-top: 6px; }
.kpi-card.attn .kpi-num { color: var(--gold-ink); }

.photo-thumb { width: 92px; height: 92px; object-fit: cover; border-radius: var(--radius-sm); border: 1px solid var(--line); margin: 4px; }

footer.app-footer { text-align: center; color: var(--muted); font-size: 0.8rem; padding: 28px 16px; }

/* ---------- Login page ---------- */

.login-wrap {
  max-width: 420px;
  margin: 6vh auto 0;
  padding: 0 4px;
}
.login-wordmark {
  text-align: center;
  margin-bottom: 24px;
}
.login-wordmark .brand-name {
  font-family: var(--serif);
  font-weight: 700;
  color: var(--navy);
  font-size: 1.9rem;
  display: block;
}
.login-wordmark .tagline {
  color: var(--muted);
  font-size: 0.88rem;
  margin-top: 2px;
}
.login-wrap h1 { text-align: center; }

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (min-width: 720px) {
  main { padding: 32px 24px 56px; }
  /* A form standing alone as its own card (login, request, handoff, trip
     log, settings) reads better at a document-ish width than stretched
     edge-to-edge on a wide screen; tables and the owner dashboard's own
     cards are untouched. */
  form.card { max-width: 640px; }
}
