:root {
  color-scheme: light dark;
  --bg: #ffffff; --s1: #f4f3ee; --tx: #1f1e1c; --tx2: #5f5e5a; --tx3: #8a8983;
  --bd: rgba(0, 0, 0, .12); --bd2: rgba(0, 0, 0, .28);
  --ac: #185FA5; --ac-bg: #e6f1fb; --ac-tx: #0c447c;
  --ok: #3b6d11; --ok-bg: #eaf3de; --ok-tx: #27500a;
  --warn-bg: #faeeda; --warn-tx: #633806; --bad: #a32d2d; --on: #ffffff;
  --radius: 8px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #1c1c1a; --s1: #2a2a27; --tx: #f1efe8; --tx2: #b4b2a9; --tx3: #888780;
    --bd: rgba(255, 255, 255, .14); --bd2: rgba(255, 255, 255, .3);
    --ac: #378add; --ac-bg: #0c447c; --ac-tx: #b5d4f4;
    --ok: #639922; --ok-bg: #27500a; --ok-tx: #c0dd97;
    --warn-bg: #633806; --warn-tx: #faeeda; --bad: #f09595;
  }
}
:root[data-theme="light"] { color-scheme: light; }
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #1c1c1a; --s1: #2a2a27; --tx: #f1efe8; --tx2: #b4b2a9; --tx3: #888780;
  --bd: rgba(255, 255, 255, .14); --bd2: rgba(255, 255, 255, .3);
  --ac: #378add; --ac-bg: #0c447c; --ac-tx: #b5d4f4;
  --ok: #639922; --ok-bg: #27500a; --ok-tx: #c0dd97;
  --warn-bg: #633806; --warn-tx: #faeeda; --bad: #f09595;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--tx); }
body { font: 400 16px/1.5 system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif; }
button, input, select, textarea { font: inherit; color: inherit; }
i.ti { vertical-align: -2px; }

#app { max-width: 560px; margin: 0 auto; min-height: 100vh; }
#view { padding: calc(env(safe-area-inset-top) + 16px) 18px calc(96px + env(safe-area-inset-bottom)); }
#nav {
  position: fixed; left: 0; right: 0; bottom: 0; display: flex; max-width: 560px; margin: 0 auto;
  background: var(--bg); border-top: 0.5px solid var(--bd); padding-bottom: env(safe-area-inset-bottom);
}
.tab {
  flex: 1; border: 0; background: transparent; padding: 10px 0 12px; display: flex; flex-direction: column;
  align-items: center; gap: 2px; font-size: 11px; color: var(--tx3); cursor: pointer; text-decoration: none;
}
.tab i { font-size: 22px; }
.tab.on { color: var(--ac); }

.head { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 14px; gap: 10px; }
.title { font-size: 22px; font-weight: 500; line-height: 1.2; }
.sub { font-size: 13px; color: var(--tx2); margin-top: 2px; }
.lbl { font-size: 12px; color: var(--tx2); margin-top: 14px; }
.hint { font-size: 13px; color: var(--tx2); margin: 6px 0 0; }
.err { font-size: 13px; color: var(--bad); margin: 8px 0 0; }

.segwrap { display: flex; gap: 8px; margin-bottom: 16px; }
.seg { flex: 1; display: flex; background: var(--s1); border-radius: 10px; padding: 3px; gap: 3px; }
.seg button {
  flex: 1; border: 0.5px solid transparent; background: transparent; color: var(--tx2); border-radius: 8px;
  padding: 7px 0; font-size: 14px; cursor: pointer;
}
.seg button.on { background: var(--bg); color: var(--tx); border-color: var(--bd2); }
.icon-btn {
  width: 40px; border: 0.5px solid var(--bd2); background: transparent; border-radius: 10px; cursor: pointer;
  display: flex; align-items: center; justify-content: center; color: var(--tx);
}

.card { background: var(--s1); border-radius: 12px; padding: 12px 14px; margin-bottom: 14px; }
.card .top { display: flex; justify-content: space-between; font-size: 13px; color: var(--tx2); margin-bottom: 8px; }
.bar { height: 6px; border-radius: 3px; background: var(--bd); overflow: hidden; }
.bar > div { height: 100%; background: var(--ok); }
.split { display: flex; height: 10px; border-radius: 5px; overflow: hidden; gap: 2px; }
.split .a0 { background: var(--ac); } .split .a1 { background: var(--ok); }
.metrics { display: flex; gap: 10px; margin-bottom: 12px; }
.metric { flex: 1; background: var(--s1); border-radius: 12px; padding: 10px 14px; }
.metric .k { font-size: 12px; color: var(--tx2); }
.metric .v { font-size: 20px; font-weight: 500; }
.metric .n { font-size: 12px; color: var(--tx3); margin-top: 2px; }

.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
  border: 0.5px solid var(--bd2); background: transparent; border-radius: 999px; padding: 5px 12px;
  font-size: 13px; color: var(--tx2); cursor: pointer;
}
.chip.on { background: var(--ac-bg); color: var(--ac-tx); border-color: var(--ac); }
.chip.lg { font-size: 14px; padding: 7px 12px; }

.row { display: flex; align-items: center; gap: 10px; padding: 11px 0; border-bottom: 0.5px solid var(--bd); cursor: pointer; }
.row.plain { cursor: default; }
.row .time { width: 46px; font-size: 13px; color: var(--tx2); flex: none; }
.row .main { flex: 1; min-width: 0; }
.row .name { font-size: 15px; }
.row .name.done { text-decoration: line-through; color: var(--tx3); }
.row .meta { font-size: 12px; color: var(--tx3); }
.row .amt { font-size: 14px; }
.group { font-size: 12px; color: var(--tx2); margin-top: 16px; }

.circle {
  width: 26px; height: 26px; border-radius: 50%; flex: none; display: flex; align-items: center; justify-content: center;
  border: 1.5px solid var(--bd2); background: transparent; padding: 0; cursor: pointer; color: var(--on);
}
.circle.on { background: var(--ok); border-color: var(--ok); }

.av {
  width: 24px; height: 24px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 500; flex: none; background: var(--s1); color: var(--tx2); border: 0.5px solid var(--bd);
}
.av.a0 { background: var(--ac-bg); color: var(--ac-tx); border-color: transparent; }
.av.a1 { background: var(--ok-bg); color: var(--ok-tx); border-color: transparent; }
.av.big { width: 30px; height: 30px; font-size: 12px; }
.badge { font-size: 11px; background: var(--s1); color: var(--tx2); border-radius: 6px; padding: 2px 6px; margin-left: 6px; }
.badge.warn { background: var(--warn-bg); color: var(--warn-tx); }
.badge.ok { background: var(--ok-bg); color: var(--ok-tx); }

.days { display: flex; gap: 4px; margin-bottom: 14px; }
.day {
  flex: 1; border: 0.5px solid var(--bd); background: transparent; border-radius: 10px; padding: 8px 0;
  display: flex; flex-direction: column; align-items: center; gap: 2px; cursor: pointer; color: var(--tx);
}
.day span:first-child { font-size: 12px; }
.day span:nth-child(2) { font-size: 15px; font-weight: 500; }
.day .dot { width: 5px; height: 5px; border-radius: 50%; background: transparent; }
.day .dot.today { background: var(--ac); }
.day.on { background: var(--ac-bg); border-color: var(--ac); color: var(--ac-tx); }
.weeknav { display: flex; gap: 6px; }

button.btn {
  height: 40px; padding: 0 16px; border: 0.5px solid var(--bd2); background: transparent; border-radius: var(--radius);
  cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 6px; color: var(--tx);
}
button.btn.block, .btn.block { width: 100%; margin-top: 10px; }
button.btn.primary { background: var(--ac); border-color: var(--ac); color: var(--on); }
button.btn.danger { color: var(--bad); }
button.link { border: 0; background: transparent; color: var(--ac); cursor: pointer; padding: 6px 4px; font-size: 13px; }
button.link.mute { color: var(--tx2); }
button.link.bad { color: var(--bad); }

input[type=text], input[type=password], input[type=time], input[type=date], select, textarea {
  width: 100%; height: 40px; padding: 0 10px; border: 0.5px solid var(--bd2); border-radius: var(--radius);
  background: transparent; font-size: 16px;
}
textarea { height: auto; min-height: 72px; padding: 8px 10px; }
input[type=checkbox] { width: 20px; height: 20px; accent-color: var(--ac); }
label.l { display: block; font-size: 13px; color: var(--tx2); margin: 14px 0 6px; }
label.tog { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 14px; font-size: 15px; cursor: pointer; }
.cols { display: flex; gap: 10px; } .cols > div { flex: 1; min-width: 0; }
.inline { display: flex; gap: 6px; align-items: center; }

.backbar { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.backbar button { border: 0; background: transparent; width: 32px; height: 32px; padding: 0; cursor: pointer; color: var(--tx); display: flex; align-items: center; justify-content: center; }
.backbar span { font-size: 13px; color: var(--tx2); }
.backbar.big span { font-size: 18px; font-weight: 500; color: var(--tx); }
.kv { background: var(--s1); border-radius: 12px; padding: 4px 14px; }
.kv div { display: flex; justify-content: space-between; gap: 12px; padding: 10px 0; font-size: 14px; }
.kv div + div { border-top: 0.5px solid var(--bd); }
.kv span:first-child { color: var(--tx2); }

.photos { display: flex; gap: 8px; flex-wrap: wrap; }
.ph { position: relative; width: 72px; height: 72px; border-radius: 10px; overflow: hidden; border: 0.5px solid var(--bd); background: var(--s1); }
.ph img { width: 100%; height: 100%; object-fit: cover; display: block; }
.ph button { position: absolute; top: 2px; right: 2px; width: 22px; height: 22px; border-radius: 50%; border: 0; background: rgba(0, 0, 0, .6); color: #fff; padding: 0; cursor: pointer; display: flex; align-items: center; justify-content: center; }
label.addphoto {
  width: 72px; height: 72px; border-radius: 10px; border: 1px dashed var(--bd2); display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 2px; font-size: 11px; color: var(--tx2); cursor: pointer;
}
label.addphoto input { display: none; }

.panel { padding: 0 0 12px 34px; border-bottom: 0.5px solid var(--bd); }
.panel .inline { margin-bottom: 8px; }
.panel .inline span { font-size: 13px; color: var(--tx2); }
.panel input[type=text] { width: 84px; height: 36px; }
.panel select { width: 68px; height: 36px; }
.panel .tot { margin-left: auto; }
.row.open { border-bottom: 0; padding-bottom: 4px; }

.add { display: flex; gap: 6px; margin-bottom: 6px; flex-wrap: wrap; }
.add input[type=text].nm { flex: 1 1 100%; }
.add input.q { width: 64px; flex: none; } .add select.u { width: 68px; flex: none; } .add select.c { flex: 1; min-width: 0; }
.add button { width: 40px; padding: 0; flex: none; }

.empty { text-align: center; padding: 36px 12px; }
.empty i { font-size: 36px; color: var(--tx3); }
.empty h3 { font-size: 17px; font-weight: 500; margin: 10px 0 4px; }
.empty p { font-size: 14px; color: var(--tx2); margin: 0 0 14px; }

#toast {
  position: fixed; left: 50%; bottom: calc(84px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--tx); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-size: 14px;
  max-width: 90%; display: none; z-index: 10;
}
#toast.show { display: block; }

.timer-card { background: var(--s1); border-radius: 12px; padding: 14px; margin-top: 12px; }
.timer-card .k { font-size: 12px; color: var(--tx2); text-align: center; }
.clock { font-size: 36px; font-weight: 500; font-variant-numeric: tabular-nums; text-align: center; margin: 4px 0 12px; }
.timer-card .cols { margin-top: 0; }
.timer-card button.btn { margin-top: 0; }
.wish-card { background: var(--ac-bg); color: var(--ac-tx); border-radius: 12px; padding: 16px; margin-bottom: 14px; text-align: center; }
.wish-card .k { font-size: 12px; opacity: .85; }
.wish-card .v { font-size: 22px; font-weight: 500; margin: 4px 0 12px; }
.wish-card .cols { margin-top: 0; }
.chip.theme { flex: 1; text-align: center; }
.stepper { display: flex; align-items: center; gap: 4px; flex: none; }
.stepper button { width: 36px; height: 36px; border-radius: 50%; border: 0.5px solid var(--bd2); background: transparent; font-size: 20px; line-height: 1; cursor: pointer; color: var(--tx); padding: 0; }
.stepper .sq { min-width: 58px; text-align: center; font-size: 16px; font-weight: 500; font-variant-numeric: tabular-nums; }
.stepper .sq small { font-size: 11px; font-weight: 400; color: var(--tx2); }
