:root {
  color-scheme: light;
  --bg: #ffffff;
  --surface: #f5f5f7;
  --surface-2: #ebebef;
  --text: #16161a;
  --muted: #6b6b76;
  --border: #e2e2e8;
  --accent: #d97706;
  --accent-text: #ffffff;
  --danger: #dc2626;
  --s-inbox: #3b82f6;
  --s-developing: #f59e0b;
  --s-parked: #8b5cf6;
  --s-done: #16a34a;
  --shadow: 0 6px 24px rgba(0, 0, 0, 0.16);
  --radius: 14px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    color-scheme: dark;
    --bg: #0f0f12;
    --surface: #1a1a1f;
    --surface-2: #26262d;
    --text: #f2f2f5;
    --muted: #9a9aa6;
    --border: #2c2c34;
    --accent: #f59e0b;
    --accent-text: #1a1203;
    --danger: #f87171;
    --shadow: 0 6px 24px rgba(0, 0, 0, 0.6);
  }
}
:root[data-theme='dark'] {
  color-scheme: dark;
  --bg: #0f0f12;
  --surface: #1a1a1f;
  --surface-2: #26262d;
  --text: #f2f2f5;
  --muted: #9a9aa6;
  --border: #2c2c34;
  --accent: #f59e0b;
  --accent-text: #1a1203;
  --danger: #f87171;
  --shadow: 0 6px 24px rgba(0, 0, 0, 0.6);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); }
body {
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; }
[hidden] { display: none !important; }

/* ---------- layout ---------- */
.screen { display: flex; flex-direction: column; height: 100dvh; max-width: 760px; margin: 0 auto; }
.topbar { padding: calc(var(--safe-t) + 10px) 16px 8px; display: flex; flex-direction: column; gap: 10px; background: var(--bg); position: sticky; top: 0; z-index: 5; }
.topbar-row { display: flex; align-items: center; gap: 8px; }
.topbar h1 { font-size: 26px; margin: 0; flex: 1; letter-spacing: -0.02em; }
.icon-btn { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; color: var(--text); position: relative; }
.icon-btn:active { background: var(--surface-2); }
.icon-btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.sync-dot { position: absolute; right: 7px; top: 7px; width: 9px; height: 9px; border-radius: 50%; background: var(--s-done); border: 2px solid var(--bg); }
.sync-dot.pending { background: var(--s-developing); }
.sync-dot.offline { background: var(--muted); }
.sync-dot.error { background: var(--danger); }

.search { width: 100%; height: 40px; border-radius: 12px; border: 0; background: var(--surface); padding: 0 14px; outline: none; }
.search:focus { box-shadow: 0 0 0 2px var(--accent); }

.chips { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; height: 34px; padding: 0 14px; border-radius: 17px; background: var(--surface); color: var(--text); font-size: 14px; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.chip.on { background: var(--accent); color: var(--accent-text); font-weight: 600; }
.chip .count { opacity: 0.7; font-size: 12px; }
.chip.filter { background: var(--surface-2); }

.list { flex: 1; overflow-y: auto; padding: 4px 16px calc(96px + var(--safe-b)); display: flex; flex-direction: column; gap: 10px; -webkit-overflow-scrolling: touch; }
.card { background: var(--surface); border-radius: var(--radius); padding: 14px; text-align: left; width: 100%; display: flex; flex-direction: column; gap: 6px; }
.card:active { background: var(--surface-2); }
.card-head { display: flex; align-items: flex-start; gap: 8px; }
.card-title { font-weight: 600; flex: 1; overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card-body { color: var(--muted); font-size: 14px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; overflow-wrap: anywhere; white-space: pre-wrap; }
.card-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px; font-size: 12px; color: var(--muted); }
.dot { width: 10px; height: 10px; border-radius: 50%; flex: none; margin-top: 6px; background: var(--s-inbox); }
.dot.developing { background: var(--s-developing); }
.dot.parked { background: var(--s-parked); }
.dot.done { background: var(--s-done); }
.tag { background: var(--surface-2); color: var(--text); border-radius: 8px; padding: 1px 8px; font-size: 12px; }
.pin { color: var(--accent); font-size: 14px; }
.badge { border-radius: 8px; padding: 1px 8px; font-size: 12px; background: var(--surface-2); }
.badge.agent { background: color-mix(in srgb, var(--accent) 22%, transparent); }
.thumb-count { display: inline-flex; align-items: center; gap: 3px; }

.empty { margin: auto; text-align: center; color: var(--muted); padding: 40px 24px; }
.empty b { display: block; font-size: 18px; color: var(--text); margin-bottom: 6px; }

.fab { position: fixed; right: max(18px, calc(50% - 362px)); bottom: calc(20px + var(--safe-b)); width: 60px; height: 60px; border-radius: 50%; background: var(--accent); color: var(--accent-text); box-shadow: var(--shadow); display: grid; place-items: center; z-index: 6; }
.fab svg { width: 28px; height: 28px; stroke: currentColor; stroke-width: 2.6; fill: none; stroke-linecap: round; }
.fab:active { transform: scale(0.95); }

/* ---------- sheets / overlays ---------- */
.scrim { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.45); z-index: 20; display: flex; align-items: flex-end; justify-content: center; }
.sheet { background: var(--bg); width: 100%; max-width: 760px; border-radius: 20px 20px 0 0; padding: 16px 16px calc(16px + var(--safe-b)); max-height: 88dvh; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; animation: up 0.18s ease-out; }
@keyframes up { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }
.sheet h2 { margin: 0; font-size: 18px; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.sheet-section { display: flex; flex-direction: column; gap: 8px; }
.sheet-section > h3 { margin: 4px 0 0; font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }

.field { width: 100%; background: var(--surface); border: 0; border-radius: 12px; padding: 12px 14px; outline: none; }
.field:focus { box-shadow: 0 0 0 2px var(--accent); }
textarea.field { resize: none; min-height: 120px; line-height: 1.45; }
select.field { appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 20px) 50%, calc(100% - 15px) 50%; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 36px; }

.btn { height: 46px; padding: 0 18px; border-radius: 12px; background: var(--surface-2); font-weight: 600; display: inline-flex; align-items: center; justify-content: center; gap: 8px; }
.btn.primary { background: var(--accent); color: var(--accent-text); }
.btn.danger { color: var(--danger); }
.btn.block { width: 100%; }
.btn:disabled { opacity: 0.5; }
.btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.btn-row { display: flex; gap: 8px; }
.btn-row .btn { flex: 1; }
.tool-row { display: flex; gap: 8px; align-items: center; }
.tool-row .spacer { flex: 1; }
.tool { width: 44px; height: 44px; border-radius: 12px; background: var(--surface); display: grid; place-items: center; }
.tool.rec { background: var(--danger); color: #fff; animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { opacity: 0.6; } }
.tool svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.hint { font-size: 12px; color: var(--muted); }

.seg { display: flex; background: var(--surface); border-radius: 12px; padding: 3px; gap: 2px; }
.seg button { flex: 1; height: 38px; border-radius: 10px; font-size: 14px; color: var(--muted); font-weight: 500; }
.seg button.on { background: var(--bg); color: var(--text); font-weight: 600; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.18); }

.list-row { display: flex; align-items: center; gap: 10px; min-height: 48px; padding: 0 4px; border-radius: 10px; width: 100%; text-align: left; }
.list-row:active { background: var(--surface); }
.list-row .grow { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text-align: left; }
.icon-btn.on { color: var(--accent); }
.icon-btn.on svg { fill: currentColor; }
.cap-folder { max-width: 55%; }
.pinform { display: contents; }
.list-row.on { font-weight: 700; color: var(--accent); }
.list-row .count { color: var(--muted); font-size: 13px; }
.inline-add { display: flex; gap: 8px; }
.inline-add .field { flex: 1; }

/* ---------- detail ---------- */
.detail { position: fixed; inset: 0; background: var(--bg); z-index: 15; display: flex; flex-direction: column; max-width: 760px; margin: 0 auto; }
.detail-top { padding: calc(var(--safe-t) + 8px) 8px 8px 8px; display: flex; align-items: center; gap: 4px; border-bottom: 1px solid var(--border); }
.detail-top .grow { flex: 1; }
.detail-top .saved { font-size: 12px; color: var(--muted); padding: 0 6px; }
.detail-scroll { flex: 1; overflow-y: auto; padding: 16px 16px calc(32px + var(--safe-b)); display: flex; flex-direction: column; gap: 14px; -webkit-overflow-scrolling: touch; }
.title-input { font-size: 22px; font-weight: 700; background: none; border: 0; outline: none; padding: 0; width: 100%; letter-spacing: -0.01em; }
.body-input { background: none; border: 0; outline: none; padding: 0; width: 100%; resize: none; line-height: 1.5; min-height: 140px; font-size: 16px; }
.label { font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin-bottom: 6px; display: block; }
.tags-edit { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.tag-x { display: inline-flex; align-items: center; gap: 4px; background: var(--surface-2); border-radius: 10px; padding: 4px 6px 4px 10px; font-size: 14px; }
.tag-x button { width: 20px; height: 20px; border-radius: 50%; color: var(--muted); font-size: 16px; line-height: 1; }
.tag-input { flex: 1; min-width: 110px; background: none; border: 0; outline: none; padding: 6px 4px; }
.thumbs { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; }
.thumb { position: relative; aspect-ratio: 1; border-radius: 12px; overflow: hidden; background: var(--surface); }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb .x { position: absolute; top: 4px; right: 4px; width: 26px; height: 26px; border-radius: 50%; background: rgba(0, 0, 0, 0.6); color: #fff; font-size: 16px; line-height: 1; }
.thumb .wait { position: absolute; left: 4px; bottom: 4px; font-size: 10px; background: rgba(0, 0, 0, 0.6); color: #fff; padding: 1px 6px; border-radius: 8px; }
.note { background: var(--surface); border-radius: 12px; padding: 10px 12px; font-size: 14px; white-space: pre-wrap; overflow-wrap: anywhere; }
.note .who { display: block; font-size: 12px; color: var(--muted); margin-bottom: 2px; }
.agent-box { background: var(--surface); border-radius: var(--radius); padding: 12px; display: flex; flex-direction: column; gap: 10px; }
.agent-box .row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }

.viewer { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.92); z-index: 40; display: grid; place-items: center; }
.viewer img { max-width: 100%; max-height: 100%; object-fit: contain; }
.viewer .close { position: absolute; top: calc(var(--safe-t) + 12px); right: 12px; width: 40px; height: 40px; border-radius: 50%; background: rgba(255, 255, 255, 0.18); color: #fff; font-size: 22px; }

/* ---------- login ---------- */
.login { height: 100dvh; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px; padding: 24px; max-width: 360px; margin: 0 auto; text-align: center; }
.login .logo { width: 72px; height: 72px; border-radius: 18px; }
.login h1 { margin: 0; font-size: 26px; }
.login .pin { width: 100%; text-align: center; font-size: 28px; letter-spacing: 0.5em; padding: 14px; color: var(--text); }
.login .err { color: var(--danger); min-height: 20px; font-size: 14px; }

#toast { position: fixed; left: 50%; bottom: calc(96px + var(--safe-b)); transform: translateX(-50%) translateY(20px); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 14px; opacity: 0; pointer-events: none; transition: 0.2s; z-index: 60; max-width: 90vw; text-align: center; }
#toast.show { opacity: 1; transform: translateX(-50%); }
