:root {
  color-scheme: light dark;
  --bg: #f5f5f7;
  --surface: #ffffff;
  --surface-raised: #ffffff;
  --text: #37373d;
  --heading: #26262d;
  --muted: #797982;
  --line: #e2e2e8;
  --accent: #5966c7;
  --accent-strong: #4855b2;
  --accent-soft: #eceefc;
  --on-accent: #ffffff;
  --danger: #d70015;
  --success: #327a55;
  --nav-bg: rgb(255 255 255 / 90%);
  --shadow: 0 8px 30px rgb(30 30 50 / 6%);
  --keyboard-inset: 0px;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display", "PingFang SC", "Segoe UI", sans-serif;
  font-synthesis: none;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111114;
    --surface: #1c1c21;
    --surface-raised: #24242b;
    --text: #e8e8ed;
    --heading: #f7f7fa;
    --muted: #9b9ba6;
    --line: #35353e;
    --accent: #aab3ff;
    --accent-strong: #bcc3ff;
    --accent-soft: #2c3050;
    --on-accent: #20244a;
    --danger: #ff6961;
    --success: #77c69a;
    --nav-bg: rgb(28 28 33 / 92%);
    --shadow: 0 10px 34px rgb(0 0 0 / 20%);
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { min-height: 100%; background: var(--bg); -webkit-text-size-adjust: 100%; }
body {
  min-width: 280px;
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
button, input, textarea { font: inherit; }
button, summary, a { -webkit-tap-highlight-color: transparent; }
button {
  min-height: 44px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  touch-action: manipulation;
}
button:disabled { opacity: .55; cursor: default; }
button:focus-visible, summary:focus-visible, input:focus-visible, textarea:focus-visible, a:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--accent) 50%, transparent);
  outline-offset: 2px;
}
input, textarea {
  width: 100%;
  min-height: 46px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
}
input:focus, textarea:focus { border-color: var(--accent); }
input::placeholder, textarea::placeholder { color: var(--muted); opacity: .75; }
textarea { min-height: 112px; line-height: 1.55; resize: vertical; }
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 7px; color: var(--heading); font-size: 32px; line-height: 1.16; letter-spacing: -.035em; }
h2 { margin: 0; color: var(--heading); font-size: 22px; line-height: 1.25; letter-spacing: -.02em; }
h3 { margin-bottom: 5px; color: var(--heading); font-size: 16px; }
a { color: var(--accent); }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}
.eyebrow {
  margin-bottom: 6px; color: var(--accent); font-size: 12px; font-weight: 700;
  letter-spacing: .08em; text-transform: uppercase;
}
.primary-button { border-color: var(--accent); background: var(--accent); color: var(--on-accent); font-weight: 700; }
.primary-button:hover:not(:disabled) { border-color: var(--accent-strong); background: var(--accent-strong); }
.full-button { width: 100%; }
.text-button { border-color: transparent; background: transparent; color: var(--accent); }
.danger-text, .danger-button { color: var(--danger); }
.icon-button { width: 44px; flex: none; padding: 0; border: 0; background: transparent; font-size: 29px; line-height: 1; }
.field { min-width: 0; margin-bottom: 17px; }
.field label { display: block; margin-bottom: 6px; color: var(--text); font-size: 14px; font-weight: 600; }
.form-hint { margin: 6px 0 0; color: var(--muted); font-size: 12px; }
.form-error { margin: 12px 0; color: var(--danger); font-size: 14px; }
.two-columns { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.auth-view {
  min-height: 100vh; min-height: 100dvh;
  padding: calc(50px + env(safe-area-inset-top)) 22px calc(30px + env(safe-area-inset-bottom));
}
.auth-content { width: 100%; max-width: 430px; margin: 0 auto; }
.login-content { padding-top: 7vh; }
.app-mark {
  display: grid; place-items: center; width: 64px; height: 64px; margin-bottom: 28px;
  border-radius: 18px; background: var(--accent); color: var(--on-accent);
  font-size: 30px; font-weight: 800; box-shadow: var(--shadow);
}
.auth-intro { margin-bottom: 28px; color: var(--muted); font-size: 15px; }

#app-view { width: 100%; max-width: 720px; min-height: 100vh; min-height: 100dvh; margin: 0 auto; }
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; justify-content: space-between;
  min-height: calc(58px + env(safe-area-inset-top)); padding: env(safe-area-inset-top) 18px 0;
  border-bottom: 1px solid color-mix(in srgb, var(--line) 75%, transparent);
  background: var(--nav-bg); -webkit-backdrop-filter: blur(20px); backdrop-filter: blur(20px);
}
.wordmark { color: var(--heading); font-size: 18px; font-weight: 750; letter-spacing: -.02em; text-decoration: none; }
.user-menu { position: relative; flex: none; }
.user-menu summary {
  display: flex; align-items: center; justify-content: center; min-width: 48px; min-height: 40px;
  padding: 0 11px; border-radius: 999px; background: var(--accent-soft); color: var(--accent);
  font-size: 14px; font-weight: 700; cursor: pointer; list-style: none;
}
.user-menu summary::-webkit-details-marker { display: none; }
.menu-chevron { margin-left: 4px; font-size: 15px; }
.menu-popover {
  position: absolute; top: 47px; right: 0; z-index: 30; width: 205px; padding: 6px;
  border: 1px solid var(--line); border-radius: 16px; background: var(--surface-raised); box-shadow: 0 14px 40px rgb(0 0 0 / 16%);
}
.menu-popover button { display: block; width: 100%; border-color: transparent; background: transparent; text-align: left; }

#main-content { padding: 0 16px calc(112px + env(safe-area-inset-bottom) + var(--keyboard-inset)); }
.view-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; padding: 27px 2px 20px; }
.view-heading .eyebrow { color: var(--muted); font-weight: 600; letter-spacing: .02em; }
.view-subtitle { margin: 0; color: var(--muted); font-size: 14px; }
.new-item-button {
  display: flex; align-items: center; gap: 4px; flex: none; min-height: 42px; padding: 0 15px;
  border: 0; border-radius: 999px; background: var(--accent); color: var(--on-accent); font-weight: 700;
  box-shadow: 0 4px 14px color-mix(in srgb, var(--accent) 22%, transparent);
}
.new-item-button span:first-child { font-size: 22px; font-weight: 400; line-height: 1; }
.search-box { position: relative; margin-bottom: 15px; }
.search-box input { min-height: 44px; padding-left: 38px; border-color: transparent; background: var(--surface); }
.search-box::before {
  content: ""; position: absolute; left: 15px; top: 14px; width: 11px; height: 11px;
  border: 1.8px solid var(--muted); border-radius: 50%; pointer-events: none;
}
.search-box::after {
  content: ""; position: absolute; left: 27px; top: 27px; width: 6px; height: 2px;
  background: var(--muted); transform: rotate(45deg); pointer-events: none;
}
.inline-error { display: flex; align-items: center; justify-content: space-between; gap: 8px; color: var(--danger); font-size: 14px; }
.group-header { display: flex; align-items: center; justify-content: space-between; min-height: 40px; padding: 0 3px; }
.group-header h2 { font-size: 17px; }
.count-badge {
  display: inline-flex; align-items: center; justify-content: center; min-width: 24px; min-height: 24px;
  padding: 2px 8px; border-radius: 999px; background: var(--surface); color: var(--muted); font-size: 12px;
}
.item-list, .history-list, .attachment-list, .selected-file-list, .insight-list { margin: 0; padding: 0; list-style: none; }
#active-list, #completed-list { overflow: hidden; border: 1px solid var(--line); border-radius: 20px; background: var(--surface); box-shadow: var(--shadow); }
#active-list:empty, #completed-list:empty { display: none; }
.item-card { display: grid; grid-template-columns: 50px minmax(0, 1fr); border-bottom: 1px solid var(--line); }
.item-card:last-child { border-bottom: 0; }
.item-card.memo-card { grid-template-columns: minmax(0, 1fr); }
.check-button { align-self: start; width: 44px; min-height: 44px; margin: 13px 0 0 5px; padding: 0; border: 0; background: transparent; }
.check-circle {
  display: block; width: 24px; height: 24px; margin: auto; border: 1.8px solid var(--muted);
  border-radius: 50%; transition: background .15s, border-color .15s;
}
.check-button:hover .check-circle { border-color: var(--accent); }
.item-card.completed .check-circle { position: relative; border-color: var(--success); background: var(--success); }
.item-card.completed .check-circle::after {
  content: ""; position: absolute; left: 7px; top: 3px; width: 6px; height: 11px;
  border: solid white; border-width: 0 2px 2px 0; transform: rotate(45deg);
}
.item-main {
  display: block; width: 100%; min-height: 74px; padding: 15px 15px 15px 0; border: 0; border-radius: 0;
  background: transparent; text-align: left;
}
.memo-card .item-main { padding-left: 17px; }
.item-title-row { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.item-title { color: var(--heading); font-size: 16px; font-weight: 650; overflow-wrap: anywhere; }
.item-card.completed .item-title { color: var(--muted); text-decoration: line-through; }
.quantity { flex: none; color: var(--accent); font-size: 13px; font-weight: 650; }
.item-note {
  display: -webkit-box; margin: 5px 0 0; overflow: hidden; color: var(--muted); font-size: 13px;
  white-space: pre-line; overflow-wrap: anywhere; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
}
.item-meta { display: flex; flex-wrap: wrap; gap: 6px 12px; margin-top: 9px; color: var(--muted); font-size: 12px; }
.meta-reminder { color: var(--accent); }
.meta-reminder.overdue { color: var(--danger); font-weight: 650; }
.memo-date { margin-left: auto; }
.attachment-strip { display: flex; gap: 7px; margin-top: 10px; overflow: hidden; }
.attachment-thumb { width: 42px; height: 42px; border: 1px solid var(--line); border-radius: 9px; object-fit: cover; }
.attachment-more { display: grid; place-items: center; min-width: 42px; height: 42px; border-radius: 9px; background: var(--accent-soft); color: var(--accent); font-size: 12px; }
.completed-section { margin-top: 18px; }
.completed-section summary {
  display: flex; align-items: center; justify-content: space-between; min-height: 46px; padding: 0 3px;
  color: var(--muted); font-size: 14px; font-weight: 650; cursor: pointer; list-style: none;
}
.completed-section summary::-webkit-details-marker { display: none; }
#completed-list { box-shadow: none; opacity: .82; }
.list-footnote { margin: 22px 8px 0; color: var(--muted); font-size: 12px; text-align: center; }
.empty-state { padding: 42px 20px 30px; text-align: center; }
.empty-symbol {
  display: grid; place-items: center; width: 54px; height: 54px; margin: 0 auto 15px;
  border-radius: 50%; background: var(--accent-soft); color: var(--accent); font-size: 26px;
}
.empty-state h3 { margin-bottom: 7px; font-size: 18px; }
.empty-state p { max-width: 290px; margin: 0 auto 5px; color: var(--muted); font-size: 14px; }
.empty-note { padding: 28px 6px; color: var(--muted); font-size: 14px; text-align: center; }

.bottom-nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 25; display: grid; grid-template-columns: repeat(3, 1fr);
  width: 100%; max-width: 720px; margin: 0 auto; padding: 7px 8px calc(7px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line); background: var(--nav-bg); -webkit-backdrop-filter: blur(22px); backdrop-filter: blur(22px);
}
.bottom-nav button {
  position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  min-height: 57px; padding: 2px; border: 0; border-radius: 12px; background: transparent; color: var(--muted); font-size: 11px;
}
.bottom-nav button[aria-current="page"] { color: var(--accent); }
.bottom-nav svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.nav-count {
  position: absolute; top: 0; left: calc(50% + 8px); min-width: 17px; height: 17px; padding: 0 4px;
  border-radius: 9px; background: var(--accent); color: var(--on-accent); font-size: 10px; line-height: 17px;
}

.secondary-header { padding: 25px 2px 20px; }
.secondary-header h1 { margin-top: 13px; }
.secondary-header p { margin: 0; color: var(--muted); font-size: 14px; }
.back-button { min-height: 40px; padding: 0; border: 0; background: transparent; color: var(--accent); }
.history-list { overflow: hidden; border: 1px solid var(--line); border-radius: 18px; background: var(--surface); }
.history-row { display: flex; align-items: center; gap: 10px; min-height: 74px; padding: 13px 14px; border-bottom: 1px solid var(--line); }
.history-row:last-child { border-bottom: 0; }
.history-info { min-width: 0; flex: 1; }
.history-title { margin: 0; color: var(--heading); font-weight: 650; overflow-wrap: anywhere; }
.history-meta { margin: 4px 0 0; color: var(--muted); font-size: 12px; }
.history-delete { flex: none; min-height: 38px; padding: 0 6px; border: 0; background: transparent; color: var(--danger); font-size: 12px; }

.bottom-sheet {
  width: 100%; max-width: 680px; max-height: 92vh; max-height: 92dvh; margin: auto auto 0; padding: 0;
  overflow: hidden; border: 1px solid var(--line); border-bottom: 0; border-radius: 24px 24px 0 0;
  background: var(--surface-raised); color: var(--text); box-shadow: 0 -12px 50px rgb(0 0 0 / 18%);
}
.bottom-sheet[open] { display: flex; flex-direction: column; }
.bottom-sheet::backdrop, .image-viewer::backdrop { background: rgb(0 0 0 / 38%); -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px); }
#editor-form { display: flex; width: 100%; min-height: 0; flex-direction: column; }
.sheet-header { display: flex; align-items: center; justify-content: space-between; flex: none; padding: 19px 18px 12px; }
.sheet-header .eyebrow { margin-bottom: 3px; }
.sheet-scroll { min-height: 0; padding: 6px 18px 18px; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.sheet-actions { flex: none; padding: 12px 18px calc(12px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); background: var(--surface-raised); }
.edit-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 9px; }
.attachment-section { margin: 7px 0 14px; padding: 14px; border-radius: 16px; background: var(--bg); }
.attachment-heading-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.attachment-heading-row h3 { margin: 0; font-size: 15px; }
.attachment-heading-row p { margin: 3px 0 0; color: var(--muted); font-size: 11px; }
.file-button {
  display: inline-flex; align-items: center; justify-content: center; flex: none; min-height: 40px; padding: 0 11px;
  border: 1px solid var(--line); border-radius: 11px; background: var(--surface); color: var(--accent); font-size: 13px; font-weight: 650; cursor: pointer;
}
.file-button input { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; opacity: 0; }
.file-button:focus-within { outline: 3px solid var(--accent-soft); }
.attachment-list:not(:empty), .selected-file-list:not(:empty) { margin-top: 12px; }
.attachment-row, .selected-file-row { display: flex; align-items: center; gap: 10px; min-height: 52px; padding: 7px 0; border-top: 1px solid var(--line); }
.attachment-preview { display: grid; place-items: center; width: 42px; height: 42px; flex: none; border-radius: 10px; background: var(--accent-soft); color: var(--accent); font-size: 10px; font-weight: 750; object-fit: cover; }
.attachment-info { min-width: 0; flex: 1; }
.attachment-name { display: block; overflow: hidden; color: var(--heading); font-size: 13px; font-weight: 600; text-overflow: ellipsis; white-space: nowrap; }
.attachment-meta { display: block; margin-top: 2px; color: var(--muted); font-size: 11px; }
.attachment-open { color: var(--accent); text-decoration: none; }
.attachment-remove { width: 40px; min-height: 40px; padding: 0; border: 0; background: transparent; color: var(--danger); font-size: 20px; }
.selected-file-row { color: var(--muted); font-size: 12px; }

.image-viewer { width: 100%; max-width: 100%; height: 100%; max-height: 100%; margin: 0; padding: 0; border: 0; background: #111; color: white; }
.image-viewer[open] { display: flex; flex-direction: column; }
.image-viewer header { display: flex; align-items: center; justify-content: space-between; flex: none; padding: calc(8px + env(safe-area-inset-top)) 14px 8px; background: #181818; }
.image-viewer header span { overflow: hidden; font-size: 14px; text-overflow: ellipsis; white-space: nowrap; }
.image-viewer .icon-button { color: white; }
#full-image { min-height: 0; flex: 1; width: 100%; object-fit: contain; }
.viewer-download { flex: none; padding: 13px; padding-bottom: calc(13px + env(safe-area-inset-bottom)); background: #181818; color: #cdd3ff; text-align: center; text-decoration: none; }

.insights-sheet { min-height: 60vh; }
.insight-cards { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.insight-card { padding: 16px; border-radius: 16px; background: var(--bg); }
.insight-value { display: block; color: var(--heading); font-size: 28px; font-weight: 750; letter-spacing: -.03em; }
.insight-label { display: block; margin-top: 3px; color: var(--muted); font-size: 12px; }
.insight-section { margin-top: 24px; }
.insight-list li { padding: 12px 0; border-bottom: 1px solid var(--line); }
.insight-item-head { display: flex; justify-content: space-between; gap: 10px; color: var(--heading); font-size: 14px; font-weight: 650; }
.insight-item-meta { margin: 4px 0 0; color: var(--muted); font-size: 12px; }
.insight-note { margin: 0; color: var(--muted); font-size: 13px; line-height: 1.7; }

#connection-note {
  position: fixed; top: calc(6px + env(safe-area-inset-top)); left: 50%; z-index: 80; width: max-content; max-width: 90%;
  padding: 7px 13px; border-radius: 999px; background: var(--heading); color: var(--bg); font-size: 12px; transform: translateX(-50%);
}
#toast {
  position: fixed; left: 50%; bottom: calc(88px + env(safe-area-inset-bottom)); z-index: 70;
  display: flex; align-items: center; justify-content: space-between; gap: 15px; width: calc(100% - 32px); max-width: 520px;
  min-height: 50px; padding: 7px 8px 7px 16px; border-radius: 15px; background: var(--heading); color: var(--bg);
  box-shadow: 0 10px 35px rgb(0 0 0 / 22%); transform: translateX(-50%); font-size: 14px;
}
#toast button { flex: none; min-height: 36px; border: 0; background: transparent; color: var(--accent); font-weight: 700; }

@media (min-width: 681px) {
  .bottom-sheet { margin: 5vh auto; border-bottom: 1px solid var(--line); border-radius: 24px; }
  .sheet-actions { padding-bottom: 12px; }
  .topbar { border-radius: 0 0 16px 16px; }
}
@media (max-width: 360px) {
  h1 { font-size: 28px; }
  .new-item-button { padding: 0 12px; }
  .new-item-button span:last-child { display: none; }
  .attachment-heading-row { align-items: flex-start; }
  .attachment-heading-row p { max-width: 145px; }
}
