:root {
  --bg: #f5f6f8;
  --card: #ffffff;
  --text: #111827;
  --muted: #6b7280;
  --line: #e5e7eb;
  --accent: #f59e0b;
  --accent-ink: #1f2937;
  --danger: #dc2626;
  --bar: #1f2937;
  --bar-text: #f9fafb;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --card: #1a1d24;
    --text: #f3f4f6;
    --muted: #9ca3af;
    --line: #2a2f3a;
    --bar: #111318;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
  padding-bottom: calc(150px + var(--safe-b));
}
button { font: inherit; color: inherit; cursor: pointer; }
input, textarea, select {
  font: inherit; font-size: 16px; /* prevents iOS zoom */
  width: 100%; padding: 10px 12px;
  border: 1px solid var(--line); border-radius: 10px;
  background: var(--card); color: var(--text);
}
textarea { resize: vertical; }
.hidden { display: none !important; }

/* Top bar */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; gap: 10px; align-items: center;
  padding: calc(10px + var(--safe-t)) 16px 10px;
  background: var(--bar); color: var(--bar-text);
}
.topbar h1 { font-size: 20px; margin: 0; color: var(--accent); }
.topbar input { flex: 1; padding: 8px 12px; border: none; background: #374151; color: #fff; }
.topbar input::placeholder { color: #9ca3af; }
.icon-btn { background: none; border: none; color: var(--bar-text); font-size: 22px; padding: 4px 8px; }

.menu {
  position: fixed; right: 12px; top: calc(56px + var(--safe-t)); z-index: 20;
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  box-shadow: 0 8px 24px rgba(0,0,0,.2); overflow: hidden; min-width: 180px;
}
.menu button, .menu .menu-item {
  display: block; width: 100%; text-align: left; padding: 12px 16px;
  background: none; border: none; cursor: pointer;
}
.menu button + button, .menu button + .menu-item { border-top: 1px solid var(--line); }

main { max-width: 720px; margin: 0 auto; padding: 12px 16px; }

.filters { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 8px; scrollbar-width: none; }
.chip {
  flex: none; padding: 6px 12px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--card); font-size: 14px;
}
.chip.active { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

.list { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.item {
  background: var(--card); border: 1px solid var(--line); border-radius: 14px;
  padding: 14px; cursor: pointer;
}
.item h3 { margin: 0 0 4px; font-size: 16px; }
.item p { margin: 0; color: var(--muted); font-size: 14px;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.meta { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; align-items: center; font-size: 12px; color: var(--muted); }
.tag { background: var(--bg); border-radius: 6px; padding: 2px 8px; }
.status { border-radius: 6px; padding: 2px 8px; font-weight: 600; }
.status.Planning { background: #dbeafe; color: #1e40af; }
.status.Active { background: #dcfce7; color: #166534; }
.status.Onhold { background: #fef3c7; color: #92400e; }
.status.Done { background: #e5e7eb; color: #374151; }
.progress { flex: 1; min-width: 60px; height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; }
.progress > div { height: 100%; background: var(--accent); }
.empty { text-align: center; color: var(--muted); margin-top: 40px; }

/* Floating buttons */
.fab-row {
  position: fixed; right: 16px; bottom: calc(76px + var(--safe-b)); z-index: 15;
  display: flex; gap: 12px; align-items: center;
}
.fab {
  width: 64px; height: 64px; border-radius: 50%; border: none;
  background: var(--accent); color: var(--accent-ink); font-size: 28px;
  box-shadow: 0 6px 18px rgba(0,0,0,.3);
}
.fab.secondary { width: 48px; height: 48px; font-size: 22px; background: var(--card); color: var(--text); border: 1px solid var(--line); }

/* Tab bar */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 14;
  display: flex; background: var(--bar); padding-bottom: var(--safe-b);
}
.tab {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 8px 0 10px; background: none; border: none; color: #9ca3af; font-size: 20px;
}
.tab span { font-size: 12px; }
.tab.active { color: var(--accent); }

/* Sheet */
.sheet {
  position: fixed; inset: 0; z-index: 30; background: rgba(0,0,0,.45);
  display: flex; align-items: flex-end; justify-content: center;
}
.sheet-card {
  background: var(--bg); width: 100%; max-width: 720px; max-height: 92vh; overflow-y: auto;
  border-radius: 18px 18px 0 0; padding-bottom: calc(16px + var(--safe-b));
}
@media (min-width: 760px) {
  .sheet { align-items: center; }
  .sheet-card { border-radius: 18px; }
}
.sheet-head {
  position: sticky; top: 0; display: flex; justify-content: space-between; align-items: center;
  padding: 14px 16px; background: var(--bg); border-bottom: 1px solid var(--line);
}
.link-btn { background: none; border: none; color: var(--muted); padding: 4px; }
.link-btn.primary { color: var(--accent); font-weight: 700; }
#editor { padding: 16px; display: grid; gap: 14px; }
#editor label, .field-label { display: grid; gap: 6px; font-size: 14px; font-weight: 600; }
#editor small { font-weight: 400; color: var(--muted); }
.with-mic { display: flex; gap: 8px; align-items: flex-start; }
.mic {
  flex: none; width: 44px; height: 44px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--card); font-size: 18px;
}
.mic.on { background: var(--danger); border-color: var(--danger); animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: .6; } }
.small-btn { flex: none; height: 44px; padding: 0 14px; border-radius: 10px; border: none; background: var(--accent); color: var(--accent-ink); font-weight: 600; }

.tasks { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.tasks li { display: flex; gap: 10px; align-items: center; background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; }
.tasks input[type=checkbox] { width: 22px; height: 22px; flex: none; }
.tasks span { flex: 1; }
.tasks li.done span { text-decoration: line-through; color: var(--muted); }
.tasks button { background: none; border: none; color: var(--muted); font-size: 18px; }

.sheet-actions { display: grid; gap: 10px; margin-top: 6px; }
.wide-btn { width: 100%; padding: 12px; border-radius: 12px; border: 1px solid var(--line); background: var(--card); font-weight: 600; }
.wide-btn.danger { color: var(--danger); }

/* Listening overlay */
.listening {
  position: fixed; inset: 0; z-index: 40; background: rgba(17,24,39,.92); color: #fff;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 24px; padding: 24px;
}
.listening p { font-size: 20px; text-align: center; max-width: 600px; line-height: 1.4; }
.listening .wide-btn { max-width: 260px; background: var(--accent); color: var(--accent-ink); border: none; }
.pulse { width: 90px; height: 90px; border-radius: 50%; background: var(--accent); animation: pulse 1.2s infinite; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(245,158,11,.6); } 100% { box-shadow: 0 0 0 36px rgba(245,158,11,0); } }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(160px + var(--safe-b)); z-index: 50;
  background: #111827; color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 14px; max-width: 90vw;
}

/* Sync status dot */
.sync-dot { width: 10px; height: 10px; border-radius: 50%; flex: none; background: #6b7280; }
.sync-dot.off { background: transparent; border: 1px solid #6b7280; }
.sync-dot.ok { background: #22c55e; }
.sync-dot.syncing { background: var(--accent); animation: blink 1s infinite; }
.sync-dot.error { background: var(--danger); }

/* Pairing QR */
.qr { background: #fff; padding: 16px; border-radius: 16px; width: min(80vw, 320px); }
.qr svg { display: block; width: 100%; height: auto; }
.pair-note { font-size: 14px !important; color: #fbbf24; }
#pair .wide-btn + .wide-btn { background: var(--card); color: var(--text); }

.scan-video { width: min(85vw, 360px); aspect-ratio: 1; object-fit: cover; border-radius: 16px; background: #000; border: 3px solid var(--accent); }
