:root {
  --bg: #eef2f6;
  --panel: #fff;
  --text: #142033;
  --muted: #667085;
  --line: #d5deea;
  --brand: #1264d8;
  --ok: #078a49;
  --warn: #a15c00;
  --danger: #b42318;
  font-family: Arial, Helvetica, sans-serif;
}
* { box-sizing: border-box; }
html, body { max-width: 100%; overflow-x: hidden; }
main,
header,
.panel,
.panel > *,
.panel-head,
.split > *,
.api-grid > *,
.campaign-grid > *,
.campaign-results > *,
.notice-grid > *,
.form-grid > *,
.send-grid > *,
.mini-grid > * {
  min-width: 0;
}
body { margin: 0; background: var(--bg); color: var(--text); }
aside {
  position: fixed; inset: 0 auto 0 0; width: 250px; padding: 22px;
  background: #0f172a; color: white; display: grid; align-content: start; gap: 18px;
}
.brand { display: grid; grid-template-columns: 44px 1fr; gap: 12px; align-items: center; padding-bottom: 14px; border-bottom: 1px solid rgba(255,255,255,.12); }
.brand-mark { display: grid; place-items: center; width: 44px; height: 44px; border-radius: 8px; background: #e0f2fe; color: #075985; font-weight: 900; }
.brand strong { display: block; font-size: 20px; }
.brand small { display: block; color: #a7b2c5; margin-top: 3px; }
.side-nav { display: grid; gap: 8px; }
aside a { color: #dbeafe; text-decoration: none; padding: 10px 12px; border-radius: 7px; font-weight: 700; }
aside a:hover, aside a.active { background: rgba(255,255,255,.1); color: #fff; }
main { margin-left: 250px; padding: 24px; }
header, .panel, .metrics div { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 8px 24px rgba(15,23,42,.06); }
header { display: flex; justify-content: space-between; align-items: center; padding: 22px; margin-bottom: 16px; }
h1, h2, h3, p { margin-top: 0; }
.eyebrow { color: var(--brand); font-weight: 800; text-transform: uppercase; font-size: 12px; letter-spacing: .04em; }
.warning { border: 1px solid #ffd7a8; background: #fff7ed; color: #9a3412; padding: 12px 14px; border-radius: 8px; margin-bottom: 16px; }
.toast {
  position: fixed; top: 18px; right: 18px; z-index: 20; max-width: min(420px, calc(100vw - 32px));
  padding: 12px 14px; border-radius: 8px; border: 1px solid var(--line); background: #fff;
  box-shadow: 0 12px 34px rgba(15,23,42,.18); font-weight: 800;
}
.toast[hidden], .notice[hidden], #qrImage[hidden] { display: none !important; }
.toast.success { border-color: #abe6c8; background: #ecfdf3; color: var(--ok); }
.toast.error { border-color: #fecdca; background: #fef3f2; color: var(--danger); }
.toast.warning { border-color: #fedf89; background: #fffaeb; color: var(--warn); }
.view[hidden] { display: none !important; }
.home-view { display: grid; gap: 16px; }
.market-hero {
  display: grid; grid-template-columns: minmax(0, 1fr) 420px; gap: 18px; align-items: stretch;
  min-height: 330px; padding: 0; overflow: hidden; background: #101827; border-color: #1f2f46; color: white;
}
.hero-main { display: grid; align-content: center; padding: 34px 36px; }
.hero-kicker { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 18px; }
.hero-kicker span, .hero-kicker b {
  display: inline-flex; align-items: center; min-height: 28px; padding: 0 10px; border: 1px solid rgba(255,255,255,.18);
  border-radius: 7px; color: #bfdbfe; font-size: 12px; letter-spacing: .08em;
}
.market-hero h1 { font-size: clamp(42px, 5vw, 74px); line-height: .94; margin-bottom: 16px; max-width: 900px; }
.hero-copy { color: #cbd5e1; font-size: 17px; line-height: 1.55; max-width: 760px; }
.hero-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 18px; }
.hero-actions .secondary { background: rgba(255,255,255,.1); color: white; }
.signal-board { margin: 22px; padding: 18px; border: 1px solid rgba(255,255,255,.14); border-radius: 8px; background: rgba(15,23,42,.82); align-self: stretch; display: grid; align-content: center; gap: 10px; }
.signal-head { border-bottom: 1px solid rgba(255,255,255,.14); padding-bottom: 12px; margin-bottom: 4px; }
.signal-head span, .market-tape span, .module-feature span, .module-card span, .board-title span, .plan-panel > span { color: #60a5fa; text-transform: uppercase; font-size: 12px; font-weight: 900; letter-spacing: .08em; }
.signal-head strong { display: block; font-size: 26px; margin-top: 8px; }
.signal-row { display: flex; justify-content: space-between; align-items: center; min-height: 42px; border-bottom: 1px solid rgba(255,255,255,.1); color: #cbd5e1; }
.signal-row b { color: white; font-size: 18px; }
.market-tape { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 8px; }
.market-tape span { display: grid; place-items: center; min-height: 42px; border: 1px solid var(--line); border-radius: 7px; background: white; color: #1d4ed8; }
.ops-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
.ops-card, .module-card, .forum-main, .plan-panel { border: 1px solid var(--line); border-radius: 8px; background: #fff; box-shadow: 0 8px 24px rgba(15,23,42,.05); }
.ops-card { padding: 16px; }
.ops-card small { color: var(--muted); font-weight: 800; }
.ops-card strong { display: block; font-size: 34px; margin: 8px 0 4px; }
.ops-card span { color: var(--muted); }
.module-board { display: grid; grid-template-columns: 1.25fr 1fr 1fr; gap: 14px; }
.module-feature, .module-card { min-height: 190px; padding: 20px; text-align: left; }
.module-feature { border: 1px solid #1f2f46; border-radius: 8px; background: #0f172a; color: white; }
.module-feature strong, .module-card strong { display: block; font-size: 24px; margin: 10px 0; }
.module-feature small { display: block; color: #cbd5e1; line-height: 1.5; max-width: 680px; }
.module-feature b { display: inline-flex; margin-top: 18px; min-height: 34px; align-items: center; padding: 0 12px; border-radius: 7px; background: #2563eb; color: #fff; }
.module-card small { color: var(--muted); line-height: 1.5; }
.forum-board { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(320px, .7fr); gap: 14px; }
.forum-main, .plan-panel { padding: 18px; }
.board-title { display: flex; align-items: end; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.board-title h2, .plan-panel h2 { margin-bottom: 0; }
.forum-row, .plan-row { display: flex; justify-content: space-between; gap: 16px; padding: 14px 0; border-top: 1px solid var(--line); }
.forum-row div, .plan-row { min-width: 0; }
.forum-row b, .plan-row b { display: block; margin-bottom: 5px; }
.forum-row small, .plan-row small { color: var(--muted); line-height: 1.45; }
.forum-row span { align-self: center; white-space: nowrap; min-height: 28px; padding: 6px 10px; border-radius: 999px; background: #eef2ff; color: #1d4ed8; font-weight: 900; font-size: 12px; }
.plan-panel { display: grid; align-content: start; gap: 10px; }
.plan-row { display: grid; border: 1px solid var(--line); border-radius: 7px; padding: 12px; }
.sub-nav {
  position: sticky; top: 0; z-index: 5; display: flex; flex-wrap: wrap; gap: 8px;
  padding: 10px; margin: -4px 0 16px; border: 1px solid var(--line); border-radius: 8px; background: rgba(248,250,252,.96);
}
.sub-nav a { text-decoration: none; color: #344054; font-weight: 800; background: #fff; border: 1px solid var(--line); padding: 8px 10px; border-radius: 7px; }
.sub-nav a:hover { border-color: var(--brand); color: var(--brand); }
.metrics { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; margin-bottom: 16px; }
.metrics div { padding: 18px; }
.metrics span { display: block; font-size: 28px; font-weight: 800; margin-bottom: 4px; }
.metrics p, .muted { color: var(--muted); margin-bottom: 0; }
.panel { padding: 20px; margin-bottom: 16px; }
.panel-head { display: flex; justify-content: space-between; gap: 16px; margin-bottom: 16px; }
.pill { display: inline-flex; align-items: center; gap: 7px; height: 28px; padding: 0 10px; background: #eef2f6; border-radius: 999px; font-weight: 800; font-size: 12px; }
.pill::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: #94a3b8; }
.pill.success { background: #ecfdf3; color: var(--ok); }
.pill.success::before { background: var(--ok); }
.pill.warning { background: #fffaeb; color: var(--warn); }
.pill.warning::before { background: var(--warn); }
.pill.error { background: #fef3f2; color: var(--danger); }
.pill.error::before { background: var(--danger); }
.notice {
  display: grid; grid-template-columns: 30px 1fr; gap: 10px; align-items: start;
  margin: 12px 0; padding: 12px; border-radius: 8px; border: 1px solid var(--line); background: #f8fafc;
}
.notice::before {
  content: "i"; display: grid; place-items: center; width: 30px; height: 30px; border-radius: 50%;
  background: #e8eef5; color: #344054; font-weight: 900;
}
.notice strong { display: block; margin-bottom: 3px; }
.notice span { color: var(--muted); }
.notice.success { border-color: #abe6c8; background: #ecfdf3; }
.notice.success::before { content: "✓"; background: var(--ok); color: white; }
.notice.error { border-color: #fecdca; background: #fef3f2; }
.notice.error::before { content: "!"; background: var(--danger); color: white; }
.notice.warning { border-color: #fedf89; background: #fffaeb; }
.notice.warning::before { content: "!"; background: var(--warn); color: white; }
.split { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.form-grid, .send-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
label { display: grid; gap: 6px; font-weight: 700; font-size: 13px; color: #344054; }
input, textarea, select { width: 100%; border: 1px solid #cbd5e1; border-radius: 7px; padding: 10px 11px; font: inherit; color: var(--text); }
textarea { min-height: 96px; resize: vertical; }
.wide { grid-column: 1 / -1; }
.check { display: flex; align-items: center; gap: 8px; }
.check input { width: auto; }
button { border: 0; border-radius: 7px; padding: 10px 14px; background: var(--brand); color: white; font-weight: 800; cursor: pointer; }
button.secondary { background: #e8eef5; color: #172033; }
button.danger { background: #fee4e2; color: var(--danger); }
.actions { display: flex; flex-wrap: wrap; gap: 10px; margin: 12px 0; }
#qrImage { display: block; max-width: 260px; border: 1px solid var(--line); border-radius: 8px; padding: 8px; background: white; }
.rule { display: grid; grid-template-columns: 80px 1fr 1fr auto; gap: 10px; margin-bottom: 10px; align-items: end; }
.account-list { display: grid; gap: 8px; margin-top: 10px; max-height: 280px; overflow: auto; }
.account-item { display: grid; grid-template-columns: auto 1fr auto; gap: 10px; align-items: center; border: 1px solid var(--line); border-radius: 8px; padding: 10px; background: #f8fafc; }
.account-item input[type="checkbox"] { width: 18px; height: 18px; }
.account-item strong { display: block; }
.account-item small { display: block; color: var(--muted); margin-top: 3px; }
.campaign-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; align-items: start; }
.campaign-box { border: 1px solid var(--line); border-radius: 8px; padding: 14px; background: #f8fafc; display: grid; gap: 12px; }
.campaign-box h3 { margin-bottom: 0; font-size: 17px; }
.campaign-box textarea { min-height: 150px; background: white; }
.mini-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.campaign-summary { display: grid; grid-template-columns: 2fr repeat(4, 1fr); gap: 10px; margin: 14px 0; }
.campaign-summary div { border: 1px solid var(--line); border-radius: 8px; padding: 12px; background: #fff; }
.campaign-summary strong { display: block; font-size: 18px; margin-bottom: 4px; }
.campaign-summary span { color: var(--muted); font-size: 12px; font-weight: 700; }
.campaign-results { display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(320px, .85fr); gap: 14px; align-items: start; margin-top: 14px; }
.result-panel { border: 1px solid var(--line); border-radius: 8px; padding: 12px; background: #fff; min-width: 0; }
.result-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.result-head.compact { align-items: start; margin-bottom: 8px; }
.result-head h3 { margin: 0; font-size: 16px; }
.result-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.result-actions button { padding: 8px 10px; font-size: 12px; }
.inline-result { border-top: 1px solid var(--line); padding-top: 12px; margin-top: 2px; }
.campaign-log, .campaign-link-list, .campaign-box-list { max-height: 360px; }
.compact-list { max-height: 220px; }
.link-item, .box-item { display: grid; gap: 6px; }
.link-item a, .box-item a { color: var(--brand); font-weight: 800; word-break: break-all; text-decoration: none; }
.link-item a:hover, .box-item a:hover { text-decoration: underline; }
.box-item strong { display: block; }
.api-toolbar { display: grid; grid-template-columns: minmax(220px, 1fr) auto auto auto; gap: 10px; align-items: center; width: min(100%, 900px); }
.api-grid { display: grid; grid-template-columns: minmax(420px, 1.1fr) 1fr; gap: 16px; align-items: start; }
.api-table-wrap { max-height: 560px; overflow: auto; border: 1px solid var(--line); border-radius: 7px; background: #fff; }
.api-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.api-table th, .api-table td { padding: 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
.api-table th { position: sticky; top: 0; background: #f8fafc; z-index: 1; color: #344054; }
.api-table tr { cursor: pointer; }
.api-table tr:hover { background: #f8fafc; }
.api-table tr.active { background: #eaf2ff; }
.api-table input[type="checkbox"] { width: 18px; height: 18px; }
.api-table strong { display: block; }
.api-table small { display: block; margin-top: 3px; color: var(--muted); }
.status-ok { color: var(--ok); font-weight: 800; }
.status-warn { color: var(--warn); font-weight: 800; }
.status-off { color: var(--danger); font-weight: 800; }
pre { white-space: pre-wrap; word-break: break-word; background: #0f172a; color: #dbeafe; padding: 12px; border-radius: 7px; max-height: 420px; overflow: auto; }
.list { display: grid; gap: 8px; max-height: 460px; overflow: auto; }
.list-item { border: 1px solid var(--line); border-radius: 7px; padding: 10px; background: #f8fafc; }
.list-item small { color: var(--muted); display: block; margin-bottom: 6px; }
.list,
.list-item,
.list-item * {
  overflow-wrap: anywhere;
}
.log-head { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; color: var(--muted); font-size: 12px; }
.log-badge { display: inline-flex; align-items: center; gap: 5px; padding: 3px 8px; border-radius: 999px; font-weight: 800; }
.log-badge.success { background: #ecfdf3; color: var(--ok); }
.log-badge.error { background: #fef3f2; color: var(--danger); }
.log-badge.warning { background: #fffaeb; color: var(--warn); }
.log-badge.info { background: #e8eef5; color: #344054; }
.log-extra {
  margin-top: 8px;
}
.log-extra summary {
  cursor: pointer;
  color: var(--brand);
  font-size: 12px;
  font-weight: 800;
}
.log-extra pre {
  margin: 8px 0 0;
  max-height: 220px;
  font-size: 12px;
}
@media (max-width: 900px) {
  aside { position: static; width: auto; }
  main { margin-left: 0; padding: 16px; }
  .market-hero, .module-board, .forum-board { grid-template-columns: 1fr; }
  .signal-board { margin: 16px; }
  .market-tape { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .metrics, .split, .api-grid, .api-toolbar, .form-grid, .send-grid, .rule, .campaign-grid, .campaign-summary, .campaign-results, .mini-grid, .ops-grid { grid-template-columns: 1fr; }
  .api-table-wrap { overflow-x: auto; }
}

.notice-grid { display: grid; grid-template-columns: minmax(360px, .95fr) minmax(420px, 1.05fr); gap: 14px; align-items: start; }
.notice-summary { grid-template-columns: repeat(4, 1fr); }
.notice-box-list .box-select-item { grid-template-columns: auto 1fr; }
.box-select-item { display: grid; grid-template-columns: auto 1fr; gap: 10px; align-items: start; }
.box-select-item input { width: 18px; height: 18px; margin-top: 3px; }
@media (max-width: 900px) { .notice-grid, .notice-summary { grid-template-columns: 1fr; } }

/* Balanced notice module layout */
#thong-bao-box .notice-grid {
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  align-items: stretch;
}
#thong-bao-box .campaign-box {
  min-width: 0;
  height: 100%;
}
#noticeForm {
  display: grid;
  align-content: start;
}
#noticeForm .notice-summary {
  grid-template-columns: repeat(5, minmax(0, 1fr));
}
.notice-phase {
  margin: -4px 0 12px;
  font-weight: 800;
  line-height: 1.45;
  overflow-wrap: anywhere;
}
#noticeLogs {
  max-height: 340px;
}
#noticeBoxList {
  max-height: 640px;
}
#noticeBoxList .list-item,
#noticeLogs .list-item {
  min-width: 0;
}
#noticeBoxList small,
#noticeBoxList strong {
  overflow-wrap: anywhere;
}
@media (max-width: 1100px) {
  #noticeForm .notice-summary {
    grid-template-columns: 1fr;
  }
  #noticeBoxList,
  #noticeLogs {
    max-height: 420px;
  }
}

.invite-box-panel { margin: 14px 0; }
.invite-box-list { max-height: 300px; }
.invite-select-item { display: grid; grid-template-columns: auto 1fr; gap: 10px; align-items: start; }
.invite-select-item input { width: 18px; height: 18px; margin-top: 3px; }
.invite-select-item small { display: block; color: var(--muted); margin-top: 4px; overflow-wrap: anywhere; }

@media (max-width: 900px) {
  aside {
    padding: 14px;
    gap: 12px;
  }
  .brand {
    grid-template-columns: 36px 1fr;
    gap: 10px;
    padding-bottom: 10px;
  }
  .brand-mark {
    width: 36px;
    height: 36px;
  }
  .brand strong {
    font-size: 18px;
  }
  .side-nav {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px;
  }
  aside a {
    padding: 9px 8px;
    text-align: center;
    font-size: 13px;
  }
  main {
    padding: 12px;
  }
  header,
  .panel {
    border-radius: 7px;
  }
  header,
  .panel-head,
  .result-head,
  .board-title {
    display: grid;
    grid-template-columns: 1fr;
    align-items: stretch;
  }
  header,
  .panel {
    padding: 14px;
  }
  .market-hero {
    min-height: 0;
  }
  .hero-main {
    padding: 22px 18px;
  }
  .market-hero h1 {
    font-size: 34px;
    line-height: 1.02;
    max-width: 100%;
  }
  .hero-copy {
    font-size: 15px;
  }
  .signal-board {
    margin: 0 18px 18px;
  }
  .signal-row,
  .forum-row {
    display: grid;
    grid-template-columns: 1fr;
    gap: 6px;
  }
  .forum-row span {
    justify-self: start;
  }
  .sub-nav {
    position: static;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    overflow: visible;
    padding: 8px;
  }
  .sub-nav a {
    display: grid;
    place-items: center;
    min-height: 40px;
    text-align: center;
    white-space: normal;
  }
  .actions,
  .result-actions,
  .hero-actions {
    display: grid;
    grid-template-columns: 1fr;
  }
  button {
    width: 100%;
    min-height: 42px;
  }
  input,
  textarea,
  select {
    font-size: 16px;
    min-width: 0;
  }
  .check {
    align-items: flex-start;
    line-height: 1.45;
  }
  .account-item,
  .rule {
    grid-template-columns: 1fr;
    align-items: stretch;
  }
  .account-item input[type="checkbox"] {
    justify-self: start;
  }
  .campaign-box,
  .result-panel,
  .list-item {
    min-width: 0;
  }
  .campaign-summary,
  #noticeForm .notice-summary {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  #thong-bao-box .notice-grid,
  .notice-grid {
    grid-template-columns: 1fr;
  }
  #noticeBoxList,
  #noticeLogs,
  .campaign-log,
  .campaign-link-list,
  .campaign-box-list,
  .list {
    max-height: 55vh;
  }
  .api-grid {
    grid-template-columns: 1fr;
  }
  .api-toolbar {
    grid-template-columns: 1fr;
    width: 100%;
  }
  .api-table-wrap {
    max-height: 55vh;
    overflow-y: auto;
    overflow-x: hidden;
    border: 0;
    background: transparent;
  }
  .api-table,
  .api-table thead,
  .api-table tbody,
  .api-table tr,
  .api-table th,
  .api-table td {
    display: block;
    width: 100%;
  }
  .api-table thead {
    display: none;
  }
  .api-table tbody {
    display: grid;
    gap: 8px;
  }
  .api-table tr {
    border: 1px solid var(--line);
    border-radius: 7px;
    background: #fff;
    padding: 10px;
  }
  .api-table tr.active {
    background: #eaf2ff;
  }
  .api-table td {
    border-bottom: 0;
    padding: 5px 0;
  }
  .api-table td:first-child {
    display: flex;
    align-items: center;
    gap: 8px;
  }
  .api-table td:first-child::before {
    content: "Bật";
    color: var(--muted);
    font-weight: 800;
    min-width: 86px;
  }
  .api-table td:nth-child(3)::before,
  .api-table td:nth-child(4)::before {
    display: block;
    margin-bottom: 3px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 800;
  }
  .api-table td:nth-child(3)::before {
    content: "Nhóm";
  }
  .api-table td:nth-child(4)::before {
    content: "Trạng thái";
  }
}

@media (max-width: 520px) {
  main {
    padding: 10px;
  }
  .panel,
  header {
    padding: 12px;
  }
  .side-nav {
    grid-template-columns: 1fr;
  }
  .market-tape,
  .campaign-summary,
  #noticeForm .notice-summary {
    grid-template-columns: 1fr;
  }
  .module-feature strong,
  .module-card strong {
    font-size: 20px;
  }
  .ops-card strong {
    font-size: 28px;
  }
  .toast {
    left: 10px;
    right: 10px;
    top: 10px;
    max-width: none;
  }
}
