/* ===== Design tokens — màu chủ đạo: xanh chính quyền, trắng, xám nhạt ===== */
:root {
  --c-primary: #0e5f76;
  --c-primary-h: #0a4a5c;
  --c-primary-l: #e7f2f5;
  --c-success: #16a34a;
  --c-success-l: #ecfdf3;
  --c-warning: #f59e0b;
  --c-warning-l: #fffbeb;
  --c-danger: #ef4444;
  --c-danger-l: #fef2f2;
  --surface: #ffffff;
  --bg: #f2f5f7;
  --border: #e2e7eb;
  --text-1: #14212b;
  --text-2: #51646f;
  --text-3: #93a3ac;
  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 16px;
  --sh-sm: 0 1px 3px rgba(15,40,50,.08);
  --sh-md: 0 4px 14px rgba(15,40,50,.10);
  --sh-lg: 0 12px 32px rgba(15,40,50,.14);
  --tr: .16s ease;
  --sidebar-w: 240px;
  /* ---- Sprint 20: thang khoảng cách + chữ dùng chung, để mọi module lấy từ 1 nguồn ---- */
  --sp-1: 4px; --sp-2: 8px; --sp-3: 12px; --sp-4: 16px; --sp-5: 20px; --sp-6: 24px; --sp-8: 32px;
  --fs-xs: 12px; --fs-sm: 13px; --fs-base: 15px; --fs-md: 16px; --fs-lg: 18px; --fs-xl: 22px; --fs-2xl: 28px;
  --content-max: 900px;
  --content-max-lg: 1180px;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0;
  font-family: -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text-1);
  font-size: 16px;
  -webkit-tap-highlight-color: transparent;
}
button, input, select, textarea { font-family: inherit; font-size: 16px; }
h1, h2, p { margin: 0; }

.screen { display: none; }
.screen.active { display: block; }

/* P0 Production Data Isolation — ẩn toàn bộ nội dung nghiệp vụ gốc của 1 screen
   (list/form/detail/hub, bất kể cấu trúc bên trong) khi module chưa có dữ liệu
   Production, chỉ để lộ banner. Chỉ display:none — không xoá DOM, nên gỡ class
   module-gated là phục hồi màn hình y nguyên. Xem _applyScreenGate() (app.js). */
.screen.module-gated > *:not(.production-gate-banner) { display: none !important; }

/* ===== Login ===== */
#screen-login.screen { display: none; }
#screen-login.active { display: flex; }
#screen-login {
  min-height: 100vh;
  align-items: center;
  justify-content: center;
  background: linear-gradient(180deg, var(--c-primary-l), var(--bg));
  padding: 24px;
}
.login-wrap { width: 100%; max-width: 380px; text-align: center; }
.login-brand { font-size: 38px; font-weight: 800; letter-spacing: -.8px; line-height: 1; margin-bottom: 4px; }
.login-brand .brand-main { color: var(--text-1); }
.login-brand .brand-accent { color: var(--c-primary); }
.login-tagline { font-size: 13px; color: var(--text-3); margin: 4px 0 20px; }
.login-title { font-size: 19px; font-weight: 700; color: var(--c-primary-h); }
.login-sub { color: var(--text-2); margin: 6px 0 24px; }
.login-form { display: flex; flex-direction: column; gap: 6px; text-align: left; }
.login-form label { font-weight: 600; font-size: 14px; margin-top: 10px; color: var(--text-2); }
.login-form input {
  padding: 14px; border: 1.5px solid var(--border); border-radius: var(--r-sm);
  background: var(--surface);
}
.login-form input:focus { outline: none; border-color: var(--c-primary); box-shadow: 0 0 0 3px rgba(14,95,118,.15); }
.login-hint { font-size: 13px; color: var(--text-3); text-align: center; margin-top: 12px; }

/* ===== App shell: sidebar (desktop) + main column ===== */
.app-shell { display: none; min-height: 100vh; }
.app-shell.active { display: flex; }
.main-col { flex: 1; display: flex; flex-direction: column; min-width: 0; min-height: 100vh; }

/* ---- Sidebar / Drawer (mobile: overlay trượt ra; desktop: cố định luôn hiện) ---- */
.side-drawer {
  position: fixed; top: 0; left: 0; bottom: 0; width: 264px; max-width: 82vw;
  background: var(--c-primary-h); color: #fff; z-index: 60;
  display: flex; flex-direction: column; padding: 20px 0;
  transform: translateX(-100%); transition: transform .22s ease;
  box-shadow: var(--sh-lg);
}
.side-drawer.open { transform: translateX(0); }
.drawer-backdrop {
  position: fixed; inset: 0; background: rgba(10,20,25,.45); z-index: 55;
  opacity: 0; pointer-events: none; transition: opacity .2s ease;
}
.drawer-backdrop.open { opacity: 1; pointer-events: auto; }

.drawer-brand { display: flex; flex-direction: column; gap: 0; padding: 16px 20px 18px; border-bottom: 1px solid rgba(255,255,255,.15); }
.drawer-brand .brand-name { font-size: 21px; font-weight: 800; letter-spacing: -.4px; line-height: 1; }
.drawer-brand .brand-main { color: #fff; }
.drawer-brand .brand-accent { color: #7dd3fc; }
.drawer-brand .brand-tagline { font-size: 10.5px; opacity: .68; margin: 5px 0 10px; }
.drawer-brand .name { font-weight: 700; font-size: 14px; line-height: 1.3; }
.drawer-brand .village { font-size: 12px; opacity: .75; }

.drawer-nav { flex: 1; display: flex; flex-direction: column; gap: 2px; padding: 14px 10px; overflow-y: auto; }
.drawer-link {
  display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-radius: var(--r-sm);
  background: none; border: none; color: rgba(255,255,255,.85); font-weight: 600; font-size: 15px;
  cursor: pointer; text-align: left; width: 100%;
}
.drawer-link .icon { font-size: 19px; width: 22px; text-align: center; }
.drawer-link:hover, .drawer-link:active { background: rgba(255,255,255,.10); color: #fff; }
.drawer-link.active { background: #fff; color: var(--c-primary-h); }
.drawer-link[hidden] { display: none; }

.drawer-footer { padding: 14px 20px 4px; border-top: 1px solid rgba(255,255,255,.15); }
.drawer-footer .user-name { font-weight: 700; font-size: 14px; }
.drawer-footer .user-role { font-size: 12px; opacity: .75; margin-bottom: 10px; }
.drawer-logout {
  width: 100%; padding: 10px; border-radius: var(--r-sm); border: 1.5px solid rgba(255,255,255,.35);
  background: none; color: #fff; font-weight: 600; cursor: pointer;
}
.drawer-logout:active { background: rgba(255,255,255,.15); }

/* ===== Topbar ===== */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 10px;
  background: var(--c-primary); color: #fff;
  padding: 14px 16px; box-shadow: var(--sh-sm);
}
.topbar-title { flex: 1; font-size: 18px; font-weight: 700; }
.topbar-back, .topbar-icon {
  background: none; border: none; color: #fff; font-size: 20px;
  width: 40px; height: 40px; border-radius: 50%; cursor: pointer; flex-shrink: 0;
}
.topbar-back:active, .topbar-icon:active { background: rgba(255,255,255,.2); }

.content { flex: 1; padding: 18px; padding-bottom: 96px; max-width: var(--content-max); margin: 0 auto; width: 100%; }

/* ===== Dashboard home ===== */
.hello-card {
  background: linear-gradient(135deg, var(--c-primary), var(--c-primary-h));
  color: #fff; border-radius: var(--r-lg); padding: 20px; box-shadow: var(--sh-md); margin-bottom: 18px;
}
.hello-name { font-size: 18px; font-weight: 700; }
.hello-village { opacity: .85; margin-top: 4px; font-size: 14px; }

.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 22px; }
.stat-card {
  background: var(--surface); border-radius: var(--r-md); padding: 16px; box-shadow: var(--sh-sm);
  border-left: 4px solid var(--c-primary); transition: box-shadow var(--tr), transform var(--tr);
  display: flex; flex-direction: column; gap: 10px;
}
.stat-card:hover { box-shadow: var(--sh-md); transform: translateY(-1px); }
.stat-icon {
  width: 38px; height: 38px; border-radius: var(--r-sm); background: var(--c-primary-l); color: var(--c-primary-h);
  display: flex; align-items: center; justify-content: center; font-size: 19px; flex-shrink: 0;
}
.stat-num { font-size: var(--fs-2xl); font-weight: 800; color: var(--c-primary-h); line-height: 1.1; }
.stat-label { font-size: var(--fs-sm); color: var(--text-2); margin-top: 2px; font-weight: 600; }
.stat-card--warn { border-left-color: var(--c-warning); }
.stat-card--warn .stat-num { color: var(--c-warning); }
.stat-card--warn .stat-icon { background: var(--c-warning-l); color: #92400e; }
.stat-card--danger { border-left-color: var(--c-danger); }
.stat-card--danger .stat-num { color: var(--c-danger); }
.stat-card--danger .stat-icon { background: var(--c-danger-l); color: var(--c-danger); }
.stat-card--success { border-left-color: var(--c-success); }
.stat-card--success .stat-num { color: var(--c-success); }
.stat-card--success .stat-icon { background: var(--c-success-l); color: var(--c-success); }
.stat-card--ai { border-left-color: #7c3aed; }
.stat-card--ai .stat-num { color: #7c3aed; }
.stat-card--ai .stat-icon { background: #f2ebfe; color: #7c3aed; }

/* Skeleton KPI card — hiện khi dashboard chưa nạp xong dữ liệu */
.stat-card--skeleton { gap: 10px; }
.stat-card--skeleton .stat-icon { background: var(--border); color: transparent; }

.btn-coming-soon { position: relative; opacity: .82; }
.coming-soon-tag {
  display: inline-block; background: var(--c-warning-l); color: #92400e; font-size: 10px;
  font-weight: 700; padding: 1px 7px; border-radius: 999px; margin-left: 6px; vertical-align: middle;
}

/* ===== ImportWizard (Nhập Excel) ===== */
.import-steps { display: flex; gap: 6px; margin-bottom: 16px; flex-wrap: wrap; }
.import-step {
  flex: 1; min-width: 90px; text-align: center; padding: 8px 6px; border-radius: var(--r-sm);
  background: var(--surface); color: var(--text-3); font-size: 12px; font-weight: 700;
  border: 1.5px solid var(--border);
}
.import-step.active { background: var(--c-primary); color: #fff; border-color: var(--c-primary); }
.import-step.done { background: var(--c-success-l); color: var(--c-success); border-color: var(--c-success); }
.import-panel[hidden] { display: none; }
.import-summary { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.import-summary-chip {
  padding: 8px 14px; border-radius: 999px; font-size: 13px; font-weight: 700; background: var(--surface); box-shadow: var(--sh-sm);
}
.import-summary-chip--valid { color: var(--c-success); }
.import-summary-chip--warning { color: var(--c-warning); }
.import-summary-chip--error { color: var(--c-danger); }
.import-row-error { background: var(--c-danger-l); }
.import-row-warning { background: var(--c-warning-l); }
.import-status-badge {
  display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 11px; font-weight: 700;
}
.import-status-badge--valid { background: var(--c-success-l); color: var(--c-success); }
.import-status-badge--warning { background: var(--c-warning-l); color: #92400e; }
.import-status-badge--error { background: var(--c-danger-l); color: var(--c-danger); }

.section-title { font-size: 14px; font-weight: 700; margin: 22px 0 10px; color: var(--text-2); text-transform: uppercase; letter-spacing: .4px; }
.section-row { display: flex; align-items: center; justify-content: space-between; margin-top: 22px; flex-wrap: wrap; gap: 8px; }
.section-row .section-title { margin: 0; }

.menu-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.menu-item {
  background: var(--surface); border: none; border-radius: var(--r-md);
  padding: 20px 8px; display: flex; flex-direction: column; align-items: center; gap: 8px;
  box-shadow: var(--sh-sm); cursor: pointer; font-weight: 600; color: var(--text-1);
  transition: transform var(--tr);
}
.menu-item:active { transform: scale(.96); background: var(--c-primary-l); }
.menu-icon { font-size: 28px; }
.menu-item[hidden] { display: none; }

.list-plain { display: flex; flex-direction: column; gap: 8px; }
.list-plain-item { background: var(--surface); border-radius: var(--r-md); padding: 12px 14px; box-shadow: var(--sh-sm); }
.list-plain-item .title { font-weight: 600; font-size: 14px; }
.list-plain-item .meta { font-size: 12px; color: var(--text-3); margin-top: 2px; }

/* ===== Cards / lists ===== */
.card-list { display: flex; flex-direction: column; gap: 10px; }
.card {
  background: var(--surface); border-radius: var(--r-md); padding: 14px;
  box-shadow: var(--sh-sm); cursor: pointer; transition: transform var(--tr), box-shadow var(--tr);
}
.card:active { transform: scale(.98); }
.card:hover { box-shadow: var(--sh-md); }
.card-title { font-weight: 700; font-size: 15px; }
.card-sub { font-size: 13px; color: var(--text-2); margin-top: 4px; }
.card-meta { font-size: 12px; color: var(--text-3); margin-top: 6px; }
.card-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }

.badge { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 700; white-space: nowrap; }
.badge--green { background: var(--c-success-l); color: #15803d; }
.badge--warn { background: var(--c-warning-l); color: #b45309; }
.badge--danger { background: var(--c-danger-l); color: #b91c1c; }
.badge--gray { background: #f1f5f9; color: var(--text-2); }
.badge--primary { background: var(--c-primary-l); color: var(--c-primary-h); }

/* ===== Search / tabs ===== */
.search-bar { margin-bottom: 14px; }
.search-bar input {
  width: 100%; padding: 12px 14px; border: 1.5px solid var(--border);
  border-radius: var(--r-sm); background: var(--surface);
}
.search-bar input:focus { outline: none; border-color: var(--c-primary); box-shadow: 0 0 0 3px rgba(14,95,118,.12); }

.tabs { display: flex; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; }
.tab {
  flex: 1; min-width: 100px; padding: 11px; border: 1.5px solid var(--border); background: var(--surface);
  border-radius: var(--r-sm); font-weight: 600; color: var(--text-2); cursor: pointer;
}
.tab.active { background: var(--c-primary); border-color: var(--c-primary); color: #fff; }

/* ===== Forms ===== */
.form { display: flex; flex-direction: column; gap: 4px; background: var(--surface); padding: 18px; border-radius: var(--r-lg); box-shadow: var(--sh-sm); }
.form label { font-weight: 600; font-size: 14px; color: var(--text-2); margin-top: 12px; }
.form input, .form select, .form textarea {
  padding: 13px; border: 1.5px solid var(--border); border-radius: var(--r-sm);
  background: #fff; width: 100%; resize: vertical;
}
.form input:focus, .form select:focus, .form textarea:focus {
  outline: none; border-color: var(--c-primary); box-shadow: 0 0 0 3px rgba(14,95,118,.12);
}
.form-actions { margin-top: 20px; display: flex; flex-direction: column; gap: 10px; }
.form-actions[hidden] { display: none; }
.form-actions-row { margin-top: 16px; display: flex; gap: 10px; flex-wrap: wrap; }
.form-actions-row[hidden] { display: none; }
.form-actions-row .btn { flex: 1; min-width: 140px; }
.photo-preview { margin-top: 10px; max-width: 100%; border-radius: var(--r-sm); max-height: 200px; object-fit: cover; }

/* ===== Demo Mode banner (an toàn dữ liệu trên bản demo public) ===== */
.demo-mode-banner {
  display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap;
  background: var(--c-warning-l); color: #92400e; border-bottom: 1px solid #fde68a;
  padding: 10px 16px; font-size: 13px; font-weight: 600;
}
.demo-mode-banner[hidden] { display: none; }
.demo-mode-banner--login {
  border-radius: var(--r-sm); border: 1px solid #fde68a; margin: 4px 0 14px; justify-content: center; text-align: center;
}

/* ===== API Key field (Cấu hình AI) ===== */
.api-key-row { display: flex; gap: 8px; align-items: center; }
.api-key-row input { flex: 1; }
.btn-eye-toggle {
  flex-shrink: 0; width: 46px; height: 46px; border-radius: var(--r-sm);
  border: 1.5px solid var(--border); background: var(--surface); font-size: 18px;
  cursor: pointer; line-height: 1;
}
.btn-eye-toggle:active { background: var(--c-primary-l); }
.btn-eye-toggle.is-visible { border-color: var(--c-primary); background: var(--c-primary-l); }
.ai-demo-warning { font-weight: 600; }

/* ===== Buttons ===== */
.btn {
  border: none; border-radius: var(--r-sm); padding: 14px 18px; font-weight: 700;
  cursor: pointer; transition: transform var(--tr), background var(--tr); font-size: 15px;
}
.btn:active { transform: scale(.97); }
.btn-block { width: 100%; }
.btn-sm { padding: 9px 14px; font-size: 13px; }
.btn-primary { background: var(--c-primary); color: #fff; }
.btn-primary:hover { background: var(--c-primary-h); }
.btn-secondary { background: #eaeff1; color: var(--text-1); }
.btn-danger { background: var(--c-danger); color: #fff; }
.btn-danger-ghost { background: var(--c-danger-l); color: var(--c-danger); }
.btn-outline { background: #fff; color: var(--c-primary-h); border: 1.5px solid var(--c-primary); }

/* ===== Detail card ===== */
.detail-card { background: var(--surface); border-radius: var(--r-lg); padding: 18px; box-shadow: var(--sh-sm); }
.detail-row { display: flex; justify-content: space-between; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--border); font-size: 14px; }
.detail-row:last-child { border-bottom: none; }
.detail-row .label { color: var(--text-2); flex-shrink: 0; }
.detail-row .value { font-weight: 600; text-align: right; }

/* ===== Fund ===== */
.fund-summary { display: flex; gap: 10px; margin: 14px 0; }
.fund-summary .box { flex: 1; background: var(--surface); border-radius: var(--r-md); padding: 12px; text-align: center; box-shadow: var(--sh-sm); }
.fund-summary .box .num { font-size: 20px; font-weight: 800; }
.fund-summary .box .lbl { font-size: 12px; color: var(--text-2); }

/* ===== Report ===== */
.report-tabs { display: flex; gap: 8px; margin-bottom: 16px; overflow-x: auto; padding-bottom: 4px; }
.report-tab {
  flex-shrink: 0; padding: 10px 14px; border: 1.5px solid var(--border); background: var(--surface);
  border-radius: 999px; font-weight: 600; font-size: 13px; color: var(--text-2); cursor: pointer;
}
.report-tab.active { background: var(--c-primary); border-color: var(--c-primary); color: #fff; }

.report-preview { background: var(--surface); border-radius: var(--r-lg); padding: 20px; margin-top: 10px; box-shadow: var(--sh-sm); line-height: 1.8; font-size: 14px; }
.report-preview h3 { margin: 0 0 10px; color: var(--c-primary-h); }
.report-preview .rline { display: flex; justify-content: space-between; border-bottom: 1px dashed var(--border); padding: 6px 0; }
.report-table { width: 100%; border-collapse: collapse; font-size: 13px; margin-top: 8px; }
.report-table th, .report-table td { border: 1px solid var(--border); padding: 8px; text-align: left; }
.report-table th { background: var(--c-primary-l); color: var(--c-primary-h); }

/* ===== Empty state ===== */
.empty-state { text-align: center; padding: 40px 16px; color: var(--text-3); }
.empty-state .icon { font-size: 42px; opacity: .45; margin-bottom: 10px; }
.empty-state .title { font-weight: 700; color: var(--text-2); margin-bottom: 4px; }
.empty-state-desc { font-size: var(--fs-sm); color: var(--text-3); max-width: 320px; margin: 0 auto 14px; line-height: 1.5; }
.empty-state-cta { margin-top: 2px; }

/* ===== Skeleton loading (danh sách/card đang tải) ===== */
@keyframes skeleton-shimmer { 0% { background-position: -120% 0; } 100% { background-position: 120% 0; } }
.skeleton {
  background: linear-gradient(90deg, var(--border) 25%, #eef1f3 37%, var(--border) 63%);
  background-size: 400% 100%; animation: skeleton-shimmer 1.4s ease infinite;
  border-radius: var(--r-sm);
}
.skeleton-card { background: var(--surface); border-radius: var(--r-md); padding: 14px; box-shadow: var(--sh-sm); display: flex; flex-direction: column; gap: 10px; }
.skeleton-line { height: 12px; }
.skeleton-line--title { width: 55%; height: 15px; }
.skeleton-line--sub { width: 80%; }
.skeleton-line--meta { width: 40%; }
.skeleton-list { display: flex; flex-direction: column; gap: 10px; }

/* ===== Spinner ===== */
@keyframes spin { to { transform: rotate(360deg); } }
.spinner {
  display: inline-block; width: 16px; height: 16px; border-radius: 50%;
  border: 2.5px solid rgba(255,255,255,.4); border-top-color: #fff;
  animation: spin .7s linear infinite; vertical-align: -3px; margin-right: 7px;
}
.spinner--dark { border-color: rgba(14,95,118,.25); border-top-color: var(--c-primary); }
.btn[disabled] { opacity: .75; cursor: wait; }

/* ===== Progress bar (Import Excel / AI / Export đang xử lý) ===== */
.progress-bar { height: 8px; border-radius: 999px; background: var(--border); overflow: hidden; margin: 10px 0; }
.progress-bar-fill { height: 100%; background: var(--c-primary); border-radius: 999px; transition: width .25s ease; width: 0%; }
.progress-bar.is-indeterminate .progress-bar-fill {
  width: 40% !important; animation: progress-indeterminate 1.1s ease-in-out infinite;
}
@keyframes progress-indeterminate {
  0% { margin-left: -40%; } 100% { margin-left: 100%; }
}
.progress-label { font-size: var(--fs-xs); color: var(--text-2); font-weight: 600; margin-top: -4px; margin-bottom: 8px; }

/* ===== Biểu đồ (Dashboard) ===== */
.chart-grid { display: grid; grid-template-columns: 1fr; gap: 14px; margin-bottom: 10px; }
.chart-card { background: var(--surface); border-radius: var(--r-md); padding: 16px; box-shadow: var(--sh-sm); }
.chart-card h3 { font-size: 14px; font-weight: 700; color: var(--text-2); margin-bottom: 10px; }
.chart-svg { width: 100%; height: auto; }
.chart-empty { color: var(--text-3); font-size: 13px; text-align: center; padding: 20px 0; }
.chart-donut-wrap { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; }
.chart-donut { width: 140px; height: 140px; flex-shrink: 0; }
.chart-legend { display: flex; flex-direction: column; gap: 6px; font-size: 13px; }
.chart-legend-item { display: flex; align-items: center; gap: 8px; }
.chart-legend-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }

/* ===== Banner chỉ xem (phân quyền) ===== */
.readonly-banner {
  background: var(--c-warning-l); color: #92400e; border: 1px solid #fde68a;
  border-radius: var(--r-sm); padding: 10px 14px; font-size: 13px; margin-bottom: 14px;
  display: flex; align-items: center; gap: 8px;
}
.readonly-banner[hidden] { display: none; }

/* ===== Nhật ký hệ thống ===== */
.log-item { background: var(--surface); border-radius: var(--r-md); padding: 12px 14px; box-shadow: var(--sh-sm); }
.log-item .log-top { display: flex; justify-content: space-between; gap: 10px; font-size: 12px; color: var(--text-3); }
.log-item .log-action { font-weight: 700; font-size: 14px; margin-top: 4px; }
.log-item .log-detail { font-size: 13px; color: var(--text-2); margin-top: 2px; }

/* ===== Sao lưu / Khôi phục ===== */
.backup-card { background: var(--surface); border-radius: var(--r-lg); padding: 18px; box-shadow: var(--sh-sm); margin-bottom: 14px; }
.backup-card h3 { font-size: 15px; margin-bottom: 6px; }
.backup-card p { font-size: 13px; color: var(--text-2); margin-bottom: 12px; }

/* ===== AI — nút, thẻ viết bằng AI, kết quả AI ===== */
:root { --c-ai: #7c3aed; --c-ai-l: #f2ebfe; }
.btn-ai { background: linear-gradient(135deg, var(--c-ai), #a855f7); color: #fff; }
.ai-write-card { background: var(--c-ai-l); border: 1px solid #ddd6fe; border-radius: var(--r-lg); padding: 16px; margin-bottom: 16px; }
.ai-write-card h3 { font-size: 15px; color: #5b21b6; margin-bottom: 4px; }
.ai-write-card p { font-size: 13px; color: var(--text-2); margin-bottom: 12px; }
.ai-topic-grid { display: flex; flex-wrap: wrap; gap: 8px; }
.ai-topic-btn {
  border: 1.5px solid #ddd6fe; background: #fff; color: #5b21b6; border-radius: 999px;
  padding: 9px 14px; font-size: 13px; font-weight: 600; cursor: pointer;
}
.ai-topic-btn:active { background: var(--c-ai-l); }
.ai-topic-btn[disabled] { opacity: .6; cursor: wait; }
.ai-status { font-size: 12px; color: #5b21b6; margin-top: 10px; }
.ai-status[hidden] { display: none; }

.ai-output-card {
  background: var(--c-ai-l); border: 1px solid #ddd6fe; border-radius: var(--r-lg);
  padding: 16px; margin: 12px 0; font-size: 14px; line-height: 1.7; white-space: pre-wrap;
}
.ai-output-card[hidden] { display: none; }
.ai-output-card .ai-output-title { font-weight: 700; color: #5b21b6; margin-bottom: 8px; font-size: 13px; }
.ai-output-card .ai-output-actions { margin-top: 12px; display: flex; gap: 8px; flex-wrap: wrap; }

.demo-badge {
  display: inline-block; background: var(--c-warning-l); color: #92400e; font-size: 11px;
  font-weight: 700; padding: 2px 8px; border-radius: 999px; margin-left: 6px; vertical-align: middle;
}

.ai-status-banner {
  border-radius: var(--r-sm); padding: 10px 14px; font-size: 13px; margin-bottom: 14px; font-weight: 600;
}
.ai-status-banner.is-demo { background: var(--c-warning-l); color: #92400e; border: 1px solid #fde68a; }
.ai-status-banner.is-configured { background: var(--c-success-l); color: #15803d; border: 1px solid #bbf7d0; }

/* ===== Khung chat (AI Assistant / Hỏi đáp) ===== */
.chat-wrap { display: flex; flex-direction: column; height: calc(100vh - 220px); min-height: 360px; }
.chat-log { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; padding: 4px 2px 10px; }
.chat-bubble { max-width: 82%; padding: 10px 14px; border-radius: 14px; font-size: 14px; line-height: 1.6; white-space: pre-wrap; }
.chat-bubble.user { align-self: flex-end; background: var(--c-primary); color: #fff; border-bottom-right-radius: 4px; }
.chat-bubble.assistant { align-self: flex-start; background: var(--surface); box-shadow: var(--sh-sm); border-bottom-left-radius: 4px; }
.chat-input-row { display: flex; gap: 8px; }
.chat-input-row input {
  flex: 1; padding: 12px 14px; border: 1.5px solid var(--border); border-radius: var(--r-sm); background: var(--surface);
}
.chat-input-row input:focus { outline: none; border-color: var(--c-primary); box-shadow: 0 0 0 3px rgba(14,95,118,.12); }

/* ===== Trợ lý công việc hôm nay ===== */
.task-assistant-card { background: var(--surface); border-radius: var(--r-lg); padding: 16px; box-shadow: var(--sh-sm); margin-bottom: 18px; }
.task-assistant-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.task-assistant-header h2 { font-size: 16px; font-weight: 700; }
.task-count-badge { background: var(--c-primary-l); color: var(--c-primary-h); font-size: 12px; font-weight: 700; padding: 4px 10px; border-radius: 999px; }
.task-list { display: flex; flex-direction: column; gap: 10px; }
.task-item { border: 1.5px solid var(--border); border-radius: var(--r-md); padding: 12px; }
.task-item.priority-high { border-left: 4px solid var(--c-danger); }
.task-item.priority-medium { border-left: 4px solid var(--c-warning); }
.task-item.priority-low { border-left: 4px solid var(--text-3); }
.task-item.done { opacity: .55; }
.task-item.done .task-title { text-decoration: line-through; }
.task-item-row { display: flex; align-items: flex-start; gap: 10px; }
.task-checkbox { width: 22px; height: 22px; flex-shrink: 0; margin-top: 2px; accent-color: var(--c-primary); cursor: pointer; }
.task-title { font-weight: 700; font-size: 14px; }
.task-detail { font-size: 13px; color: var(--text-2); margin-top: 2px; white-space: pre-wrap; }
.task-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.task-actions .btn { padding: 8px 12px; font-size: 12px; }
.task-empty { text-align: center; padding: 20px; color: var(--text-3); font-size: 14px; }

/* ===== FAB ===== */
.fab {
  position: fixed; right: 20px; bottom: 88px; width: 56px; height: 56px; border-radius: 50%;
  background: var(--c-primary); color: #fff; font-size: 28px; border: none; box-shadow: var(--sh-md);
  cursor: pointer; z-index: 15; line-height: 0;
}
.fab:active { transform: scale(.94); }

/* ===== Bottom nav (mobile) ===== */
.bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20;
  display: flex; background: var(--surface); border-top: 1px solid var(--border);
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
}
.nav-item {
  flex: 1; background: none; border: none; display: flex; flex-direction: column;
  align-items: center; gap: 2px; padding: 6px 2px; font-size: 11px; color: var(--text-3);
  font-weight: 600; cursor: pointer; border-radius: var(--r-sm);
}
.nav-item.active { color: var(--c-primary-h); }
.nav-item[hidden] { display: none; }
.nav-icon { font-size: 20px; }

/* ===== Toast (stack tối đa 4, tự ẩn, có icon theo loại) ===== */
.toast-container {
  position: fixed; bottom: 100px; left: 50%; transform: translateX(-50%);
  display: flex; flex-direction: column-reverse; gap: 8px; z-index: 100;
  width: min(360px, 92vw); align-items: center;
}
.toast-item {
  display: flex; align-items: center; gap: 9px; background: #14212b; color: #fff;
  padding: 12px 16px; border-radius: 999px; font-size: 13.5px; font-weight: 600;
  box-shadow: var(--sh-md); width: 100%; justify-content: center; text-align: center;
  animation: toast-in .18s ease;
}
.toast-item .toast-icon { font-size: 16px; flex-shrink: 0; }
.toast-item--success { background: #0f3d24; }
.toast-item--success .toast-icon { color: #4ade80; }
.toast-item--error { background: #4c1414; }
.toast-item--error .toast-icon { color: #f87171; }
.toast-item--warning { background: #4a3306; }
.toast-item--warning .toast-icon { color: #fbbf24; }
.toast-item--info { background: #0e2f3d; }
.toast-item--info .toast-icon { color: #7dd3fc; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

/* ===== Confirm dialog ===== */
.dialog-overlay {
  position: fixed; inset: 0; background: rgba(10,20,25,.45); z-index: 200;
  display: flex; align-items: center; justify-content: center; padding: 24px;
}
.dialog-overlay[hidden] { display: none; }
.dialog-box { background: #fff; border-radius: var(--r-lg); padding: 20px; max-width: 320px; width: 100%; box-shadow: var(--sh-lg); }
.dialog-box p { font-size: 15px; margin-bottom: 18px; }
.dialog-actions { display: flex; gap: 10px; }
.dialog-actions .btn { flex: 1; }

/* ===== Responsive: mobile (mặc định) → tablet (768px) → laptop/desktop (1024px) → desktop rộng (1280px) ===== */
@media (min-width: 640px) {
  .stat-grid { grid-template-columns: repeat(3, 1fr); }
  .menu-grid { grid-template-columns: repeat(4, 1fr); }
  .chart-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (min-width: 768px) {
  .stat-grid { grid-template-columns: repeat(4, 1fr); }
  .menu-grid { grid-template-columns: repeat(5, 1fr); }
  .content { padding: 22px 26px; }
}
@media (min-width: 1024px) {
  .chart-grid { grid-template-columns: repeat(3, 1fr); }
  .stat-grid { grid-template-columns: repeat(4, 1fr); }
}
@media (min-width: 1280px) {
  .content { max-width: var(--content-max-lg); }
  .stat-grid { grid-template-columns: repeat(6, 1fr); }
}

@media (min-width: 1024px) {
  /* Sidebar cố định luôn hiện, không còn là drawer trượt */
  .side-drawer {
    position: sticky; top: 0; left: auto; transform: none !important;
    width: var(--sidebar-w); height: 100vh; flex-shrink: 0; box-shadow: none;
    border-right: 1px solid rgba(255,255,255,.08);
  }
  .drawer-backdrop { display: none; }
  .bottom-nav { display: none; } /* sidebar đã có đủ điều hướng */
  .content { padding: 28px 32px; padding-bottom: 32px; }
  .fab { bottom: 32px; }
}

/* ===== In / Xuất PDF ===== */
@media print {
  .topbar, .bottom-nav, .fab, .side-drawer, .drawer-backdrop,
  #form-report, .report-tabs, .form-actions-row { display: none !important; }
  .content { padding: 0; max-width: 100%; }
  body { background: #fff; }
}
