:root {
  --bg: #f3f5f8;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --primary: #10b981;
  --primary-dark: #059669;
  --primary-soft: rgba(16, 185, 129, 0.12);

  --muy-bg: rgba(239, 68, 68, 0.12);
  --muy-fg: #dc2626;
  --muy-bd: rgba(239, 68, 68, 0.35);

  --urg-bg: rgba(245, 158, 11, 0.14);
  --urg-fg: #b45309;
  --urg-bd: rgba(245, 158, 11, 0.38);

  --no-bg: rgba(16, 185, 129, 0.12);
  --no-fg: #047857;
  --no-bd: rgba(16, 185, 129, 0.35);

  --danger: #dc2626;
  --radius: 14px;
  --shadow: 0 2px 10px rgba(15, 23, 42, 0.05);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1120;
    --surface: #111827;
    --surface-2: #1e293b;
    --border: #263244;
    --text: #f1f5f9;
    --muted: #94a3b8;
    --primary: #10b981;
    --primary-dark: #34d399;
    --primary-soft: rgba(16, 185, 129, 0.16);

    --muy-bg: rgba(239, 68, 68, 0.18);
    --muy-fg: #fca5a5;
    --muy-bd: rgba(248, 113, 113, 0.38);

    --urg-bg: rgba(245, 158, 11, 0.18);
    --urg-fg: #fcd34d;
    --urg-bd: rgba(251, 191, 36, 0.38);

    --no-bg: rgba(16, 185, 129, 0.18);
    --no-fg: #6ee7b7;
    --no-bd: rgba(52, 211, 153, 0.38);

    --shadow: 0 4px 16px rgba(0, 0, 0, 0.35);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  line-height: 1.4;
  -webkit-tap-highlight-color: transparent;
}

[hidden] { display: none !important; }

.small { font-size: 0.84rem; }
.muted { color: var(--muted); }
.neg { color: var(--danger); }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

/* Auth */
.auth {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: var(--bg);
}

.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 28px 22px;
  box-shadow: var(--shadow);
  text-align: center;
}

.auth-logo { border-radius: 14px; margin-bottom: 10px; }
.auth-card h1 { margin: 0 0 6px; font-size: 1.4rem; }
.auth-card form { display: flex; flex-direction: column; gap: 10px; margin-top: 16px; }
.auth-card input {
  width: 100%;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 1rem;
}
.auth-alt { margin-top: 14px; }
.btn-link {
  background: none;
  border: none;
  color: var(--primary-dark);
  font-size: 0.88rem;
  cursor: pointer;
  text-decoration: underline;
}

/* Topbar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding-top: env(safe-area-inset-top);
}

.topbar-inner {
  max-width: 820px;
  margin: 0 auto;
  padding: 10px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-icon { font-size: 1.5rem; }
.brand h1 { margin: 0; font-size: 1.15rem; font-weight: 700; letter-spacing: -0.01em; }

.sync {
  font-size: 0.76rem;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
}
.sync::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--primary);
  display: inline-block;
}
.sync.saving::before { background: #f59e0b; }
.sync.offline::before { background: #94a3b8; }
.sync.error::before { background: var(--danger); }

.top-actions { display: flex; align-items: center; gap: 6px; }

.seg {
  display: inline-flex;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 2px;
}
.seg button {
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 600;
  padding: 6px 10px;
  border-radius: 8px;
  cursor: pointer;
}
.seg button.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

.icon-btn {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 1.05rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.icon-btn:active { transform: scale(0.96); }

/* Main container */
.container {
  max-width: 820px;
  margin: 0 auto;
  padding: 14px 12px calc(32px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* Composer */
.composer { padding: 12px; }
.composer-row {
  display: flex;
  gap: 8px;
  align-items: stretch;
}
.composer-row input {
  flex: 1;
  min-width: 0;
  padding: 11px 13px;
  border-radius: 11px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 1rem;
}
.composer-row input:focus {
  outline: 2px solid var(--primary);
  border-color: transparent;
}

.mic-btn {
  width: 46px;
  flex-shrink: 0;
  border-radius: 11px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  font-size: 1.25rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, transform 0.1s;
}
.mic-btn.listening {
  background: var(--muy-bg);
  border-color: var(--muy-fg);
  animation: micPulse 1.2s infinite;
}
@keyframes micPulse {
  0% { box-shadow: 0 0 0 0 rgba(220, 38, 38, 0.45); }
  70% { box-shadow: 0 0 0 10px rgba(220, 38, 38, 0); }
  100% { box-shadow: 0 0 0 0 rgba(220, 38, 38, 0); }
}

.btn {
  border: none;
  border-radius: 11px;
  padding: 10px 15px;
  font-size: 0.94rem;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
.btn:active { transform: scale(0.98); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-danger-outline {
  background: transparent;
  color: var(--danger);
  border: 1px solid var(--muy-bd);
}

.urgency-bar {
  margin-top: 10px;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.urgency-bar-label { font-size: 0.82rem; color: var(--muted); font-weight: 600; }
.urgency-pills { display: flex; gap: 6px; flex-wrap: wrap; }

.u-pill {
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--muted);
  border-radius: 999px;
  padding: 5px 11px;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
}
.u-pill.active.u-muy_urgente { background: var(--muy-bg); color: var(--muy-fg); border-color: var(--muy-bd); }
.u-pill.active.u-urgente { background: var(--urg-bg); color: var(--urg-fg); border-color: var(--urg-bd); }
.u-pill.active.u-no_urgente { background: var(--no-bg); color: var(--no-fg); border-color: var(--no-bd); }

/* Voice panel */
.voice-panel {
  margin-top: 10px;
  padding: 10px 12px;
  border-radius: 11px;
  background: var(--surface-2);
  border: 1px dashed var(--primary);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.voice-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}
.voice-live { display: flex; align-items: center; gap: 8px; font-size: 0.85rem; font-weight: 500; }
.pulse-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--danger);
  flex-shrink: 0;
  animation: micPulse 1.1s infinite;
}
.pulse-dot.paused { animation: none; background: var(--primary); }

.voice-auto-toggle {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 0.8rem;
  color: var(--muted);
  cursor: pointer;
}
.voice-transcript {
  font-size: 0.9rem;
  font-style: italic;
  color: var(--text);
  background: var(--surface);
  padding: 7px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
}
.voice-preview { display: flex; flex-direction: column; gap: 8px; }
.voice-chips { display: flex; flex-direction: column; gap: 6px; }
.voice-chip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 7px 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 9px;
  flex-wrap: wrap;
}
.voice-chip-main { display: flex; align-items: center; gap: 6px; font-weight: 600; font-size: 0.92rem; }
.voice-chip-controls { display: flex; align-items: center; gap: 5px; flex-wrap: wrap; }
.voice-actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }

/* Filters */
.filters-bar { display: flex; flex-direction: column; gap: 8px; }
.filter-chips {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 2px;
  scrollbar-width: none;
}
.filter-chips::-webkit-scrollbar { display: none; }

.f-chip {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 0.83rem;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.f-chip .count {
  background: var(--surface-2);
  padding: 1px 7px;
  border-radius: 999px;
  font-size: 0.76rem;
}
.f-chip.active { background: var(--text); color: var(--surface); border-color: var(--text); }
.f-chip.active .count { background: rgba(255, 255, 255, 0.22); color: inherit; }
.f-chip.active.u-muy_urgente { background: var(--muy-fg); color: #fff; border-color: var(--muy-fg); }
.f-chip.active.u-urgente { background: #d97706; color: #fff; border-color: #d97706; }
.f-chip.active.u-no_urgente { background: var(--primary); color: #fff; border-color: var(--primary); }

.search-row { display: flex; gap: 8px; }
.search-row input,
.search-row select {
  padding: 9px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 0.9rem;
}
.search-row input { flex: 1; min-width: 0; }
.search-row select { max-width: 48%; }

/* Groups & items */
.list-groups { display: flex; flex-direction: column; gap: 12px; }

.group-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.group-head {
  width: 100%;
  border: none;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  padding: 10px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  cursor: pointer;
  color: var(--text);
  font-weight: 700;
  font-size: 0.95rem;
  text-align: left;
}
.group-head-left { display: flex; align-items: center; gap: 8px; }
.group-badge {
  font-size: 0.78rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--muted);
}

.group-items { display: flex; flex-direction: column; }

.item-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 11px 12px;
  border-bottom: 1px solid var(--border);
  transition: background 0.15s;
}
.item-row:last-child { border-bottom: none; }

.check-btn {
  width: 28px;
  height: 28px;
  margin-top: 2px;
  flex-shrink: 0;
  border-radius: 8px;
  border: 2px solid var(--border);
  background: var(--surface-2);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.95rem;
  color: transparent;
}
.check-btn:hover { border-color: var(--primary); }
.item-row.is-done .check-btn {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.item-main { flex: 1; min-width: 0; }
.item-title-line {
  display: flex;
  align-items: baseline;
  gap: 6px;
  flex-wrap: wrap;
}
.item-name {
  font-size: 1rem;
  font-weight: 600;
  word-break: break-word;
}
.item-row.is-done .item-name {
  text-decoration: line-through;
  color: var(--muted);
  font-weight: 500;
}

.qty-tag {
  font-size: 0.78rem;
  font-weight: 700;
  padding: 1px 7px;
  border-radius: 6px;
  background: var(--primary-soft);
  color: var(--primary-dark);
}

.item-note {
  font-size: 0.82rem;
  color: var(--muted);
  margin-top: 2px;
}

.item-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 6px;
}

.badge-btn {
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  border-radius: 999px;
  padding: 2px 9px;
  font-size: 0.76rem;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.badge-btn.u-muy_urgente { background: var(--muy-bg); color: var(--muy-fg); border-color: var(--muy-bd); }
.badge-btn.u-urgente { background: var(--urg-bg); color: var(--urg-fg); border-color: var(--urg-bd); }
.badge-btn.u-no_urgente { background: var(--no-bg); color: var(--no-fg); border-color: var(--no-bd); }

.author-tag { font-size: 0.75rem; color: var(--muted); }

.item-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}
.mini-btn {
  width: 32px;
  height: 32px;
  border: none;
  background: transparent;
  color: var(--muted);
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.95rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.mini-btn:hover { background: var(--surface-2); color: var(--text); }

/* Empty state */
.empty-state {
  text-align: center;
  padding: 38px 20px;
}
.empty-emoji { font-size: 2.6rem; margin-bottom: 8px; }
.empty-state h2 { margin: 0 0 6px; font-size: 1.12rem; }
.empty-state p { margin: 0; color: var(--muted); font-size: 0.9rem; }

/* Done section */
.done-section { overflow: hidden; }
.done-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
}
.done-toggle {
  border: none;
  background: none;
  color: var(--text);
  font-weight: 700;
  font-size: 0.92rem;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  padding: 0;
}
.btn-ghost-danger {
  border: none;
  background: transparent;
  color: var(--danger);
  font-weight: 600;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 7px;
}
.btn-ghost-danger:hover { background: var(--muy-bg); }

/* Modals */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 80;
  background: rgba(15, 23, 42, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.modal {
  width: 100%;
  max-width: 460px;
  max-height: 90vh;
  overflow-y: auto;
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}
.modal-head h2 { margin: 0; font-size: 1.08rem; }
.modal-body {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.field { display: flex; flex-direction: column; gap: 5px; }
.field > span { font-size: 0.83rem; font-weight: 600; color: var(--muted); }
.field input,
.field select {
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 0.95rem;
}
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.info-box {
  padding: 12px;
  border-radius: 11px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.info-box p { margin: 0; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }
.sep { border: none; border-top: 1px solid var(--border); margin: 4px 0; }

.modal-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 4px;
}
.spacer { flex: 1; }

/* Toast */
.toast {
  position: fixed;
  bottom: calc(18px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  z-index: 120;
  background: #0f172a;
  color: #fff;
  padding: 10px 15px;
  border-radius: 12px;
  font-size: 0.9rem;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.28);
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: calc(100vw - 24px);
}
.toast button {
  border: none;
  background: rgba(255, 255, 255, 0.16);
  color: #fff;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 7px;
  cursor: pointer;
}

@media (max-width: 520px) {
  .add-btn { padding: 10px 12px; font-size: 0.88rem; }
  .field-row { grid-template-columns: 1fr; }
  .brand h1 { font-size: 1.05rem; }
  .seg button { padding: 5px 8px; font-size: 0.78rem; }
}
