/* ════════════════════════════════════════════════════════════════════════
   DVC Quảng Ngãi — styles.css
   Modern dashboard design với CSS variables, dark theme support.
   ════════════════════════════════════════════════════════════════════════ */

/* ── CSS Variables (light theme) ───────────────────────────────────── */
:root {
  --color-bg:           #f5f6fa;
  --color-bg-soft:      #eceef5;
  --color-surface:      #ffffff;
  --color-surface-2:    #f8fafc;
  --color-border:       #e2e8f0;
  --color-border-soft:  #f1f5f9;
  --color-text:         #0f172a;
  --color-text-muted:   #64748b;
  --color-text-faint:   #94a3b8;

  --color-primary:      #1a56db;
  --color-primary-soft: #eff6ff;
  --color-primary-dark: #1447b6;

  --color-accent:       #f59e0b;
  --color-accent-dark:  #d97706;
  --color-accent-soft:  #fffbeb;

  --color-success:      #16a34a;
  --color-success-soft: #dcfce7;
  --color-warning:      #d97706;
  --color-warning-soft: #fef3c7;
  --color-danger:       #dc2626;
  --color-danger-soft:  #fee2e2;
  --color-info:         #0284c7;
  --color-info-soft:    #e0f2fe;

  --shadow-sm:  0 1px 2px rgba(15,23,42,0.05);
  --shadow:     0 2px 8px rgba(15,23,42,0.06);
  --shadow-md:  0 4px 12px rgba(15,23,42,0.08);
  --shadow-lg:  0 12px 32px rgba(15,23,42,0.10);

  --radius-sm: 6px;
  --radius:    10px;
  --radius-lg: 14px;
  --radius-xl: 20px;

  --font-sans:  'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-mono:  'JetBrains Mono', 'Consolas', monospace;

  --sidebar-w:  300px;
  --stats-w:    320px;
  --topbar-h:   72px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --color-bg:           #0b1020;
    --color-bg-soft:      #0f172a;
    --color-surface:      #131a2c;
    --color-surface-2:    #1a2236;
    --color-border:       #25304a;
    --color-border-soft:  #1d2638;
    --color-text:         #e6ecf5;
    --color-text-muted:   #94a3b8;
    --color-text-faint:   #64748b;

    --color-primary:      #5b8def;
    --color-primary-soft: #18233f;
    --color-primary-dark: #3b6ddf;

    --color-accent:       #fbbf24;
    --color-accent-soft:  #2a2014;

    --shadow-sm:  0 1px 2px rgba(0,0,0,0.4);
    --shadow:     0 2px 8px rgba(0,0,0,0.4);
    --shadow-md:  0 4px 12px rgba(0,0,0,0.5);
    --shadow-lg:  0 12px 32px rgba(0,0,0,0.6);
  }
}

/* ── Reset ─────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; min-height: 100%; }
body {
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
  color: var(--color-text);
  background: var(--color-bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
button { font-family: inherit; }
a { color: var(--color-primary); text-decoration: none; }
a:hover { text-decoration: underline; }
ul { list-style: none; margin: 0; padding: 0; }
h1, h2, h3, h4 { margin: 0; }
.hidden { display: none !important; }
.mono { font-family: var(--font-mono); font-size: 0.85em; }

/* ── Topbar ────────────────────────────────────────────────────────── */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  background: linear-gradient(135deg, #0a1e52 0%, #1a56db 100%);
  color: #fff;
  box-shadow: var(--shadow-md);
}
.topbar-inner {
  height: var(--topbar-h);
  max-width: 1600px;
  margin: 0 auto;
  padding: 0 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}
.brand-logo {
  width: 32px;
  height: 32px;
  padding: 6px;
  background: rgba(255,255,255,0.15);
  border-radius: 8px;
  color: var(--color-accent);
}
.brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.1;
}
.brand-text strong {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.01em;
}
.brand-text span {
  font-size: 11px;
  color: rgba(255,255,255,0.7);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-top: 2px;
}
.topbar-stats {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.stat-pill {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 6px 14px;
  background: rgba(255,255,255,0.1);
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 10px;
  min-width: 70px;
}
.stat-num {
  font-size: 18px;
  font-weight: 700;
  color: var(--color-accent);
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.stat-lbl {
  font-size: 10px;
  color: rgba(255,255,255,0.7);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-top: 3px;
}

@media (max-width: 720px) {
  .topbar-stats { display: none; }
  .brand-text span { display: none; }
}

/* ── App shell ─────────────────────────────────────────────────────── */
.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr) var(--stats-w);
  gap: 16px;
  max-width: 1600px;
  margin: 0 auto;
  padding: 0 16px 24px;
  /* height: auto — expands to fit sidebar + stats content naturally.
     No min-height constraint so 7 sidebar sections + full stats panel
     are never clipped on standard viewport heights. */
}

@media (max-width: 900px) {
  .app-shell { grid-template-columns: 1fr; gap: 12px; }
  .sidebar, .stats-sidebar { position: static; overflow: hidden; }
}

/* ── Sidebar ───────────────────────────────────────────────────────── */
/* Sidebar fills its natural content height — no scroll on container.
   Each child section/ul manages its own scroll independently via
   overflow-y: auto (ward-list, sidebar-tree, scrollable-list, fav-list).
   position: static (not sticky) so all 7 sections are always visible. */
.sidebar {
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
  padding: 8px 0;
  overflow: hidden;           /* container never scrolls */
  position: static;           /* allow natural flow, all sections visible */
}

/* ── Section wrappers ────────────────────────────────────────────────
   The sidebar is rendered with two wrapper classes:
     .sidebar-section        → "Lĩnh vực", "Hệ thống DVC", "Thường dùng"
     .sidebar-tree-section   → "UBND xã phường", "Sở/Ban ngành", "ĐKĐĐ", "Ngành dọc"
   Compact mode: tighter padding, smaller headers. Lets the user see
   more section titles above the fold without sacrificing click targets
   (interactive items still keep min-height: 36–40px on desktop). */
.sidebar-section,
.sidebar-tree-section {
  padding: 8px 14px 10px;
  border-bottom: 1px solid var(--color-border-soft);
}
.sidebar-section:last-child,
.sidebar-tree-section:last-child { border-bottom: none; }
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 4px;
}
.section-header h3 {
  font-size: 10.5px;
  font-weight: 700;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.section-count {
  font-size: 10px;
  font-weight: 600;
  color: var(--color-text-faint);
  padding: 2px 6px;
  background: var(--color-bg-soft);
  border-radius: 999px;
}
.link-btn {
  background: none;
  border: none;
  font-size: 11px;
  color: var(--color-text-muted);
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 4px;
}
.link-btn:hover { color: var(--color-primary); background: var(--color-primary-soft); }

/* Ward list */
.ward-list { margin-top: 6px; overflow-y: auto; max-height: 260px; }
.ward-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 10px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 12.5px;
  transition: all 0.1s ease;
  border: 1px solid transparent;
}
.ward-item:hover {
  background: var(--color-bg-soft);
  border-color: var(--color-border-soft);
}
.ward-item.active {
  background: var(--color-primary-soft);
  color: var(--color-primary);
  font-weight: 600;
  border-color: var(--color-primary);
}
.ward-name {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-right: 8px;
}
.ward-count {
  font-size: 10px;
  color: var(--color-text-faint);
  background: var(--color-bg-soft);
  padding: 1px 6px;
  border-radius: 999px;
  font-variant-numeric: tabular-nums;
  flex-shrink: 0;
}
.ward-item.active .ward-count {
  background: var(--color-primary);
  color: #fff;
}

/* Scrollable lists (fields, systems) — keep inner cap so the section
   title stays visible when scrolled. Above-the-fold visible space is
   increased by tighter section padding rather than by removing the cap. */
.scrollable-list {
  overflow-y: auto;
  max-height: 240px;
  margin-top: 4px;
}
.list-placeholder {
  font-size: 12px;
  color: var(--color-text-faint);
  padding: 10px 10px;
  font-style: italic;
  text-align: center;
}
.list-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 5px 10px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 12.5px;
  transition: all 0.1s ease;
  border: 1px solid transparent;
}
.list-item:hover {
  background: var(--color-bg-soft);
  border-color: var(--color-border-soft);
}
.list-item.active {
  background: var(--color-accent-soft);
  color: var(--color-accent-dark);
  font-weight: 600;
  border-color: var(--color-accent);
}
.list-item .item-name {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-right: 8px;
}
.list-item .item-count {
  font-size: 10px;
  color: var(--color-text-faint);
  background: var(--color-bg-soft);
  padding: 1px 6px;
  border-radius: 999px;
  font-variant-numeric: tabular-nums;
  flex-shrink: 0;
}
.list-item.active .item-count {
  background: var(--color-accent);
  color: #fff;
}

/* Favorites — small fixed cap, scroll inside as items grow. */
.fav-list {
  margin-top: 4px;
  overflow-y: auto;
  max-height: 200px;
}

/* Sidebar's own scrollbar is the only one user needs. Keep thin visible
   thumb on all inner lists too in case any third-party or render path
   re-introduces overflow-y on a particular section in the future. */
.sidebar .ward-list,
.sidebar .scrollable-list,
.sidebar .fav-list,
.sidebar .sidebar-tree {
  scrollbar-gutter: stable;
  scrollbar-width: thin;
  scrollbar-color: var(--color-border) transparent;
}
.sidebar .ward-list::-webkit-scrollbar,
.sidebar .scrollable-list::-webkit-scrollbar,
.sidebar .fav-list::-webkit-scrollbar,
.sidebar .sidebar-tree::-webkit-scrollbar { width: 8px; }
.sidebar .ward-list::-webkit-scrollbar-track,
.sidebar .scrollable-list::-webkit-scrollbar-track,
.sidebar .fav-list::-webkit-scrollbar-track,
.sidebar .sidebar-tree::-webkit-scrollbar-track {
  background: var(--color-bg-soft);
  border-radius: 4px;
}
.sidebar .ward-list::-webkit-scrollbar-thumb,
.sidebar .scrollable-list::-webkit-scrollbar-thumb,
.sidebar .fav-list::-webkit-scrollbar-thumb,
.sidebar .sidebar-tree::-webkit-scrollbar-thumb {
  background: var(--color-border);
  border-radius: 4px;
  border: 1px solid var(--color-bg-soft);
}
.sidebar .ward-list::-webkit-scrollbar-thumb:hover,
.sidebar .scrollable-list::-webkit-scrollbar-thumb:hover,
.sidebar .fav-list::-webkit-scrollbar-thumb:hover,
.sidebar .sidebar-tree::-webkit-scrollbar-thumb:hover {
  background: var(--color-text-muted);
}
.fav-item {
  padding: 7px 10px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 12.5px;
  border: 1px solid var(--color-border-soft);
  background: var(--color-surface-2);
  margin-bottom: 5px;
  position: relative;
  transition: all 0.1s ease;
}
.fav-item:hover {
  background: var(--color-primary-soft);
  border-color: var(--color-primary);
}
.fav-item.loading {
  opacity: 0.65;
  pointer-events: none;
}
.fav-item-name {
  font-weight: 500;
  margin-bottom: 2px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.fav-item-meta {
  font-size: 10px;
  color: var(--color-text-faint);
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.fav-item-remove {
  position: absolute;
  top: 4px;
  right: 4px;
  background: none;
  border: none;
  color: var(--color-text-faint);
  cursor: pointer;
  font-size: 14px;
  padding: 2px 6px;
  border-radius: 4px;
  line-height: 1;
}
.fav-item-remove:hover {
  color: var(--color-danger);
  background: var(--color-danger-soft);
}

/* ── "Thủ tục thường dùng" (quick-access) ─────────────────────────
   Section ngay dưới search bar. CSS cũ thiếu hoàn toàn → chips hiển thị
   với default <button> style (border đen 2px, padding 1px 6px, không wrap).
   Khối này style khớp với .chip pattern + warning-soft palette để phân biệt
   với filter chips (primary).
   ──────────────────────────────────────────────────────────────────── */
.frequent-section {
  margin: 12px 24px 4px;
  padding: 12px 14px 14px;
  background: linear-gradient(135deg, var(--color-warning-soft) 0%, #fffbeb 100%);
  border: 1px solid #fcd34d;
  border-radius: 10px;
}
.frequent-section__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}
.frequent-section__title {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--color-warning);
  letter-spacing: 0.01em;
}
.frequent-section__title strong {
  color: var(--color-text);
  font-weight: 600;
}
.frequent-section__icon {
  font-size: 14px;
  line-height: 1;
}
.frequent-section__hint {
  font-size: 11.5px;
  font-weight: 500;
  color: #92400e;
  background: rgba(255, 255, 255, 0.7);
  border: 1px dashed #fcd34d;
  border-radius: 999px;
  padding: 3px 9px;
  white-space: nowrap;
  cursor: default;
}
.frequent-section__source {
  font-size: 10.5px;
  font-weight: 500;
  color: var(--color-text-faint);
  margin-left: 6px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.frequent-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}
.frequent-chips__loading,
.frequent-chips__error {
  font-size: 12px;
  color: var(--color-text-faint);
  font-style: italic;
  padding: 2px 0;
}
.frequent-chips__error { color: var(--color-danger); }

/* ─── Recently updated TTHC section ─────────────────────────────────── */
.recent-updated-section {
  margin: 8px 0 4px;
  padding: 10px 12px 12px;
  background: linear-gradient(135deg, #eff6ff 0%, #f0f9ff 100%);
  border: 1px solid #93c5fd;
  border-radius: 10px;
}
.recent-updated-section__header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}
.recent-updated-section__title {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 600;
  color: #1e40af;
}
.recent-icon {
  width: 15px;
  height: 15px;
  flex-shrink: 0;
}
.recent-updated-section__badge {
  font-size: 11px;
  font-weight: 500;
  color: #1d4ed8;
  background: rgba(255,255,255,0.7);
  border: 1px dashed #93c5fd;
  border-radius: 999px;
  padding: 2px 8px;
  white-space: nowrap;
}
.recent-updated-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.recent-item {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 8px 10px;
  background: #fff;
  border: 1px solid #dbeafe;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s;
}
.recent-item:hover { background: #eff6ff; }
.recent-item__status {
  flex-shrink: 0;
  margin-top: 2px;
  font-size: 16px;
  line-height: 1;
}
.recent-item__body { flex: 1; min-width: 0; }
.recent-item__name {
  font-size: 13px;
  font-weight: 500;
  color: var(--color-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.recent-item__meta {
  font-size: 11.5px;
  color: #64748b;
  margin-top: 2px;
}
.recent-item__time {
  flex-shrink: 0;
  font-size: 11px;
  color: #94a3b8;
  white-space: nowrap;
  margin-top: 2px;
}

.frequent-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 11px 6px 8px;
  border-radius: 999px;
  font-size: 12.5px;
  font-weight: 500;
  font-family: var(--font-sans);
  line-height: 1.3;
  background: var(--color-surface);
  color: var(--color-text);
  border: 1px solid var(--color-border);
  cursor: pointer;
  transition: all 0.12s ease;
  text-align: left;
  max-width: 100%;
}
.frequent-chip:hover {
  border-color: var(--color-warning);
  background: #fffbeb;
  color: var(--color-text);
  transform: translateY(-1px);
  box-shadow: 0 2px 4px rgba(245, 158, 11, 0.12);
}
.frequent-chip:active { transform: translateY(0); }
.frequent-chip:focus-visible {
  outline: 2px solid var(--color-warning);
  outline-offset: 2px;
}
.frequent-chip__badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 22px;
  height: 18px;
  padding: 0 5px;
  border-radius: 6px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.02em;
  background: var(--color-bg-soft);
  color: var(--color-text-muted);
  flex-shrink: 0;
}
.frequent-chip__badge--full {
  background: var(--color-success-soft);
  color: #166534;
}
.frequent-chip__badge--partial {
  background: var(--color-warning-soft);
  color: var(--color-warning);
}
.frequent-chip__name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 260px;
}
.frequent-chip__count {
  font-size: 10.5px;
  font-weight: 600;
  color: var(--color-warning, #f59e0b);
  background: var(--color-warning-soft, #fef3c7);
  padding: 1px 7px;
  border-radius: 999px;
  margin-left: 4px;
  flex-shrink: 0;
  line-height: 1.4;
  letter-spacing: 0.01em;
}
.frequent-empty {
  width: 100%;
  padding: 14px 14px;
  font-size: 12.5px;
  line-height: 1.5;
  color: var(--color-text-faint);
  text-align: center;
  background: var(--color-bg-soft);
  border: 1px dashed var(--color-border);
  border-radius: 10px;
  margin: 4px 0 2px;
}

/* ── Search bar ────────────────────────────────────────────────────── */
.searchbar {
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  padding: 16px 24px;
}
.search-wrap {
  position: relative;
}
.search-wrap .search-icon {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  width: 18px;
  height: 18px;
  color: var(--color-text-faint);
  pointer-events: none;
}
.input {
  width: 100%;
  padding: 11px 14px 11px 42px;
  border: 1.5px solid var(--color-border);
  border-radius: 10px;
  font-size: 14px;
  font-family: var(--font-sans);
  background: var(--color-surface-2);
  color: var(--color-text);
  outline: none;
  transition: all 0.15s;
}
.input:focus {
  border-color: var(--color-primary);
  background: var(--color-surface);
  box-shadow: 0 0 0 3px var(--color-primary-soft);
}
.input::placeholder { color: var(--color-text-faint); }
.input--sm { padding: 7px 10px 7px 30px; font-size: 12.5px; }
.search-wrap--sm .search-icon { left: 9px; width: 14px; height: 14px; }
.search-wrap--lg .input {
  padding: 14px 50px 14px 46px;
  font-size: 15px;
  border: 2px solid var(--color-primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}
.search-wrap--lg .input:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.2);
  outline: none;
}
.clear-btn {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: var(--color-text-faint);
  cursor: pointer;
  font-size: 14px;
  padding: 4px 8px;
  border-radius: 4px;
  line-height: 1;
}
.clear-btn:hover { color: var(--color-danger); background: var(--color-danger-soft); }
.clear-btn.hidden { display: none; }

/* ── Search autocomplete dropdown ─────────────────────────────────── */
.search-wrap--search { position: relative; }
.ac-dropdown {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  background: var(--color-surface, #fff);
  border: 1px solid var(--color-border, #e5e7eb);
  border-radius: 10px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.08), 0 2px 8px rgba(0, 0, 0, 0.04);
  max-height: 360px;
  overflow-y: auto;
  z-index: 50;
  padding: 4px;
}
.ac-dropdown.hidden { display: none; }
.ac-item {
  display: block;
  width: 100%;
  padding: 10px 14px;
  text-align: left;
  background: none;
  border: none;
  cursor: pointer;
  font-size: 13.5px;
  font-family: var(--font-sans);
  color: var(--color-text);
  border-radius: 6px;
  line-height: 1.4;
  transition: background 0.1s;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ac-item:hover,
.ac-item:focus-visible {
  background: var(--color-primary-soft, rgba(59, 130, 246, 0.08));
  outline: none;
}

/* ── Extension status badge (inside topbar) ─────────────────────────────── */
.ext-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
  background: var(--color-bg-soft);
  border: 1px solid var(--color-border);
  white-space: nowrap;
}
.ext-badge__dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
}
.ext-badge__dot--ok {
  background: var(--color-success);
  box-shadow: 0 0 0 2px rgba(34, 197, 94, 0.25);
}
.ext-badge__dot--warn {
  background: #f59e0b;
  box-shadow: 0 0 0 2px rgba(245, 158, 11, 0.2);
  animation: ext-badge-pulse 2s ease-in-out infinite;
}
.ext-badge__dot--outdated {
  background: var(--color-danger);
  box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.2);
  animation: ext-badge-pulse-outdated 1.4s ease-in-out infinite;
}
@keyframes ext-badge-pulse-outdated {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%       { opacity: 0.65; transform: scale(0.88); }
}
@keyframes ext-badge-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}
.ext-badge__label { color: var(--color-text-muted); }
.ext-badge__dot--ok  ~ .ext-badge__label { color: var(--color-success); }
.ext-badge__dot--warn ~ .ext-badge__label { color: #d97706; }
.ext-badge__dot--outdated ~ .ext-badge__label { color: var(--color-danger); }

.ext-badge--outdated {
  background: var(--color-danger-soft, #fee2e2);
  border-color: rgba(220, 38, 38, 0.35);
}

/* ── Extension install notice (inside search wrap) ─────────────────────── */
.ext-notice {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 12px 9px 10px;
  background: var(--color-danger-soft, #fee2e2);
  border: 1.5px solid var(--color-danger, #dc2626);
  border-radius: 10px;
  box-shadow: 0 4px 16px rgba(220, 38, 38, 0.10), 0 1px 4px rgba(15, 23, 42, 0.05);
  font-size: 13px;
  color: var(--color-text, #0f172a);
  z-index: 50;
  animation: extNoticeSlide 0.2s ease-out;
}
@keyframes extNoticeSlide {
  from { opacity: 0; transform: translateY(-6px); }
  to   { opacity: 1; transform: translateY(0); }
}
.ext-notice__icon {
  flex: 0 0 auto;
  width: 16px;
  height: 16px;
  color: var(--color-danger, #dc2626);
  margin-right: 2px;
}
.ext-notice__text {
  flex: 1 1 auto;
  line-height: 1.4;
  color: var(--color-text, #0f172a);
}
.ext-notice__text strong {
  color: var(--color-danger, #dc2626);
  font-weight: 600;
}
.ext-notice__link {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  background: var(--color-danger, #dc2626);
  color: #fff;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
  transition: background 0.12s ease, transform 0.1s ease;
}
.ext-notice__link:hover {
  background: #b91c1c;
  transform: translateY(-1px);
  text-decoration: none;
}
.ext-notice__link--ghost {
  background: transparent;
  color: var(--color-danger, #dc2626);
  border: 1px solid var(--color-danger, #dc2626);
}
.ext-notice__link--ghost:hover {
  background: var(--color-danger, #dc2626);
  color: #fff;
}
.ext-notice__close {
  flex: 0 0 auto;
  background: none;
  border: none;
  color: var(--color-text-muted, #64748b);
  cursor: pointer;
  font-size: 13px;
  padding: 3px 5px;
  border-radius: 4px;
  line-height: 1;
  transition: background 0.1s, color 0.1s;
}
.ext-notice__close:hover {
  background: rgba(220, 38, 38, 0.12);
  color: var(--color-danger, #dc2626);
}
@media (max-width: 480px) {
  .ext-notice {
    flex-wrap: wrap;
    gap: 6px;
    padding: 10px 12px;
  }
  .ext-notice__text { flex: 1 1 100%; font-size: 12.5px; }
}

/* ── Search results: summary header + back button + empty state ──── */
.search-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 18px;
  background: linear-gradient(135deg,
    var(--color-primary-soft, rgba(59, 130, 246, 0.06)) 0%,
    var(--color-surface, #fff) 100%);
  border: 1px solid var(--color-border, #e5e7eb);
  border-radius: 10px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.search-summary-text {
  display: flex;
  align-items: baseline;
  gap: 8px;
  flex-wrap: wrap;
}
.search-count { font-size: 15px; color: var(--color-text); }
.search-count strong { color: var(--color-primary); font-size: 17px; }
.search-query {
  font-size: 13.5px;
  color: var(--color-text-faint, #6b7280);
}
.btn-clear-search {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  font-size: 13px;
}
.btn-clear-search .icon { width: 14px; height: 14px; }

.results-grid-inner {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(360px, 1fr));
  gap: 14px;
}

.search-empty {
  text-align: center;
  padding: 64px 24px;
}
.search-empty .search-empty-hint {
  font-size: 13px;
  color: var(--color-text-faint, #9ca3af);
  margin-top: 8px;
}

/* ── Highlight tokens in search results ──────────────────────────── */
.tthc-card--search .tthc-title mark,
.tthc-card--search .meta-dept-name mark {
  background: linear-gradient(transparent 55%, var(--color-warning-soft, #fef3c7) 55%);
  color: inherit;
  font-weight: 600;
  padding: 0 2px;
  border-radius: 2px;
}

.filter-chips {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin-top: 10px;
}
.filter-label {
  font-size: 11px;
  color: var(--color-text-muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-right: 4px;
}
.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 11px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
  border: 1.5px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-text-muted);
  cursor: pointer;
  transition: all 0.12s ease;
  white-space: nowrap;
  user-select: none;
}
.chip:hover {
  border-color: var(--color-primary);
  color: var(--color-primary);
  background: var(--color-primary-soft);
}
.chip.active {
  background: var(--color-primary);
  color: #fff;
  border-color: var(--color-primary);
}
.dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
}
.dot--green { background: var(--color-success); }
.dot--amber { background: var(--color-warning); }

/* Active filter chips (shows what filters are applied) */
.chip-dismissible {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px 4px 11px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
  background: var(--color-accent-soft);
  color: var(--color-accent-dark);
  border: 1px solid var(--color-accent);
}
.chip-dismissible button {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--color-accent-dark);
  font-size: 14px;
  padding: 0 4px;
  line-height: 1;
}

/* ── Result bar ────────────────────────────────────────────────────── */
.result-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  background: var(--color-bg-soft);
  border-bottom: 1px solid var(--color-border-soft);
}
.result-count {
  font-size: 13px;
  color: var(--color-text-muted);
  font-variant-numeric: tabular-nums;
}
.result-actions { display: flex; gap: 8px; }
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border: 1.5px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-text);
  font-size: 12.5px;
  font-weight: 500;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.12s ease;
  font-family: var(--font-sans);
}
.btn:hover {
  border-color: var(--color-primary);
  background: var(--color-primary-soft);
  color: var(--color-primary);
}
.btn--primary {
  background: var(--color-primary);
  color: #fff;
  border-color: var(--color-primary);
}
.btn--primary:hover {
  background: var(--color-primary-dark);
  color: #fff;
  border-color: var(--color-primary-dark);
}
.btn--danger {
  background: var(--color-danger-soft);
  color: var(--color-danger);
  border-color: var(--color-danger-soft);
}
.btn--danger:hover {
  background: var(--color-danger);
  color: #fff;
  border-color: var(--color-danger);
}
.btn--ghost {
  background: transparent;
  border-color: var(--color-border);
}
.btn .icon { width: 14px; height: 14px; }

/* ── Results grid ──────────────────────────────────────────────────── */
.main-content {
  min-width: 0;
  display: flex;
  flex-direction: column;
}
.results-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  padding: 16px 24px;
}
@media (min-width: 1100px) {
  .results-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (min-width: 1500px) {
  .results-grid { grid-template-columns: repeat(2, 1fr); }
}

.tthc-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 16px 18px;
  transition: all 0.15s ease;
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 8px;
  border-left: 3px solid var(--color-primary);
}
.tthc-card:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
  border-color: var(--color-primary);
}
.tthc-card:hover { border-left-color: var(--color-accent); }

.tthc-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
}
.tthc-title {
  font-size: 14.5px;
  font-weight: 600;
  color: var(--color-text);
  line-height: 1.35;
  flex: 1;
  margin: 0;
}
.tthc-code {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--color-text-faint);
  background: var(--color-bg-soft);
  padding: 2px 6px;
  border-radius: 4px;
  flex-shrink: 0;
  font-weight: 500;
}
.tthc-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  font-size: 11.5px;
  color: var(--color-text-muted);
}
.tthc-meta-item {
  display: inline-flex;
  align-items: center;
  gap: 3px;
}
.tthc-meta-item .meta-icon {
  width: 11px;
  height: 11px;
  opacity: 0.6;
}
.tthc-meta strong {
  color: var(--color-text);
  font-weight: 600;
}
.tthc-meta-item--dept {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.meta-dept-name {
  font-weight: 500;
  color: var(--color-text);
}
.meta-dept-code {
  font-size: 10.5px;
  color: var(--color-text-muted);
  padding: 1px 5px;
  border: 1px solid var(--color-border-soft);
  border-radius: 3px;
  background: var(--color-bg-soft);
}
.meta-dept-fallback {
  color: var(--color-text-muted);
  font-style: italic;
}
.tthc-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}
.tag {
  font-size: 10.5px;
  font-weight: 500;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--color-bg-soft);
  color: var(--color-text-muted);
  border: 1px solid var(--color-border-soft);
}
.tag--field { background: var(--color-info-soft); color: var(--color-info); border-color: var(--color-info-soft); }
.tag--system {
  background: var(--color-primary-soft);
  color: var(--color-primary);
  border-color: var(--color-primary-soft);
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-weight: 600;
  padding: 2px 8px 2px 8px;
}
.tag--system .tag--system-name { color: var(--color-primary); }
.tag--system .tag--system-domain { color: var(--color-text-muted); font-weight: 400; font-size: 9.5px; opacity: 0.85; }
.tag--level-full { background: var(--color-success-soft); color: var(--color-success); border-color: var(--color-success-soft); }
.tag--level-partial { background: var(--color-warning-soft); color: var(--color-warning); border-color: var(--color-warning-soft); }
.tag--occurrences {
  background: var(--color-accent-soft, #f3e8ff);
  color: var(--color-accent, #7c3aed);
  border-color: var(--color-accent-soft, #f3e8ff);
  font-weight: 600;
}

/* Sidebar system item enhancements */
.list-item.system-item { padding: 8px 12px; }
.badge--type { margin-left: 4px; font-size: 12px; }

/* System-type badge in sidebar (icon-only) */
.badge--type {
  font-size: 12px;
  line-height: 1;
  padding: 0 2px;
  margin-right: 2px;
  opacity: 0.75;
}

.tthc-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 4px;
  padding-top: 8px;
  border-top: 1px solid var(--color-border-soft);
}
.tthc-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}
.tthc-pin {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 18px;
  color: var(--color-text-faint);
  padding: 4px 6px;
  border-radius: 4px;
  transition: all 0.1s;
  line-height: 1;
}
.tthc-pin:hover { color: var(--color-accent); background: var(--color-accent-soft); }
.tthc-pin.pinned { color: var(--color-accent); }

.btn-submit {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 6px 12px;
  background: linear-gradient(135deg, var(--color-accent) 0%, var(--color-accent-dark) 100%);
  color: #fff;
  border: none;
  border-radius: 6px;
  font-size: 11.5px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  text-decoration: none;
  font-family: var(--font-sans);
  white-space: nowrap;
  box-shadow: 0 1px 3px rgba(245,158,11,0.3);
}
.btn-submit:hover {
  transform: translateY(-1px);
  box-shadow: 0 3px 8px rgba(245,158,11,0.4);
}
.btn-submit:active { transform: translateY(0); }
.btn-submit[disabled] {
  opacity: 0.5;
  cursor: not-allowed;
  background: var(--color-text-faint);
  box-shadow: none;
}
.btn-submit .icon { width: 12px; height: 12px; }

.btn-detail {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 6px 12px;
  background: linear-gradient(135deg, var(--color-primary) 0%, var(--color-primary-dark) 100%);
  color: #fff;
  border: none;
  border-radius: 6px;
  font-size: 11.5px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  font-family: var(--font-sans);
  white-space: nowrap;
  box-shadow: 0 1px 3px rgba(26,86,219,0.3);
}
.btn-detail:hover {
  transform: translateY(-1px);
  box-shadow: 0 3px 8px rgba(26,86,219,0.4);
}
.btn-detail:active { transform: translateY(0); }
.btn-detail .icon { width: 12px; height: 12px; }

.loading-spinner {
  text-align: center;
  padding: 40px 20px;
  color: var(--color-text-secondary);
  font-size: 14px;
}

.detail-section {
  margin-bottom: 24px;
}
.detail-section:last-child { margin-bottom: 0; }
.detail-section h3 {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 12px;
  color: var(--color-text);
  border-bottom: 2px solid var(--color-accent);
  padding-bottom: 6px;
}
.detail-info-grid {
  display: grid;
  grid-template-columns: 140px 1fr;
  gap: 12px 16px;
  font-size: 13px;
}
.detail-info-grid dt {
  font-weight: 600;
  color: var(--color-text-secondary);
}
.detail-info-grid dd {
  color: var(--color-text);
  margin: 0;
}
.detail-list {
  list-style: none;
  padding: 0;
  margin: 0;
}
.detail-list li {
  padding: 10px 12px;
  margin-bottom: 8px;
  background: var(--color-surface-elevated);
  border-radius: 6px;
  border-left: 3px solid var(--color-accent);
  font-size: 13px;
}
.detail-list li:last-child { margin-bottom: 0; }
.detail-step-title {
  font-weight: 600;
  color: var(--color-text);
  margin-bottom: 4px;
}
.detail-step-desc {
  color: var(--color-text-secondary);
  line-height: 1.5;
}

/* ── Skeleton loading ──────────────────────────────────────────────── */
.loading-state { padding: 16px 24px; }
.skeleton-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}
@media (min-width: 1100px) {
  .skeleton-grid { grid-template-columns: repeat(2, 1fr); }
}
.skeleton-card {
  height: 130px;
  border-radius: var(--radius-lg);
  background: linear-gradient(90deg, var(--color-border-soft) 0%, var(--color-surface-2) 50%, var(--color-border-soft) 100%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
}
@keyframes shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ── Empty state ───────────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 60px 24px;
  color: var(--color-text-muted);
}
.empty-icon {
  width: 60px;
  height: 60px;
  margin: 0 auto 16px;
  color: var(--color-text-faint);
  opacity: 0.5;
}
.empty-state h3 {
  font-size: 18px;
  font-weight: 600;
  color: var(--color-text);
  margin-bottom: 8px;
}
.empty-state p { margin: 0 0 16px; }

/* ── Grouped sections (khi chọn 1 ward cụ thể) ──────────────────────── */
/*.results-grid khi grouped → render dạng block cards thay vì grid 2-column.*/
.results-section {
  margin-bottom: 16px;
  border: 1px solid var(--color-border, #e5e7eb);
  border-radius: 10px;
  background: var(--color-surface, #fff);
  overflow: hidden;
}
.results-section.is-empty { opacity: 0.65; }

.results-section__header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 18px;
  background: var(--color-surface-2, #f4f6f9);
  cursor: pointer;
  user-select: none;
  transition: background 0.15s ease;
}
.results-section__header:hover { background: var(--color-surface-3, #e9eef5); }
.results-section__header:focus-visible {
  outline: 2px solid var(--color-accent, #3b82f6);
  outline-offset: -2px;
}

.results-section__chevron {
  display: inline-flex;
  align-items: center;
  color: var(--color-text-muted, #6b7280);
  transition: transform 0.18s ease;
  flex: 0 0 auto;
}
.results-section.collapsed .results-section__chevron { transform: rotate(-90deg); }

.results-section__title {
  flex: 1;
  font-size: 15px;
  font-weight: 600;
  margin: 0;
  color: var(--color-text, #111827);
}

.results-section__count {
  font-size: 13px;
  color: var(--color-text-muted, #6b7280);
  background: var(--color-surface, #fff);
  padding: 3px 10px;
  border-radius: 999px;
  border: 1px solid var(--color-border, #e5e7eb);
  white-space: nowrap;
}

.results-section__items {
  padding: 14px 18px;
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}
@media (min-width: 1100px) {
  .results-section__items { grid-template-columns: repeat(2, 1fr); }
}
.results-section.collapsed .results-section__items { display: none; }

.results-section__empty {
  color: var(--color-text-muted, #6b7280);
  font-size: 13px;
  font-style: italic;
  margin: 0;
  padding: 8px 0;
}

/* Khi grouped, .results-grid thành block (không phải grid 2-col).*/
.results-grid:has(.results-section) {
  display: block;
  padding: 16px 24px;
}

/* ── Pagination ────────────────────────────────────────────────────── */
.pagination {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 8px;
  padding: 20px 24px;
  border-top: 1px solid var(--color-border-soft);
}
.page-info {
  font-size: 13px;
  color: var(--color-text-muted);
  font-variant-numeric: tabular-nums;
  margin: 0 6px;
}
.pager-numbers {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  align-items: center;
}
.pager-btn {
  min-width: 36px;
  height: 36px;
  padding: 0 10px;
  border: 1px solid var(--color-border-soft, #e5e7eb);
  background: var(--color-surface, #fff);
  color: var(--color-text, #1f2937);
  cursor: pointer;
  border-radius: 6px;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  transition: background 0.12s ease, border-color 0.12s ease, color 0.12s ease;
}
.pager-btn:hover:not(:disabled):not(.is-active) {
  background: var(--color-surface-hover, #f3f4f6);
  border-color: var(--color-border, #d1d5db);
}
.pager-btn.is-active {
  background: var(--color-primary, #2563eb);
  color: #fff;
  border-color: var(--color-primary, #2563eb);
  font-weight: 600;
}
.pager-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}
.pager-ellipsis {
  padding: 0 4px;
  color: var(--color-text-muted, #6b7280);
  font-size: 13px;
  user-select: none;
}
.page-size-selector {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--color-text-muted, #6b7280);
  margin-left: auto;
}
.page-size-selector select {
  height: 32px;
  padding: 0 8px;
  border: 1px solid var(--color-border-soft, #e5e7eb);
  border-radius: 6px;
  background: var(--color-surface, #fff);
  color: var(--color-text, #1f2937);
  font-size: 13px;
  cursor: pointer;
}
.page-size-selector select:hover {
  border-color: var(--color-border, #d1d5db);
}
/* Mobile: stack page-size selector lên đầu dòng mới */
@media (max-width: 640px) {
  .pagination {
    gap: 6px;
    padding: 16px 12px;
  }
  .pager-btn {
    min-width: 32px;
    height: 32px;
    padding: 0 8px;
    font-size: 12px;
  }
  .page-info {
    font-size: 12px;
    margin: 0 4px;
  }
  .page-size-selector {
    width: 100%;
    justify-content: flex-end;
    margin-left: 0;
    margin-top: 4px;
  }
}
.btn[disabled] {
  opacity: 0.4;
  cursor: not-allowed;
}

/* ── Modal ─────────────────────────────────────────────────────────── */
.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15,23,42,0.55);
  backdrop-filter: blur(2px);
}
.modal-content {
  position: relative;
  background: var(--color-surface);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
}
.modal-content--lg { max-width: 640px; }
.modal-content--xl { max-width: 900px; width: 90vw; }
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--color-border);
}
.modal-header h2 { font-size: 16px; font-weight: 600; }
.icon-btn {
  background: none;
  border: none;
  font-size: 18px;
  color: var(--color-text-muted);
  cursor: pointer;
  padding: 4px 10px;
  border-radius: 6px;
}
.icon-btn:hover { background: var(--color-bg-soft); }
.modal-body { padding: 20px; overflow-y: auto; }
.modal-desc {
  font-size: 13px;
  color: var(--color-text-muted);
  margin: 0 0 16px;
}
.crawl-status-card {
  background: var(--color-surface-2);
  border: 1px solid var(--color-border-soft);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 16px;
}
.status-row {
  display: flex;
  justify-content: space-between;
  padding: 4px 0;
  font-size: 13px;
  border-bottom: 1px solid var(--color-border-soft);
}
.status-row:last-child { border-bottom: none; }
.status-label { color: var(--color-text-muted); font-weight: 500; }
.status-value { color: var(--color-text); font-weight: 600; }
.modal-actions {
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
}
.log-details summary {
  cursor: pointer;
  font-size: 12px;
  color: var(--color-text-muted);
  font-weight: 500;
  margin-bottom: 8px;
}
.log-box {
  background: #0f172a;
  color: #cbd5e1;
  font-family: var(--font-mono);
  font-size: 11.5px;
  padding: 12px;
  border-radius: var(--radius);
  max-height: 240px;
  overflow-y: auto;
  margin: 0;
  white-space: pre-wrap;
  word-break: break-all;
}

/* ── TTHC detail modal ─────────────────────────────────────────────── */
body.modal-open { overflow: hidden; }
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(15, 23, 42, 0.62);
  backdrop-filter: blur(3px);
  animation: detailFadeIn 0.15s ease-out;
}
.tthc-detail {
  width: min(680px, 100%);
  max-height: min(86vh, 760px);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-xl);
  box-shadow: 0 24px 70px rgba(15, 23, 42, 0.28);
  animation: detailSlideUp 0.2s ease-out;
}
.detail-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  padding: 20px 22px 18px;
  border-bottom: 1px solid var(--color-border);
  background: linear-gradient(135deg, var(--color-primary-soft), var(--color-surface) 70%);
}
.detail-header h2 {
  margin: 3px 0 0;
  font-size: 18px;
  line-height: 1.4;
  color: var(--color-text);
}
.detail-eyebrow {
  display: block;
  color: var(--color-primary);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}
.detail-close {
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  border: 1px solid transparent;
  border-radius: 9px;
  background: transparent;
  color: var(--color-text-muted);
  font-size: 18px;
  cursor: pointer;
  transition: all 0.12s ease;
}
.detail-close:hover,
.detail-close:focus-visible {
  color: var(--color-danger);
  background: var(--color-danger-soft);
  border-color: var(--color-danger-soft);
  outline: none;
}
.detail-body {
  padding: 22px;
  overflow-y: auto;
}
.detail-body dl {
  display: grid;
  grid-template-columns: minmax(130px, 160px) minmax(0, 1fr);
  gap: 0;
  margin: 0;
  border: 1px solid var(--color-border-soft);
  border-radius: var(--radius);
  overflow: hidden;
}
.detail-body dt,
.detail-body dd {
  min-width: 0;
  margin: 0;
  padding: 10px 13px;
  border-bottom: 1px solid var(--color-border-soft);
}
.detail-body dt {
  color: var(--color-text-muted);
  background: var(--color-surface-2);
  font-size: 12px;
  font-weight: 600;
}
.detail-body dd {
  color: var(--color-text);
  font-size: 13.5px;
  overflow-wrap: anywhere;
}
.detail-body dt:last-of-type,
.detail-body dd:last-of-type { border-bottom: none; }
.detail-body code {
  padding: 3px 7px;
  border-radius: 5px;
  background: var(--color-bg-soft);
  color: var(--color-text);
  font-family: var(--font-mono);
  font-size: 12px;
}
.detail-body a {
  color: var(--color-primary);
  font-weight: 600;
}
.detail-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 16px 22px;
  border-top: 1px solid var(--color-border);
  background: var(--color-surface-2);
}
@keyframes detailFadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}
@keyframes detailSlideUp {
  from { opacity: 0; transform: translateY(18px) scale(0.985); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
@media (max-width: 560px) {
  .modal-overlay { padding: 12px; align-items: flex-end; }
  .tthc-detail { max-height: 92vh; border-radius: var(--radius-lg) var(--radius-lg) 0 0; }
  .detail-header, .detail-body, .detail-footer { padding-left: 16px; padding-right: 16px; }
  .detail-body dl { grid-template-columns: 1fr; }
  .detail-body dt { padding-bottom: 3px; border-bottom: 0; }
  .detail-body dd { padding-top: 3px; }
  .detail-footer { flex-direction: column-reverse; }
  .detail-footer .btn { justify-content: center; }
}
@media (prefers-reduced-motion: reduce) {
  .modal-overlay, .tthc-detail { animation: none; }
}

/* ── Site footer ────────────────────────────────────────────────────── */
.site-footer {
  margin-top: 48px;
  padding: 28px 24px;
  background: linear-gradient(180deg, #f8fafc 0%, #eef2f7 100%);
  border-top: 1px solid rgba(15, 23, 42, 0.06);
  color: #475569;
  font-size: 14px;
  text-align: center;
}

.site-footer .footer-content {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.site-footer .footer-content > * {
  margin: 0;
}

.site-footer p,
.site-footer .footer-text {
  line-height: 1.6;
  color: #64748b;
}

.site-footer .footer-brand-block {
  display: inline-flex;
  align-items: center;
  gap: 13px;
  padding: 6px 4px;
  text-align: left;
}
.site-footer .footer-emblem {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 12px;
  color: var(--color-primary, #1a56db);
  background: var(--color-primary-soft, #eff6ff);
  border: 1px solid rgba(26, 86, 219, 0.15);
}
.site-footer .footer-emblem svg { width: 22px; height: 22px; }
.site-footer .footer-brand-text {
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.site-footer .footer-brand {
  font-weight: 600;
  font-size: 14px;
  color: #1e293b;
  letter-spacing: -0.01em;
}
.site-footer .footer-meta {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
  color: #94a3b8;
  letter-spacing: 0.01em;
}
.site-footer .footer-meta strong {
  font-weight: 600;
  color: #64748b;
}
.site-footer .footer-dot { color: #cbd5e1; font-size: 10px; }
.site-footer .footer-author {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.site-footer .footer-author__badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px 3px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  color: #fff;
  background: linear-gradient(135deg, var(--color-primary, #1a56db) 0%, #7c3aed 100%);
  box-shadow: 0 2px 8px rgba(124, 58, 237, 0.3);
  letter-spacing: 0.01em;
}
.site-footer .footer-author__badge svg {
  width: 13px;
  height: 13px;
  opacity: 0.9;
}
@media (max-width: 480px) {
  .site-footer .footer-brand-block { flex-direction: column; text-align: center; gap: 10px; }
  .site-footer .footer-brand-text { align-items: center; }
  .site-footer .footer-meta { flex-wrap: wrap; justify-content: center; }
}

/* ── Footer guide CTA (nổi bật) ──────────────────────────────────── */
.footer-guide-cta {
  display: inline-flex;
  align-items: center;
  gap: 14px;
  max-width: 100%;
  margin-bottom: 6px;
  padding: 12px 18px;
  background: linear-gradient(135deg, var(--color-primary, #1a56db) 0%, var(--color-primary-dark, #1447b6) 100%);
  border-radius: var(--radius-lg, 14px);
  color: #fff;
  text-decoration: none;
  text-align: left;
  box-shadow: 0 6px 18px rgba(26, 86, 219, 0.28);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.footer-guide-cta:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 26px rgba(26, 86, 219, 0.38);
  text-decoration: none;
}
.footer-guide-cta:active { transform: translateY(0); }
.footer-guide-cta__icon {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.18);
}
.footer-guide-cta__icon svg { width: 20px; height: 20px; }
.footer-guide-cta__text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  line-height: 1.35;
}
.footer-guide-cta__text strong {
  font-size: 14.5px;
  font-weight: 700;
  color: #fff;
}
.footer-guide-cta__text small {
  font-size: 11.5px;
  color: rgba(255, 255, 255, 0.82);
}
.footer-guide-cta__arrow {
  flex: 0 0 auto;
  font-size: 20px;
  font-weight: 700;
  transition: transform 0.15s ease;
}
.footer-guide-cta:hover .footer-guide-cta__arrow { transform: translateX(4px); }
@media (max-width: 480px) {
  .footer-guide-cta { gap: 10px; padding: 10px 14px; }
  .footer-guide-cta__icon { width: 34px; height: 34px; }
  .footer-guide-cta__text strong { font-size: 13px; }
  .footer-guide-cta__text small { font-size: 10.5px; }
}

/* ── Footer usage stats (today / cumulative) ─────────────────────── */
.site-footer .footer-stats {
  margin-top: 10px;
  display: inline-flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: center;
  gap: 8px 14px;
  font-size: 12.5px;
  color: #475569;
  letter-spacing: 0.01em;
}

.site-footer .footer-stat-item {
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
  white-space: nowrap;
}

.site-footer .footer-stat-label {
  color: #64748b;
}

.site-footer .footer-stat-value {
  font-weight: 600;
  color: #1e293b;
  font-variant-numeric: tabular-nums;
  min-width: 2ch;
  text-align: right;
  display: inline-block;
}

.site-footer .footer-stat-unit {
  color: #94a3b8;
  font-size: 12px;
}

.site-footer .footer-stat-divider {
  color: #cbd5e1;
  font-weight: 400;
}

@media (prefers-color-scheme: dark) {
  .site-footer .footer-stats {
    color: #cbd5e1;
  }
  .site-footer .footer-stat-label {
    color: #94a3b8;
  }
  .site-footer .footer-stat-value {
    color: #f1f5f9;
  }
  .site-footer .footer-stat-unit {
    color: #64748b;
  }
  .site-footer .footer-stat-divider {
    color: #475569;
  }
}

@media (max-width: 480px) {
  .site-footer .footer-stats {
    gap: 4px 10px;
    font-size: 12px;
  }
  .site-footer .footer-stat-divider {
    display: none;
  }
}

@media (prefers-color-scheme: dark) {
  .site-footer {
    background: linear-gradient(180deg, #111827 0%, #0f172a 100%);
    border-top-color: rgba(148, 163, 184, 0.16);
    color: #cbd5e1;
  }

  .site-footer p,
  .site-footer .footer-text {
    color: #94a3b8;
  }

  .site-footer .footer-brand {
    color: #e2e8f0;
  }

  .site-footer .footer-meta {
    color: #64748b;
  }
  .site-footer .footer-meta strong { color: #94a3b8; }
  .site-footer .footer-dot { color: #475569; }
  .site-footer .footer-emblem {
    color: #93b4f5;
    background: rgba(91, 141, 239, 0.12);
    border-color: rgba(91, 141, 239, 0.22);
  }
}

/* ── Ward stats panel ─────────────────────────────────────────────────────── */
/* Khi ở sidebar trái (legacy, fallback). Khi đã di chuyển sang stats-sidebar
   thì ẩn — block này không nên tồn tại trên DOM nữa. */
.sidebar .ward-stats-section { display: none; }

/* Trong stats-sidebar: ward stats là 1 card giống stats-card khác */
.stats-sidebar .ward-stats-card {
  border-color: var(--color-primary-soft);
  background: linear-gradient(180deg, var(--color-primary-soft) 0%, var(--color-surface) 60%);
}
.stats-sidebar .ward-stats-card .stats-card__title {
  color: var(--color-primary);
  font-size: 14px;
  font-weight: 600;
}
.stats-sidebar .stats-card__close {
  font-size: 11.5px;
  color: var(--color-text-muted);
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
}
.stats-sidebar .stats-card__close:hover {
  background: var(--color-bg-soft);
  color: var(--color-danger);
}
.ward-stats-panel {
  font-size: 12.5px;
  color: var(--color-text);
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.ward-stats-loading,
.ward-stats-empty,
.ward-stats-error {
  font-size: 12px;
  padding: 12px 10px;
  text-align: center;
  color: var(--color-text-muted);
  font-style: italic;
  background: var(--color-surface-2);
  border-radius: 6px;
  border: 1px dashed var(--color-border);
}
.ward-stats-error {
  color: var(--color-danger);
  border-color: var(--color-danger-soft);
  background: var(--color-danger-soft);
  font-style: normal;
}
.ward-stats-name {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--color-text);
  margin-bottom: 2px;
}
.ward-stats-name code {
  font-family: var(--font-mono);
  font-size: 11px;
  background: var(--color-bg-soft);
  color: var(--color-text-muted);
  padding: 1px 6px;
  border-radius: 4px;
  margin-left: 4px;
  font-weight: 400;
}
.ward-stats-subtitle {
  font-size: 11px;
  color: var(--color-text-muted);
  margin-bottom: 2px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 600;
}
.ward-stats-summary {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
}
.ward-stat-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 8px;
  padding: 8px 10px;
  text-align: center;
}
.ward-stat-card .stat-label {
  font-size: 10px;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 600;
  margin-bottom: 2px;
}
.ward-stat-card .stat-value {
  font-size: 18px;
  font-weight: 700;
  color: var(--color-text);
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}
.ward-stat-card .stat-pct {
  font-size: 10px;
  color: var(--color-text-muted);
  margin-top: 2px;
  font-variant-numeric: tabular-nums;
}
.ward-stat-card .stat-sub {
  margin-top: 6px;
  padding-top: 6px;
  border-top: 1px dashed var(--color-border-soft);
  font-size: 10px;
  line-height: 1.4;
  color: var(--color-text-muted);
  font-variant-numeric: tabular-nums;
}
.ward-stat-card .stat-sub b {
  font-weight: 600;
  color: var(--color-text);
}
.ward-stat-card.stat-full {
  background: var(--color-success-soft);
  border-color: rgba(22, 163, 74, 0.25);
}
.ward-stat-card.stat-full .stat-value { color: var(--color-success); }
.ward-stat-card.stat-partial {
  background: var(--color-warning-soft);
  border-color: rgba(217, 119, 6, 0.25);
}
.ward-stat-card.stat-partial .stat-value { color: var(--color-warning); }
.ward-stat-card.stat-meta .stat-value {
  font-size: 15px;
  color: var(--color-primary);
}

.ward-stats-table-wrap {
  max-height: 280px;
  overflow-y: auto;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  background: var(--color-surface);
}
.ward-stats-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}
.ward-stats-table thead th {
  position: sticky;
  top: 0;
  background: var(--color-surface-2);
  text-align: left;
  padding: 7px 9px;
  font-weight: 600;
  font-size: 10.5px;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid var(--color-border);
  z-index: 1;
}
.ward-stats-table tbody td {
  padding: 7px 9px;
  border-bottom: 1px solid var(--color-border-soft);
  vertical-align: top;
}
.ward-stats-table tbody tr:last-child td { border-bottom: none; }
.ward-stats-table tbody tr:hover { background: var(--color-bg-soft); }
.ward-stats-table .num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.ward-stats-table .dept-code {
  font-family: var(--font-mono);
  font-size: 11px;
  background: var(--color-bg-soft);
  padding: 1px 5px;
  border-radius: 4px;
  color: var(--color-text-muted);
  white-space: nowrap;
}
.ward-stats-table .dept-name {
  font-size: 12px;
  color: var(--color-text);
  word-break: break-word;
}
.ward-stats-table .num.full { color: var(--color-success); font-weight: 600; }
.ward-stats-table .num.partial { color: var(--color-warning); font-weight: 600; }
.ward-stats-progress {
  position: relative;
  background: var(--color-bg-soft);
  border-radius: 4px;
  height: 16px;
  overflow: hidden;
  min-width: 72px;
}
.ward-stats-progress .progress-fill {
  position: absolute;
  top: 0;
  left: 0;
  height: 100%;
  background: linear-gradient(90deg, var(--color-success), #4ade80);
  transition: width 0.4s ease;
}
.ward-stats-progress .progress-fill.is-low {
  background: linear-gradient(90deg, var(--color-warning), #fbbf24);
}
.ward-stats-progress .progress-fill.is-zero {
  background: linear-gradient(90deg, var(--color-danger), #f87171);
}
.ward-stats-progress span {
  position: relative;
  display: block;
  text-align: center;
  font-size: 10px;
  line-height: 16px;
  color: var(--color-text);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.ward-stats-more {
  font-size: 11px;
  color: var(--color-text-muted);
  text-align: center;
  font-style: italic;
  padding: 6px 0 0;
}

/* ── Per-agency stats panel additions (Thống kê DVC) ──────────────── */
.ward-stat-card.stat-total {
  background: var(--color-primary-soft);
  border-color: rgba(8, 145, 178, 0.25);
}
.ward-stat-card.stat-total .stat-value {
  color: var(--color-primary);
  font-size: 20px;
}
.ward-stat-card.stat-total .stat-pct {
  font-weight: 600;
  color: var(--color-primary);
  letter-spacing: 0.02em;
}

.ward-stat-progress-wrap {
  display: flex;
  flex-direction: column;
  gap: 4px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 8px;
  padding: 8px 10px;
}
.ward-stat-progress-row {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--color-text-muted);
  font-weight: 600;
}
.ward-stat-progress-row span:last-child {
  color: var(--color-text);
  font-variant-numeric: tabular-nums;
}
.ward-stat-progress-wrap .ward-stats-progress {
  height: 8px;
  min-width: 0;
  border-radius: 4px;
}
.ward-stat-progress-wrap .ward-stats-progress span {
  display: none;
}

.ward-stats-footer {
  font-size: 11px;
  color: var(--color-text-muted);
  text-align: center;
  padding: 6px 8px 0;
  border-top: 1px dashed var(--color-border);
  margin-top: 2px;
}
.ward-stats-footer strong {
  color: var(--color-primary);
  font-weight: 700;
}

/* ── Toast ─────────────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--color-text);
  color: var(--color-surface);
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 500;
  z-index: 200;
  opacity: 0;
  pointer-events: none;
  transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  box-shadow: var(--shadow-lg);
  max-width: 90vw;
}
.toast.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}
.toast--success { background: var(--color-success); color: #fff; }
.toast--error   { background: var(--color-danger);  color: #fff; }

/* ── Scrollbar ─────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--color-border); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--color-text-faint); }

/* ── Sidebar tree (browse by organization) ──────────────────────────
   Three sections: UBND xã phường / Sở/Ban ngành / VP ĐKĐĐ / Ngành dọc.
   Each section has a header with badge + list of agencies.
   Inner max-height caps are KEPT so the section header remains visible
   when the user scrolls the inner list — the goal is "no hidden section
   titles". The outer sidebar no longer scrolls past them. */
.sidebar-tree-section {
  padding: 8px 14px 10px;
  border-bottom: 1px solid var(--color-border-soft);
}
.sidebar-tree-section:last-child { border-bottom: none; }
.sidebar-tree-section .section-header h3 {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 10.5px;
  font-weight: 700;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin: 0;
}
.sidebar-tree-section .section-header h3 .tree-icon {
  font-size: 13px;
}
.sidebar-tree-section .section-header .badge-count {
  font-size: 10px;
  font-weight: 600;
  color: var(--color-text-faint);
  padding: 2px 7px;
  background: var(--color-bg-soft);
  border-radius: 999px;
  font-variant-numeric: tabular-nums;
}
.sidebar-tree-section.is-so-tai-nguyen .section-header h3 { color: var(--color-accent-dark); }
.sidebar-tree-section.is-so-tai-nguyen .section-header .badge-count {
  background: var(--color-accent-soft);
  color: var(--color-accent-dark);
}
.sidebar-tree-section.is-nganh-doc .section-header h3 { color: var(--color-info); }

.sidebar-tree-search {
  position: relative;
  margin: 4px 0 2px;
}
.sidebar-tree-search input {
  width: 100%;
  padding: 5px 10px 5px 28px;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  font-size: 12px;
  font-family: inherit;
  background: var(--color-surface-2);
  color: var(--color-text);
  outline: none;
}
.sidebar-tree-search input:focus {
  border-color: var(--color-primary);
  background: var(--color-surface);
  box-shadow: 0 0 0 2px var(--color-primary-soft);
}
.sidebar-tree-search .search-icon {
  position: absolute;
  left: 8px;
  top: 50%;
  transform: translateY(-50%);
  width: 13px;
  height: 13px;
  color: var(--color-text-faint);
  pointer-events: none;
}

.sidebar-tree {
  list-style: none;
  padding: 0;
  margin: 2px 0 0;
  overflow-y: auto;
  max-height: 220px;
}
.sidebar-tree.compressed { max-height: 180px; }
.sidebar-tree-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 5px 10px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 12.5px;
  color: var(--color-text);
  border: 1px solid transparent;
  background: transparent;
  width: 100%;
  text-align: left;
  transition: background 0.1s ease;
  font-family: inherit;
}
.sidebar-tree-item:hover {
  background: var(--color-bg-soft);
  border-color: var(--color-border-soft);
}
.sidebar-tree-item.active {
  background: var(--color-primary-soft);
  border-color: var(--color-primary);
  color: var(--color-primary);
  font-weight: 600;
}
.sidebar-tree-item.is-dangkydatdai.active {
  background: var(--color-accent-soft);
  border-color: var(--color-accent);
  color: var(--color-accent-dark);
}
.sidebar-tree-item.is-nganh-doc.active {
  background: var(--color-info-soft);
  border-color: var(--color-info);
  color: var(--color-info);
}
.sidebar-tree-item .agency-name {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-right: 6px;
  min-width: 0;
}
.sidebar-tree-item .agency-code {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--color-text-muted);
  padding: 1px 5px;
  background: var(--color-bg-soft);
  border-radius: 3px;
  font-weight: 500;
  flex-shrink: 0;
}
.sidebar-tree-item.active .agency-code {
  background: rgba(255,255,255,0.18);
  color: inherit;
}
.sidebar-tree-item .agency-count {
  font-size: 10px;
  font-weight: 600;
  color: var(--color-text-faint);
  padding: 2px 7px;
  background: var(--color-bg-soft);
  border-radius: 999px;
  font-variant-numeric: tabular-nums;
  flex-shrink: 0;
}
.sidebar-tree-item.active .agency-count {
  background: var(--color-primary);
  color: #fff;
}
.sidebar-tree-item.is-dangkydatdai.active .agency-count {
  background: var(--color-accent);
}
.sidebar-tree-item.is-nganh-doc.active .agency-count {
  background: var(--color-info);
}
.sidebar-tree-item .child-flag {
  display: inline-block;
  font-size: 9.5px;
  font-weight: 600;
  color: var(--color-text-faint);
  background: var(--color-surface-2);
  border: 1px solid var(--color-border-soft);
  padding: 1px 5px;
  border-radius: 999px;
  flex-shrink: 0;
}
.sidebar-tree-item.active .child-flag {
  background: rgba(255,255,255,0.18);
  border-color: transparent;
  color: inherit;
}
.sidebar-tree-empty {
  padding: 8px 10px;
  font-size: 12px;
  color: var(--color-text-faint);
  font-style: italic;
  text-align: center;
}

.sidebar-tree-loading {
  padding: 8px 10px;
  font-size: 12px;
  color: var(--color-text-muted);
  font-style: italic;
  text-align: center;
}

/* Result-context bar — shows which org is currently selected */
.browse-context {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  background: linear-gradient(135deg,
    var(--color-primary-soft, rgba(59,130,246,0.08)) 0%,
    var(--color-surface, #fff) 100%);
  border: 1px solid var(--color-border, var(--border, #e5e7eb));
  border-radius: 10px;
  margin: 12px 24px 0;
  font-size: 13px;
  color: var(--color-text, #0f172a);
}
.browse-context.is-dangkydatdai {
  background: linear-gradient(135deg,
    var(--color-accent-soft, rgba(245,158,11,0.08)) 0%,
    var(--color-surface, #fff) 100%);
  border-color: var(--color-accent);
}
.browse-context.is-nganh-doc {
  background: linear-gradient(135deg,
    var(--color-info-soft, #e0f2fe) 0%,
    var(--color-surface, #fff) 100%);
  border-color: var(--color-info);
}
.browse-context .ctx-eyebrow {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--color-text-muted);
  letter-spacing: 0.06em;
}
.browse-context .ctx-name {
  font-weight: 600;
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.browse-context .ctx-code {
  font-family: var(--font-mono);
  font-size: 11px;
  padding: 2px 7px;
  background: var(--color-bg-soft);
  border-radius: 4px;
  color: var(--color-text-muted);
  flex-shrink: 0;
}
.browse-context .ctx-clear {
  background: none;
  border: none;
  color: var(--color-text-muted);
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 14px;
  line-height: 1;
}
.browse-context .ctx-clear:hover {
  background: var(--color-bg-soft);
  color: var(--color-danger);
}

/* ── Stats sidebar (cột phải) — RESTORED from .bak.20260719-090542 (lines 2222-2564).
   Previous fix dropped this entire desktop block → stats panel invisible / unstyled.
   Now restored verbatim. */
.stats-sidebar {
  position: sticky;
  top: calc(var(--topbar-h) + 16px);
  align-self: start;
  display: flex;
  flex-direction: column;
  gap: 14px;
  /* max-height removed — all stats cards always visible, page scrolls */
  overflow: hidden;
  padding-right: 4px;
}
.stats-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border-soft);
  border-radius: var(--radius);
  padding: 14px;
}
.stats-card__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}
.stats-card__title {
  font-size: 14px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin: 0;
}
.stats-card__icon { font-size: 16px; }
.stats-scope {
  display: flex;
  align-items: center;
  margin: -2px 0 10px;
  padding: 6px 9px;
  border: 1px solid var(--color-primary);
  border-radius: 7px;
  background: var(--color-primary-soft);
  color: var(--color-primary);
  font-size: 11px;
  font-weight: 600;
  line-height: 1.3;
}
.stats-scope-row {
  display: flex;
  align-items: stretch;
  gap: 6px;
  margin: -2px 0 10px;
}
.stats-scope-row .stats-scope {
  margin: 0;
  flex: 1 1 auto;
  min-width: 0;
}
.stats-scope-back {
  flex: 0 0 auto;
  border: 1px solid var(--color-border-soft);
  background: var(--color-surface-2);
  color: var(--color-text-muted);
  border-radius: 7px;
  padding: 6px 9px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.12s ease;
  white-space: nowrap;
}
.stats-scope-back:hover {
  border-color: var(--color-primary);
  color: var(--color-primary);
}
.stats-scope-back.hidden { display: none; }
.stats-card__subtitle {
  font-size: 12.5px;
  font-weight: 600;
  margin: 0;
  color: var(--color-text);
  line-height: 1.3;
}
.stats-refresh {
  background: var(--color-surface-2);
  border: 1px solid var(--color-border-soft);
  border-radius: 6px;
  width: 28px;
  height: 28px;
  font-size: 14px;
  color: var(--color-text-muted);
  cursor: pointer;
  transition: all 0.12s ease;
}
.stats-refresh:hover {
  color: var(--color-primary);
  border-color: var(--color-primary);
}
.stats-refresh.is-loading { animation: stats-spin 0.9s linear infinite; }
@keyframes stats-spin { to { transform: rotate(360deg); } }

.stats-summary {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 10px;
}
.stat-tile {
  position: relative;
  padding: 10px 12px;
  background: var(--color-surface-2);
  border-radius: 8px;
  border: 1px solid transparent;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.stat-tile--full     { border-color: rgba(34, 197, 94, 0.35); }
.stat-tile--partial  { border-color: rgba(245, 158, 11, 0.35); }
.stat-tile--total    { grid-column: 1 / -1; background: var(--color-primary-soft); border-color: var(--color-primary); }
.stat-tile__num {
  font-size: 22px;
  font-weight: 700;
  line-height: 1.1;
  color: var(--color-text);
  font-variant-numeric: tabular-nums;
}
.stat-tile--full .stat-tile__num    { color: #15803d; }
.stat-tile--partial .stat-tile__num { color: #b45309; }
.stat-tile--total .stat-tile__num   { color: var(--color-primary); font-size: 18px; }
.stat-tile__label {
  font-size: 11.5px;
  font-weight: 500;
  color: var(--color-text-muted);
}
.stat-tile__pct {
  position: absolute;
  top: 8px;
  right: 10px;
  font-size: 11px;
  font-weight: 600;
  color: var(--color-text-faint);
}
.stat-tile__sub {
  display: block;
  width: 100%;
  margin-top: 6px;
  font-size: 10px;
  line-height: 1.35;
  color: var(--color-text-muted);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.01em;
}
.stat-tile__sub b {
  font-weight: 600;
  color: var(--color-text);
}
.stats-bar {
  display: flex;
  height: 8px;
  border-radius: 999px;
  background: var(--color-bg-soft);
  overflow: hidden;
  border: 1px solid var(--color-border-soft);
}
.stats-bar__full {
  background: linear-gradient(90deg, #22c55e, #16a34a);
  transition: width 0.6s ease;
}
.stats-bar__partial {
  background: linear-gradient(90deg, #f59e0b, #d97706);
  transition: width 0.6s ease;
}

/* Stats meta — note + toggle button (unique ↔ rows) */
.stats-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
  font-size: 11px;
  color: var(--color-text-faint, #6b7280);
}
.stats-mode-label {
  flex: 1 1 auto;
  line-height: 1.35;
  word-break: break-word;
}
.btn-toggle-rows {
  flex: 0 0 auto;
  font-size: 11px;
  padding: 3px 9px;
  background: transparent;
  border: 1px solid var(--color-border, #e5e7eb);
  border-radius: 4px;
  cursor: pointer;
  color: var(--color-text, #1f2937);
  transition: background 0.15s ease, border-color 0.15s ease;
}
.btn-toggle-rows:hover {
  background: var(--color-bg-soft, #f9fafb);
}
.btn-toggle-rows[aria-pressed="true"] {
  background: var(--color-primary-soft, #eef2ff);
  border-color: var(--color-primary, #4f46e5);
  color: var(--color-primary, #4f46e5);
}

.stats-count {
  font-size: 11px;
  color: var(--color-text-faint);
  font-weight: 500;
}

.stats-by-agency {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.stats-by-agency__loading,
.stats-by-agency__error,
.stats-by-agency__empty {
  font-size: 12px;
  color: var(--color-text-faint);
  font-style: italic;
  padding: 12px 6px;
  text-align: center;
  background: var(--color-surface-2);
  border-radius: 8px;
  border: 1px dashed var(--color-border);
}
.stats-by-agency__error {
  color: var(--color-danger);
  font-style: normal;
  border-color: var(--color-danger-soft);
  background: var(--color-danger-soft);
}
.stats-sector {
  border-top: 1px solid var(--color-border-soft);
  padding-top: 8px;
}
.stats-sector:first-child {
  border-top: none;
  padding-top: 0;
}
.stats-sector__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 11.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--color-text-muted);
  margin-bottom: 6px;
  cursor: pointer;
  padding: 4px 0;
  user-select: none;
}
.stats-sector__head:hover { color: var(--color-primary); }
.stats-sector__caret {
  display: inline-block;
  margin-left: 6px;
  font-size: 10px;
  transition: transform 0.15s ease;
}
.stats-sector.is-collapsed .stats-sector__caret { transform: rotate(-90deg); }
.stats-sector.is-collapsed .stats-sector__body { display: none; }
.stats-sector__body {
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.stats-agency {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  padding: 4px 6px;
  border-radius: 6px;
  transition: background 0.12s ease;
}
.stats-agency:hover {
  background: var(--color-primary-soft);
}
.stats-agency__name {
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.stats-agency__title {
  font-weight: 500;
  color: var(--color-text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.stats-agency__code {
  font-size: 10.5px;
  color: var(--color-text-faint);
  font-family: var(--font-mono);
}
.stats-agency__bar-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  color: var(--color-text-muted);
}
.stats-agency__mini-bar {
  width: 56px;
  height: 5px;
  border-radius: 999px;
  background: var(--color-bg-soft);
  overflow: hidden;
  display: flex;
}
.stats-agency__mini-bar > span {
  display: block;
  height: 100%;
}
.stats-agency__mini-bar > .stats-bar-mini__full    { background: #22c55e; }
.stats-agency__mini-bar > .stats-bar-mini__partial { background: #f59e0b; }
.stats-agency__total {
  font-size: 10.5px;
  color: var(--color-text-faint);
}

.stats-by-agency__more {
  margin-top: 6px;
  text-align: center;
  font-size: 11px;
  color: var(--color-text-faint);
  font-style: italic;
  padding: 4px;
}

/* Empty state "back to province" link — nút phụ trong panel khi by_field rỗng */
.stats-by-agency .link-btn {
  display: inline-block;
  padding: 4px 12px;
  background: var(--color-primary-soft);
  color: var(--color-primary);
  border: 1px solid var(--color-primary);
  border-radius: 6px;
  font-weight: 600;
  cursor: pointer;
  font-size: 11.5px;
  font-style: normal;
}
.stats-by-agency .link-btn:hover {
  background: var(--color-primary);
  color: #fff;
}

/* ════════════════════════════════════════════════════════════════════════
   MOBILE / iOS SAFARI FIXES  (v=12)
   - Sidebar collapse → drawer < 900px
   - Stats sidebar collapse → ẩn < 900px (chỉ hiện top stats card ở toggle)
   - Tap targets ≥ 44px
   - iOS auto-zoom prevention: input font-size ≥ 16px
   - 100dvh fallback cho iOS Safari
   - Safe-area inset cho iPhone notch
   - Sidebar tree items ≥ 44px height
   - Stats summary tiles: 2-col → 1-col dưới 480px
   - Hamburger button chỉ hiện trên mobile
   - Backdrop cho drawer
   - Stats sidebar trở thành tab/toggle trên mobile
   ════════════════════════════════════════════════════════════════════════ */

/* Default: iOS auto-zoom nếu input < 16px */
html {
  -webkit-text-size-adjust: 100%;
  -moz-text-size-adjust: 100%;
  text-size-adjust: 100%;
}
html, body {
  overflow-x: hidden;
  max-width: 100vw;
}

/* Force input/textarea ≥ 16px để iOS không auto-zoom khi focus */
input, textarea, select, button {
  font-size: 14px;
}
input[type="search"],
input[type="text"],
textarea {
  font-size: 16px !important;
}

/* Safe area insets cho iPhone notch (chỉ áp dụng khi mở fullscreen hoặc có safe-area) */
body {
  padding-top: env(safe-area-inset-top);
  padding-right: env(safe-area-inset-right);
  padding-bottom: env(safe-area-inset-bottom);
  padding-left: env(safe-area-inset-left);
}

/* 100dvh fallback: iOS Safari 15.4+ hỗ trợ, cũ thì dùng 100vh đã có */
@supports (height: 100dvh) {
  .sidebar { overflow: hidden; }
  .stats-sidebar { overflow: hidden; }
}

/* Hamburger button (ẩn trên desktop, hiện < 900px) */
.mobile-menu-btn,
.stats-mobile-btn {
  display: none;
}
.mobile-menu-btn {
  position: fixed;
  top: calc(72px + 10px);
  left: 12px;
  z-index: 95;
  width: 44px;
  height: 44px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 10px;
  cursor: pointer;
  align-items: center;
  justify-content: center;
  color: var(--color-text);
  box-shadow: var(--shadow-md);
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}
.mobile-menu-btn:active {
  background: var(--color-bg-soft);
}
.mobile-menu-btn svg {
  width: 22px;
  height: 22px;
}

/* Sidebar backdrop (chỉ dùng trên mobile) */
.sidebar-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.5);
  z-index: 90;
  -webkit-tap-highlight-color: transparent;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}
.sidebar-backdrop.is-open {
  opacity: 1;
  pointer-events: auto;
}

/* ─── TABLET (< 900px) ───────────────────────────────────────────── */
@media (max-width: 900px) {
  .app-shell {
    grid-template-columns: 1fr;
    gap: 12px;
    padding-left: 12px;
    padding-right: 12px;
  }

  /* Sidebar collapse thành drawer */
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: min(86vw, 360px);
    max-width: 360px;
    max-height: 100dvh;
    height: 100dvh;
    z-index: 100;
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
    padding-left: env(safe-area-inset-left);
    transform: translateX(-105%);
    transition: transform 0.25s ease;
    overflow-y: auto;
    border-right: 1px solid var(--color-border);
    background: var(--color-surface);
    box-shadow: var(--shadow-lg);
  }
  .sidebar.is-open {
    transform: translateX(0);
  }

  /* Stats sidebar collapse: ẩn mặc định < 900, có nút toggle để mở */
  .stats-sidebar {
    position: fixed;
    top: 0;
    right: 0;
    width: min(86vw, 380px);
    max-width: 380px;
    max-height: 100dvh;
    height: 100dvh;
    z-index: 100;
    padding-top: calc(env(safe-area-inset-top, 0px) + 12px);
    padding-bottom: env(safe-area-inset-bottom);
    padding-right: env(safe-area-inset-right);
    background: var(--color-surface);
    border-left: 1px solid var(--color-border);
    border-radius: 14px 0 0 14px;
    transform: translateX(105%);
    transition: transform 0.25s ease;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
  }
  .stats-sidebar.is-open {
    transform: translateX(0);
  }

  /* Hamburger chỉ hiện < 900 */
  .mobile-menu-btn { display: inline-flex; }

  /* Stats toggle button (nút bật stats sidebar phải) */
  .stats-mobile-btn {
    display: inline-flex;
    position: fixed;
    top: calc(72px + 10px);
    right: 12px;
    z-index: 95;
    width: 44px;
    height: 44px;
    background: var(--color-primary);
    color: #fff;
    border: none;
    border-radius: 10px;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: var(--shadow-md);
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    font-size: 18px;
  }
  .stats-mobile-btn svg { width: 22px; height: 22px; }

  /* Sidebar tree items ≥ 44px để tap dễ */
  .sidebar-tree-item {
    min-height: 44px;
    padding: 10px 12px;
    font-size: 13px;
  }
  .sidebar-tree { max-height: 50vh; }
  .sidebar-tree.compressed { max-height: 50vh; }

  /* Sidebar section header h3 — đảm bảo đọc được */
  .section-header h3 { font-size: 12px; }

  /* Tap target: 44px cho list item trong fields/systems */
  .list-item { min-height: 44px; padding: 10px 12px; }

  /* Result-bar items không quá nhỏ */
  .result-bar { padding: 12px 16px; }

  /* TTHC card padding */
  .tthc-card { padding: 14px 16px; }

  /* Search bar mobile */
  .searchbar { padding: 12px 14px; }

  /* Browse context */
  .browse-context { margin: 12px 14px 0; padding: 10px 12px; font-size: 12.5px; }

  /* Footer gọn lại */
  .footer-content { font-size: 12px; }
}

/* ─── PHONE (< 600px) ────────────────────────────────────────────── */
@media (max-width: 600px) {
  body { font-size: 13px; }

  /* Stats card 2-col → 1-col */
  .stats-summary {
    grid-template-columns: 1fr !important;
  }
  .stat-tile--total { grid-column: 1 !important; }

  .stat-tile__num { font-size: 19px; }

  /* TTHC card full width, các item wrap dễ hơn */
  .results-grid { padding: 12px 14px; }
  .tthc-meta { font-size: 11.5px; }

  /* Browse context pin vẫn hiện */
  .ctx-code { font-size: 10.5px; }

  /* Bỏ padding trái cho main content khi sidebar collapsed */
  .main-content { padding-left: 0; }

  /* Hide frequent-section__hint nếu quá chật */
  .frequent-section__hint { display: none; }

  /* Frequent chip line-height chuẩn */
  .frequent-chip { font-size: 12px; padding: 6px 10px; }

  /* Modal trượt từ dưới lên trên mobile */
  .modal-overlay { padding: 0; align-items: flex-end; }
  .tthc-detail {
    max-height: 92vh;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  }
  .detail-header, .detail-body, .detail-footer { padding-left: 14px; padding-right: 14px; }
  .detail-body dl { grid-template-columns: 1fr; }
  .detail-body dt { padding-bottom: 2px; border-bottom: 0; }
  .detail-body dd { padding-top: 4px; }
  .detail-footer { flex-direction: column-reverse; }
  .detail-footer .btn { justify-content: center; }

  /* Stats tiles 1-col */
  .ward-stats-summary { grid-template-columns: 1fr 1fr !important; }

  /* Topbar stats ẩn (< 720px), ở đây vẫn giữ brand */
  .topbar-inner { padding: 0 12px; gap: 12px; }
}

/* ─── VERY SMALL (< 380px, vd iPhone SE 1) ─────────────────────── */
@media (max-width: 380px) {
  .stat-tile { padding: 9px 10px; }
  .stat-tile__num { font-size: 17px; }
  .brand-text strong { font-size: 13px; }
  .sidebar-tree { max-height: 45vh; }
  .tthc-title { font-size: 14px; }
  .tthc-card { padding: 12px 14px; }
}

/* ─── LANDSCAPE phone ───────────────────────────────────────────── */
@media (max-height: 500px) and (orientation: landscape) {
  .sidebar { position: static; overflow: hidden; }
  .stats-sidebar { position: static; overflow: hidden; }
}

/* ─── iOS-specific Safari polish ───────────────────────────────── */
@supports (-webkit-touch-callout: none) {
  .sidebar,
  .stats-sidebar {
    -webkit-overflow-scrolling: touch;
  }

  /* Tap targets không bị tap-highlight xanh */
  .sidebar-tree-item,
  .list-item,
  .chip,
  .btn,
  .frequent-chip,
  .tthc-pin,
  .btn-submit {
    -webkit-tap-highlight-color: transparent;
  }

  /* Sticky có thể fail trong flex parent → ép safari đúng cách */
  .topbar {
    position: -webkit-sticky;
    position: sticky;
  }
}

/* Reduced motion cho user accessibility */
@media (prefers-reduced-motion: reduce) {
  .sidebar,
  .stats-sidebar,
  .sidebar-backdrop {
    transition: none !important;
  }
}
