/* Cloudflare V1: risk-first cockpit — dark mặc định, mobile-first, số liệu dễ quét. */
/* Chia sẻ chung giữa mọi page (multi-page Pattern B): template.html (chung-khoan),
   template-overview.html (/), template-shell.html (life-os/agent-os). */
:root {
  color-scheme: dark;
  --bg: #07111f;
  --surface: #0d1b2a;
  --surface-2: #10243a;
  --surface-3: #132b45;
  --text: #e8eef7;
  --muted: #93a7bd;
  --faint: #60758c;
  --divider: #20364d;
  --link: #8bc2ff;
  --good: #49d3a1;
  --bad: #ff7f8f;
  --warn: #ffca70;
  --accent: #82aaff;
  --shadow: 0 16px 40px rgba(0, 0, 0, .18);
}
@media (prefers-color-scheme: light) {
  :root {
    color-scheme: light;
    --bg: #f4f7fb;
    --surface: #ffffff;
    --surface-2: #eef4fb;
    --surface-3: #e5eef9;
    --text: #122033;
    --muted: #5f7185;
    --faint: #8797a8;
    --divider: #dce5ef;
    --link: #075db5;
    --good: #087f5b;
    --bad: #c7354c;
    --warn: #a75c00;
    --accent: #315fc2;
    --shadow: 0 12px 30px rgba(37, 61, 88, .08);
  }
}
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; min-width: 320px; }
body {
  background: var(--bg); color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display", "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  font-size: 15px; line-height: 1.55; font-weight: 400;
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { font-weight: 700; line-height: 1.2; letter-spacing: -.018em; }
a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }
:focus-visible { outline: 2px solid var(--link); outline-offset: 3px; }

.stale-banner {
  display: none; position: fixed; inset: 0 0 auto; z-index: 99;
  background: var(--bad); color: #fff; padding: 11px 18px;
  font-size: 13px; font-weight: 700; text-align: center;
}
body.build-stale .stale-banner { display: block; }

.page-shell { min-height: 100vh; padding-bottom: 72px; }
.site-header, .dashboard-main, .site-footer { width: min(1180px, calc(100% - 40px)); margin: 0 auto; }
.site-header { padding: 34px 0 22px; padding-top: max(34px, calc(22px + env(safe-area-inset-top))); }
.brand-block { padding: 22px 24px; background: linear-gradient(135deg, var(--surface-2), var(--surface)); border: 1px solid var(--divider); border-radius: 20px; box-shadow: var(--shadow); }
.page-kicker { color: var(--accent); font-size: 11px; font-weight: 800; letter-spacing: .11em; text-transform: uppercase; }
.title-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-top: 6px; }
.page-title { margin: 0; font-size: clamp(27px, 4vw, 42px); }
.status-pill { border: 1px solid var(--divider); border-radius: 999px; color: var(--muted); font-size: 10px; font-weight: 800; letter-spacing: .08em; padding: 4px 8px; }
.page-subtitle { color: var(--muted); margin: 8px 0 0; max-width: 680px; }
.page-asof, .freshness-line, .quick-links { display: flex; flex-wrap: wrap; gap: 6px 12px; }
.page-asof { color: var(--muted); font-size: 12px; margin-top: 17px; }
.header-snapshot { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 8px; margin-top: 15px; }
.snapshot-chip { display: inline-flex; align-items: baseline; gap: 7px; padding: 8px 10px; background: var(--surface-3); border: 1px solid var(--divider); border-radius: 10px; }
.snapshot-chip .lbl { color: var(--muted); font-size: 12px; }
.snapshot-chip .val { color: var(--text); font-size: 13px; font-weight: 700; }
.freshness-line { margin-top: 13px; font-size: 11px; }
.freshness-chip { color: var(--muted); }
.freshness-fresh { color: var(--good); }
.freshness-stale, .freshness-conflicting { color: var(--bad); font-weight: 700; }
.freshness-unknown, .freshness-partial { color: var(--warn); font-weight: 700; }
.quick-links { align-items: baseline; margin-top: 13px; font-size: 12px; }
.quick-links .ql-k { color: var(--muted); font-weight: 700; }
.quick-links a { color: var(--muted); border-bottom: 1px dotted var(--faint); }
.quick-links a:hover { color: var(--link); border-bottom-color: var(--link); }
.quick-links a + a::before { content: ' · '; margin-right: 4px; color: var(--faint); }

/* Multi-page nav — dùng chung mọi page (Pattern B) */
.page-nav { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 16px; }
.page-nav a { padding: 6px 14px; border: 1px solid var(--divider); border-radius: 999px; color: var(--muted); font-size: 12px; font-weight: 700; }
.page-nav a:hover { color: var(--link); border-color: var(--link); text-decoration: none; }
.page-nav a.active { background: var(--accent); border-color: var(--accent); color: var(--bg); }

.dashboard-main { display: grid; gap: 18px; }
.dashboard-section { min-width: 0; padding: 20px; background: var(--surface); border: 1px solid var(--divider); border-radius: 16px; box-shadow: var(--shadow); }
.section-primary { border-color: color-mix(in srgb, var(--accent) 42%, var(--divider)); }
.section-kicker { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin: 0 0 14px; font-size: 18px; }
.section-kicker .sec-sub, .sec-tag { color: var(--muted); font-size: 11px; font-weight: 500; letter-spacing: .01em; }
.section-kicker .sec-sub { font-size: inherit; }
.section-primary .section-kicker { color: var(--accent); }

.feed-card { min-width: 0; margin-bottom: 12px; padding: 15px; background: var(--surface-2); border: 1px solid var(--divider); border-radius: 13px; transition: background-color 0.15s ease, border-color 0.15s ease; }
.feed-card:last-child { margin-bottom: 0; }
@media (hover: hover) { .feed-card:hover { background: color-mix(in srgb, var(--surface-3) 70%, var(--surface-2)); border-color: color-mix(in srgb, var(--accent) 18%, var(--divider)); } }
.feed-card .meta { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; flex-wrap: wrap; margin-bottom: 4px; color: var(--muted); font-size: 11px; }
.feed-card .meta .author { color: var(--text); font-weight: 700; }
.feed-card .topic { margin-bottom: 4px; color: var(--text); font-size: 14px; font-weight: 700; }
.feed-card .summary { color: var(--text); font-size: 14px; }
.feed-card .summary.warn, .summary.warn { color: var(--warn); }
.holding-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin-bottom: 8px; }
.holding-head .ticker { color: var(--accent); font-size: 23px; font-weight: 800; letter-spacing: .04em; }
.holding-head .qty { color: var(--muted); font-size: 12px; }
.kv { display: grid; grid-template-columns: minmax(106px, 150px) minmax(0, 1fr); gap: 10px; padding: 4px 0; font-size: 13px; }
.kv .kv-k { color: var(--muted); min-width: 0; padding-top: 1px; }
.kv .kv-v { min-width: 0; color: var(--text); overflow-wrap: anywhere; }
.kv-rank { color: var(--muted); white-space: nowrap; }
.sub-topic { padding: 7px 0 2px; color: var(--muted); font-size: 13px; font-weight: 800; letter-spacing: .04em; text-transform: uppercase; }
.tk-core { font-weight: 800; }
.tk-link { color: var(--link); font-weight: 800; border-bottom: 1px dotted var(--link); }
.tk-link:hover { text-decoration: none; border-bottom-style: solid; }
.kv.warn, .kv.warn .kv-v, .kv.warn .kv-k { color: var(--warn); }
.sector-row { display: grid; grid-template-columns: 190px minmax(0, 1fr); gap: 12px; padding: 6px 0; border-bottom: 1px solid color-mix(in srgb, var(--divider) 65%, transparent); font-size: 13px; }
.sector-row:last-of-type { border-bottom: 0; }
.sector-name { color: var(--muted); }
.sector-codes { color: var(--text); overflow-wrap: anywhere; }

#portfolio-content, #alerts-content, #case-board-content { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 12px; }
#portfolio-content .feed-card, #alerts-content .feed-card, #case-board-content .feed-card { margin: 0; }

/* Macro / Bối cảnh thị trường — chia 2 cột sections khi ≥640px để khỏi kéo dọc */
.macro-sections { display: grid; gap: 16px 28px; grid-template-columns: 1fr; }
.macro-section { min-width: 0; }
.macro-section > .topic { margin-bottom: 6px; }
@media (min-width: 640px) {
  .macro-sections { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 390px) {
  .macro-section { padding-bottom: 2px; border-bottom: 1px solid color-mix(in srgb, var(--divider) 50%, transparent); }
  .macro-section:last-child { border-bottom: 0; padding-bottom: 0; }
}
#strategy-content { padding: 4px 0 0; }
.strategy-subhead { margin: 15px 0 7px; color: var(--accent); font-size: 12px; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; }
.strategy-list { margin: 0 0 10px; padding-left: 20px; }
.strategy-item { margin-bottom: 6px; color: var(--text); font-size: 13px; }
.strategy-decision { margin: 4px 0; color: var(--good); font-size: 13px; }
.strategy-meta { margin-top: 10px; color: var(--muted); font-size: 11px; }
.inline-code { padding: 1px 5px; background: var(--surface-3); border-radius: 5px; color: var(--accent); font-size: 12px; }

.prov { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 10px; padding-top: 9px; border-top: 1px solid var(--divider); color: var(--muted); font-size: 12px; }
.prov a { color: var(--muted); border-bottom: 1px dotted var(--faint); }
.prov a:hover { color: var(--link); border-bottom-color: var(--link); }
.prov-meta { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; min-width: 0; }
.badge { font-size: 10px; font-weight: 800; white-space: nowrap; }
.badge-fresh { color: var(--good); }
.badge-stale { color: var(--bad); }
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table-scroll table { min-width: 360px; border-collapse: collapse; font-size: 14.5px; }
.table-scroll th { padding: 8px; border-bottom: 1px solid var(--divider); color: var(--muted); font-size: 11px; font-weight: 800; text-align: left; }
.table-scroll td { padding: 9px 8px; border-bottom: 1px solid var(--divider); color: var(--text); vertical-align: top; }
.align-center { text-align: center !important; }
.table-ticker { color: var(--accent) !important; font-weight: 800; }
.changed-chip { color: var(--warn); font-size: 10px; font-weight: 800; }
.empty { padding: 12px 0; color: var(--muted); font-size: 14px; font-style: italic; }
.empty::before { content: '— '; color: var(--faint); font-style: normal; }
.site-footer { margin-top: 18px; color: var(--faint); font-size: 11px; text-align: center; }

/* Overview (/): domain cards điểm vào */
.domain-grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); }
.domain-card { min-width: 0; display: block; padding: 18px; background: var(--surface); border: 1px solid var(--divider); border-radius: 16px; box-shadow: var(--shadow); color: var(--text); transition: border-color 0.15s ease, transform 0.15s ease; }
@media (hover: hover) { .domain-card:hover { border-color: var(--accent); text-decoration: none; transform: translateY(-1px); } }
.domain-card.primary { border-color: color-mix(in srgb, var(--accent) 42%, var(--divider)); }
.domain-card .dc-name { color: var(--accent); font-size: 17px; font-weight: 800; }
.domain-card .dc-desc { color: var(--muted); font-size: 13px; margin-top: 4px; }
.domain-card .dc-status { margin-top: 10px; font-size: 11px; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; }
.domain-card .dc-status.live { color: var(--good); }
.domain-card .dc-status.shell { color: var(--warn); }
.domain-card .dc-meta { margin-top: 8px; color: var(--faint); font-size: 12px; }

/* Shell pages (life-os/agent-os): khung cơ bản */
.shell-block { padding: 26px 22px; text-align: center; }
.shell-block .shell-icon { font-size: 34px; margin-bottom: 8px; }
.shell-block .shell-title { font-size: 18px; font-weight: 800; margin: 0 0 6px; }
.shell-block .shell-note { color: var(--muted); font-size: 13px; margin: 0 0 18px; }
.shell-actions { display: flex; justify-content: center; gap: 10px; flex-wrap: wrap; }

@media (max-width: 720px) {
  .site-header, .dashboard-main, .site-footer { width: min(100% - 24px, 680px); }
  .site-header { padding-top: 16px; }
  .brand-block, .dashboard-section { padding: 16px; border-radius: 14px; }
  .page-title { font-size: 29px; }
  .dashboard-main { gap: 12px; }
  .section-kicker { font-size: 16px; }
  .sector-row { grid-template-columns: 125px minmax(0, 1fr); gap: 8px; }
}
@media (max-width: 390px) {
  .site-header, .dashboard-main, .site-footer { width: calc(100% - 20px); }
  .brand-block, .dashboard-section { padding: 13px; }
  .kv { grid-template-columns: 92px minmax(0, 1fr); gap: 7px; font-size: 14.5px; }
  .summary { font-size: 15px; }
  .snapshot-chip { width: 100%; justify-content: space-between; }
  .header-snapshot { grid-template-columns: 1fr; }
  .sub-topic { font-size: 12px; }
  .prov { font-size: 11px; }
}
