/* PetWatch dashboard. No build step: this file is served as is.
   Palette: "Collar teal" primary, "Marmalade" accent (an orange tabby), "Nose pink" highlight, cream and biscuit surfaces,
   cocoa ink. Warm and friendly, readable in sunlight, with a warm dark mode. */

/* Plus Jakarta Sans, SIL Open Font License 1.1 (fonts/OFL.txt), self-hosted so the page makes no third-party requests. */
@font-face {
  font-family: "Plus Jakarta Sans";
  font-style: normal;
  font-weight: 400 800;
  font-display: swap;
  src: url("/fonts/PlusJakartaSans-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

:root {
  color-scheme: light;
  /* brand */
  --collar-teal: #1E6F6A;
  --marmalade: #F0A04B;
  --nose-pink: #E07A8F;
  --cream: #FFF8EF;
  --biscuit: #F5E6CF;
  --cocoa: #33261F;

  /* surfaces and text */
  --bg: var(--cream);
  --card: #FFFFFF;
  --sunk: #FBF1E3;
  --ink: var(--cocoa);
  --muted: #6E5F55;
  --line: #EADCC9;
  --line-strong: #D4C1A9;
  --primary: var(--collar-teal);
  --primary-hover: #175955;
  --on-primary: #FFFFFF;
  --primary-soft: #E2F1EF;
  --accent: var(--marmalade);
  --accent-ink: #8A4E0E;
  --highlight: var(--nose-pink);
  --focus: #C46A12;

  /* status: always a soft container with dark text */
  --success: #3C7A3A; --success-bg: #E7F3E4; --success-ink: #1E4A1C;
  --warning: #B8711A; --warning-bg: #FDF0DA; --warning-ink: #5A3404;
  --info: #2F6A8A;    --info-bg: #E5F0F6;    --info-ink: #163B4F;
  --neutral: #74685F; --neutral-bg: #F1ECE6; --neutral-ink: #40362F;
  --danger: #B0413E;  --danger-bg: #FBE8E6;  --danger-ink: #6B1E1C;

  /* what a pet did: the day strip and the zone boxes */
  --act-eating: #F0A04B;
  --act-drinking: #3D9BD1;
  --act-litter: #9A8B3A;
  --act-sleeping: #7E6BC4;
  --act-resting: #B9AA9C;
  --act-door: #E07A8F;

  --shadow: 0 1px 2px rgba(51, 38, 31, .05), 0 4px 14px -6px rgba(51, 38, 31, .12);
  --radius: 18px;
  --radius-sm: 10px;
  --font: "Plus Jakarta Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

/* Dark: warm cocoa, never black-blue. The same tokens again under the explicit attribute, so a theme switch can be added later. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #1A1512; --card: #241D19; --sunk: #1F1915; --ink: #F6ECDF; --muted: #C5B4A4; --line: #3B312A; --line-strong: #574A40;
    --primary: #5CC4BB; --primary-hover: #77D2CA; --on-primary: #08201E; --primary-soft: #143533;
    --accent: #F5B465; --accent-ink: #F8C98C; --highlight: #EE97A8; --focus: #F5B465;
    --success: #79C374; --success-bg: #17301A; --success-ink: #BDE8B8;
    --warning: #E9A44A; --warning-bg: #352106; --warning-ink: #FFD8A1;
    --info: #74B4D6;    --info-bg: #102938;    --info-ink: #A9D6EE;
    --neutral: #A99D93; --neutral-bg: #2C2520; --neutral-ink: #DCD1C8;
    --danger: #E9807A;  --danger-bg: #3A1514;  --danger-ink: #FFB7B1;
    --act-eating: #F5B465; --act-drinking: #6DB8E3; --act-litter: #C3B35C; --act-sleeping: #A797E6; --act-resting: #8A7D72; --act-door: #EE97A8;
    --shadow: 0 1px 2px rgba(0, 0, 0, .35);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #1A1512; --card: #241D19; --sunk: #1F1915; --ink: #F6ECDF; --muted: #C5B4A4; --line: #3B312A; --line-strong: #574A40;
  --primary: #5CC4BB; --primary-hover: #77D2CA; --on-primary: #08201E; --primary-soft: #143533;
  --accent: #F5B465; --accent-ink: #F8C98C; --highlight: #EE97A8; --focus: #F5B465;
  --success: #79C374; --success-bg: #17301A; --success-ink: #BDE8B8;
  --warning: #E9A44A; --warning-bg: #352106; --warning-ink: #FFD8A1;
  --info: #74B4D6;    --info-bg: #102938;    --info-ink: #A9D6EE;
  --neutral: #A99D93; --neutral-bg: #2C2520; --neutral-ink: #DCD1C8;
  --danger: #E9807A;  --danger-bg: #3A1514;  --danger-ink: #FFB7B1;
  --act-eating: #F5B465; --act-drinking: #6DB8E3; --act-litter: #C3B35C; --act-sleeping: #A797E6; --act-resting: #8A7D72; --act-door: #EE97A8;
  --shadow: 0 1px 2px rgba(0, 0, 0, .35);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.5 var(--font); }
main { max-width: 1040px; margin: 0 auto; padding: 16px 16px 48px; padding-left: max(16px, env(safe-area-inset-left)); padding-right: max(16px, env(safe-area-inset-right)); }
h1, h2, h3 { line-height: 1.25; margin: 0 0 8px; }
h1 { font-size: 22px; font-weight: 800; }
h2 { font-size: 19px; font-weight: 750; }
h3 { font-size: 16px; font-weight: 700; }
p { margin: 0 0 10px; }
a { color: var(--primary); }
.muted { color: var(--muted); }
.spacer { flex: 1; }
.gap-top { margin-top: 12px; }
.uppercase { text-transform: uppercase; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; margin-bottom: 16px; }
.card.empty { text-align: center; }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 8px; }
.err { color: var(--danger); min-height: 1.5em; font-size: 14px; }
.note { color: var(--muted); font-size: 14px; min-height: 1.5em; }

input, select, textarea, button, .button { font: inherit; }
input, select, textarea { border: 1px solid var(--line-strong); border-radius: var(--radius-sm); padding: 10px 12px; background: var(--card); color: var(--ink); min-height: 44px; max-width: 100%; }
textarea { min-height: 88px; width: 100%; }
button, .button { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px; padding: 8px 18px; border-radius: 999px; border: 1px solid transparent; background: var(--primary); color: var(--on-primary); font-weight: 700; cursor: pointer; text-decoration: none; }
button:hover, .button:hover { background: var(--primary-hover); }
button:disabled { opacity: .5; cursor: default; }
button.quiet, .button.quiet { background: transparent; color: var(--primary); border-color: var(--line-strong); }
button.quiet:hover, .button.quiet:hover { background: var(--primary-soft); }
button.small, .button.small { min-height: 36px; padding: 4px 12px; font-size: 14px; }
button.link { background: none; border: 0; padding: 0; min-height: 0; color: var(--primary); text-decoration: underline; font-weight: 600; }
button.danger { background: var(--danger); color: #FFFFFF; }

.brand { display: flex; align-items: center; gap: 12px; }
.brand h1 { margin: 0; }
.login { max-width: 420px; margin: 10vh auto 0; }
.login input { width: 100%; }
header.top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
nav.tabs { display: flex; gap: 4px; background: var(--sunk); border: 1px solid var(--line); border-radius: 999px; padding: 4px; margin-bottom: 16px; }
nav.tabs a { flex: 1; text-align: center; padding: 10px 4px; border-radius: 999px; color: var(--ink); text-decoration: none; font-weight: 650; }
nav.tabs a.active { background: var(--primary); color: var(--on-primary); }
.section-head { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 12px; }
.section-head h2, .section-head h3 { margin: 0; }
.back { margin-bottom: 12px; }
ul.plain { list-style: none; padding: 0; margin: 0; }
ul.plain li { padding: 10px 0; border-top: 1px solid var(--line); display: flex; flex-wrap: wrap; gap: 6px 12px; align-items: center; }
ul.plain li:first-child { border-top: 0; }

.pill { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 13px; font-weight: 700; background: var(--neutral-bg); color: var(--neutral-ink); }
.pill.ok { background: var(--success-bg); color: var(--success-ink); }
.pill.warn { background: var(--warning-bg); color: var(--warning-ink); }
.pill.info { background: var(--info-bg); color: var(--info-ink); }
.pill.bad { background: var(--danger-bg); color: var(--danger-ink); }

/* ---- Today ---- */
.welcome ol.steps { margin: 8px 0 0; padding-left: 22px; }
.welcome li { margin: 6px 0; }
.welcome li.done a { text-decoration: line-through; color: var(--muted); }
.pet-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; margin-bottom: 16px; }
.pet-card { margin: 0; }
.pet-card .head { display: flex; gap: 12px; align-items: center; margin-bottom: 12px; }
.face { width: 56px; height: 56px; border-radius: 50%; background: var(--biscuit); flex: none; overflow: hidden; display: grid; place-items: center; font-weight: 800; font-size: 22px; color: var(--accent-ink); }
.face img { width: 100%; height: 100%; object-fit: cover; }
.pet-card .reason { font-size: 13px; margin-top: 2px; }
.facts { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 16px; margin: 0 0 12px; }
.facts dt { font-size: 13px; color: var(--muted); }
.facts dd { margin: 0; font-weight: 700; }
.strip { position: relative; height: 22px; border-radius: 6px; background: var(--sunk); border: 1px solid var(--line); overflow: hidden; }
.strip i { position: absolute; top: 0; bottom: 0; min-width: 3px; background: var(--act-resting); }
.strip i.eating { background: var(--act-eating); }
.strip i.drinking { background: var(--act-drinking); }
.strip i.litter { background: var(--act-litter); }
.strip i.sleeping { background: var(--act-sleeping); }
.strip i.came-in, .strip i.went-out { background: var(--act-door); }
.strip-scale { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); margin-top: 2px; }
.legend { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 12px; color: var(--muted); margin-top: 6px; }
.legend b { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 4px; vertical-align: -1px; }
.legend .eating { background: var(--act-eating); }
.legend .drinking { background: var(--act-drinking); }
.legend .litter { background: var(--act-litter); }
.legend .sleeping { background: var(--act-sleeping); }
.legend .door { background: var(--act-door); }

/* ---- Clips ---- */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }
.clip { padding: 0; overflow: hidden; margin: 0; }
.clip .pic { position: relative; aspect-ratio: 16 / 9; background: var(--sunk); }
.clip .pic img, .clip video { width: 100%; height: 100%; object-fit: cover; display: block; }
.clip .cannot-play { position: absolute; inset: 0; margin: 0; padding: 16px; display: grid; place-items: center; text-align: center; font-size: 14px; color: var(--neutral-ink); background: var(--neutral-bg); }
.clip .meta { padding: 10px 14px; display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: center; }
.clip .who { display: flex; gap: 6px; padding: 0 14px 12px; flex-wrap: wrap; }
.clip .who button { padding: 0; min-height: 0; width: 56px; height: 56px; border-radius: 10px; overflow: hidden; background: var(--sunk); border: 2px solid var(--line); }
.clip .who button.named { border-color: var(--success); }
.clip .who img { width: 100%; height: 100%; object-fit: cover; }

/* ---- Pets ---- */
.pets { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.pet { display: flex; gap: 12px; align-items: center; padding: 12px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius-sm); text-decoration: none; color: var(--ink); }
.pet:hover { border-color: var(--primary); }
.inbox-link { display: flex; gap: 12px; align-items: center; padding: 12px 16px; margin-bottom: 16px; background: var(--warning-bg); color: var(--warning-ink); border-radius: var(--radius-sm); text-decoration: none; }
.inbox-crops { display: flex; }
.inbox-crops img { width: 40px; height: 40px; border-radius: 50%; object-fit: cover; border: 2px solid var(--card); margin-left: -10px; }
.inbox-crops img:first-child { margin-left: 0; }
.fields { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 16px; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field > span, .field > legend, .label { font-size: 14px; font-weight: 650; }
.field.wide { grid-column: 1 / -1; }
fieldset.group { border: 0; padding: 0; margin: 0; }
.seg { display: flex; flex-wrap: wrap; gap: 6px; }
.seg label { position: relative; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span { display: inline-flex; align-items: center; min-height: 40px; padding: 6px 14px; border-radius: 999px; border: 1px solid var(--line-strong); cursor: pointer; font-size: 14px; font-weight: 600; }
.seg input:checked + span { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.seg input:focus-visible + span { outline: 3px solid var(--focus); outline-offset: 2px; }
.check { display: flex; gap: 8px; align-items: center; }
.check input { min-height: 0; width: 20px; height: 20px; }
details.more { margin: 16px 0; }
details summary { cursor: pointer; font-weight: 650; color: var(--primary); }
.save-row { margin-top: 12px; }
.photos { display: flex; flex-wrap: wrap; gap: 10px; }
.photo { position: relative; width: 96px; height: 96px; border-radius: var(--radius-sm); overflow: hidden; background: var(--sunk); border: 1px solid var(--line); }
.photo img { width: 100%; height: 100%; object-fit: cover; }
.photo button { position: absolute; top: 4px; right: 4px; min-height: 0; width: 28px; height: 28px; padding: 0; border-radius: 50%; background: rgba(0, 0, 0, .6); color: #FFFFFF; }
.photo.add { display: grid; place-items: center; cursor: pointer; color: var(--primary); font-weight: 700; font-size: 28px; border-style: dashed; }
.table-wrap { overflow-x: auto; }
table.days { width: 100%; border-collapse: collapse; font-size: 14px; }
table.days th, table.days td { padding: 6px 8px; border-top: 1px solid var(--line); text-align: right; white-space: nowrap; }
table.days th:first-child, table.days td:first-child { text-align: left; }
table.days tr.unwatched td { color: var(--muted); font-style: italic; }
table.days tr.unwatched td + td { text-align: left; }
.crop-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 12px; }
.crop { position: relative; padding: 0; background: var(--card); border: 2px solid var(--line); border-radius: var(--radius-sm); overflow: hidden; color: var(--ink); display: flex; flex-direction: column; min-height: 0; font-weight: 500; }
.crop:hover { background: var(--card); border-color: var(--primary); }
.crop img { width: 100%; aspect-ratio: 1; object-fit: cover; display: block; background: var(--sunk); }
.crop span { padding: 4px 6px; font-size: 12px; text-align: left; }
.crop.selected { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.crop.guess span b { color: var(--success); }
.select-bar, .undo-bar { position: sticky; bottom: 12px; margin-top: 16px; padding: 12px 16px; background: var(--card); border: 1px solid var(--line-strong); border-radius: var(--radius); box-shadow: var(--shadow); }
.select-pets { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }

/* ---- Who's this? ---- */
dialog { border: 0; border-radius: var(--radius); padding: 0; background: var(--card); color: var(--ink); max-width: min(560px, calc(100vw - 24px)); width: 100%; }
dialog::backdrop { background: rgba(26, 21, 18, .55); }
.who-sheet { padding: 20px; }
.who-head { display: flex; gap: 16px; align-items: center; margin-bottom: 12px; }
.who-head img { width: 112px; height: 112px; border-radius: var(--radius-sm); object-fit: cover; background: var(--sunk); }
.who-hint { color: var(--success-ink); background: var(--success-bg); padding: 4px 10px; border-radius: 8px; display: inline-block; }
.who-pets { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.who-pets button { justify-content: flex-start; background: var(--sunk); color: var(--ink); border-color: var(--line); border-radius: var(--radius-sm); }
.who-pets button.current { border-color: var(--primary); background: var(--primary-soft); }

/* ---- Settings ---- */
.settings-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
.pairing { margin-top: 12px; padding: 16px; border-radius: var(--radius-sm); background: var(--primary-soft); text-align: center; }
.pairing .code { font-size: 34px; font-weight: 800; letter-spacing: .12em; margin: 4px 0; font-variant-numeric: tabular-nums; }
.cameras li { align-items: flex-start; }
.cameras .why { flex-basis: 100%; font-size: 14px; color: var(--muted); }
.danger-zone { margin-top: 16px; }

/* ---- zones (Settings) ---- */
.zone-pic { position: relative; border-radius: var(--radius-sm); overflow: hidden; background: var(--sunk); user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
.zone-pic img { display: block; width: 100%; height: auto; pointer-events: none; }
.zone-layer { position: absolute; inset: 0; }
.zone-box { position: absolute; border: 2px solid var(--zone); background: color-mix(in srgb, var(--zone) 18%, transparent); border-radius: 4px; touch-action: none; cursor: move; }
.zone-box.food { --zone: var(--act-eating); }
.zone-box.water { --zone: var(--act-drinking); }
.zone-box.bed { --zone: var(--act-sleeping); }
.zone-box.litter { --zone: var(--act-litter); }
.zone-box.door { --zone: var(--act-door); }
.zone-box.selected { border-width: 3px; box-shadow: 0 0 0 1px rgba(0, 0, 0, .55), inset 0 0 0 1px rgba(0, 0, 0, .35); }
.zone-box.edge-top { border-top-width: 6px; border-top-style: double; }
.zone-box.edge-bottom { border-bottom-width: 6px; border-bottom-style: double; }
.zone-box.edge-left { border-left-width: 6px; border-left-style: double; }
.zone-box.edge-right { border-right-width: 6px; border-right-style: double; }
.zone-label { position: absolute; left: -2px; bottom: 100%; max-width: calc(100% + 4px); padding: 1px 6px; border-radius: 4px 4px 0 0; background: var(--zone); color: #241A14; font-size: 12px; font-weight: 700; line-height: 1.5; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; pointer-events: none; }
.zone-box.label-inside .zone-label { bottom: auto; top: 0; border-radius: 0 0 4px 0; }
/* Corner handles: drawn small, but each catches a finger-sized area around it. */
.zone-handle { position: absolute; width: 36px; height: 36px; margin: -18px; touch-action: none; }
.zone-handle::after { content: ""; position: absolute; left: 11px; top: 11px; width: 14px; height: 14px; border-radius: 50%; background: #FFFFFF; border: 3px solid var(--zone); box-shadow: 0 0 0 1px rgba(0, 0, 0, .5); }
.zone-handle.nw { left: 0; top: 0; cursor: nwse-resize; }
.zone-handle.ne { left: 100%; top: 0; cursor: nesw-resize; }
.zone-handle.sw { left: 0; top: 100%; cursor: nesw-resize; }
.zone-handle.se { left: 100%; top: 100%; cursor: nwse-resize; }
.zone-edit { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; padding: 12px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--sunk); }

@media (max-width: 560px) {
  main { padding-top: 12px; }
  .card { padding: 16px; border-radius: 14px; }
  nav.tabs a { font-size: 14px; padding: 9px 2px; }
  .grid, .settings-grid, .pet-cards { grid-template-columns: 1fr; }
  .fields { grid-template-columns: 1fr; }
  .crop-grid { grid-template-columns: repeat(3, 1fr); gap: 8px; }
  .who-pets { grid-template-columns: 1fr 1fr; }
  .who-head img { width: 88px; height: 88px; }
}
