:root {
  --bg: #0f1216;
  --surface: #171b21;
  --surface-2: #1f242c;
  --border: #2a303a;
  --text: #e8eaed;
  --text-dim: #9aa4b2;
  --accent: #4f8cff;
  --accent-dim: #2c4b82;
  --good: #34c77b;
  --bad: #f0555a;
  --warn: #e0a53a;
  --radius: 10px;
  font-size: 15px;
  /* Tells the browser to draw native widgets (date-picker popup, select
     dropdown list, scrollbars, checkboxes) in dark mode instead of the
     OS-default light theme, and to tint their accent highlight with our
     own blue instead of the system default. */
  color-scheme: dark;
  accent-color: var(--accent);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.app-shell {
  max-width: 1180px;
  margin: 0 auto;
  padding: 0 20px 60px;
}

/* Nav */
@media (min-width: 701px) {
  .topnav .brand { order: 1; }
  .topnav nav { order: 2; }
  .topnav .user-actions { order: 3; }
}

.build-stamp {
  font-size: 0.68rem;
  color: var(--text-dim);
  opacity: 0.55;
  font-variant-numeric: tabular-nums;
}

.topnav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 28px;
  flex-wrap: wrap;
}

.topnav .brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--text);
  white-space: nowrap;
}

.brand-icon {
  width: 24px;
  height: 24px;
  border-radius: 6px;
  flex: 0 0 auto;
}

.topnav nav {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}

.topnav nav a {
  color: var(--text-dim);
  padding: 8px 12px;
  border-radius: var(--radius);
  font-size: 0.92rem;
}

.topnav nav a:hover { color: var(--text); text-decoration: none; background: var(--surface-2); }
.topnav nav a.active { color: var(--text); background: var(--surface-2); }

.topnav .user-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 0.85rem;
  color: var(--text-dim);
}

.btn-link {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 0.85rem;
  padding: 0;
}
.btn-link:hover { color: var(--text); text-decoration: underline; }

/* Cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
}

/* NOTE: deliberately no `.card + .card { margin-top }` rule. Cards that
   need top spacing set it inline, and a sibling rule would also match the
   second card of a side-by-side grid pair — pushing it 16px down and
   making it 16px shorter than its neighbour. */

.card h2, .card h3 {
  margin-top: 0;
}

.grid {
  display: grid;
  gap: 16px;
}

/* Six stats, laid out so every row is full: 3x2, then 2x3, then stacked.
   auto-fit would leave a ragged trailing row at some widths. */
.stat-row {
  grid-template-columns: repeat(3, 1fr);
}

@media (max-width: 1000px) {
  .stat-row { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 560px) {
  .stat-row { grid-template-columns: 1fr; }
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
}

.stat-card .label {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-dim);
  margin-bottom: 6px;
}

.stat-card .value {
  font-size: 1.5rem;
  font-weight: 700;
}

.stat-card .value.good { color: var(--good); }
.stat-card .value.bad { color: var(--bad); }

.two-col {
  grid-template-columns: 1fr 1fr;
}

@media (max-width: 860px) {
  .two-col { grid-template-columns: 1fr; }
}

/* Forms */
form.entry-form {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
  align-items: end;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.field label {
  font-size: 0.8rem;
  color: var(--text-dim);
}

input, select, textarea {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 9px 10px;
  font-size: 0.92rem;
  font-family: inherit;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
}

/* A toggle that's currently open — reads as pressed, and makes it obvious
   that clicking again closes it. */
button.is-open {
  background: var(--surface-2);
  color: var(--text-dim);
  border: 1px solid var(--border);
}
button.is-open:hover { background: var(--border); color: var(--text); }

button, .btn {
  background: var(--accent);
  color: white;
  /* Transparent rather than none: inputs and selects carry a 1px border,
     so a borderless button sits 2px shorter beside them. */
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 9px 16px;
  font-size: 0.92rem;
  /* Without this a button falls back to the browser's own button font,
     which renders at a different height than the inputs beside it. */
  font-family: inherit;
  cursor: pointer;
  font-weight: 600;
  white-space: nowrap;
}

button:hover { background: #3f76e0; }
button.secondary { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); }
button.secondary:hover { background: var(--border); }
button.danger { background: transparent; color: var(--bad); border: 1px solid var(--bad); padding: 5px 10px; font-size: 0.8rem; }
button.danger:hover { background: var(--bad); color: white; }
button:disabled { opacity: 0.5; cursor: not-allowed; }

/* Tables */
.table-wrap { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}

th, td {
  text-align: left;
  padding: 9px 10px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

th {
  color: var(--text-dim);
  font-weight: 600;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  cursor: pointer;
  user-select: none;
}

th:hover { color: var(--text); }

tbody tr:hover { background: var(--surface-2); }

.filters {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 14px;
  align-items: end;
}

.badge {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 0.74rem;
  font-weight: 600;
  text-transform: capitalize;
}

.badge.booked { background: #3a3f2c; color: var(--warn); }
.badge.shot { background: #2c3a3f; color: #59c3e0; }
.badge.delivered { background: #2c3a4f; color: var(--accent); }
.badge.paid { background: #1f3a2c; color: var(--good); }
/* Logged offline, not yet on the server. */
.pending-row td:first-child::after {
  content: 'Pending';
  display: inline-block;
  margin-left: 8px;
  padding: 2px 8px;
  border-radius: 999px;
  background: #3a352c;
  color: var(--warn);
  font-size: 0.7rem;
  font-weight: 600;
  white-space: nowrap;
}

.empty-state {
  color: var(--text-dim);
  padding: 30px 10px;
  text-align: center;
  font-size: 0.9rem;
}

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
  flex-wrap: wrap;
  gap: 10px;
}

.hint {
  color: var(--text-dim);
  font-size: 0.8rem;
}

.error-text {
  color: var(--bad);
  font-size: 0.85rem;
  min-height: 1.2em;
}

.actions-cell { display: flex; gap: 6px; }
.actions-cell button { padding: 5px 10px; font-size: 0.78rem; }

/* Combobox (custom dropdown replacing native <input list>) */
.combobox { position: relative; display: flex; }
.combobox input { width: 100%; padding-right: 26px; }
.combobox-toggle {
  position: absolute;
  right: 2px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  padding: 4px 7px;
  font-size: 0.7rem;
  line-height: 1;
}
.combobox-toggle:hover { color: var(--text); background: none; }
.combobox-menu {
  /* Position (top/left) is always set in JS from the anchor's bounding box.
     Width hugs the longest option rather than stretching to the viewport
     edge — no `right` anchor here, or a fixed-position menu would span the
     whole remaining screen width. */
  position: fixed;
  width: max-content;
  max-width: 320px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  max-height: 220px;
  overflow-y: auto;
  z-index: 30;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}
.combobox-option { padding: 8px 10px; font-size: 0.86rem; cursor: pointer; }
.combobox-option:hover { background: var(--accent-dim); }
.combobox-empty { padding: 8px 10px; font-size: 0.78rem; color: var(--text-dim); }

/* Inline cell editing — hover highlights just the value (like the original
   status badge did), not the whole table cell, so it doesn't turn into a
   wide empty-looking box on columns wider than their content. */
.editable-cell { cursor: pointer; }
.editable-cell .ev { display: inline-block; border-radius: 4px; padding: 2px 5px; margin: -2px -5px; }
.editable-cell:hover .ev { outline: 1px dashed var(--text-dim); outline-offset: 0; background: var(--surface-2); }
.editable-cell:hover .badge { outline: 1px dashed var(--text-dim); outline-offset: 2px; }
.inline-edit-input { min-width: 130px; padding: 5px 8px; font-size: 0.85rem; }
select.inline-edit-input { min-width: 110px; }

/* Hours + minutes pickers sitting side by side in one cell */
.duration-edit { display: inline-flex; gap: 6px; flex-wrap: wrap; }
.duration-edit select.inline-edit-input { min-width: 68px; }
.duration-edit input.duration-text { width: 104px; }
.duration-picker { display: flex; gap: 8px; flex-wrap: wrap; }
.duration-picker select { flex: 1; min-width: 72px; }
.duration-picker input { flex: 1.4; min-width: 104px; }

/* Chart sizing — the box owns the height, not the canvas's aspect ratio. */
.chart-box { position: relative; height: 340px; }

/* Expanded: the card lifts out over the page so the chart gets the whole
   screen. On a phone that's the difference between a readable trend and a
   flat squiggle. */
.card.chart-expanded {
  position: fixed;
  inset: 0;
  z-index: 60;
  margin: 0;
  border-radius: 0;
  display: flex;
  flex-direction: column;
  padding: 14px 16px calc(14px + env(safe-area-inset-bottom));
}

.card.chart-expanded .chart-box {
  flex: 1 1 auto;
  height: auto;
  min-height: 0;
}

/* Stop the page behind it scrolling under the expanded chart. */
body.chart-expanded-open { overflow: hidden; }

/* Chart controls: the Cumulative switch beside the chart-type picker */
.chart-controls { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.chart-controls #chart-expand { flex: 0 0 auto; }

.switch {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  font-size: 0.88rem;
  color: var(--text-dim);
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
}
/* The real checkbox stays in the page for keyboard and screen readers;
   the track beside it is what you see. */
.switch input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
  min-height: 0;
  margin: 0;
  padding: 0;
  border: 0;
}
.switch-track {
  position: relative;
  flex: 0 0 auto;
  width: 40px;
  height: 24px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  transition: background 0.15s, border-color 0.15s;
}
.switch-track::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--text-dim);
  transition: transform 0.15s, background 0.15s;
}
.switch input:checked + .switch-track { background: var(--accent); border-color: var(--accent); }
.switch input:checked + .switch-track::after { transform: translateX(16px); background: #fff; }
.switch input:checked ~ .switch-label { color: var(--text); }
.switch input:focus-visible + .switch-track { outline: 2px solid var(--accent); outline-offset: 2px; }
.switch input:disabled + .switch-track,
.switch input:disabled ~ .switch-label { opacity: 0.4; }
.switch:has(input:disabled) { cursor: not-allowed; }

@media (max-width: 700px) {
  .chart-controls { width: 100%; }
  .chart-controls select { flex: 1; min-width: 0; }
}

/* Table toolbar (export / undo / redo) */
.toolbar { display: flex; gap: 8px; align-items: center; }
.toolbar button {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 7px 12px;
  font-size: 0.85rem;
  font-weight: 500;
}
.toolbar button:hover:not(:disabled) { background: var(--border); }
.toolbar button:disabled { opacity: 0.35; cursor: not-allowed; }

/* Offline notice */
.offline-banner {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--warn);
  color: #241a05;
  font-size: 0.84rem;
  font-weight: 600;
  text-align: center;
  padding: 10px 14px;
  z-index: 120;
  /* Clear of the iPhone home indicator */
  padding-bottom: calc(10px + env(safe-area-inset-bottom));
}

/* Toasts */
.toast-stack {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 100;
  align-items: center;
}

.toast {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 11px 12px 11px 16px;
  font-size: 0.88rem;
  color: var(--text);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  animation: toast-in 0.18s ease-out;
}

.toast.leaving { opacity: 0; transition: opacity 0.18s ease-in; }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

.toast-action {
  background: none;
  border: none;
  color: var(--accent);
  font-weight: 600;
  font-size: 0.88rem;
  padding: 2px 4px;
  cursor: pointer;
}
.toast-action:hover { background: none; text-decoration: underline; }

.toast-close {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 1.1rem;
  line-height: 1;
  padding: 0 4px;
  cursor: pointer;
}
.toast-close:hover { background: none; color: var(--text); }

/* ---------------------------------------------------------------------
   Phones. A 10-column table can't be made readable at 390px by scrolling
   it — you end up unable to see a client and their amount at the same
   time — so each row becomes its own card with the column name as a label
   beside the value. Controls also grow to a 44px minimum, which is the
   smallest reliable thumb target.
   --------------------------------------------------------------------- */
@media (max-width: 700px) {
  .app-shell { padding: 0 12px 48px; }

  /* Row-as-card */
  .table-wrap { overflow-x: visible; }
  .table-wrap thead { display: none; }
  .table-wrap table,
  .table-wrap tbody,
  .table-wrap tr,
  .table-wrap td { display: block; width: 100%; }

  .table-wrap tr {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 6px 14px;
    margin-bottom: 10px;
  }
  .table-wrap tr:hover { background: var(--surface-2); }

  .table-wrap td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 14px;
    text-align: right;
    white-space: normal;
    border: none;
    border-bottom: 1px solid var(--border);
    padding: 9px 0;
    min-height: 44px;
  }
  .table-wrap tr td:last-child { border-bottom: none; }

  /* The column heading, carried over as a label on each value */
  .table-wrap td::before {
    content: attr(data-label);
    color: var(--text-dim);
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    text-align: left;
    flex: 0 0 auto;
  }
  .table-wrap td:not([data-label])::before { content: none; }

  /* Edit / Delete / Duplicate sit on their own full-width row */
  .table-wrap td.actions-cell { justify-content: flex-end; padding: 10px 0 6px; }
  .table-wrap td.actions-cell button { flex: 1; min-height: 44px; font-size: 0.85rem; }

  /* Tap targets */
  input, select, textarea, button, .btn { min-height: 44px; }
  .toolbar { width: 100%; }
  .toolbar button { flex: 1; }
  .btn-link { min-height: 44px; padding: 0 4px; }
  .topnav nav a { min-height: 44px; display: flex; align-items: center; }

  /* One field per row — two half-width dropdowns are hard to hit */
  .filters { flex-direction: column; align-items: stretch; gap: 12px; }
  .filters .field { width: 100%; }
  .filters button { width: 100%; }

  form.entry-form { grid-template-columns: 1fr; }

  /* Header: keep the brand and nav, drop the wasted vertical space */
  /* Breathing room under the iPhone status bar / notch. The app runs
     full-bleed (viewport-fit=cover with a translucent status bar), so
     without this the title sits under the clock and reads as cropped. */
  .topnav {
    padding: max(28px, calc(18px + env(safe-area-inset-top))) 12px 12px;
    gap: 10px;
    margin-bottom: 18px;
  }

  /* Stacked order: name and logo, then who's signed in, then the tabs. */
  .topnav .brand { order: 1; }
  .topnav .user-actions { order: 2; }
  .topnav nav { order: 3; }
  /* All five tabs on one row. "Subscriptions" is the long one, so the type
     shrinks and the padding tightens rather than letting Gear wrap onto a
     second line. overflow-x is the safety valve on very narrow phones. */
  .topnav nav {
    width: 100%;
    gap: 2px;
    flex-wrap: nowrap;
    justify-content: space-between;
    overflow-x: auto;
    scrollbar-width: none;
  }
  .topnav nav::-webkit-scrollbar { display: none; }
  .topnav nav a {
    flex: 0 1 auto;
    justify-content: center;
    padding: 8px 6px;
    font-size: 0.78rem;
    white-space: nowrap;
  }

  /* A phone screen is mostly vertical — give the chart more of it. */
  .chart-box { height: 300px; }
  .topnav .user-actions { width: 100%; justify-content: space-between; }

  .section-header { align-items: stretch; }
  .stat-card .value { font-size: 1.35rem; }
}

/* Auth page */
.auth-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px 28px;
}

.auth-card h1 {
  font-size: 1.3rem;
  margin: 0 0 4px;
}

.auth-card p.sub {
  color: var(--text-dim);
  font-size: 0.85rem;
  margin: 0 0 22px;
}

.auth-card form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.auth-card button { width: 100%; padding: 11px; margin-top: 4px; }
