/* Colors live here as variables so light and dark mode only swap values. */
:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --text: #16181d;
  --muted: #5f6672;
  --border: #e2e5ea;
  --work: #0f766e;
  --work-soft: #d7f0ec;
  --break: #b45309;
  --break-soft: #fbead3;
  --danger: #b42318;
  --radius: 14px;
  /* Filled button colors. Same in light and dark mode, picked so their text stays readable. */
  --go: #0f766e;      /* green: Start Work, End Break, Save */
  --pause: #f5b800;   /* yellow: Start Break */
  --pause-text: #241a00;
  --stop: #c62828;    /* red: Clock Out, Cancel */
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1013;
    --surface: #181b20;
    --text: #eef0f3;
    --muted: #9aa1ac;
    --border: #2a2f37;
    --work: #2dd4bf;
    --work-soft: #12332f;
    --break: #f59e0b;
    --break-soft: #3a2a10;
    --danger: #f97066;
  }
}

* { box-sizing: border-box; }

/* Anything marked hidden stays hidden, even if a layout rule (like .field { display: grid }) says otherwise. */
[hidden] { display: none !important; }

html, body { margin: 0; }

/* No double-tap zoom: two quick taps on a heading should open and close it, not zoom.
   Pinch zoom is blocked in app.js. */
html { touch-action: manipulation; }

body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  -webkit-tap-highlight-color: transparent;
  /* Keep content clear of the notch and home bar on iPhone. */
  padding: env(safe-area-inset-top) env(safe-area-inset-right) 0 env(safe-area-inset-left);
}

main {
  max-width: 560px;
  margin: 0 auto;
  padding: 16px 16px calc(88px + env(safe-area-inset-bottom));
}

h1 { font-size: 28px; margin: 8px 0 16px; }
h2 { font-size: 18px; margin: 0 0 6px; }
p { margin: 0 0 12px; color: var(--muted); }

/* ---- Test copy ---- */

.beta-strip {
  background: #f97316;
  color: #1c0d00;
  text-align: center;
  font-size: 13px;
  font-weight: 700;
  padding: 4px 12px;
}

/* ---- Clock screen ---- */

.status-pill {
  display: inline-block;
  margin: 12px 0 0;
  padding: 4px 12px;
  border-radius: 999px;
  background: var(--border);
  color: var(--text);
  font-weight: 600;
  font-size: 14px;
}
body[data-status="working"] .status-pill { background: var(--work-soft); color: var(--work); }
body[data-status="break"] .status-pill { background: var(--break-soft); color: var(--break); }

.hero { text-align: center; padding: 32px 0 24px; }
.hero-label { color: var(--muted); font-weight: 600; }
.hero-time {
  font-size: clamp(56px, 18vw, 84px);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: -1px;
}
body[data-status="working"] .hero-time { color: var(--work); }
body[data-status="break"] .hero-time { color: var(--break); }
.since { color: var(--muted); min-height: 1.4em; }

.stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 20px;
}
.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
}
.stat-label { color: var(--muted); font-size: 13px; }
.stat-value { font-size: 22px; font-weight: 600; font-variant-numeric: tabular-nums; }

.actions { display: grid; gap: 10px; }

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

.button {
  display: block;
  width: 100%;
  min-height: 56px;
  padding: 14px 18px;
  border: 0;
  border-radius: var(--radius);
  background: var(--go);
  color: #fff;
  font: inherit;
  font-size: 18px;
  font-weight: 600;
  text-align: center;
  cursor: pointer;
}
.button:active { opacity: 0.8; }
.button.break { background: var(--pause); color: var(--pause-text); }
.button.stop { background: var(--stop); }
.button.secondary { background: var(--surface); color: var(--text); border: 1px solid var(--border); }
.button.danger { background: transparent; color: var(--danger); border: 1px solid var(--danger); }
.button.small { min-height: 40px; padding: 8px 12px; font-size: 15px; width: auto; }
.button + .button { margin-top: 10px; }

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* ---- Cards (More screen) ---- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
}
.card.danger { border-color: var(--danger); }

.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 10px; }

select, input[type="text"] {
  font: inherit;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
}
.field { display: grid; gap: 6px; }
.field span { color: var(--muted); font-size: 14px; }

.log-view {
  max-height: 320px;
  overflow: auto;
  margin: 0;
  padding: 10px;
  background: var(--bg);
  border-radius: 10px;
  font: 12px/1.4 ui-monospace, Menlo, Consolas, monospace;
  white-space: pre-wrap;
  word-break: break-word;
}

.import-report { margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--border); }
.import-report .file { margin-bottom: 10px; }
.import-report .file strong { word-break: break-all; }
.import-report .error { color: var(--danger); }
.import-report details { color: var(--muted); font-size: 14px; }
.import-report ul { padding-left: 18px; margin: 6px 0; }

.footer { text-align: center; font-size: 13px; }

/* ---- History ---- */

/* Years hold month cards; month cards hold weeks and shift lines.
   Year and month headings are buttons that open and close them. */
.year { margin-bottom: 22px; }
.empty { text-align: center; padding: 40px 0; }
.month { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 10px; overflow: hidden; }

.year-head,
.month-head {
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr) auto;
  column-gap: 6px;
  align-items: baseline;
  width: 100%;
  border: 0;
  background: none;
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
  font-variant-numeric: tabular-nums;
}
.year-head { padding: 4px 4px 10px; }
.month-head { padding: 12px 14px; }
.year-head:active, .month-head:active { opacity: 0.6; }
.year-head .label { font-size: 22px; font-weight: 800; }
.year-head .total { font-size: 20px; font-weight: 800; color: var(--work); }
.month-head .label, .month-head .total { font-weight: 700; }
.month-head .total { color: var(--work); }
/* A drawn chevron: points right when closed, turns to point down when open. */
.chev {
  width: 22px;
  height: 22px;
  align-self: center;
  fill: none;
  stroke: var(--muted);
  stroke-width: 3;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: transform 0.15s;
}
[aria-expanded="true"] > .chev { transform: rotate(90deg); }
.sub { grid-column: 2 / 4; color: var(--muted); font-size: 13px; }

.week-head {
  display: flex;
  justify-content: space-between;
  padding: 8px 14px 6px;
  border-top: 1px solid var(--border);
  background: var(--bg);
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.shift-row {
  display: grid;
  grid-template-columns: 6.4em minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  width: 100%;
  min-height: 46px;
  padding: 0 14px;
  border: 0;
  border-top: 1px solid var(--border);
  background: none;
  color: var(--text);
  font: inherit;
  font-size: 15px;
  font-variant-numeric: tabular-nums;
  text-align: left;
  cursor: pointer;
}
.shift-row:active { background: var(--bg); }
.shift-row .day-name { font-weight: 600; white-space: nowrap; }
/* Too long to fit? End it with "…" instead of wrapping. */
.shift-row .times { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.shift-row .worked { font-weight: 600; text-align: right; }

.title-row { display: flex; justify-content: space-between; align-items: center; }

/* ---- Clock screen extras ---- */

body[data-status="scheduled"] .status-pill { background: var(--work-soft); color: var(--work); }

.link-row { display: flex; flex-wrap: wrap; justify-content: center; gap: 4px 18px; margin-top: 14px; }
.link-button {
  border: 0;
  background: none;
  color: var(--work);
  font: inherit;
  font-size: 15px;
  font-weight: 600;
  padding: 8px 4px;
  cursor: pointer;
}

.banner {
  background: var(--break-soft);
  color: var(--text);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-top: 12px;
}
.banner p { color: var(--text); margin-bottom: 8px; }

/* ---- Popups (dialogs) ---- */

.sheet {
  width: min(520px, calc(100% - 24px));
  max-height: calc(100% - 24px);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 18px;
  background: var(--surface);
  color: var(--text);
}
.sheet::backdrop { background: rgb(0 0 0 / 0.45); }
.sheet form { display: grid; gap: 12px; }
.sheet h2 { margin: 0; }
.sheet p { margin: 0; }
.sheet input[type="date"],
.sheet input[type="time"],
.sheet input[type="text"],
.sheet textarea {
  width: 100%;
  font: inherit;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
}
/* iOS shrinks date and time inputs to fit their text unless told otherwise. */
.sheet input[type="date"],
.sheet input[type="time"] { min-height: 46px; -webkit-appearance: none; appearance: none; text-align: left; }

/* Cancel / title / Save across the top, like Apple's own apps. */
.sheet-bar {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 10px;
  margin-bottom: 4px;
}
.sheet-bar h2 { font-size: 16px; line-height: 1.25; text-align: center; outline: none; }
.bar-button {
  min-width: 92px;
  min-height: 48px;
  padding: 10px 16px;
  border: 0;
  border-radius: 12px;
  font: inherit;
  font-size: 17px;
  font-weight: 700;
  color: #fff;
  cursor: pointer;
}
.bar-button:active { opacity: 0.8; }
.bar-button.cancel { background: var(--stop); }
.bar-button.strong { background: var(--go); }
.bar-button:disabled { background: var(--border); color: var(--muted); }

.date-time { display: grid; grid-template-columns: 1.3fr 1fr; gap: 10px; }
.date-time.three { grid-template-columns: 1.4fr 1fr 1fr; }
.date-time.three.running { grid-template-columns: 1.4fr 1fr; }
.date-time .field { min-width: 0; }

/* Keep Delete well away from everything else. */
.delete-shift { margin-top: 28px; }

.break-row { display: grid; grid-template-columns: 1fr auto 1fr auto; gap: 6px; align-items: center; margin-bottom: 8px; }
.break-row input { min-width: 0; }
.break-row .to { color: var(--muted); font-size: 14px; }
.break-row .remove { border: 0; background: none; color: var(--danger); font-size: 22px; padding: 4px 8px; }
.break-row .running { color: var(--break); font-size: 14px; }

.summary { font-weight: 600; font-variant-numeric: tabular-nums; }
.hint { color: var(--muted); font-size: 14px; }
.form-error { color: var(--danger); margin: 0; padding-left: 18px; font-size: 14px; }
.form-error:empty { display: none; }
p.form-error { padding-left: 0; }

/* ---- Undo bar ---- */

.toast {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: calc(68px + env(safe-area-inset-bottom));
  max-width: 536px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border-radius: var(--radius);
  background: var(--text);
  color: var(--bg);
  box-shadow: 0 6px 20px rgb(0 0 0 / 0.25);
}
.toast[hidden] { display: none; }
.toast button { border: 0; background: none; color: var(--work-soft); font: inherit; font-weight: 700; padding: 4px 8px; }

/* ---- Tab bar ---- */

.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar button {
  flex: 1;
  min-height: 56px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-size: 12px;
  border: 0;
  background: none;
  color: var(--muted);
  font: inherit;
  font-weight: 600;
}
.tabbar button[aria-current="page"] { color: var(--work); }

.tab-icon { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ---- Settings groups ---- */

.group-title {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin: 22px 4px 8px;
}
.card h3 { font-size: 17px; margin: 0 0 6px; }
details.card summary { list-style: none; cursor: pointer; display: flex; justify-content: space-between; align-items: center; }
details.card summary::-webkit-details-marker { display: none; }
details.card summary::after { content: "Show"; color: var(--work); font-weight: 600; font-size: 15px; }
details.card[open] summary::after { content: "Hide"; }
details.card summary h3 { margin: 0; }
details.card[open] summary { margin-bottom: 8px; }
.tabbar button { font-size: 12px; }

/* ---- Daily backup banner (Clock tab) ---- */

.backup-banner {
  display: flex;
  align-items: stretch;
  margin-top: 22px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.backup-banner[hidden] { display: none; }
.backup-main {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 60px;
  padding: 10px 14px;
  border: 0;
  background: none;
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.backup-main:active { background: var(--bg); }
.backup-main strong { display: block; font-size: 16px; }
.backup-sub { display: block; color: var(--muted); font-size: 13px; }
.backup-icon { width: 30px; height: 30px; flex: none; fill: none; stroke: var(--work); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.backup-dismiss {
  width: 52px;
  border: 0;
  border-left: 1px solid var(--border);
  background: none;
  color: var(--muted);
  font-size: 24px;
  cursor: pointer;
}
.last-backup { margin: 8px 0 0; }

/* ---- Jobs ---- */

.jobs-list { list-style: none; margin: 0 0 12px; padding: 0; }
.jobs-list li {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 48px;
  border-bottom: 1px solid var(--border);
}
.jobs-list li:last-child { border-bottom: 0; }
.jobs-list .job-name { flex: 1; min-width: 0; font-weight: 600; overflow-wrap: anywhere; }
.jobs-list .job-name small { display: block; color: var(--muted); font-weight: 400; font-size: 13px; }
.jobs-list li.hidden-job .job-name { color: var(--muted); }
.jobs-list button {
  border: 0;
  background: none;
  color: var(--work);
  font: inherit;
  font-size: 15px;
  font-weight: 600;
  padding: 10px 6px;
  cursor: pointer;
}
.jobs-list button.remove-job { color: var(--danger); }

.bar-spacer { min-width: 92px; }
.job-choices { display: grid; gap: 10px; }
.job-choices .button { text-align: left; }
.job-choices .button small { display: block; font-size: 13px; font-weight: 500; opacity: 0.85; }

.current-job { color: var(--text); font-weight: 700; margin-bottom: 4px; overflow-wrap: anywhere; }

/* History job filter: "Filter jobs" (smaller, up to 45% wide) and "All jobs" (bigger) side by side. */
.job-filter { display: grid; grid-template-columns: fit-content(45%) minmax(0, 1fr); gap: 8px; margin: 0 0 14px; }
.job-filter[hidden] { display: none; }
.job-filter button {
  flex: none;
  min-height: 40px;
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}
.job-filter button[aria-pressed="true"] { background: var(--go); border-color: var(--go); color: #fff; }
.job-filter .filter-button { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.job-filter .filter-button::after { content: " ▾"; }
/* The current choice in a pick-one popup. */
.job-choices.with-current .button.selected { outline: 3px solid var(--text); outline-offset: 2px; }
.job-choices.with-current .button:not(.selected) { background: var(--surface); color: var(--text); border: 1px solid var(--border); }

#shift-job { width: 100%; }

/* ---- Pay ---- */

.earned-card { margin: -10px 0 20px; }
.earned-card .stat-value { color: var(--work); }

.rate-row { display: grid; grid-template-columns: 1fr 1.2fr auto; gap: 6px; align-items: center; margin-bottom: 8px; }
.rate-row input { min-width: 0; }
.rate-row .remove { border: 0; background: none; color: var(--danger); font-size: 22px; padding: 4px 8px; }
.money-input { position: relative; }
.money-input::before { content: "$"; position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.money-input input { padding-left: 22px !important; width: 100%; }
.sheet input[type="number"] {
  font: inherit;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
}
.check { display: flex; align-items: center; gap: 10px; font-weight: 600; color: var(--text) !important; font-size: 16px !important; }
.check input { width: 22px; height: 22px; }
.ot-fields { display: grid; gap: 8px; color: var(--text); }
.ot-fields input { width: 5.5em; }
.ot-fields select { padding: 8px 10px; }
