/* Colors. Brand values come from config.js (BRAND) via app.js -> applyBrand().
   The fallbacks here are only used until that runs. Light/dark follows the phone,
   or the per-device choice in Settings (html[data-theme="light"|"dark"]). */
:root {
  --bg: #f5f3f0;      /* site --sand */
  --surface: #fbfaf8; /* site --paper */
  --text: #1c1e22;    /* site --ink */
  --muted: #5f6a72;   /* site --muted */
  --line: #e6e0d8;    /* site --line */
  --brand: var(--brand-l, #d71920);
  --brand-ink: var(--brand-ink-l, #ffffff);
  --header: var(--header-l, #161616);
  --header-ink: var(--header-ink-l, #ffffff);
  --accent: var(--accent-l, #f4b62b);
  --accent-ink: var(--accent-ink-l, #111111);
  --ok: #2f8f5b;      /* site --green */
  --ok-bg: #eaf5ee;
  --warn-bg: #fdf1d6;
  --danger: #af131a;  /* site --red-dark */
  --radius: 12px;
  --tap: 48px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121212;
    --surface: #1f1f1f;
    --text: #f2efea;
    --muted: #b3aea8;
    --line: #343230;
    --brand: var(--brand-d, #f0585d);
    --brand-ink: var(--brand-ink-d, #0f141a);
    --header: var(--header-d, #161616);
    --header-ink: var(--header-ink-d, #ffffff);
    --accent: var(--accent-d, #f4b62b);
    --accent-ink: var(--accent-ink-d, #0f141a);
    --ok: #6fcf97;
    --ok-bg: #16301f;
    --warn-bg: #33270f;
    --danger: #f28b82;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #121212;
  --surface: #1f1f1f;
  --text: #f2efea;
  --muted: #b3aea8;
  --line: #343230;
  --brand: var(--brand-d, #f0585d);
  --brand-ink: var(--brand-ink-d, #0f141a);
  --header: var(--header-d, #161616);
  --header-ink: var(--header-ink-d, #ffffff);
  --accent: var(--accent-d, #f4b62b);
  --accent-ink: var(--accent-ink-d, #0f141a);
  --ok: #6fcf97;
  --ok-bg: #16301f;
  --warn-bg: #33270f;
  --danger: #f28b82;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none; /* no pull-to-refresh bounce fighting the fixed tab bar */
}
a { color: var(--brand); }
h1, h2, h3 { margin: 0; line-height: 1.2; }

/* header + tabs */
.top {
  position: sticky; top: 0; z-index: 5;
  display: grid; grid-template-columns: 48px 1fr 48px; align-items: center;
  padding: calc(env(safe-area-inset-top, 0px) + 8px) 8px 8px;
  background: var(--header); color: var(--header-ink);
  border-bottom: 3px solid var(--accent);
}
.top h1 { font-size: 18px; text-align: center; }
.top .back { color: var(--header-ink); font-size: 32px; text-decoration: none; text-align: center; line-height: 1; }
main { max-width: 640px; margin: 0 auto; padding: 16px 16px calc(96px + var(--safe-b)); }
.tabs {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 5;
  display: grid; grid-template-columns: repeat(3, 1fr);
  background: var(--surface); border-top: 1px solid var(--line);
  padding-bottom: var(--safe-b);
}
.tabs a {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 8px 0; min-height: 56px; font-size: 12px; color: var(--muted); text-decoration: none;
}
.tabs a .ico { font-size: 20px; filter: grayscale(1); opacity: .7; }
.tabs a.on { color: var(--brand); font-weight: 600; }
.tabs a.on .ico { filter: none; opacity: 1; }

/* buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: var(--tap); padding: 0 18px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
  font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
}
.btn:disabled { opacity: .5; }
.btn.primary { background: var(--brand-fill, var(--brand)); color: var(--brand-fill-ink, var(--brand-ink)); border-color: var(--brand-fill, var(--brand)); }
.btn.danger { color: var(--danger); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--brand); padding: 0 10px; }
.btn.small { min-height: 36px; padding: 0 12px; font-size: 14px; }
.btn.block { width: 100%; }
.link { background: none; border: 0; color: var(--brand); font: inherit; padding: 12px 0; cursor: pointer; }
.fab {
  position: fixed; right: 16px; bottom: calc(72px + var(--safe-b)); z-index: 6;
  background: var(--accent); color: var(--accent-ink); font-weight: 700; text-decoration: none;
  padding: 14px 20px; border-radius: 28px; box-shadow: 0 6px 18px rgba(0,0,0,.2);
}

/* schedule */
.range { display: flex; justify-content: space-between; margin-bottom: 8px; }
h2.day { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 18px 0 8px; }
h2.day.today { color: var(--accent-text-l, #96690a); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) h2.day.today { color: var(--accent-text-d, var(--accent)); } }
:root[data-theme="dark"] h2.day.today { color: var(--accent-text-d, var(--accent)); }
.card {
  display: flex; align-items: center; gap: 12px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px 14px; margin-bottom: 8px; color: inherit; text-decoration: none; min-height: 64px;
}
.card .time { min-width: 66px; font-weight: 700; font-size: 15px; }
.card .body { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.card .body strong, .card .body .muted { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge { font-size: 11px; font-weight: 700; padding: 3px 8px; border-radius: 99px; background: var(--bg); color: var(--muted); white-space: nowrap; }
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.dim { opacity: .8; }
.pill { display: inline-block; font-size: 13px; padding: 2px 10px; border-radius: 99px; background: var(--bg); border: 1px solid var(--line); }

/* panels + forms */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 12px; }
.panel h2 { font-size: 20px; margin-bottom: 6px; }
.panel h3 { font-size: 15px; margin-bottom: 8px; }
.panel.ok { background: var(--ok-bg); border-color: transparent; }
.panel.warn { background: var(--warn-bg); border-color: transparent; }
.panel-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.panel-head h3 { margin: 0; }
.when { color: var(--muted); margin: 0 0 8px; }
.contact { display: flex; gap: 8px; flex-wrap: wrap; }
.actions { display: flex; gap: 8px; justify-content: space-between; }
.form { display: flex; flex-direction: column; gap: 14px; }
.form.panel { gap: 12px; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
label { display: flex; flex-direction: column; gap: 6px; font-size: 14px; font-weight: 600; color: var(--muted); }
label.check { flex-direction: row; align-items: center; gap: 10px; color: var(--text); font-weight: 500; }
label.check input { width: 22px; height: 22px; }
input, select, textarea {
  font: inherit; font-size: 16px; color: var(--text); background: var(--surface);
  border: 1px solid var(--line); border-radius: 10px; padding: 12px; min-height: var(--tap); width: 100%;
}
textarea { resize: vertical; }
/* iPhone Safari: date/time inputs shrink and misalign without these */
input[type="date"], input[type="time"] { -webkit-appearance: none; appearance: none; display: block; text-align: left; line-height: 22px; }
input::-webkit-date-and-time-value { text-align: left; }
.row > * { min-width: 0; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); outline-offset: 1px; }
fieldset { border: 1px dashed var(--line); border-radius: var(--radius); padding: 12px; display: flex; flex-direction: column; gap: 12px; }
legend { font-weight: 700; padding: 0 6px; }
.search { margin-bottom: 12px; }

.notes { list-style: none; margin: 14px 0 0; padding: 0; }
.notes li { border-top: 1px solid var(--line); padding: 10px 0; }
.notes li p { margin: 0 0 4px; }
#noteForm { display: flex; flex-direction: column; gap: 8px; }

.muted { color: var(--muted); }
.small { font-size: 13px; }
.pre { white-space: pre-wrap; }
.loading, .splash { color: var(--muted); padding: 32px 0; text-align: center; }
.empty { text-align: center; padding: 32px 0; color: var(--muted); }

.login { max-width: 380px; margin: 0 auto; padding: 18vh 24px 24px; display: flex; flex-direction: column; gap: 16px; text-align: center; }
.login img { margin: 0 auto; border-radius: 16px; }
.login form { display: flex; flex-direction: column; gap: 12px; text-align: left; }
.err { color: var(--danger); min-height: 1em; }

.demo-bar { background: var(--accent); color: var(--accent-ink); text-align: center; font-size: 13px; font-weight: 600; padding: 6px 16px; }
.install {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  background: var(--surface); border: 1px solid var(--line); border-left: 4px solid var(--accent);
  border-radius: var(--radius); padding: 10px 12px; margin-bottom: 12px; font-size: 14px;
}
.install > span:first-child { flex: 1 1 180px; }
.install .x { background: none; border: 0; font-size: 22px; color: var(--muted); min-width: 36px; min-height: 36px; cursor: pointer; }
.ios-share {
  display: inline-block; width: 14px; height: 16px; vertical-align: -2px; margin: 0 2px;
  border: 2px solid var(--brand); border-top: 0; border-radius: 0 0 3px 3px; position: relative;
}
.ios-share::after { content: "\2191"; position: absolute; left: 50%; top: -9px; transform: translateX(-50%); color: var(--brand); font-size: 13px; font-weight: 700; }

#toast {
  position: fixed; left: 50%; bottom: calc(140px + var(--safe-b)); transform: translateX(-50%) translateY(20px);
  background: var(--text); color: var(--bg); padding: 12px 18px; border-radius: 10px; font-weight: 600;
  opacity: 0; pointer-events: none; transition: all .2s; z-index: 20; max-width: 90vw; text-align: center;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.error { background: var(--danger); color: #fff; }

/* display:flex on fieldset/spans must not beat the hidden attribute */
[hidden] { display: none !important; }

/* Theme picker (Settings) */
.seg { display: grid; grid-template-columns: repeat(3, 1fr); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.seg button { min-height: 44px; border: 0; background: var(--surface); color: var(--text); font: inherit; font-weight: 600; cursor: pointer; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button.on { background: var(--brand-fill, var(--brand)); color: var(--brand-fill-ink, var(--brand-ink)); }

/* Login logo: Jake's logo sits on black in both themes, so it gets a black badge */
.logo-badge { background: #000; border-radius: 18px; padding: 18px 20px; margin: 0 auto; box-shadow: 0 8px 24px rgba(0,0,0,.18); }
.logo-badge img { display: block; width: 240px; max-width: 70vw; height: auto; }

/* Privacy / terms pages */
.legal { max-width: 680px; margin: 0 auto; padding: 32px 16px 64px; }
.legal h1 { font-size: 26px; margin-bottom: 4px; }
.legal h2 { font-size: 18px; margin: 24px 0 6px; }
.legal li { margin-bottom: 6px; }

/* Job type chips */
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: -4px; }
.chip { display: inline-flex; align-items: center; gap: 6px; min-height: 36px; padding: 0 14px; border-radius: 99px;
  border: 1px solid var(--line); background: var(--surface); color: var(--text); font: inherit; font-size: 14px; font-weight: 600; cursor: pointer; }
.chip.on { background: var(--brand-fill, var(--brand)); color: var(--brand-fill-ink, var(--brand-ink)); border-color: transparent; }
.chip-x { background: none; border: 0; color: inherit; font-size: 18px; line-height: 1; padding: 0 0 0 2px; min-width: 24px; min-height: 28px; cursor: pointer; }
.row-inline { display: flex; gap: 8px; margin-top: 12px; }
.row-inline input { flex: 1; min-width: 0; }

/* ---------- Calendar: views, week grid, month grid, blocks ---------- */
:root { --blk-other: #5f6a72; --blk-family: #7b52b0; --blk-personal: #23808f; --blk-off: #8a8178; --blk-ink: #ffffff; --grid: #e9e4dd; --off-hours: rgba(0,0,0,.035); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --blk-other: #7d8891; --blk-family: #9a74cc; --blk-personal: #3a9fae; --blk-off: #8f877e; --blk-ink: #0f0f0f; --grid: #2b2927; --off-hours: rgba(255,255,255,.035); } }
:root[data-theme="dark"] { --blk-other: #7d8891; --blk-family: #9a74cc; --blk-personal: #3a9fae; --blk-off: #8f877e; --blk-ink: #0f0f0f; --grid: #2b2927; --off-hours: rgba(255,255,255,.035); }
.t-other-job { --blk: var(--blk-other); } .t-family { --blk: var(--blk-family); } .t-personal { --blk: var(--blk-personal); } .t-time-off { --blk: var(--blk-off); }

.seg.views { margin-bottom: 4px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* week */
.wk { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: clip; } /* clip, not hidden: keeps the day header sticky to the page */
.wk-row { display: grid; grid-template-columns: 30px repeat(7, minmax(0, 1fr)); }
.wk-heads { position: sticky; top: calc(env(safe-area-inset-top, 0px) + 56px); z-index: 3; background: var(--surface); border-bottom: 1px solid var(--line); }
.wk-head { display: flex; flex-direction: column; align-items: center; padding: 6px 0 4px; min-width: 0; }
.wk-dow { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.wk-num { font-size: 17px; font-weight: 700; line-height: 1.2; }
.wk-head.today .wk-num { background: var(--brand-fill, var(--brand)); color: var(--brand-fill-ink, #fff); border-radius: 99px; padding: 0 7px; }
.wk-open { font-size: 10px; font-weight: 700; color: var(--ok); white-space: nowrap; min-height: 13px; }
.wk-open.none { color: var(--muted); }
.wk-gutter { font-size: 10px; color: var(--muted); text-align: right; padding-right: 3px; }
.wk-adl { padding-top: 4px; font-size: 9px; text-transform: uppercase; }
.wk-allday { border-left: 1px solid var(--grid); border-bottom: 1px solid var(--line); min-height: 22px; padding: 2px 1px; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.wk-hr { border-top: 1px solid transparent; transform: translateY(-6px); }
.wk-hr:first-child { transform: none; }
.wk-col { position: relative; border-left: 1px solid var(--grid); min-width: 0;
  background-image: repeating-linear-gradient(to bottom, var(--grid) 0, var(--grid) 1px, transparent 1px, transparent 44px); cursor: pointer; }
.wk-col.today { background-color: color-mix(in srgb, var(--accent) 7%, transparent); }
.wk-off { position: absolute; left: 0; right: 0; background: var(--off-hours); pointer-events: none; }
.ev { position: absolute; border-radius: 5px; padding: 2px 3px; overflow: hidden; text-decoration: none; display: flex; flex-direction: column; z-index: 1; font-size: 10px; line-height: 1.2; }
.ev.job { background: var(--brand-fill, var(--brand)); color: var(--brand-fill-ink, #fff); }
.ev.block { background: var(--blk); color: var(--blk-ink); background-image: repeating-linear-gradient(135deg, rgba(255,255,255,.10) 0 6px, transparent 6px 12px); }
.ev-t { font-weight: 700; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; word-break: break-word; }
.ev-s { opacity: .85; white-space: nowrap; }
.ev-chip { display: block; font-size: 10px; font-weight: 700; border-radius: 4px; padding: 2px 3px; text-decoration: none; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.ev-chip.job { background: var(--brand-fill, var(--brand)); color: var(--brand-fill-ink, #fff); }
.ev-chip.block { background: var(--blk); color: var(--blk-ink); }
.wk-legend { margin-top: 10px; line-height: 1.9; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin: 0 4px 0 6px; vertical-align: -1px; }
.dot.job { background: var(--brand-fill, var(--brand)); } .dot.block { background: var(--blk); }

/* month */
.mo { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); background: var(--line); gap: 1px; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.mo-dow { background: var(--surface); text-align: center; font-size: 11px; color: var(--muted); text-transform: uppercase; padding: 6px 0; }
.mo-cell { background: var(--surface); border: 0; min-height: 78px; padding: 3px 2px; display: flex; flex-direction: column; gap: 2px; align-items: stretch; text-align: left; font: inherit; color: var(--text); cursor: pointer; min-width: 0; }
.mo-cell.out { background: var(--bg); color: var(--muted); }
.mo-num { font-size: 12px; font-weight: 700; padding-left: 2px; }
.mo-cell.today .mo-num { color: var(--brand); }
.mo-cell.today { box-shadow: inset 0 0 0 2px var(--accent); }
.mo-bar { font-size: 9px; font-weight: 700; border-radius: 3px; padding: 1px 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mo-bar.job { background: var(--brand-fill, var(--brand)); color: var(--brand-fill-ink, #fff); }
.mo-bar.block { background: var(--blk); color: var(--blk-ink); }
.mo-more { font-size: 10px; color: var(--muted); padding-left: 2px; }

/* list + detail styling for blocks */
.card.blockcard { border-left: 5px solid var(--blk); background-image: repeating-linear-gradient(135deg, color-mix(in srgb, var(--blk) 7%, transparent) 0 8px, transparent 8px 16px); }
.panel.blockpanel { border-left: 5px solid var(--blk); }

/* create sheet */
.sheet-wrap { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 30; display: flex; align-items: flex-end; justify-content: center; }
.sheet { background: var(--surface); width: 100%; max-width: 640px; border-radius: 16px 16px 0 0; padding: 16px 16px calc(16px + var(--safe-b)); display: flex; flex-direction: column; gap: 10px; box-shadow: 0 -8px 30px rgba(0,0,0,.2); }
.sheet-when { margin: 0 0 2px; text-align: center; }
button.fab { border: 0; font: inherit; font-weight: 700; cursor: pointer; }

/* weekday toggles */
.dows { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.dow { min-height: 42px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); color: var(--text); font: inherit; font-weight: 700; cursor: pointer; }
.dow.on { background: var(--brand-fill, var(--brand)); color: var(--brand-fill-ink, #fff); border-color: transparent; }
.panel.small { padding: 10px 12px; font-size: 14px; }
