:root {
  --bg: #f5f6fa;
  --panel: #ffffff;
  --border: #e6e8ef;
  --text: #1d2130;
  --muted: #6b7185;
  --primary: #4f46e5;
  --primary-50: #eef0ff;
  --primary-600: #4338ca;
  --danger: #dc2626;
  --danger-50: #fef2f2;
  --success: #16a34a;
  --success-50: #ecfdf3;
  --warning: #b45309;
  --warning-50: #fffbeb;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .06);
  --shadow-lg: 0 20px 40px rgba(16, 24, 40, .18);
  font-family: Inter, "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  font-size: 14px;
  color: var(--text);
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); }
a { color: var(--primary); text-decoration: none; }
h1, h2, h3 { margin: 0; font-weight: 650; }
h1 { font-size: 22px; }
h2 { font-size: 16px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.hidden { display: none !important; }
.row { display: flex; align-items: center; gap: 8px; }
.row.wrap { flex-wrap: wrap; }
.spacer { flex: 1; }
.grid { display: grid; gap: 16px; }

/* ---------- Shell ---------- */
.shell { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.sidebar { background: var(--panel); border-right: 1px solid var(--border); padding: 16px 12px; position: sticky; top: 0; height: 100vh; overflow-y: auto; display: flex; flex-direction: column; gap: 4px; }
.brand { display: flex; align-items: center; gap: 10px; padding: 6px 10px 18px; font-weight: 700; font-size: 17px; }
.brand-logo { width: 32px; height: 32px; border-radius: 9px; background: linear-gradient(135deg, #6366f1, #ec4899); display: grid; place-items: center; color: #fff; font-size: 15px; }
.nav-item { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 9px; color: #3a3f52; font-weight: 500; }
.nav-item svg { width: 18px; height: 18px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.nav-item:hover { background: #f1f2f7; }
.nav-item.active { background: var(--primary-50); color: var(--primary); }
.nav-sep { height: 1px; background: var(--border); margin: 8px 6px; }
.sidebar-foot { margin-top: auto; padding: 10px; border-top: 1px solid var(--border); font-size: 13px; }
.main { min-width: 0; }
.topbar { height: 60px; display: flex; align-items: center; gap: 12px; padding: 0 28px; background: var(--panel); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 5; }
.topbar .ws { font-weight: 600; }
.content { padding: 24px 28px 48px; max-width: 1280px; }
.page-head { display: flex; align-items: flex-end; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head p { margin: 4px 0 0; color: var(--muted); }

/* ---------- Primitives ---------- */
.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-pad { padding: 18px; }
.section { margin-top: 28px; }
.section > h2 { margin-bottom: 12px; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 36px; padding: 0 14px; border-radius: 9px; border: 1px solid var(--border); background: #fff; color: var(--text); font: inherit; font-weight: 550; cursor: pointer; white-space: nowrap; }
.btn:hover { background: #f6f7fb; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-600); }
.btn.danger { color: var(--danger); }
.btn.danger:hover { background: var(--danger-50); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.sm { height: 30px; padding: 0 10px; font-size: 13px; }
.btn.block { width: 100%; height: 44px; }
.btn svg { width: 16px; height: 16px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn { width: 32px; height: 32px; padding: 0; }
input[type=text], input[type=email], input[type=password], input[type=date], input[type=time], input[type=datetime-local], input[type=search], select, textarea {
  width: 100%; height: 38px; padding: 0 12px; border: 1px solid var(--border); border-radius: 9px; font: inherit; background: #fff; color: var(--text);
}
textarea { height: auto; min-height: 140px; padding: 10px 12px; resize: vertical; line-height: 1.5; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary-50); border-color: var(--primary); }
label.field { display: block; margin-bottom: 14px; }
label.field > span { display: block; font-size: 13px; font-weight: 550; margin-bottom: 6px; }
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 99px; font-size: 12px; font-weight: 550; background: #f1f2f7; color: #4b5064; white-space: nowrap; }
.badge.ok, .badge.published, .badge.active, .badge.succeeded { background: var(--success-50); color: var(--success); }
.badge.err, .badge.failed, .badge.expired, .badge.error { background: var(--danger-50); color: var(--danger); }
.badge.warn, .badge.partial, .badge.expiring { background: var(--warning-50); color: var(--warning); }
.badge.info, .badge.scheduled, .badge.queued, .badge.publishing, .badge.running { background: var(--primary-50); color: var(--primary); }
.badge.mock { background: #fff3cd; color: #7a5b00; }
.empty { text-align: center; padding: 40px 16px; color: var(--muted); }
.spinner { width: 16px; height: 16px; border: 2px solid var(--primary-50); border-top-color: var(--primary); border-radius: 50%; animation: spin .8s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }
table.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table th { font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 600; background: #fafbfd; }
.tabs { display: inline-flex; background: #eef0f5; border-radius: 10px; padding: 3px; gap: 2px; }
.tabs button { border: 0; background: transparent; padding: 6px 12px; border-radius: 8px; font: inherit; cursor: pointer; color: var(--muted); font-weight: 550; }
.tabs button.active { background: #fff; color: var(--text); box-shadow: var(--shadow); }

/* ---------- Stats ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 14px; }
.stat { padding: 16px 18px; }
.stat .label { color: var(--muted); font-size: 13px; }
.stat .value { font-size: 28px; font-weight: 700; margin-top: 6px; }
.stat.ok .value { color: var(--success); }
.stat.err .value { color: var(--danger); }
.stat.info .value { color: var(--primary); }

/* ---------- Channels ---------- */
.channel-badge { width: 40px; height: 40px; border-radius: 11px; display: grid; place-items: center; color: #fff; font-weight: 800; font-size: 17px; flex: none; }
.channel-badge.sm { width: 22px; height: 22px; border-radius: 6px; font-size: 11px; }
.channel-badge.lg { width: 56px; height: 56px; border-radius: 15px; font-size: 24px; margin: 0 auto 14px; }
.channel-badge svg { width: 58%; height: 58%; stroke: #fff; fill: none; stroke-width: 2; }
.ch-instagram { background: radial-gradient(circle at 30% 107%, #fdf497 0%, #fdf497 5%, #fd5949 45%, #d6249f 60%, #285aeb 90%); }
.ch-facebook { background: #1877f2; }
.ch-tiktok { background: #111; }
.ch-youtube { background: #ff0000; }
.ch-telegram { background: #229ed9; }
.ch-x { background: #000; }
.ch-threads { background: #101010; }
.ch-linkedin { background: #0a66c2; }
.ch-zalo { background: #0068ff; }
.channel-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; }
.channel-tile { padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.channel-tile .meta b { display: block; font-size: 15px; }
.channel-tile .meta span { color: var(--muted); font-size: 12.5px; }
.account-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 14px; }
.account-card { padding: 16px; display: flex; flex-direction: column; gap: 12px; transition: box-shadow .3s; }
.account-card.highlight { box-shadow: 0 0 0 3px #c7d2fe; }
.account-card .head { display: flex; gap: 12px; align-items: center; }
.account-card .platform { font-weight: 650; }
.account-card .type { font-size: 12.5px; color: var(--muted); }
.account-card .handle { font-size: 16px; font-weight: 650; word-break: break-all; }
.account-card dl { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; margin: 0; font-size: 12.5px; }
.account-card dt { color: var(--muted); }
.account-card dd { margin: 0; }
.account-card .error-text { color: var(--danger); font-size: 12.5px; }
.avatar { width: 40px; height: 40px; border-radius: 50%; object-fit: cover; background: #eee; }

/* ---------- Modal ---------- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(17, 20, 32, .45); display: grid; place-items: center; z-index: 50; padding: 16px; animation: fade .15s ease; }
.modal { background: #fff; border-radius: 16px; width: 100%; max-width: 440px; box-shadow: var(--shadow-lg); max-height: calc(100vh - 32px); overflow: auto; animation: pop .18s ease; }
.modal.wide { max-width: 760px; }
.modal-head { display: flex; align-items: center; gap: 8px; padding: 18px 20px 6px; }
.modal-head h2 { font-size: 17px; flex: 1; }
.modal-body { padding: 12px 20px 20px; }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { transform: translateY(8px) scale(.98); opacity: 0; } }
.connect-option { display: flex; align-items: center; gap: 14px; width: 100%; padding: 16px; border: 1px solid var(--border); border-radius: 12px; background: #fff; cursor: pointer; text-align: left; font: inherit; margin-bottom: 12px; }
.connect-option:hover { border-color: var(--primary); background: #fafaff; }
.connect-option .ico { width: 42px; height: 42px; border-radius: 10px; background: var(--primary-50); color: var(--primary); display: grid; place-items: center; flex: none; }
.connect-option .ico svg { width: 22px; height: 22px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.connect-option b { display: block; font-size: 14.5px; }
.connect-option span { color: var(--muted); font-size: 12.5px; }
.pair-status { display: flex; align-items: center; justify-content: center; gap: 10px; padding: 12px; border-radius: 10px; background: #f6f7fb; font-weight: 600; margin-bottom: 14px; }
.pair-status.done { background: var(--success-50); color: var(--success); }
.pair-status.expired { background: var(--danger-50); color: var(--danger); }
.pair-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.qr-box { display: grid; place-items: center; padding: 16px 0 6px; }
.qr-box img { width: 232px; height: 232px; border: 1px solid var(--border); border-radius: 12px; padding: 8px; background: #fff; image-rendering: pixelated; }
.link-box { margin-top: 12px; font-size: 12px; color: var(--muted); word-break: break-all; background: #f6f7fb; border-radius: 8px; padding: 8px 10px; }

/* ---------- Toast ---------- */
.toasts { position: fixed; right: 20px; bottom: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 100; }
.toast { background: #1d2130; color: #fff; padding: 10px 14px; border-radius: 10px; box-shadow: var(--shadow-lg); max-width: 380px; animation: pop .18s ease; }
.toast.err { background: var(--danger); }
.toast.ok { background: var(--success); }

/* ---------- Auth & standalone ---------- */
body.standalone, body.auth { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.standalone-card, .auth-card { background: #fff; border: 1px solid var(--border); border-radius: 16px; box-shadow: var(--shadow); padding: 28px; width: 100%; max-width: 420px; text-align: center; }
.auth-card { text-align: left; }
.standalone-card h1 { margin-bottom: 10px; }
.standalone-card form { margin: 18px 0 8px; }
.standalone-card .handle { font-size: 18px; font-weight: 650; }
.result-icon { width: 56px; height: 56px; border-radius: 50%; display: grid; place-items: center; margin: 0 auto 14px; font-size: 26px; font-weight: 700; }
.result-icon.ok { background: var(--success-50); color: var(--success); }
.result-icon.error { background: var(--danger-50); color: var(--danger); }
.auth-card .switch { margin-top: 14px; text-align: center; color: var(--muted); }
.form-error { color: var(--danger); font-size: 13px; min-height: 18px; margin-bottom: 8px; }

@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; flex-direction: row; flex-wrap: wrap; padding: 8px; }
  .sidebar .brand { width: 100%; padding-bottom: 6px; }
  .nav-item span { display: none; }
  .nav-sep, .sidebar-foot { display: none; }
  .content { padding: 16px; }
  .topbar { padding: 0 16px; }
}
