:root {
  --bg: #eef1f7;
  --bg-2: #f7f9fc;
  --card: #ffffff;
  --ink: #17202e;
  --muted: #6b7686;
  --line: #e3e8f0;
  --accent: #2f6fed;
  --accent-2: #5b8def;
  --accent-soft: rgba(47,111,237,.10);
  --accent-ink: #ffffff;
  --ring: rgba(47,111,237,.28);
  --overdue: #e5484d;
  --overdue-soft: rgba(229,72,77,.13);
  --due: #eab308;
  --due-ink: #9a6a00;
  --due-soft: rgba(234,179,8,.16);
  --upcoming: #16a34a;
  --upcoming-soft: rgba(22,163,74,.13);
  --radius: 16px;
  --shadow: 0 1px 2px rgba(20,30,50,.05), 0 4px 14px rgba(20,30,50,.05);
  --shadow-lg: 0 12px 40px rgba(15,25,50,.22);
  --tabbar-h: 64px;
  --ease: cubic-bezier(.32,.72,0,1);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1219; --bg-2: #161b24; --card: #1a1f2b; --ink: #e8ecf3; --muted: #93a0b4;
    --line: #2a313d; --accent: #5b8def; --accent-2: #7aa5f5; --accent-soft: rgba(91,141,239,.16);
    --ring: rgba(91,141,239,.35); --accent-ink: #0f1219;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 6px 20px rgba(0,0,0,.35);
    --shadow-lg: 0 16px 50px rgba(0,0,0,.6);
    --due-ink: #eab308;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }  /* beat class rules that set display */
html, body { margin: 0; padding: 0; overflow-x: hidden; max-width: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg); color: var(--ink);
  background-image: radial-gradient(120% 60% at 100% 0, var(--bg-2), var(--bg) 60%);
  background-attachment: fixed;
  -webkit-text-size-adjust: 100%;
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
}
a { color: inherit; text-decoration: none; }
h1 { font-size: 1.5rem; margin: 0; letter-spacing: -.02em; }
h2.sec { font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 24px 4px 10px; font-weight: 700; }

/* top bar */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
  background: var(--card); border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; font-size: 1.15rem; }
.topbar-actions { display: flex; align-items: center; gap: 14px; }
.topbar-search { font-size: 1.2rem; }
.logout-form { margin: 0; display: flex; }
.topbar-btn { background: none; border: none; font-size: 1.2rem; cursor: pointer; color: var(--muted); padding: 0; line-height: 1; }

/* auth pages */
.auth-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; }
.auth-card { width: 100%; max-width: 380px; background: var(--card); border: 1px solid var(--line);
  border-radius: 20px; box-shadow: var(--shadow-lg); padding: 30px 26px; }
.auth-brand { font-size: 1.3rem; font-weight: 800; margin-bottom: 18px; }
.auth-title { font-size: 1.5rem; margin: 0; letter-spacing: -.02em; }
.auth-sub { color: var(--muted); margin: 6px 0 20px; font-size: .92rem; }
.auth-form { display: flex; flex-direction: column; gap: 14px; }
.auth-form .btn { margin-top: 6px; }
.auth-error { background: var(--overdue-soft); color: var(--overdue); font-size: .88rem; font-weight: 600;
  padding: 10px 12px; border-radius: 10px; margin-bottom: 16px; }

.content { max-width: 760px; margin: 0 auto; padding: 14px 14px 30px; }

/* page head */
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 6px 2px 14px; }
.ph-title { display: flex; align-items: center; gap: 6px; min-width: 0; }
.ph-title h1 { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.back { font-size: 1.7rem; line-height: 1; color: var(--muted); padding: 0 6px 0 0; }
.coll-emoji, .coll-dot { display: inline-block; }
.coll-dot { width: 9px; height: 9px; border-radius: 50%; margin-right: 5px; vertical-align: middle; }

/* buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font-size: .95rem; font-weight: 650; padding: 10px 16px; border-radius: 11px;
  border: 1px solid var(--line); background: var(--card); color: var(--ink);
  cursor: pointer; min-height: 44px; transition: transform .12s var(--ease), box-shadow .18s, filter .18s;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: scale(.96); }
.btn.sm { padding: 6px 12px; min-height: 34px; font-size: .85rem; border-radius: 9px; }
.btn.big { padding: 14px 20px; min-height: 52px; font-size: 1rem; border-radius: 13px; }
.btn.primary { background: linear-gradient(180deg, var(--accent-2), var(--accent)); color: #fff;
  border-color: transparent; box-shadow: 0 2px 10px var(--ring); }
.btn.primary:hover { filter: brightness(1.04); }
.btn.ghost { background: transparent; }
.btn.ghost:hover { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.btn.danger { background: transparent; color: var(--overdue); border-color: transparent; }
.btn.done-btn { background: linear-gradient(180deg, #22b866, var(--upcoming)); color: #fff;
  border-color: transparent; padding: 9px 18px; box-shadow: 0 2px 10px rgba(22,163,74,.25); }
.subbar { display: flex; gap: 8px; margin: -6px 2px 12px; flex-wrap: wrap; }

/* chips (collection filter) */
.chip-row { display: flex; gap: 8px; overflow-x: auto; padding: 2px 2px 10px; -webkit-overflow-scrolling: touch; }
.chip {
  flex: 0 0 auto; padding: 8px 14px; border-radius: 999px; background: var(--card);
  border: 1px solid var(--line); font-size: .88rem; font-weight: 650; white-space: nowrap;
  box-shadow: var(--shadow); transition: transform .12s var(--ease);
}
.chip:active { transform: scale(.95); }
.chip.on { background: var(--ink); color: var(--bg-2); border-color: var(--ink); }

/* cards */
.cards { display: flex; flex-direction: column; gap: 10px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 15px; transition: transform .14s var(--ease), box-shadow .18s; }
a.card:active, .collection-card:active { transform: scale(.985); }
@media (hover: hover) { a.card:hover, .collection-card:hover { box-shadow: var(--shadow-lg); transform: translateY(-1px); } }

/* collection grid */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.collection-card {
  display: flex; align-items: center; gap: 12px; padding: 16px;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); border-left: 5px solid var(--accent);
}
.cc-icon { font-size: 1.9rem; }
.cc-name { font-weight: 700; }
.cc-count { color: var(--muted); font-size: .85rem; }

/* item rows */
.item-row { display: flex; align-items: center; gap: 12px; }
.item-row.archived { opacity: .55; }
.item-thumb {
  width: 54px; height: 54px; border-radius: 10px; overflow: hidden; flex: 0 0 auto;
  background: var(--bg); display: flex; align-items: center; justify-content: center;
}
.item-thumb img { width: 100%; height: 100%; object-fit: cover; }
.item-thumb.mono { background: color-mix(in srgb, var(--c) 15%, var(--bg)); }
.thumb-mono { font-size: 1.5rem; font-weight: 800; color: var(--c); line-height: 1; }
.thumb-ph { font-size: 1.6rem; }
.item-body { min-width: 0; flex: 1; }
.item-name { font-weight: 700; }
.item-sub { font-size: .85rem; }
.chevron { color: var(--muted); font-size: 1.4rem; }
.tag { font-size: .68rem; background: var(--line); color: var(--muted); padding: 2px 6px; border-radius: 6px; vertical-align: middle; }

/* event cards (upcoming) */
.event-card { border-left: 4px solid var(--line); }
.event-card.status-overdue { border-left-color: var(--overdue); }
.event-card.status-due_soon { border-left-color: var(--due); }
.event-card.status-upcoming { border-left-color: var(--upcoming); }
.event-main { display: flex; align-items: center; gap: 12px; }
.event-info { flex: 1; min-width: 0; }
.event-title { font-weight: 700; display: block; }
.event-sub { color: var(--muted); font-size: .85rem; margin-top: 2px; }
.due { font-weight: 600; }

.badge { display: inline-flex; align-items: center; gap: 4px; font-size: .66rem; font-weight: 800;
  text-transform: uppercase; letter-spacing: .04em; padding: 3px 8px; border-radius: 999px; }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-overdue { background: var(--overdue-soft); color: var(--overdue); }
.badge-due_soon { background: var(--due-soft); color: var(--due-ink); }
.badge-upcoming { background: var(--upcoming-soft); color: var(--upcoming); }

/* event history table */
.ev-table { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); overflow: hidden; }
.ev-head, .ev-tr { display: grid; grid-template-columns: 15px 56px 1fr 58px 46px; gap: 8px;
  align-items: center; padding: 9px 12px; }
.ev-head { font-size: .62rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted);
  font-weight: 700; background: var(--bg-2); border-bottom: 1px solid var(--line); }
.ev-tr { width: 100%; text-align: left; background: none; border: none; border-top: 1px solid var(--line);
  font: inherit; color: inherit; cursor: pointer; min-height: 0; -webkit-tap-highlight-color: transparent; }
.ev-rowwrap:first-of-type .ev-tr { border-top: none; }
.ev-tr.static { cursor: default; }
.ev-tr:not(.static):active { background: var(--bg); }
.ev-caret { color: var(--muted); font-size: 1.1rem; line-height: 1; text-align: center;
  transition: transform .18s var(--ease); }
.ev-rowwrap.open .ev-caret { transform: rotate(90deg); color: var(--accent); }
.c-date { font-size: .8rem; color: var(--muted); white-space: nowrap; }
.c-desc { font-weight: 600; font-size: .89rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.c-num { text-align: right; font-size: .83rem; font-variant-numeric: tabular-nums; white-space: nowrap; }
.ev-head .c-desc { font-weight: 700; }
.ev-detail { display: none; padding: 4px 14px 16px 35px; border-top: 1px dashed var(--line); }
.ev-rowwrap.open .ev-detail { display: block; animation: ed-in .18s var(--ease); }
@keyframes ed-in { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }
.ed-what { font-size: .93rem; margin-bottom: 12px; white-space: pre-wrap; line-height: 1.4; }
.ed-facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(88px, 1fr)); gap: 10px 16px; margin-bottom: 12px; }
.ed-facts .k { display: block; font-size: .66rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.ed-facts .v { font-weight: 650; font-size: .92rem; }
.ed-notes { font-size: .9rem; white-space: pre-wrap; margin-bottom: 12px; line-height: 1.4; }
.ed-photos { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.ed-photos img { width: 68px; height: 68px; object-fit: cover; border-radius: 9px; border: 1px solid var(--line); }
.ed-actions { display: flex; gap: 8px; }

/* event line (item page) */
.event-line { display: flex; align-items: center; gap: 10px; }
.event-line.status-overdue { border-left: 4px solid var(--overdue); }
.event-line.status-due_soon { border-left: 4px solid var(--due); }
.el-main { flex: 1; min-width: 0; }
.el-title { font-weight: 600; display: block; }
.el-sub { font-size: .82rem; margin-top: 2px; }

/* forms */
.stack { display: flex; flex-direction: column; gap: 14px; }
label { display: block; font-size: .8rem; font-weight: 600; color: var(--muted); }
input, select, textarea {
  width: 100%; margin-top: 5px; padding: 11px 12px; font-size: 1rem;
  border: 1px solid var(--line); border-radius: 10px; background: var(--card); color: var(--ink);
  font-family: inherit;
}
input[type=color] { padding: 4px; height: 44px; }
textarea { resize: vertical; }
.field-row { display: flex; gap: 10px; }
.field-row > label { flex: 1; }
.field-row .narrow { flex: 0 0 90px; }
.field-row .grow { flex: 1; }
.inline-form { margin-bottom: 12px; }
.form-actions { display: flex; gap: 10px; justify-content: flex-end; align-items: center; margin-top: 4px; }
.form-actions.between { justify-content: space-between; }
.action-row { display: flex; flex-wrap: wrap; gap: 8px; margin: 14px 0; }
.action-row form { margin: 0; }

/* segmented control */
.seg { display: flex; gap: 6px; background: var(--bg); padding: 4px; border-radius: 12px; }
.seg.small { max-width: 340px; }
.seg-opt { flex: 1; }
.seg-opt input { display: none; }
.seg-opt span { display: block; text-align: center; padding: 9px; border-radius: 9px; font-weight: 600; font-size: .9rem; color: var(--muted); }
.seg-opt input:checked + span { background: var(--card); color: var(--ink); box-shadow: var(--shadow); }

fieldset.recur { border: 1px solid var(--line); border-radius: 12px; padding: 12px; }
fieldset.recur legend { font-size: .8rem; color: var(--muted); font-weight: 600; padding: 0 6px; }
.hint { font-size: .78rem; color: var(--muted); margin: 8px 2px 0; }

/* specs */
.specs { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 18px; }
.spec { display: flex; flex-direction: column; }
.spec .k { font-size: .72rem; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.spec .v { font-weight: 600; }
.spec .v.strong { color: var(--accent); }
.desc { white-space: pre-wrap; color: var(--ink); font-size: .95rem; }
.item-collection { margin: -6px 2px 12px; color: var(--muted); font-weight: 600; }

/* usage card */
.usage-card { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.usage-now { flex: 1; }
.usage-now .k { display: block; font-size: .72rem; color: var(--muted); text-transform: uppercase; }
.usage-val { font-size: 1.5rem; font-weight: 700; }
.usage-val small { font-size: .9rem; color: var(--muted); font-weight: 600; }
.usage-form { flex-basis: 100%; }

/* photos */
.photo-strip { display: flex; gap: 10px; overflow-x: auto; padding: 4px 2px 12px; }
.ph-item { position: relative; flex: 0 0 auto; }
.ph-item img { width: 92px; height: 92px; object-fit: cover; border-radius: 10px; border: 1px solid var(--line); }
.ph-del { position: absolute; top: -6px; right: -6px; width: 24px; height: 24px; border-radius: 50%;
  background: var(--overdue); color: #fff; border: 2px solid var(--card); font-size: 14px; line-height: 1; cursor: pointer; }
.ph-add { display: flex; align-items: center; justify-content: center; width: 92px; height: 92px; flex: 0 0 auto;
  border: 2px dashed var(--line); border-radius: 10px; color: var(--muted); font-size: 1.3rem; cursor: pointer; }
.ph-add input { display: none; }
.photo-field { display: block; border: 2px dashed var(--line); border-radius: 12px; padding: 14px; text-align: center; color: var(--muted); font-weight: 600; cursor: pointer; }
.photo-field.big { padding: 22px; }
.photo-field input[type=file] { display: none; }
.photo-field.dragover { border-color: var(--accent); color: var(--accent); }
.photo-hint { display: block; font-weight: 400; font-size: .78rem; margin-top: 6px; }

/* search */
.search-form { display: flex; gap: 8px; margin-bottom: 6px; }
.search-form input { margin-top: 0; }

/* icon picker */
.icon-picker { margin-top: 6px; }
.icon-preview {
  width: 52px; height: 52px; display: flex; align-items: center; justify-content: center;
  font-size: 1.9rem; border: 1px solid var(--line); border-radius: 12px; background: var(--bg); margin-bottom: 8px;
}
.icon-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(44px, 1fr)); gap: 6px;
  max-height: 168px; overflow-y: auto; padding: 4px; border: 1px solid var(--line);
  border-radius: 12px; background: var(--card);
}
.emoji-opt {
  aspect-ratio: 1; min-height: 44px; font-size: 1.4rem; line-height: 1;
  border: 1px solid transparent; border-radius: 10px; background: var(--bg);
  cursor: pointer; display: flex; align-items: center; justify-content: center; padding: 0;
}
.emoji-opt:active { transform: scale(.92); }
.emoji-opt.selected { border-color: var(--accent); background: rgba(47,111,237,.12); box-shadow: 0 0 0 2px rgba(47,111,237,.25); }
.icon-custom { margin-top: 8px; }

.empty { text-align: center; padding: 40px 20px; color: var(--ink); }
.empty .muted { font-size: .9rem; }
.muted { color: var(--muted); }
.pad { padding: 4px 4px 8px; }

/* bottom tab bar */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: flex; background: var(--card); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom); height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
}
.tab { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  color: var(--muted); font-size: .68rem; font-weight: 650; padding-top: 8px; position: relative; transition: color .15s; }
.tab.active { color: var(--accent); }
.tab.active .tico { transform: translateY(-1px); }
.tico { font-size: 1.3rem; transition: transform .18s var(--ease); }

/* ===== complete-event bottom sheet ===== */
.sheet-backdrop {
  position: fixed; inset: 0; z-index: 60; background: rgba(10,15,30,.5);
  backdrop-filter: blur(2px); opacity: 0; transition: opacity .24s var(--ease);
}
.sheet-backdrop.show { opacity: 1; }
.sheet {
  position: fixed; z-index: 61; left: 0; right: 0; bottom: 0;
  background: var(--bg-2); border-radius: 22px 22px 0 0;
  box-shadow: var(--shadow-lg); max-height: 94vh; display: flex; flex-direction: column;
  transform: translateY(101%); transition: transform .3s var(--ease);
  padding-bottom: env(safe-area-inset-bottom);
}
.sheet.show { transform: translateY(0); }
@media (min-width: 620px) {
  .sheet { left: 50%; right: auto; bottom: 24px; width: 540px; transform: translate(-50%, 120%);
    border-radius: 22px; max-height: 88vh; }
  .sheet.show { transform: translate(-50%, 0); }
}
.sheet form { display: flex; flex-direction: column; min-height: 0; }
.sheet-grip { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 10px auto 4px; flex: 0 0 auto; }

.sheet-head { display: flex; align-items: flex-start; gap: 12px; padding: 8px 20px 14px; border-bottom: 1px solid var(--line); }
.sheet-head-main { flex: 1; min-width: 0; }
.sheet-kicker { font-size: .68rem; font-weight: 800; text-transform: uppercase; letter-spacing: .08em; color: var(--accent); }
.sheet-title { font-size: 1.35rem; font-weight: 750; letter-spacing: -.02em; margin-top: 2px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sheet-sub { color: var(--muted); font-size: .9rem; font-weight: 600; margin-top: 2px; }
.sheet-x { width: 36px; height: 36px; flex: 0 0 auto; border-radius: 50%; border: none;
  background: var(--card); color: var(--muted); font-size: 1.5rem; line-height: 1; cursor: pointer; box-shadow: var(--shadow); }

.sheet-body { overflow-y: auto; padding: 16px 20px 8px; display: flex; flex-direction: column; gap: 0; }

.cs-block { border: 1px solid var(--line); border-radius: 15px; padding: 14px; background: var(--card); }
.cs-block.cs-next { background: linear-gradient(180deg, var(--accent-soft), transparent 140%); border-color: var(--accent); border-style: dashed; }
.cs-step { display: flex; align-items: center; gap: 9px; font-weight: 750; font-size: .95rem; margin-bottom: 10px; }
.cs-badge { display: inline-flex; align-items: center; justify-content: center; width: 24px; height: 24px;
  border-radius: 50%; font-size: .8rem; font-weight: 800; flex: 0 0 auto; }
.cs-badge.done { background: var(--upcoming); color: #fff; }
.cs-badge.next { background: var(--accent); color: #fff; }
.cs-flow { text-align: center; color: var(--accent); font-size: 1.3rem; line-height: 1; padding: 7px 0; font-weight: 800; }

.cs-next-card { background: var(--card); border: 1px solid var(--accent); border-radius: 12px; padding: 13px 14px; display: flex; flex-direction: column; gap: 10px; }
.cs-fld { display: block; font-size: .72rem; font-weight: 700; color: var(--muted);
  text-transform: uppercase; letter-spacing: .03em; margin: 0; }
.cs-fld input { margin-top: 5px; }
.cs-next-meta { color: var(--muted); font-size: .82rem; }
.cs-next-meta b { color: var(--ink); font-weight: 700; }
.cs-next-none { color: var(--muted); font-size: .9rem; margin: 4px 0 0; }
.unit-tag { background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 0 6px; font-size: .72rem; font-weight: 700; color: var(--muted); }

.sheet-foot { display: flex; gap: 10px; padding: 14px 20px calc(16px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line); background: var(--bg-2); }
.sheet-foot .btn { flex: 1; }
.sheet-foot .btn.ghost { flex: 0 0 auto; }
.photo-field.slim { padding: 12px; }

/* confirm popover */
.confirm-pop { position: fixed; z-index: 50; background: var(--card); border: 1px solid var(--line);
  border-radius: 12px; box-shadow: 0 8px 30px rgba(0,0,0,.22); padding: 14px; max-width: 280px; }
.confirm-pop p { margin: 0 0 12px; font-size: .92rem; }
.confirm-actions { display: flex; gap: 8px; justify-content: flex-end; }
.confirm-backdrop { position: fixed; inset: 0; z-index: 45; }
