:root {
  --bg: #f5f6f8; --surface: #ffffff; --surface-2: #f0f2f5; --border: #e2e5ea;
  --text: #14171c; --muted: #6b7280; --primary: #2563eb; --primary-text: #fff;
  --up: #0a9f4f; --down: #e0322e; --ref: #c98a00; --ceil: #a73ad6; --floor: #1b8fd1;
  --danger: #dc2626; --radius: 12px; --shadow: 0 1px 2px rgba(0,0,0,.05), 0 2px 8px rgba(0,0,0,.04);
  --mono: ui-monospace, SFMono-Regular, Menlo, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115; --surface: #171a21; --surface-2: #1f232c; --border: #2a2f3a;
    --text: #e8eaed; --muted: #9aa1ad; --primary: #3b82f6;
    --up: #22c55e; --down: #f05252; --ref: #eab308; --ceil: #c77dff; --floor: #38bdf8;
    --shadow: none; color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; }
.hidden { display: none !important; }
.muted { color: var(--muted); } .small { font-size: 12px; }
h2 { font-size: 16px; margin: 0 0 12px; } h3 { margin: 0 0 14px; font-size: 17px; }
a { color: var(--primary); }

/* buttons & inputs */
.btn { border: 1px solid var(--border); background: var(--surface); color: var(--text); border-radius: 9px;
  padding: 9px 14px; font: inherit; font-weight: 500; cursor: pointer; white-space: nowrap; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; }
.btn.small { padding: 5px 10px; font-size: 13px; }
.btn.danger { color: var(--danger); }
.icon-btn { border: 0; background: transparent; color: var(--muted); cursor: pointer; padding: 4px 6px; border-radius: 6px; font-size: 15px; }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
input, select { width: 100%; font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border);
  border-radius: 9px; padding: 9px 11px; }
input:focus, select:focus { outline: 2px solid color-mix(in srgb, var(--primary) 40%, transparent); border-color: var(--primary); }
label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--muted); }
label.check { flex-direction: row; align-items: center; gap: 8px; color: var(--text); font-size: 14px; }
label.check input { width: auto; }
.help { font-size: 12px; color: var(--muted); }
.err { color: var(--danger); font-size: 13px; min-height: 1em; margin: 8px 0 0; }

/* layout */
.top { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 12px;
  padding: 12px max(16px, env(safe-area-inset-left)); background: var(--surface); border-bottom: 1px solid var(--border); }
.brand { font-weight: 700; font-size: 17px; display: flex; align-items: center; gap: 8px; }
.logo { display: inline-grid; place-items: center; width: 26px; height: 26px; border-radius: 7px; background: var(--primary); color: #fff; font-size: 13px; }
.status { flex: 1; display: flex; align-items: center; gap: 8px; justify-content: flex-end; min-width: 0; }
.pill { font-size: 12px; padding: 3px 9px; border-radius: 99px; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.pill.open { background: color-mix(in srgb, var(--up) 15%, transparent); color: var(--up); }
.pill.err { background: color-mix(in srgb, var(--down) 15%, transparent); color: var(--down); }
.tabs { display: flex; gap: 4px; padding: 8px 16px 0; max-width: 1100px; margin: 0 auto; }
.tab { border: 0; background: transparent; color: var(--muted); font: inherit; font-weight: 600; padding: 8px 12px; border-radius: 8px; cursor: pointer; }
.tab.active { color: var(--text); background: var(--surface); box-shadow: var(--shadow); }
main { max-width: 1100px; margin: 0 auto; padding: 12px 16px 60px; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.add-row { display: flex; gap: 8px; margin-bottom: 12px; }
.hint { background: color-mix(in srgb, var(--ref) 14%, transparent); border-radius: 10px; padding: 10px 12px; margin-bottom: 12px; font-size: 14px; }
.empty { text-align: center; color: var(--muted); padding: 40px 0; }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; box-shadow: var(--shadow); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.span2 { grid-column: span 2; }
.checks { display: flex; flex-wrap: wrap; gap: 16px; margin: 14px 0 4px; }
.actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; flex-wrap: wrap; }

/* cards */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(330px, 1fr)); gap: 12px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 10px; }
.card.off { opacity: .72; }
.card-head { display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; }
.sym { font-size: 19px; font-weight: 700; letter-spacing: .3px; }
.name { font-size: 12px; color: var(--muted); max-width: 170px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.px { text-align: right; font-variant-numeric: tabular-nums; }
.px .last { font-size: 22px; font-weight: 700; font-family: var(--mono); }
.px .chg { font-size: 13px; font-family: var(--mono); }
.c-up { color: var(--up); } .c-down { color: var(--down); } .c-ref { color: var(--ref); } .c-ceil { color: var(--ceil); } .c-floor { color: var(--floor); }
.flash { animation: flash .8s ease-out; }
@keyframes flash { from { background: color-mix(in srgb, var(--primary) 18%, transparent); } to { background: transparent; } }
.meta { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.meta b { color: var(--text); font-weight: 600; }
.book { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; font-family: var(--mono); font-size: 12.5px; }
.book .side { background: var(--surface-2); border-radius: 8px; padding: 6px 8px; }
.book .side div { display: flex; justify-content: space-between; }
.book .lbl { font-family: inherit; font-size: 11px; color: var(--muted); margin-bottom: 2px; }
.toggles { display: flex; gap: 14px; flex-wrap: wrap; }
.switch { display: inline-flex; align-items: center; gap: 7px; font-size: 13px; color: var(--text); cursor: pointer; user-select: none; flex-direction: row; }
.switch input { appearance: none; width: 34px; height: 20px; border-radius: 99px; background: var(--border); position: relative; cursor: pointer; transition: .15s; padding: 0; border: 0; flex: none; }
.switch input::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: .15s; box-shadow: 0 1px 2px rgba(0,0,0,.3); }
.switch input:checked { background: var(--up); }
.switch input:checked::after { left: 16px; }
.rules { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; align-items: center; gap: 4px; border: 1px solid var(--border); background: var(--surface-2); border-radius: 99px; padding: 3px 4px 3px 10px; font-size: 12.5px; }
.chip.disabled { opacity: .5; text-decoration: line-through; }
.chip button { border: 0; background: transparent; color: var(--muted); cursor: pointer; padding: 0 4px; font-size: 13px; line-height: 1; }
.chip button:hover { color: var(--text); }
.chip .txt { cursor: pointer; }
.add-rule { border-style: dashed; background: transparent; color: var(--primary); cursor: pointer; padding: 3px 10px; }
.card-foot { display: flex; justify-content: space-between; align-items: center; border-top: 1px solid var(--border); padding-top: 8px; }

/* notifier list */
.nrow { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-top: 1px solid var(--border); }
.nrow:first-child { border-top: 0; }
.nrow .info { flex: 1; min-width: 0; }
.nrow .info div:last-child { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* history */
.history { list-style: none; padding: 0; margin: 0; }
.history li { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; margin-bottom: 8px; }
.history .t { display: flex; justify-content: space-between; gap: 8px; font-weight: 600; }
.history time { font-weight: 400; font-size: 12px; color: var(--muted); white-space: nowrap; }
.history pre { margin: 4px 0 0; font: 12.5px/1.45 var(--mono); white-space: pre-wrap; color: var(--muted); }
.history .e { color: var(--danger); font-size: 12px; margin-top: 4px; }

/* modal, toast, login */
dialog { border: 1px solid var(--border); border-radius: 14px; background: var(--surface); color: var(--text); padding: 18px; width: min(440px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(0,0,0,.45); }
#modalBody { display: flex; flex-direction: column; gap: 12px; }
.toast { position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); transform: translateX(-50%) translateY(20px); opacity: 0;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-size: 14px; transition: .2s; pointer-events: none; max-width: calc(100vw - 32px); z-index: 50; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.error { background: var(--danger); color: #fff; }
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 24px; width: min(360px, 100%); display: flex; flex-direction: column; gap: 12px; box-shadow: var(--shadow); }

@media (max-width: 640px) {
  .grid2 { grid-template-columns: 1fr; } .span2 { grid-column: auto; }
  .cards { grid-template-columns: 1fr; }
  #lastFetch { display: none; }
  .top { padding: 10px 16px; }
}

/* autocomplete */
.ac { position: relative; flex: 1; }
.ac-list { position: absolute; z-index: 20; top: calc(100% + 4px); left: 0; right: 0; margin: 0; padding: 4px; list-style: none;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px; box-shadow: 0 8px 24px rgba(0,0,0,.14);
  max-height: min(360px, 60vh); overflow-y: auto; }
.ac-list li { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 7px; cursor: pointer; }
.ac-list li.active, .ac-list li:hover { background: var(--surface-2); }
.ac-list li.added { opacity: .5; cursor: default; }
.ac-sym { font-weight: 700; min-width: 64px; font-family: var(--mono); }
.ac-name { flex: 1; min-width: 0; font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ac-ex { font-size: 11px; padding: 1px 6px; border-radius: 5px; background: var(--surface-2); color: var(--muted); }
.ac-empty { color: var(--muted); font-size: 13px; cursor: default !important; }

/* panel chọn mã nhận thông báo */
.notify-panel { padding: 12px 14px; display: flex; flex-direction: column; gap: 10px; }
.np-row { display: flex; gap: 12px; align-items: flex-start; }
.np-label { width: 118px; flex: none; font-weight: 600; font-size: 14px; display: flex; flex-direction: column; padding-top: 4px; }
.np-label .help { font-weight: 400; font-size: 11px; }
.np-chips { display: flex; flex-wrap: wrap; gap: 6px; flex: 1; }
.tchip { border: 1px solid var(--border); background: transparent; color: var(--muted); border-radius: 99px; padding: 5px 12px;
  font: 600 13px var(--mono); cursor: pointer; transition: .12s; }
.tchip:hover { border-color: var(--primary); color: var(--text); }
.tchip.on { background: var(--primary); border-color: var(--primary); color: #fff; }
.tchip.on::before { content: "✓ "; }
.tlink { border: 0; background: none; color: var(--primary); font-size: 12px; cursor: pointer; padding: 5px 4px; }
.np-foot { display: flex; justify-content: space-between; align-items: center; gap: 8px; border-top: 1px solid var(--border); padding-top: 10px; }
.badge-send { font-size: 11px; font-weight: 600; padding: 2px 7px; border-radius: 99px; background: color-mix(in srgb, var(--primary) 14%, transparent); color: var(--primary); margin-left: 6px; vertical-align: middle; }
.hist-filter { display: flex; gap: 8px; margin-bottom: 10px; }
.hist-filter select { width: auto; min-width: 140px; }
.history .sym-tag { font: 600 11px var(--mono); padding: 1px 6px; border-radius: 5px; background: var(--surface-2); margin-right: 6px; }
@media (max-width: 640px) { .np-row { flex-direction: column; gap: 6px; } .np-label { width: auto; flex-direction: row; gap: 8px; align-items: baseline; } }

/* kênh theo mã */
.card-foot { gap: 8px; }
.chan-row { display: flex; align-items: center; gap: 8px; width: 100%; border: 1px dashed var(--border); background: transparent;
  color: var(--muted); border-radius: 9px; padding: 7px 10px; font: inherit; font-size: 13px; cursor: pointer; text-align: left; }
.chan-row b { flex: 1; min-width: 0; color: var(--text); font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chan-row .edit { color: var(--primary); font-size: 12px; }
.chan-row:hover { border-color: var(--primary); }
.chan-row.set { border-style: solid; border-color: color-mix(in srgb, var(--primary) 45%, transparent);
  background: color-mix(in srgb, var(--primary) 6%, transparent); }
.chan-row.set b { color: var(--primary); }
.chan-list { display: flex; flex-direction: column; gap: 8px; padding-left: 26px; }
.history .sent { font-size: 12px; color: var(--muted); margin-top: 4px; }

/* đa người dùng */
.user-menu { position: relative; }
.drop { position: absolute; right: 0; top: calc(100% + 6px); z-index: 30; min-width: 220px; background: var(--surface);
  border: 1px solid var(--border); border-radius: 10px; box-shadow: 0 8px 24px rgba(0,0,0,.14); padding: 6px; }
.drop button { display: block; width: 100%; text-align: left; border: 0; background: none; color: var(--text); font: inherit;
  padding: 8px 10px; border-radius: 7px; cursor: pointer; }
.drop button:hover { background: var(--surface-2); }
.drop-info { padding: 8px 10px 10px; border-bottom: 1px solid var(--border); margin-bottom: 4px; }
.role-badge { font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .4px; padding: 1px 6px; border-radius: 5px;
  background: color-mix(in srgb, var(--ceil) 16%, transparent); color: var(--ceil); }
.count { display: inline-grid; place-items: center; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 99px;
  background: var(--down); color: #fff; font-size: 11px; margin-left: 4px; }
.usage { margin: -4px 0 10px; }
.center { text-align: center; }
.ok { color: var(--up); font-size: 13px; margin: 8px 0 0; }
.table-wrap { overflow-x: auto; margin: 0 -4px; }
.utable { width: 100%; border-collapse: collapse; font-size: 14px; }
.utable th { text-align: left; font-size: 12px; font-weight: 600; color: var(--muted); padding: 6px 8px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.utable td { padding: 9px 8px; border-bottom: 1px solid var(--border); vertical-align: middle; white-space: nowrap; }
.utable tr.disabled td { opacity: .55; }
.utable tr.pending td { background: color-mix(in srgb, var(--ref) 8%, transparent); }
.row-actions { text-align: right; }
@media (max-width: 640px) { .brand-txt { display: none; } }
