:root {
  color-scheme: light;
  --bg: #f4f3ef;
  --surface: #fcfcfb;
  --surface-2: #eeede8;
  --line: #e2e0d9;
  --text: #0b0b0b;
  --text-2: #52514e;
  --text-3: #86857f;
  --accent: #6250d6;
  --danger: #d03b3b;
  --c0: #2a78d6; --c1: #eb6834; --c2: #1baf7a; --c3: #eda100;
  --c4: #e87ba4; --c5: #008300; --c6: #6250d6; --c7: #e34948;
  --radius: 16px;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #111110;
    --surface: #1a1a19;
    --surface-2: #2a2a28;
    --line: #353532;
    --text: #f0efec;
    --text-2: #c3c2b7;
    --text-3: #8d8c84;
    --accent: #9085e9;
    --danger: #e66767;
    --c0: #3987e5; --c1: #d95926; --c2: #199e70; --c3: #c98500;
    --c4: #d55181; --c5: #0ca30c; --c6: #9085e9; --c7: #e66767;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--text); min-height: 100vh;
  -webkit-text-size-adjust: 100%;
}
#app { max-width: 920px; margin: 0 auto; padding: 0 14px 60px; }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; }
.muted { color: var(--text-3); }
.small { font-size: 13px; }

/* ---------- header ---------- */
.top { display: flex; align-items: center; gap: 12px; padding: 16px 2px 12px; flex-wrap: wrap; }
.brand {
  font-weight: 900; font-size: 24px; letter-spacing: -.5px;
  background: linear-gradient(90deg, var(--c6), var(--c4), var(--c1));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.who { margin-left: auto; color: var(--text-3); font-size: 14px; }
.tabs { display: flex; gap: 4px; background: var(--surface-2); padding: 4px; border-radius: 12px; margin-bottom: 16px; }
.tab {
  flex: 1; border: 0; background: none; padding: 9px 8px; border-radius: 9px; cursor: pointer;
  font-weight: 700; color: var(--text-2);
}
.tab.on { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.12); }

/* ---------- basics ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 12px; }
.card > h3 { font-size: 16px; margin-bottom: 2px; }
.card .sub { color: var(--text-3); font-size: 13px; margin: 0 0 10px; }
.section { font-size: 12px; text-transform: uppercase; letter-spacing: 1.2px; font-weight: 800; color: var(--text-3); margin: 22px 4px 8px; }
input[type=text], input[type=password], input[type=number], input[type=date], select, textarea {
  background: var(--bg); border: 1.5px solid var(--line); border-radius: 10px; padding: 10px 12px; width: 100%; outline: none;
  font-size: 16px;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
textarea { resize: vertical; min-height: 70px; }
.btn {
  border: 1.5px solid var(--line); background: var(--surface); border-radius: 10px; padding: 9px 14px; cursor: pointer;
  font-weight: 700; white-space: nowrap;
}
a.btn { text-decoration: none; color: var(--text); display: inline-block; }
.btn:hover { border-color: var(--text-3); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { color: var(--danger); }
.btn.sm { padding: 5px 9px; font-size: 13px; }
.btn:disabled { opacity: .4; cursor: default; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.err { color: var(--danger); font-weight: 600; min-height: 1.2em; margin: 8px 0 0; font-size: 14px; }
.dot { width: 12px; height: 12px; border-radius: 50%; flex: none; display: inline-block; background: var(--mc); }
.toast {
  position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%); background: var(--text); color: var(--bg);
  padding: 10px 16px; border-radius: 10px; font-weight: 600; z-index: 20; max-width: 90vw;
}

/* ---------- login ---------- */
.auth { max-width: 380px; margin: 10vh auto 0; }
.auth .brand { font-size: 40px; display: inline-block; }
.auth label { display: block; font-weight: 700; font-size: 14px; margin-top: 12px; }
.auth label input { margin-top: 5px; }
.auth .btn { width: 100%; margin-top: 16px; padding: 12px; }

/* ---------- log ---------- */
.daynav { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.daynav .title { flex: 1; text-align: center; }
.daynav .title b { display: block; font-size: 19px; }
.daynav input[type=date] { width: auto; padding: 6px 8px; font-size: 14px; }
.nav { width: 42px; height: 42px; border-radius: 50%; padding: 0; font-size: 20px; }
.field { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.field .name { font-weight: 700; flex: 1; min-width: 120px; display: flex; align-items: center; gap: 8px; }
.field .ctl { display: flex; gap: 6px; align-items: center; }
.field .hint { flex-basis: 100%; margin: -4px 0 0 20px; }
.field input[type=number] { width: 120px; text-align: right; }
.pick {
  border: 1.5px solid var(--line); background: var(--bg); border-radius: 10px; min-width: 44px; height: 42px; padding: 0 12px;
  cursor: pointer; font-weight: 800; color: var(--text-2);
}
.pick.on { background: var(--mc); border-color: var(--mc); color: #fff; }
.pick.no.on { background: var(--text-3); border-color: var(--text-3); }
.field.text { display: block; }
.field.text textarea { margin-top: 10px; }
.saved { text-align: center; height: 18px; font-size: 13px; color: var(--text-3); }

/* ---------- dashboard ---------- */
.ranges { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.ranges .btn.on { background: var(--text); color: var(--bg); border-color: var(--text); }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; margin-bottom: 12px; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; border-top: 4px solid var(--mc); }
.tile .lbl { font-size: 13px; color: var(--text-2); font-weight: 700; }
.tile .val { font-size: 28px; font-weight: 800; letter-spacing: -.5px; margin: 2px 0; }
.tile .val small { font-size: 14px; font-weight: 600; color: var(--text-3); letter-spacing: 0; }
.tile .more { font-size: 12.5px; color: var(--text-3); }
.chartbox { position: relative; height: 240px; }
.cardhead { display: flex; align-items: flex-start; gap: 10px; }
.cardhead .grow h3 { font-size: 16px; }
.toggle { font-size: 13px; color: var(--text-2); display: flex; gap: 6px; align-items: center; cursor: pointer; white-space: nowrap; }
.empty { text-align: center; color: var(--text-3); padding: 28px 10px; }

.heat { margin-top: 14px; }
.heat:first-of-type { margin-top: 4px; }
.heat .hd { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 14px; margin-bottom: 6px; flex-wrap: wrap; }
.heat .hd .cap { margin-left: auto; font-weight: 500; font-size: 12.5px; color: var(--text-3); }
.heat .scroll { overflow-x: auto; padding-bottom: 4px; }
.heat .months { display: grid; grid-auto-flow: column; grid-auto-columns: 14px; gap: 3px; font-size: 10.5px; color: var(--text-3); height: 15px; }
.heat .months span { white-space: nowrap; }
.heat .grid { display: grid; grid-template-rows: repeat(7, 14px); grid-auto-flow: column; grid-auto-columns: 14px; gap: 3px; }
.cell { border-radius: 4px; }
.cell.none { box-shadow: inset 0 0 0 1px var(--line); }
.cell.off { background: var(--surface-2); box-shadow: inset 0 0 0 1px var(--text-3); }
.cell.l1 { background: color-mix(in srgb, var(--mc) 22%, var(--surface)); }
.cell.l2 { background: color-mix(in srgb, var(--mc) 42%, var(--surface)); }
.cell.l3 { background: color-mix(in srgb, var(--mc) 62%, var(--surface)); }
.cell.l4 { background: color-mix(in srgb, var(--mc) 82%, var(--surface)); }
.cell.l5 { background: var(--mc); }
.cell:hover { outline: 2px solid var(--text); outline-offset: 1px; }
.key { display: flex; gap: 10px; align-items: center; font-size: 12px; color: var(--text-3); margin-top: 12px; flex-wrap: wrap; }
.key .cell { width: 12px; height: 12px; display: inline-block; vertical-align: -2px; margin-right: 4px; }
.notes { list-style: none; margin: 0; padding: 0; }
.notes li { padding: 8px 0; border-bottom: 1px solid var(--line); }
.notes li:last-child { border: 0; }
.notes time { display: block; font-size: 12px; color: var(--text-3); }

/* ---------- settings ---------- */
.param { display: flex; gap: 8px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.param:last-of-type { border-bottom: 0; }
.param.hidden .grow, .param.hidden .unit { opacity: .5; }
.param input[type=text] { padding: 7px 10px; }
.param .unit { width: 76px; }
.param .kind { font-size: 12px; color: var(--text-3); width: 62px; }
.swatch { width: 26px; height: 26px; border-radius: 50%; border: 0; background: var(--mc); cursor: pointer; flex: none; }
.addrow { display: grid; grid-template-columns: 1fr 150px 90px auto; gap: 8px; margin-top: 12px; }
@media (max-width: 600px) { .addrow { grid-template-columns: 1fr 1fr; } }
.linkbox { background: var(--bg); border: 1.5px dashed var(--line); border-radius: 10px; padding: 8px 10px; font-size: 13px; word-break: break-all; font-family: ui-monospace, monospace; }
.person { display: flex; align-items: center; gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.person:last-child { border: 0; }
