/* SCV 2 — giao diện admin */
:root {
  --bg: #f5f6fa;
  --surface: #ffffff;
  --surface-2: #f9fafb;
  --border: #e5e7eb;
  --border-strong: #d1d5db;
  --text: #111827;
  --text-2: #4b5563;
  --text-3: #9ca3af;
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --primary-soft: #eef2ff;
  --success: #059669;
  --success-soft: #ecfdf5;
  --warning: #d97706;
  --warning-soft: #fffbeb;
  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --info: #0284c7;
  --info-soft: #f0f9ff;
  --sidebar: #111827;
  --sidebar-text: #9ca3af;
  --sidebar-active: #ffffff;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .06);
  --shadow-lg: 0 12px 32px rgba(16, 24, 40, .16);
  --radius: 10px;
  --radius-sm: 7px;
  --font: "Be Vietnam Pro", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b0f17; --surface: #121826; --surface-2: #171e2e; --border: #232b3d; --border-strong: #2f3a51;
    --text: #e5e7eb; --text-2: #a3acbd; --text-3: #6b7489;
    --primary: #818cf8; --primary-hover: #a5b4fc; --primary-soft: #1e2140;
    --success: #34d399; --success-soft: #0f2a22; --warning: #fbbf24; --warning-soft: #2b2210;
    --danger: #f87171; --danger-soft: #2d1416; --info: #38bdf8; --info-soft: #0c2533;
    --sidebar: #080b12; --shadow: 0 1px 2px rgba(0,0,0,.4); --shadow-lg: 0 12px 32px rgba(0,0,0,.5);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0b0f17; --surface: #121826; --surface-2: #171e2e; --border: #232b3d; --border-strong: #2f3a51;
  --text: #e5e7eb; --text-2: #a3acbd; --text-3: #6b7489;
  --primary: #818cf8; --primary-hover: #a5b4fc; --primary-soft: #1e2140;
  --success: #34d399; --success-soft: #0f2a22; --warning: #fbbf24; --warning-soft: #2b2210;
  --danger: #f87171; --danger-soft: #2d1416; --info: #38bdf8; --info-soft: #0c2533;
  --sidebar: #080b12; --shadow: 0 1px 2px rgba(0,0,0,.4); --shadow-lg: 0 12px 32px rgba(0,0,0,.5);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 14px/1.5 var(--font); -webkit-font-smoothing: antialiased; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; line-height: 1.3; }
code, .mono { font-family: var(--mono); font-size: 12.5px; }
hr { border: 0; border-top: 1px solid var(--border); margin: 16px 0; }

/* ---------- Layout ---------- */
.layout { display: grid; grid-template-columns: 236px 1fr; min-height: 100vh; }
.sidebar { background: var(--sidebar); color: var(--sidebar-text); position: sticky; top: 0; height: 100vh; overflow-y: auto; display: flex; flex-direction: column; }
.brand { display: flex; align-items: center; gap: 10px; padding: 18px 18px 14px; color: #fff; font-weight: 700; font-size: 16px; }
.brand-logo { width: 30px; height: 30px; border-radius: 8px; background: #4f46e5; display: grid; place-items: center; font-weight: 800; }
.brand small { display: block; font-weight: 400; color: var(--sidebar-text); font-size: 11px; }
.nav { padding: 6px 10px 16px; flex: 1; }
.nav-group { margin-top: 14px; }
.nav-label { font-size: 10.5px; text-transform: uppercase; letter-spacing: .08em; padding: 0 10px 6px; color: #6b7280; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; color: var(--sidebar-text); font-weight: 500; text-decoration: none; }
.nav a:hover { background: rgba(255,255,255,.06); color: #e5e7eb; }
.nav a.active { background: rgba(129,140,248,.16); color: var(--sidebar-active); }
.nav a svg { width: 18px; height: 18px; flex: none; opacity: .85; }
.nav .count { margin-left: auto; font-size: 11px; background: rgba(255,255,255,.1); padding: 0 7px; border-radius: 99px; }
.side-foot { padding: 12px 18px 16px; border-top: 1px solid rgba(255,255,255,.07); font-size: 12px; display: flex; align-items: center; gap: 8px; }
.side-foot .avatar { width: 28px; height: 28px; border-radius: 50%; background: #374151; color: #fff; display: grid; place-items: center; font-weight: 600; }
.side-foot button { margin-left: auto; background: none; border: 0; color: var(--sidebar-text); cursor: pointer; padding: 4px; border-radius: 6px; }
.side-foot button:hover { color: #fff; background: rgba(255,255,255,.08); }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { position: sticky; top: 0; z-index: 20; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(8px); border-bottom: 1px solid var(--border); padding: 12px 28px; display: flex; align-items: center; gap: 12px; min-height: 60px; }
.topbar h1 { font-size: 18px; font-weight: 650; }
.topbar .crumb { color: var(--text-3); font-size: 13px; }
.topbar .actions { margin-left: auto; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.menu-btn { display: none; background: none; border: 0; color: var(--text); padding: 6px; cursor: pointer; }
.content { padding: 24px 28px 48px; max-width: 1400px; width: 100%; }

/* ---------- Cards ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card + .card, .card + .grid, .grid + .card, .grid + .grid { margin-top: 20px; }
.card-head { display: flex; align-items: center; gap: 10px; padding: 14px 18px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.card-head h2 { font-size: 15px; font-weight: 600; }
.card-head .sub { color: var(--text-3); font-size: 12.5px; }
.card-head .right { margin-left: auto; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.card-body { padding: 18px; }
.card-foot { padding: 12px 18px; border-top: 1px solid var(--border); display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

.grid { display: grid; gap: 20px; }
.grid > .card, .stack > .card { margin-top: 0 !important; }
a > svg, td svg:not(.empty svg), .cell-sub svg, .small svg { width: 14px; height: 14px; vertical-align: -2px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.side-right { grid-template-columns: minmax(0, 1fr) 340px; align-items: start; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }

/* ---------- Stats ---------- */
.stat { padding: 16px 18px; display: flex; gap: 14px; align-items: center; }
.stat-ic { width: 42px; height: 42px; border-radius: 10px; display: grid; place-items: center; flex: none; }
.stat-ic svg { width: 22px; height: 22px; }
.stat-v { font-size: 22px; font-weight: 700; line-height: 1.1; }
.stat-l { color: var(--text-2); font-size: 12.5px; }
.tone-primary { background: var(--primary-soft); color: var(--primary); }
.tone-success { background: var(--success-soft); color: var(--success); }
.tone-warning { background: var(--warning-soft); color: var(--warning); }
.tone-danger { background: var(--danger-soft); color: var(--danger); }
.tone-info { background: var(--info-soft); color: var(--info); }

/* ---------- Buttons ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 36px; padding: 0 14px; border-radius: var(--radius-sm); border: 1px solid var(--border-strong); background: var(--surface); color: var(--text); font: 500 13.5px var(--font); cursor: pointer; white-space: nowrap; text-decoration: none !important; transition: background .12s, border-color .12s; }
.btn:hover { background: var(--surface-2); }
.btn svg { width: 16px; height: 16px; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
:root[data-theme="dark"] .btn-primary, :root:not([data-theme="light"]) .btn-primary { color: #fff; }
.btn-danger { color: var(--danger); }
.btn-danger:hover { background: var(--danger-soft); border-color: var(--danger); }
.btn-solid-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-ghost:hover { background: var(--surface-2); }
.btn-sm { height: 30px; padding: 0 10px; font-size: 12.5px; }
.btn-xs { height: 26px; padding: 0 8px; font-size: 12px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.loading { pointer-events: none; opacity: .7; }
.btn.loading::before { content: ""; width: 13px; height: 13px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.icon-btn { width: 30px; height: 30px; padding: 0; }

/* ---------- Forms ---------- */
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > label, .lbl { font-weight: 500; font-size: 13px; color: var(--text-2); }
.field .hint { color: var(--text-3); font-size: 12px; }
.field .req { color: var(--danger); }
input[type=text], input[type=url], input[type=number], input[type=password], input[type=email], input[type=search], input[type=date], input[type=datetime-local], select, textarea {
  width: 100%; height: 38px; padding: 0 11px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text); font: 14px var(--font); outline: none; transition: border-color .12s, box-shadow .12s;
}
textarea { height: auto; min-height: 90px; padding: 9px 11px; resize: vertical; line-height: 1.5; }
input:focus, select:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
input[readonly] { background: var(--surface-2); color: var(--text-2); }
.fg2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.fg3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; user-select: none; }
.check input { width: 16px; height: 16px; accent-color: var(--primary); margin: 0; }
.search { position: relative; }
.search svg { position: absolute; left: 10px; top: 50%; width: 16px; height: 16px; transform: translateY(-50%); color: var(--text-3); pointer-events: none; }
.search input { padding-left: 34px; }
.seg { display: inline-flex; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); overflow: hidden; background: var(--surface); }
.seg button { border: 0; background: transparent; padding: 0 14px; height: 34px; font: 500 13px var(--font); color: var(--text-2); cursor: pointer; }
.seg button + button { border-left: 1px solid var(--border); }
.seg button.on { background: var(--primary-soft); color: var(--primary); }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: 12px; font-weight: 600; color: var(--text-2); background: var(--surface-2); white-space: nowrap; text-transform: none; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: color-mix(in srgb, var(--surface-2) 70%, transparent); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
td.w-check, th.w-check { width: 40px; padding-right: 0; }
.cell-title { font-weight: 550; color: var(--text); }
.cell-sub { color: var(--text-3); font-size: 12px; }
.thumb { width: 40px; height: 40px; border-radius: 6px; object-fit: cover; background: var(--surface-2); border: 1px solid var(--border); flex: none; }
.empty { padding: 48px 20px; text-align: center; color: var(--text-3); }
.empty svg { width: 40px; height: 40px; margin-bottom: 8px; opacity: .6; }
.trunc { max-width: 360px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.break { word-break: break-all; }

/* ---------- Badges ---------- */
.badge { display: inline-flex; align-items: center; gap: 4px; height: 22px; padding: 0 8px; border-radius: 99px; font-size: 11.5px; font-weight: 600; white-space: nowrap; background: var(--surface-2); color: var(--text-2); border: 1px solid var(--border); }
.badge.green { background: var(--success-soft); color: var(--success); border-color: transparent; }
.badge.red { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.badge.orange { background: var(--warning-soft); color: var(--warning); border-color: transparent; }
.badge.blue { background: var(--info-soft); color: var(--info); border-color: transparent; }
.badge.indigo { background: var(--primary-soft); color: var(--primary); border-color: transparent; }
.dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }

/* ---------- Pagination ---------- */
.pager { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.pager .info { color: var(--text-3); font-size: 12.5px; margin-right: 8px; }
.pager button { min-width: 32px; height: 32px; border: 1px solid var(--border); background: var(--surface); color: var(--text-2); border-radius: 7px; cursor: pointer; font: 500 13px var(--font); }
.pager button.on { background: var(--primary); border-color: var(--primary); color: #fff; }
.pager button:disabled { opacity: .45; cursor: default; }

/* ---------- Progress ---------- */
.progress { height: 8px; background: var(--surface-2); border-radius: 99px; overflow: hidden; display: flex; border: 1px solid var(--border); }
.progress > span { height: 100%; transition: width .3s; }
.progress .s { background: var(--success); }
.progress .f { background: var(--danger); }

/* ---------- Modal ---------- */
.modal-bg { position: fixed; inset: 0; background: rgba(15, 23, 42, .5); z-index: 100; display: grid; place-items: center; padding: 20px; animation: fade .15s; }
.modal { background: var(--surface); border-radius: 14px; box-shadow: var(--shadow-lg); width: min(560px, 100%); max-height: calc(100vh - 40px); display: flex; flex-direction: column; animation: pop .15s; border: 1px solid var(--border); }
.modal.wide { width: min(860px, 100%); }
.modal-head { padding: 16px 20px; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 10px; }
.modal-head h3 { font-size: 16px; font-weight: 600; }
.modal-head .x { margin-left: auto; }
.modal-body { padding: 20px; overflow-y: auto; }
.modal-foot { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { transform: translateY(8px) scale(.98); opacity: 0; } }

/* ---------- Toast ---------- */
#toasts { position: fixed; right: 20px; bottom: 20px; z-index: 200; display: flex; flex-direction: column; gap: 8px; max-width: min(420px, calc(100vw - 40px)); }
.toast { background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--primary); border-radius: 10px; box-shadow: var(--shadow-lg); padding: 12px 14px; font-size: 13.5px; animation: pop .15s; white-space: pre-line; }
.toast.ok { border-left-color: var(--success); }
.toast.err { border-left-color: var(--danger); }

/* ---------- Misc ---------- */
.alert { padding: 12px 14px; border-radius: var(--radius-sm); border: 1px solid; font-size: 13.5px; }
.alert > svg, .alert.row > svg { width: 18px; height: 18px; flex: none; }
.alert.row { flex-wrap: nowrap; }
.alert.info { background: var(--info-soft); border-color: color-mix(in srgb, var(--info) 30%, transparent); color: var(--text); }
.alert.warn { background: var(--warning-soft); border-color: color-mix(in srgb, var(--warning) 35%, transparent); color: var(--text); }
.alert.err { background: var(--danger-soft); border-color: color-mix(in srgb, var(--danger) 30%, transparent); color: var(--text); }
.alert.ok { background: var(--success-soft); border-color: color-mix(in srgb, var(--success) 30%, transparent); color: var(--text); }
.muted { color: var(--text-3); }
.text-2 { color: var(--text-2); }
.small { font-size: 12.5px; }
.ok-text { color: var(--success); }
.err-text { color: var(--danger); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 2px 4px 2px 10px; background: var(--primary-soft); color: var(--primary); border-radius: 99px; font-size: 12.5px; font-weight: 500; }
.chip button { border: 0; background: none; color: inherit; cursor: pointer; width: 20px; height: 20px; border-radius: 50%; line-height: 1; }
.chip button:hover { background: rgba(0,0,0,.08); }
.checklist { max-height: 260px; overflow-y: auto; border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 6px; }
.checklist label { display: flex; gap: 8px; align-items: center; padding: 5px 8px; border-radius: 6px; cursor: pointer; }
.checklist label:hover { background: var(--surface-2); }
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); padding: 0 6px; }
.tabs button { border: 0; background: none; padding: 12px 14px; font: 500 13.5px var(--font); color: var(--text-2); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs button.on { color: var(--primary); border-bottom-color: var(--primary); }
.dropzone { border: 2px dashed var(--border-strong); border-radius: var(--radius); padding: 32px; text-align: center; color: var(--text-2); cursor: pointer; transition: border-color .12s, background .12s; }
.dropzone:hover, .dropzone.over { border-color: var(--primary); background: var(--primary-soft); }
.dropzone svg { width: 36px; height: 36px; color: var(--primary); }
.img-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 10px; }
.img-tile { position: relative; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; background: var(--surface-2); aspect-ratio: 1; }
.img-tile img { width: 100%; height: 100%; object-fit: cover; display: block; }
.img-tile .tools { position: absolute; inset: auto 4px 4px 4px; display: flex; gap: 4px; justify-content: flex-end; }
.img-tile .tools button { width: 26px; height: 26px; border-radius: 6px; border: 0; background: rgba(17,24,39,.75); color: #fff; cursor: pointer; display: grid; place-items: center; }
.img-tile .tools button svg { width: 14px; height: 14px; }
.img-tile .tag { position: absolute; top: 4px; left: 4px; }
.feat-img { width: 100%; aspect-ratio: 1; border-radius: 10px; border: 1px solid var(--border); object-fit: cover; background: var(--surface-2); display: block; }
.feat-empty { width: 100%; aspect-ratio: 1; border-radius: 10px; border: 2px dashed var(--border-strong); display: grid; place-items: center; color: var(--text-3); }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; font-size: 13.5px; }
.kv dt { color: var(--text-3); }
.kv dd { margin: 0; }
pre.code { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 12px 14px; overflow-x: auto; font: 12.5px/1.6 var(--mono); margin: 0; }
.token-box { font: 600 14px var(--mono); padding: 14px; background: var(--success-soft); border: 1px dashed var(--success); border-radius: 8px; word-break: break-all; }
.sticky-foot { position: sticky; bottom: 0; z-index: 15; background: color-mix(in srgb, var(--bg) 90%, transparent); backdrop-filter: blur(8px); border-top: 1px solid var(--border); padding: 12px 28px; margin: 24px -28px -48px; display: flex; gap: 10px; align-items: center; }

/* Editor */
.editor { border: 1px solid var(--border-strong); border-radius: var(--radius-sm); overflow: hidden; background: var(--surface); }
.editor:focus-within { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.ed-bar { display: flex; flex-wrap: wrap; gap: 2px; padding: 6px; border-bottom: 1px solid var(--border); background: var(--surface-2); }
.ed-bar button { height: 28px; min-width: 28px; padding: 0 7px; border: 0; background: none; border-radius: 6px; color: var(--text-2); cursor: pointer; font: 600 12.5px var(--font); }
.ed-bar button:hover { background: var(--surface); color: var(--text); }
.ed-bar button.on { background: var(--primary-soft); color: var(--primary); }
.ed-bar .sep { width: 1px; background: var(--border); margin: 4px 4px; }
.ed-area { min-height: 260px; max-height: 640px; overflow-y: auto; padding: 14px 16px; outline: none; line-height: 1.65; }
.ed-area img { max-width: 100%; height: auto; }
.ed-area table { border-collapse: collapse; }
.ed-area td, .ed-area th { border: 1px solid var(--border); padding: 6px; }
.ed-src { width: 100%; min-height: 300px; border: 0; border-radius: 0; font: 12.5px/1.6 var(--mono); padding: 12px 14px; resize: vertical; background: var(--surface); color: var(--text); outline: none; box-shadow: none !important; }

/* Login */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: radial-gradient(1200px 600px at 10% -10%, var(--primary-soft), transparent), var(--bg); }
.login-card { width: min(400px, 100%); padding: 32px; }
.login-card .brand-logo { width: 44px; height: 44px; font-size: 20px; color: #fff; margin-bottom: 16px; }

/* Responsive */
@media (max-width: 1100px) {
  .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .side-right { grid-template-columns: 1fr; }
}
@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: fixed; z-index: 90; left: 0; top: 0; width: 260px; transform: translateX(-100%); transition: transform .2s; }
  .sidebar.open { transform: none; box-shadow: var(--shadow-lg); }
  .menu-btn { display: inline-flex; }
  .topbar { padding: 10px 16px; }
  .content { padding: 16px; }
  .g2, .g3, .fg2, .fg3 { grid-template-columns: 1fr; }
  .sticky-foot { margin: 20px -16px -48px; padding: 12px 16px; }
}
@media (max-width: 520px) { .g4 { grid-template-columns: 1fr; } }
