/* ═══════════════════════════════════════════════════════════
   ZALO-APP // TERMINAL BRUTALISM
   Inspired by Terminal.html — mono, neon accents
═══════════════════════════════════════════════════════════ */

:root,
:root[data-theme="dark"] {
  --bg: #07080a;
  --bg-1: #0d0f12;
  --bg-2: #14171c;
  --bg-3: #1c2028;
  --line: #1f2329;
  --line-2: #2a3038;
  --text: #e6edf3;
  --text-2: #8b96a5;
  --text-3: #5a6270;
  --text-4: #3a4050;

  --ok: #3ddc84;
  --warn: #ffb000;
  --err: #ff4d4d;
  --info: #4dd0ff;
  --purple: #c084fc;

  --scan: rgba(255,255,255,.008);
  --grad-1: rgba(0,255,156,.04);
  --grad-2: rgba(77,208,255,.03);
}

:root[data-theme="light"] {
  --bg: #fafaf7;
  --bg-1: #f1f1ec;
  --bg-2: #e7e7e0;
  --bg-3: #dcdcd3;
  --line: #d3d3c7;
  --line-2: #b8b8a8;
  --text: #1a1c1f;
  --text-2: #4a5159;
  --text-3: #7a818a;
  --text-4: #a3a8b0;

  --ok: #18a558;
  --warn: #b67800;
  --err: #d23535;
  --info: #1e88c8;
  --purple: #7c3aed;

  --scan: rgba(0,0,0,.012);
  --grad-1: rgba(0,170,100,.06);
  --grad-2: rgba(30,136,200,.05);
}

:root {
  --acc: #00ff9c;
  --acc-dim: rgba(0, 255, 156, 0.10);
  --acc-h: rgba(0, 255, 156, 0.22);

  --mono: 'Geist Mono', 'JetBrains Mono', ui-monospace, monospace;
  --t: 140ms cubic-bezier(.2,.6,.2,1);

  /* spacing scale — 4/8/12/16/20/24 */
  --s-1: 4px;
  --s-2: 8px;
  --s-3: 12px;
  --s-4: 16px;
  --s-5: 20px;
  --s-6: 24px;

  /* control sizes — đảm bảo input/select/button cao bằng nhau */
  --ctl-h: 34px;
  --ctl-h-sm: 26px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 14px; }
body {
  font-family: var(--mono);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  background-image:
    radial-gradient(1200px 600px at 20% -10%, var(--grad-1), transparent 60%),
    radial-gradient(800px 400px at 100% 100%, var(--grad-2), transparent 60%);
  transition: background-color var(--t), color var(--t);
}

/* scanline */
body::before {
  content:''; position: fixed; inset: 0;
  background: repeating-linear-gradient(
    to bottom, transparent 0, transparent 2px,
    var(--scan) 2px, var(--scan) 3px);
  pointer-events: none; z-index: 200;
}

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: var(--bg-1); }
::-webkit-scrollbar-thumb { background: var(--line-2); }
::-webkit-scrollbar-thumb:hover { background: var(--acc); }

button, input, textarea, select { font-family: inherit; font-size: inherit; color: inherit; }
button { cursor: pointer; background: none; border: none; }
a { color: var(--acc); text-decoration: none; }
a:hover { text-decoration: underline; }
::selection { background: var(--acc); color: var(--bg); }

/* ─── TOP BAR ─────────────────────────────────────────── */
.topbar {
  position: fixed; top: 0; left: 0; right: 0;
  height: 36px; background: var(--bg-1); border-bottom: 1px solid var(--line);
  display: flex; align-items: center; padding: 0 16px; gap: 20px;
  font-size: 0.74rem; color: var(--text-2); z-index: 100;
}
.topbar-brand { color: var(--text); font-weight: 600; }
.topbar-brand .prompt { color: var(--acc); margin-right: 6px; }
.topbar-brand .flash { color: var(--text-3); margin-left: 8px; animation: blink 1s steps(1) infinite; }
@keyframes blink { 50% { opacity: 0; } }

.topbar-tickers {
  display: flex; gap: 16px; flex: 1; overflow: hidden;
  mask-image: linear-gradient(to right, transparent, #000 5%, #000 95%, transparent);
}
.ticker { display: flex; align-items: center; gap: 6px; white-space: nowrap; font-size: 0.7rem; color: var(--text-3); }
.ticker .tag { color: var(--ok); }
.ticker .v { color: var(--text-2); font-weight: 500; }

.topbar-right { display: flex; align-items: center; gap: 14px; font-size: 0.7rem; }
.topbar-stat { display: flex; align-items: center; gap: 5px; color: var(--text-2); }
.topbar-stat b { color: var(--text); font-weight: 600; }
.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 8px var(--ok); animation: pulse 1.6s ease-in-out infinite; }
.dot.err { background: var(--err); box-shadow: 0 0 8px var(--err); }
@keyframes pulse { 50% { opacity: .35; } }

/* ─── LAYOUT ─────────────────────────────────────────── */
.app { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; padding-top: 36px; }
.sidebar {
  border-right: 1px solid var(--line); background: var(--bg-1);
  padding: 20px 0; position: sticky; top: 36px;
  height: calc(100vh - 36px); overflow-y: auto; display: flex; flex-direction: column;
}
.sb-section { padding: 0 16px; margin-bottom: 18px; }
.sb-label {
  font-size: 0.64rem; letter-spacing: .14em; color: var(--text-4);
  text-transform: uppercase; margin-bottom: 10px; display: flex; align-items: center; gap: 6px;
}
.sb-label::before { content: '#'; color: var(--acc); font-weight: 700; }

.sb-nav { display: flex; flex-direction: column; gap: 2px; }
.sb-item {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px;
  font-size: 0.78rem; color: var(--text-2); border-left: 2px solid transparent;
  transition: all var(--t); text-align: left; font-weight: 500;
}
.sb-item:hover { background: var(--bg-2); color: var(--text); }
.sb-item.active { color: var(--acc); background: var(--acc-dim); border-left-color: var(--acc); }
.sb-item .sb-key {
  margin-left: auto; font-size: 0.66rem; color: var(--text-4);
  border: 1px solid var(--line-2); padding: 1px 5px; border-radius: 2px; font-weight: 500;
}
.sb-item.active .sb-key { border-color: var(--acc-h); color: var(--acc); }
/* Lucide icon defaults */
.sb-glyph,
.sb-grp-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: var(--text-3);
  transition: color var(--t);
}
.sb-glyph { width: 16px; height: 16px; }
.sb-glyph svg { width: 14px; height: 14px; stroke-width: 1.75; }
.sb-grp-icon { width: 16px; height: 16px; color: var(--text-2); }
.sb-grp-icon svg { width: 14px; height: 14px; stroke-width: 1.75; }

.sb-item:hover .sb-glyph { color: var(--text); }
.sb-item.active .sb-glyph { color: var(--acc); }

/* group header (collapsible section) */
.sb-group {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 6px 4px;
  font-size: 0.7rem;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--text-3);
  font-weight: 600;
  text-align: left;
  margin-bottom: 4px;
  transition: color var(--t);
  user-select: none;
}
.sb-group:hover { color: var(--text-2); }
.sb-grp-caret {
  display: inline-flex; align-items: center; justify-content: center;
  width: 12px; height: 12px;
  color: var(--text-4);
  flex-shrink: 0;
  transition: transform var(--t);
}
.sb-grp-caret svg { width: 12px; height: 12px; stroke-width: 2; }
.sb-group.collapsed .sb-grp-caret { transform: rotate(-90deg); }
.sb-sub { padding-left: 8px; border-left: 1px dashed var(--line); margin-left: 12px; }
.sb-group.collapsed + .sb-sub { display: none; }

.sb-footer { margin-top: auto; padding: 12px 16px; border-top: 1px solid var(--line); font-size: 0.68rem; color: var(--text-3); }
.sb-footer .line { margin-bottom: 3px; }
.sb-footer .line b { color: var(--text-2); }

/* ─── MAIN ─────────────────────────────────────────── */
.main { padding: var(--s-6) 28px 80px; overflow-x: hidden; min-width: 0; }
.main > .page > .panel,
.main > .page > .two-col,
.main > .page > .split-col,
.main > .page > .stats { margin-bottom: var(--s-5); }
.main > .page > :last-child { margin-bottom: 0; }
.page { display: none; animation: fadeIn .25s ease; }
.page.active { display: block; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; } }

.page-cli {
  font-size: 0.74rem; color: var(--text-3);
  margin-bottom: var(--s-1);
  height: 18px; line-height: 18px;
}
.page-cli .p { color: var(--acc); }
.page-cli .c { color: var(--text); }
.page-cli .f { color: var(--info); }
.page-cli .v { color: var(--warn); }

.page-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--s-4);
  margin-bottom: var(--s-6); padding-bottom: var(--s-4);
  border-bottom: 1px dashed var(--line-2);
  min-height: 56px;
}
.page-head > div:first-child { min-width: 0; flex: 1; }
.page-title-row { display: flex; align-items: center; gap: var(--s-3); flex-wrap: wrap; }
.page-title { font-size: 1.4rem; font-weight: 700; letter-spacing: -.02em; line-height: 1.1; }
.page-title .br { color: var(--text-3); font-weight: 400; margin: 0 var(--s-1); }
.page-title .sub { color: var(--acc); }
.page-meta { font-size: 0.7rem; color: var(--text-3); display: flex; gap: var(--s-3); align-items: center; flex-wrap: wrap; }
.page-meta .kv b { color: var(--text-2); font-weight: 500; }

/* ─── CHIPS ─────────────────────────────────────────── */
.chip {
  display: inline-flex; align-items: center; gap: 5px; padding: 3px 8px;
  font-size: 0.66rem; font-weight: 600; border: 1px solid; border-radius: 3px;
  text-transform: uppercase; letter-spacing: .04em;
}
.chip::before { content: ''; width: 5px; height: 5px; border-radius: 50%; background: currentColor; box-shadow: 0 0 6px currentColor; }
.chip.ok { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 30%, transparent); background: color-mix(in srgb, var(--ok) 8%, transparent); }
.chip.warn { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 30%, transparent); background: color-mix(in srgb, var(--warn) 8%, transparent); }
.chip.err { color: var(--err); border-color: color-mix(in srgb, var(--err) 30%, transparent); background: color-mix(in srgb, var(--err) 8%, transparent); }
.chip.info { color: var(--info); border-color: color-mix(in srgb, var(--info) 30%, transparent); background: color-mix(in srgb, var(--info) 8%, transparent); }
.chip.ghost { color: var(--text-3); border-color: var(--line-2); background: transparent; }
.chip.ghost::before { background: var(--text-3); box-shadow: none; }

/* ─── STATS ─────────────────────────────────────────── */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0; border: 1px solid var(--line); margin-bottom: 24px; background: var(--bg-1); }
.stat { padding: 16px 18px; border-right: 1px solid var(--line); }
.stat:last-child { border-right: none; }
.stat-label {
  font-size: 0.64rem; letter-spacing: .14em; text-transform: uppercase;
  color: var(--text-3); margin-bottom: 8px;
}
.stat-label::before { content: '> '; color: var(--acc); }
.stat-val { font-size: 1.9rem; font-weight: 700; letter-spacing: -.02em; line-height: 1; }
.stat-val.acc { color: var(--acc); }
.stat-val.warn { color: var(--warn); }
.stat-val.info { color: var(--info); }
.stat-delta { font-size: 0.68rem; color: var(--text-3); margin-top: 6px; }

/* ─── PANEL ─────────────────────────────────────────── */
.panel {
  background: var(--bg-1);
  border: 1px solid var(--line);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.panel-head {
  display: flex; align-items: center; gap: var(--s-2);
  padding: var(--s-2) var(--s-3); height: 38px; flex-shrink: 0;
  border-bottom: 1px solid var(--line); background: var(--bg-2);
  font-size: 0.72rem;
  box-sizing: border-box;
}
.panel-head .title { font-weight: 600; color: var(--text); }
.panel-head .title svg { width: 14px; height: 14px; vertical-align: -2px; }
.panel-head .title::before { content: '//'; color: var(--acc); margin-right: var(--s-1); font-weight: 700; }
.panel-head .spacer { flex: 1; }
.panel-body {
  padding: var(--s-4);
  flex: 1;
  min-width: 0;
}

/* ─── FORM ─────────────────────────────────────────── */
.field { margin-bottom: var(--s-3); }
.field:last-child { margin-bottom: 0; }
.field-label {
  display: block; font-size: 0.66rem; letter-spacing: .1em;
  text-transform: uppercase; color: var(--text-3); margin-bottom: var(--s-1);
  height: 14px; line-height: 14px;
}
.field-label::before { content: '$ '; color: var(--acc); }

/* Inline group of fields (vd: delay min / max / count) */
.field-row {
  display: grid;
  grid-template-columns: repeat(var(--cols, 3), 1fr);
  gap: var(--s-3);
  margin-bottom: var(--s-3);
}
.field-row .field { margin-bottom: 0; }

/* Action row — căn nút bên phải, inputs cùng size */
.action-row {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  flex-wrap: wrap;
}
.action-row .spacer { flex: 1; }

.input {
  width: 100%; height: var(--ctl-h);
  background: var(--bg-2); border: 1px solid var(--line);
  padding: 0 10px; color: var(--text); font-family: var(--mono);
  font-size: 0.78rem; outline: none;
  transition: border-color var(--t), box-shadow var(--t);
  box-sizing: border-box;
}
.input:focus { border-color: var(--acc); box-shadow: 0 0 0 1px var(--acc-h); }
.input::placeholder { color: var(--text-4); }
textarea.input {
  resize: vertical; min-height: 80px; height: auto;
  padding: var(--s-2) 10px; line-height: 1.5;
}
select.input {
  appearance: none; padding-right: 28px;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--text-3) 50%),
    linear-gradient(135deg, var(--text-3) 50%, transparent 50%);
  background-position: calc(100% - 14px) center, calc(100% - 9px) center;
  background-size: 5px 5px;
  background-repeat: no-repeat;
}
input[type="number"].input {
  /* hide spinner — đỡ thừa chỗ */
  -moz-appearance: textfield;
}
input[type="number"].input::-webkit-outer-spin-button,
input[type="number"].input::-webkit-inner-spin-button {
  -webkit-appearance: none; margin: 0;
}

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: var(--s-2);
  height: var(--ctl-h);
  padding: 0 14px;
  font-family: var(--mono);
  font-size: 0.74rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  border: 1px solid var(--line-2);
  color: var(--text);
  background: var(--bg-2);
  transition: all 160ms cubic-bezier(.2,.7,.3,1);
  white-space: nowrap;
  box-sizing: border-box;
  position: relative;
  user-select: none;
}
.btn:hover {
  border-color: var(--acc-h);
  color: var(--acc);
  background: var(--bg-3);
}
.btn:active { transform: translateY(1px); }
.btn .arr { color: var(--acc); font-weight: 700; }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn:disabled:hover { transform: none; }

.btn.primary {
  height: var(--ctl-h);
  padding: 0 18px;
  background: var(--acc);
  color: var(--bg);
  border-color: var(--acc);
  font-weight: 700;
  font-size: 0.78rem;
  letter-spacing: 0.02em;
  box-shadow: 0 1px 0 0 color-mix(in srgb, var(--bg) 30%, transparent) inset,
              0 4px 12px -2px color-mix(in srgb, var(--acc) 35%, transparent);
}
.btn.primary:hover {
  background: color-mix(in srgb, var(--acc) 92%, white);
  color: var(--bg);
  border-color: color-mix(in srgb, var(--acc) 92%, white);
  box-shadow: 0 1px 0 0 color-mix(in srgb, var(--bg) 30%, transparent) inset,
              0 6px 20px -2px color-mix(in srgb, var(--acc) 50%, transparent);
  transform: translateY(-1px);
}
.btn.primary:active {
  transform: translateY(0);
  box-shadow: 0 1px 4px -2px color-mix(in srgb, var(--acc) 40%, transparent);
}
.btn.primary .arr { color: var(--bg); }
.btn.primary svg { width: 15px; height: 15px; }

.btn.full { width: 100%; }
.btn.sm { height: var(--ctl-h-sm); padding: 0 10px; font-size: 0.7rem; }
.btn.sm svg { width: 12px; height: 12px; }
.btn.ghost { background: transparent; }
.btn.ghost:hover { background: var(--bg-2); }
.btn.danger:hover { color: var(--err); border-color: var(--err); background: color-mix(in srgb, var(--err) 6%, transparent); }

/* SVG spin animation cho refresh button */
@keyframes spin360 { to { transform: rotate(360deg); } }
svg.spin { animation: spin360 1s linear infinite; transform-origin: center; }

/* Icon-only button — chỉ chứa SVG, hình vuông */
.btn.icon {
  width: var(--ctl-h-sm);
  height: var(--ctl-h-sm);
  padding: 0;
  flex-shrink: 0;
}
.btn.icon svg { width: 14px; height: 14px; stroke-width: 1.75; }
.btn.icon:hover { color: var(--acc); border-color: var(--acc-h); }
.btn.icon.danger-hover:hover { color: var(--err); border-color: var(--err); background: color-mix(in srgb, var(--err) 8%, transparent); }
/* Button có icon + text */
.btn svg { width: 14px; height: 14px; stroke-width: 1.75; flex-shrink: 0; }

/* ─── TABLE ─────────────────────────────────────────── */
.tbl-wrap { overflow-x: auto; }
.tbl { width: 100%; border-collapse: collapse; font-size: 0.76rem; }
.tbl th {
  text-align: left; padding: var(--s-2) var(--s-3);
  font-size: 0.62rem; font-weight: 600;
  text-transform: uppercase; letter-spacing: .14em; color: var(--text-3);
  background: var(--bg-1); border-bottom: 1px solid var(--line);
  white-space: nowrap;
  height: 36px;
  box-sizing: border-box;
}
.tbl td {
  padding: var(--s-2) var(--s-3);
  border-bottom: 1px solid var(--line);
  color: var(--text-2);
  vertical-align: middle;
  height: 44px;
  box-sizing: border-box;
}
.tbl tr:last-child td { border-bottom: none; }
.tbl tr:hover td { background: var(--bg-1); }
.tbl .idx { color: var(--text-4); font-size: 0.7rem; width: 32px; }
.tbl .uid { color: var(--info); font-size: 0.72rem; }
.tbl .phone { color: var(--acc); font-weight: 600; }
.tbl .name { color: var(--text); }
.tbl td .actions { display: flex; gap: var(--s-1); flex-wrap: nowrap; }

/* ─── ACCOUNT TABLE ─────────────────────────────────── */
/* Mọi cell + header center cho cân đối */
.acct-tbl th,
.acct-tbl td { text-align: center; vertical-align: middle; }
.acct-tbl td { font-size: 0.74rem; }
/* Display name vẫn left để text dễ đọc khi tên dài */
.acct-tbl th:nth-child(3),
.acct-tbl td:nth-child(3) { text-align: left; }
/* Avatar cell — cần flex center */
.acct-tbl td:nth-child(2) > .acct-av { margin: 0 auto; }
/* Status chip + actions — center */
.acct-tbl .actions { justify-content: center; }
.stat-cell {
  text-align: center;
  font-variant-numeric: tabular-nums;
}
.stat-cell b { color: var(--acc); font-weight: 700; font-size: 0.85rem; }
.dot-load {
  display: inline-block;
  width: 14px; height: 4px;
  background: var(--line-2);
  position: relative;
  overflow: hidden;
}
.dot-load::after {
  content: '';
  position: absolute; inset: 0;
  background: linear-gradient(90deg, transparent, var(--acc), transparent);
  animation: shimmer 1.4s linear infinite;
}
@keyframes shimmer {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(100%); }
}
.acct-av {
  width: 32px; height: 32px;
  border: 1px solid var(--line-2);
  background: var(--bg-2);
  display: flex; align-items: center; justify-content: center;
  color: var(--acc); font-weight: 700; font-size: 0.78rem;
  overflow: hidden;
}
.acct-av img { width: 100%; height: 100%; object-fit: cover; }
.acct-tbl .actions { display: flex; gap: var(--s-1); flex-wrap: nowrap; justify-content: flex-start; }
.acct-tbl .name { color: var(--text); font-weight: 600; }

/* ─── QR LOGIN PANE ─────────────────────────────────── */
.qr-pane {
  display: flex; flex-direction: column; align-items: center; gap: 14px;
  padding: 24px; background: var(--bg); border: 1px dashed var(--line-2);
}
.qr-img-wrap {
  width: 240px; height: 240px; background: var(--bg-2);
  border: 1px solid var(--line-2); display: flex; align-items: center; justify-content: center;
  position: relative;
}
.qr-img-wrap img { width: 100%; height: 100%; object-fit: contain; padding: 8px; background: white; }
.qr-img-wrap .placeholder { color: var(--text-4); font-size: .74rem; text-align: center; padding: 12px; }
.qr-status { font-size: .76rem; color: var(--text-2); text-align: center; min-height: 18px; }
.qr-status.ok { color: var(--ok); }
.qr-status.err { color: var(--err); }
.qr-status.info { color: var(--info); }

/* ─── LOG STREAM ─────────────────────────────────────── */
.log-stream {
  background: var(--bg); border: 1px solid var(--line);
  height: 380px; overflow-y: auto; padding: 10px 14px;
  font-size: .72rem; line-height: 1.55;
}
.log-stream .ln { display: flex; gap: 10px; padding: 1px 0; }
.log-stream .ts { color: var(--text-4); flex-shrink: 0; font-size: .68rem; }
.log-stream .lvl { flex-shrink: 0; font-weight: 700; width: 36px; }
.log-stream .lvl.info { color: var(--info); }
.log-stream .lvl.ok { color: var(--ok); }
.log-stream .lvl.warn { color: var(--warn); }
.log-stream .lvl.err { color: var(--err); }
.log-stream .msg { color: var(--text-2); word-break: break-word; }

.notice {
  font-size: 0.72rem;
  color: var(--text-3);
  margin-top: var(--s-2);
  padding: var(--s-2) var(--s-3);
  background: var(--bg);
  border-left: 2px solid var(--acc);
  line-height: 1.55;
}
/* Ẩn khi notice rỗng (status placeholder chưa có message) */
.notice:empty { display: none; }
.notice::before { content: '#  '; color: var(--acc); font-weight: 700; }
.notice b { color: var(--text-2); font-weight: 600; }

.kbd { font-size: 0.66rem; padding: 1px 5px; border: 1px solid var(--line-2); color: var(--text-3); background: var(--bg-2); }

.empty { padding: 30px; text-align: center; color: var(--text-3); font-size: .78rem; }
.empty::before { content: '○ '; color: var(--text-4); }

/* ─── CONTEXT MENU ─────────────────────────────────── */
.ctx-menu {
  position: fixed;
  z-index: 1000;
  background: var(--bg-1);
  border: 1px solid var(--line);
  box-shadow: 0 8px 28px rgba(0,0,0,.4);
  min-width: 200px;
  padding: var(--s-1) 0;
  animation: popIn .12s ease;
}
.ctx-item {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  width: 100%;
  padding: 6px 12px;
  font-size: 0.74rem;
  color: var(--text-2);
  border: none;
  background: none;
  text-align: left;
  cursor: pointer;
  transition: all var(--t);
}
.ctx-item:hover { background: var(--acc-dim); color: var(--acc); }
.ctx-item.danger:hover { background: color-mix(in srgb, var(--err) 10%, transparent); color: var(--err); }
.ctx-icon {
  width: 16px; height: 16px;
  display: inline-flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  color: var(--text-3);
}
.ctx-icon svg { width: 14px; height: 14px; stroke-width: 1.75; }
.ctx-item:hover .ctx-icon { color: inherit; }
.ctx-item .ctx-arrow { margin-left: auto; width: 12px; height: 12px; }
.ctx-item .ctx-arrow svg { width: 12px; height: 12px; }
.ctx-sep {
  height: 1px;
  background: var(--line);
  margin: var(--s-1) 0;
}

/* ─── CHECKBOX (option toggle) ─────────────────────────────── */
.check {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  height: var(--ctl-h);
  padding: 0 12px;
  margin-top: var(--s-2);
  margin-bottom: var(--s-3);
  font-size: 0.78rem;
  color: var(--text-2);
  cursor: pointer;
  user-select: none;
  border: 1px solid var(--line);
  background: var(--bg-2);
  transition: all var(--t);
  box-sizing: border-box;
}
/* inline variant — khi muốn nhỏ gọn (vd: trong action bar) */
.check.inline {
  width: auto;
  display: inline-flex;
  margin-bottom: 0;
}
.check:hover {
  color: var(--text);
  border-color: var(--line-2);
  background: var(--bg-3);
}
.check input[type="checkbox"] {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}
.check .cb {
  width: 16px; height: 16px;
  border: 1.5px solid var(--line-2);
  background: var(--bg);
  flex-shrink: 0;
  position: relative;
  transition: all var(--t);
  box-sizing: border-box;
}
.check:hover .cb { border-color: var(--text-3); }
.check input:checked + .cb {
  background: var(--acc);
  border-color: var(--acc);
}
/* Checkmark vẽ bằng border xoay 45° — sắc nét, không phụ thuộc font */
.check input:checked + .cb::after {
  content: '';
  position: absolute;
  left: 4px; top: 1px;
  width: 4px; height: 8px;
  border: solid var(--bg);
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}
/* State khi đã tick: highlight nhẹ cả label */
.check:has(input:checked) {
  border-color: var(--acc-h);
  background: var(--acc-dim);
  color: var(--text);
}

/* ─── SELECTION CHECKBOX trong table ─────────────────────────── */
.tbl .row-check {
  width: 32px;
  text-align: center;
  padding: 0 var(--s-2);
}
.tbl .row-check input[type="checkbox"] {
  margin: 0;
  width: 14px;
  height: 14px;
  cursor: pointer;
  accent-color: var(--acc);
}
.tbl tr.selected td { background: var(--acc-dim); }
.tbl tr.selected td.row-check { background: color-mix(in srgb, var(--acc) 16%, transparent); }

/* ─── ACTION BAR (floating khi có selection) ───────────────── */
.action-bar {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  z-index: 500;
  background: var(--bg-1);
  border: 1px solid var(--acc-h);
  box-shadow: 0 8px 32px rgba(0,0,0,.5), 0 0 0 1px var(--acc-dim);
  padding: var(--s-2) var(--s-3);
  display: flex;
  align-items: center;
  gap: var(--s-2);
  font-size: 0.74rem;
  opacity: 0;
  pointer-events: none;
  transition: all 200ms cubic-bezier(.2,.7,.3,1);
}
.action-bar.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
  pointer-events: auto;
}
.action-bar .ab-count {
  color: var(--acc);
  font-weight: 700;
  padding: 0 var(--s-2);
  border-right: 1px solid var(--line);
  white-space: nowrap;
}
.action-bar .ab-count b { font-size: 0.9rem; margin-right: 4px; }
.action-bar .btn { height: 30px; padding: 0 var(--s-3); font-size: 0.72rem; }
.action-bar .btn svg { width: 13px; height: 13px; }
.action-bar .ab-spacer { width: 1px; height: 20px; background: var(--line); margin: 0 var(--s-1); }
.action-bar .btn.clear { color: var(--text-3); }

/* ─── SAFETY PANEL (collapsible advanced settings) ─────────── */
.safety-panel {
  border: 1px solid var(--line);
  background: var(--bg-2);
  margin-bottom: var(--s-3);
}
.safety-panel summary {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  padding: 10px 12px;
  cursor: pointer;
  user-select: none;
  font-size: 0.74rem;
  color: var(--text-2);
  font-weight: 600;
  transition: color var(--t);
  list-style: none;
}
.safety-panel summary::-webkit-details-marker { display: none; }
.safety-panel summary:hover { color: var(--text); }
.safety-panel summary svg { width: 14px; height: 14px; stroke-width: 1.75; }
.safety-panel summary svg:first-child { color: var(--acc); }
.safety-panel summary .caret {
  margin-left: auto;
  transition: transform var(--t);
}
.safety-panel[open] summary .caret { transform: rotate(180deg); }
.safety-panel .safety-body {
  padding: 12px 14px;
  border-top: 1px solid var(--line);
  background: var(--bg);
}

/* ─── AI BUTTON (floating, top-right of textarea) ─────── */
.field-with-ai {
  position: relative;
}
.btn-ai {
  position: absolute;
  top: 18px; right: 6px;
  z-index: 2;
  height: 24px; padding: 0 8px;
  font-size: 0.66rem; font-weight: 700;
  background: color-mix(in srgb, var(--acc) 14%, transparent);
  border: 1px solid var(--acc-h);
  color: var(--acc);
  cursor: pointer;
  display: inline-flex; align-items: center; gap: 4px;
  transition: all var(--t);
}
.btn-ai:hover {
  background: var(--acc);
  color: var(--bg);
  border-color: var(--acc);
  box-shadow: 0 0 12px var(--acc-h);
}
.btn-ai svg { width: 12px; height: 12px; stroke-width: 2; }

/* ─── AI PRESET GRID ───────────────────────────────────── */
.ai-preset-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 5px;
}
.ai-preset-btn {
  padding: 6px 8px;
  font-size: 0.72rem;
  font-family: inherit;
  font-weight: 500;
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--text-2);
  cursor: pointer;
  border-radius: 4px;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: all var(--t);
  line-height: 1.4;
}
.ai-preset-btn:hover {
  border-color: var(--acc);
  color: var(--acc);
  background: var(--acc-dim);
}
.ai-preset-btn.active {
  border-color: var(--acc);
  color: var(--acc);
  background: var(--acc-dim);
  font-weight: 700;
}

/* ─── PREVIEW BOX ─────────────────────────────────────── */
.preview-box {
  padding: 10px 12px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-left: 2px solid var(--info);
  font-size: 0.78rem;
  min-height: 60px;
  white-space: pre-wrap;
  color: var(--text-2);
  line-height: 1.5;
  font-family: var(--mono);
}
.preview-box:empty::before { content: 'preview sẽ hiện sau khi gõ template'; color: var(--text-4); font-style: italic; }

/* ─── PICKER (multi-select list with toolbar) ──────────── */
.picker-toolbar {
  display: flex;
  gap: var(--s-2);
  margin-bottom: var(--s-2);
  align-items: stretch;
}
.picker-toolbar .input { flex: 1; min-width: 0; }
/* Buttons trong toolbar luôn cao bằng input (dù mặc định là btn.sm) */
.picker-toolbar .btn {
  flex-shrink: 0;
  height: var(--ctl-h);
  font-size: 0.74rem;
  padding: 0 12px;
}
.picker-toolbar .btn svg { width: 14px; height: 14px; }

.picker-list {
  flex: 1 1 auto;
  min-height: 240px;
  overflow-y: auto;
  border: 1px solid var(--line);
  background: var(--bg);
}
/* Khi trong panel với flex column → list giãn full chiều cao */
.two-col > .panel .picker-list {
  flex: 1 1 0;
}

/* ─── COUNTER ROW (textarea footer) ─────────────────────── */
.counter-row {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  margin-top: 6px;
  height: 28px;
}
.counter-row .spacer { flex: 1; }
.counter-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 10px;
  height: 22px;
  font-size: 0.7rem;
  color: var(--text-3);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 11px;
  font-family: var(--mono);
}
.counter-badge b {
  color: var(--acc);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

/* ─── FILE PICKER / ATTACHMENTS ─────────────────────────── */
.file-picker {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--s-3);
  width: 100%;
  min-height: 84px;
  padding: var(--s-3) var(--s-4);
  border: 1.5px dashed var(--line-2);
  background: var(--bg-2);
  cursor: pointer;
  transition: all var(--t);
  box-sizing: border-box;
}
.file-picker:hover { border-color: var(--acc); background: var(--bg-3); }
.file-picker.dragover {
  border-color: var(--acc);
  background: var(--acc-dim);
  border-style: solid;
}
.file-picker-label {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  color: var(--text-3);
  font-size: 0.76rem;
  text-align: left;
  pointer-events: none;
}
.file-picker-label .icon {
  width: 36px; height: 36px;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--acc-dim);
  color: var(--acc);
}
.file-picker-label .icon svg {
  width: 18px; height: 18px; stroke-width: 1.75;
}
.file-picker-label .text { line-height: 1.4; }
.file-picker-label .text b { color: var(--text); font-weight: 600; display: block; margin-bottom: 2px; }
.file-picker:hover .file-picker-label .icon { background: color-mix(in srgb, var(--acc) 18%, transparent); }

.file-list {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-2);
  margin-top: var(--s-2);
}
.file-list:empty { display: none; }

.file-thumb {
  position: relative;
  width: 72px; height: 72px;
  border: 1px solid var(--line);
  background: var(--bg-2);
  display: flex; align-items: center; justify-content: center;
  font-size: 0.66rem;
  color: var(--text-3);
  overflow: hidden;
  flex-shrink: 0;
}
.file-thumb img { width: 100%; height: 100%; object-fit: cover; }
.file-thumb .file-meta {
  position: absolute; bottom: 0; left: 0; right: 0;
  background: rgba(0,0,0,.65);
  color: #fff;
  font-size: 0.6rem;
  padding: 2px 5px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  font-weight: 500;
}
.file-thumb .file-rm {
  position: absolute; top: 4px; right: 4px;
  width: 18px; height: 18px;
  border-radius: 50%;
  background: var(--bg-1);
  color: var(--err);
  border: 1px solid var(--err);
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700;
  cursor: pointer;
  opacity: 0;
  transition: all var(--t);
  line-height: 1;
}
.file-thumb:hover .file-rm { opacity: 1; }
.file-thumb .file-rm:hover { background: var(--err); color: #fff; }

/* ─── TOAST ─────────────────────────────────── */
#toast-bar {
  position: fixed;
  bottom: 20px; right: 20px;
  z-index: 1100;
  display: flex; flex-direction: column; gap: var(--s-2);
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  background: var(--bg-1);
  border: 1px solid var(--line-2);
  padding: 10px 14px;
  font-size: 0.76rem;
  color: var(--text);
  box-shadow: 0 4px 16px rgba(0,0,0,.4);
  transition: opacity .3s;
  border-left: 3px solid var(--acc);
  max-width: 360px;
}
.toast.err { border-left-color: var(--err); }
.toast.warn { border-left-color: var(--warn); }
.toast.info { border-left-color: var(--info); }

/* responsive */
@media (max-width: 1100px) {
  .stats { grid-template-columns: repeat(2, 1fr); }
  .stat:nth-child(2) { border-right: none; }
  .stat:nth-child(-n+2) { border-bottom: 1px solid var(--line); }
}
@media (max-width: 720px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .main { padding: 16px; }
  .topbar-tickers { display: none; }
}

/* two-col grid — stretch để 2 panel cùng chiều cao */
.two-col {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: var(--s-4);
  align-items: stretch;
}
.two-col > .panel { height: 100%; }
.two-col > .panel > .panel-body {
  display: flex;
  flex-direction: column;
}
/* Textarea chính trong panel-body sẽ giãn ra chiếm không gian dư
   → 2 panel có content stack đều, đáy align nhau */
.two-col > .panel textarea.input.main-area {
  flex: 1 1 auto;
  min-height: 200px;
  resize: vertical;
}
/* Đẩy notice cuối cùng xuống đáy panel → 2 panel có "bottom hint" align ngang */
.two-col > .panel > .panel-body > .notice:last-child {
  margin-top: auto;
}
/* Run button + notice cuối → group lại, đẩy xuống cùng */
.two-col > .panel > .panel-body > .btn.primary.full {
  margin-top: var(--s-2);
}
@media (max-width: 900px) { .two-col { grid-template-columns: 1fr; } }

/* asymmetric two-col: form trái nhỏ + content phải lớn */
.split-col {
  display: grid;
  grid-template-columns: 380px minmax(0, 1fr);
  gap: var(--s-4);
  align-items: stretch;
}
.split-col > .panel { height: 100%; }
@media (max-width: 900px) { .split-col { grid-template-columns: 1fr; } }

/* ─── MODAL — generic overlay ───────────────────────────── */
/* Mọi modal: id="*-modal" chứa .modal-bg + .modal — căn giữa viewport */
[id$="-modal"] {
  position: fixed; inset: 0; z-index: 300;
  display: flex; align-items: center; justify-content: center;
  animation: fadeIn .15s ease;
}
[id$="-modal"] .modal-bg {
  position: absolute; inset: 0;
  background: color-mix(in srgb, var(--bg) 70%, transparent);
  backdrop-filter: blur(4px);
}
[id$="-modal"] .modal {
  position: relative;
  background: var(--bg-1);
  border: 1px solid var(--line);
  width: 90%; max-width: 560px;
  max-height: 85vh;
  display: flex; flex-direction: column;
  box-shadow: 0 8px 40px rgba(0,0,0,.5);
}
[id$="-modal"] .modal-body {
  padding: var(--s-4);
  overflow-y: auto;
}
/* info-modal có table → padding nhỏ hơn */
#info-modal .modal { max-width: 700px; }
#info-modal .modal-body { padding: var(--s-2); }

/* ─── Schedule modal — segmented tabs + preview ─── */
#schedule-modal .modal { max-width: 480px; }
.sch-tabs {
  display: grid; grid-template-columns: 1fr 1fr; gap: 8px;
}
.sch-tab {
  display: flex; align-items: center; gap: 10px;
  padding: 12px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  cursor: pointer;
  font-family: inherit; color: var(--text-1);
  text-align: left;
  transition: all .12s ease;
}
.sch-tab:hover { background: var(--bg-3); border-color: var(--acc-h); }
.sch-tab.active {
  background: color-mix(in srgb, var(--acc) 8%, transparent);
  border-color: var(--acc);
  color: var(--acc);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--acc) 18%, transparent);
}
.sch-tab svg { width: 20px; height: 20px; flex-shrink: 0; }
.sch-tab-title { font-size: 0.82rem; font-weight: 700; letter-spacing: 0.02em; }
.sch-tab-sub { font-size: 0.67rem; color: var(--text-3); margin-top: 2px; }
.sch-tab.active .sch-tab-sub { color: color-mix(in srgb, var(--acc) 80%, transparent); }
.sch-quick {
  display: flex; flex-wrap: wrap; gap: 6px;
  margin-top: 10px;
}
.sch-quick .btn { font-size: 0.7rem; }
.sch-preview {
  margin-top: 14px;
  padding: 10px 12px;
  background: var(--bg-2);
  border-left: 2px solid var(--acc);
  font-size: 0.76rem;
  color: var(--text-2);
  font-family: var(--mono);
}
.sch-preview:empty { display: none; }
.sch-preview svg { width: 13px; height: 13px; vertical-align: -2px; margin-right: 4px; color: var(--acc); }
.sch-preview b { color: var(--text-1); }
.sch-lbl {
  font-size: 0.66rem;
  letter-spacing: 0.1em;
  color: var(--text-3);
  text-transform: uppercase;
  margin-bottom: 6px;
}

/* ─── THEME SWITCHER ───────────────────────────────────── */
.sb-theme {
  display: flex;
  gap: 8px;
  margin-top: 8px;
  align-items: center;
}
.sb-theme .sw {
  width: 18px; height: 18px;
  border-radius: 50%;
  cursor: pointer;
  border: none;
  transition: transform var(--t);
  flex-shrink: 0;
}
.sb-theme .sw:hover { transform: scale(1.12); }
.sb-theme .sw.sel {
  outline: 1.5px solid var(--text);
  outline-offset: 2px;
}

/* mode toggle — 2 circle previews, cùng size với theme dots */
.mode-toggle {
  display: flex;
  gap: 10px;
  margin-top: 8px;
  align-items: center;
}
.mode-toggle button {
  width: 18px; height: 18px;
  border-radius: 50%;
  padding: 0;
  background: none;
  border: none;
  position: relative;
  cursor: pointer;
  transition: transform var(--t);
  flex-shrink: 0;
}
.mode-toggle button:hover { transform: scale(1.12); }
.mode-toggle button::before {
  content: '';
  display: block;
  width: 100%; height: 100%;
  border-radius: 50%;
  box-sizing: border-box;
}
.mode-toggle button[data-mode="dark"]::before {
  background: #07080a;
}
.mode-toggle button[data-mode="light"]::before {
  background: #ffffff;
  border: 1px solid #d3d3c7;
}
.mode-toggle button.on {
  outline: 1.5px solid var(--acc);
  outline-offset: 2px;
}

/* ─── ACCOUNT PILL ───────────────────────────────────── */
.acct-pill {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 12px 6px 6px;
  margin-top: 8px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 30px;
  cursor: pointer;
  transition: all var(--t);
  position: relative;
  user-select: none;
}
.acct-pill:hover { border-color: var(--acc-h); background: var(--bg-3); }

.acct-avatar {
  position: relative;
  width: 32px; height: 32px;
  flex-shrink: 0;
}
.acct-avatar-inner {
  width: 100%; height: 100%;
  border-radius: 50%;
  background: var(--bg);
  border: 2px solid var(--acc);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.78rem;
  color: var(--text);
  overflow: hidden;
  box-sizing: border-box;
}
.acct-avatar-inner img { width: 100%; height: 100%; object-fit: cover; }
.acct-online {
  position: absolute;
  bottom: -1px; right: -1px;
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--ok);
  border: 2px solid var(--bg-2);
  box-shadow: 0 0 6px color-mix(in srgb, var(--ok) 70%, transparent);
}

.acct-meta { flex: 1; min-width: 0; }
.acct-name {
  font-weight: 600;
  font-size: 0.82rem;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.acct-chevron {
  color: var(--text-3);
  flex-shrink: 0;
  transition: transform var(--t), color var(--t);
}
.acct-pill:hover .acct-chevron { color: var(--text-2); }
.acct-pill.open .acct-chevron { transform: rotate(180deg); color: var(--acc); }

/* popover */
.acct-popover {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 0; right: 0;
  background: var(--bg-1);
  border: 1px solid var(--line);
  box-shadow: 0 8px 24px rgba(0,0,0,.4);
  z-index: 50;
  animation: popIn .12s ease;
}
@keyframes popIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; } }
.acct-pop-head {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  display: flex; flex-direction: column;
  font-size: .78rem;
}
.acct-pop-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 9px 14px;
  font-size: 0.74rem;
  color: var(--text-2);
  border: none;
  background: none;
  border-bottom: 1px solid var(--line);
  text-align: left;
  cursor: pointer;
  transition: all var(--t);
}
.acct-pop-item:last-child { border-bottom: none; }
.acct-pop-item:hover { background: var(--bg-2); color: var(--text); }
.acct-pop-item.danger:hover { color: var(--err); background: color-mix(in srgb, var(--err) 8%, transparent); }
