:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f9fafb;
  --border: #e5e7eb;
  --text: #111827;
  --text-2: #374151;
  --muted: #6b7280;
  --faint: #9ca3af;
  --accent: #2563eb;
  --accent-soft: #eff4ff;

  --sidebar: #0f172a;
  --sidebar-hover: #1e293b;
  --sidebar-active: #1e293b;
  --sidebar-text: #cbd5e1;
  --sidebar-muted: #64748b;

  --s-hi: #047857;   --s-hi-bg: #d1fae5;   /* từ 8 điểm */
  --s-mid: #059669;  --s-mid-bg: #ecfdf5;  /* 7 điểm */
  --s-low: #b45309;  --s-low-bg: #fef3c7;  /* 5–6 điểm */
  --s-none: #6b7280; --s-none-bg: #f3f4f6;

  --ok: #047857;
  --bad: #b91c1c;
  --warn: #b45309;

  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05);
  --sidebar-w: 248px;
  color-scheme: light;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

button, input, select, textarea { font: inherit; color: inherit; }

button {
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 8px;
  padding: 6px 12px;
  font-weight: 500;
}
button:hover { background: var(--surface-2); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover { background: #1d4ed8; }
button.danger { color: var(--bad); }
button.ghost { border-color: transparent; background: none; }
button.ghost:hover { background: var(--surface-2); }
button.link { border: 0; background: none; padding: 0; color: var(--accent); font-weight: 400; }
button.link:hover { text-decoration: underline; background: none; }
button:disabled { opacity: .55; cursor: default; }

input[type=text], input[type=password], input[type=search], input[type=url], select, textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 10px;
  background: var(--surface);
}
textarea { min-height: 120px; resize: vertical; line-height: 1.6; }
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* Ô mật khẩu có nút con mắt ẩn/hiện */
.pw-wrap { position: relative; display: block; flex: 1; min-width: 0; }
.pw-wrap input { padding-right: 40px; }
.pw-wrap > .pw-eye {
  position: absolute; right: 4px; top: 50%; transform: translateY(-50%);
  width: auto; margin: 0;
  border: 0; background: none; padding: 4px 6px; border-radius: 6px;
  color: var(--muted); display: grid; place-items: center;
}
.pw-wrap > .pw-eye:hover { color: var(--text); background: var(--surface-2); }

label { display: block; font-weight: 600; font-size: 13px; margin: 12px 0 4px; }
.hint { color: var(--muted); font-size: 13px; font-weight: 400; }
.msg { font-size: 13px; }
.msg.error { color: var(--bad); }
.msg.success { color: var(--ok); }

/* =========================================================
   Khung ứng dụng: menu trái + nội dung
   ========================================================= */
body.app { display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); min-height: 100vh; }

.sidebar {
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
  background: var(--sidebar); color: var(--sidebar-text);
  display: flex; flex-direction: column;
  padding: 18px 12px;
}
.sidebar .brand { display: flex; align-items: center; gap: 10px; padding: 0 10px 18px; color: #fff; }
.sidebar .brand:hover { text-decoration: none; }
.sidebar .brand img { width: 28px; height: 28px; }
.sidebar .brand b { display: block; font-size: 16px; line-height: 1.2; }
.sidebar .brand span { display: block; font-size: 12px; color: var(--sidebar-muted); }

.nav-section { margin-top: 14px; }
.nav-section > .title {
  font-size: 11px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase;
  color: var(--sidebar-muted); padding: 0 10px 6px;
}
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 7px 10px; border-radius: 8px;
  color: var(--sidebar-text); font-size: 14px;
}
.nav-item:hover { background: var(--sidebar-hover); color: #fff; text-decoration: none; }
.nav-item.active { background: var(--sidebar-active); color: #fff; font-weight: 600; }
.nav-item .ico { width: 18px; text-align: center; opacity: .8; flex-shrink: 0; }
.nav-item .label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-item .badge {
  font-size: 11px; font-weight: 600; color: var(--sidebar-text);
  background: #334155; border-radius: 999px; padding: 0 7px; line-height: 18px;
}
.dot { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; display: inline-block; }

.sidebar .spacer { flex: 1; }
.sidebar .user {
  border-top: 1px solid #1e293b; margin-top: 14px; padding: 12px 10px 0;
  display: flex; align-items: center; gap: 10px; font-size: 13px;
}
.sidebar .user .avatar {
  width: 30px; height: 30px; border-radius: 50%; background: #334155; color: #fff;
  display: grid; place-items: center; font-weight: 700; font-size: 13px; flex-shrink: 0;
}
.sidebar .user .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; color: #fff; }
.sidebar .user .role { color: var(--sidebar-muted); font-size: 12px; }
.sidebar .user button { color: var(--sidebar-text); border-color: #334155; background: none; padding: 4px 8px; font-size: 12px; }
.sidebar .user button:hover { background: var(--sidebar-hover); }

.main { min-width: 0; display: flex; flex-direction: column; }

.pagebar {
  display: flex; align-items: center; gap: 16px;
  padding: 18px 28px; background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 5;
}
.pagebar h1 { font-size: 20px; margin: 0; letter-spacing: -.01em; }
.pagebar .sub { color: var(--muted); font-size: 13px; }
.pagebar .titles { flex: 1; min-width: 0; }
.pagebar .actions { display: flex; gap: 10px; align-items: center; }
.pagebar .actions input[type=search] { width: 260px; }
.menu-btn { display: none; }
.clock { text-align: right; line-height: 1.25; font-variant-numeric: tabular-nums; white-space: nowrap; }
.clock b { display: block; font-size: 18px; letter-spacing: .02em; }
.clock span { font-size: 12px; color: var(--muted); }

.content { padding: 24px 28px 48px; }

/* =========================================================
   Thành phần chung
   ========================================================= */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.card-head {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 18px; border-bottom: 1px solid var(--border);
}
.card-head h2, .card-head h3 { margin: 0; font-size: 15px; flex: 1; min-width: 0; }
.card-body { padding: 16px 18px; }

.section-title { display: flex; align-items: baseline; gap: 10px; margin: 28px 0 12px; }
.section-title h2 { font-size: 16px; margin: 0; }

.score {
  display: inline-grid; place-items: center; flex-shrink: 0;
  min-width: 26px; height: 22px; padding: 0 5px; border-radius: 6px;
  font-size: 12px; font-weight: 700;
  background: var(--s-none-bg); color: var(--s-none);
}
.score.hi { background: var(--s-hi-bg); color: var(--s-hi); }
.score.mid { background: var(--s-mid-bg); color: var(--s-mid); }
.score.low { background: var(--s-low-bg); color: var(--s-low); }

.tag {
  display: inline-block; font-size: 12px; color: var(--text-2); background: var(--surface-2);
  border: 1px solid var(--border); border-radius: 6px; padding: 0 7px; line-height: 20px;
}
.pill { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }

.segmented { display: inline-flex; background: #eceef1; border-radius: 9px; padding: 3px; flex-shrink: 0; }
.segmented button { border: 0; background: none; border-radius: 7px; padding: 5px 14px; color: var(--text-2); font-weight: 500; }
.segmented button:hover { background: rgba(255,255,255,.6); }
.segmented button.active { background: var(--surface); color: var(--text); font-weight: 600; box-shadow: 0 1px 2px rgba(0,0,0,.08); }
.segmented .count { color: var(--muted); font-weight: 400; margin-left: 5px; font-size: 12px; }

.empty { text-align: center; color: var(--muted); padding: 36px 12px; }

/* =========================================================
   Trang Tổng quan
   ========================================================= */
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; }
.kpi { padding: 16px 18px; }
.kpi .k-label { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.kpi .k-value { font-size: 30px; font-weight: 700; letter-spacing: -.02em; margin: 4px 0 2px; }
.kpi .k-foot { font-size: 12px; color: var(--muted); }
.kpi .k-foot.bad { color: var(--bad); }

.overview-row { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: 16px; margin-top: 16px; }

.digest-card .card-body ul { margin: 0; padding-left: 18px; }
.digest-card .card-body li { margin: 6px 0; color: var(--text-2); }

.bars { list-style: none; margin: 0; padding: 0; }
.bars li { display: grid; grid-template-columns: minmax(0, 1fr) 40px; gap: 4px 10px; align-items: center; margin-bottom: 12px; }
.bars li:last-child { margin-bottom: 0; }
.bars .b-name { display: flex; align-items: center; gap: 8px; font-size: 13px; min-width: 0; }
.bars .b-name a { color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bars .b-num { text-align: right; font-weight: 600; font-size: 13px; }
.bars .b-track { grid-column: 1 / -1; height: 6px; background: #eef0f3; border-radius: 99px; overflow: hidden; }
.bars .b-fill { height: 100%; border-radius: 99px; }

.board { display: grid; grid-template-columns: repeat(auto-fit, minmax(290px, 1fr)); gap: 16px; }
.board .card { display: flex; flex-direction: column; }
.board .card-head .count { font-size: 12px; color: var(--muted); }
.board ul { list-style: none; margin: 0; padding: 4px 0; flex: 1; }
.board li { display: flex; gap: 10px; padding: 10px 18px; border-bottom: 1px solid #f1f2f4; }
.board li:last-child { border-bottom: 0; }
.board li .t { min-width: 0; flex: 1; }
.board li a.title {
  color: var(--text); font-weight: 500; line-height: 1.4;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.board li a.title:hover { color: var(--accent); text-decoration: none; }
.board li .m { font-size: 12px; color: var(--muted); margin-top: 2px; }
.board .card-foot { padding: 10px 18px; border-top: 1px solid var(--border); font-size: 13px; }

/* =========================================================
   Danh sách tin (Nổi bật / Tất cả / theo chủ đề)
   ========================================================= */
.list-layout { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 24px; align-items: start; }
.list-tools { display: flex; gap: 12px; align-items: center; margin-bottom: 16px; flex-wrap: wrap; }
.list-tools input[type=search] { max-width: 320px; }
.rail { position: sticky; top: 92px; display: flex; flex-direction: column; gap: 16px; }

.day {
  font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .05em;
  margin: 22px 0 10px;
}
.day:first-child { margin-top: 0; }

.article {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px 18px; margin-bottom: 10px;
  display: flex; gap: 14px;
}
.article .a-body { flex: 1; min-width: 0; }
.article h3 { font-size: 15px; margin: 0 0 4px; line-height: 1.45; font-weight: 600; }
.article h3 a { color: var(--text); }
.article h3 a:hover { color: var(--accent); text-decoration: none; }
.article .summary { margin: 0 0 8px; color: var(--text-2); }
.article .meta { font-size: 12px; color: var(--muted); display: flex; flex-wrap: wrap; align-items: center; gap: 4px 0; }
.article .meta > * + *::before { content: "·"; margin: 0 8px; color: #d1d5db; }
.article .meta .topic { display: inline-flex; align-items: center; gap: 5px; }
.article .meta button.link { font-size: 12px; font-weight: 600; }
.article .dups { margin: 8px 0 0; padding-left: 18px; font-size: 13px; }
.article .dups li { margin: 2px 0; }
.analysis { margin-top: 12px; padding: 14px 16px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; }
.analysis .note { font-size: 12px; color: var(--muted); margin-top: 10px; }

.more { display: block; margin: 16px auto; }

/* =========================================================
   Văn bản Markdown (phân tích)
   ========================================================= */
.md { font-size: 14px; line-height: 1.65; }
.md h3 { font-size: 16px; margin: 22px 0 8px; }
.md h4 { font-size: 15px; margin: 16px 0 6px; }
.md > :first-child { margin-top: 0; }
.md p { margin: 8px 0; }
.md ul, .md ol { margin: 8px 0; padding-left: 22px; }
.md li { margin: 5px 0; }
.md a.ref { font-size: 11px; font-weight: 700; vertical-align: super; line-height: 0; padding: 0 1px; }

/* =========================================================
   Trang Phân tích
   ========================================================= */
.digest-layout { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 24px; align-items: start; }
.digest-doc { padding: 28px 34px; }
.digest-doc h1 { font-size: 24px; margin: 0 0 4px; letter-spacing: -.01em; }
.digest-doc .sub { color: var(--muted); font-size: 13px; margin-bottom: 20px; }
.digest-doc .sources { margin-top: 28px; padding-top: 14px; border-top: 1px solid var(--border); font-size: 13px; }
.digest-doc .sources ol { padding-left: 22px; margin: 8px 0 0; color: var(--text-2); }
.digest-doc .sources li { margin: 3px 0; }
.digest-list { list-style: none; margin: 0; padding: 6px; }
.digest-list a { display: block; padding: 8px 12px; border-radius: 8px; color: var(--text-2); }
.digest-list a:hover { background: var(--surface-2); text-decoration: none; }
.digest-list a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.digest-list .when { display: block; font-size: 12px; color: var(--muted); font-weight: 400; }

/* =========================================================
   Trang Cài đặt
   ========================================================= */
.tabs-line { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 22px; overflow-x: auto; }
.tabs-line a {
  padding: 10px 14px; color: var(--muted); font-weight: 600; border-bottom: 2px solid transparent;
  margin-bottom: -1px; white-space: nowrap;
}
.tabs-line a:hover { color: var(--text); text-decoration: none; }
.tabs-line a.active { color: var(--text); border-bottom-color: var(--accent); }

.toolbar { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.toolbar .grow { flex: 1; min-width: 200px; }
.toolbar p { margin: 0; }

.watch-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 16px; }
.watch-card { padding: 16px 18px; display: flex; flex-direction: column; gap: 10px; }
.watch-card.off { opacity: .6; }
.watch-card .w-head { display: flex; align-items: center; gap: 10px; }
.watch-card .w-head b { font-size: 15px; flex: 1; min-width: 0; }
.watch-card .chips { display: flex; flex-wrap: wrap; gap: 6px; }
.watch-card .chips .tag.ex { color: var(--bad); }
.watch-card .note { color: var(--muted); font-size: 13px; }
.watch-card .w-foot { display: flex; gap: 8px; margin-top: auto; padding-top: 6px; }

.table-card { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 11px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
th { font-size: 12px; color: var(--muted); font-weight: 600; background: var(--surface-2); }
td .sub { font-size: 12px; color: var(--muted); }
td.actions { white-space: nowrap; text-align: right; }
td.actions button { margin-left: 6px; }
.status { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; }
.status .dot { width: 8px; height: 8px; }
.status.ok { color: var(--ok); }   .status.ok .dot { background: var(--ok); }
.status.bad { color: var(--bad); } .status.bad .dot { background: var(--bad); }
.status.off { color: var(--muted); } .status.off .dot { background: var(--faint); }

.stats-inline { display: flex; gap: 18px; flex-wrap: wrap; font-size: 13px; color: var(--muted); }
.stats-inline b { color: var(--text); }

.two-col { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; align-items: start; }
.sys-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 16px; }
.sys-grid .card-body p { margin: 0 0 8px; }
code.cmd { display: block; background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; font-size: 12px; overflow-x: auto; white-space: pre; }

pre.report { background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; font-size: 12px; white-space: pre-wrap; margin: 12px 0 0; }

/* Cửa sổ nổi để thêm/sửa */
dialog {
  border: 0; border-radius: 14px; padding: 0; width: min(640px, calc(100vw - 32px));
  box-shadow: 0 20px 50px rgba(15, 23, 42, .25);
}
dialog::backdrop { background: rgba(15, 23, 42, .45); }
dialog .d-head { padding: 16px 22px; border-bottom: 1px solid var(--border); display: flex; align-items: center; }
dialog .d-head h3 { margin: 0; font-size: 16px; flex: 1; }
dialog .d-body { padding: 6px 22px 18px; max-height: calc(100vh - 200px); overflow-y: auto; }
dialog .d-foot { padding: 14px 22px; border-top: 1px solid var(--border); display: flex; gap: 8px; align-items: center; justify-content: flex-end; }
dialog .d-foot .msg { flex: 1; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.form-grid .full { grid-column: 1 / -1; }
.check { display: flex; align-items: center; gap: 8px; font-weight: 400; margin-top: 14px; }

/* =========================================================
   Đăng nhập
   ========================================================= */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; background: var(--sidebar); }
.login-box { width: 100%; max-width: 380px; background: var(--surface); border-radius: 16px; padding: 30px 28px; }
.login-box h1 { font-size: 21px; margin: 0 0 4px; }
.login-box p { color: var(--muted); margin: 0 0 14px; font-size: 14px; }
.login-box button[type="submit"] { width: 100%; margin-top: 18px; padding: 9px; }

/* =========================================================
   Màn hình nhỏ
   ========================================================= */
@media (max-width: 1200px) {
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .list-layout, .digest-layout { grid-template-columns: minmax(0, 1fr); }
  .rail { position: static; }
}
@media (max-width: 900px) {
  body.app { grid-template-columns: minmax(0, 1fr); }
  .sidebar { position: fixed; z-index: 20; left: 0; top: 0; width: 270px; transform: translateX(-100%); transition: transform .2s; }
  body.nav-open .sidebar { transform: none; box-shadow: 0 0 40px rgba(0,0,0,.35); }
  .menu-btn { display: inline-block; }
  .pagebar { padding: 12px 16px; flex-wrap: wrap; }
  .pagebar .actions { width: 100%; }
  .clock b { font-size: 15px; }
  .pagebar .actions input[type=search] { width: 100%; }
  .content { padding: 16px 14px 40px; }
  .overview-row, .two-col { grid-template-columns: minmax(0, 1fr); }
  .board { grid-template-columns: minmax(0, 1fr); }
  .form-grid { grid-template-columns: 1fr; }
  .digest-doc { padding: 18px; }
}
@media (max-width: 520px) {
  .kpis { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 10px; }
  .kpi .k-value { font-size: 24px; }
}
