/* =================================================================
   Channel cards
   ================================================================= */
.channel-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: var(--s-4);
}
.channel-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: var(--s-4) var(--s-5);
  transition: all 0.2s ease;
  position: relative;
  overflow: hidden;
}
.channel-card:hover {
  border-color: var(--border-strong);
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}
.channel-card-head {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  margin-bottom: var(--s-3);
  padding-bottom: var(--s-3);
  border-bottom: 1px solid var(--surface-3);
}
.channel-card-head .icon {
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border-radius: var(--r-sm);
  background: var(--surface-3);
  font-size: 14px;
}
.channel-card-head h4 {
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  flex: 1;
}
.channel-winner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-2);
  padding: var(--s-3) 0;
  margin-bottom: var(--s-3);
}
.channel-winner .name {
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.channel-winner .figures {
  text-align: right;
  flex-shrink: 0;
}
.channel-winner .visits {
  font-size: 18px;
  font-weight: 700;
  color: var(--brand-darker);
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}
.channel-winner .pct {
  font-size: 11px;
  color: var(--text-3);
  font-weight: 600;
  margin-top: 2px;
}
.channel-bar {
  height: 6px;
  background: var(--surface-3);
  border-radius: 999px;
  overflow: hidden;
  margin-bottom: var(--s-3);
}
.channel-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--brand) 0%, var(--brand-dark) 100%);
  border-radius: 999px;
  transition: width 0.4s ease;
}
.channel-others {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.channel-others .row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
  color: var(--text-2);
  padding: 3px 0;
}
.channel-others .row .name {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.channel-others .row .v {
  font-weight: 600;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}
.channel-empty {
  text-align: center;
  color: var(--text-3);
  font-size: 12px;
  padding: var(--s-3) 0;
}

/* =================================================================
   Region distribution stacked bars
   ================================================================= */
.region-bars { display: flex; flex-direction: column; gap: var(--s-3); }
.region-bar-row {
  display: grid;
  grid-template-columns: 200px 1fr 120px;
  gap: var(--s-4);
  align-items: center;
}
@media (max-width: 760px) {
  .region-bar-row { grid-template-columns: 1fr; gap: 6px; }
}
.region-bar-row .domain-label {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 8px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.region-bar {
  height: 36px;
  background: var(--surface-3);
  border-radius: var(--r-sm);
  overflow: hidden;
  display: flex;
  position: relative;
  box-shadow: inset 0 1px 2px rgba(0,0,0,0.04);
}
.region-seg {
  height: 100%;
  transition: opacity 0.15s ease;
  position: relative;
  display: grid;
  place-items: center;
  font-size: 11px;
  font-weight: 700;
  color: rgba(255,255,255,0.95);
  text-shadow: 0 1px 2px rgba(0,0,0,0.2);
  cursor: default;
  overflow: hidden;
  white-space: nowrap;
}
.region-seg:hover { opacity: 0.85; }
.region-seg .seg-tip {
  visibility: hidden;
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: #fff;
  padding: 6px 10px;
  border-radius: var(--r-sm);
  font-size: 11px;
  white-space: nowrap;
  font-weight: 500;
  text-shadow: none;
  box-shadow: var(--shadow-md);
  z-index: 20;
}
.region-seg:hover .seg-tip { visibility: visible; }
.region-bar-row .total {
  text-align: right;
  font-size: 13px;
  color: var(--text-2);
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}
.region-legend {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-3);
  margin-top: var(--s-5);
  padding-top: var(--s-4);
  border-top: 1px solid var(--surface-3);
  font-size: 12px;
  color: var(--text-2);
}
.region-legend .item { display: inline-flex; align-items: center; gap: 6px; }
.region-legend .dot { width: 12px; height: 12px; border-radius: 3px; }

/* =================================================================
   Login overlay (Google Sign-In, @fabcom.hk only)
   ================================================================= */
.login-overlay {
  position: fixed;
  inset: 0;
  background: linear-gradient(135deg, #fafafa 0%, #fff7ed 100%);
  display: grid;
  place-items: center;
  z-index: 1000;
}
.login-card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  padding: 48px 56px;
  box-shadow: var(--shadow-xl);
  text-align: center;
  max-width: 420px;
  animation: fadeUp 0.4s ease;
}
.login-logo {
  width: 56px;
  height: 56px;
  margin: 0 auto 20px;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, var(--brand) 0%, var(--brand-dark) 100%);
  color: #fff;
  border-radius: var(--r-md);
  font-weight: 800;
  font-size: 24px;
  box-shadow: var(--shadow-md);
}
.login-card h2 {
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 6px;
  letter-spacing: -0.01em;
}
.login-sub {
  color: var(--text-2);
  font-size: 13px;
  margin-bottom: 4px;
}
.login-error {
  background: var(--bad-bg);
  border: 1px solid #fca5a5;
  color: var(--bad);
  padding: 10px 14px;
  border-radius: var(--r-md);
  font-size: 13px;
  margin-top: 16px;
}

/* User pill in toolbar (shown when logged in) */
.user-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 4px 12px 4px 4px;
  font-size: 12px;
  color: var(--text-2);
  font-weight: 600;
}
.user-pill img {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 1px solid var(--border);
}
.user-pill .logout {
  background: none;
  border: none;
  color: var(--text-3);
  cursor: pointer;
  font-size: 11px;
  padding: 0 4px;
  margin-left: 4px;
  border-left: 1px solid var(--border);
  height: 16px;
}
.user-pill .logout:hover { color: var(--bad); }

/* =================================================================
   Action bar (PDF, future actions)
   ================================================================= */
.action-bar {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-bottom: var(--s-3);
}

/* =================================================================
   PDF / Print export
   ================================================================= */
.pdf-btn {
  background: #fff;
  border: 1px solid var(--border);
  color: var(--text-2);
  padding: 8px 16px;
  border-radius: var(--r-md);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  box-shadow: var(--shadow-xs);
  transition: all 0.15s ease;
}
.pdf-btn:hover { border-color: var(--brand); color: var(--brand-darker); }

@media print {
  /* Hide interactive bits when printing */
  .toolbar, .input-panel, .ai-btn, .pdf-btn, .btn-mini, .events-controls,
  details.advanced summary { display: none !important; }
  details.advanced { border: 1px solid #ccc; }
  details.advanced[open] summary { display: block !important; }

  body { background: #fff; padding: 0; font-size: 11px; }
  .container { max-width: none; padding: 0 12mm; }
  .section, .hero, .ai-section, details.advanced {
    box-shadow: none;
    page-break-inside: avoid;
    break-inside: avoid;
    border: 1px solid #d4d4d4;
    margin-bottom: 10px;
  }
  .hero { background: #fff !important; }
  .hero::after { display: none; }
  .hero-headline .winner { color: #c2410c !important; -webkit-text-fill-color: #c2410c !important; }
  .chart-wrap { height: 280px !important; }
  .chart-wrap.tall { height: 240px !important; }
  /* Force colour-printing for backgrounds (Chrome) */
  * { -webkit-print-color-adjust: exact !important; print-color-adjust: exact !important; }
  /* Page break hints */
  .section { page-break-after: auto; }
  h1, h2, h3 { page-break-after: avoid; }
}

/* =================================================================
   AI Insights section (OpenAI gpt-4o-mini)
   ================================================================= */
.ai-section {
  background: linear-gradient(135deg, #fff 0%, #faf5ff 100%);
  border: 1px solid #e9d5ff;
  border-radius: var(--r-lg);
  padding: var(--s-5) var(--s-6);
  margin-bottom: var(--s-5);
  box-shadow: var(--shadow-sm);
}
.ai-section.ai-loading { background: linear-gradient(135deg, #fff 0%, #f0f9ff 100%); border-color: #bae6fd; }
.ai-section.ai-error { background: var(--bad-bg); border-color: #fca5a5; }
.ai-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--s-4);
  flex-wrap: wrap;
}
.ai-title {
  font-size: 16px;
  font-weight: 700;
  color: #6b21a8;
  display: flex;
  align-items: center;
  gap: 8px;
}
.ai-sub {
  font-size: 12px;
  color: var(--text-3);
  margin-top: 4px;
}
.ai-btn {
  background: linear-gradient(135deg, #a855f7 0%, #7c3aed 100%);
  color: #fff;
  border: none;
  padding: 9px 20px;
  border-radius: var(--r-md);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: all 0.15s ease;
  white-space: nowrap;
}
.ai-btn:hover { transform: translateY(-1px); box-shadow: var(--shadow-md); }
.ai-cache {
  display: inline-block;
  background: var(--surface-3);
  color: var(--text-3);
  font-size: 10px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 10px;
  margin-left: 6px;
  vertical-align: middle;
}
.ai-tokens { font-family: ui-monospace, "SF Mono", Consolas, monospace; }
.ai-body {
  margin-top: var(--s-4);
  padding-top: var(--s-4);
  border-top: 1px solid #e9d5ff;
  font-size: 14px;
  line-height: 1.7;
  color: var(--text);
}
.ai-body p { margin: 8px 0; }
.ai-body b { color: #6b21a8; }
.ai-list {
  margin: 0;
  padding-left: 24px;
  list-style: none;
}
.ai-list li {
  position: relative;
  margin-bottom: 12px;
  padding-left: 4px;
}
.ai-list li::marker { display: none; }

/* =================================================================
   Trend events panel (news + LIHKG threads, with hide checkboxes)
   ================================================================= */
.events-panel {
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}
.events-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}
.events-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 8px;
}
.events-title .events-count {
  background: var(--surface-3);
  color: var(--text-2);
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 10px;
  font-variant-numeric: tabular-nums;
}
.events-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.btn-mini {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-2);
  font-size: 11px;
  font-weight: 600;
  padding: 5px 10px;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.15s ease;
}
.btn-mini:hover {
  background: var(--brand-light);
  color: var(--brand-darker);
  border-color: var(--brand);
}
.events-divider {
  width: 1px;
  height: 18px;
  background: var(--border);
}
.kind-toggle {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  color: var(--text-2);
  cursor: pointer;
  user-select: none;
}
.kind-toggle input[type="checkbox"] {
  cursor: pointer;
  accent-color: var(--brand);
}
.events-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 14px;
}
.events-col {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 12px 14px;
}
.events-col-head {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 8px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}
.events-col-count {
  margin-left: auto;
  color: var(--text-3);
  font-weight: 600;
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}
.events-col-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 240px;
  overflow-y: auto;
}
.event-row {
  display: grid;
  grid-template-columns: auto auto auto 1fr;
  gap: 6px;
  align-items: center;
  padding: 4px 6px;
  border-radius: 4px;
  font-size: 11px;
  color: var(--text-2);
  cursor: pointer;
  transition: background 0.1s ease;
}
.event-row:hover { background: var(--surface-3); }
.event-row.hidden { opacity: 0.45; }
.event-row input[type="checkbox"] {
  cursor: pointer;
  accent-color: var(--brand);
  margin: 0;
}
.event-date {
  font-variant-numeric: tabular-nums;
  color: var(--text-3);
  font-size: 10px;
  font-weight: 600;
}
.event-icon { font-size: 12px; }
.event-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}
.event-title a { color: inherit; text-decoration: none; }
.event-title a:hover { color: var(--brand-darker); text-decoration: underline; }
.events-more {
  font-size: 11px;
  color: var(--text-3);
  text-align: center;
  padding: 6px 0;
  font-style: italic;
}

/* =================================================================
   Online Footprint cards
   ================================================================= */
.footprint-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(360px, 1fr));
  gap: var(--s-4);
}
.footprint-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: var(--s-5);
  transition: all 0.2s ease;
}
.footprint-card:hover {
  border-color: var(--border-strong);
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}
.footprint-card h4 {
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: var(--s-4);
  padding-bottom: var(--s-3);
  border-bottom: 1px solid var(--surface-3);
  display: flex;
  align-items: center;
  gap: 6px;
}
.brand-tag {
  background: linear-gradient(135deg, #faf5ff 0%, #ede9fe 100%);
  color: #6b21a8; font-size: 9px; font-weight: 800; padding: 2px 7px;
  border-radius: 8px; text-transform: uppercase; letter-spacing: 0.5px;
  margin-left: auto; border: 1px solid #ddd6fe;
}
.fp-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--s-3) var(--s-4);
}
.fp-stat {
  display: flex;
  align-items: flex-start;
  gap: 10px;
}
.fp-icon {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  font-size: 14px;
  flex-shrink: 0;
}
.fp-body {
  min-width: 0;
  flex: 1;
}
.fp-num {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.fp-label {
  font-size: 11px;
  color: var(--text-3);
  margin-top: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.fp-sample {
  margin-top: var(--s-4);
  padding-top: var(--s-3);
  border-top: 1px solid var(--surface-3);
}
.fp-sample-head {
  font-size: 10px;
  font-weight: 700;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 0.6px;
  margin-bottom: 8px;
}
.fp-sample-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  padding: 4px 0;
  color: var(--text-2);
}
.fp-sample-row .badge {
  background: var(--info-bg);
  color: var(--info);
  padding: 1px 6px;
  border-radius: var(--r-sm);
  font-size: 10px;
  font-weight: 700;
  flex-shrink: 0;
}
.fp-sample-row .t {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.fp-sample-row .score {
  color: var(--text-3);
  font-size: 11px;
  font-weight: 600;
  flex-shrink: 0;
}

/* =================================================================
   Keywords
   ================================================================= */
.keywords-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: var(--s-4);
}
.kw-card {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: var(--s-4);
  transition: all 0.15s ease;
}
.kw-card:hover { border-color: var(--border-strong); box-shadow: var(--shadow-sm); }
.kw-card h4 { font-size: 13px; font-weight: 700; margin-bottom: var(--s-3); color: var(--text); display: flex; align-items: center; gap: 6px; }
.kw-row {
  display: flex;
  justify-content: space-between;
  padding: 5px 0;
  font-size: 12px;
  color: var(--text-2);
  gap: var(--s-2);
}
.kw-row .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; flex: 1; }
.kw-row .vol { color: var(--text-3); font-variant-numeric: tabular-nums; flex-shrink: 0; }

/* =================================================================
   Cross-source validation table (collapsed advanced section)
   ================================================================= */
details.advanced {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 0;
  margin-bottom: var(--s-5);
  box-shadow: var(--shadow-sm);
}
details.advanced summary {
  padding: var(--s-5) var(--s-8);
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  gap: var(--s-3);
  user-select: none;
}
details.advanced summary::-webkit-details-marker { display: none; }
details.advanced summary::before {
  content: "▶";
  font-size: 11px;
  color: var(--text-3);
  transition: transform 0.15s ease;
}
details.advanced[open] summary::before { transform: rotate(90deg); }
details.advanced[open] summary { border-bottom: 1px solid var(--border); }
details.advanced .body { padding: var(--s-6) var(--s-8); }
.cross-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.cross-table th, .cross-table td {
  padding: 10px var(--s-3);
  text-align: left;
  border-bottom: 1px solid var(--surface-3);
}
.cross-table th {
  background: var(--surface-2);
  color: var(--text-3);
  font-weight: 700;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.cross-table td.num { text-align: right; font-variant-numeric: tabular-nums; }
.cross-table tr:hover td { background: var(--surface-2); }
.cross-table .domain-cell { font-weight: 600; }
