*, *::before, *::after { box-sizing: border-box; }
html { background: var(--bg); -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink); font-family: var(--font); font-size: 16px; line-height: 1.35;
  overflow-x: hidden; -webkit-tap-highlight-color: transparent; overscroll-behavior-x: none;
}
body.locked { position: fixed; left: 0; right: 0; overflow: hidden; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
input, select, textarea { font-size: 16px; } /* 16px stops iOS zooming into fields */
a { color: var(--accent); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.grow { flex: 1; min-width: 0; }

/* Home */
.home {
  max-width: 560px; margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 18px) max(16px, env(safe-area-inset-right)) calc(env(safe-area-inset-bottom) + 120px) max(16px, env(safe-area-inset-left));
}
.blk { margin-top: 28px; }
.blk:first-child { margin-top: 0; }
.sh { display: flex; align-items: center; gap: 2px; margin-bottom: 10px; }
.shb { flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: flex-start; border: 0; background: none; padding: 4px 0; text-align: left; color: var(--ink); }
.k { font-size: 13px; font-weight: 600; letter-spacing: .02em; color: var(--muted); }
.k.now { color: var(--accent); }
.h { display: flex; align-items: center; gap: 6px; margin-top: 2px; font-size: 24px; font-weight: 700; letter-spacing: -0.02em; line-height: 1.15; }
.fold-ic { display: flex; color: var(--muted); }
.ib { width: var(--tap); height: var(--tap); flex: none; border: 0; border-radius: var(--radius-ctl); background: transparent; color: var(--ink); display: flex; align-items: center; justify-content: center; padding: 0; }
.ib:hover { background: var(--line-2); }
.back { height: 32px; padding: 0 12px; margin-right: 4px; border: 0; border-radius: 999px; background: var(--accent-soft); color: var(--accent-soft-ink); font-size: 13px; font-weight: 600; }
.swp { touch-action: pan-y; }
.sub { margin: 16px 4px 6px; font-size: 12px; font-weight: 600; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); }
.sub:first-child { margin-top: 0; }
.banner { width: 100%; display: flex; align-items: center; gap: 8px; margin-bottom: 10px; padding: 10px 14px; border: 0; border-radius: var(--radius-ctl); background: var(--accent-soft); color: var(--accent-soft-ink); font-size: 14px; font-weight: 600; text-align: left; }

.card { background: var(--surface); border-radius: var(--radius-card); }
.row { position: relative; border-top: 1px solid var(--line); }
.row:first-child { border-top: 0; }
.row-main { display: flex; align-items: center; min-height: var(--row-h); }
.tick { width: 56px; height: var(--row-h); flex: none; border: 0; background: transparent; display: flex; align-items: center; justify-content: center; padding: 0; }
.tick.sm { width: 40px; height: 40px; }
.notick { width: 56px; height: var(--row-h); flex: none; display: flex; align-items: center; justify-content: center; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ring); }
.tk-fill { fill: var(--accent); }
.tk-check { fill: none; stroke: var(--accent-ink); stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.tk-ring { fill: none; stroke: var(--ring); stroke-width: 1.75; }
.body { flex: 1; min-width: 0; display: flex; align-items: center; gap: 6px; min-height: var(--row-h); padding: 8px 0; border: 0; background: transparent; text-align: left; color: inherit; }
.body.pad { padding-left: 14px; padding-right: 12px; }
.when { width: 58px; flex: none; font-size: 13px; font-weight: 600; color: var(--ink-2); line-height: 1.25; }
.when.wide { width: 52px; }
.txt { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.tl { display: flex; align-items: center; gap: 8px; min-width: 0; }
.t { font-size: 16px; font-weight: 500; line-height: 1.3; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.t.done { color: var(--faint); text-decoration: line-through; }
.t.past { color: var(--muted); }
.m { margin-top: 2px; font-size: 13px; color: var(--muted); line-height: 1.3; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.m:empty { display: none; }
.chip { flex: none; padding: 2px 8px; border-radius: 999px; background: var(--highlight); color: var(--highlight-ink); font-size: 12px; font-weight: 600; white-space: nowrap; }
.dots { width: 44px; height: 48px; flex: none; border: 0; border-radius: 10px; background: transparent; color: var(--muted); display: flex; align-items: center; justify-content: center; padding: 0; }
.dots:hover { background: var(--line); }
.pips { display: flex; gap: 5px; flex: none; }
.pip { width: 10px; height: 10px; border-radius: 50%; border: 1.75px solid var(--ring); }
.pip.on { background: var(--accent); border-color: var(--accent); }
.empty { padding: 16px; font-size: 15px; color: var(--muted); }

.menu { position: absolute; right: 8px; top: 50px; z-index: 30; min-width: 196px; padding: 6px; display: flex; flex-direction: column; background: var(--surface); border-radius: 14px; box-shadow: 0 10px 30px rgba(21,23,28,.18), 0 1px 3px rgba(21,23,28,.12); }
.mi { height: 44px; display: flex; align-items: center; gap: 10px; padding: 0 12px; border: 0; border-radius: 10px; background: transparent; font-size: 15px; font-weight: 500; text-align: left; color: var(--ink); }
.mi:hover { background: var(--surface-2); }
.mi.danger { color: var(--danger); }
.menu-close { position: fixed; inset: 0; z-index: 20; border: 0; background: transparent; cursor: default; }
.inline-add { display: flex; align-items: center; gap: 8px; padding: 0 10px 10px 56px; }
.inline-in { flex: 1; min-width: 0; height: 44px; padding: 0 10px; border: 1.5px solid var(--accent); border-radius: 10px; outline: none; background: var(--surface); }

.fab {
  position: fixed; z-index: 10; right: max(20px, env(safe-area-inset-right)); bottom: calc(env(safe-area-inset-bottom) + 24px);
  width: 60px; height: 60px; border: 0; border-radius: 20px; background: var(--accent); color: var(--accent-ink);
  display: flex; align-items: center; justify-content: center; box-shadow: 0 6px 18px rgba(45,91,215,.35);
}

/* Sheets */
.sheet-wrap { position: fixed; inset: 0; z-index: 40; }
.backdrop { position: absolute; inset: 0; background: var(--scrim); opacity: 0; transition: opacity .2s; }
.sheet {
  position: absolute; left: 0; right: 0; bottom: 0; max-height: calc(100% - env(safe-area-inset-top) - 24px); max-width: 560px; margin: 0 auto;
  display: flex; flex-direction: column; background: var(--surface); border-radius: var(--radius-sheet) var(--radius-sheet) 0 0;
  transform: translateY(100%); transition: transform .24s ease-out;
}
.sheet-wrap.open .backdrop { opacity: 1; }
.sheet-wrap.open .sheet { transform: none; }
.sheet.behind { visibility: hidden; }
.grabber { width: 40px; height: 5px; margin: 10px auto 0; border-radius: 3px; background: var(--border); flex: none; }
.sheet-head { flex: none; padding: 8px 20px 6px; }
.head-row { display: flex; align-items: center; gap: 8px; }
.head-row.top { align-items: flex-start; }
.head-row .ib { background: #EDEFF2; }
.sh-title { margin: 0; font-size: 22px; font-weight: 700; line-height: 1.2; }
.sh-sub { margin-top: 2px; font-size: 14px; color: var(--muted); }
.sheet-body { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 8px 20px 24px; display: flex; flex-direction: column; }
.sheet-foot { flex: none; display: flex; gap: 10px; padding: 12px 20px calc(env(safe-area-inset-bottom) + 16px); border-top: 1px solid var(--line); }

.btn { height: 50px; padding: 0 18px; border: 0; border-radius: 14px; font-size: 16px; font-weight: 600; display: flex; align-items: center; justify-content: center; }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.soft { background: #EDEFF2; color: var(--ink); }
.btn.danger { background: var(--danger-soft); color: var(--danger); }
.btn.grow { flex: 1; }
.btn.grow2 { flex: 1.4; }
.btn-soft { height: 44px; padding: 0 12px; border: 0; border-radius: 10px; background: #EDEFF2; font-size: 14px; font-weight: 600; }
.btn-text { align-self: flex-start; margin-top: 6px; height: 44px; padding: 0 4px; border: 0; background: none; font-size: 14px; font-weight: 600; }
.btn-text.danger { color: var(--danger); }

/* Forms */
.lab { display: block; margin: 0 0 8px; font-size: 13px; font-weight: 600; color: var(--muted); }
.lab.mt, .mt { margin-top: 18px; }
.lab.m0 { margin: 0; }
.field { width: 100%; height: 46px; padding: 0 12px; border: 1.5px solid var(--border); border-radius: var(--radius-ctl); background: var(--surface); color: var(--ink); appearance: none; -webkit-appearance: none; }
select.field { padding-right: 30px; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 17px) 50%, calc(100% - 12px) 50%; background-size: 5px 5px; background-repeat: no-repeat; }
.field.big { height: 52px; font-size: 17px; font-weight: 600; }
.field.fixed { display: flex; align-items: center; margin-top: 8px; border-color: var(--surface-2); background: var(--surface-2); font-weight: 600; }
.fl { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 600; color: var(--muted); }
.hint { margin: 6px 0 0; font-size: 13px; line-height: 1.4; color: var(--muted); }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.grid3 { display: grid; grid-template-columns: minmax(0, .8fr) minmax(0, 1.2fr) minmax(0, 1.2fr); gap: 8px; }
.grid12 { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 2fr); gap: 8px; }
.when-area { height: 104px; margin-top: 10px; display: flex; flex-direction: column; gap: 8px; }
.when-area.short { height: 104px; }
.seg { display: grid; gap: 4px; padding: 4px; border-radius: var(--radius-ctl); background: var(--line-2); }
.opt { height: 40px; padding: 0; border: 0; border-radius: 9px; background: transparent; font-size: 15px; font-weight: 500; color: var(--ink-2); white-space: nowrap; overflow: hidden; }
.opt.on { background: var(--surface); color: var(--ink); font-weight: 600; box-shadow: 0 1px 2px rgba(21,23,28,.10); }
.days { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 5px; }
.day { height: 42px; padding: 0; border: 1.5px solid var(--border); border-radius: var(--radius-ctl); background: var(--surface); font-size: 15px; font-weight: 600; color: var(--ink-2); }
.day.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.datebox { position: relative; height: 52px; display: flex; align-items: center; gap: 10px; padding: 0 6px 0 14px; border: 1.5px solid var(--border); border-radius: var(--radius-ctl); background: var(--surface); color: var(--muted); }
.date-t { flex: 1; font-size: 16px; font-weight: 600; color: var(--ink); }
.date-t.empty { font-weight: 500; color: var(--faint); }
.date-native { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; }
.date-x { position: relative; z-index: 2; }
.x { width: 40px; height: 40px; flex: none; border: 0; border-radius: 10px; background: transparent; color: var(--muted); display: flex; align-items: center; justify-content: center; padding: 0; }
.x:hover { background: var(--line-2); }

.ddg { margin-top: 14px; background: var(--surface-2); border-radius: var(--radius-card); overflow: hidden; }
.dd { border-top: 1px solid var(--line-2); }
.dd:first-child { border-top: 0; }
.ddh { display: flex; align-items: center; padding-right: 6px; }
.ddb { flex: 1; min-width: 0; min-height: 56px; display: flex; align-items: center; gap: 10px; padding: 0 8px 0 16px; border: 0; background: transparent; text-align: left; color: var(--ink); }
.ddb:disabled { opacity: .45; cursor: default; }
.ddb b { flex: none; font-size: 16px; font-weight: 600; }
.sm { flex: 1; min-width: 0; text-align: right; font-size: 14px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cv { display: flex; flex: none; color: var(--muted); }
.ddp { display: flex; flex-direction: column; gap: 10px; padding: 0 14px 14px; }

.switch { position: relative; width: 52px; height: 32px; flex: none; padding: 0; border: 0; border-radius: 16px; background: #C9CDD4; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 26px; height: 26px; border-radius: 50%; background: #FFFFFF; box-shadow: 0 1px 2px rgba(0,0,0,.2); transition: left .15s; }
.switch.on { background: var(--accent); }
.switch.on::after { left: 23px; }

.lcard { display: flex; flex-direction: column; gap: 10px; padding: 6px 8px 10px 12px; border-radius: 14px; background: var(--surface); }
.lcard.lsw { flex-direction: row; align-items: center; min-height: 52px; padding: 0 12px; }
.sw-l { flex: 1; font-size: 16px; font-weight: 600; }
.lrow { display: flex; align-items: center; gap: 6px; }
.lname { flex: 1; min-width: 0; height: 44px; padding: 0; border: 0; outline: none; background: transparent; font-weight: 600; }
.vrow { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.vchip { height: 34px; display: inline-flex; align-items: center; gap: 2px; padding: 0 2px 0 10px; border-radius: 999px; background: var(--accent-soft); color: var(--accent-soft-ink); font-size: 13px; font-weight: 600; }
.vchip button { width: 30px; height: 30px; padding: 0; border: 0; border-radius: 999px; background: transparent; color: inherit; display: flex; align-items: center; justify-content: center; }
.vadd { height: 34px; padding: 0 12px; border: 1.5px solid var(--border); border-radius: 999px; background: var(--surface); color: var(--accent); font-weight: 600; appearance: none; -webkit-appearance: none; }
.sets-l { flex: 1; font-size: 14px; font-weight: 600; color: var(--ink-2); }
.sets-n { min-width: 24px; text-align: center; font-weight: 700; }
.step { width: 40px; height: 40px; border: 0; border-radius: 10px; background: #EDEFF2; display: flex; align-items: center; justify-content: center; padding: 0; color: var(--ink); }
.addlog { height: 48px; display: flex; align-items: center; justify-content: center; gap: 8px; border: 0; border-radius: var(--radius-ctl); background: var(--surface); color: var(--accent); font-size: 15px; font-weight: 600; }

.li { display: flex; align-items: center; gap: 4px; min-height: 50px; padding: 0 2px 0 12px; border-radius: var(--radius-ctl); background: var(--surface); }
.li.new { border: 1.5px solid var(--border); padding-right: 4px; }
.li.link { width: 100%; border: 0; text-align: left; color: var(--ink); padding-right: 8px; }
.li .n { flex: 1; min-width: 0; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.li-in { flex: 1; min-width: 0; height: 46px; padding: 0; border: 0; outline: none; background: transparent; }
.li-m { font-size: 13px; color: var(--muted); white-space: nowrap; }
.addb { width: 40px; height: 40px; flex: none; border: 0; border-radius: 10px; background: var(--accent); color: var(--accent-ink); display: flex; align-items: center; justify-content: center; padding: 0; }

/* Interact */
.grp { background: var(--surface-2); border-radius: var(--radius-card); }
.crow { position: relative; display: flex; align-items: center; gap: 2px; min-height: 54px; padding: 0 4px 0 0; border-top: 1px solid var(--line-2); }
.crow:first-child { border-top: 0; }
.crow .tick, .crow .notick { width: 48px; height: 52px; }
.crow.link { width: 100%; border-left: 0; border-right: 0; border-bottom: 0; background: transparent; padding-left: 14px; padding-right: 10px; gap: 8px; text-align: left; color: var(--ink); }
.crow.link:first-child { border-top: 0; }
.crow .menu { top: 48px; right: 4px; }
.plus-ic { width: 48px; display: flex; justify-content: center; color: var(--accent); }
.chk-new .addb { margin-right: 4px; }
.logcard { margin-bottom: 10px; padding: 12px 12px 12px 14px; border-radius: 16px; background: var(--surface-2); }
.loghead { display: flex; align-items: baseline; gap: 8px; margin-bottom: 8px; }
.loghead .t { flex: 1; font-weight: 600; }
.loghead .m { margin: 0; }
.setrow { display: flex; align-items: center; gap: 8px; margin-top: 6px; }
.setrow.heads { margin-top: 0; }
.setno { width: 40px; flex: none; font-size: 13px; font-weight: 600; color: var(--ink-2); }
.colh { flex: 1; min-width: 0; font-size: 12px; font-weight: 600; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.num { flex: 1; min-width: 0; height: 44px; padding: 0 10px; border: 1.5px solid var(--border); border-radius: 10px; background: var(--surface); font-weight: 600; }
.trend-head { display: flex; align-items: baseline; gap: 8px; margin-bottom: 8px; }
.trend-head .lab { flex: 1; }
.accent-t { font-size: 13px; font-weight: 600; color: var(--accent); }
.strip { display: grid; grid-template-columns: repeat(14, minmax(0, 1fr)); gap: 4px; }
.strip span { aspect-ratio: 1; border-radius: 6px; }
.dd-full { background: var(--accent); }
.dd-part { background: #A9C1FF; }
.dd-none { background: var(--line-2); }
.dd-off { background: transparent; border: 1.5px dashed var(--line-2); }
.strip .today { outline: 2px solid var(--ink); outline-offset: 1px; }
.rates { display: flex; flex-direction: column; gap: 12px; }
.rate { display: flex; align-items: center; gap: 10px; }
.rate-n { width: 112px; flex: none; font-size: 14px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar { flex: 1; height: 8px; border-radius: 4px; background: var(--line-2); overflow: hidden; }
.bar i { display: block; height: 100%; border-radius: 4px; background: var(--accent); }
.pct { width: 42px; flex: none; text-align: right; font-size: 13px; font-weight: 600; color: var(--ink-2); }
.spark { display: block; width: 100%; height: auto; }
.spark-line { fill: none; stroke: var(--accent); stroke-width: 2.5; stroke-linejoin: round; stroke-linecap: round; }
.spark-dot { fill: var(--accent); }
.spark-last { fill: var(--surface); stroke: var(--accent); stroke-width: 2.5; }
.spark-labels { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); }
.note { width: 100%; min-height: 84px; padding: 10px 12px; border: 1.5px solid var(--border); border-radius: var(--radius-ctl); background: var(--surface); line-height: 1.45; resize: vertical; }

/* Toast */
.toast {
  position: fixed; z-index: 60; left: 16px; right: 96px; bottom: calc(env(safe-area-inset-bottom) + 28px); max-width: 460px;
  min-height: 52px; display: flex; align-items: center; gap: 8px; padding: 0 6px 0 14px; border-radius: 14px; background: var(--ink); color: #FFFFFF; font-size: 14px;
}
.toast-text { flex: 1; min-width: 0; }
.toast-btn { height: 40px; padding: 0 12px; border: 0; border-radius: 10px; background: transparent; color: #A9C1FF; font-weight: 700; }

/* Access screen */
.access { min-height: 100vh; min-height: 100dvh; max-width: 480px; margin: 0 auto; display: flex; flex-direction: column; gap: 16px; padding: calc(env(safe-area-inset-top) + 40px) 28px calc(env(safe-area-inset-bottom) + 28px); }
.access-top { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; text-align: center; }
.access-top h1 { margin: 8px 0 0; font-size: 28px; letter-spacing: -0.02em; }
.access-top p { margin: 0; max-width: 300px; color: var(--ink-2); line-height: 1.5; }
.access-msg:empty { display: none; }
.access-msg { color: var(--danger) !important; font-weight: 600; }
.qr-tile { width: 112px; height: 112px; border-radius: 28px; background: var(--surface); color: var(--accent); display: flex; align-items: center; justify-content: center; }
.access-form { display: flex; gap: 8px; }
.stored { padding: 16px; border-radius: var(--radius-card); background: var(--surface); font-size: 14px; color: var(--ink-2); line-height: 1.5; }
.stored p { margin: 4px 0 0; }

/* Fixes: keep sheet sections at full height; title fills the header row; lighter "last time" hints */
.sheet-body > * { flex-shrink: 0; }
.head-row > .sh-title { flex: 1; min-width: 0; }
.num::placeholder, .li-in::placeholder, .inline-in::placeholder, .field::placeholder, .note::placeholder { color: #9AA0AA; font-weight: 500; }

/* Drag to move */
.grip { width: 30px; height: var(--row-h); flex: none; border: 0; background: transparent; color: var(--ring); display: flex; align-items: center; justify-content: center; padding: 0 0 0 4px; touch-action: none; cursor: grab; }
.grip.off { cursor: default; }
.row-main .grip + .tick, .row-main .grip + .notick { width: 44px; }
.row.dragging { opacity: .35; }
.ghost { position: fixed; z-index: 70; pointer-events: none; opacity: .72; transform: scale(.94); transform-origin: 0 50%; background: var(--surface); border-radius: 14px; border-top: 0; box-shadow: 0 12px 30px rgba(21,23,28,.22); }
.row.drop-into { background: var(--accent-soft); box-shadow: inset 0 0 0 2px var(--accent); border-radius: 12px; }
.row.drop-before::before, .row.drop-after::after { content: ""; position: absolute; left: 12px; right: 12px; height: 3px; border-radius: 2px; background: var(--accent); z-index: 5; }
.row.drop-before::before { top: -2px; }
.row.drop-after::after { bottom: -2px; }
.row .when { width: 54px; }
