:root {
  --fjord: #14324A;      /* xanh vịnh hẹp – màu chủ đạo */
  --fjord-2: #1E4A6B;
  --paper: #F5F7F8;
  --surface: #FFFFFF;
  --ink: #1B2329;
  --muted: #5F6B74;
  --line: #DDE3E7;
  --lacquer: #A3242A;    /* đỏ sơn mài – chỉ dùng cho tin quan hệ Việt Nam */
  --brass: #9A7632;      /* đồng thau – số liệu */
  --brass-bg: #F6EFE0;
  --focus: #2F7FBF;
  --ui: 'Be Vietnam Pro', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --read: 'Source Serif 4', Georgia, 'Times New Roman', serif;
  --r-sm: 6px; --r-md: 10px;
}
@media (prefers-color-scheme: dark) {
  :root { --paper: #0F1A22; --surface: #15232E; --ink: #E4EAEE; --muted: #93A1AB; --line: #263744; --fjord: #8DB8D8; --fjord-2: #A9CBE4; --brass: #D3AE62; --brass-bg: #2A2416; --lacquer: #E06A6F; }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font: 15px/1.5 var(--ui); color: var(--ink); background: var(--paper); -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
[hidden] { display: none !important; }

/* ---------- Nút & điều khiển ---------- */
.btn { border: 1px solid var(--line); background: var(--surface); padding: 8px 14px; border-radius: var(--r-sm); cursor: pointer; font-weight: 500; white-space: nowrap; }
.btn:hover { border-color: var(--fjord); }
.btn.primary { background: var(--fjord); color: #fff; border-color: var(--fjord); }
@media (prefers-color-scheme: dark) { .btn.primary { color: #0F1A22; } }
.btn.primary:hover { background: var(--fjord-2); }
.btn.small { padding: 5px 10px; font-size: 13px; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn:disabled { opacity: .55; cursor: progress; }
input, select, textarea { border: 1px solid var(--line); background: var(--surface); border-radius: var(--r-sm); padding: 8px 10px; min-width: 0; }
textarea { width: 100%; resize: vertical; font-family: var(--read); }
label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); font-weight: 500; }
label small { font-weight: 400; }
label.check { flex-direction: row; align-items: center; gap: 8px; color: var(--ink); }
.chip { border: 1px solid var(--line); background: transparent; border-radius: 999px; padding: 4px 12px; font-size: 13px; cursor: pointer; }
.chip.active { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: var(--r-sm); overflow: hidden; }
.seg button { border: 0; background: var(--surface); padding: 7px 12px; cursor: pointer; font-size: 13px; border-right: 1px solid var(--line); }
.seg button:last-child { border-right: 0; }
.seg button.active { background: var(--fjord); color: #fff; }
.row { display: flex; gap: 10px; align-items: flex-end; }
.row.wrap { flex-wrap: wrap; }

/* ---------- Đăng nhập ---------- */
.login { min-height: 100%; display: grid; place-items: center; padding: 24px; background: var(--fjord); }
.login-card { background: var(--surface); padding: 36px 32px; border-radius: var(--r-md); width: min(380px, 100%); display: flex; flex-direction: column; gap: 14px; }
.login-card h1 { margin: 6px 0 0; font: 600 28px/1.1 var(--read); }
.login-card p { margin: 0; color: var(--muted); }
.err { color: var(--lacquer); min-height: 1.2em; }

/* ---------- Khung ứng dụng (desktop: 3 cột) ---------- */
.app { display: grid; grid-template-columns: 248px 1fr; height: 100vh; height: 100dvh; }
.rail { background: var(--fjord); color: #DCE7EF; display: flex; flex-direction: column; padding: 20px 14px; gap: 18px; overflow-y: auto; }
@media (prefers-color-scheme: dark) { .rail { background: #0B141A; } }
.brand { display: flex; gap: 10px; align-items: center; padding: 0 6px; color: inherit; text-decoration: none; border-radius: var(--r-sm); }
.brand:hover strong { text-decoration: underline; }
.brand:focus-visible { outline: 2px solid var(--focus); outline-offset: 3px; }
.brand strong { display: block; color: #fff; font-size: 17px; }
.brand span { font-size: 11.5px; opacity: .75; }
.brand-mark { width: 36px; height: 36px; border-radius: 9px; background: #F5F7F8; color: #14324A; display: grid; place-items: center; font: 700 20px var(--read); flex: none; }
.brand-mark.big { width: 52px; height: 52px; font-size: 30px; background: var(--fjord); color: #fff; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: var(--r-sm); cursor: pointer; color: inherit; text-decoration: none; }
.nav a:hover { background: rgba(255,255,255,.08); }
.nav a.active { background: rgba(255,255,255,.14); color: #fff; font-weight: 600; }
.logout { margin-top: auto; color: #B9CAD6 !important; align-self: flex-start; }

/* Lịch nhỏ */
.cal { background: rgba(255,255,255,.06); border-radius: var(--r-md); padding: 10px; font-size: 12px; }
.cal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; color: #fff; font-weight: 600; }
.cal-head button { background: none; border: 0; color: inherit; cursor: pointer; padding: 2px 8px; font-size: 16px; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; text-align: center; }
.cal-grid .wd { opacity: .55; font-size: 10.5px; padding: 2px 0; }
.cal-grid button { background: none; border: 0; color: inherit; padding: 5px 0; border-radius: 5px; cursor: pointer; position: relative; font-size: 12px; }
.cal-grid button.has::after { content: ''; position: absolute; left: 50%; bottom: 1px; width: 4px; height: 4px; margin-left: -2px; border-radius: 50%; background: #E8C77A; }
.cal-grid button.sel { background: #F5F7F8; color: #14324A; font-weight: 700; }
.cal-grid button.today { outline: 1px solid rgba(255,255,255,.5); }
.cal-grid button:disabled { opacity: .3; cursor: default; }

.main { overflow: hidden; min-width: 0; }
.view { display: grid; grid-template-columns: minmax(360px, 440px) 1fr; height: 100%; }
.pane { overflow-y: auto; min-width: 0; }
.list-pane { border-right: 1px solid var(--line); background: var(--surface); }
.pane.wide { grid-column: 1 / -1; padding: 28px clamp(18px, 4vw, 56px) 80px; max-width: 1100px; }
.view-title { font: 600 26px/1.2 var(--read); margin: 0 0 18px; }
.sub { font-size: 15px; margin: 34px 0 12px; padding-top: 18px; border-top: 1px solid var(--line); }

/* Đầu trang ngày – yếu tố nhận diện: ngày tháng lớn bằng chữ có chân */
.day-head { padding: 22px 20px 14px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--surface); z-index: 2; }
.day-title { display: flex; align-items: center; gap: 14px; }
.day-num { font: 600 52px/0.9 var(--read); color: var(--fjord); letter-spacing: -0.02em; font-variant-numeric: lining-nums; }
.day-week { font-weight: 600; font-size: 15px; }
.day-count { color: var(--muted); font-size: 13px; }
.auto-note { color: var(--muted); font-size: 12.5px; margin: 8px 0 0; }
.day-actions { display: flex; gap: 8px; margin-top: 14px; }
.day-actions input { flex: 1; }
.progress { margin-top: 12px; font-size: 12.5px; color: var(--muted); }
.bar { height: 4px; background: var(--line); border-radius: 2px; overflow: hidden; margin-bottom: 6px; }
.bar i { display: block; height: 100%; width: 5%; background: var(--fjord); transition: width .4s; }

.digest { margin: 14px 20px 4px; border: 1px solid var(--line); border-radius: var(--r-md); background: var(--paper); }
.digest summary { padding: 12px 14px; cursor: pointer; font-weight: 600; display: flex; justify-content: space-between; align-items: baseline; gap: 10px; list-style: none; }
.digest summary::-webkit-details-marker { display: none; }
.digest summary::after { content: '+'; color: var(--muted); font-weight: 400; }
.digest[open] summary::after { content: '–'; }
.digest summary small { color: var(--muted); font-weight: 400; margin-left: auto; }
.digest-tools { display: flex; gap: 6px; padding: 0 14px 10px; }
.digest .prose { padding: 0 16px 16px; font-size: 15px; }

.filters { display: flex; gap: 6px; padding: 14px 20px 6px; flex-wrap: wrap; }

/* Danh sách tin */
.items { list-style: none; margin: 0; padding: 6px 0 80px; }
.item { padding: 14px 20px 14px 22px; border-bottom: 1px solid var(--line); cursor: pointer; position: relative; }
.item:hover { background: var(--paper); }
.item.sel { background: var(--paper); }
.item.sel::before { content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--fjord); }
.item.vn::after { content: ''; position: absolute; left: 8px; top: 20px; width: 6px; height: 6px; border-radius: 50%; background: var(--lacquer); }
.item h4 { margin: 0 0 4px; font: 600 16px/1.35 var(--read); }
.item .orig { color: var(--muted); font-size: 12.5px; margin: 0 0 6px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.meta { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 12px; color: var(--muted); align-items: center; }
.cat { font-weight: 600; color: var(--fjord); }
.badge { font-size: 11px; padding: 1px 7px; border-radius: 4px; background: var(--paper); border: 1px solid var(--line); }
.badge.warn { color: var(--lacquer); border-color: currentColor; background: transparent; }
.empty { padding: 40px 24px; color: var(--muted); text-align: center; }
.empty strong { display: block; color: var(--ink); font-size: 16px; margin-bottom: 6px; }

/* Khung đọc */
.reader-pane { background: var(--paper); }
.reader { max-width: 780px; margin: 0 auto; padding: 30px clamp(18px, 4vw, 48px) 100px; }
.reader .back { display: none; }
.reader h1 { font: 600 clamp(22px, 2.4vw, 30px)/1.25 var(--read); margin: 8px 0 6px; }
.reader .orig-title { color: var(--muted); font: italic 16px/1.4 var(--read); margin: 0 0 14px; }
.reader .src-line { display: flex; flex-wrap: wrap; gap: 8px 14px; align-items: center; font-size: 13px; color: var(--muted); padding-bottom: 16px; border-bottom: 1px solid var(--line); }
.reader .src-line a { color: var(--fjord); font-weight: 600; }
.tabs { display: flex; gap: 2px; margin: 18px 0 0; border-bottom: 1px solid var(--line); overflow-x: auto; position: sticky; top: 0; background: var(--paper); z-index: 1; }
.tabs button { background: none; border: 0; padding: 10px 14px; cursor: pointer; color: var(--muted); font-weight: 500; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tabs button.active { color: var(--ink); border-bottom-color: var(--fjord); }
.tab-tools { display: flex; justify-content: flex-end; gap: 6px; margin: 14px 0 6px; }
.prose { font: 17px/1.7 var(--read); max-width: 70ch; }
.prose p { margin: 0 0 .9em; }
.prose h3 { font: 600 17px/1.4 var(--ui); margin: 1.2em 0 .5em; }
.prose ul { padding-left: 1.2em; }
.tin-a { background: var(--surface); border: 1px solid var(--line); border-left: 3px solid var(--fjord); border-radius: var(--r-sm); padding: 18px 20px; }
.figs { list-style: none; padding: 0; margin: 0; display: grid; gap: 10px; }
.figs li { background: var(--brass-bg); border-radius: var(--r-sm); padding: 12px 14px; }
.figs .v { font: 600 19px/1.3 var(--read); color: var(--brass); display: block; }
.figs .c { display: block; margin: 2px 0 4px; }
.figs .s { font-size: 12.5px; color: var(--muted); }
.reason { font-size: 13px; color: var(--muted); margin-top: 28px; padding-top: 12px; border-top: 1px dashed var(--line); }

/* Chủ đề */
.topic-form { display: grid; grid-template-columns: 1fr auto auto; gap: 12px; align-items: end; background: var(--surface); padding: 18px; border: 1px solid var(--line); border-radius: var(--r-md); }
.topic-form .grow { grid-column: 1 / -1; }
.topic-form .check { grid-column: 1 / 3; }
.topic-result { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); padding: 22px 26px; margin-top: 18px; }
.topic-result .head { display: flex; justify-content: space-between; gap: 10px; align-items: baseline; margin-bottom: 12px; color: var(--muted); font-size: 13px; }
.topic-result .refs { font-size: 13px; color: var(--muted); margin-top: 18px; padding-left: 1.4em; }
.topic-result .refs a { color: var(--fjord); }
.history { list-style: none; padding: 0; margin: 0; }
.history li { padding: 10px 0; border-bottom: 1px solid var(--line); cursor: pointer; display: flex; justify-content: space-between; gap: 12px; font-size: 14px; }
.history li small { color: var(--muted); white-space: nowrap; }

/* Tìm kiếm */
.search-head { padding: 22px 20px 14px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--surface); z-index: 2; }
.search-form { display: flex; flex-direction: column; gap: 10px; }
.search-form .seg { align-self: flex-start; flex-wrap: wrap; }
.custom-range { display: flex; gap: 6px; align-items: center; }

/* Cài đặt */
.settings { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 16px; }
.settings .full { grid-column: 1 / -1; }
.saved { font-size: 13px; color: var(--muted); align-self: center; }
.mode-pick { border: 1px solid var(--line); border-radius: var(--r-md); padding: 12px 14px; display: grid; gap: 10px; margin: 0; min-width: 0; }
.mode-pick legend { font-weight: 600; color: var(--ink); padding: 0 6px; }
.mode-pick label.mode { flex-direction: row; align-items: flex-start; gap: 10px; padding: 10px; border-radius: var(--r-sm); cursor: pointer; color: var(--ink); }
.mode-pick label.mode:has(input:checked) { background: var(--paper); outline: 1px solid var(--fjord); }
.mode-pick label.mode input { margin-top: 3px; flex: none; }
.mode-pick label.mode > span { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.mode-pick label.mode small { color: var(--muted); }
.mode-pick label.mode .row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.mode-pick em { font-style: normal; font-size: 12px; }.mode-pick em.ok { color: var(--muted); }
.mode-pick em.missing { color: var(--lacquer); }
.table-wrap { overflow-x: auto; }
.sources { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.sources th, .sources td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
.sources th { color: var(--muted); font-weight: 500; }
.sources td.err { color: var(--lacquer); font-size: 12px; max-width: 280px; }
.add-src { margin-top: 12px; }
.add-src input { flex: 1; min-width: 160px; }

.tabbar { display: none; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); background: var(--ink); color: var(--paper); padding: 10px 16px; border-radius: var(--r-sm); opacity: 0; pointer-events: none; transition: .25s; z-index: 50; font-size: 14px; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Máy tính bảng ---------- */
@media (max-width: 1180px) and (min-width: 821px) {
  .app { grid-template-columns: 76px 1fr; }
  .rail { padding: 16px 8px; align-items: center; }
  .brand div:last-child, .nav span, .cal, .logout { display: none; }
  .nav a { justify-content: center; }
}

/* ---------- Di động: một cột, thanh tab dưới, khung đọc trượt toàn màn hình ---------- */
@media (max-width: 820px) {
  body { font-size: 15.5px; }
  .app { display: block; height: auto; min-height: 100dvh; padding-bottom: calc(64px + env(safe-area-inset-bottom)); }
  .rail { display: none; }
  .main { overflow: visible; }
  .view { display: block; height: auto; }
  .list-pane { border: 0; }
  .pane { overflow: visible; }
  .day-head, .search-head { padding: calc(14px + env(safe-area-inset-top)) 16px 12px; }
  .day-num { font-size: 44px; }
  .digest { margin: 12px 16px 4px; }
  .filters { padding: 12px 16px 4px; overflow-x: auto; flex-wrap: nowrap; }
  .chip { flex: none; }
  .item { padding: 14px 16px 14px 20px; }
  .item.vn::after { left: 7px; }
  .reader-pane { position: fixed; inset: 0; z-index: 30; overflow-y: auto; transform: translateX(100%); transition: transform .28s ease; display: block !important; padding-bottom: env(safe-area-inset-bottom); }
  .reader-pane.open { transform: none; }
  .reader { padding: calc(10px + env(safe-area-inset-top)) 18px 60px; }
  .reader .back { display: inline-flex; align-items: center; gap: 4px; position: sticky; top: 0; background: var(--paper); border: 0; padding: 10px 0; font-weight: 600; color: var(--fjord); cursor: pointer; z-index: 2; width: 100%; }
  .tabs { top: 42px; }
  .prose { font-size: 17px; }
  .pane.wide { padding: calc(18px + env(safe-area-inset-top)) 16px 40px; }
  .topic-form { grid-template-columns: 1fr 1fr; }
  .topic-form .check, .topic-form button { grid-column: 1 / -1; }
  .tabbar { display: grid; grid-template-columns: repeat(4, 1fr); position: fixed; left: 0; right: 0; bottom: 0; background: var(--surface); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); z-index: 20; }
  .tabbar a { display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 11px; padding: 8px 0 7px; color: var(--muted); cursor: pointer; }
  .tabbar a.active { color: var(--fjord); font-weight: 600; }
  .toast { bottom: calc(80px + env(safe-area-inset-bottom)); }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
