/* =========================================================================
   BKOracle Admin — Function Code
   Design tokens, layout, components. Light + dark theme ([data-theme]).
   ========================================================================= */

:root {
  --font: "Be Vietnam Pro", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;

  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-2: #f8f9fc;
  --surface-3: #eef1f7;
  --border: #e3e7ef;
  --border-strong: #d2d8e4;
  --text: #0f172a;
  --text-2: #4b5870;
  --text-3: #8b97ad;

  --primary: #4f46e5;
  --primary-600: #4338ca;
  --primary-50: #eef2ff;
  --primary-100: #e0e7ff;
  --primary-ring: rgba(79, 70, 229, .28);
  --accent: #0ea5b7;

  --success: #15803d;
  --success-bg: #dcfce7;
  --warning: #b45309;
  --warning-bg: #fef3c7;
  --danger: #dc2626;
  --danger-bg: #fee2e2;
  --info: #0369a1;
  --info-bg: #e0f2fe;

  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 14px;
  --radius-xl: 20px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, .06);
  --shadow: 0 1px 2px rgba(15, 23, 42, .04), 0 6px 18px -6px rgba(15, 23, 42, .10);
  --shadow-lg: 0 28px 60px -16px rgba(15, 23, 42, .30);

  --sidebar-w: 256px;
  --sidebar-mini: 72px;
  --topbar-h: 60px;
  --row-pad: 11px;
  --ease: cubic-bezier(.2, .8, .2, 1);

  color-scheme: light;
}

[data-theme="dark"] {
  --bg: #0a0f1d;
  --surface: #111830;
  --surface-2: #151d36;
  --surface-3: #1b2542;
  --border: #233054;
  --border-strong: #2f3e66;
  --text: #e7ebf5;
  --text-2: #a9b4cc;
  --text-3: #6d7a98;
  --primary: #8b93ff;
  --primary-600: #6f78ff;
  --primary-50: rgba(139, 147, 255, .12);
  --primary-100: rgba(139, 147, 255, .22);
  --primary-ring: rgba(139, 147, 255, .35);
  --success: #4ade80;
  --success-bg: rgba(74, 222, 128, .14);
  --warning: #fbbf24;
  --warning-bg: rgba(251, 191, 36, .14);
  --danger: #f87171;
  --danger-bg: rgba(248, 113, 113, .14);
  --info: #38bdf8;
  --info-bg: rgba(56, 189, 248, .14);
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px -8px rgba(0, 0, 0, .5);
  --shadow-lg: 0 30px 70px -20px rgba(0, 0, 0, .7);
  color-scheme: dark;
}

[data-density="compact"] { --row-pad: 7px; }

/* ---------- Reset ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { font-size: 14px; -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 1rem;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
h1, h2, h3, h4, h5, h6 { margin: 0; font-weight: 650; line-height: 1.25; letter-spacing: -.01em; }
p { margin: 0; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
code, kbd, .mono { font-family: var(--mono); font-size: .92em; }
img, svg { vertical-align: middle; }
[hidden] { display: none !important; }
::selection { background: var(--primary-100); }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

.icon { width: 18px; height: 18px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.icon-sm { width: 15px; height: 15px; }
.icon-lg { width: 22px; height: 22px; }

/* ---------- App shell ---------- */
/* Trang không cuộn: chỉ vùng .main cuộn khi nội dung thật sự dài hơn màn hình. */
.app { display: flex; height: 100vh; }

.sidebar {
  position: fixed; inset: 0 auto 0 0; z-index: 40;
  width: var(--sidebar-w);
  display: flex; flex-direction: column;
  background: var(--surface);
  border-right: 1px solid var(--border);
  transition: transform .25s var(--ease);
}
.brand {
  display: flex; align-items: center; gap: 12px;
  height: var(--topbar-h); padding: 0 20px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
}
.brand:hover { text-decoration: none; }
.brand-mark {
  flex: none; /* không bị bóp khi menu thu gọn */
  width: 34px; height: 34px; border-radius: 10px;
  display: grid; place-items: center;
  background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 55%, #06b6d4 100%);
  color: #fff; box-shadow: 0 6px 16px -6px rgba(99, 102, 241, .8);
}
.brand-mark .icon { width: 19px; height: 19px; stroke-width: 2.2; }
.brand-text strong { display: block; font-size: 15px; letter-spacing: -.01em; }
.brand-text span { display: block; font-size: 11.5px; color: var(--text-3); margin-top: -1px; }

.nav { flex: 1; overflow-y: auto; padding: 14px 12px; }
.nav-section { margin: 16px 10px 6px; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .08em; color: var(--text-3); }
.nav-section:first-child { margin-top: 2px; }
.nav-link {
  display: flex; align-items: center; gap: 11px;
  padding: 9px 12px; margin: 2px 0;
  border-radius: var(--radius);
  color: var(--text-2); font-weight: 500;
  transition: background .15s, color .15s;
}
.nav-link:hover { background: var(--surface-3); color: var(--text); text-decoration: none; }
.nav-link.active { background: var(--primary-50); color: var(--primary); }
.nav-link.active .icon { stroke-width: 2.2; }
.nav-link .nav-badge { margin-left: auto; font-size: 11px; font-weight: 600; padding: 1px 8px; border-radius: 999px; background: var(--surface-3); color: var(--text-2); }
.nav-link.active .nav-badge { background: var(--primary-100); color: var(--primary); }

.sidebar-foot { padding: 14px; border-top: 1px solid var(--border); }
.conn-card {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: var(--radius);
  background: var(--surface-2); border: 1px solid var(--border);
  font-size: 12.5px; color: var(--text-2);
}
.conn-card strong { color: var(--text); font-weight: 600; }
.conn-card .meta { line-height: 1.35; min-width: 0; }
.conn-card .meta span { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--text-3); flex: none; box-shadow: 0 0 0 3px var(--surface-3); }
.dot.ok { background: #22c55e; box-shadow: 0 0 0 3px rgba(34, 197, 94, .18); }
.dot.err { background: #ef4444; box-shadow: 0 0 0 3px rgba(239, 68, 68, .18); }

.main { flex: 1; min-width: 0; margin-left: var(--sidebar-w); display: flex; flex-direction: column; height: 100vh; overflow-y: auto; }

/* ---------- Menu thu gọn: html[data-nav] = click | hover (mặc định mở rộng) ---------- */
.sidebar-toggle { display: none; width: 100%; border: 0; background: transparent; font: inherit; text-align: left; cursor: pointer; margin: 0 0 10px; }
.sidebar-toggle .icon { transition: transform .2s var(--ease); }
.brand, .nav-link, .nav-section { white-space: nowrap; }
@media (min-width: 1025px) {
  html[data-nav="click"] .sidebar-toggle { display: flex; }
  /* Khi đang co/giãn: luôn cắt chữ tràn, không thanh cuộn ngang; mọi khoảng cách giữ nguyên để icon không xê dịch. */
  html[data-nav] .sidebar { overflow: hidden; transition: transform .25s var(--ease), width .22s var(--ease), box-shadow .22s; }
  html[data-nav] .nav { overflow-x: hidden; }
  html[data-nav] .main { transition: margin-left .22s var(--ease); }
  /* Chữ (kể cả tiêu đề nhóm) chỉ hiện khi menu đã mở gần hết; thu lại thì tắt ngay. */
  html[data-nav] :is(.nav-text, .brand-text, .nav-badge, .conn-card .meta) { transition: opacity .14s .16s; }
  html[data-nav] .nav-section { position: relative; transition: color .14s .16s; }
  html[data-nav] .nav-section::after { content: ""; position: absolute; left: 2px; right: 2px; top: 50%; height: 1px; background: var(--border); opacity: 0; transition: opacity .1s; }
  html[data-nav="hover"] .main, html[data-nav="click"]:not([data-nav-open]) .main { margin-left: var(--sidebar-mini); }
  /* Rê chuột: chờ .12s mới mở (lướt qua không bật ra), chữ hiện sau khi độ rộng gần xong. */
  html[data-nav="hover"] .sidebar:is(:hover, :focus-within) {
    box-shadow: var(--shadow-lg); transition-delay: .12s;
    :is(.nav-text, .brand-text, .nav-badge, .conn-card .meta) { transition-delay: .26s; }
    .nav-section { transition-delay: .26s; }
  }
  html[data-nav="hover"] .sidebar:not(:hover, :focus-within),
  html[data-nav="click"]:not([data-nav-open]) .sidebar {
    width: var(--sidebar-mini);
    :is(.nav-text, .brand-text, .nav-badge, .conn-card .meta) { opacity: 0; pointer-events: none; transition: opacity .06s; }
    /* Tiêu đề nhóm giữ nguyên chiều cao, chữ thay bằng một vạch ngắn. */
    .nav-section { color: transparent; transition: color .06s; }
    .nav-section::after { opacity: 1; transition: opacity .1s .1s; }
    .sidebar-toggle .icon { transform: rotate(180deg); }
  }
}

.topbar {
  position: sticky; top: 0; z-index: 30;
  height: var(--topbar-h);
  display: flex; align-items: center; gap: 12px;
  padding: 0 28px;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: saturate(160%) blur(10px);
  border-bottom: 1px solid var(--border);
}
.topbar-title { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-3); min-width: 0; }
.topbar-title strong { color: var(--text); font-weight: 600; font-size: 14px; }
.topbar-spacer { flex: 1; }
.search-trigger {
  display: flex; align-items: center; gap: 10px;
  width: 300px; max-width: 34vw; height: 38px; padding: 0 10px 0 12px;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); color: var(--text-3);
  transition: border-color .15s, box-shadow .15s;
}
.search-trigger:hover { border-color: var(--border-strong); box-shadow: var(--shadow-sm); }
.search-trigger span { flex: 1; text-align: left; font-size: 13px; }
kbd {
  display: inline-flex; align-items: center; justify-content: center; min-width: 22px; height: 21px; padding: 0 6px;
  font-size: 11px; font-weight: 500; color: var(--text-2);
  background: var(--surface-2); border: 1px solid var(--border); border-bottom-width: 2px; border-radius: 5px;
}
.icon-btn {
  display: inline-grid; place-items: center;
  width: 38px; height: 38px; border-radius: var(--radius);
  border: 1px solid transparent; background: transparent; color: var(--text-2);
  transition: background .15s, color .15s, border-color .15s;
}
.icon-btn:hover { background: var(--surface-3); color: var(--text); }
.icon-btn.sm { width: 30px; height: 30px; border-radius: 8px; }
.icon-btn.danger:hover { background: var(--danger-bg); color: var(--danger); }
.menu-toggle { display: none; }
.theme-dark { display: none; }
[data-theme="dark"] .theme-light { display: none; }
[data-theme="dark"] .theme-dark { display: inline; }

.user-menu { position: relative; }
.user-chip {
  display: flex; align-items: center; gap: 10px;
  padding: 4px 10px 4px 4px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--surface);
}
.user-chip:hover { border-color: var(--border-strong); }
.user-chip .name { font-size: 13px; font-weight: 600; line-height: 1.1; text-align: left; }
.user-chip .role { display: block; font-size: 11px; color: var(--text-3); font-weight: 500; }
.avatar {
  display: grid; place-items: center; flex: none;
  width: 32px; height: 32px; border-radius: 50%;
  background: linear-gradient(135deg, #6366f1, #a855f7);
  color: #fff; font-weight: 700; font-size: 12.5px; letter-spacing: .02em;
}
.avatar.xl { width: 84px; height: 84px; font-size: 28px; border-radius: 24px; box-shadow: 0 16px 32px -14px rgba(99, 102, 241, .9); }

.dropdown {
  position: absolute; right: 0; top: calc(100% + 8px); z-index: 60;
  min-width: 240px; padding: 6px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  opacity: 0; transform: translateY(-4px) scale(.98); pointer-events: none;
  transition: opacity .14s, transform .14s var(--ease);
}
.dropdown.open { opacity: 1; transform: none; pointer-events: auto; }
.dropdown-head { padding: 10px 12px 12px; border-bottom: 1px solid var(--border); margin-bottom: 6px; }
.dropdown-head strong { display: block; }
.dropdown-head span { font-size: 12px; color: var(--text-3); }
.dropdown-item {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 8px 12px; border: 0; border-radius: 8px; background: none;
  color: var(--text-2); font-size: 13.5px; text-align: left;
}
.dropdown-item:hover { background: var(--surface-3); color: var(--text); text-decoration: none; }
.dropdown-item.danger:hover { background: var(--danger-bg); color: var(--danger); }
.dropdown-sep { height: 1px; background: var(--border); margin: 6px 0; }

.content { flex: 1; width: 100%; max-width: 1480px; margin: 0 auto; padding: 24px 28px 24px; }

/* Trang bảng (Function, Nhóm): bảng kéo hết chiều cao còn lại, số dòng tự tính theo chiều cao này. */
body[data-page="func"] .content, body[data-page="group"] .content { height: calc(100vh - var(--topbar-h)); flex: none; display: flex; flex-direction: column; }
[data-crud-root] { flex: 1; min-height: 0; display: flex; flex-direction: column; }
[data-crud-root] .summary-chips { min-height: 30px; } /* giữ chỗ trước khi số đếm tải xong để bảng không bị đẩy xuống */
[data-crud-root] > .card { flex: 1; min-height: 0; display: flex; flex-direction: column; overflow: hidden; }
[data-crud-root] .table-wrap { flex: 1; min-height: 0; overflow: auto; }
.sidebar-backdrop { display: none; }

/* ---------- Page header ---------- */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head h1 { font-size: 23px; font-weight: 700; letter-spacing: -.02em; }
.page-head p { color: var(--text-2); margin-top: 4px; }
.page-head .table-name { font-family: var(--mono); font-size: 12px; color: var(--text-3); background: var(--surface-3); padding: 1px 7px; border-radius: 6px; }
.page-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 38px; padding: 0 15px;
  border-radius: var(--radius); border: 1px solid var(--border-strong);
  background: var(--surface); color: var(--text);
  font-size: 13.5px; font-weight: 600; white-space: nowrap;
  transition: background .15s, border-color .15s, box-shadow .15s, transform .05s, color .15s;
  user-select: none;
}
.btn:hover { background: var(--surface-2); border-color: var(--text-3); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn:disabled, .btn.disabled { opacity: .55; pointer-events: none; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; box-shadow: 0 6px 14px -6px var(--primary-ring), inset 0 1px 0 rgba(255, 255, 255, .15); }
.btn-primary:hover { background: var(--primary-600); border-color: var(--primary-600); color: #fff; }
[data-theme="dark"] .btn-primary { color: #0b1020; }
.btn-ghost { border-color: transparent; background: transparent; color: var(--text-2); }
.btn-ghost:hover { background: var(--surface-3); border-color: transparent; color: var(--text); }
.btn-soft { background: var(--primary-50); border-color: transparent; color: var(--primary); }
.btn-soft:hover { background: var(--primary-100); border-color: transparent; }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { background: #b91c1c; border-color: #b91c1c; color: #fff; }
.btn-danger-soft { background: var(--danger-bg); border-color: transparent; color: var(--danger); }
.btn-danger-soft:hover { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-sm { height: 32px; padding: 0 11px; font-size: 12.5px; border-radius: 8px; }
.btn-lg { height: 46px; padding: 0 20px; font-size: 15px; }
.btn-block { width: 100%; }
.btn .spinner { width: 15px; height: 15px; }

.spinner {
  width: 18px; height: 18px; border-radius: 50%;
  border: 2px solid currentColor; border-right-color: transparent;
  animation: spin .7s linear infinite; display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Cards ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-sm); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.card-head h2, .card-head h3 { font-size: 15px; font-weight: 650; }
.card-head p { font-size: 12.5px; color: var(--text-3); margin-top: 2px; }
.card-body { padding: 18px 20px; }
.card-foot { padding: 12px 20px; border-top: 1px solid var(--border); }

.grid { display: grid; gap: 18px; }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-main { grid-template-columns: minmax(0, 1.65fr) minmax(0, 1fr); }
.stack { display: flex; flex-direction: column; gap: 18px; }

/* KPI */
.kpi { position: relative; overflow: hidden; padding: 18px 20px; }
.kpi-top { display: flex; align-items: center; justify-content: space-between; }
.kpi-label { font-size: 12.5px; font-weight: 600; color: var(--text-2); }
.kpi-icon { width: 38px; height: 38px; border-radius: 11px; display: grid; place-items: center; }
.kpi-value { font-size: 30px; font-weight: 700; letter-spacing: -.03em; margin-top: 10px; line-height: 1.1; font-variant-numeric: tabular-nums; }
.kpi-sub { margin-top: 6px; font-size: 12.5px; color: var(--text-3); }
.kpi-bar { height: 6px; border-radius: 99px; background: var(--surface-3); overflow: hidden; margin-top: 12px; }
.kpi-bar > span { display: block; height: 100%; border-radius: inherit; background: linear-gradient(90deg, #22c55e, #16a34a); transition: width .6s var(--ease); }
.tone-indigo { background: var(--primary-50); color: var(--primary); }
.tone-violet { background: rgba(139, 92, 246, .12); color: #7c3aed; }
.tone-green { background: var(--success-bg); color: var(--success); }
.tone-amber { background: var(--warning-bg); color: var(--warning); }
.tone-cyan { background: rgba(14, 165, 183, .12); color: var(--accent); }
[data-theme="dark"] .tone-violet { color: #c4b5fd; }

/* ---------- Form controls ---------- */
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > label, .label { font-size: 12.5px; font-weight: 600; color: var(--text-2); display: flex; align-items: center; gap: 6px; }
.field > label .req { color: var(--danger); }
.field .hint { font-size: 12px; color: var(--text-3); }
.field .error-text { font-size: 12px; color: var(--danger); display: none; }
.field .hint-warn { font-size: 12px; color: var(--warning); }
.field .hint-warn:empty { display: none; }
.field.has-error .error-text { display: block; }
.field.has-error .input, .field.has-error .select, .field.has-error .textarea { border-color: var(--danger); box-shadow: 0 0 0 3px var(--danger-bg); }
.field.span-2 { grid-column: span 2; }
.field .counter { margin-left: auto; font-weight: 500; font-size: 11px; color: var(--text-3); font-variant-numeric: tabular-nums; }

.input, .select, .textarea {
  width: 100%; height: 38px; padding: 0 12px;
  border: 1px solid var(--border-strong); border-radius: var(--radius);
  background: var(--surface); color: var(--text);
  font-size: 13.5px;
  transition: border-color .15s, box-shadow .15s, background .15s;
}
.textarea { height: auto; min-height: 84px; padding: 9px 12px; resize: vertical; line-height: 1.5; }
.input::placeholder, .textarea::placeholder { color: var(--text-3); }
.input:hover, .select:hover, .textarea:hover { border-color: var(--text-3); }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-ring); }
.input[readonly], .textarea[readonly] { background: var(--surface-2); color: var(--text-2); }
.input.mono, .textarea.mono { font-family: var(--mono); font-size: 12.5px; }
.select {
  appearance: none; padding-right: 34px; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%238b97ad' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center;
}
/* Select tuỳ biến bằng CSS gốc (Chrome 135+, appearance: base-select); trình duyệt cũ giữ select mặc định. */
@supports (appearance: base-select) {
  .select, .select::picker(select) { appearance: base-select; }
  .select { display: flex; align-items: center; }
  .select::picker-icon { display: none; }
  .select:open { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-ring); }
  .select::picker(select) {
    margin-block: 6px; padding: 5px; max-height: 320px; overflow-y: auto;
    border: 1px solid var(--border); border-radius: 12px;
    background: var(--surface); color: var(--text); box-shadow: var(--shadow-lg);
    opacity: 0; translate: 0 -4px;
    transition: opacity .14s ease, translate .14s ease, display .14s allow-discrete, overlay .14s allow-discrete;
  }
  .select:open::picker(select) { opacity: 1; translate: 0 0; }
  @starting-style { .select:open::picker(select) { opacity: 0; translate: 0 -4px; } }
  .select option { display: flex; align-items: center; gap: 10px; min-height: 34px; padding: 6px 10px; border-radius: 8px; font-size: 13px; cursor: pointer; }
  .select option:hover, .select option:focus-visible { background: var(--surface-3); outline: none; }
  .select option:checked { background: var(--primary-50); color: var(--primary); font-weight: 600; }
  .select option::checkmark { order: 1; margin-left: auto; color: var(--primary); }
}
.input-icon { position: relative; }
.input-icon > .icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--text-3); pointer-events: none; }
.input-icon > .input { padding-left: 38px; }
.input-icon > .input-addon { position: absolute; right: 6px; top: 50%; transform: translateY(-50%); }
.input-group { display: flex; gap: 6px; }
.input-group > .input { flex: 1; }

.switch { position: relative; display: inline-flex; align-items: center; gap: 10px; cursor: pointer; user-select: none; font-size: 13.5px; font-weight: 500; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch .track { width: 38px; height: 22px; border-radius: 99px; background: var(--border-strong); position: relative; transition: background .2s; flex: none; }
.switch .track::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .25); transition: transform .2s var(--ease); }
.switch input:checked + .track { background: #22c55e; }
.switch input:checked + .track::after { transform: translateX(16px); }
.switch input:focus-visible + .track { outline: 2px solid var(--primary); outline-offset: 2px; }
.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-size: 13.5px; }
.check input { width: 16px; height: 16px; accent-color: var(--primary); cursor: pointer; margin: 0; }

.segmented { display: inline-flex; padding: 3px; gap: 2px; background: var(--surface-3); border-radius: var(--radius); }
.segmented button { white-space: nowrap; border: 0; background: transparent; padding: 6px 12px; border-radius: 8px; font-size: 12.5px; font-weight: 600; color: var(--text-2); }
.segmented button.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }

/* ---------- Badges & chips ---------- */
.badge { display: inline-flex; align-items: center; gap: 6px; height: 23px; padding: 0 9px; border-radius: 99px; font-size: 11.5px; font-weight: 600; white-space: nowrap; background: var(--surface-3); color: var(--text-2); }
.badge .dot { width: 7px; height: 7px; box-shadow: none; }
.badge.on { background: var(--success-bg); color: var(--success); }
.badge.on .dot { background: currentColor; }
.badge.off { background: var(--surface-3); color: var(--text-3); }
.badge.off .dot { background: currentColor; }
.badge.warn { background: var(--warning-bg); color: var(--warning); }
.badge.info { background: var(--info-bg); color: var(--info); }
.badge.primary { background: var(--primary-50); color: var(--primary); }
.badge.danger { background: var(--danger-bg); color: var(--danger); }
.badge.outline { background: transparent; border: 1px solid var(--border-strong); }

.rt { display: inline-flex; align-items: center; height: 22px; padding: 0 8px; border-radius: 6px; font-family: var(--mono); font-size: 11px; font-weight: 600; letter-spacing: .01em; white-space: nowrap; background: var(--surface-3); color: var(--text-2); }
.rt[data-rt="RETURN_LIST"] { background: rgba(59, 130, 246, .12); color: #2563eb; }
.rt[data-rt="RETURN_PAGING"] { background: rgba(139, 92, 246, .13); color: #7c3aed; }
.rt[data-rt="RETURN_SINGLE"] { background: rgba(20, 184, 166, .13); color: #0f766e; }
.rt[data-rt="RETURN_SCALAR"] { background: rgba(245, 158, 11, .15); color: #b45309; }
.rt[data-rt="RETURN_NONE"] { background: rgba(100, 116, 139, .14); color: #475569; }
.rt[data-rt="RETURN_MULTIPLE"] { background: rgba(236, 72, 153, .12); color: #be185d; }
[data-theme="dark"] .rt[data-rt="RETURN_LIST"] { color: #93c5fd; }
[data-theme="dark"] .rt[data-rt="RETURN_PAGING"] { color: #c4b5fd; }
[data-theme="dark"] .rt[data-rt="RETURN_SINGLE"] { color: #5eead4; }
[data-theme="dark"] .rt[data-rt="RETURN_SCALAR"] { color: #fcd34d; }
[data-theme="dark"] .rt[data-rt="RETURN_NONE"] { color: #cbd5e1; }
[data-theme="dark"] .rt[data-rt="RETURN_MULTIPLE"] { color: #f9a8d4; }

.chip { display: inline-flex; align-items: center; gap: 7px; height: 30px; padding: 0 12px; border-radius: 99px; border: 1px solid var(--border); background: var(--surface); color: var(--text-2); font-size: 12.5px; font-weight: 600; transition: all .15s; }
.chip:hover { border-color: var(--border-strong); color: var(--text); }
.chip.active { background: var(--primary-50); border-color: var(--primary-100); color: var(--primary); }
.chip .count { font-variant-numeric: tabular-nums; color: var(--text); }
.chip.active .count { color: var(--primary); }

.code-pill { display: inline-flex; align-items: center; gap: 6px; font-family: var(--mono); font-size: 12.5px; font-weight: 600; color: var(--text); }
.copy-btn { opacity: 0; border: 0; background: transparent; color: var(--text-3); padding: 2px; border-radius: 5px; display: inline-grid; place-items: center; transition: opacity .15s, color .15s, background .15s; }
tr:hover .copy-btn, .copy-btn:focus-visible, .copy-always .copy-btn { opacity: 1; }
.copy-btn:hover { color: var(--primary); background: var(--primary-50); }

/* ---------- Toolbar ---------- */
.toolbar { display: flex; align-items: center; gap: 10px; padding: 14px 16px; flex-wrap: wrap; border-bottom: 1px solid var(--border); }
.toolbar .search { flex: 1 1 220px; min-width: 200px; }
/* Bộ lọc rộng cố định, một dòng: chọn giá trị dài không làm thanh công cụ đổi kích thước. */
.toolbar .select { width: 190px; flex: none; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; line-height: 36px; }
.toolbar .tools { display: flex; align-items: center; gap: 2px; margin-left: auto; }
.summary-chips { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }

/* ---------- Table ---------- */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 13.5px; }
.table th {
  position: sticky; top: 0; z-index: 1;
  padding: 10px 14px; text-align: left;
  font-size: 11.5px; font-weight: 650; letter-spacing: .04em; text-transform: uppercase;
  color: var(--text-3); background: var(--surface-2);
  border-bottom: 1px solid var(--border); white-space: nowrap;
}
.table th.sortable { cursor: pointer; user-select: none; }
.table th.sortable:hover { color: var(--text); }
.table th .sort { display: inline-block; width: 12px; margin-left: 4px; opacity: .35; }
.table th.sorted { color: var(--primary); }
.table th.sorted .sort { opacity: 1; }
.table td.nowrap, .table td .nowrap { white-space: nowrap; }
.table td { padding: var(--row-pad) 14px; border-bottom: 1px solid var(--border); vertical-align: middle; color: var(--text); }
.table tbody tr { transition: background .12s; cursor: pointer; }
.table tbody tr:hover { background: var(--surface-2); }
.table tbody tr.selected { background: var(--primary-50); }
.table tbody tr:last-child td { border-bottom: 0; }
.table .col-check { width: 44px; padding-right: 0; }
.table .col-actions { width: 1%; white-space: nowrap; text-align: right; }
.table .muted { color: var(--text-3); }
.table .sub { display: block; font-size: 12px; color: var(--text-3); margin-top: 1px; max-width: 360px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.table .truncate { display: block; max-width: 300px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.row-actions { display: inline-flex; gap: 2px; opacity: .0; transition: opacity .15s; }
tr:hover .row-actions, tr:focus-within .row-actions { opacity: 1; }
@media (hover: none) { .row-actions { opacity: 1; } }

.skeleton { display: block; height: 12px; border-radius: 6px; background: linear-gradient(90deg, var(--surface-3) 0%, var(--surface-2) 50%, var(--surface-3) 100%); background-size: 200% 100%; animation: shimmer 1.2s infinite; }
@keyframes shimmer { 0% { background-position: 100% 0; } 100% { background-position: -100% 0; } }

.empty { padding: 56px 20px; text-align: center; color: var(--text-2); }
.empty-art { width: 76px; height: 76px; margin: 0 auto 16px; border-radius: 22px; display: grid; place-items: center; background: var(--primary-50); color: var(--primary); }
.empty-art .icon { width: 34px; height: 34px; stroke-width: 1.6; }
.empty h3 { font-size: 16px; color: var(--text); margin-bottom: 6px; }
.empty p { max-width: 460px; margin: 0 auto 16px; }
.empty.error .empty-art { background: var(--danger-bg); color: var(--danger); }
.empty .detail { font-family: var(--mono); font-size: 12px; color: var(--text-3); margin-top: -6px; margin-bottom: 16px; word-break: break-word; }

.pager { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 16px; border-top: 1px solid var(--border); flex-wrap: wrap; font-size: 13px; color: var(--text-2); }
.pager-pages { display: flex; gap: 4px; align-items: center; }
.pager-pages button { min-width: 32px; height: 32px; padding: 0 8px; border-radius: 8px; border: 1px solid transparent; background: transparent; color: var(--text-2); font-weight: 600; font-size: 13px; font-variant-numeric: tabular-nums; }
.pager-pages button:hover:not(:disabled) { background: var(--surface-3); color: var(--text); }
.pager-pages button.active { background: var(--primary); color: #fff; }
[data-theme="dark"] .pager-pages button.active { color: #0b1020; }
.pager-pages button:disabled { opacity: .4; cursor: default; }
.pager-pages .gap { padding: 0 4px; color: var(--text-3); }
.pager .select { height: 32px; width: auto; font-size: 13px; }

.bulk-bar {
  position: fixed; left: 50%; bottom: 24px; z-index: 50;
  display: flex; align-items: center; gap: 10px;
  padding: 8px 8px 8px 18px; border-radius: 16px;
  background: #0f172a; color: #e2e8f0; box-shadow: var(--shadow-lg);
  transform: translate(-50%, 140%); opacity: 0;
  transition: transform .25s var(--ease), opacity .2s;
}
.bulk-bar.show { transform: translate(-50%, 0); opacity: 1; }
.bulk-bar strong { color: #fff; margin-right: 6px; font-variant-numeric: tabular-nums; }
.bulk-bar .btn { height: 34px; background: rgba(255, 255, 255, .08); border-color: transparent; color: #e2e8f0; }
.bulk-bar .btn:hover { background: rgba(255, 255, 255, .16); }
.bulk-bar .btn.danger:hover { background: #dc2626; color: #fff; }
[data-theme="dark"] .bulk-bar { background: #e7ebf5; color: #1e293b; }
[data-theme="dark"] .bulk-bar strong { color: #0f172a; }
[data-theme="dark"] .bulk-bar .btn { background: rgba(15, 23, 42, .06); color: #1e293b; }

/* ---------- Modal / dialog ---------- */
.modal-root { position: fixed; inset: 0; z-index: 80; display: grid; grid-template-columns: minmax(0, 1fr); place-items: center; padding: 24px; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(15, 23, 42, .5); backdrop-filter: blur(3px); animation: fade .18s ease; }
.modal {
  position: relative; width: 100%; max-width: 560px; max-height: calc(100vh - 48px);
  display: flex; flex-direction: column;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  animation: pop .22s var(--ease);
}
.modal.lg { max-width: 1060px; }
.modal:focus { outline: none; }
.modal.md { max-width: 720px; }
.modal-head { display: flex; align-items: flex-start; gap: 14px; padding: 20px 22px 16px; border-bottom: 1px solid var(--border); }
.modal-head .title { flex: 1; min-width: 0; }
.modal-head h2 { font-size: 18px; font-weight: 700; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.modal-head .subtitle { color: var(--text-3); font-size: 13px; margin-top: 3px; }
.modal-head .mode { display: inline-flex; align-items: center; gap: 6px; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; padding: 3px 8px; border-radius: 6px; background: var(--surface-3); color: var(--text-2); }
.modal-head .mode.edit { background: var(--warning-bg); color: var(--warning); }
.modal-head .mode.create { background: var(--primary-50); color: var(--primary); }
.modal-body { flex: 1; overflow-y: auto; padding: 20px 22px; }
.modal-foot { display: flex; align-items: center; gap: 8px; padding: 14px 22px; border-top: 1px solid var(--border); background: var(--surface-2); border-radius: 0 0 var(--radius-xl) var(--radius-xl); }
.modal-foot .spacer { flex: 1; }
.modal-foot .shortcut-hint { font-size: 12px; color: var(--text-3); display: flex; align-items: center; gap: 6px; }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: translateY(10px) scale(.98); } }

.detail-layout { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 22px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px 18px; align-content: start; }
.side-panel { display: flex; flex-direction: column; gap: 14px; }
.panel { border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--surface-2); }
.panel-head { display: flex; align-items: center; gap: 8px; padding: 11px 14px; border-bottom: 1px solid var(--border); font-size: 12.5px; font-weight: 650; color: var(--text-2); }
.panel-head .icon { color: var(--primary); }
.panel-head .right { margin-left: auto; }
.panel-body { padding: 12px 14px; font-size: 13px; }
.panel .empty-mini { color: var(--text-3); font-size: 12.5px; padding: 6px 0; }

.view-value { min-height: 38px; display: flex; align-items: center; gap: 8px; padding: 8px 0; color: var(--text); font-size: 14px; word-break: break-word; border-bottom: 1px dashed var(--border); }
.view-value.multiline { white-space: pre-wrap; align-items: flex-start; }
.view-value .muted { color: var(--text-3); }
.view-value.mono { font-family: var(--mono); font-size: 12.5px; }

.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; font-size: 12.5px; }
.kv dt { color: var(--text-3); }
.kv dd { margin: 0; color: var(--text); text-align: right; word-break: break-word; }

.fnkey-box { font-family: var(--mono); font-size: 11.5px; line-height: 1.55; word-break: break-all; padding: 10px 12px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--border); color: var(--text); }
.fnkey-plain { display: flex; align-items: center; gap: 8px; margin-top: 8px; font-family: var(--mono); font-size: 12px; color: var(--text-2); }

.args { width: 100%; border-collapse: collapse; font-size: 12px; }
.args th { text-align: left; font-weight: 600; color: var(--text-3); padding: 4px 6px; border-bottom: 1px solid var(--border); font-size: 11px; text-transform: uppercase; letter-spacing: .04em; }
.args td { padding: 5px 6px; border-bottom: 1px solid var(--border); font-family: var(--mono); }
.args tr:last-child td { border-bottom: 0; }
.io { font-size: 10.5px; font-weight: 700; padding: 1px 5px; border-radius: 4px; background: var(--surface-3); color: var(--text-2); }
.io.out { background: var(--warning-bg); color: var(--warning); }
.io.inout { background: var(--info-bg); color: var(--info); }
.suggest { display: flex; align-items: flex-start; gap: 10px; padding: 10px 12px; border-radius: var(--radius); background: var(--primary-50); color: var(--text); font-size: 12.5px; margin-top: 10px; }
.suggest .icon { color: var(--primary); margin-top: 1px; }

.autocomplete { position: relative; }
.ac-list { position: absolute; left: 0; right: 0; top: calc(100% + 4px); z-index: 90; max-height: 260px; overflow-y: auto; padding: 4px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-lg); }
.ac-item { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 7px 10px; border-radius: 7px; font-family: var(--mono); font-size: 12.5px; cursor: pointer; }
.ac-item small { font-family: var(--font); color: var(--text-3); font-size: 11px; }
.ac-item:hover, .ac-item.active { background: var(--primary-50); color: var(--primary); }
.ac-item .ac-label { font-family: var(--font); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ac-item.ac-create, .ac-item.ac-plain { justify-content: flex-start; font-family: var(--font); font-weight: 600; }
.ac-item.ac-create { color: var(--primary); border-top: 1px solid var(--border); border-radius: 0 0 7px 7px; margin-top: 2px; }
.ac-item.ac-plain { color: var(--text-3); }
.ac-empty { padding: 8px 10px; font-size: 12.5px; color: var(--text-3); }

/* Form trong modal: mỗi ô một dòng, riêng ô chọn ngắn (.half) đứng cạnh nhau */
.form-grid.one { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form-grid.one > .field { grid-column: span 2; }
.form-grid.one > .field.half { grid-column: span 1; }
/* Chọn 1 trong 2 (Loại chức năng, Cách áp dụng): thanh gạt cao bằng ô nhập */
.segmented.seg-full { display: flex; width: 100%; height: 38px; }
.segmented.seg-full button { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; font-size: 13px; }
.segmented.seg-full button.active { color: var(--primary); }
.field.has-error .seg-full { box-shadow: 0 0 0 1px var(--danger); }
.side-stack { display: flex; flex-direction: column; gap: 12px; margin-top: 18px; }
.side-stack:empty { display: none; }

/* Kiểu trả về: thẻ chọn kiểu radio */
.rt-pick { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.rt-opt {
  position: relative; display: flex; align-items: center; gap: 11px; min-width: 0;
  padding: 11px 13px; border: 1.5px solid var(--border); border-radius: 12px;
  background: var(--surface); color: var(--text); text-align: left; cursor: pointer;
  transition: border-color .15s, background .15s, box-shadow .15s;
}
.rt-opt:hover { border-color: var(--border-strong); background: var(--surface-2); }
.rt-opt .rt-radio { width: 18px; height: 18px; flex: none; border-radius: 50%; border: 2px solid var(--border-strong); display: grid; place-items: center; transition: border-color .15s; }
.rt-opt .rt-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.rt-opt .rt-text b { font-family: var(--mono); font-size: 12.5px; font-weight: 700; letter-spacing: .02em; }
.rt-opt .rt-text small { font-size: 12px; color: var(--text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rt-opt.active { border-color: var(--primary); background: var(--primary-50); box-shadow: 0 0 0 3px var(--primary-50); }
.rt-opt.active .rt-radio { border-color: var(--primary); }
.rt-opt.active .rt-radio::after { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--primary); }
.rt-opt.active .rt-text b { color: var(--primary); }
.rt-opt.suggested::after { content: "Gợi ý"; position: absolute; top: -9px; right: 10px; padding: 1px 7px; border-radius: 99px; font-size: 10.5px; font-weight: 700; background: var(--primary); color: #fff; }
.field.has-error .rt-opt { border-color: var(--danger); }

/* Modal sửa gần toàn màn hình, hai cột, không cuộn */
.modal.xl { max-width: min(1320px, 96vw); height: min(860px, 94vh); max-height: none; }
.modal-body.split { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 24px; overflow: hidden; }
.modal-body.split > .pane { min-height: 0; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; }
.modal-body.split .form-grid { gap: 14px 16px; }
.panel.grow { flex: 1; min-height: 160px; display: flex; flex-direction: column; }
.panel.grow > .panel-body { flex: 1; min-height: 0; overflow: auto; }
.panel-body > .suggest:first-child { margin-top: 0; }
.audit-line { display: flex; flex-wrap: wrap; gap: 4px 18px; font-size: 12.5px; color: var(--text-3); padding: 0 2px; }
.audit-line b { color: var(--text-2); font-weight: 600; }
@media (max-width: 960px) {
  .modal.xl { height: auto; max-height: 94vh; }
  .modal-body.split { grid-template-columns: minmax(0, 1fr); overflow-y: auto; }
  .modal-body.split > .pane { overflow: visible; }
}

/* Tạo nhóm mới ngay trong form function */
.combo-new { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.6fr) auto auto; gap: 8px; align-items: center; margin-top: 8px; padding: 10px; border: 1px dashed var(--border-strong); border-radius: var(--radius); background: var(--surface-2); }
.combo-new[hidden] { display: none; }
.combo-new .error-text { grid-column: 1 / -1; display: block; }
.combo-new .error-text:empty { display: none; }

.confirm-icon { width: 46px; height: 46px; border-radius: 14px; display: grid; place-items: center; background: var(--danger-bg); color: var(--danger); flex: none; }
.confirm-icon.info { background: var(--primary-50); color: var(--primary); }
.confirm-body { display: flex; gap: 16px; }
.confirm-body h3 { font-size: 16px; margin-bottom: 6px; }
.confirm-body p { color: var(--text-2); }
.confirm-list { margin-top: 10px; max-height: 140px; overflow-y: auto; display: flex; flex-wrap: wrap; gap: 6px; }

/* Command palette */
.palette { max-width: 620px; align-self: start; margin-top: 10vh; }
.palette-input { display: flex; align-items: center; gap: 12px; padding: 16px 18px; border-bottom: 1px solid var(--border); }
.palette-input input { flex: 1; border: 0; outline: 0; background: transparent; font-size: 16px; }
.palette-list { max-height: 400px; overflow-y: auto; padding: 8px; }
.palette-group { padding: 8px 10px 4px; font-size: 11px; font-weight: 650; text-transform: uppercase; letter-spacing: .07em; color: var(--text-3); }
.palette-item { display: flex; align-items: center; gap: 12px; padding: 9px 10px; border-radius: 9px; cursor: pointer; color: var(--text-2); }
.palette-item .p-label { flex: 1; min-width: 0; }
.palette-item .p-label strong { display: block; color: var(--text); font-weight: 600; font-size: 13.5px; }
.palette-item .p-label span { display: block; font-size: 12px; color: var(--text-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.palette-item.active { background: var(--primary-50); }
.palette-item.active .p-label strong { color: var(--primary); }
.palette-foot { display: flex; gap: 16px; padding: 10px 18px; border-top: 1px solid var(--border); font-size: 12px; color: var(--text-3); }
.palette-foot span { display: inline-flex; align-items: center; gap: 6px; }

/* Toasts */
.toasts { position: fixed; right: 20px; bottom: 20px; z-index: 100; display: flex; flex-direction: column; gap: 10px; width: 380px; max-width: calc(100vw - 40px); }
.toast { display: flex; gap: 12px; align-items: flex-start; padding: 13px 14px; border-radius: var(--radius-lg); background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow-lg); animation: toast-in .3s var(--ease); }
.toast.leaving { animation: toast-out .2s ease forwards; }
.toast .t-icon { width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center; flex: none; }
.toast.success .t-icon { background: var(--success-bg); color: var(--success); }
.toast.error .t-icon { background: var(--danger-bg); color: var(--danger); }
.toast.info .t-icon { background: var(--primary-50); color: var(--primary); }
.toast .t-body { flex: 1; min-width: 0; padding-top: 4px; }
.toast .t-body strong { display: block; font-size: 13.5px; }
.toast .t-body span { display: block; font-size: 12.5px; color: var(--text-2); margin-top: 2px; word-break: break-word; }
@keyframes toast-in { from { opacity: 0; transform: translateY(12px) scale(.97); } }
@keyframes toast-out { to { opacity: 0; transform: translateX(30px); } }

.alert { display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border-radius: var(--radius); font-size: 13px; }
.alert .icon { margin-top: 1px; }
.alert.warn { background: var(--warning-bg); color: var(--warning); }
.alert.danger { background: var(--danger-bg); color: var(--danger); }
.alert.info { background: var(--info-bg); color: var(--info); }
.alert ul { margin: 4px 0 0; padding-left: 18px; }

/* Dashboard */
.hero { display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 24px 26px; margin-bottom: 18px; border-radius: var(--radius-xl); color: #fff; position: relative; overflow: hidden;
  background: radial-gradient(1200px 300px at 0% 0%, rgba(255, 255, 255, .18), transparent 60%), linear-gradient(120deg, #4338ca 0%, #6d28d9 52%, #0e7490 100%); box-shadow: 0 24px 48px -24px rgba(79, 70, 229, .8); }
.hero::after { content: ""; position: absolute; right: -60px; top: -60px; width: 260px; height: 260px; border-radius: 50%; background: rgba(255, 255, 255, .08); }
.hero h1 { font-size: 22px; font-weight: 700; }
.hero p { opacity: .85; margin-top: 4px; }
.hero .page-actions { position: relative; z-index: 1; }
.hero .btn { background: rgba(255, 255, 255, .14); border-color: rgba(255, 255, 255, .22); color: #fff; }
.hero .btn:hover { background: rgba(255, 255, 255, .24); }
.hero .btn-white { background: #fff; color: #4338ca; border-color: #fff; }
.hero .btn-white:hover { background: #eef2ff; color: #3730a3; }

.bars { display: flex; flex-direction: column; gap: 12px; }
.bar-row { display: grid; grid-template-columns: minmax(0, 170px) 1fr 44px; gap: 12px; align-items: center; font-size: 13px; cursor: pointer; border-radius: 8px; }
.bar-row:hover .bar-label { color: var(--primary); }
.bar-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-2); font-weight: 500; }
.bar-track { display: block; height: 10px; border-radius: 99px; background: var(--surface-3); overflow: hidden; }
/* Nhãn màu theo nhóm (màu tính từ mã nhóm, --h là hue) */
.grp-tag { display: inline-flex; align-items: center; gap: 6px; max-width: 100%; padding: 2px 10px 2px 8px; border-radius: 99px; font-size: 12.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; background: hsl(var(--h) 85% 95%); color: hsl(var(--h) 55% 32%); }
.grp-tag::before, .grp-dot { content: ""; width: 7px; height: 7px; border-radius: 50%; flex: none; background: hsl(var(--h) 65% 50%); }
.grp-dot { display: inline-block; margin-right: 7px; vertical-align: 1px; }
[data-theme="dark"] .grp-tag { background: hsl(var(--h) 40% 20%); color: hsl(var(--h) 80% 78%); }
.bar-fill { display: block; height: 100%; border-radius: inherit; background: linear-gradient(90deg, #818cf8, #6366f1); transition: width .7s var(--ease); }
.bar-value { text-align: right; font-weight: 650; font-variant-numeric: tabular-nums; }

.donut-wrap { display: flex; align-items: center; gap: 22px; }
.donut { width: 150px; height: 150px; border-radius: 50%; flex: none; position: relative; }
.donut::after { content: ""; position: absolute; inset: 22px; border-radius: 50%; background: var(--surface); }
.donut-center { position: absolute; inset: 0; display: grid; place-items: center; z-index: 1; text-align: center; }
.donut-center strong { display: block; font-size: 24px; font-weight: 700; letter-spacing: -.02em; }
.donut-center span { font-size: 11.5px; color: var(--text-3); }
.legend { display: flex; flex-direction: column; gap: 8px; flex: 1; min-width: 0; }
.legend-item { display: flex; align-items: center; gap: 8px; font-size: 12.5px; }
.legend-item i { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.legend-item span { flex: 1; font-family: var(--mono); font-size: 11.5px; overflow: hidden; text-overflow: ellipsis; }
.legend-item b { font-variant-numeric: tabular-nums; }

.list { display: flex; flex-direction: column; }
.list-item { display: flex; align-items: center; gap: 12px; padding: 11px 20px; border-bottom: 1px solid var(--border); cursor: pointer; transition: background .12s; }
.list-item:last-child { border-bottom: 0; }
.list-item:hover { background: var(--surface-2); }
.list-item .li-main { flex: 1; min-width: 0; }
.list-item .li-main strong { display: block; font-size: 13px; font-family: var(--mono); }
.list-item .li-main span { display: block; font-size: 12px; color: var(--text-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-item .li-side { text-align: right; font-size: 12px; color: var(--text-3); white-space: nowrap; }
.li-icon { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; flex: none; background: var(--surface-3); color: var(--text-2); }

.timeline { display: flex; flex-direction: column; gap: 0; }
.tl-item { display: flex; gap: 12px; padding: 10px 0; position: relative; }
.tl-item:not(:last-child)::before { content: ""; position: absolute; left: 13px; top: 36px; bottom: -4px; width: 2px; background: var(--border); }
.tl-dot { width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; flex: none; background: var(--primary-50); color: var(--primary); }
.tl-dot.del { background: var(--danger-bg); color: var(--danger); }
.tl-dot.add { background: var(--success-bg); color: var(--success); }
.tl-body { flex: 1; min-width: 0; font-size: 13px; }
.tl-body strong { font-weight: 600; }
.tl-body .tl-meta { font-size: 12px; color: var(--text-3); }

/* Profile */
.profile-hero { display: flex; align-items: center; gap: 22px; padding: 26px; }
.profile-hero h2 { font-size: 21px; font-weight: 700; }
.profile-hero .meta-row { display: flex; gap: 16px; flex-wrap: wrap; margin-top: 8px; color: var(--text-2); font-size: 13px; }
.profile-hero .meta-row span { display: inline-flex; align-items: center; gap: 6px; }
.info-list { display: flex; flex-direction: column; }
.info-row { display: flex; justify-content: space-between; gap: 16px; padding: 11px 0; border-bottom: 1px solid var(--border); font-size: 13.5px; }
.info-row:last-child { border-bottom: 0; }
.info-row span:first-child { color: var(--text-3); }
.info-row span:last-child { font-weight: 500; text-align: right; word-break: break-word; }
.pref-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 12px 0; border-bottom: 1px solid var(--border); }
.pref-row:last-child { border-bottom: 0; }
.pref-row strong { display: block; font-size: 13.5px; font-weight: 600; }
.pref-row span { font-size: 12.5px; color: var(--text-3); }
.shortcuts { display: grid; grid-template-columns: 1fr auto; gap: 10px 16px; font-size: 13px; align-items: center; }
.shortcuts kbd + kbd { margin-left: 4px; }

/* Schema */
.schema-table td code { font-size: 12px; }
.role-tag { display: inline-flex; padding: 1px 8px; border-radius: 6px; background: var(--primary-50); color: var(--primary); font-size: 11.5px; font-weight: 600; }
.flag { display: inline-flex; padding: 0 6px; border-radius: 4px; font-size: 10.5px; font-weight: 700; background: var(--surface-3); color: var(--text-2); margin-right: 3px; }
.flag.pk { background: var(--warning-bg); color: var(--warning); }
.flag.uk { background: var(--info-bg); color: var(--info); }
pre.snippet { margin: 0; padding: 14px 16px; border-radius: var(--radius); background: #0f172a; color: #e2e8f0; font-family: var(--mono); font-size: 12px; line-height: 1.6; overflow-x: auto; }
[data-theme="dark"] pre.snippet { background: #070b16; border: 1px solid var(--border); }

/* Tools */
.tool-result { margin-top: 14px; }
.result-row { display: flex; align-items: center; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--border); font-size: 13px; }
.result-row:last-child { border-bottom: 0; }
.result-row > span:first-child { width: 120px; color: var(--text-3); flex: none; }
.result-row > :last-child { flex: 1; min-width: 0; word-break: break-all; }

/* ---------- Login ---------- */
.auth { min-height: 100vh; display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(420px, .9fr); background: var(--surface); }
.auth-art {
  position: relative; overflow: hidden; padding: 48px 56px; color: #fff;
  display: flex; flex-direction: column; justify-content: space-between;
  background:
    radial-gradient(600px 400px at 15% 20%, rgba(129, 140, 248, .55), transparent 60%),
    radial-gradient(500px 400px at 85% 75%, rgba(6, 182, 212, .45), transparent 60%),
    radial-gradient(400px 300px at 70% 15%, rgba(168, 85, 247, .45), transparent 60%),
    #1e1b4b;
}
.auth-art::before { content: ""; position: absolute; inset: 0; background-image: linear-gradient(rgba(255, 255, 255, .05) 1px, transparent 1px), linear-gradient(90deg, rgba(255, 255, 255, .05) 1px, transparent 1px); background-size: 44px 44px; mask-image: radial-gradient(ellipse at center, #000 30%, transparent 75%); }
.auth-art > * { position: relative; }
.auth-brand { display: flex; align-items: center; gap: 12px; font-weight: 700; font-size: 17px; }
.auth-brand .brand-mark { background: rgba(255, 255, 255, .16); box-shadow: none; border: 1px solid rgba(255, 255, 255, .25); }
.auth-copy h1 { font-size: 40px; line-height: 1.12; font-weight: 750; letter-spacing: -.03em; max-width: 560px; }
.auth-copy h1 span { background: linear-gradient(90deg, #a5b4fc, #67e8f9); -webkit-background-clip: text; background-clip: text; color: transparent; }
.auth-copy p { margin-top: 16px; font-size: 16px; opacity: .82; max-width: 520px; }
.auth-features { display: grid; gap: 14px; margin-top: 32px; max-width: 520px; }
.auth-feature { display: flex; gap: 14px; align-items: flex-start; padding: 14px 16px; border-radius: 14px; background: rgba(255, 255, 255, .07); border: 1px solid rgba(255, 255, 255, .12); backdrop-filter: blur(6px); }
.auth-feature .icon { margin-top: 2px; color: #a5b4fc; }
.auth-feature strong { display: block; font-size: 14px; }
.auth-feature span { font-size: 13px; opacity: .75; }
.auth-code { font-family: var(--mono); font-size: 12.5px; opacity: .7; }
.auth-form-wrap { display: grid; place-items: center; padding: 40px 28px; background: var(--bg); }
.auth-card { width: 100%; max-width: 400px; }
.auth-card h2 { font-size: 26px; font-weight: 750; letter-spacing: -.02em; }
.auth-card > p { color: var(--text-2); margin-top: 6px; margin-bottom: 26px; }
.auth-card form { display: flex; flex-direction: column; gap: 16px; }
.auth-card .input { height: 46px; font-size: 14.5px; border-radius: 12px; }
.auth-card .input-icon > .input { padding-left: 42px; }
.auth-card .input-icon > .icon { left: 14px; }
.auth-card .btn-lg { border-radius: 12px; }
.pw-toggle { position: absolute; right: 6px; top: 50%; transform: translateY(-50%); }
.caps-warn { font-size: 12px; color: var(--warning); display: none; align-items: center; gap: 6px; }
.caps-warn.show { display: flex; }
.auth-row { display: flex; align-items: center; justify-content: space-between; font-size: 13px; }
.auth-foot { margin-top: 28px; font-size: 12.5px; color: var(--text-3); text-align: center; }
.auth-foot code { background: var(--surface-3); padding: 1px 6px; border-radius: 5px; }
.field-validation-error, .validation-summary-errors { color: var(--danger); font-size: 12.5px; }
.validation-summary-errors ul { margin: 0; padding: 0; list-style: none; }
.validation-summary-valid { display: none; }

/* ---------- Utilities ---------- */
.row { display: flex; align-items: center; gap: 8px; }
.wrap { flex-wrap: wrap; }
.between { justify-content: space-between; }
.mt-1 { margin-top: 6px; } .mt-2 { margin-top: 12px; } .mt-3 { margin-top: 18px; } .mb-2 { margin-bottom: 12px; } .mb-3 { margin-bottom: 18px; }
.text-muted { color: var(--text-3); } .text-2 { color: var(--text-2); } .small { font-size: 12.5px; }
.nowrap { white-space: nowrap; }
.w-100 { width: 100%; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); border: 0; }

/* ---------- Responsive ---------- */
@media (max-width: 1200px) {
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-main { grid-template-columns: minmax(0, 1fr); }
  .detail-layout { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 1024px) {
  .sidebar { transform: translateX(-100%); box-shadow: var(--shadow-lg); }
  body.nav-open .sidebar { transform: none; }
  body.nav-open .sidebar-backdrop { display: block; position: fixed; inset: 0; z-index: 35; background: rgba(15, 23, 42, .45); }
  .main { margin-left: 0; }
  .menu-toggle { display: inline-grid; }
  .auth { grid-template-columns: 1fr; }
  .auth-art { display: none; }
}
@media (max-width: 720px) {
  .content { padding: 18px 14px 24px; }
  .topbar { padding: 0 12px; }
  .search-trigger { width: auto; }
  .search-trigger span, .search-trigger kbd, .user-chip .name, .topbar-title > span, .topbar-title > .icon, .topbar [data-action=shortcuts] { display: none; }
  .topbar-title strong { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .modal-foot { flex-wrap: wrap; }
  .modal-foot .shortcut-hint { display: none; }
  .user-chip { padding: 2px; }
  .grid-4, .grid-3, .grid-2 { grid-template-columns: minmax(0, 1fr); }
  .form-grid { grid-template-columns: minmax(0, 1fr); }
  .field.span-2 { grid-column: auto; }
  .rt-pick { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .form-grid.one > .field.half { grid-column: span 2; }
  .combo-new { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .modal-root { padding: 0; place-items: end stretch; }
  .modal { max-height: 94vh; border-radius: 20px 20px 0 0; }
  .modal-foot { border-radius: 0; }
  .toolbar .select { flex: 1 1 140px; max-width: none; }
  .hero { flex-direction: column; align-items: flex-start; }
  .donut-wrap { flex-direction: column; align-items: flex-start; }
  .pager { justify-content: center; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}

/* Table checkboxes */
.table input[type="checkbox"] { width: 16px; height: 16px; margin: 0; accent-color: var(--primary); cursor: pointer; vertical-align: middle; }
.btn kbd { height: 19px; min-width: 19px; font-size: 10.5px; background: rgba(255, 255, 255, .18); border-color: rgba(255, 255, 255, .25); color: inherit; }
.btn:not(.btn-primary) kbd { background: var(--surface-2); border-color: var(--border); color: var(--text-3); }
.table tbody tr:focus-visible { outline: 2px solid var(--primary); outline-offset: -2px; }
