/* iBayan Lex — Styles
   Mobile-first, government-appropriate, offline PWA
   Brand system: iBayan / MIMS v1.0 (March 2026)
   ──────────────────────────────────────────────── */

/* ── Custom Properties ───────────────────────────────────────────── */
:root {
  /* Brand primary colors — Philippine flag palette */
  --navy:        #1A3A6B;   /* Philippine Navy — primary UI */
  --navy-dark:   #142d55;   /* Navy darkened — active states */
  --navy-light:  #2a5099;   /* Navy lightened — hover states */
  --gold:        #C8960C;   /* Philippine Gold — accents, CTA */
  --gold-light:  #d4a820;   /* Gold lightened */
  --red:         #A02020;   /* Philippine Red — alerts, section accent */
  --red-dark:    #7d1818;   /* Darkened red — deep hierarchy bars */

  /* Brand support colors */
  --white:       #FFFFFF;
  --dgray:       #2C3E50;   /* Dark Gray — body text, field values */
  --mgray:       #6C757D;   /* Mid Gray — labels, captions, helper text */
  --lgray:       #F5F6F7;   /* Light Gray — alternating rows, backgrounds */
  --sky:         #E8F2FA;   /* Sky Blue — callout boxes, address headers */
  --border:      #BDC3C7;   /* Border Gray — table lines, box outlines */

  /* Semantic aliases */
  --bg:          var(--lgray);
  --surface:     var(--white);
  --text:        var(--dgray);
  --text-2:      var(--mgray);
  --text-3:      #94A3B8;   /* Tertiary text — placeholders, muted */

  /* Layout */
  --radius:      12px;
  --radius-sm:   8px;
  --shadow:      0 1px 4px rgba(0,0,0,.08), 0 4px 16px rgba(0,0,0,.06);
  --shadow-sm:   0 1px 3px rgba(0,0,0,.08);
  --nav-h:       64px;
  --header-h:    56px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);

  /* Typography — Lato single family (brand spec) */
  --font:        'Lato', -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

/* ── Reset ───────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}
button { font-family: inherit; cursor: pointer; border: none; background: none; }
a { color: inherit; text-decoration: none; }
input, textarea { font-family: inherit; }
img, svg { display: block; }

/* ── App Shell ───────────────────────────────────────────────────── */
#app {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}

#top-bar {
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--header-h);
  background: var(--navy);
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 12px;
  box-shadow: 0 2px 8px rgba(0,0,0,.25);
}
#top-bar .logo {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
}
#top-bar .logo img,
#top-bar .logo svg {
  width: 30px;
  height: 30px;
}
#top-bar .logo-text {
  font-size: 18px;
  font-weight: 700;
  color: var(--white);
  letter-spacing: -.3px;
}
#top-bar .logo-sub {
  font-size: 11px;
  color: rgba(255,255,255,.6);
  letter-spacing: .5px;
  text-transform: uppercase;
}
#top-bar .logo-wrap {
  display: flex;
  flex-direction: column;
  line-height: 1.1;
}

/* ── Main Content ────────────────────────────────────────────────── */
#main-content {
  flex: 1;
  padding-bottom: calc(var(--nav-h) + var(--safe-bottom) + 8px);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

/* ── Bottom Navigation ───────────────────────────────────────────── */
#bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 100;
  height: calc(var(--nav-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  box-shadow: 0 -2px 12px rgba(0,0,0,.08);
}
.nav-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 8px 4px;
  color: var(--text-3);
  transition: color .15s, background .15s;
  border-radius: 0;
}
.nav-btn .nav-icon {
  font-size: 22px;
  line-height: 1;
}
.nav-btn .nav-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .3px;
}
.nav-btn.active {
  color: var(--navy);
}
.nav-btn.active .nav-icon {
  position: relative;
}
.nav-btn.active .nav-label {
  font-weight: 700;
}

/* ── Loading State ───────────────────────────────────────────────── */
#loading-screen {
  position: fixed;
  inset: 0;
  background: var(--navy);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 24px;
  z-index: 999;
  transition: opacity .4s;
}
#loading-screen.hidden {
  opacity: 0;
  pointer-events: none;
}
.spinner {
  width: 44px;
  height: 44px;
  border: 3px solid rgba(200,150,12,.25);
  border-top-color: var(--gold);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-text {
  color: rgba(255,255,255,.7);
  font-size: 14px;
}

/* ── Page Header ─────────────────────────────────────────────────── */
.page-header {
  background: var(--navy);
  color: var(--white);
  padding: 20px 16px 24px;
}
.page-header h1 {
  font-size: 26px;
  font-weight: 900;
  color: var(--white);
  letter-spacing: -.5px;
}
.page-header h2 {
  font-size: 20px;
  font-weight: 700;
  color: var(--white);
  line-height: 1.2;
  margin-top: 4px;
}
.page-header .subtitle {
  font-size: 13px;
  color: rgba(255,255,255,.65);
  margin-top: 4px;
}
.page-header .topic-icon-large {
  font-size: 36px;
  display: block;
  margin-bottom: 8px;
}

/* ── Back Button ─────────────────────────────────────────────────── */
.back-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: rgba(255,255,255,.8);
  font-size: 14px;
  font-weight: 700;
  padding: 4px 0;
  margin-bottom: 12px;
  transition: color .15s;
}
.back-btn:hover { color: var(--white); }

/* ── Topic Grid ──────────────────────────────────────────────────── */
.topic-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  padding: 16px;
}
.topic-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border);
  text-align: left;
  transition: transform .12s, box-shadow .12s;
  -webkit-tap-highlight-color: transparent;
}
.topic-card:active {
  transform: scale(.97);
  box-shadow: none;
}
.topic-card .topic-icon {
  font-size: 28px;
  line-height: 1;
}
.topic-card .topic-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
  line-height: 1.3;
}
.topic-card .topic-count {
  font-size: 11px;
  color: var(--text-3);
  font-weight: 400;
}
.ra-info {
  text-align: center;
  padding: 8px 16px 20px;
  color: var(--text-3);
  font-size: 12px;
}

/* ── Section List ────────────────────────────────────────────────── */
.section-list {
  padding: 8px 16px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.section-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  text-align: left;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 3px;
  transition: background .12s;
  -webkit-tap-highlight-color: transparent;
}
.section-item:active {
  background: var(--bg);
}
.section-number {
  font-size: 11px;
  font-weight: 700;
  color: var(--navy);
  text-transform: uppercase;
  letter-spacing: .5px;
}
.section-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
  line-height: 1.35;
}
.section-subtitle {
  font-size: 12px;
  color: var(--text-2);
  line-height: 1.4;
}
.section-snippet {
  font-size: 12px;
  color: var(--text-2);
  line-height: 1.4;
  margin-top: 2px;
}
.section-snippet mark {
  background: rgba(200,150,12,.18);
  color: #7a5c00;
  border-radius: 2px;
  padding: 0 1px;
}

/* ── Section Detail ──────────────────────────────────────────────── */
.view-section {
  max-width: 680px;
  margin: 0 auto;
}
.section-nav-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px 0;
  background: var(--navy);
}
.pdf-btn {
  font-size: 12px;
  font-weight: 700;
  color: var(--white);
  border: 1.5px solid rgba(255,255,255,.55);
  border-radius: 6px;
  padding: 4px 10px;
  letter-spacing: .3px;
  transition: background .12s, border-color .12s;
}
.pdf-btn:active {
  background: rgba(255,255,255,.15);
  border-color: var(--white);
}
.section-header {
  background: var(--navy);
  padding: 0 16px 20px;
  color: var(--white);
}
.section-breadcrumb {
  font-size: 11px;
  color: rgba(255,255,255,.5);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: .4px;
}
.section-title-row {
  display: flex;
  align-items: center;
  gap: 10px;
}
.section-header h2 {
  font-size: 22px;
  font-weight: 900;
  color: var(--white);
  line-height: 1;
}
.legend-btn {
  background: none;
  border: none;
  color: rgba(255,255,255,.55);
  font-size: 18px;
  line-height: 1;
  padding: 0 4px;
  cursor: pointer;
  flex-shrink: 0;
  transition: color 0.15s;
}
.legend-btn:hover, .legend-btn:active { color: var(--gold); }

/* Popover */
.legend-popover {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  z-index: 200;
  box-shadow: 0 4px 20px rgba(0,0,0,.15);
  min-width: 220px;
}
.legend-popover strong {
  display: block;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .6px;
  color: var(--text-2);
  margin-bottom: 8px;
}

/* One-time hint banner */
.legend-hint {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  background: var(--sky);
  border-bottom: 1px solid var(--border);
  padding: 10px 14px;
  transition: opacity 0.3s, max-height 0.3s;
  overflow: hidden;
}
.legend-hint-out {
  opacity: 0;
  max-height: 0;
  padding: 0;
}
.legend-hint-label {
  font-size: 12px;
  font-weight: 700;
  color: var(--navy);
  display: block;
  margin-bottom: 6px;
}
.legend-hint-body { flex: 1; }
.legend-hint-dismiss {
  background: none;
  border: none;
  font-size: 14px;
  color: var(--mgray);
  cursor: pointer;
  padding: 0 2px;
  line-height: 1;
  flex-shrink: 0;
}

/* Shared legend items */
.legend-items {
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.legend-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text);
}
.legend-bar {
  display: inline-block;
  width: 4px;
  height: 18px;
  border-radius: 2px;
  flex-shrink: 0;
}
/* Class names preserved from earlier iteration; colors updated to flag order */
.legend-bar.gold   { background: var(--navy); }       /* Level 1: (a)(b)(c) — Navy */
.legend-bar.gray   { background: var(--gold); }       /* Level 2: (1)(2)(3) — Gold */
.legend-bar.dotted { background: var(--red-dark); }   /* Level 3: (aa)(bb) — Red   */

.section-header h3 {
  font-size: 16px;
  font-weight: 700;
  color: var(--white);
  margin-top: 4px;
  line-height: 1.3;
}
.section-body {
  padding: 20px 16px;
  background: var(--surface);
}
.section-body p {
  font-size: 15px;
  line-height: 1.75;
  color: var(--text);
  margin-bottom: 16px;
}
.section-body p:last-child { margin-bottom: 0; }
.section-body .placeholder {
  color: var(--text-3);
  font-style: italic;
  font-size: 14px;
  padding: 16px;
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
  text-align: center;
}

/* Subsection formatting — flag color order: Navy / Gold / Red */
.section-body p.sec-para {
  margin-bottom: 14px;
}
.section-body p.sec-sub-alpha {
  padding-left: 20px;
  border-left: 3px solid var(--navy);
  margin-bottom: 10px;
  margin-top: 10px;
}
.section-body p.sec-sub-num {
  padding-left: 14px;
  border-left: 2px solid var(--gold);
  margin-bottom: 8px;
  margin-top: 12px;
  font-weight: 400;
}
.section-body p.sec-sub-deep {
  padding-left: 32px;
  border-left: 2px dotted var(--red-dark);
  margin-bottom: 6px;
  color: var(--text-2);
}
.section-topics {
  padding: 12px 16px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}
.section-topics .label {
  font-size: 12px;
  color: var(--text-3);
  font-weight: 400;
}
.topic-tag {
  background: var(--sky);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 12px;
  font-weight: 700;
  color: var(--navy);
}
.section-actions {
  padding: 16px;
  display: flex;
  gap: 12px;
  background: var(--surface);
  border-top: 1px solid var(--border);
}
.citation-group {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 1;
}
.citation-group .btn-secondary {
  flex: 1;
}
.btn-citation-full {
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-2);
  font-size: 12px;
  font-weight: 700;
  padding: 6px 10px;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, color 0.15s;
}
.btn-citation-full:hover,
.btn-citation-full:active {
  background: var(--bg);
  color: var(--text);
}
.btn-primary {
  flex: 1;
  background: var(--navy);
  color: var(--white);
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 700;
  text-align: center;
  transition: background .12s;
}
.btn-primary:active { background: var(--navy-dark); }
.btn-secondary {
  flex: 1;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 700;
  text-align: center;
  transition: background .12s;
}
.btn-secondary:active { background: var(--border); }
.section-pagination {
  display: flex;
  justify-content: space-between;
  padding: 12px 16px 8px;
  border-top: 1px solid var(--border);
  background: var(--surface);
}
.page-btn {
  font-size: 13px;
  font-weight: 700;
  color: var(--navy);
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  transition: background .12s;
}
.page-btn:active { background: var(--bg); }

/* ── Search ──────────────────────────────────────────────────────── */
.view-search {
  display: flex;
  flex-direction: column;
  min-height: calc(100dvh - var(--header-h) - var(--nav-h));
}
.search-header {
  background: var(--navy);
  padding: 16px 16px 20px;
  color: var(--white);
}
.search-header h2 {
  font-size: 20px;
  font-weight: 700;
  color: var(--white);
  margin-bottom: 12px;
}
.search-box {
  display: flex;
  gap: 8px;
}
.search-box input {
  flex: 1;
  background: rgba(255,255,255,.12);
  border: 1.5px solid rgba(255,255,255,.25);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 15px;
  color: var(--white);
  outline: none;
  transition: border-color .15s, background .15s;
}
.search-box input::placeholder { color: rgba(255,255,255,.45); }
.search-box input:focus {
  background: rgba(255,255,255,.18);
  border-color: var(--gold);
}
.search-box button {
  background: var(--gold);
  color: var(--white);
  font-weight: 700;
  font-size: 14px;
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  transition: opacity .12s;
}
.search-box button:active { opacity: .8; }
.search-results {
  padding: 12px 16px 16px;
}
.hint, .no-results {
  color: var(--text-3);
  font-size: 14px;
  text-align: center;
  padding: 32px 0;
}
.results-count {
  font-size: 13px;
  color: var(--text-2);
  margin-bottom: 10px;
  font-weight: 700;
}

/* ── PDF View ────────────────────────────────────────────────────── */
.view-pdf {
  display: flex;
  flex-direction: column;
  height: calc(100dvh - var(--header-h) - var(--nav-h));
}
.pdf-header {
  background: var(--navy);
  padding: 14px 16px 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.pdf-header h2 {
  font-size: 18px;
  font-weight: 700;
  color: var(--white);
}
.pdf-header p {
  font-size: 13px;
  color: rgba(255,255,255,.65);
}
.btn-download {
  display: inline-block;
  margin-top: 8px;
  background: var(--gold);
  color: var(--white);
  font-size: 13px;
  font-weight: 700;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  align-self: flex-start;
  transition: opacity .12s;
}
.btn-download:active { opacity: .8; }
.pdf-frame-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: #525659;
}
.pdf-frame {
  flex: 1;
  width: 100%;
  height: 100%;
  border: none;
  min-height: 400px;
}
.pdf-fallback {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 40px 24px;
  text-align: center;
  color: var(--white);
  flex: 1;
}
.pdf-fallback p { font-size: 15px; color: rgba(255,255,255,.75); line-height: 1.5; }

/* ── AI Chat ─────────────────────────────────────────────────────── */
.view-chat {
  display: flex;
  flex-direction: column;
  height: calc(100dvh - var(--header-h) - var(--nav-h));
}
.chat-header {
  background: var(--navy);
  padding: 14px 16px;
}
.chat-header h2 {
  font-size: 18px;
  font-weight: 700;
  color: var(--white);
}
.chat-scope {
  font-size: 12px;
  color: rgba(255,255,255,.6);
  margin-top: 2px;
}
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  -webkit-overflow-scrolling: touch;
}
.chat-welcome {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 8px 0;
}
.chat-welcome > p {
  font-size: 15px;
  color: var(--text-2);
  line-height: 1.5;
}
.examples-label {
  font-size: 13px;
  color: var(--text-3);
  font-weight: 700;
}
.example-questions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.example-questions button {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  text-align: left;
  font-size: 13px;
  font-weight: 700;
  color: var(--navy);
  line-height: 1.4;
  transition: background .12s;
}
.example-questions button:active { background: var(--bg); }

.chat-msg {
  display: flex;
  flex-direction: column;
  max-width: 92%;
}
.chat-msg.user {
  align-self: flex-end;
  align-items: flex-end;
}
.chat-msg.assistant {
  align-self: flex-start;
  align-items: flex-start;
}
.chat-bubble {
  border-radius: 18px;
  padding: 10px 14px;
  font-size: 14px;
  line-height: 1.55;
}
.chat-msg.user .chat-bubble {
  background: var(--navy);
  color: var(--white);
  border-bottom-right-radius: 4px;
}
.chat-msg.assistant .chat-bubble {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}
.chat-citation {
  font-size: 12px;
  margin-top: 6px;
  display: inline-block;
}
.chat-citation-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--navy);
  font-weight: 700;
  text-decoration: none;
  padding: 4px 10px;
  background: rgba(26,58,107,.07);
  border-radius: 6px;
  transition: background 0.15s;
}
.chat-citation-link:hover,
.chat-citation-link:active {
  background: rgba(26,58,107,.15);
  text-decoration: underline;
}
.chat-disclaimer {
  background: var(--sky);
  border-top: 1px solid var(--border);
  padding: 8px 14px;
  font-size: 12px;
  color: var(--navy);
  font-weight: 700;
  line-height: 1.4;
  flex-shrink: 0;
}
.chat-input-area {
  display: flex;
  gap: 10px;
  padding: 10px 12px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  align-items: flex-end;
  flex-shrink: 0;
  padding-bottom: calc(10px + var(--safe-bottom));
}
.chat-input-area textarea {
  flex: 1;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 15px;
  resize: none;
  outline: none;
  line-height: 1.45;
  max-height: 120px;
  overflow-y: auto;
  transition: border-color .15s;
}
.chat-input-area textarea:focus { border-color: var(--navy); }
.chat-input-area button {
  background: var(--navy);
  color: var(--white);
  font-size: 14px;
  font-weight: 700;
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  align-self: flex-end;
  height: 42px;
  white-space: nowrap;
  transition: opacity .12s;
  flex-shrink: 0;
}
.chat-input-area button:active { opacity: .8; }
.chat-input-area button:disabled {
  opacity: .4;
  cursor: not-allowed;
}
.chat-typing {
  display: flex;
  gap: 4px;
  padding: 10px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  border-bottom-left-radius: 4px;
  width: fit-content;
}
.chat-typing span {
  width: 7px;
  height: 7px;
  background: var(--text-3);
  border-radius: 50%;
  animation: bounce 1.2s ease-in-out infinite;
}
.chat-typing span:nth-child(2) { animation-delay: .15s; }
.chat-typing span:nth-child(3) { animation-delay: .3s; }
@keyframes bounce {
  0%, 80%, 100% { transform: scale(1); opacity: .5; }
  40% { transform: scale(1.25); opacity: 1; }
}
.chat-error {
  color: var(--red);
  font-size: 13px;
  font-style: italic;
  padding: 6px 10px;
  background: #fff0f0;
  border-radius: var(--radius-sm);
  border: 1px solid #ffd0d0;
}
.offline-notice {
  background: var(--sky);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-size: 13px;
  color: var(--navy);
  text-align: center;
  line-height: 1.5;
}

/* ── Footer Brand ────────────────────────────────────────────────── */
.brand-footer {
  text-align: center;
  padding: 20px 16px 8px;
  border-top: 1px solid var(--border);
  background: var(--surface);
}
.brand-footer p {
  font-size: 11px;
  color: var(--text-3);
}
.brand-footer .ibayan-link {
  font-size: 12px;
  font-weight: 700;
  color: var(--navy);
}

/* ── Toast Notification ──────────────────────────────────────────── */
#toast {
  position: fixed;
  bottom: calc(var(--nav-h) + var(--safe-bottom) + 12px);
  left: 50%;
  transform: translateX(-50%) translateY(12px);
  background: var(--dgray);
  color: var(--white);
  font-size: 13px;
  font-weight: 700;
  padding: 10px 20px;
  border-radius: 999px;
  box-shadow: var(--shadow);
  opacity: 0;
  transition: opacity .2s, transform .2s;
  pointer-events: none;
  white-space: nowrap;
  z-index: 200;
}
#toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ── Offline Banner ──────────────────────────────────────────────── */
#offline-banner {
  display: none;
  background: var(--gold);
  color: var(--white);
  text-align: center;
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 700;
}
body.is-offline #offline-banner { display: block; }

/* ── Tablet/Desktop upscale ──────────────────────────────────────── */
@media (min-width: 480px) {
  .topic-grid { grid-template-columns: repeat(3, 1fr); }
}
@media (min-width: 768px) {
  #bottom-nav { max-width: 480px; left: 50%; transform: translateX(-50%); border-radius: 20px 20px 0 0; border-left: 1px solid var(--border); border-right: 1px solid var(--border); }
  #main-content { max-width: 480px; margin: 0 auto; }
  #top-bar { max-width: 480px; margin: 0 auto; /* keep sticky full-width */ }
  .topic-grid { grid-template-columns: repeat(3, 1fr); }
}
