/* ===== Font Be Vietnam Pro (SIL Open Font License), tự phục vụ thay vì gọi Google Fonts ===== */
/* vietnamese */
@font-face {
  font-family: 'Be Vietnam Pro';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url(fonts/be-vietnam-pro-400-vietnamese.woff2) format('woff2');
  unicode-range: U+0102-0103, U+0110-0111, U+0128-0129, U+0168-0169, U+01A0-01A1, U+01AF-01B0, U+0300-0301, U+0303-0304, U+0308-0309, U+0323, U+0329, U+1EA0-1EF9, U+20AB;
}
/* latin-ext */
@font-face {
  font-family: 'Be Vietnam Pro';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url(fonts/be-vietnam-pro-400-latin-ext.woff2) format('woff2');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C4, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
/* latin */
@font-face {
  font-family: 'Be Vietnam Pro';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url(fonts/be-vietnam-pro-400-latin.woff2) format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
/* vietnamese */
@font-face {
  font-family: 'Be Vietnam Pro';
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url(fonts/be-vietnam-pro-500-vietnamese.woff2) format('woff2');
  unicode-range: U+0102-0103, U+0110-0111, U+0128-0129, U+0168-0169, U+01A0-01A1, U+01AF-01B0, U+0300-0301, U+0303-0304, U+0308-0309, U+0323, U+0329, U+1EA0-1EF9, U+20AB;
}
/* latin-ext */
@font-face {
  font-family: 'Be Vietnam Pro';
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url(fonts/be-vietnam-pro-500-latin-ext.woff2) format('woff2');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C4, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
/* latin */
@font-face {
  font-family: 'Be Vietnam Pro';
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url(fonts/be-vietnam-pro-500-latin.woff2) format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
/* vietnamese */
@font-face {
  font-family: 'Be Vietnam Pro';
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url(fonts/be-vietnam-pro-600-vietnamese.woff2) format('woff2');
  unicode-range: U+0102-0103, U+0110-0111, U+0128-0129, U+0168-0169, U+01A0-01A1, U+01AF-01B0, U+0300-0301, U+0303-0304, U+0308-0309, U+0323, U+0329, U+1EA0-1EF9, U+20AB;
}
/* latin-ext */
@font-face {
  font-family: 'Be Vietnam Pro';
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url(fonts/be-vietnam-pro-600-latin-ext.woff2) format('woff2');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C4, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
/* latin */
@font-face {
  font-family: 'Be Vietnam Pro';
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url(fonts/be-vietnam-pro-600-latin.woff2) format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
/* vietnamese */
@font-face {
  font-family: 'Be Vietnam Pro';
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url(fonts/be-vietnam-pro-700-vietnamese.woff2) format('woff2');
  unicode-range: U+0102-0103, U+0110-0111, U+0128-0129, U+0168-0169, U+01A0-01A1, U+01AF-01B0, U+0300-0301, U+0303-0304, U+0308-0309, U+0323, U+0329, U+1EA0-1EF9, U+20AB;
}
/* latin-ext */
@font-face {
  font-family: 'Be Vietnam Pro';
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url(fonts/be-vietnam-pro-700-latin-ext.woff2) format('woff2');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C4, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
/* latin */
@font-face {
  font-family: 'Be Vietnam Pro';
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url(fonts/be-vietnam-pro-700-latin.woff2) format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

/* ===== Màu & kích thước (chủ đề sáng mặc định, tối qua data-theme) ===== */
:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-2: #ffffff;
  --surface-3: #f8fafd;
  --text: #1b2333;
  --muted: #667085;
  --border: #e4e8f0;
  --primary: #1a73e8;
  --primary-2: #6a5cff;
  --on-primary: #ffffff;
  --primary-soft: #e8f0fe;
  --success: #188038;
  --warning: #b06000;
  --danger: #d93025;
  --danger-soft: #fce8e6;
  --good: #188038;
  --bad: #d93025;
  --hover: color-mix(in srgb, var(--text) 6%, transparent);
  --row-hover: color-mix(in srgb, var(--primary) 4%, var(--surface));
  --row-selected: color-mix(in srgb, var(--primary) 10%, var(--surface));
  --chart-1: #1a73e8;
  --chart-2: #f29900;
  --chart-3: #188038;
  --chart-4: #a142f4;
  --toast-bg: #1f2937;
  --toast-text: #f9fafb;
  --radius: 14px;
  --shadow-sm: 0 1px 2px rgb(16 24 40 / 0.05), 0 1px 3px rgb(16 24 40 / 0.06);
  --shadow: 0 4px 12px -2px rgb(16 24 40 / 0.08), 0 2px 4px -2px rgb(16 24 40 / 0.05);
  --shadow-lg: 0 18px 40px -12px rgb(16 24 40 / 0.22), 0 4px 10px -4px rgb(16 24 40 / 0.08);
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
  --spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --sidebar-w: 248px;
  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg: #0b0f17;
  --surface: #121826;
  --surface-2: #182033;
  --surface-3: #0f1522;
  --text: #e6e9f0;
  --muted: #98a2b3;
  --border: #232c3d;
  --primary: #8ab4f8;
  --primary-2: #b4a7ff;
  --on-primary: #0b1d36;
  --primary-soft: #1b2a45;
  --success: #81c995;
  --warning: #fdd663;
  --danger: #f28b82;
  --danger-soft: #3b2220;
  --good: #81c995;
  --bad: #f28b82;
  --hover: color-mix(in srgb, var(--text) 7%, transparent);
  --row-hover: color-mix(in srgb, var(--primary) 6%, var(--surface));
  --row-selected: color-mix(in srgb, var(--primary) 14%, var(--surface));
  --chart-1: #8ab4f8;
  --chart-2: #fbbc04;
  --chart-3: #81c995;
  --chart-4: #c58af9;
  --toast-bg: #1d2638;
  --toast-text: #e6e9f0;
  --shadow-sm: 0 1px 2px rgb(0 0 0 / 0.3);
  --shadow: 0 4px 14px -2px rgb(0 0 0 / 0.4);
  --shadow-lg: 0 20px 44px -12px rgb(0 0 0 / 0.6), 0 4px 10px -4px rgb(0 0 0 / 0.4);
  color-scheme: dark;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 "Be Vietnam Pro", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  transition: background-color 0.3s, color 0.3s;
}

[hidden] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.center { display: grid; place-items: center; min-height: 60vh; }
.spacer { flex: 1; }
.text-bad { color: var(--bad); }
.icon { flex: none; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

kbd {
  font: 600 11px/1 inherit; padding: 3px 6px; border-radius: 6px; color: var(--muted);
  border: 1px solid var(--border); background: var(--bg); box-shadow: inset 0 -1px 0 var(--border);
}

/* ===== Nút & ô nhập ===== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 8px 14px; border-radius: 10px; border: 1px solid transparent;
  font: inherit; font-weight: 500; cursor: pointer; text-decoration: none;
  background: var(--surface); color: var(--text);
  transition: background-color 0.15s, border-color 0.15s, box-shadow 0.2s, transform 0.12s, filter 0.15s;
}
.btn:active:not(:disabled) { transform: scale(0.97); }
.btn:disabled { opacity: 0.6; cursor: default; }
.btn-primary {
  background: linear-gradient(135deg, var(--primary), var(--primary-2)); color: var(--on-primary);
  box-shadow: 0 6px 16px -6px color-mix(in srgb, var(--primary) 70%, transparent);
}
.btn-primary:hover:not(:disabled) { filter: brightness(1.07); box-shadow: 0 10px 22px -8px color-mix(in srgb, var(--primary) 80%, transparent); }
.btn-danger { background: var(--danger); color: #fff; }
:root[data-theme="dark"] .btn-danger { color: #2a0f0d; }
.btn-danger:hover:not(:disabled) { filter: brightness(1.08); }
.btn-ghost { border-color: var(--border); }
.btn-ghost:hover:not(:disabled) { background: var(--hover); border-color: color-mix(in srgb, var(--text) 18%, var(--border)); }
.btn-sm { padding: 5px 10px; font-size: 13px; border-radius: 8px; }
.btn.danger { color: var(--bad); }
.btn-google {
  border-color: var(--border); padding: 11px 22px; font-size: 15px; box-shadow: var(--shadow);
}
.btn-google:hover { transform: translateY(-1px); box-shadow: var(--shadow-lg); }
.link { background: none; border: 0; padding: 0; color: var(--primary); font: inherit; font-weight: 500; cursor: pointer; text-align: left; }
.link:hover { text-decoration: underline; text-underline-offset: 3px; }

select, input, textarea {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 10px; padding: 7px 11px;
  transition: border-color 0.15s, box-shadow 0.15s;
}
select:focus, input:focus, textarea:focus {
  outline: none; border-color: var(--primary);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 22%, transparent);
}
input[type="checkbox"], input[type="radio"] { accent-color: var(--primary); width: 16px; height: 16px; padding: 0; }

/* Công tắc */
input.switch {
  appearance: none; width: 36px; height: 20px; border-radius: 999px; border: 0; padding: 0; margin: 0;
  background: color-mix(in srgb, var(--muted) 35%, transparent); position: relative; cursor: pointer; flex: none;
  transition: background-color 0.2s;
}
input.switch::before {
  content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgb(0 0 0 / 0.3); transition: transform 0.25s var(--spring);
}
input.switch:checked { background: var(--primary); }
input.switch:checked::before { transform: translateX(16px); }

/* ===== Màn hình chờ & đăng nhập ===== */
.boot { display: grid; place-items: center; min-height: 100vh; }
.boot-logo { animation: breathe 1.4s ease-in-out infinite; }

.login { position: relative; overflow: hidden; display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.login-bg { position: absolute; inset: 0; z-index: 0; }
.blob { position: absolute; width: 520px; height: 520px; border-radius: 50%; filter: blur(90px); opacity: 0.45; animation: drift 18s ease-in-out infinite alternate; }
.b1 { background: #4285f4; top: -180px; left: -140px; }
.b2 { background: #34a853; bottom: -220px; right: -160px; animation-delay: -6s; }
.b3 { background: #fbbc04; top: 38%; left: 52%; width: 360px; height: 360px; opacity: 0.32; animation-delay: -12s; }
:root[data-theme="dark"] .blob { opacity: 0.25; }
.login-card {
  position: relative; z-index: 1; max-width: 440px; width: 100%; text-align: center;
  padding: 40px 34px; border-radius: 22px;
  background: color-mix(in srgb, var(--surface) 74%, transparent);
  backdrop-filter: blur(18px) saturate(1.5); -webkit-backdrop-filter: blur(18px) saturate(1.5);
  border: 1px solid color-mix(in srgb, var(--surface) 50%, var(--border));
  box-shadow: 0 30px 80px -24px rgb(16 24 40 / 0.3);
  animation: rise 0.6s var(--ease) backwards;
}
.login-card .logo svg { animation: float 4s ease-in-out infinite; }
.login-card h1 { margin: 12px 0 8px; font-size: 24px; letter-spacing: -0.02em; }
.login-card .btn-google { margin: 18px 0 8px; }
.login-features { list-style: none; padding: 0; margin: 18px 0 4px; display: grid; gap: 8px; text-align: left; }
.login-features li {
  display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 12px; font-size: 13.5px;
  background: color-mix(in srgb, var(--surface) 65%, transparent); border: 1px solid color-mix(in srgb, var(--border) 70%, transparent);
  animation: rise 0.5s var(--ease) backwards;
}
.login-features li:nth-child(1) { animation-delay: 0.15s; }
.login-features li:nth-child(2) { animation-delay: 0.25s; }
.login-features li:nth-child(3) { animation-delay: 0.35s; }
.login-features .icon { color: var(--primary); }

.alert { background: var(--danger-soft); color: var(--danger); border-radius: 10px; padding: 10px 12px; text-align: left; }

/* ===== Khung ứng dụng ===== */
.app {
  display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); min-height: 100vh;
  transition: grid-template-columns 0.28s var(--ease);
  --bulk-offset: calc(var(--sidebar-w) / 2);
}
.main-col { min-width: 0; display: flex; flex-direction: column; }

/* Menu bên trái */
.sidebar {
  position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 6px;
  padding: 14px 12px; background: var(--surface); border-right: 1px solid var(--border);
  overflow-x: hidden; overflow-y: auto; z-index: 30;
}
.sidebar-brand { display: flex; align-items: center; gap: 10px; padding: 6px 10px 14px; white-space: nowrap; }
.brand-text {
  font-weight: 700; font-size: 16px; letter-spacing: -0.01em;
  background: linear-gradient(135deg, var(--primary), var(--primary-2)); -webkit-background-clip: text; background-clip: text; color: transparent;
}
.nav { display: grid; gap: 10px; }
.nav-group { display: grid; gap: 2px; }
.nav-title { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.07em; color: var(--muted); padding: 6px 12px 4px; white-space: nowrap; }
.nav-item {
  position: relative; display: flex; align-items: center; gap: 12px; width: 100%;
  padding: 9px 12px; border: 0; border-radius: 10px; background: none; color: var(--muted);
  font: inherit; font-weight: 500; text-align: left; cursor: pointer; white-space: nowrap;
  transition: background-color 0.15s, color 0.15s;
}
.nav-item .icon { transition: transform 0.25s var(--spring); }
.nav-item:hover { background: var(--hover); color: var(--text); }
.nav-item:hover .icon { transform: scale(1.12); }
.nav-item.active { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.nav-item.active::before {
  content: ""; position: absolute; left: -12px; top: 8px; bottom: 8px; width: 3px; border-radius: 0 3px 3px 0;
  background: var(--primary); animation: grow-y 0.3s var(--ease);
}
.nav-ai .icon { color: #a142f4; }
:root[data-theme="dark"] .nav-ai .icon { color: #c58af9; }
.collapse-btn { margin-top: auto; }

@media (min-width: 901px) {
  .app.collapsed { --sidebar-w: 72px; }
  .app.collapsed .nav-label, .app.collapsed .brand-text { display: none; }
  .app.collapsed .nav-title { font-size: 0; padding: 0; margin: 4px 12px; height: 1px; background: var(--border); }
  .app.collapsed .sidebar, .app.collapsed .nav { overflow: visible; }
  .app.collapsed .nav-item { justify-content: center; padding: 10px; }
  .app.collapsed .collapse-btn .icon { transform: scaleX(-1); }
  .app.collapsed .nav-item:hover::after {
    content: attr(data-tip); position: absolute; left: calc(100% + 12px); top: 50%; transform: translateY(-50%);
    padding: 6px 10px; border-radius: 8px; background: var(--toast-bg); color: var(--toast-text);
    font-size: 12.5px; font-weight: 500; box-shadow: var(--shadow); pointer-events: none; z-index: 50;
    animation: fade 0.15s;
  }
  .menu-btn { display: none !important; }
}

.scrim { position: fixed; inset: 0; z-index: 25; background: rgb(10 14 24 / 0.45); backdrop-filter: blur(2px); animation: fade 0.2s; }

/* Thanh trên */
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 10px;
  padding: 10px 24px; border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(14px) saturate(1.4); -webkit-backdrop-filter: blur(14px) saturate(1.4);
}
.icon-btn {
  display: grid; place-items: center; width: 40px; height: 40px; flex: none; padding: 0;
  border: 1px solid var(--border); border-radius: 12px; background: var(--surface); color: var(--muted); cursor: pointer;
  transition: background-color 0.15s, color 0.15s, transform 0.12s;
}
.icon-btn:hover { background: var(--hover); color: var(--text); }
.icon-btn:active { transform: scale(0.93); }
#refresh.spinning .icon { animation: spin 0.9s linear infinite; }
#theme-btn .icon { transition: transform 0.5s var(--spring); }
#theme-btn:hover .icon { transform: rotate(25deg); }
:root[data-theme="dark"] .for-light, :root[data-theme="light"] .for-dark { display: none; }
#theme-btn .icon { animation: pop-in 0.35s var(--spring); }

.picker { position: relative; min-width: 0; }
.picker-btn {
  display: flex; align-items: center; gap: 10px; min-height: 42px; max-width: 100%;
  padding: 5px 10px 5px 6px; border: 1px solid var(--border); border-radius: 12px;
  background: var(--surface); color: var(--text); font: inherit; text-align: left; cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.picker-range .picker-btn { padding-left: 12px; }
.picker-btn:hover { border-color: color-mix(in srgb, var(--primary) 45%, var(--border)); box-shadow: var(--shadow-sm); }
.picker-btn[aria-expanded="true"] { border-color: var(--primary); box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 18%, transparent); }
.picker-btn > .icon { color: var(--muted); }
.picker-account .picker-btn { width: 320px; }
.picker-text { display: flex; flex-direction: column; min-width: 0; flex: 1; line-height: 1.25; }
.picker-main { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.picker-sub { font-size: 11.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.picker-sub:empty { display: none; }
.chev { transition: transform 0.25s var(--ease); }
[aria-expanded="true"] .chev { transform: rotate(180deg); }
.flag { font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: var(--primary-soft); color: var(--primary); white-space: nowrap; }

.pop {
  position: absolute; top: calc(100% + 8px); left: 0; z-index: 40;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 16px; box-shadow: var(--shadow-lg);
  animation: pop-in 0.18s var(--ease); transform-origin: top left;
}
.pop-search {
  display: flex; align-items: center; gap: 8px; padding: 0 10px; margin-bottom: 6px; color: var(--muted);
  border: 1px solid var(--border); border-radius: 10px; background: var(--surface);
}
.pop-search:focus-within { border-color: var(--primary); box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 18%, transparent); }
.pop-search input { flex: 1; min-width: 0; border: 0; background: transparent; padding: 9px 0; box-shadow: none !important; }

.pop-accounts { width: 400px; padding: 8px; }
.acc-list { display: grid; gap: 2px; max-height: 380px; overflow-y: auto; }
.acc-group { display: flex; align-items: center; gap: 6px; padding: 10px 10px 4px; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); }
.acc-item {
  display: flex; align-items: center; gap: 10px; width: 100%; padding: 7px 10px; border: 0; border-radius: 10px;
  background: none; color: var(--text); font: inherit; text-align: left; cursor: pointer;
}
.acc-item.active { background: var(--hover); }
.acc-item.current { color: var(--primary); }
.acc-item.current .acc-name { font-weight: 600; }
.acc-item:disabled { opacity: 0.55; cursor: default; }
.acc-item > .icon { color: var(--primary); }
.acc-avatar {
  display: grid; place-items: center; width: 30px; height: 30px; border-radius: 9px; flex: none;
  font-weight: 700; font-size: 13px; color: #fff;
  background: linear-gradient(135deg, hsl(var(--hue, 220) 72% 56%), hsl(calc(var(--hue, 220) + 40) 70% 44%));
}
.acc-avatar.error { background: var(--danger); }
.acc-text { display: flex; flex-direction: column; min-width: 0; flex: 1; line-height: 1.3; }
.acc-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 500; }
.acc-sub { font-size: 11.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.acc-empty { padding: 20px; text-align: center; color: var(--muted); }

.pop-range { width: 470px; display: grid; grid-template-columns: 150px 1fr; gap: 8px; padding: 8px; }
.presets { display: grid; gap: 2px; align-content: start; padding-right: 8px; border-right: 1px solid var(--border); }
.preset {
  padding: 8px 10px; border: 0; border-radius: 8px; background: none; color: var(--text);
  font: inherit; text-align: left; cursor: pointer; transition: background-color 0.12s;
}
.preset:hover { background: var(--hover); }
.preset.active { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.custom-range { display: grid; gap: 10px; align-content: start; padding: 6px; }
.date-row { display: flex; align-items: center; gap: 6px; }
.date-row input { flex: 1; min-width: 0; }
.range-error { margin: 0; font-size: 12px; color: var(--bad); }
.switch-row { display: flex; align-items: center; gap: 10px; padding-top: 12px; margin-top: 2px; border-top: 1px solid var(--border); cursor: pointer; }

.search-trigger {
  display: flex; align-items: center; gap: 8px; height: 40px; min-width: 210px; padding: 0 8px 0 12px;
  border: 1px solid var(--border); border-radius: 12px; background: var(--surface); color: var(--muted);
  font: inherit; cursor: pointer; transition: border-color 0.15s, box-shadow 0.15s;
}
.search-trigger:hover { border-color: color-mix(in srgb, var(--primary) 45%, var(--border)); box-shadow: var(--shadow-sm); }
.search-trigger kbd { margin-left: auto; }

.user-btn { position: relative; display: grid; place-items: center; width: 40px; height: 40px; padding: 0; border: 0; border-radius: 50%; background: none; cursor: pointer; flex: none; transition: box-shadow 0.2s; }
.user-btn:hover, .user-btn[aria-expanded="true"] { box-shadow: 0 0 0 3px var(--primary-soft); }
.user-btn img, .user-btn .avatar { width: 36px; height: 36px; border-radius: 50%; }
.pop-user { left: auto; right: 0; width: 270px; padding: 8px; transform-origin: top right; }
.user-card { display: grid; gap: 6px; justify-items: start; padding: 10px 10px 12px; margin-bottom: 6px; border-bottom: 1px solid var(--border); }
.user-email { font-weight: 600; word-break: break-all; }
.role-pill { font-size: 11.5px; font-weight: 600; padding: 2px 9px; border-radius: 999px; background: var(--primary-soft); color: var(--primary); }
.menu-item {
  display: flex; align-items: center; gap: 10px; width: 100%; padding: 9px 10px; border: 0; border-radius: 8px;
  background: none; color: var(--bad); font: inherit; font-weight: 500; text-align: left; cursor: pointer;
}
.menu-item:hover { background: var(--hover); }

main { padding: 24px; max-width: 1600px; width: 100%; margin: 0 auto; }
#content > * { animation: view-in 0.38s var(--ease) backwards; }

/* ===== Đầu màn hình & bộ lọc ===== */
.view-header { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-bottom: 18px; }
.view-header h1 { font-size: 22px; font-weight: 700; letter-spacing: -0.02em; margin: 0 8px 0 0; }
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-bottom: 14px; }
.toolbar .spacer { flex: 1; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 4px 6px 4px 12px;
  background: var(--primary-soft); color: var(--primary); border-radius: 999px; font-weight: 500;
  animation: pop-in 0.25s var(--spring);
}
.chip button { border: 0; background: none; color: inherit; cursor: pointer; font-size: 16px; line-height: 1; padding: 0 4px; border-radius: 50%; }
.chip button:hover { background: color-mix(in srgb, var(--primary) 15%, transparent); }

/* ===== Thẻ số liệu ===== */
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; margin-bottom: 18px; }
.kpi, .card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-sm); }
.kpi {
  --tone: var(--primary);
  position: relative; overflow: hidden; padding: 16px 18px 14px;
  transition: transform 0.25s var(--ease), box-shadow 0.25s, border-color 0.25s;
  animation: rise 0.5s var(--ease) backwards; animation-delay: calc(var(--i, 0) * 45ms);
}
.kpi::before { content: ""; position: absolute; inset: 0 0 auto; height: 3px; background: linear-gradient(90deg, var(--tone), transparent); opacity: 0; transition: opacity 0.25s; }
.kpi:hover { transform: translateY(-3px); box-shadow: var(--shadow-lg); border-color: color-mix(in srgb, var(--tone) 35%, var(--border)); }
.kpi:hover::before { opacity: 1; }
.kpi-head { display: flex; align-items: center; gap: 10px; }
.kpi-icon {
  display: grid; place-items: center; width: 34px; height: 34px; border-radius: 10px; flex: none;
  background: color-mix(in srgb, var(--tone) 14%, transparent); color: var(--tone);
  transition: transform 0.3s var(--spring);
}
.kpi:hover .kpi-icon { transform: scale(1.08) rotate(-6deg); }
.kpi .label { color: var(--muted); font-size: 13px; font-weight: 500; }
.kpi .value { font-size: 26px; font-weight: 700; letter-spacing: -0.02em; margin: 10px 0 6px; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi-foot { display: flex; align-items: flex-end; justify-content: space-between; gap: 8px; min-height: 34px; }
.kpi-delta { display: flex; flex-wrap: wrap; align-items: center; gap: 2px; }
.sparkline { width: 96px; height: 34px; flex: none; color: var(--tone); overflow: visible; }
.spark-line { stroke-dasharray: 1; stroke-dashoffset: 1; animation: draw 1.2s var(--ease) 0.25s forwards; }
.spark-area { opacity: 0; animation: fade 0.8s ease 0.6s forwards; }
.tone-blue { --tone: #1a73e8; }
.tone-violet { --tone: #7c4dff; }
.tone-cyan { --tone: #0891b2; }
.tone-teal { --tone: #0d9488; }
.tone-amber { --tone: #d97706; }
.tone-green { --tone: #16a34a; }
.tone-orange { --tone: #ea580c; }
.tone-pink { --tone: #db2777; }
:root[data-theme="dark"] .kpi-icon, :root[data-theme="dark"] .sparkline { color: color-mix(in srgb, var(--tone) 70%, white); }

.delta { display: inline-flex; align-items: center; padding: 1px 7px; border-radius: 999px; font-size: 11.5px; font-weight: 600; white-space: nowrap; }
.delta.good { color: var(--good); background: color-mix(in srgb, var(--good) 13%, transparent); }
.delta.bad { color: var(--bad); background: color-mix(in srgb, var(--bad) 13%, transparent); }
.delta.neutral { color: var(--muted); background: color-mix(in srgb, var(--muted) 12%, transparent); }

.card { padding: 18px; margin-bottom: 18px; }
.card h2 { margin: 0 0 14px; font-size: 15px; font-weight: 600; }
.chart-box { position: relative; height: 320px; }

/* ===== Bảng ===== */
.table-block { display: grid; gap: 10px; }
.table-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; min-height: 36px; }
.search-box {
  display: flex; align-items: center; gap: 8px; min-width: 250px; padding: 0 10px; color: var(--muted);
  border: 1px solid var(--border); border-radius: 10px; background: var(--surface);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.search-box:focus-within { border-color: var(--primary); box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 18%, transparent); }
.search-box input { flex: 1; min-width: 0; border: 0; padding: 7px 0; background: transparent; box-shadow: none !important; }

.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-sm); }
table { width: 100%; border-collapse: separate; border-spacing: 0; }
th, td { padding: 11px 14px; border-bottom: 1px solid color-mix(in srgb, var(--border) 75%, transparent); vertical-align: middle; }
th {
  position: sticky; top: 0; background: var(--surface-3); text-align: left;
  font-size: 12px; font-weight: 600; color: var(--muted); cursor: pointer; user-select: none; white-space: nowrap;
  transition: color 0.15s;
}
th:hover, th.sorted { color: var(--text); }
.sort-arrow { display: inline-block; margin-left: 4px; font-size: 10px; opacity: 0; transition: opacity 0.15s, transform 0.2s; }
th:hover .sort-arrow { opacity: 0.45; }
th.sorted .sort-arrow { opacity: 1; color: var(--primary); }
tbody td { transition: background-color 0.12s; }
tbody tr:hover td { background: var(--row-hover); }
tbody tr.selected td { background: var(--row-selected); }
tbody tr:last-child td { border-bottom: 0; }
table.anim tbody tr { animation: row-in 0.4s var(--ease) backwards; animation-delay: calc(var(--i, 0) * 18ms); }
tfoot td { font-weight: 600; border-top: 1px solid var(--border); border-bottom: 0; background: var(--surface-3); }
td.name { min-width: 200px; max-width: 360px; }
.check-col { width: 40px; text-align: center; }
.sticky { position: sticky; z-index: 1; background: var(--surface); }
th.sticky { z-index: 3; background: var(--surface-3); }
tfoot .sticky { background: var(--surface-3); }
.sticky-edge { transition: box-shadow 0.2s; }
.table-wrap.scrolled .sticky-edge { box-shadow: 8px 0 10px -8px rgb(16 24 40 / 0.25); }
.empty { padding: 40px; text-align: center; color: var(--muted); }

/* Thanh thao tác hàng loạt (nổi) */
.bulk-bar {
  position: fixed; left: calc(50% + var(--bulk-offset, 0px)); bottom: 24px; z-index: 35;
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px; max-width: calc(100vw - 32px);
  padding: 8px 8px 8px 12px; border-radius: 16px; background: var(--toast-bg); color: var(--toast-text);
  box-shadow: var(--shadow-lg); border: 1px solid rgb(255 255 255 / 0.08);
  transform: translate(-50%, 150%); opacity: 0; pointer-events: none;
  transition: transform 0.35s var(--spring), opacity 0.2s;
}
.bulk-bar.show { transform: translate(-50%, 0); opacity: 1; pointer-events: auto; }
.bulk-count { display: grid; place-items: center; min-width: 26px; height: 26px; padding: 0 8px; border-radius: 999px; background: linear-gradient(135deg, #4f8df5, #7b6cff); color: #fff; font-weight: 700; font-size: 12.5px; }
.bulk-label { font-weight: 500; margin-right: 4px; }
.bulk-sep { width: 1px; height: 22px; background: currentColor; opacity: 0.2; }
.bulk-btn { background: rgb(255 255 255 / 0.08); color: inherit; }
.bulk-btn:hover:not(:disabled) { background: rgb(255 255 255 / 0.16); }
.bulk-close { display: grid; place-items: center; padding: 6px; border: 0; border-radius: 8px; background: none; color: inherit; opacity: 0.7; cursor: pointer; }
.bulk-close:hover { opacity: 1; background: rgb(255 255 255 / 0.1); }

/* Trạng thái */
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.badge.ENABLED { color: var(--success); background: color-mix(in srgb, var(--success) 13%, transparent); }
.badge.ENABLED::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; animation: ping 2.2s ease-out infinite; }
.badge.PAUSED { color: var(--muted); background: color-mix(in srgb, var(--muted) 15%, transparent); }
.badge.warn { color: var(--warning); background: color-mix(in srgb, var(--warning) 15%, transparent); }
.badge.bad { color: var(--bad); background: color-mix(in srgb, var(--bad) 13%, transparent); }

.status-cell { display: flex; align-items: center; gap: 10px; }
.toggle {
  position: relative; width: 38px; height: 22px; flex: none; padding: 0; border: 0; border-radius: 999px; cursor: pointer;
  background: color-mix(in srgb, var(--muted) 35%, transparent); transition: background-color 0.25s;
}
.toggle::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgb(0 0 0 / 0.3); transition: transform 0.3s var(--spring);
}
.toggle.on { background: var(--success); }
.toggle.on::after { transform: translateX(16px); }
.toggle:disabled { cursor: progress; }
.toggle.busy::after { animation: knob-pulse 0.9s ease-in-out infinite; }
.toggle.shake { animation: shake 0.4s; }

.edit-btn { border: 0; background: none; color: var(--primary); cursor: pointer; padding: 2px 6px; margin-left: 2px; border-radius: 6px; opacity: 0.55; transition: opacity 0.15s, background-color 0.15s; }
tr:hover .edit-btn, .edit-btn:focus-visible { opacity: 1; }
.edit-btn:hover { background: var(--primary-soft); }

/* Ngân sách */
.budget-cell { display: inline-grid; gap: 6px; justify-items: end; }
.budget-meter { width: 96px; height: 5px; border-radius: 3px; overflow: hidden; background: color-mix(in srgb, var(--muted) 20%, transparent); }
.budget-meter span { display: block; height: 100%; width: var(--w); border-radius: inherit; background: var(--good); transform-origin: left; animation: grow-x 0.9s var(--ease) 0.2s backwards; }
.budget-meter.near span { background: var(--warning); }
.budget-meter.over span { background: var(--bad); }

/* ===== Màn hình trống, lỗi, khung tải ===== */
.empty-state { display: grid; justify-items: center; gap: 6px; padding: 48px 24px; text-align: center; }
.empty-state.compact { padding: 32px 16px; }
.empty-state h3 { margin: 6px 0 0; font-size: 15px; font-weight: 600; }
.empty-state p { margin: 0 0 8px; max-width: 460px; }
.empty-art { position: relative; display: grid; place-items: center; width: 84px; height: 84px; margin-bottom: 6px; color: var(--primary); }
.compact .empty-art { width: 64px; height: 64px; }
.empty-art .ring { position: absolute; inset: 0; border-radius: 50%; }
.empty-art .r1 { background: var(--primary-soft); }
.empty-art .r2 { inset: -9px; border: 1.5px dashed color-mix(in srgb, var(--primary) 35%, transparent); animation: spin 22s linear infinite; }
.empty-art .icon { position: relative; animation: float 3.6s ease-in-out infinite; }

.error-card { display: flex; gap: 16px; align-items: flex-start; }
.error-icon { display: grid; place-items: center; width: 42px; height: 42px; border-radius: 12px; flex: none; background: var(--danger-soft); color: var(--danger); }
.error-body { flex: 1; min-width: 0; }
.error-body h2 { margin: 8px 0 10px; }
.error-body .alert { margin: 0 0 12px; }

.skeleton { animation: fade 0.3s 0.1s backwards; }
.sk {
  height: 12px; border-radius: 8px;
  background: linear-gradient(90deg, color-mix(in srgb, var(--text) 6%, transparent) 25%, color-mix(in srgb, var(--text) 12%, transparent) 37%, color-mix(in srgb, var(--text) 6%, transparent) 63%);
  background-size: 400% 100%; animation: shimmer 1.4s ease infinite;
}
.sk-header { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.sk-title { width: 180px; height: 26px; }
.sk-btn { width: 130px; height: 36px; border-radius: 10px; }
.sk-toolbar { display: flex; align-items: center; margin-bottom: 10px; }
.sk-search { width: 250px; height: 36px; border-radius: 10px; }
.sk-row { display: grid; grid-template-columns: 2.4fr 1fr 1fr 1fr; gap: 24px; padding: 15px 16px; border-bottom: 1px solid color-mix(in srgb, var(--border) 75%, transparent); }
.sk-row:last-child { border-bottom: 0; }
.sk-head { background: var(--surface-3); }
.sk-head .sk { height: 9px; opacity: 0.7; }
.sk-kpi { display: grid; gap: 14px; }
.sk-big { height: 26px; width: 70%; }
.sk-spark { height: 30px; }
.sk-chart { height: 280px; margin-top: 16px; border-radius: 12px; }
.w-50 { width: 50%; }
.w-25 { width: 25%; }

/* ===== Hộp thoại ===== */
dialog {
  border: 1px solid var(--border); border-radius: 18px; padding: 0; width: min(460px, calc(100vw - 32px));
  max-height: calc(100vh - 40px); background: var(--surface); color: var(--text);
  box-shadow: 0 30px 70px -16px rgb(0 0 0 / 0.4);
}
dialog[open] { animation: dialog-in 0.24s var(--ease); }
dialog[open]::backdrop { background: rgb(10 14 24 / 0.45); backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px); animation: fade 0.2s; }
dialog.closing { animation: dialog-out 0.16s ease forwards; }
dialog.closing::backdrop { animation: fade-out 0.16s ease forwards; }
dialog.wide { width: min(860px, calc(100vw - 32px)); }
.modal-form { padding: 24px; display: grid; gap: 14px; }
.modal-form h2 { margin: 0; font-size: 18px; letter-spacing: -0.01em; }
.modal-form label { display: grid; gap: 5px; }
.modal-form label > span { font-weight: 500; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }

.confirm { width: min(440px, calc(100vw - 32px)); }
.confirm-box { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; padding: 22px; }
.confirm-icon { display: grid; place-items: center; width: 44px; height: 44px; border-radius: 12px; background: var(--primary-soft); color: var(--primary); animation: pop-in 0.35s var(--spring) 0.05s backwards; }
.confirm-icon.danger { background: var(--danger-soft); color: var(--danger); }
.confirm-text h2 { margin: 2px 0 4px; font-size: 17px; }
.confirm-text p { margin: 0; color: var(--muted); }
.confirm-box .modal-actions { grid-column: 1 / -1; margin-top: 14px; }

/* Ô tìm nhanh */
dialog.palette { width: min(640px, calc(100vw - 32px)); margin: 12vh auto auto; overflow: hidden; display: flex; flex-direction: column; }
.pal-search { display: flex; align-items: center; gap: 10px; padding: 14px 18px; border-bottom: 1px solid var(--border); color: var(--muted); }
.pal-search input { flex: 1; border: 0; background: transparent; padding: 4px 0; font-size: 16px; box-shadow: none !important; }
.pal-list { max-height: min(440px, 58vh); overflow-y: auto; padding: 6px 8px 8px; }
.pal-title { padding: 10px 10px 6px; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.pal-item {
  display: flex; align-items: center; gap: 12px; width: 100%; padding: 8px 10px; border: 0; border-radius: 10px;
  background: none; color: var(--text); font: inherit; text-align: left; cursor: pointer;
}
.pal-item.active { background: var(--primary-soft); }
.pal-icon { display: grid; place-items: center; width: 30px; height: 30px; border-radius: 8px; flex: none; background: var(--surface-3); color: var(--muted); border: 1px solid var(--border); transition: background-color 0.15s, color 0.15s; }
.pal-item.active .pal-icon { background: var(--primary); color: var(--on-primary); border-color: transparent; }
.pal-label { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 500; }
.pal-hint { max-width: 45%; font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pal-enter { color: var(--muted); display: grid; }
.pal-empty { display: grid; justify-items: center; gap: 8px; padding: 34px; color: var(--muted); }
.pal-foot { display: flex; gap: 18px; padding: 10px 18px; border-top: 1px solid var(--border); font-size: 12px; color: var(--muted); background: var(--surface-3); }
.pal-foot kbd { margin-right: 3px; }

/* Thông báo */
.toasts { position: fixed; right: 20px; bottom: 20px; z-index: 60; display: flex; flex-direction: column; align-items: flex-end; gap: 10px; max-width: calc(100vw - 40px); pointer-events: none; }
.toast {
  position: relative; overflow: hidden; display: flex; align-items: center; gap: 10px;
  min-width: 260px; max-width: 420px; padding: 12px 10px 12px 12px; border-radius: 14px;
  background: var(--toast-bg); color: var(--toast-text); box-shadow: var(--shadow-lg); border: 1px solid rgb(255 255 255 / 0.06);
  pointer-events: auto; animation: toast-in 0.35s var(--spring);
}
.toast.leaving { animation: toast-out 0.22s ease forwards; }
.toast-icon { display: grid; place-items: center; width: 28px; height: 28px; border-radius: 50%; flex: none; background: rgb(74 222 128 / 0.18); color: #4ade80; }
.toast.error .toast-icon { background: rgb(248 113 113 / 0.18); color: #f87171; }
.toast-msg { flex: 1; line-height: 1.4; word-break: break-word; }
.toast-close { display: grid; place-items: center; padding: 4px; border: 0; border-radius: 6px; background: none; color: inherit; opacity: 0.6; cursor: pointer; }
.toast-close:hover { opacity: 1; background: rgb(255 255 255 / 0.1); }
.toast-progress { position: absolute; left: 0; bottom: 0; height: 3px; width: 100%; background: #4ade80; transform-origin: left; animation: toast-time linear forwards; }
.toast.error .toast-progress { background: #f87171; }

.spinner { width: 32px; height: 32px; border-radius: 50%; border: 3px solid var(--border); border-top-color: var(--primary); animation: spin 0.8s linear infinite; }

/* ===== Bố cục chung ===== */
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }
.row > * { flex: 1 1 160px; }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.row-actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(380px, 1fr)); gap: 16px; margin-bottom: 18px; }
.grid-2 > .card { margin-bottom: 0; }
.avatar { display: grid; place-items: center; background: linear-gradient(135deg, var(--primary), var(--primary-2)); color: var(--on-primary); font-weight: 600; }

/* Biểu mẫu */
.modal-form textarea { width: 100%; padding: 8px 10px; resize: vertical; }
.modal-form fieldset { border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px 14px; display: grid; gap: 12px; margin: 0; }
.modal-form legend { font-weight: 600; padding: 0 6px; }
.modal-form.compact { padding: 0; gap: 10px; }
.field-label { font-weight: 500; display: block; margin-bottom: 4px; }
.checks { display: flex; flex-wrap: wrap; gap: 6px 14px; }
.check { display: inline-flex !important; align-items: center; gap: 6px; font-weight: 400; cursor: pointer; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.geo-results { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.counted-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 8px; }
.counted { position: relative; }
.counted input { width: 100%; padding-right: 48px; }
.counter { position: absolute; right: 8px; top: 50%; transform: translateY(-50%); font-size: 11px; color: var(--muted); }
.counter.over { color: var(--bad); }
.conditions { display: grid; gap: 8px; }
select.narrow { flex: 0 0 70px !important; }
.schedule { display: grid; gap: 10px; padding-left: 4px; }

/* Quảng cáo */
.ad-col { min-width: 320px; max-width: 460px; }
.ad-preview { display: grid; gap: 2px; }
.ad-url { font-size: 12px; color: var(--success); }
.ad-title { color: var(--primary); font-weight: 500; }
.ad-desc { font-size: 13px; }
.policy { color: var(--bad); }

/* Báo cáo */
.share { display: flex; align-items: center; gap: 8px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.share-bar { width: 80px; height: 6px; border-radius: 3px; background: var(--border); overflow: hidden; }
.share-bar span { display: block; height: 100%; transform-origin: left; animation: grow-x 0.8s var(--ease) backwards; }

/* Trợ lý AI */
.grid-ai { display: grid; grid-template-columns: minmax(0, 3fr) minmax(300px, 2fr); gap: 16px; align-items: start; }
.chat { display: grid; gap: 12px; }
.chat h2 { margin: 0; }
.chat-list { display: grid; gap: 12px; align-content: start; min-height: 320px; max-height: 60vh; overflow-y: auto; padding: 4px; }
.bubble { padding: 10px 14px; border-radius: 14px; max-width: 92%; }
.bubble.user { justify-self: end; background: linear-gradient(135deg, var(--primary), var(--primary-2)); color: var(--on-primary); white-space: pre-wrap; border-bottom-right-radius: 4px; }
.bubble.user p { margin: 0; }
.bubble.assistant { justify-self: start; background: var(--surface-3); border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.chat-input { display: flex; gap: 8px; align-items: stretch; }
.chat-input textarea { flex: 1; padding: 8px 10px; resize: vertical; }
.chat-buttons { display: grid; gap: 6px; align-content: start; }
.quick { display: flex; flex-wrap: wrap; gap: 6px; }
.chip-btn {
  border: 1px solid var(--border); background: var(--surface); color: var(--text); border-radius: 999px;
  padding: 5px 12px; font: inherit; font-size: 13px; cursor: pointer; transition: background-color 0.15s, border-color 0.15s, transform 0.12s;
}
.chip-btn:hover { background: var(--primary-soft); border-color: color-mix(in srgb, var(--primary) 40%, var(--border)); }
.chip-btn:active { transform: scale(0.96); }
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md h3, .md h4, .md h5 { margin: 14px 0 6px; font-size: 15px; }
.md p { margin: 6px 0; }
.md ul, .md ol { margin: 6px 0; padding-left: 20px; }
.md code { background: var(--primary-soft); padding: 1px 4px; border-radius: 4px; }
.copy-list { list-style: none; padding: 0; margin: 0 0 12px; display: grid; gap: 4px; }
.copy-list li { display: flex; align-items: center; gap: 6px; padding: 4px 8px; border: 1px solid var(--border); border-radius: 8px; }
.copy-list li > span:first-child { flex: 1; }
.ad-copy-result h3 { font-size: 14px; margin: 14px 0 6px; }
.small-center { min-height: 120px; }

/* Điểm chất lượng */
.badge.plain::before { display: none; }
.seg-tabs {
  display: flex; gap: 4px; padding: 4px; margin-bottom: 16px; width: fit-content; max-width: 100%; overflow-x: auto;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow-sm);
}
.seg {
  display: inline-flex; align-items: center; gap: 6px; border: 0; background: none; color: var(--muted); font: inherit; font-weight: 500;
  padding: 7px 14px; border-radius: 9px; cursor: pointer; white-space: nowrap; transition: background-color 0.15s, color 0.15s;
}
.seg:hover { color: var(--text); background: var(--surface-3); }
.seg.active { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.seg-count { min-width: 18px; padding: 0 5px; border-radius: 999px; background: var(--warning); color: var(--surface); font-size: 11px; font-weight: 700; text-align: center; }
.quality-body { animation: view-in 0.25s var(--ease); }
.qs-bars { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; }
.qs-bar { display: grid; gap: 8px; }
.qs-bar-head { display: flex; justify-content: space-between; gap: 8px; font-size: 13px; }
.qs-bar-head strong { color: var(--bad); font-weight: 600; }
.qs-bar .share-bar { width: 100%; height: 8px; border-radius: 4px; }
.qs-bar .share-bar span { background: var(--bad); }
.fix-list { display: grid; gap: 10px; }
.fix-item { border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; background: var(--surface-3); }
.fix-head { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 10px; }
.fix-title strong { font-size: 15px; }
.fix-components { display: flex; flex-wrap: wrap; gap: 12px; }
.comp { display: grid; gap: 3px; justify-items: start; }
.fix-issues { margin: 10px 0 0; padding-left: 18px; display: grid; gap: 6px; }
.fix-issues ul { margin: 4px 0 0; padding-left: 16px; display: grid; gap: 4px; }
.fix-issues ul li { font-size: 13px; }
.fix-issues ul li .btn { margin-left: 8px; vertical-align: middle; }
.row-actions { display: flex; gap: 4px; justify-content: flex-end; white-space: nowrap; }
.split-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-start; gap: 10px; }
.split-head h2 { margin-bottom: 2px; }
.clusters { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 12px; margin-top: 12px; }
.cluster { border: 1px solid var(--border); border-radius: 12px; padding: 12px; display: grid; gap: 8px; align-content: start; }
.cluster.other { border-style: dashed; }
.cluster-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.cluster ul { margin: 0; padding-left: 18px; display: grid; gap: 4px; font-size: 13px; }
.cluster .btn { justify-self: start; }
.checks.column { flex-direction: column; gap: 6px; max-height: 260px; overflow-y: auto; }
.url { color: var(--primary); text-decoration: none; word-break: break-all; }
.url:hover { text-decoration: underline; }
.quick-filters { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-bottom: 10px; }
.quick-filter {
  display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--border); background: var(--surface); color: var(--text);
  border-radius: 999px; padding: 4px 6px 4px 12px; font: inherit; font-size: 13px; cursor: pointer; transition: background-color 0.15s, border-color 0.15s;
}
.quick-filter:hover { border-color: color-mix(in srgb, var(--primary) 40%, var(--border)); }
.quick-filter.active { background: var(--primary-soft); border-color: var(--primary); color: var(--primary); font-weight: 600; }
.quick-filter .count { min-width: 20px; padding: 0 6px; border-radius: 999px; background: var(--surface-3); font-size: 11.5px; text-align: center; }
.quick-filters .link { margin-left: auto; }
.row.between { justify-content: space-between; align-items: center; }
.kw-checks { display: flex; flex-wrap: wrap; gap: 6px; }
.kw-check { padding: 3px 10px; border-radius: 999px; font-size: 13px; background: color-mix(in srgb, var(--warning) 15%, transparent); color: var(--warning); transition: background-color 0.2s, color 0.2s; }
.kw-check.ok { background: color-mix(in srgb, var(--success) 13%, transparent); color: var(--success); }

/* Tự tối ưu AI */
.ai-toolbar { margin-bottom: 12px; align-items: flex-start; }
.chip-btn.active { background: var(--primary-soft); color: var(--primary); border-color: color-mix(in srgb, var(--primary) 40%, var(--border)); font-weight: 600; }
.ai-list { display: grid; gap: 10px; }
.ai-card {
  display: grid; gap: 8px; padding: 14px 16px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow-sm); animation: view-in 0.25s var(--ease);
}
.ai-card.decided { background: var(--surface-3); box-shadow: none; }
.ai-card-head { display: flex; align-items: flex-start; gap: 10px; flex-wrap: wrap; }
.ai-card-title { flex: 1 1 260px; min-width: 0; }
.ai-card-title strong { overflow-wrap: anywhere; }
.ai-select { margin-top: 4px; width: 16px; height: 16px; accent-color: var(--primary); }
.ai-kind {
  display: inline-flex; align-items: center; gap: 5px; padding: 3px 9px; border-radius: 8px; font-size: 12px; font-weight: 600; white-space: nowrap;
  color: var(--primary); background: var(--primary-soft);
}
.ai-kind.kind-ADD_NEGATIVE, .ai-kind.kind-PAUSE_AD, .ai-kind.kind-PAUSE_KEYWORD { color: var(--bad); background: color-mix(in srgb, var(--bad) 11%, transparent); }
.ai-kind.kind-SET_BUDGET, .ai-kind.kind-SET_KEYWORD_BID { color: var(--warning); background: color-mix(in srgb, var(--warning) 13%, transparent); }
.ai-kind.kind-ADD_KEYWORD, .ai-kind.kind-CREATE_AD { color: var(--success); background: color-mix(in srgb, var(--success) 12%, transparent); }
.ai-kind.kind-NOTE { color: var(--muted); background: color-mix(in srgb, var(--muted) 13%, transparent); }
.ai-reason { margin: 0; font-size: 14px; }
.ai-detail { font-size: 14px; padding: 8px 12px; border-radius: 10px; background: var(--surface-3); border: 1px dashed var(--border); overflow-wrap: anywhere; }
.ai-card.decided .ai-detail { background: var(--surface); }
.ai-detail details { margin-top: 6px; }
.ai-detail summary { cursor: pointer; }
.ai-change { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.ai-ad { display: grid; gap: 2px; }
.ai-chips { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 6px; }
.ai-chip { padding: 2px 8px; border-radius: 999px; background: var(--surface); border: 1px solid var(--border); font-size: 12px; }
.ai-desc-list { margin: 6px 0 0; padding-left: 18px; font-size: 13px; }
.ai-card-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.ai-module { display: grid; gap: 10px; align-content: start; }
.ai-module h2 { margin: 0; }
.ai-module p { margin: 0; }
.ai-module > .btn, .ai-module > button { justify-self: start; }
.ai-module-head { display: flex; align-items: center; gap: 10px; }
.ai-module-head .kpi-icon { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 10px; color: var(--primary); background: var(--primary-soft); }
.ai-digest { padding: 10px 14px; border-radius: 10px; background: var(--surface-3); border: 1px solid var(--border); max-height: 320px; overflow-y: auto; }
.ai-jobs { margin: 0; padding-left: 18px; color: var(--muted); }
.ai-settings .block { display: block; margin-top: 2px; }
.ai-config-status { margin-top: 8px; }
.ai-config-test { display: grid; gap: 6px; }
.ai-config-test:empty { display: none; }
.ai-test-row { display: flex; align-items: center; gap: 8px; padding: 8px 12px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface-3); overflow-wrap: anywhere; }
.ai-test-row.ok { color: var(--success, #15803d); }
.ai-test-row.bad { color: var(--danger, #b91c1c); }
.ai-test-row svg { flex: none; }
.ai-config-history { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.ai-config-history li { padding-bottom: 10px; border-bottom: 1px solid var(--border); overflow-wrap: anywhere; }
.ai-config-history li:last-child { border-bottom: 0; padding-bottom: 0; }
.ai-inline { display: grid; gap: 8px; margin: 8px 0; }
.ai-inline .ai-card { box-shadow: none; }
.tool-step { display: inline-flex; align-items: center; gap: 6px; margin: 4px 0; padding: 2px 9px; border-radius: 999px; font-size: 12px; color: var(--muted); background: var(--surface); border: 1px solid var(--border); }
.ai-score { font-size: 15px; padding: 4px 12px; }
.ai-facts { display: flex; flex-wrap: wrap; gap: 6px; }
.ai-facts span { padding: 2px 9px; border-radius: 999px; background: var(--surface-3); border: 1px solid var(--border); font-size: 12px; color: var(--muted); }
.ai-issues { display: grid; gap: 8px; }
.ai-issue { padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface-3); }
.ai-issue p { margin: 4px 0 0; }
.spinner.small { width: 18px; height: 18px; border-width: 2px; }
.spinner.inline { display: inline-block; vertical-align: middle; margin-right: 6px; width: 14px; height: 14px; }
.url { overflow-wrap: anywhere; }
@media (max-width: 640px) {
  .ai-card { padding: 12px; }
  .ai-toolbar .row-actions { justify-content: flex-start; }
}

/* Người dùng */
.user-cell { display: flex; align-items: center; gap: 10px; }
.user-cell img, .user-cell .avatar { width: 32px; height: 32px; border-radius: 50%; flex: none; }

/* ===== Màn hình nhỏ ===== */
@media (max-width: 1100px) {
  .search-trigger { min-width: 0; }
  .search-text, .search-trigger kbd { display: none; }
  .picker-account .picker-btn { width: 260px; }
}

@media (max-width: 900px) {
  .app { grid-template-columns: minmax(0, 1fr); --bulk-offset: 0px; }
  .sidebar {
    position: fixed; left: 0; top: 0; bottom: 0; width: 272px; box-shadow: var(--shadow-lg);
    transform: translateX(-105%); visibility: hidden; transition: transform 0.3s var(--ease), visibility 0s linear 0.3s;
  }
  .app.nav-open .sidebar { transform: none; visibility: visible; transition: transform 0.3s var(--ease), visibility 0s; }
  .collapse-btn { display: none; }
  .grid-ai, .grid-2 { grid-template-columns: 1fr; }
}

@media (max-width: 720px) {
  .topbar { padding: 8px 16px; gap: 8px; flex-wrap: wrap; }
  main { padding: 16px; }
  .topbar > .spacer, #refresh { display: none; }
  .picker-account { flex: 1; }
  .picker-account .picker-btn { width: 100%; }
  .picker-sub, .flag { display: none; }
  .picker-range { order: 10; flex-basis: 100%; }
  .picker-range .picker-btn { width: 100%; }
  .pop { position: fixed; left: 16px; right: 16px; width: auto; } /* top: đặt bằng JS theo nút mở */
  .pop-range { grid-template-columns: 1fr; }
  .presets { grid-template-columns: repeat(3, 1fr); padding: 0 0 8px; border-right: 0; border-bottom: 1px solid var(--border); }
  .preset { text-align: center; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .kpi { padding: 14px; }
  .kpi .value { font-size: 20px; }
  .kpi-foot { flex-direction: column; align-items: stretch; }
  .sparkline { width: 100%; }
  .table-bar .search-box { min-width: 0; width: 100%; }
  .sticky { position: static; }
  .pal-foot { display: none; }
  dialog.palette { margin-top: 8vh; }
  .toasts { left: 16px; right: 16px; bottom: 16px; max-width: none; align-items: stretch; }
  .toast { min-width: 0; max-width: none; }
}

/* ===== Hiệu ứng ===== */
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes fade { from { opacity: 0; } }
@keyframes fade-out { to { opacity: 0; } }
@keyframes rise { from { opacity: 0; transform: translateY(10px); } }
@keyframes view-in { from { opacity: 0; transform: translateY(8px); } }
@keyframes row-in { from { opacity: 0; transform: translateY(4px); } }
@keyframes pop-in { from { opacity: 0; transform: scale(0.94) translateY(-4px); } }
@keyframes dialog-in { from { opacity: 0; transform: translateY(10px) scale(0.96); } }
@keyframes dialog-out { to { opacity: 0; transform: translateY(6px) scale(0.97); } }
@keyframes toast-in { from { opacity: 0; transform: translateX(30px) scale(0.95); } }
@keyframes toast-out { to { opacity: 0; transform: translateX(30px); } }
@keyframes toast-time { to { transform: scaleX(0); } }
@keyframes draw { to { stroke-dashoffset: 0; } }
@keyframes grow-x { from { transform: scaleX(0); } }
@keyframes grow-y { from { transform: scaleY(0); } }
@keyframes shimmer { from { background-position: 100% 50%; } to { background-position: 0 50%; } }
@keyframes float { 50% { transform: translateY(-5px); } }
@keyframes breathe { 50% { transform: scale(0.88); opacity: 0.7; } }
@keyframes drift { 50% { transform: translate(60px, 40px) scale(1.1); } to { transform: translate(-40px, 70px) scale(0.95); } }
@keyframes ping { from { box-shadow: 0 0 0 0 color-mix(in srgb, currentColor 55%, transparent); } 70%, to { box-shadow: 0 0 0 5px transparent; } }
@keyframes knob-pulse { 50% { transform: translateX(var(--knob-x, 0)) scale(0.75); } }
@keyframes shake { 20%, 60% { transform: translateX(-4px); } 40%, 80% { transform: translateX(4px); } }
.toggle.on.busy { --knob-x: 16px; }

/* Máy đặt "giảm chuyển động": tắt hiệu ứng, giữ nguyên trạng thái cuối. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; animation-delay: 0s !important;
    transition-duration: 0.01ms !important; scroll-behavior: auto !important;
  }
  .blob, .empty-art .icon, .empty-art .r2, .boot-logo, .badge.ENABLED::before { animation: none !important; }
}
