:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #e2e5ea;
  --text: #1a1d23;
  --muted: #646b78;
  --accent: #2b7de9;
  --accent-text: #ffffff;
  --ok: #1f9d55;
  --ok-bg: #e5f6ec;
  --warn: #b26b00;
  --warn-bg: #fff3dc;
  --bad: #d23f3f;
  --bad-bg: #fde9e9;
  --info-bg: #e7f0fd;
  --bubble: #ffffff;
  --bubble-border: #dfe3e8;
  --link: #2b7de9;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.05), 0 1px 3px rgba(16, 24, 40, 0.06);
  --ch-ai-tools: #7c4dff;
  --ch-free-software: #1f9d55;
  --ch-github-gems: #24292f;
  --ch-ai-automation: #e8590c;
  --ch-saas-deals: #0b7fa8;
  --radius: 10px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111317;
    --surface: #1a1d23;
    --surface-2: #22262e;
    --border: #2d323c;
    --text: #e8eaee;
    --muted: #9aa1ad;
    --accent: #4c95f5;
    --accent-text: #0b1220;
    --ok: #3ccf7f;
    --ok-bg: #12301f;
    --warn: #f0b04a;
    --warn-bg: #352710;
    --bad: #ff7272;
    --bad-bg: #3a1717;
    --info-bg: #15243b;
    --bubble: #212630;
    --bubble-border: #2f3542;
    --link: #6fb0ff;
    --shadow: none;
    --ch-ai-tools: #a98bff;
    --ch-free-software: #3ccf7f;
    --ch-github-gems: #c9d1d9;
    --ch-ai-automation: #ff8a4c;
    --ch-saas-deals: #3bb9e0;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #111317;
  --surface: #1a1d23;
  --surface-2: #22262e;
  --border: #2d323c;
  --text: #e8eaee;
  --muted: #9aa1ad;
  --accent: #4c95f5;
  --accent-text: #0b1220;
  --ok: #3ccf7f;
  --ok-bg: #12301f;
  --warn: #f0b04a;
  --warn-bg: #352710;
  --bad: #ff7272;
  --bad-bg: #3a1717;
  --info-bg: #15243b;
  --bubble: #212630;
  --bubble-border: #2f3542;
  --link: #6fb0ff;
  --shadow: none;
  --ch-ai-tools: #a98bff;
  --ch-free-software: #3ccf7f;
  --ch-github-gems: #c9d1d9;
  --ch-ai-automation: #ff8a4c;
  --ch-saas-deals: #3bb9e0;
  color-scheme: dark;
}
:root[data-theme="light"] { color-scheme: light; }

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

a { color: var(--link); }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h2 { font-size: 16px; }
h3 { font-size: 14px; }

/* ---------- Khung trang ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  padding: 16px 24px 12px;
  max-width: 1200px;
  margin: 0 auto;
}
.brand { display: flex; align-items: center; gap: 12px; }
.logo { width: 36px; height: 36px; color: var(--accent); display: block; }
.logo svg { width: 100%; height: 100%; display: block; }
.brand h1 { font-size: 18px; }
.sub { margin: 2px 0 0; color: var(--muted); font-size: 12px; }

.status-pills { display: flex; gap: 6px; flex-wrap: wrap; }

.tabs {
  display: flex;
  gap: 4px;
  padding: 0 24px;
  max-width: 1200px;
  margin: 0 auto;
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
}
.tabs a {
  padding: 10px 14px;
  color: var(--muted);
  text-decoration: none;
  font-weight: 500;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 6px;
}
.tabs a:hover { color: var(--text); }
.tabs a.active { color: var(--accent); border-bottom-color: var(--accent); }
.count {
  background: var(--bad);
  color: #fff;
  border-radius: 999px;
  font-size: 11px;
  padding: 0 7px;
  line-height: 18px;
  font-weight: 600;
}

main { max-width: 1200px; margin: 0 auto; padding: 20px 24px 64px; }

/* ---------- Thành phần chung ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.card-pad { padding: 16px; }
.section { margin-bottom: 24px; }
.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 12px; }
.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.spacer { flex: 1; }
.empty {
  padding: 40px 16px;
  text-align: center;
  color: var(--muted);
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  font-weight: 500;
  padding: 2px 9px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  white-space: nowrap;
}
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.pill.plain::before { display: none; }
.pill.ok { background: var(--ok-bg); color: var(--ok); }
.pill.warn { background: var(--warn-bg); color: var(--warn); }
.pill.bad { background: var(--bad-bg); color: var(--bad); }
.pill.info { background: var(--info-bg); color: var(--accent); }

.channel-tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-weight: 600;
  font-size: 12px;
  color: var(--ch, var(--text));
}
.channel-tag::before { content: ""; width: 8px; height: 8px; border-radius: 2px; background: var(--ch, var(--muted)); }
[data-ch="ai-tools"] { --ch: var(--ch-ai-tools); }
[data-ch="free-software"] { --ch: var(--ch-free-software); }
[data-ch="github-gems"] { --ch: var(--ch-github-gems); }
[data-ch="ai-automation"] { --ch: var(--ch-ai-automation); }
[data-ch="saas-deals"] { --ch: var(--ch-saas-deals); }

button, .btn {
  font: inherit;
  font-weight: 500;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 8px;
  padding: 6px 12px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 32px;
}
button:hover:not(:disabled) { background: var(--surface-2); }
button:disabled { opacity: 0.5; cursor: not-allowed; }
a.btn { text-decoration: none; }
button.primary, .btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
button.primary:hover:not(:disabled) { filter: brightness(1.08); background: var(--accent); }
button.ok { color: var(--ok); }
button.danger { color: var(--bad); }
button.ghost { border-color: transparent; background: transparent; }
button:focus-visible, a:focus-visible, select:focus-visible, input:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

select, input[type="search"], input[type="text"], input[type="password"], input[type="number"], textarea {
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 10px;
  min-height: 32px;
}
textarea { width: 100%; resize: vertical; font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 13px; }

.spinner {
  width: 14px;
  height: 14px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Tổng quan ---------- */
.setup { border-color: var(--warn); background: var(--warn-bg); }
.setup h2 { color: var(--warn); margin-bottom: 8px; }
.setup ol { margin: 0; padding-left: 20px; }
.setup li { margin: 4px 0; }
.setup code { background: var(--surface); padding: 1px 5px; border-radius: 4px; font-size: 12px; }

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; }
.tile { padding: 14px 16px; }
.tile .label { color: var(--muted); font-size: 12px; }
.tile .value { font-size: 28px; font-weight: 650; font-variant-numeric: tabular-nums; margin-top: 2px; }
.tile .hint { font-size: 12px; color: var(--muted); }
a.tile { text-decoration: none; color: inherit; display: block; }
a.tile:hover { border-color: var(--accent); }

.jobs { display: grid; gap: 0; }
.job {
  display: grid;
  grid-template-columns: minmax(160px, 1.2fr) 2fr auto;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
}
.job:first-child { border-top: 0; }
.job .name { font-weight: 600; }
.job .err { color: var(--bad); font-size: 12px; }

.channels { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(210px, 100%), 1fr)); gap: 12px; }
.channel-card { padding: 14px 16px; border-top: 3px solid var(--ch); }
.channel-card .stats { display: flex; gap: 14px; margin: 10px 0 8px; }
.channel-card .stats div { display: flex; flex-direction: column; }
.channel-card .stats b { font-size: 18px; font-variant-numeric: tabular-nums; }
.channel-card .stats span { font-size: 11px; color: var(--muted); }

.config-list { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 0; }
.config-list dt { color: var(--muted); }
.config-list dd { margin: 0; }

/* ---------- Bài viết ---------- */
.filters { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.chip {
  border-radius: 999px;
  padding: 4px 12px;
  min-height: 30px;
  font-size: 13px;
}
.chip.active { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.chip .n { opacity: 0.75; font-variant-numeric: tabular-nums; }

.post-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(360px, 100%), 1fr)); gap: 14px; align-items: start; }
.post { display: flex; flex-direction: column; overflow: hidden; position: relative; min-width: 0; }
.post-head { display: flex; align-items: center; gap: 8px; padding: 12px 14px 0; flex-wrap: wrap; }
.post-head .id { color: var(--muted); font-size: 12px; }
.post-body { padding: 10px 14px; display: grid; gap: 10px; }
.note { font-size: 12px; padding: 8px 10px; border-radius: 8px; background: var(--warn-bg); color: var(--warn); }
.note.bad { background: var(--bad-bg); color: var(--bad); }
.note.info { background: var(--info-bg); color: var(--accent); }

.tg {
  background: var(--bubble);
  border: 1px solid var(--bubble-border);
  border-radius: 12px 12px 12px 4px;
  padding: 10px 12px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-size: 14px;
  line-height: 1.45;
}
.tg a { color: var(--link); }
.tg code, .tg pre { font-family: ui-monospace, Consolas, monospace; font-size: 13px; }

.meta { display: flex; gap: 6px 12px; flex-wrap: wrap; font-size: 12px; color: var(--muted); }
.meta a { color: var(--muted); }
.post-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  padding: 10px 14px;
  border-top: 1px solid var(--border);
  background: var(--surface-2);
  margin-top: auto;
}
.editor { display: grid; gap: 8px; }
.editor .bar { display: flex; align-items: center; gap: 8px; }
.inline-form { display: flex; gap: 6px; width: 100%; }
.inline-form input { flex: 1; min-width: 0; }

.busy-overlay {
  position: absolute;
  inset: 0;
  background: color-mix(in srgb, var(--surface) 80%, transparent);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-weight: 600;
  color: var(--accent);
}

/* ---------- Lịch đăng ---------- */
.day { margin-bottom: 18px; }
.day h3 { margin-bottom: 8px; color: var(--muted); font-weight: 600; text-transform: capitalize; }
.slot {
  display: grid;
  grid-template-columns: 64px 190px 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 10px 14px;
  border-top: 1px solid var(--border);
}
.slot:first-child { border-top: 0; }
.slot .time { font-weight: 650; font-variant-numeric: tabular-nums; }
.slot .title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- Tin thu thập ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 12px; border-top: 1px solid var(--border); vertical-align: top; }
th { font-size: 12px; color: var(--muted); font-weight: 600; border-top: 0; white-space: nowrap; }
td.num { text-align: right; font-variant-numeric: tabular-nums; }
td .title-link { font-weight: 500; color: var(--text); text-decoration: none; }
td .title-link:hover { color: var(--link); text-decoration: underline; }
td .reason { font-size: 12px; color: var(--warn); margin-top: 2px; }
td .snippet { font-size: 12px; color: var(--muted); margin-top: 2px; max-width: 520px; }
td.nowrap, .row.nowrap { white-space: nowrap; flex-wrap: nowrap; }
td select { font-size: 13px; max-width: 190px; }
.pager { display: flex; align-items: center; gap: 10px; justify-content: flex-end; padding: 10px 12px; border-top: 1px solid var(--border); }

/* ---------- Cài đặt ---------- */
.settings-card { margin-bottom: 20px; }
.settings-card > header { padding: 14px 16px; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.settings-card > header p { margin: 0; flex-basis: 100%; }
.settings-body { padding: 16px; display: grid; gap: 16px; max-width: 760px; }
.settings-actions { padding: 12px 16px; border-top: 1px solid var(--border); background: var(--surface-2); display: flex; gap: 8px; flex-wrap: wrap; border-radius: 0 0 var(--radius) var(--radius); }
.field { display: grid; gap: 4px; }
.field-label { font-weight: 600; }
.field-hint { font-size: 12px; color: var(--muted); }
.field-row { display: flex; gap: 8px; align-items: center; }
.field-row input[type="text"], .field-row input[type="password"], .field-row select { flex: 1; min-width: 0; }
.field-row input[type="number"] { width: 100px; }
.channel-fields { display: grid; gap: 10px; }
.channel-fields .field { grid-template-columns: 200px 1fr; align-items: center; gap: 8px; }
.check { display: flex; gap: 8px; align-items: flex-start; }
.check input { margin-top: 3px; }
details.help { background: var(--surface-2); border-radius: 8px; padding: 10px 12px; }
details.help summary { cursor: pointer; font-weight: 600; }
details.help ol { margin: 8px 0 0; padding-left: 20px; }
details.help li { margin: 4px 0; }
.results { display: grid; gap: 6px; padding: 12px 16px; border-top: 1px solid var(--border); }
.result-row { display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; }
.result-row .pill { flex: none; }
.state-line { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* Nút cạnh từng ô channel */
.channel-fields .field-row { flex-wrap: wrap; }
.channel-fields .field-row input[type="text"] { min-width: 160px; }
.slot-btn { padding: 4px 10px; min-height: 32px; font-size: 13px; white-space: nowrap; }

/* Kết nối AI */
.conn { display: grid; gap: 8px; padding: 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); margin-bottom: 8px; }
.conn-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

/* Kết nối Telegram và channel phát hiện */
.live-box { display: grid; gap: 10px; }
.approver, .detected {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  flex-wrap: wrap;
}
.approver-main { flex: 1; min-width: 160px; }
.avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--surface-2);
  display: grid;
  place-items: center;
  font-size: 18px;
}
.detected-controls { display: flex; gap: 6px; align-items: center; margin-left: auto; flex-wrap: nowrap; }
.detected select { min-width: 180px; max-width: 100%; }
.pair-panel {
  display: flex;
  gap: 16px;
  padding: 14px;
  border: 1px solid var(--accent);
  border-radius: 10px;
  background: var(--info-bg);
  flex-wrap: wrap;
}
.pair-qr { background: #fff; padding: 6px; border-radius: 8px; image-rendering: pixelated; flex: none; }
.pair-steps { flex: 1; min-width: 220px; display: grid; gap: 8px; align-content: start; }
.pair-steps ol { margin: 0; padding-left: 20px; }
.pair-steps li { margin: 2px 0; }

/* ---------- Thông báo ---------- */
.toasts { position: fixed; bottom: 16px; right: 16px; display: grid; gap: 8px; z-index: 10; max-width: calc(100vw - 32px); }
.toast {
  background: var(--text);
  color: var(--bg);
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 13px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
  animation: rise 0.18s ease-out;
}
.toast.bad { background: var(--bad); color: #fff; }
@keyframes rise { from { transform: translateY(8px); opacity: 0; } }

@media (max-width: 720px) {
  .topbar, .tabs, main { padding-left: 16px; padding-right: 16px; }
  .post-list { grid-template-columns: 1fr; }
  .job { grid-template-columns: 1fr; gap: 6px; }
  .slot { grid-template-columns: 56px 1fr; }
  .slot .title { grid-column: 1 / -1; white-space: normal; }
  .slot .actions { grid-column: 1 / -1; }
  .channel-fields .field { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  .spinner, .toast { animation: none; }
}

/* ---------- Đăng xuất + đổi mật khẩu ---------- */
.topbar-right { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.logout svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.security-form { display: grid; gap: 14px; max-width: 460px; }
.strength { display: flex; align-items: center; gap: 10px; min-height: 18px; }
.strength-bars { display: flex; gap: 4px; flex: 1; max-width: 200px; }
.strength-bar { height: 6px; flex: 1; border-radius: 3px; background: var(--border); transition: background 0.15s; }
.strength-bar.on.weak { background: var(--bad); }
.strength-bar.on.fair { background: var(--warn); }
.strength-bar.on.good { background: var(--accent); }
.strength-bar.on.strong { background: var(--ok); }
.bad-text { color: var(--bad); }
.ok-text { color: var(--ok); }
.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0, 0, 0, 0); border: 0; }


/* =====================================================================
   Giao diện v2: biểu tượng, quy trình, nhật ký, lịch dạng lưới, di động
   ===================================================================== */
.ico { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* ---------- Thanh trên cùng ---------- */
.icon-btn { padding: 0; width: 34px; height: 34px; min-height: 0; justify-content: center; color: var(--muted); }
.icon-btn:hover:not(:disabled) { color: var(--text); }
#bellBtn.on { color: var(--accent); background: var(--info-bg); }
.live {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 5px 12px;
  border-radius: 999px;
  background: var(--info-bg);
  color: var(--accent);
  text-decoration: none;
  font-size: 13px;
  max-width: min(420px, 100%);
}
.live .live-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text); opacity: 0.75; }
.logout .ico { width: 16px; height: 16px; }

/* ---------- Thanh tab ---------- */
.tabs a .ico { width: 16px; height: 16px; }
.tabs a { position: relative; }

/* ---------- Khung chờ khi tải ---------- */
.skeleton {
  background: linear-gradient(90deg, var(--surface-2) 25%, var(--border) 37%, var(--surface-2) 63%);
  background-size: 400% 100%;
  animation: shimmer 1.4s ease infinite;
  border-radius: var(--radius);
}
.skeleton-page { display: grid; gap: 16px; }
.sk-wide { height: 56px; }
.sk-wide.tall { height: 220px; }
.skeleton-row { display: grid; grid-template-columns: repeat(6, 1fr); gap: 12px; }
.sk-card { height: 110px; }
@keyframes shimmer { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }

/* ---------- Checklist thiết lập ---------- */
details.setup { padding: 0; }
details.setup > summary { list-style: none; cursor: pointer; padding: 12px 16px; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
details.setup > summary::-webkit-details-marker { display: none; }
details.setup > summary::after { content: "▾"; margin-left: auto; color: var(--warn); }
details.setup:not([open]) > summary::after { content: "▸"; }
.setup-title { font-weight: 700; color: var(--warn); font-size: 15px; }
.setup-bar { flex: 1; min-width: 80px; max-width: 220px; }
.setup-list { list-style: none; margin: 0; padding: 0 16px 8px; display: grid; gap: 10px; }
.setup-list li { display: flex; gap: 10px; align-items: flex-start; margin: 0; }
.setup-mark { width: 20px; height: 20px; border-radius: 50%; border: 2px solid var(--warn); display: grid; place-items: center; flex: none; margin-top: 1px; color: #fff; }
.setup-list li.done .setup-mark { background: var(--ok); border-color: var(--ok); }
.setup-list li.done .setup-mark .ico { width: 12px; height: 12px; stroke-width: 3; }
.setup-list li.done b { text-decoration: line-through; color: var(--muted); font-weight: 500; }
.setup-foot { padding: 4px 16px 14px; }

/* ---------- Dải quy trình ---------- */
.pipeline { padding: 0; overflow: hidden; }
.stages { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); }
.stage {
  position: relative;
  display: grid;
  gap: 2px;
  padding: 14px 16px 12px;
  text-decoration: none;
  color: inherit;
  border-left: 1px solid var(--border);
  transition: background 0.15s;
}
.stage:first-child { border-left: 0; }
.stage:hover { background: var(--surface-2); }
.stage:not(:last-child)::after {
  content: "";
  position: absolute;
  right: -6px;
  top: 50%;
  width: 11px;
  height: 11px;
  border-top: 1px solid var(--border);
  border-right: 1px solid var(--border);
  background: var(--surface);
  transform: translateY(-50%) rotate(45deg);
  z-index: 1;
}
.stage-ico { width: 32px; height: 32px; border-radius: 10px; display: grid; place-items: center; background: var(--surface-2); color: var(--muted); margin-bottom: 6px; }
.stage-ico .ico { width: 17px; height: 17px; }
.stage-label { font-size: 12px; color: var(--muted); font-weight: 600; }
.stage-value { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.15; }
.stage-hint { font-size: 12px; color: var(--muted); min-height: 18px; }
.stage.running { background: var(--info-bg); }
.stage.running .stage-ico { background: var(--accent); color: var(--accent-text); animation: pulse 1.6s ease-in-out infinite; }
.stage.running .stage-value { color: var(--accent); }
.stage.blocked .stage-ico, .stage.attention .stage-ico { background: var(--warn-bg); color: var(--warn); }
.stage.attention .stage-value { color: var(--warn); }
.stage.blocked .stage-value { color: var(--muted); }
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent) 45%, transparent); }
  50% { box-shadow: 0 0 0 7px transparent; }
}

.now { border-top: 1px solid var(--border); padding: 10px 16px; background: var(--surface-2); display: grid; gap: 8px; }
.now-row { display: grid; grid-template-columns: auto auto minmax(80px, 240px) minmax(0, 1fr); align-items: center; gap: 10px; }
.now-text { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.now-idle { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.dot-idle { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); }
.progress { height: 8px; border-radius: 999px; background: var(--border); overflow: hidden; position: relative; min-width: 60px; }
.progress-fill { height: 100%; background: var(--accent); border-radius: inherit; transition: width 0.4s ease; }
.progress.indeterminate .progress-fill { width: 40%; animation: slide 1.2s ease-in-out infinite; }
@keyframes slide { 0% { margin-left: -40%; } 100% { margin-left: 100%; } }
.job .progress { margin-bottom: 6px; }

/* ---------- Bố cục Tổng quan ---------- */
.overview-grid { display: grid; grid-template-columns: minmax(0, 1.7fr) minmax(0, 1fr); gap: 20px; align-items: start; }
.section-head.spaced { margin-top: 18px; }

/* ---------- Nhật ký hoạt động ---------- */
.feed { display: grid; overflow: hidden; }
.event { display: grid; grid-template-columns: 32px minmax(0, 1fr) auto; gap: 12px; padding: 11px 14px; border-top: 1px solid var(--border); align-items: start; }
.event:first-child { border-top: 0; }
.ev-ico { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; background: var(--surface-2); color: var(--muted); }
.ev-ico .ico { width: 15px; height: 15px; }
.ev-ico.ok { background: var(--ok-bg); color: var(--ok); }
.ev-ico.info { background: var(--info-bg); color: var(--accent); }
.ev-ico.warn { background: var(--warn-bg); color: var(--warn); }
.ev-ico.bad { background: var(--bad-bg); color: var(--bad); }
.ev-line { display: flex; gap: 4px 8px; align-items: baseline; flex-wrap: wrap; }
.ev-label { font-size: 12px; color: var(--muted); font-weight: 600; white-space: nowrap; }
.ev-title { font-weight: 500; color: var(--text); text-decoration: none; overflow-wrap: anywhere; }
a.ev-title:hover { color: var(--link); text-decoration: underline; }
.ev-title .ext { width: 12px; height: 12px; margin-left: 4px; opacity: 0.55; vertical-align: -1px; }
.ev-detail { font-size: 12px; color: var(--muted); margin-top: 2px; overflow-wrap: anywhere; }
.ev-time { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.day-title { margin: 0; padding: 10px 14px 6px; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; background: var(--surface-2); border-top: 1px solid var(--border); font-weight: 600; }
.feed-full .day-title:first-child { border-top: 0; }
.empty-inline { text-align: center; padding: 28px 16px; }

/* ---------- Thẻ channel ---------- */
.slot-chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0 8px; }
.slot-chip { display: inline-flex; align-items: center; gap: 4px; padding: 3px 8px; border-radius: 999px; font-size: 12px; font-variant-numeric: tabular-nums; border: 1px solid var(--border); color: var(--text); }
.slot-chip .ico { width: 12px; height: 12px; stroke-width: 2.4; }
.slot-chip.posted { background: var(--ok-bg); color: var(--ok); border-color: transparent; }
.slot-chip.scheduled { background: var(--info-bg); color: var(--accent); border-color: transparent; }
.slot-chip.failed { background: var(--bad-bg); color: var(--bad); border-color: transparent; }
.slot-chip.missed { color: var(--muted); border-style: dashed; opacity: 0.75; }
.ch-today { font-size: 12px; color: var(--muted); }
.ch-today b { color: var(--text); font-variant-numeric: tabular-nums; }
.ch-next { font-size: 12px; margin-bottom: 2px; }

/* ---------- Biểu đồ 7 ngày ---------- */
.daily { display: grid; grid-template-columns: repeat(7, 1fr); gap: 8px; height: 130px; }
.dbar { display: flex; flex-direction: column; align-items: center; gap: 4px; height: 100%; min-width: 0; }
.dbar-n { font-size: 12px; font-variant-numeric: tabular-nums; color: var(--muted); }
.dbar-col { flex: 1; width: 100%; display: flex; align-items: flex-end; background: var(--surface-2); border-radius: 6px; overflow: hidden; }
.dbar-fill { width: 100%; background: color-mix(in srgb, var(--accent) 50%, transparent); border-radius: 6px 6px 0 0; min-height: 2px; transition: height 0.4s ease; }
.dbar.today .dbar-fill { background: var(--accent); }
.dbar-l { font-size: 11px; color: var(--muted); }
.dbar.today .dbar-l { color: var(--text); font-weight: 600; }

/* ---------- Bài viết ---------- */
.post-check { width: 18px; height: 18px; margin: 0; flex: none; }
.post.selected { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.post.cursor { outline: 2px solid var(--accent); outline-offset: 2px; }
.bulk {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  padding: 8px 12px;
  margin-bottom: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  position: sticky;
  top: 8px;
  z-index: 5;
}
.bulk.active { border-color: var(--accent); background: var(--info-bg); }
.bulk .keys { margin-left: auto; }
.tg-msg { display: grid; gap: 6px; }
.tg-from { display: flex; align-items: center; gap: 8px; font-weight: 600; color: var(--ch, var(--accent)); font-size: 13px; }
.tg-avatar { width: 24px; height: 24px; border-radius: 50%; background: var(--ch, var(--accent)); color: #fff; display: grid; place-items: center; font-size: 12px; flex: none; }
.src-title { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-style: italic; }
.empty-actions { margin-top: 14px; }
.row.center { justify-content: center; }

/* ---------- Lịch dạng lưới ---------- */
.g-grid { display: grid; grid-template-columns: repeat(var(--cols), minmax(150px, 1fr)); min-width: 780px; }
.g-col { border-left: 1px solid var(--border); display: grid; align-content: start; }
.g-col:first-child { border-left: 0; }
.g-head { padding: 8px 10px; font-weight: 600; font-size: 12px; border-top: 3px solid var(--ch); border-bottom: 1px solid var(--border); background: var(--surface-2); display: flex; gap: 6px; align-items: center; }
.g-head .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ch); flex: none; }
.g-cell { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 2px 8px; padding: 8px 10px; border-top: 1px solid var(--border); min-height: 54px; align-items: center; }
.g-time { font-variant-numeric: tabular-nums; font-weight: 650; font-size: 12px; }
.g-none { font-size: 12px; color: var(--muted); }
.g-cell.empty.past { opacity: 0.5; }
.g-cell.filled { background: color-mix(in srgb, var(--ch) 9%, var(--surface)); box-shadow: inset 3px 0 0 var(--ch); }
.g-title { font-size: 12px; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.g-actions { grid-column: 1 / -1; display: flex; gap: 4px; }
.g-actions .icon-btn { width: 26px; height: 26px; border-color: var(--border); }
.g-actions .icon-btn .ico { width: 14px; height: 14px; }

/* ---------- Màn hình vừa và nhỏ ---------- */
@media (max-width: 1000px) {
  .stages { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .stage:nth-child(3n + 1) { border-left: 0; }
  .stage:nth-child(n + 4) { border-top: 1px solid var(--border); }
  .stage::after { display: none; }
  .overview-grid { grid-template-columns: 1fr; }
}

@media (max-width: 720px) {
  .topbar-right { width: 100%; }
  .logout span { display: none; }
  .skeleton-row { grid-template-columns: repeat(2, 1fr); }
  .stages { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stage:nth-child(3n + 1) { border-left: 1px solid var(--border); }
  .stage:nth-child(2n + 1) { border-left: 0; }
  .stage:nth-child(n + 3) { border-top: 1px solid var(--border); }
  .now-row { grid-template-columns: auto 1fr; }
  .now-row .now-bar, .now-row .now-text { grid-column: 1 / -1; }
  .event { grid-template-columns: 32px minmax(0, 1fr); }
  .ev-time { grid-column: 2; }
  .bulk .keys { display: none; }

  /* Thanh tab chuyển xuống đáy màn hình như một ứng dụng di động */
  .tabs {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 20;
    max-width: none;
    margin: 0;
    padding: 0 2px env(safe-area-inset-bottom);
    background: var(--surface);
    border-top: 1px solid var(--border);
    border-bottom: 0;
    gap: 0;
    overflow: visible;
  }
  .tabs a {
    flex: 1;
    flex-direction: column;
    justify-content: center;
    gap: 2px;
    padding: 8px 2px 6px;
    margin: 0;
    font-size: 10.5px;
    border-bottom: 0;
    border-top: 2px solid transparent;
    min-width: 0;
  }
  .tabs a span:not(.count) { overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
  .tabs a.active { border-top-color: var(--accent); }
  .tabs a .ico { width: 20px; height: 20px; }
  .tabs a .count { position: absolute; top: 3px; left: 54%; font-size: 10px; line-height: 15px; padding: 0 5px; }
  main { padding-bottom: 92px; }
  .toasts { bottom: 76px; }
}
.live b { white-space: nowrap; }
@media (max-width: 720px) {
  .status-pills { display: none; }
  .topbar-right { justify-content: flex-end; }
  .live { flex: 1; }
}
