/* ==========================================================================
   Quản lý Nội bộ · UBND Xã Bình Mỹ — hệ thống giao diện
   Màu sắc gom thành biến ở :root; chế độ tối ghi đè các biến này.
   ========================================================================== */

:root {
  --font: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;

  --bg: #f3f6fb;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --surface-3: #eef2f7;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --text: #0f172a;
  --text-2: #475569;
  --text-3: #7c8aa3;

  --primary: #2563eb;
  --primary-soft: #eaf2ff;
  --primary-text: #1d4ed8;
  --success: #059669;
  --success-soft: #e7f8f1;
  --danger: #dc2626;
  --danger-soft: #fdecec;
  --warning: #b45309;
  --warning-soft: #fdf3dc;

  --sidebar-w: 268px;
  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 18px;
  --shadow-sm: 0 1px 2px rgb(15 23 42 / 0.05);
  --shadow: 0 1px 2px rgb(15 23 42 / 0.04), 0 8px 24px -12px rgb(15 23 42 / 0.12);
  --shadow-lg: 0 24px 60px -20px rgb(15 23 42 / 0.35);
  --ring: 0 0 0 4px rgb(37 99 235 / 0.16);
  color-scheme: light;
}

:root[data-theme='dark'] {
  --bg: #0a1020;
  --surface: #121a2d;
  --surface-2: #0e1628;
  --surface-3: #1b2640;
  --border: #22304d;
  --border-strong: #33446a;
  --text: #e8eefb;
  --text-2: #aab6cc;
  --text-3: #74829f;
  --primary: #60a5fa;
  --primary-soft: rgb(96 165 250 / 0.14);
  --primary-text: #93c5fd;
  --success: #34d399;
  --success-soft: rgb(52 211 153 / 0.13);
  --danger: #f87171;
  --danger-soft: rgb(248 113 113 / 0.14);
  --warning: #fbbf24;
  --warning-soft: rgb(251 191 36 / 0.14);
  --shadow: 0 1px 2px rgb(0 0 0 / 0.3), 0 8px 24px -12px rgb(0 0 0 / 0.6);
  --shadow-lg: 0 24px 60px -20px rgb(0 0 0 / 0.7);
  --ring: 0 0 0 4px rgb(96 165 250 / 0.22);
  color-scheme: dark;
}

/* ---------- Nền tảng ---------- */
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4, p { margin: 0; }
h1, h2, h3, h4 { line-height: 1.25; letter-spacing: -0.01em; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: inherit; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; border-radius: 6px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip-link {
  position: absolute; left: 12px; top: -60px; z-index: 300;
  padding: 8px 14px; border-radius: 8px; background: var(--primary); color: #fff; font-weight: 600;
  transition: top .2s;
}
.skip-link:focus { top: 12px; }
.muted { color: var(--text-3); }
.t-right { text-align: right; }

/* ---------- Khung ứng dụng ---------- */
.app { display: flex; height: 100vh; height: 100dvh; overflow: hidden; }

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: linear-gradient(180deg, #0c1528 0%, #111d36 100%);
  color: #94a3b8;
  transition: width .25s ease;
  overflow: hidden;
  z-index: 40;
}
.brand {
  height: 72px; flex-shrink: 0;
  display: flex; align-items: center; gap: 12px;
  padding: 0 20px;
  border-bottom: 1px solid rgb(255 255 255 / 0.06);
}
.brand-mark {
  width: 40px; height: 40px; flex-shrink: 0;
  display: grid; place-items: center;
  border-radius: 12px;
  background: linear-gradient(135deg, #3b82f6, #0ea5e9);
  color: #fff; font-size: 17px;
  box-shadow: 0 10px 24px -8px rgb(59 130 246 / 0.7);
}
.brand-text { display: flex; flex-direction: column; min-width: 0; white-space: nowrap; }
.brand-text strong { color: #fff; font-size: 14px; font-weight: 800; letter-spacing: .06em; }
.brand-text span { font-size: 12px; color: #7d8ba6; }

.nav { flex: 1; display: flex; flex-direction: column; gap: 4px; padding: 18px 14px; }
.nav-label {
  padding: 6px 12px 10px;
  font-size: 11px; font-weight: 700; letter-spacing: .14em; text-transform: uppercase;
  color: #5b6b87; white-space: nowrap;
}
.nav-label.nav-group-gap { margin-top: 14px; padding-top: 14px; border-top: 1px solid rgb(255 255 255 / 0.06); }
.nav-item {
  position: relative;
  display: flex; align-items: center; gap: 12px;
  padding: 11px 12px;
  border-radius: 10px;
  color: #9aa8bf; text-decoration: none; font-weight: 600; white-space: nowrap;
  transition: background .2s, color .2s;
}
.nav-item i { width: 20px; flex-shrink: 0; text-align: center; font-size: 15px; }
.nav-item:hover { background: rgb(255 255 255 / 0.05); color: #e2e8f0; }
.nav-item.is-active {
  background: linear-gradient(90deg, rgb(59 130 246 / 0.24), rgb(59 130 246 / 0.04));
  color: #fff;
}
.nav-item.is-active i { color: #7cb6ff; }
.nav-item.is-active::before {
  content: ''; position: absolute; left: -14px; top: 9px; bottom: 9px;
  width: 3px; border-radius: 0 3px 3px 0; background: #60a5fa;
}
.nav-count {
  margin-left: auto; min-width: 22px; padding: 1px 7px;
  border-radius: 999px; background: rgb(248 113 113 / 0.2); color: #fca5a5;
  font-size: 11px; font-weight: 700; text-align: center;
}
.sidebar-foot {
  display: flex; align-items: center; gap: 12px;
  padding: 16px 18px;
  border-top: 1px solid rgb(255 255 255 / 0.06);
}
.user-meta { display: flex; flex-direction: column; min-width: 0; white-space: nowrap; }
.user-meta strong { color: #e2e8f0; font-size: 13px; }
.user-meta span { color: #7d8ba6; font-size: 12px; }
.scrim { display: none; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; overflow: hidden; }
.topbar {
  position: relative; z-index: 10;
  height: 72px; flex-shrink: 0;
  display: flex; align-items: center; gap: 14px;
  padding: 0 24px;
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(12px);
}
.topbar-title { flex: 1; min-width: 0; }
.topbar-title h1 { font-size: 19px; font-weight: 800; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-title p { font-size: 12.5px; color: var(--text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-actions { display: flex; align-items: center; gap: 12px; }
.clock { display: flex; flex-direction: column; align-items: flex-end; line-height: 1.25; }
.clock span { font-size: 12px; color: var(--text-3); text-transform: capitalize; }
.clock strong { font-size: 14px; font-variant-numeric: tabular-nums; }

.icon-btn {
  width: 38px; height: 38px; flex-shrink: 0;
  display: inline-grid; place-items: center;
  border: 1px solid transparent; border-radius: 10px;
  background: transparent; color: var(--text-2);
  transition: background .2s, color .2s, border-color .2s;
}
.icon-btn:hover { background: var(--surface-3); color: var(--text); }
.icon-btn.bordered { border-color: var(--border-strong); background: var(--surface); }
.icon-btn.is-danger:hover { color: var(--danger); background: var(--danger-soft); }
.icon-btn.banner-close { position: absolute; top: 14px; right: 14px; color: #fff; background: rgb(255 255 255 / 0.16); }
.icon-btn.banner-close:hover { background: rgb(255 255 255 / 0.28); color: #fff; }

.content { flex: 1; overflow-y: auto; padding: 24px; }
.view {
  max-width: 1400px; margin: 0 auto;
  display: flex; flex-direction: column; gap: 16px;
  animation: rise .35s ease both;
}
@keyframes rise { from { opacity: 0; transform: translateY(6px); } }

@media (min-width: 961px) {
  .app.is-collapsed .sidebar { width: 80px; }
  .app.is-collapsed .brand { justify-content: center; padding: 0; }
  .app.is-collapsed .brand-text,
  .app.is-collapsed .nav-text,
  .app.is-collapsed .nav-count,
  .app.is-collapsed .nav-label,
  .app.is-collapsed .user-meta { display: none; }
  .app.is-collapsed .nav-item { justify-content: center; padding: 12px 0; }
  .app.is-collapsed .sidebar-foot { justify-content: center; padding: 16px 0; }
}

@media (max-width: 960px) {
  .sidebar {
    position: fixed; inset: 0 auto 0 0; height: 100%;
    transform: translateX(-102%);
    transition: transform .3s cubic-bezier(.2, .8, .2, 1);
    box-shadow: var(--shadow-lg);
  }
  .app.nav-open .sidebar { transform: none; }
  .scrim {
    display: block; position: fixed; inset: 0; z-index: 35;
    background: rgb(2 6 23 / 0.5);
    opacity: 0; pointer-events: none; transition: opacity .3s;
  }
  .app.nav-open .scrim { opacity: 1; pointer-events: auto; }
  .content { padding: 16px; }
  .topbar { padding: 0 16px; }
  .clock { display: none; }
}
@media (max-width: 640px) {
  .topbar-title p { display: none; }
}

/* ---------- Thành phần chung ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}
.card-title { font-size: 14px; font-weight: 700; }

.toolbar {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between;
  gap: 12px; padding: 14px 16px;
}
.toolbar-group { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; min-width: 0; }
.search { position: relative; display: block; width: 280px; max-width: 100%; }
.search i {
  position: absolute; left: 13px; top: 50%; transform: translateY(-50%);
  color: var(--text-3); font-size: 13px; pointer-events: none;
}
.search .input { width: 100%; padding-left: 36px; }
.date-range { display: flex; align-items: center; gap: 8px; font-size: 12px; font-weight: 700; color: var(--text-3); text-transform: uppercase; letter-spacing: .06em; }
.date-range .input { width: 150px; }

.input {
  height: 40px; min-width: 0;
  padding: 0 12px;
  border: 1px solid var(--border-strong); border-radius: 10px;
  background: var(--surface);
  font-size: 14px;
  transition: border-color .2s, box-shadow .2s;
}
.input::placeholder { color: var(--text-3); }
.input:focus { outline: none; border-color: var(--primary); box-shadow: var(--ring); }
.input[readonly] { background: var(--surface-2); color: var(--text-2); }
select.input {
  padding-right: 34px; cursor: pointer; appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5l5 5 5-5' fill='none' stroke='%237c8aa3' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
}
textarea.input { height: auto; min-height: 92px; padding: 10px 12px; resize: vertical; line-height: 1.55; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 40px; padding: 0 16px;
  border: 1px solid transparent; border-radius: 10px;
  font-size: 14px; font-weight: 600; white-space: nowrap; text-decoration: none;
  transition: transform .15s, box-shadow .2s, background .2s, border-color .2s, filter .2s;
}
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn-primary {
  background: linear-gradient(180deg, #3b82f6 0%, #2563eb 100%);
  color: #fff;
  box-shadow: 0 8px 18px -10px rgb(37 99 235 / 0.9);
}
.btn-primary:hover { box-shadow: 0 12px 24px -10px rgb(37 99 235 / 0.95); }
.btn-secondary { background: var(--surface); border-color: var(--border-strong); color: var(--text); }
.btn-secondary:hover { background: var(--surface-3); }
.btn-ghost { background: transparent; color: var(--primary-text); }
.btn-ghost:hover { background: var(--primary-soft); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { filter: brightness(1.06); }
.btn-danger-ghost { background: transparent; color: var(--danger); }
.btn-danger-ghost:hover { background: var(--danger-soft); }
.btn-sm { height: 34px; padding: 0 12px; font-size: 13px; border-radius: 9px; }
.btn-group { display: flex; flex-wrap: wrap; gap: 10px; }

.segmented {
  display: inline-flex; gap: 4px; padding: 4px;
  border: 1px solid var(--border); border-radius: 11px;
  background: var(--surface-3);
}
.segmented button {
  height: 32px; padding: 0 14px;
  border: none; border-radius: 8px;
  background: transparent; color: var(--text-2);
  font-size: 13px; font-weight: 600;
  transition: background .2s, color .2s;
}
.segmented button[aria-pressed='true'] { background: var(--surface); color: var(--primary-text); box-shadow: var(--shadow-sm); }

.cal-nav { display: flex; align-items: center; gap: 6px; }
.cal-title { min-width: 170px; font-size: 18px; font-weight: 800; }

.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 10px; border: 1px solid var(--border); border-radius: 999px;
  background: var(--surface-3); color: var(--text-2);
  font-size: 12px; font-weight: 600; white-space: nowrap;
}
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip-person {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 4px 12px 4px 4px;
  border: 1px solid var(--border); border-radius: 999px;
  background: var(--surface-2);
  font-size: 13px; font-weight: 600;
}

.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: 999px;
  font-size: 12px; font-weight: 700; white-space: nowrap;
}
.badge-todo { background: var(--surface-3); color: var(--text-2); }
.badge-doing { background: var(--primary-soft); color: var(--primary-text); }
.badge-done { background: var(--success-soft); color: var(--success); }
.badge-overdue { background: var(--danger-soft); color: var(--danger); }
.badge-deadline { background: var(--warning-soft); color: var(--warning); }
.prio-high { background: var(--danger-soft); color: var(--danger); }
.prio-mid { background: var(--primary-soft); color: var(--primary-text); }
.prio-low { background: var(--surface-3); color: var(--text-2); }

.avatar {
  width: 36px; height: 36px; flex-shrink: 0;
  display: inline-grid; place-items: center;
  border-radius: 50%;
  font-size: 14px; font-weight: 700;
}
.avatar.sm { width: 26px; height: 26px; font-size: 11px; }
.avatar.lg { width: 96px; height: 96px; font-size: 36px; box-shadow: 0 0 0 5px var(--surface), var(--shadow); }
.av-0 { background: #fde9b4; color: #8a4b08; }
.av-1 { background: #cfe3ff; color: #1e4fb8; }
.av-2 { background: #c9f1df; color: #0b6b48; }
.av-3 { background: #e4dcff; color: #5b34c4; }
.av-4 { background: #fcd9ea; color: #9d2663; }
.av-5 { background: #c8f1f6; color: #0b6a7d; }
.av-none { background: var(--surface-3); color: var(--text-3); }
:root[data-theme='dark'] .av-0 { background: rgb(251 191 36 / 0.16); color: #fcd34d; }
:root[data-theme='dark'] .av-1 { background: rgb(96 165 250 / 0.18); color: #93c5fd; }
:root[data-theme='dark'] .av-2 { background: rgb(52 211 153 / 0.16); color: #6ee7b7; }
:root[data-theme='dark'] .av-3 { background: rgb(167 139 250 / 0.18); color: #c4b5fd; }
:root[data-theme='dark'] .av-4 { background: rgb(244 114 182 / 0.16); color: #f9a8d4; }
:root[data-theme='dark'] .av-5 { background: rgb(34 211 238 / 0.16); color: #67e8f9; }

.person { display: flex; align-items: center; gap: 12px; min-width: 0; }
.person-meta { min-width: 0; }
.person-name { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.person-sub { font-size: 12px; color: var(--text-3); }
.dept-icon {
  width: 38px; height: 38px; flex-shrink: 0;
  display: grid; place-items: center;
  border-radius: 11px;
  background: var(--primary-soft); color: var(--primary);
}
a.tel { color: var(--text-2); text-decoration: none; font-variant-numeric: tabular-nums; }
a.tel:hover { color: var(--primary); }

.eyebrow {
  font-size: 11.5px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--text-3);
}
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.section-gap { margin-top: 22px; }
.empty {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 56px 16px; text-align: center; color: var(--text-3);
}
.empty i { margin-bottom: 8px; font-size: 40px; opacity: 0.35; }
.empty p { font-weight: 700; color: var(--text-2); }
.empty-inline {
  padding: 14px; text-align: center; font-size: 13px; color: var(--text-3);
  background: var(--surface-2); border: 1px dashed var(--border-strong); border-radius: var(--radius);
}

/* ---------- KPI ---------- */
.kpi-grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.kpi {
  --tone: #64748b;
  position: relative; overflow: hidden;
  display: flex; flex-direction: column; gap: 14px;
  padding: 18px 20px;
}
.kpi::after {
  content: ''; position: absolute; right: -34px; top: -34px;
  width: 116px; height: 116px; border-radius: 50%;
  background: var(--tone); opacity: 0.08;
}
.kpi-head { display: flex; align-items: center; justify-content: space-between; }
.kpi-label { font-size: 12px; font-weight: 700; letter-spacing: .07em; text-transform: uppercase; color: var(--text-3); }
.kpi-icon {
  width: 38px; height: 38px; display: grid; place-items: center;
  border-radius: 11px; font-size: 15px;
  background: color-mix(in srgb, var(--tone) 14%, transparent);
  color: var(--tone);
}
.kpi-value { font-size: 34px; font-weight: 800; line-height: 1; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.tone-slate { --tone: #64748b; }
.tone-blue { --tone: #2563eb; }
.tone-green { --tone: #059669; }
.tone-red { --tone: #dc2626; }
.tone-amber { --tone: #d97706; }

/* ---------- Trang Giao việc ---------- */
.tasks-top { display: grid; grid-template-columns: minmax(280px, 340px) minmax(0, 1fr); gap: 16px; }
.chart-card { display: flex; flex-direction: column; gap: 16px; padding: 20px; }
.tasks-top > *, .kpi-grid-2 > * { min-width: 0; }
.chart-wrap { position: relative; height: 190px; min-width: 0; }
.chart-wrap canvas { max-width: 100%; }
.chart-center {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  pointer-events: none;
}
.chart-center strong { font-size: 30px; font-weight: 800; line-height: 1; font-variant-numeric: tabular-nums; }
.chart-center span { margin-top: 4px; font-size: 12px; color: var(--text-3); }
.legend { display: grid; gap: 10px; margin: 0; padding: 0; list-style: none; }
.legend li { display: flex; align-items: center; justify-content: space-between; font-size: 13px; color: var(--text-2); }
.legend b { color: var(--text); font-variant-numeric: tabular-nums; }
.legend-dot { display: inline-block; width: 10px; height: 10px; margin-right: 8px; border-radius: 3px; vertical-align: middle; }
@media (max-width: 1100px) { .tasks-top { grid-template-columns: minmax(0, 1fr); } }

/* ---------- Bảng ---------- */
.table-card { overflow: hidden; }
.table-wrap { overflow-x: auto; }
.table { width: 100%; min-width: 820px; border-collapse: separate; border-spacing: 0; }
.table th {
  position: sticky; top: 0; z-index: 1;
  padding: 13px 16px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  font-size: 11.5px; font-weight: 700; letter-spacing: .07em; text-transform: uppercase;
  color: var(--text-3); text-align: left; white-space: nowrap;
}
.table td { padding: 15px 16px; vertical-align: middle; border-bottom: 1px solid var(--border); }
.table tbody tr { transition: background .15s; }
.table tbody tr[data-id] { cursor: pointer; }
.table tbody tr:hover { background: var(--surface-2); }
.table tbody tr:focus-visible { outline: none; box-shadow: inset 3px 0 0 var(--primary); }
.table tbody tr:last-child td { border-bottom: none; }
.table tr.is-overdue td:first-child { box-shadow: inset 3px 0 0 var(--danger); }

.task-title { display: flex; align-items: center; gap: 8px; font-weight: 700; }
.task-desc {
  max-width: 420px; margin-top: 3px;
  font-size: 12.5px; color: var(--text-3);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.meta-line { display: flex; align-items: center; gap: 6px; margin-top: 4px; font-size: 12px; color: var(--text-3); }
.sync-icon { font-size: 12px; color: var(--primary); }
.date-chip {
  display: inline-block; padding: 4px 10px; border-radius: 8px;
  background: var(--surface-3); font-size: 13px; font-weight: 600; white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.date-chip.is-overdue { background: var(--danger-soft); color: var(--danger); }
.row-actions { display: inline-flex; gap: 4px; }
.row-actions .icon-btn { width: 32px; height: 32px; }

/* ---------- Lịch công tác ---------- */
.cal-card { display: flex; flex-direction: column; overflow: hidden; }
.cal-head, .cal-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); }
.cal-head { background: var(--surface-2); border-bottom: 1px solid var(--border); }
.cal-head div {
  padding: 12px 8px; text-align: center;
  font-size: 11.5px; font-weight: 700; letter-spacing: .07em; text-transform: uppercase; color: var(--text-3);
}
.cal-head .is-weekend { color: var(--danger); }
.cal-cell {
  position: relative; min-width: 0; min-height: 116px;
  display: flex; flex-direction: column; gap: 4px;
  padding: 8px;
  border-right: 1px solid var(--border); border-bottom: 1px solid var(--border);
  cursor: pointer; transition: background .15s;
}
.cal-cell:nth-child(7n) { border-right: none; }
.cal-cell:hover, .cal-cell:focus-visible { background: var(--surface-2); }
.cal-cell.is-muted { background: var(--surface-2); }
.cal-cell.is-muted .day-num { color: var(--text-3); }
.cal-cell.is-weekend .day-num { color: var(--danger); }
.cal-cell.is-today .day-num { background: var(--primary); color: #fff; box-shadow: 0 6px 14px -6px var(--primary); }
.day-num {
  align-self: flex-end; width: 28px; height: 28px;
  display: grid; place-items: center; margin-bottom: 2px;
  border-radius: 50%;
  font-size: 13px; font-weight: 700; color: var(--text-2);
}
.cal-grid.is-week .cal-cell { min-height: 460px; }
.ev {
  display: flex; align-items: center; gap: 6px;
  width: 100%; min-width: 0;
  padding: 4px 7px;
  border: none; border-radius: 6px;
  background: var(--primary-soft); color: var(--primary-text);
  font-size: 12px; font-weight: 600; text-align: left;
}
.ev:hover { filter: brightness(0.97); }
.ev-time { flex-shrink: 0; font-weight: 700; font-variant-numeric: tabular-nums; }
.ev-title { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ev-deadline { background: var(--warning-soft); color: var(--warning); }
.ev.is-done { opacity: 0.55; text-decoration: line-through; }
.ev-more {
  align-self: flex-start; padding: 2px 6px;
  border: none; border-radius: 6px; background: none;
  color: var(--primary-text); font-size: 12px; font-weight: 700;
}
.ev-more:hover { background: var(--primary-soft); }

@media (max-width: 720px) {
  .cal-title { min-width: 0; font-size: 16px; }
  .cal-cell { min-height: 60px; align-items: center; padding: 4px; }
  .day-num { align-self: center; width: 24px; height: 24px; font-size: 12px; }
  .ev { width: 7px; height: 7px; padding: 0; border-radius: 50%; background: var(--primary); }
  .ev-deadline { background: var(--warning); }
  .ev-time, .ev-title, .ev-more { display: none; }
  .cal-grid.is-week .cal-cell { min-height: 120px; }
}

/* ---------- Modal ---------- */
.modal {
  position: fixed; inset: 0; z-index: 100;
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  background: rgb(2 6 23 / 0.55);
  backdrop-filter: blur(5px);
  animation: fadeIn .2s ease;
}
@keyframes fadeIn { from { opacity: 0; } }
.modal-panel {
  width: min(640px, 100%); max-height: calc(100dvh - 40px);
  display: flex; flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  animation: pop .28s cubic-bezier(.2, .8, .2, 1);
}
@keyframes pop { from { opacity: 0; transform: translateY(10px) scale(0.98); } }
.modal-panel.wide { width: min(880px, 100%); }
.modal-panel.xwide { width: min(1120px, 100%); }
.modal-panel.narrow { width: min(430px, 100%); }
.modal-panel.detail { height: min(860px, calc(100dvh - 40px)); }
.modal-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  flex-shrink: 0; padding: 18px 22px;
  border-bottom: 1px solid var(--border);
}
.modal-title { display: flex; align-items: center; gap: 12px; font-size: 17px; font-weight: 800; }
.title-icon {
  width: 36px; height: 36px; flex-shrink: 0;
  display: grid; place-items: center; border-radius: 10px;
  background: var(--primary-soft); color: var(--primary); font-size: 15px;
}
.head-actions { display: flex; align-items: center; gap: 8px; }
.modal-body { flex: 1; min-height: 0; overflow-y: auto; padding: 22px; }
.modal-foot {
  display: flex; align-items: center; justify-content: flex-end; gap: 10px;
  flex-shrink: 0; padding: 16px 22px;
  border-top: 1px solid var(--border);
  background: var(--surface-2);
}
.modal-foot.split { justify-content: space-between; }

.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.field { display: flex; flex-direction: column; gap: 7px; min-width: 0; }
.field.full { grid-column: 1 / -1; }
fieldset.field { margin: 0; padding: 0; border: none; }
.label { display: flex; align-items: center; gap: 6px; padding: 0; font-size: 13px; font-weight: 600; color: var(--text-2); }
.req { color: var(--danger); }

.dropzone {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  margin-top: 8px; padding: 22px 16px;
  border: 1.5px dashed var(--border-strong); border-radius: var(--radius);
  background: var(--surface-2); text-align: center; cursor: pointer;
  transition: border-color .2s, background .2s;
}
.dropzone i { margin-bottom: 4px; font-size: 22px; color: var(--primary); }
.dropzone strong { font-size: 14px; }
.dropzone small { font-size: 12px; color: var(--text-3); }
.dropzone:hover, .dropzone.is-drag { border-color: var(--primary); background: var(--primary-soft); }

.sync-toggle {
  display: flex; align-items: flex-start; gap: 12px;
  margin-top: 22px; padding: 14px 16px;
  border: 1px solid color-mix(in srgb, var(--primary) 24%, transparent); border-radius: var(--radius);
  background: var(--primary-soft);
  cursor: pointer;
}
.sync-toggle input { width: 18px; height: 18px; margin-top: 2px; flex-shrink: 0; accent-color: var(--primary); }
.sync-toggle span { display: flex; flex-direction: column; gap: 2px; }
.sync-toggle strong { font-size: 13.5px; color: var(--primary-text); }
.sync-toggle small { font-size: 12px; color: var(--text-3); }

.check-list {
  display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px;
  max-height: 210px; overflow-y: auto; padding: 8px;
  border: 1px solid var(--border-strong); border-radius: 10px;
  background: var(--surface-2);
}
.check-item {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 8px 10px; border-radius: 8px;
  background: var(--surface); cursor: pointer;
}
.check-item:hover { background: var(--surface-3); }
.check-item input { width: 16px; height: 16px; margin-top: 2px; accent-color: var(--primary); }
.check-item span { display: flex; flex-direction: column; font-size: 13px; font-weight: 600; line-height: 1.3; }
.check-item small { font-size: 11.5px; font-weight: 500; color: var(--text-3); }
.radio-row { display: flex; flex-wrap: wrap; gap: 22px; padding: 4px 0; }
.radio-row label { display: flex; align-items: center; gap: 8px; font-weight: 500; cursor: pointer; }
.radio-row input { width: 16px; height: 16px; accent-color: var(--primary); }

/* Tệp đính kèm */
.file-list { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
.file-item {
  display: flex; align-items: center; gap: 12px; min-width: 0;
  padding: 10px 12px;
  border: 1px solid var(--border); border-radius: 12px;
  background: var(--surface);
  transition: border-color .2s, box-shadow .2s;
}
.file-item[data-preview-file] { cursor: pointer; }
.file-item[data-preview-file]:hover { border-color: var(--primary); box-shadow: var(--shadow-sm); }
.file-icon, .file-icon-lg {
  display: grid; place-items: center; flex-shrink: 0;
  width: 38px; height: 38px; border-radius: 10px;
  background: var(--surface-3); font-size: 17px;
}
.file-icon-lg { width: 64px; height: 64px; border-radius: 16px; background: var(--surface); box-shadow: var(--shadow); font-size: 28px; }
.ft-pdf { color: #dc2626; }
.ft-img { color: #059669; }
.ft-doc { color: #2563eb; }
.ft-xls { color: #15803d; }
.ft-ppt { color: #ea580c; }
.ft-other { color: var(--text-3); }
.file-info { display: flex; flex: 1; flex-direction: column; min-width: 0; }
.file-name { font-size: 13.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.file-size { font-size: 12px; color: var(--text-3); }
.file-actions { display: flex; flex-shrink: 0; gap: 2px; }

/* Chi tiết công việc */
.status-select { height: 36px; padding-right: 34px; border-radius: 10px; font-size: 13px; font-weight: 700; }
.status-select[data-status='Hoàn thành'] { background-color: var(--success-soft); border-color: transparent; color: var(--success); }
.status-select[data-status='Đang thực hiện'] { background-color: var(--primary-soft); border-color: transparent; color: var(--primary-text); }
.status-select[data-status='Quá hạn'] { background-color: var(--danger-soft); border-color: transparent; color: var(--danger); }

.detail-layout { flex: 1; min-height: 0; display: grid; grid-template-columns: 340px minmax(0, 1fr); }
.detail-info { display: flex; flex-direction: column; min-height: 0; border-right: 1px solid var(--border); }
.detail-scroll { flex: 1; min-height: 0; overflow-y: auto; display: flex; flex-direction: column; gap: 20px; padding: 22px; }
.detail-foot { flex-shrink: 0; padding: 14px 22px; border-top: 1px solid var(--border); }
.detail-title { font-size: 20px; font-weight: 800; line-height: 1.3; }
.detail-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 10px; margin-top: 10px; font-size: 13px; color: var(--text-2); }
.detail-meta b { color: var(--text); }
.pre { margin-top: 8px; white-space: pre-wrap; line-height: 1.6; color: var(--text-2); }
.people-card {
  display: flex; flex-direction: column; gap: 12px;
  padding: 14px;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface-2);
}
.person-line { display: flex; align-items: center; gap: 12px; }
.person-line small { display: block; font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--text-3); }
.person-line b { font-size: 14px; }
.mini-ico {
  display: grid; place-items: center; flex-shrink: 0;
  width: 32px; height: 32px; border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface); color: var(--primary); font-size: 13px;
}

.detail-preview { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--surface-2); }
.preview-head {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border); background: var(--surface);
  font-weight: 600; min-width: 0;
}
#preview-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.preview-stage {
  flex: 1; min-height: 0;
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.preview-stage img {
  max-width: 100%; max-height: 100%;
  object-fit: contain; border-radius: 12px;
  background: var(--surface); box-shadow: var(--shadow-lg);
}
.preview-stage iframe {
  width: 100%; height: 100%;
  border: 1px solid var(--border); border-radius: 12px; background: #fff;
}
#preview-empty { display: flex; justify-content: center; }
.preview-placeholder {
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  max-width: 360px; padding: 24px; text-align: center; color: var(--text-3);
}
.preview-title { font-weight: 700; color: var(--text); word-break: break-word; }
.preview-placeholder .btn { margin-top: 10px; }

/* Hồ sơ cán bộ */
.profile-banner {
  position: relative; flex-shrink: 0; height: 120px;
  background: linear-gradient(120deg, #1d4ed8 0%, #0ea5e9 60%, #22d3ee 100%);
}
.profile-body { padding: 0 24px 24px; }
.profile-grid { display: grid; grid-template-columns: 260px minmax(0, 1fr); gap: 28px; }
.profile-side { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; margin-top: -48px; }
.profile-name { margin-top: 12px; font-size: 20px; font-weight: 800; }
.profile-title { font-weight: 600; color: var(--primary-text); }
.profile-side .people-card { width: 100%; margin-top: 14px; }
.profile-main { min-width: 0; padding-top: 22px; }
.stack-list { display: flex; flex-direction: column; gap: 10px; margin-top: 10px; }
.stack-item {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 14px;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface);
}
.stack-main { display: flex; flex: 1; flex-direction: column; gap: 2px; min-width: 0; }
.stack-main b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13.5px; }
.stack-main small { font-size: 12px; color: var(--text-3); }
.date-badge {
  display: flex; flex-direction: column; flex-shrink: 0;
  width: 52px; padding: 6px 0;
  border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface); box-shadow: var(--shadow-sm);
  text-align: center;
}
.date-badge small { font-size: 10px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--text-3); }
.date-badge b { font-size: 18px; line-height: 1.1; }
.info-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; padding: 16px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface-2); }
.info-grid .full { grid-column: 1 / -1; }
.info-grid small { display: block; margin-bottom: 2px; font-size: 11.5px; font-weight: 700; color: var(--text-3); text-transform: uppercase; letter-spacing: .05em; }
.info-grid b { font-size: 14px; }
.modal-body .detail-title { margin-top: 12px; }

/* Xác nhận */
.confirm-body { display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 28px 24px 8px; text-align: center; }
.confirm-body .modal-title { justify-content: center; font-size: 18px; }
.confirm-body p { font-size: 14px; line-height: 1.6; color: var(--text-2); }
.confirm-icon {
  display: grid; place-items: center;
  width: 52px; height: 52px; margin-bottom: 4px;
  border-radius: 16px; background: var(--warning-soft); color: var(--warning); font-size: 20px;
}
.confirm-icon.is-danger { background: var(--danger-soft); color: var(--danger); }

/* Thông báo */
#toasts {
  position: fixed; right: 20px; bottom: 20px; z-index: 200;
  display: flex; flex-direction: column; gap: 10px;
  pointer-events: none;
}
.toast {
  display: flex; align-items: center; gap: 10px;
  min-width: 260px; max-width: 380px;
  padding: 12px 16px;
  border: 1px solid var(--border); border-radius: 12px;
  background: var(--surface); box-shadow: var(--shadow-lg);
  font-size: 13.5px; font-weight: 600;
  pointer-events: auto;
  animation: toastIn .3s cubic-bezier(.2, .8, .2, 1);
}
.toast i { font-size: 16px; }
.toast-success i { color: var(--success); }
.toast-error i { color: var(--danger); }
.toast-info i { color: var(--primary); }
.toast.is-leaving { opacity: 0; transform: translateY(8px); transition: opacity .3s, transform .3s; }
@keyframes toastIn { from { opacity: 0; transform: translateY(12px); } }

@media (max-width: 760px) {
  .form-grid, .info-grid { grid-template-columns: 1fr; }
  .check-list { grid-template-columns: 1fr; }
  .detail-layout { grid-template-columns: 1fr; grid-template-rows: auto minmax(300px, 1fr); }
  .detail-info { border-right: none; border-bottom: 1px solid var(--border); }
  .detail-scroll { max-height: 42dvh; }
  .profile-grid { grid-template-columns: 1fr; }
  .profile-side { align-items: center; text-align: center; }
  .profile-side .people-card { text-align: left; }
  .date-range .input { width: 132px; }
}
@media (max-width: 640px) {
  .modal { align-items: flex-end; padding: 0; }
  .modal-panel,
  .modal-panel.detail,
  .modal-panel.wide,
  .modal-panel.xwide { width: 100%; max-height: 92dvh; border-radius: 18px 18px 0 0; }
  .modal-panel.detail { height: 92dvh; }
  .modal-head, .modal-body, .modal-foot { padding-left: 16px; padding-right: 16px; }
  .modal-foot { flex-wrap: wrap; }
  .modal-foot .btn { flex: 1; }
  .modal-foot.split .btn { flex: 1; }
  #toasts { left: 16px; right: 16px; bottom: 16px; }
  .toast { min-width: 0; max-width: none; }
  .toolbar { padding: 12px; }
  .search { width: 100%; }
  .toolbar-group { width: 100%; }
  .toolbar-group .input, .toolbar-group select { flex: 1 1 140px; }
  .date-range { width: 100%; }
  .date-range .input { flex: 1; width: auto; }
}

/* ---------- Đơn thư, Phản ánh 1022, Giao việc BTV ---------- */
.src-badge {
  display: inline-flex; align-items: center; margin-left: 6px; padding: 2px 8px;
  border-radius: 999px; font-size: 11px; font-weight: 700; white-space: nowrap; vertical-align: middle;
}
.src-btv { background: rgb(124 58 237 / 0.14); color: #7c3aed; }
.src-don { background: rgb(8 145 178 / 0.14); color: #0e7490; }
.src-pa { background: rgb(234 88 12 / 0.14); color: #c2410c; }
.code {
  font-weight: 700; color: var(--primary-text);
  font-variant-numeric: tabular-nums; letter-spacing: 0.01em;
}
.stack-tags { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.report-cell { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; }
.link-btn {
  padding: 3px 6px; border: none; border-radius: 6px; background: none;
  color: var(--primary-text); font-size: 12.5px; font-weight: 700;
}
.link-btn:hover { background: var(--primary-soft); }
.clamp {
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden; max-width: 380px; white-space: normal;
}
.suggest {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px;
  margin-top: 8px; padding: 10px 12px;
  border-radius: 10px; background: var(--primary-soft); color: var(--primary-text); font-size: 13px;
}
.suggest .link-btn { margin-left: auto; }
.dupes {
  margin-top: 8px; padding: 10px 12px;
  border-radius: 10px; background: var(--warning-soft); color: var(--warning); font-size: 13px;
}
.dupes-title { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; font-weight: 700; }
.dupe-row {
  display: block; width: 100%; padding: 4px 0;
  border: none; background: none; text-align: left; color: inherit; font-size: 13px;
}
.dupe-row:hover b { text-decoration: underline; }
.detail-foot { display: flex; flex-wrap: wrap; gap: 10px; justify-content: space-between; }
.timeline-wrap { height: 100%; padding: 22px; overflow-y: auto; }
.timeline { list-style: none; margin: 14px 0 0; padding: 0 0 0 4px; }
.timeline li {
  position: relative; padding: 0 0 18px 22px;
  border-left: 2px solid var(--border); margin-left: 6px;
}
.timeline li:last-child { border-left-color: transparent; }
.timeline .tl-dot {
  position: absolute; left: -7px; top: 3px;
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--primary); box-shadow: 0 0 0 4px var(--surface-2);
}
.timeline b { display: block; font-size: 13.5px; font-weight: 600; }
.timeline small { font-size: 12px; color: var(--text-3); }
.stack-link {
  width: 100%; align-items: center; text-align: left; cursor: pointer;
  background: var(--surface); color: inherit; font: inherit;
}
.stack-link:hover { border-color: var(--primary); box-shadow: var(--shadow-sm); }
.chart-wrap.tall { height: 240px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
