/* ════════════════════════════════════════════════════════════════════════
   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; 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;
  min-height: calc(100vh - var(--topbar-h));
}

@media (max-width: 900px) {
  .app-shell { grid-template-columns: 1fr; gap: 12px; }
  .sidebar, .stats-sidebar { max-height: none; position: static; }
}

/* ── Sidebar ───────────────────────────────────────────────────────── */
.sidebar {
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
  padding: 16px 0;
  overflow-y: auto;
  position: sticky;
  top: var(--topbar-h);
  max-height: calc(100vh - var(--topbar-h));
}
.sidebar-section {
  padding: 12px 16px;
  border-bottom: 1px solid var(--color-border-soft);
}
.sidebar-section:last-child { border-bottom: none; }
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}
.section-header h3 {
  font-size: 11px;
  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: 8px; max-height: 240px; overflow-y: auto; }
.ward-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 7px 10px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  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) */
.scrollable-list {
  max-height: 220px;
  overflow-y: auto;
  margin-top: 4px;
}
.list-placeholder {
  font-size: 12px;
  color: var(--color-text-faint);
  padding: 12px 10px;
  font-style: italic;
  text-align: center;
}
.list-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;
}
.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 */
.fav-list { margin-top: 4px; max-height: 240px; overflow-y: auto; }
.fav-item {
  padding: 8px 10px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 12.5px;
  border: 1px solid var(--color-border-soft);
  background: var(--color-surface-2);
  margin-bottom: 6px;
  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);
}

/* ── 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; }
.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;
}

/* ── 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-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; }

/* ── 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;
  justify-content: center;
  align-items: center;
  gap: 16px;
  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;
}
.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-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: 32px;
  padding: 18px 24px;
  background: var(--color-surface, var(--surface, #fff));
  border-top: 1px solid var(--color-border, var(--border, #e5e7eb));
  color: var(--color-text-muted, var(--text-muted, #6b7280));
  font-size: 13px;
  line-height: 1.5;
}

.footer-content {
  max-width: 1280px;
  margin: 0 auto;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.footer-copyright strong {
  color: var(--color-text, var(--text, #1f2937));
  font-weight: 600;
}

.footer-year {
  margin-left: 8px;
  opacity: 0.7;
}

.footer-credits {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

.footer-credits-label {
  color: var(--color-text-muted, var(--text-muted, #6b7280));
  font-style: italic;
}

.footer-credits-name {
  color: var(--color-primary, var(--primary, #2563eb));
  font-weight: 600;
}

.footer-credits-sep {
  opacity: 0.5;
}

.footer-credits-role {
  opacity: 0.85;
}

@media (max-width: 640px) {
  .footer-content {
    flex-direction: column;
    align-items: flex-start;
    text-align: left;
  }
}

@media (prefers-color-scheme: dark) {
  .site-footer {
    background: var(--color-surface, var(--surface, #1f2937));
    border-top-color: var(--color-border, var(--border, #374151));
  }
}

/* ── Ward stats panel (sidebar) ─────────────────────────────────────────── */
.ward-stats-section {
  background: var(--color-primary-soft);
  border-top: 2px solid var(--color-primary);
}
.ward-stats-section .section-header h3 {
  color: var(--color-primary);
}
.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-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;
}

/* ── 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 + scrollable list of agencies.
*/
.sidebar-tree-section {
  padding: 10px 16px 12px;
  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: 11px;
  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: 6px 0 4px;
}
.sidebar-tree-search input {
  width: 100%;
  padding: 6px 10px 6px 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: 4px 0 0;
  max-height: 280px;
  overflow-y: auto;
}
.sidebar-tree.compressed { max-height: 200px; }
.sidebar-tree-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 7px 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: 10px;
  font-size: 12px;
  color: var(--color-text-faint);
  font-style: italic;
  text-align: center;
}

.sidebar-tree-loading {
  padding: 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);
}

@media (max-width: 900px) {
  .sidebar { max-height: 50vh; }
  .sidebar-tree { max-height: 220px; }
}

/* ── Thủ tục thường dùng (chips dưới search bar) ───────────────────── */
.frequent-section {
  margin-top: 14px;
  padding: 12px 14px;
  background: var(--color-surface-2);
  border: 1px solid var(--color-border-soft);
  border-radius: var(--radius);
}
.frequent-section__header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}
.frequent-section__title {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--color-text);
}
.frequent-section__icon {
  font-size: 14px;
  filter: saturate(1.1);
}
.frequent-section__hint {
  font-size: 11px;
  color: var(--color-text-faint);
  font-style: italic;
}
.frequent-section__source {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 10px;
  background: var(--color-accent-soft, rgba(99, 102, 241, 0.08));
  color: var(--color-accent, #4f46e5);
  font-weight: 500;
  margin-left: 4px;
  white-space: nowrap;
}
.frequent-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.frequent-chips__loading {
  font-size: 12px;
  color: var(--color-text-faint);
  font-style: italic;
  padding: 4px 2px;
}
.frequent-chips:empty::before,
.frequent-chips:has(.frequent-chips__loading:only-child) {
  /* Không cần selector phức tạp — message loading inline OK */
}
.frequent-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 6px 11px;
  border-radius: 999px;
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-text);
  font-size: 12.5px;
  font-weight: 500;
  line-height: 1.2;
  cursor: pointer;
  transition: all 0.12s ease;
  max-width: 360px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.frequent-chip:hover {
  border-color: var(--color-primary);
  background: var(--color-primary-soft);
  color: var(--color-primary);
  transform: translateY(-1px);
}
.frequent-chip__badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  font-size: 10.5px;
  font-weight: 600;
  flex-shrink: 0;
}
.frequent-chip__badge--full {
  background: var(--color-success-soft, #dcfce7);
  color: var(--color-success, #15803d);
}
.frequent-chip__badge--partial {
  background: var(--color-warning-soft, #fef3c7);
  color: var(--color-warning, #b45309);
}
.frequent-chip__name {
  overflow: hidden;
  text-overflow: ellipsis;
}
.frequent-chip__name mark {
  background: transparent;
  color: var(--color-primary);
  font-weight: 600;
}
.frequent-chips__error {
  font-size: 12px;
  color: var(--color-danger);
  font-style: italic;
}

/* ── Stats sidebar (cột phải) ─────────────────────────────────────── */
.stats-sidebar {
  position: sticky;
  top: calc(var(--topbar-h) + 16px);
  align-self: start;
  display: flex;
  flex-direction: column;
  gap: 14px;
  max-height: calc(100vh - var(--topbar-h) - 32px);
  overflow-y: auto;
  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-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);
}
.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;
}