:root {
  --font: 'Inter', system-ui, -apple-system, sans-serif;
  --sky-50: #E8F4FA;
  --sky-100: #D2EAF4;
  --sky-200: #A8D4E8;
  --sky-600: #0B6E99;
  --sky-700: #095A7D;
  --sky-800: #084E6E;
  --sky-900: #0A3D5C;
  --green-50: #EAF3DE;
  --green-600: #3B6D11;
  --red-50: #FCEBEB;
  --red-600: #A32D2D;
  --amber-50: #FAEEDA;
  --amber-700: #854F0B;
  --gray-50: #F7F8F8;
  --gray-200: #E2E6E8;
  --gray-400: #8AA0AB;
  --gray-600: #5F7380;
  --bg: #F4F8FA;
  --surface: #FFFFFF;
  --border: rgba(10, 61, 92, 0.12);
  --text: #0A3D5C;
  --text-muted: #5F7380;
  --text-faint: #8AA0AB;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-xl: 22px;
  --shadow-md: 0 8px 28px rgba(11, 110, 153, 0.12);
  --bottom-nav-h: 68px;
  --topbar-h: 56px;
}
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body, input, select, textarea, button, label, h1, h2, h3, p, a, li {
  font-family: var(--font);
}
body {
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }
a { color: var(--sky-600); }
.muted { color: var(--text-muted); font-size: 14px; }
.hint { font-weight: 400; opacity: .6; }
.form-error { color: var(--red-600); font-size: 13px; margin-top: 10px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: none; border-radius: var(--radius-md); padding: 12px 16px;
  font-size: 14px; font-weight: 600; cursor: pointer;
}
.btn:disabled { opacity: .55; cursor: default; }
.btn-primary { background: var(--sky-600); color: #fff; }
.btn-primary:hover { background: var(--sky-700); }
.btn-secondary { background: var(--sky-50); color: var(--sky-800); }
.btn-ghost { background: transparent; color: var(--text-muted); }
.btn-danger { background: var(--red-50); color: var(--red-600); }
.btn-sm { padding: 8px 12px; font-size: 13px; }

.form-row { margin-bottom: 14px; }
.form-row label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; }
.form-row input, .form-row select, .form-row textarea {
  width: 100%; padding: 11px 12px; border: 1px solid var(--border);
  border-radius: var(--radius-md); font-size: 15px; background: #fff; color: var(--text);
}
.form-row input:focus, .form-row select:focus { outline: 2px solid var(--sky-200); border-color: var(--sky-600); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.auth-body, #auth-screen {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  padding: 24px; background: linear-gradient(160deg, var(--sky-900) 0%, var(--sky-600) 100%);
}
.auth-card {
  background: var(--surface); border-radius: var(--radius-xl);
  padding: 32px 28px; width: 100%; max-width: 420px; box-shadow: var(--shadow-md);
}
.auth-logo { text-align: center; margin-bottom: 20px; }
.auth-brand, .topbar-brand {
  display: flex; align-items: center; justify-content: center; gap: 10px;
}
.auth-logo-img {
  height: 56px; width: 56px; margin: 0; display: block; object-fit: contain;
  border-radius: 12px;
}
.brand-wordmark {
  font-size: 22px; font-weight: 700; letter-spacing: -0.03em; color: var(--sky-900);
}
.auth-logo p { font-size: 13px; color: var(--text-muted); margin-top: 8px; }
.auth-tabs {
  display: flex; border: 1px solid var(--border); border-radius: var(--radius-md);
  padding: 3px; margin-bottom: 20px; gap: 3px;
}
.auth-tab {
  flex: 1; padding: 8px; border: none; background: transparent; color: var(--text-muted);
  border-radius: 8px; font-weight: 500; font-size: 13px; cursor: pointer;
}
.auth-tab.active { background: var(--sky-600); color: #fff; }
.auth-forgot { text-align: right; margin-bottom: 14px; }
.auth-forgot button { background: none; border: none; color: var(--sky-600); font-size: 12px; cursor: pointer; }
.auth-divider { text-align: center; color: var(--text-faint); font-size: 12px; margin: 14px 0; }
.biometric-btn {
  width: 100%; display: flex; align-items: center; justify-content: center; gap: 8px;
  padding: 11px; border-radius: var(--radius-md); border: 1px solid var(--border);
  background: #fff; color: var(--sky-800); font-weight: 600; cursor: pointer;
}

.topbar {
  position: sticky; top: 0; z-index: 20; height: var(--topbar-h);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 16px; background: #fff; border-bottom: 1px solid var(--border);
}
.topbar-brand { justify-content: flex-start; gap: 8px; }
.topbar-logo { height: 32px; width: 32px; object-fit: contain; border-radius: 8px; display: block; }
.topbar-brand .brand-wordmark { font-size: 18px; }
.topbar-user { font-size: 13px; color: var(--text-muted); font-weight: 500; }

.main { padding: 16px 16px calc(var(--bottom-nav-h) + 24px); max-width: 720px; margin: 0 auto; }
.view h1 { font-size: 22px; margin-bottom: 4px; }
.view-sub { color: var(--text-muted); font-size: 13px; margin-bottom: 16px; }

.bottom-nav {
  position: fixed; left: 0; right: 0; bottom: 0; height: var(--bottom-nav-h);
  background: #fff; border-top: 1px solid var(--border);
  display: flex; z-index: 30;
}
.nav-btn {
  flex: 1; border: none; background: none; color: var(--text-faint);
  font-size: 11px; font-weight: 600; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 4px; cursor: pointer;
}
.nav-btn.active { color: var(--sky-600); }
.nav-btn svg { width: 22px; height: 22px; }

.watch-card {
  background: #fff; border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: 14px; margin-bottom: 12px; box-shadow: 0 1px 3px rgba(0,0,0,.04);
}
.watch-route { font-size: 18px; font-weight: 700; letter-spacing: -0.02em; }
.watch-meta { font-size: 13px; color: var(--text-muted); margin: 4px 0 8px; }
.search-window {
  background: var(--sky-50);
  border: 1px solid var(--sky-100);
  border-radius: 10px;
  padding: 8px 10px;
  margin: 0 0 10px;
  font-size: 13px;
  font-weight: 600;
  color: var(--sky-900);
  line-height: 1.45;
}
.search-window .sw-k {
  display: inline-block;
  min-width: 52px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--sky-700);
}
.search-window .sw-note {
  margin-top: 6px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
}
.leg-dates { font-size: 13px; font-weight: 700; margin-bottom: 4px; color: var(--sky-900); }
.watch-price { font-size: 22px; font-weight: 700; }
.watch-source { font-size: 12px; color: var(--text-muted); margin-top: 4px; }
.watch-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.badge {
  display: inline-block; font-size: 11px; font-weight: 700; padding: 3px 8px;
  border-radius: 999px; text-transform: uppercase; letter-spacing: .03em;
}
.badge-pending { background: var(--amber-50); color: var(--amber-700); }
.badge-active { background: var(--green-50); color: var(--green-600); }
.badge-inactive { background: var(--red-50); color: var(--red-600); }
.badge-paused { background: var(--sky-50); color: var(--sky-800); }

.empty {
  text-align: center; padding: 40px 16px; color: var(--text-muted);
}
.suggest { position: relative; }
.suggest-list {
  position: absolute; left: 0; right: 0; top: 100%; z-index: 10;
  background: #fff; border: 1px solid var(--border); border-radius: 8px;
  box-shadow: var(--shadow-md); max-height: 220px; overflow: auto;
}
.suggest-item {
  display: block; width: 100%; text-align: left; padding: 10px 12px;
  border: none; background: none; cursor: pointer; font-size: 13px;
}
.suggest-item:hover { background: var(--sky-50); }
.suggest-item strong { display: inline-block; width: 38px; color: var(--sky-700); }

.sheet {
  position: fixed; inset: 0; background: rgba(10, 61, 92, .45);
  z-index: 50; display: flex; align-items: flex-end; justify-content: center;
}
.sheet-card {
  background: #fff; width: 100%; max-width: 560px; border-radius: 20px 20px 0 0;
  padding: 24px 20px calc(20px + env(safe-area-inset-bottom));
  max-height: 90vh; overflow: auto;
}
.a2hs-lead { font-size: 14px; color: var(--text-muted); margin-bottom: 12px; line-height: 1.45; }
.a2hs-steps { margin: 12px 0 16px 18px; font-size: 14px; color: var(--text-muted); }
.a2hs-steps li { margin-bottom: 10px; }
.a2hs-chip {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 28px; height: 24px; padding: 2px 7px; border-radius: 6px;
  background: var(--sky-50); color: var(--sky-800); font-weight: 700; font-size: 12px;
  vertical-align: middle; margin: 0 3px;
}
.a2hs-chip-share { background: #e8f0fe; color: #007aff; }
.a2hs-share-icon { width: 14px; height: 14px; display: block; }
.a2hs-chip-menu { background: var(--gray-200); color: var(--sky-900); }
.a2hs-actions { display: flex; gap: 8px; margin-top: 12px; }
.a2hs-actions .btn { flex: 1; }

.invite-share-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.invite-share-btn {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 8px; padding: 16px 10px;
  border: 1px solid var(--border); border-radius: var(--radius-md);
  background: #fff; color: var(--text);
  cursor: pointer; font-size: 13px; font-weight: 600;
}
.invite-share-btn:hover { background: var(--sky-50); }
.invite-share-glyph {
  display: inline-flex; align-items: center; justify-content: center;
  width: 28px; height: 28px; border-radius: 8px;
  font-size: 11px; font-weight: 800; color: #fff;
}
.invite-share-whatsapp .invite-share-glyph { background: #25D366; }
.invite-share-messenger .invite-share-glyph { background: #0084FF; }

.leg-retrieved { font-size: 12px; color: var(--text-muted); font-weight: 500; margin-top: 6px; }
.price-chart { width: 100%; height: auto; display: block; margin: 0; }
.price-chart-wrap {
  background: #fff; border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: 12px 10px 10px; margin-bottom: 8px;
}
.price-chart-cur {
  text-align: center; font-size: 12px; color: var(--text-muted); margin: 2px 0 4px;
}
.btn-logout {
  width: 100%; margin-top: 16px; padding: 14px 16px;
  background: var(--sky-900); color: #fff; border-radius: var(--radius-md);
  font-size: 15px;
}
.btn-logout:hover { background: var(--sky-800); }
.settings-copy {
  text-align: center; margin: 28px 0 8px;
  font-size: 12px; color: var(--text-faint);
}
.cache-note {
  background: var(--amber-50); color: var(--amber-700);
  border-radius: 8px; padding: 8px 10px; font-size: 13px; margin: 8px 0 12px;
}

#toast-container {
  position: fixed; top: 12px; left: 50%; transform: translateX(-50%);
  z-index: 80; display: flex; flex-direction: column; gap: 8px; width: min(92vw, 400px);
}
.toast {
  background: var(--sky-900); color: #fff; padding: 10px 14px; border-radius: 10px;
  font-size: 13px; box-shadow: var(--shadow-md);
}
.toast.error { background: var(--red-600); }
.toast.success { background: var(--green-600); }

.history-row {
  display: flex; justify-content: space-between; gap: 12px;
  padding: 10px 0; border-bottom: 1px solid var(--border); font-size: 13px;
}
.leg-group { margin-top: 10px; }
.leg-label { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--sky-700); margin-bottom: 4px; }
.leg { font-size: 13px; line-height: 1.45; color: var(--text); }
.leg-when { font-weight: 600; color: var(--sky-900); }
.admin-table { width: 100%; border-collapse: collapse; font-size: 13px; background: #fff; border-radius: 12px; overflow: hidden; }
.admin-table th, .admin-table td { padding: 10px 8px; text-align: left; border-bottom: 1px solid var(--border); }
.admin-table th { font-size: 11px; text-transform: uppercase; color: var(--text-faint); }
.code-pill {
  font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 13px;
  background: var(--sky-50); padding: 4px 8px; border-radius: 6px;
}
.log-toolbar {
  display: flex; gap: 8px; align-items: center; margin: 8px 0 10px;
}
.log-toolbar select {
  flex: 1; min-width: 0; font-size: 13px;
}
.log-view {
  margin: 0 0 24px; max-height: 420px; overflow: auto;
  padding: 12px; border-radius: 12px;
  background: var(--sky-900); color: #E8F4FA;
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: 11px; line-height: 1.45; white-space: pre-wrap; word-break: break-word;
}

@media (min-width: 640px) {
  .sheet { align-items: center; }
  .sheet-card { border-radius: var(--radius-xl); margin: 16px; }
}
