:root {
  --bg: #0b1220;
  --surface: #121a2b;
  --surface2: #1a2438;
  --text: #f1f5f9;
  --muted: #94a3b8;
  --accent: #38bdf8;
  --danger: #f87171;
  --ok: #4ade80;
  --warn: #fbbf24;
  --border: #243044;
  --row: #151e30;
  --fab: #0ea5e9;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --nav-h: 64px;
  --thumb: 48px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text); min-height: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; }
a { color: var(--accent); }

#app { min-height: 100dvh; padding-bottom: calc(var(--nav-h) + var(--safe-bottom) + 16px); }

.screen { padding: 12px 14px 24px; max-width: 520px; margin: 0 auto; }
.topbar { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; min-height: 44px; }
.topbar h1 { font-size: 1.25rem; margin: 0; flex: 1; font-weight: 700; }
.icon-btn {
  width: var(--thumb); height: var(--thumb); border-radius: 12px;
  background: var(--surface2); color: var(--text); display: grid; place-items: center;
  font-size: 1.2rem;
}
.muted { color: var(--muted); font-size: 0.9rem; }
.danger { color: var(--danger); }
.ok { color: var(--ok); }

.field { margin-bottom: 12px; }
.field label { display: block; font-size: 0.85rem; color: var(--muted); margin-bottom: 6px; }
.field input, .field select, .field textarea {
  width: 100%; padding: 14px 12px; border-radius: 12px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); min-height: var(--thumb);
}
.field textarea { min-height: 110px; resize: vertical; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: var(--thumb); padding: 0 16px; border-radius: 14px;
  background: var(--accent); color: #082f49; font-weight: 700; width: 100%;
}
.btn.secondary { background: var(--surface2); color: var(--text); }
.btn.ghost { background: transparent; border: 1px solid var(--border); color: var(--text); }
.btn:disabled { opacity: 0.5; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0 12px; }
.chip {
  min-height: 40px; padding: 0 14px; border-radius: 999px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font-size: 0.9rem;
}
.chip.active { background: #0c4a6e; border-color: var(--accent); color: #e0f2fe; }

.list { display: flex; flex-direction: column; gap: 8px; }
.row {
  display: flex; align-items: stretch; background: var(--row); border: 1px solid var(--border);
  border-radius: 14px; overflow: hidden; min-height: 72px;
}
.row-main {
  flex: 1; padding: 12px 14px; text-align: left; display: flex; flex-direction: column; gap: 4px;
  color: inherit; min-width: 0;
}
.row-main .name { font-weight: 700; font-size: 1.05rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-main .summary { color: var(--muted); font-size: 0.85rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-main .meta { font-size: 0.8rem; color: var(--muted); }
.row-main .meta.overdue { color: var(--danger); font-weight: 600; }
.row-call {
  width: 56px; display: grid; place-items: center; border-left: 1px solid var(--border);
  color: var(--ok); font-size: 1.3rem; text-decoration: none; background: var(--surface2);
}

.bottom-nav {
  position: fixed; left: 0; right: 0; bottom: 0; height: calc(var(--nav-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom); background: rgba(11,18,32,0.96); border-top: 1px solid var(--border);
  display: flex; z-index: 40; backdrop-filter: blur(8px);
}
.bottom-nav button {
  flex: 1; color: var(--muted); font-weight: 600; font-size: 0.85rem;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
}
.bottom-nav button.active { color: var(--accent); }

.fab {
  position: fixed; right: 16px; bottom: calc(var(--nav-h) + var(--safe-bottom) + 16px);
  width: 58px; height: 58px; border-radius: 50%; background: var(--fab); color: #042f2e;
  font-size: 1.8rem; font-weight: 700; box-shadow: 0 8px 24px rgba(14,165,233,0.35); z-index: 45;
}

.sheet-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.55); z-index: 50;
  display: flex; align-items: flex-end; justify-content: center;
}
.sheet {
  width: 100%; max-width: 520px; background: var(--surface); border-radius: 20px 20px 0 0;
  padding: 16px 16px calc(16px + var(--safe-bottom)); max-height: 88dvh; overflow: auto;
}
.sheet h2 { margin: 0 0 12px; font-size: 1.1rem; }

.tabs { display: flex; gap: 6px; margin-bottom: 12px; background: var(--surface); padding: 4px; border-radius: 12px; }
.tabs button {
  flex: 1; min-height: 40px; border-radius: 10px; color: var(--muted); font-weight: 600;
}
.tabs button.active { background: var(--surface2); color: var(--text); }

.timeline { display: flex; flex-direction: column; gap: 10px; }
.activity-card {
  background: var(--row); border: 1px solid var(--border); border-radius: 14px; padding: 12px;
}
.activity-card .type { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--accent); font-weight: 700; }
.activity-card .body { white-space: pre-wrap; margin: 6px 0; line-height: 1.4; }
.activity-card a.body.link { display: block; color: var(--accent); word-break: break-all; text-decoration: underline; }
.activity-card .when { font-size: 0.8rem; color: var(--muted); }

.mic-btn {
  width: 100%; min-height: 64px; border-radius: 16px; background: #14532d; color: #dcfce7;
  font-weight: 700; font-size: 1.05rem; margin: 8px 0 12px;
}
.mic-btn.recording { background: #7f1d1d; color: #fee2e2; animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { opacity: 0.75; } }

.match-card {
  background: var(--row); border: 1px solid var(--border); border-radius: 14px; padding: 12px;
  display: grid; grid-template-columns: 32px 1fr; gap: 10px; align-items: start;
}
.match-card img { width: 100%; height: 72px; object-fit: cover; border-radius: 10px; grid-column: 1 / -1; }
.match-card.no-check { grid-template-columns: 1fr; }
.match-card .match-img-link { grid-column: 1 / -1; display: block; }
.match-card .match-img-link img { grid-column: auto; }
.match-card .reasons { font-size: 0.78rem; color: var(--muted); margin-top: 4px; }
.match-link {
  display: inline-block; min-height: 44px; line-height: 44px; margin-top: 2px;
  color: var(--accent); font-weight: 600; text-decoration: none;
}
.match-link:active { opacity: 0.7; }
.badge {
  display: inline-block; font-size: 0.7rem; font-weight: 700; padding: 2px 8px; border-radius: 999px;
  background: var(--surface2); color: var(--accent); margin-left: 6px;
}
.badge.manual { color: var(--warn); }
.section-title { font-size: 0.85rem; color: var(--muted); margin: 16px 0 8px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; }

.sticky-bar {
  position: sticky; bottom: calc(var(--nav-h) + var(--safe-bottom) + 8px);
  background: #0c4a6e; color: #e0f2fe; border-radius: 14px; padding: 12px; font-weight: 700;
  text-align: center; z-index: 30; margin-top: 12px;
}

.empty {
  text-align: center; padding: 40px 16px; color: var(--muted); line-height: 1.5;
}

.toast {
  position: fixed; left: 50%; bottom: calc(var(--nav-h) + 24px); transform: translateX(-50%);
  background: #1e293b; color: var(--text); padding: 10px 16px; border-radius: 999px;
  border: 1px solid var(--border); z-index: 60; font-size: 0.9rem; max-width: 90%;
}

.login-card {
  max-width: 420px; margin: 10vh auto 0; padding: 20px; background: var(--surface);
  border-radius: 18px; border: 1px solid var(--border);
}
.login-card h1 { margin-top: 0; }

.search-bar input {
  width: 100%; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--border);
  background: var(--surface); margin-bottom: 10px; min-height: var(--thumb);
}

.stepper { display: flex; gap: 6px; margin-bottom: 12px; }
.stepper span {
  flex: 1; height: 4px; border-radius: 999px; background: var(--border);
}
.stepper span.on { background: var(--accent); }

.task-section { margin-bottom: 18px; }
.task-section h3 { margin: 0 0 8px; font-size: 0.95rem; color: var(--muted); }
