@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Sans:wght@400;500;600;700&display=swap');

:root {
  --bg: #F8FAFC;
  --surface: #FFFFFF;
  --surface-2: #F1F5F9;
  --fg: #0F172A;
  --mut: #475569;
  --bd: #E2E8F0;
  --ac: #1E40AF;
  --ac-2: #3B82F6;
  --ac-soft: #EFF6FF;
  --gn: #15803D;
  --gn-soft: #DCFCE7;
  --rd: #B91C1C;
  --rd-soft: #FEE2E2;
  --am: #B45309;
  --am-soft: #FEF3C7;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.06), 0 1px 2px rgba(15, 23, 42, 0.04);
  --radius: 12px;
  --font: 'IBM Plex Sans', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0B1120;
  --surface: #111827;
  --surface-2: #1E293B;
  --fg: #F8FAFC;
  --mut: #94A3B8;
  --bd: #334155;
  --ac: #3B82F6;
  --ac-2: #60A5FA;
  --ac-soft: rgba(59, 130, 246, 0.16);
  --gn: #4ADE80;
  --gn-soft: rgba(74, 222, 128, 0.15);
  --rd: #F87171;
  --rd-soft: rgba(248, 113, 113, 0.15);
  --am: #FBBF24;
  --am-soft: rgba(251, 191, 36, 0.15);
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.35);
}

*, *::before, *::after {
  box-sizing: border-box;
}

html {
  scroll-padding-top: 16px;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 14px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
}

.num, td, .kpi b {
  font-variant-numeric: tabular-nums;
}

.shell {
  max-width: 1120px;
  margin: 0 auto;
  padding: 16px;
}

/* Sidebar Shell & Full-Width Sticky Header */
.app-shell {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.layout {
  display: flex;
  flex: 1;
  min-height: 0;
}

.sidebar {
  width: 248px;
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--bd);
  padding: 14px 12px;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 58px;
  height: calc(100vh - 58px);
  overflow-y: auto;
  overflow-x: hidden;
  z-index: 45;
  transition: width 0.2s ease, padding 0.2s ease;
}

.sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 2px 4px;
}

.sidebar-toggle {
  padding: 5px;
  border-radius: 8px;
  flex-shrink: 0;
}

.sidebar.collapsed {
  width: 68px;
  padding: 14px 8px;
}

.sidebar.collapsed .sidebar-head {
  flex-direction: column;
  gap: 8px;
  padding: 2px 0;
}

.sidebar.collapsed .brand-text,
.sidebar.collapsed .sidebar-label,
.sidebar.collapsed .side-text,
.sidebar.collapsed .side-badge,
.sidebar.collapsed .sidebar-user-meta {
  display: none;
}

.sidebar.collapsed .side-link {
  justify-content: center;
  padding: 10px 8px;
}

.sidebar.collapsed .sidebar-footer-actions {
  flex-direction: column;
}

.sidebar-group {
  margin-top: 18px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.sidebar-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--mut);
  padding: 0 10px 6px;
}

.side-link {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
  border: none;
  background: transparent;
  color: var(--mut);
  padding: 9px 11px;
  border-radius: 9px;
  font-size: 13.5px;
  font-weight: 500;
  text-decoration: none;
  text-align: left;
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.side-link-main {
  display: inline-flex;
  align-items: center;
  gap: 9px;
}

.side-link:hover:not(:disabled) {
  background: var(--surface-2);
  color: var(--fg);
}

.side-link.on {
  background: var(--ac);
  color: #FFFFFF;
}

.side-link.on:hover {
  background: var(--ac);
  color: #FFFFFF;
}

.side-badge {
  font-size: 10px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--mut);
  flex-shrink: 0;
}

.side-badge.warn {
  background: rgba(245, 158, 11, 0.16);
  color: #D97706;
  border: 1px solid rgba(245, 158, 11, 0.35);
}

.side-badge.setup {
  background: rgba(59, 130, 246, 0.14);
  color: #2563EB;
  border: 1px solid rgba(59, 130, 246, 0.3);
}

.side-dot {
  width: 7px;
  height: 7px;
  border-radius: 999px;
  flex-shrink: 0;
}

.side-dot.ok {
  background: #10B981;
  box-shadow: 0 0 0 2px rgba(16, 185, 129, 0.18);
}

.side-link.on .side-badge,
.side-link.on .side-badge.warn,
.side-link.on .side-badge.setup {
  background: rgba(255, 255, 255, 0.22);
  color: #FFFFFF;
  border-color: rgba(255, 255, 255, 0.35);
}

.side-link.on .side-dot.ok {
  background: #FFFFFF;
  box-shadow: none;
}

.sidebar.collapsed .side-dot {
  display: none;
}

.sidebar-footer {
  margin-top: auto;
  padding-top: 14px;
  border-top: 1px solid var(--bd);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.main-col {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.main-inner {
  width: 100%;
  max-width: 1100px;
  margin: 0 auto;
  padding: 16px 20px;
}

.menu-btn {
  display: none;
}

.side-backdrop {
  display: none;
}

/* Header & Navigation */
.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--bd);
  border-radius: var(--radius);
  padding: 12px 16px;
  box-shadow: var(--shadow);
  margin-bottom: 14px;
}

.topbar-full {
  position: sticky;
  top: 0;
  z-index: 60;
  width: 100%;
  min-height: 58px;
  border-radius: 0;
  border: none;
  border-bottom: 1px solid var(--bd);
  margin-bottom: 0;
  padding: 10px 18px;
  box-shadow: 0 1px 4px rgba(15, 23, 42, 0.04);
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.topbar-divider {
  width: 1px;
  height: 22px;
  background: var(--bd);
  flex-shrink: 0;
}

.topbar-title {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 17px;
  letter-spacing: -0.01em;
}

.brand-mark {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: var(--ac);
  color: #FFFFFF;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.brand-sub {
  font-size: 11px;
  font-weight: 500;
  color: var(--mut);
  display: block;
  line-height: 1.2;
}

.top-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border-radius: 9px;
  border: 1px solid var(--bd);
  background: var(--surface);
  color: var(--mut);
  cursor: pointer;
}

.icon-btn:hover,
.icon-btn.on {
  background: var(--ac-soft);
  color: var(--ac);
  border-color: var(--ac);
}

.profile-wrap {
  position: relative;
}

.profile-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 4px 10px 4px 5px;
  height: 36px;
  border-radius: 999px;
  border: 1px solid var(--bd);
  background: var(--surface);
  color: var(--fg);
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
}

.profile-btn:hover,
.profile-btn.on {
  background: var(--surface-2);
  border-color: var(--ac-2);
}

.profile-avatar {
  width: 26px;
  height: 26px;
  border-radius: 999px;
  background: var(--ac);
  color: #FFFFFF;
  font-size: 11px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.profile-menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  width: 240px;
  background: var(--surface);
  border: 1px solid var(--bd);
  border-radius: 12px;
  box-shadow: 0 12px 32px rgba(15, 23, 42, 0.16);
  padding: 6px;
  z-index: 80;
}

.profile-menu-hd {
  padding: 8px 10px;
  border-bottom: 1px solid var(--bd);
  margin-bottom: 4px;
}

.profile-menu-item {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  border: none;
  background: transparent;
  color: var(--fg);
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  text-decoration: none;
  text-align: left;
  cursor: pointer;
}

.profile-menu-item:hover {
  background: var(--surface-2);
}

.profile-menu-item.danger {
  color: var(--rd);
}

.profile-menu-item.danger:hover {
  background: var(--rd-soft);
}

.profile-sep {
  height: 1px;
  background: var(--bd);
  margin: 4px 6px;
}

details.faq-item {
  border: 1px solid var(--bd);
  border-radius: 10px;
  padding: 10px 14px;
  background: var(--surface);
}

details.faq-item + details.faq-item {
  margin-top: 8px;
}

details.faq-item summary {
  cursor: pointer;
  font-weight: 600;
  font-size: 14px;
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

details.faq-item summary::-webkit-details-marker {
  display: none;
}

details.faq-item[open] summary {
  color: var(--ac);
  margin-bottom: 8px;
}

.nav {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 16px;
}

.nav button {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  background: var(--surface);
  color: var(--mut);
  border: 1px solid var(--bd);
  border-radius: 10px;
  padding: 8px 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.nav button:hover {
  color: var(--fg);
  background: var(--surface-2);
}

.nav button.on {
  background: var(--ac);
  color: #FFFFFF;
  border-color: var(--ac);
}

/* Buttons & Inputs */
button, .btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: var(--surface);
  color: var(--fg);
  border: 1px solid var(--bd);
  border-radius: 8px;
  padding: 8px 13px;
  font: inherit;
  font-weight: 500;
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease, opacity 0.15s ease;
}

button:hover:not(:disabled) {
  background: var(--surface-2);
}

button.p, .btn.p {
  background: var(--ac);
  color: #FFFFFF;
  border-color: var(--ac);
}

button.p:hover:not(:disabled), .btn.p:hover:not(:disabled) {
  opacity: 0.92;
  background: var(--ac);
}

button.sm {
  padding: 5px 10px;
  font-size: 12px;
}

button.danger {
  color: var(--rd);
}

button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, a:focus-visible {
  outline: 2px solid var(--ac-2);
  outline-offset: 2px;
}

input, select, textarea {
  background: var(--surface);
  color: var(--fg);
  border: 1px solid var(--bd);
  border-radius: 8px;
  padding: 8px 10px;
  font: inherit;
  max-width: 100%;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

select {
  appearance: none;
  -webkit-appearance: none;
  padding-right: 32px;
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 9px center;
  background-size: 15px 15px;
}

select:hover:not(:disabled), input:hover:not(:disabled), textarea:hover:not(:disabled) {
  border-color: var(--ac-2);
}

select option {
  background: var(--surface);
  color: var(--fg);
}

input:disabled, select:disabled {
  opacity: 0.72;
  cursor: not-allowed;
  background: var(--surface-2);
}

.form-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: flex-end;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  font-weight: 500;
  color: var(--mut);
}

/* Toggle Switch & Permission Grid */
.switch {
  position: relative;
  display: inline-block;
  width: 40px;
  height: 22px;
  flex-shrink: 0;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
  position: absolute;
}

.switch-slider {
  position: absolute;
  inset: 0;
  cursor: pointer;
  background: var(--bd);
  border-radius: 999px;
  transition: background-color 0.18s ease;
}

.switch-slider::before {
  content: '';
  position: absolute;
  width: 16px;
  height: 16px;
  left: 3px;
  top: 3px;
  border-radius: 50%;
  background: #FFFFFF;
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.25);
  transition: transform 0.18s ease;
}

.switch input:checked + .switch-slider {
  background: var(--ac);
}

.switch input:checked + .switch-slider::before {
  transform: translateX(18px);
}

.switch input:focus-visible + .switch-slider {
  outline: 2px solid var(--ac-2);
  outline-offset: 2px;
}

.perm-groups {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.perm-group-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--mut);
  margin-bottom: 8px;
}

.perm-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(290px, 1fr));
  gap: 10px;
}

.perm-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 11px 13px;
  border: 1px solid var(--bd);
  border-radius: 10px;
  background: var(--surface-2);
  cursor: pointer;
}

.perm-item:hover {
  border-color: var(--ac-2);
}

.perm-item-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--fg);
}

.perm-item-desc {
  font-size: 11.5px;
  color: var(--mut);
  line-height: 1.35;
  margin-top: 2px;
}

/* Searchable Dropdown */
.combo-wrap {
  position: relative;
  display: inline-block;
  min-width: 240px;
}

.combo-btn {
  display: inline-flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
  background: var(--surface);
  color: var(--fg);
  border: 1px solid var(--bd);
  border-radius: 8px;
  padding: 7px 10px;
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
}

.combo-btn:hover,
.combo-btn.on {
  border-color: var(--ac-2);
}

.combo-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  width: 280px;
  background: var(--surface);
  border: 1px solid var(--bd);
  border-radius: 10px;
  box-shadow: 0 12px 30px rgba(15, 23, 42, 0.16);
  padding: 8px;
  z-index: 85;
}

.combo-menu input {
  width: 100%;
  margin-bottom: 6px;
  font-size: 12.5px;
  padding: 6px 9px;
}

.combo-list {
  max-height: 220px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.combo-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
  border: none;
  background: transparent;
  color: var(--fg);
  padding: 7px 9px;
  border-radius: 7px;
  font-size: 12.5px;
  text-align: left;
  cursor: pointer;
}

.combo-item:hover,
.combo-item.on {
  background: var(--surface-2);
}

.combo-item.on {
  color: var(--ac);
  font-weight: 600;
}

/* Badges & Status Pills */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  background: var(--surface-2);
  color: var(--mut);
  border: 1px solid var(--bd);
}

.pill.ok {
  background: var(--gn-soft);
  color: var(--gn);
  border-color: transparent;
}

.pill.warn {
  background: var(--am-soft);
  color: var(--am);
  border-color: transparent;
}

.pill.err {
  background: var(--rd-soft);
  color: var(--rd);
  border-color: transparent;
}

.pill.admin {
  background: var(--ac-soft);
  color: var(--ac);
  border-color: transparent;
}

.pill.elss {
  background: rgba(124, 58, 237, 0.12);
  color: #6D28D9;
  border-color: rgba(124, 58, 237, 0.25);
}

.pill.br-none { background: var(--surface-2); color: var(--mut); border-color: var(--bd); }
.pill.br-0 { background: #D1FAE5; color: #065F46; border-color: #A7F3D0; }
.pill.br-1 { background: #E0E7FF; color: #3730A3; border-color: #C7D2FE; }
.pill.br-2 { background: #FEF3C7; color: #92400E; border-color: #FDE68A; }
.pill.br-3 { background: #E0F2FE; color: #075985; border-color: #BAE6FD; }
.pill.br-4 { background: #CCFBF1; color: #115E59; border-color: #99F6E4; }
.pill.br-5 { background: #F3E8FF; color: #6B21A8; border-color: #E9D5FF; }
.pill.br-6 { background: #FFE4E6; color: #9F1239; border-color: #FECDD3; }
.pill.br-7 { background: #FFEDD5; color: #9A3412; border-color: #FED7AA; }
.pill.br-8 { background: #ECFCCB; color: #3F6212; border-color: #D9F99D; }
.pill.br-9 { background: #FCE7F3; color: #9D174D; border-color: #FBCFE8; }

:root[data-theme="dark"] .pill.elss {
  background: rgba(167, 139, 250, 0.18);
  color: #C4B5FD;
  border-color: rgba(167, 139, 250, 0.35);
}
:root[data-theme="dark"] .pill.br-0 { background: rgba(16, 185, 129, 0.2); color: #6EE7B7; border-color: rgba(16, 185, 129, 0.35); }
:root[data-theme="dark"] .pill.br-1 { background: rgba(99, 102, 241, 0.22); color: #A5B4FC; border-color: rgba(99, 102, 241, 0.38); }
:root[data-theme="dark"] .pill.br-2 { background: rgba(245, 158, 11, 0.2); color: #FCD34D; border-color: rgba(245, 158, 11, 0.35); }
:root[data-theme="dark"] .pill.br-3 { background: rgba(14, 165, 233, 0.2); color: #7DD3FC; border-color: rgba(14, 165, 233, 0.35); }
:root[data-theme="dark"] .pill.br-4 { background: rgba(20, 184, 166, 0.2); color: #5EEAD4; border-color: rgba(20, 184, 166, 0.35); }
:root[data-theme="dark"] .pill.br-5 { background: rgba(168, 85, 247, 0.22); color: #D8B4FE; border-color: rgba(168, 85, 247, 0.38); }
:root[data-theme="dark"] .pill.br-6 { background: rgba(244, 63, 94, 0.2); color: #FDA4AF; border-color: rgba(244, 63, 94, 0.35); }
:root[data-theme="dark"] .pill.br-7 { background: rgba(249, 115, 22, 0.2); color: #FDBA74; border-color: rgba(249, 115, 22, 0.35); }
:root[data-theme="dark"] .pill.br-8 { background: rgba(132, 204, 22, 0.2); color: #BEF264; border-color: rgba(132, 204, 22, 0.35); }
:root[data-theme="dark"] .pill.br-9 { background: rgba(236, 72, 153, 0.2); color: #F9A8D4; border-color: rgba(236, 72, 153, 0.35); }

/* Cards & Grids */
.card {
  background: var(--surface);
  border: 1px solid var(--bd);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  margin-bottom: 14px;
}

.card-hero-ok {
  border-color: rgba(16, 185, 129, 0.4);
  border-left: 4px solid #16A34A;
  background: linear-gradient(180deg, rgba(16, 185, 129, 0.08) 0%, var(--surface) 80px);
}

.card-hd {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 12px;
}

.card-hd h2 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(175px, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.kpi {
  background: var(--surface);
  border: 1px solid var(--bd);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow);
}

.kpi > span {
  display: block;
  font-size: 12px;
  color: var(--mut);
  margin-bottom: 4px;
}

.info-tip {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 15px;
  height: 15px;
  margin-left: 4px;
  border-radius: 50%;
  border: 1px solid var(--bd);
  background: var(--surface-2);
  color: var(--mut);
  font-size: 10px;
  font-weight: 700;
  font-style: normal;
  line-height: 1;
  cursor: help;
  vertical-align: middle;
}

.info-tip:hover,
.info-tip:focus-visible {
  color: var(--ac);
  border-color: var(--ac);
  outline: none;
}

.info-tip::after {
  content: attr(data-tip);
  position: absolute;
  left: 50%;
  bottom: calc(100% + 7px);
  transform: translateX(-50%);
  width: max-content;
  max-width: 240px;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--bd);
  background: #0F172A;
  color: #F8FAFC;
  font-size: 11.5px;
  font-weight: 500;
  line-height: 1.4;
  white-space: normal;
  text-align: left;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.28);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s ease;
  z-index: 60;
}

.info-tip:hover::after,
.info-tip:focus-visible::after {
  opacity: 1;
}

.kpi b {
  display: block;
  font-size: 20px;
  letter-spacing: -0.01em;
}

.kpi small {
  display: block;
  font-size: 12px;
  color: var(--mut);
  margin-top: 2px;
}

.charts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}

/* Tables */
.table-wrap {
  overflow-x: auto;
  border-radius: 8px;
}

table {
  border-collapse: collapse;
  width: 100%;
  min-width: 620px;
}

.charts-grid table,
.table-wrap.compact table {
  min-width: 0;
}

th, td {
  padding: 9px 10px;
  border-bottom: 1px solid var(--bd);
  text-align: right;
  white-space: nowrap;
}

th:first-child, td:first-child {
  text-align: left;
  white-space: normal;
}

th {
  color: var(--mut);
  font-weight: 600;
  font-size: 12px;
  background: var(--surface-2);
}

th.th-sort {
  cursor: pointer;
  user-select: none;
  transition: color 0.12s ease;
}

th.th-sort:hover,
th.th-sort.on {
  color: var(--fg);
}

tr.total td {
  font-weight: 700;
  border-top: 2px solid var(--bd);
  background: var(--surface-2);
}

tr.acc-row {
  cursor: pointer;
  transition: background 0.12s ease;
}

tr.acc-row:hover td {
  background: var(--surface-2);
}

.acc-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
}

.acc-chev {
  display: inline-flex;
  color: var(--mut);
  flex-shrink: 0;
}

tr.acc-child td {
  background: var(--surface-2);
  font-size: 12.5px;
  color: var(--mut);
}

tr.acc-child td:first-child {
  padding-left: 34px;
}

/* Utilities & Colors */
.g { color: var(--gn); }
.r { color: var(--rd); }
.m { color: var(--mut); font-size: 12px; }
.hint { font-size: 12px; color: var(--mut); white-space: normal; text-align: left; }

.banner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 14px;
  border-radius: 10px;
  margin-bottom: 14px;
  font-size: 13px;
  background: var(--ac-soft);
  color: var(--fg);
  border: 1px solid var(--bd);
}

.banner.warn {
  background: var(--am-soft);
}

.banner.err {
  background: var(--rd-soft);
}

#toast-slot, #adm-toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 60;
  max-width: min(420px, calc(100vw - 32px));
  pointer-events: none;
}

.toast-box {
  pointer-events: auto;
  margin-bottom: 0;
  background: var(--surface);
  border: 1px solid var(--ac-2);
  box-shadow: 0 10px 25px rgba(15, 23, 42, 0.18);
}

.toast-box.warn {
  background: var(--am-soft);
  border-color: var(--am);
}

.toast-box.err {
  background: var(--rd-soft);
  border-color: var(--rd);
}

.dash-section {
  border: 1px solid var(--bd);
  border-radius: 14px;
  padding: 16px;
  background: var(--surface-2);
  margin-bottom: 18px;
}

.dash-section.fy {
  border-color: var(--ac-2);
  background: linear-gradient(180deg, var(--ac-soft) 0%, var(--surface-2) 110px);
}

.dash-section-hd {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding-bottom: 12px;
  margin-bottom: 14px;
  border-bottom: 1px solid var(--bd);
}

.dash-section-hd h2 {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

/* Dropzone */
.dropzone {
  border: 2px dashed var(--bd);
  border-radius: 12px;
  padding: 18px;
  text-align: center;
  background: var(--surface-2);
  cursor: pointer;
  transition: border-color 0.15s ease, background-color 0.15s ease;
}

.dropzone:hover, .dropzone.drag {
  border-color: var(--ac-2);
  background: var(--ac-soft);
}

/* Auth Screen */
.auth-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.auth-card {
  width: 100%;
  max-width: 440px;
  background: var(--surface);
  border: 1px solid var(--bd);
  border-radius: 16px;
  padding: 24px;
  box-shadow: var(--shadow);
}

.auth-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  background: var(--surface-2);
  padding: 4px;
  border-radius: 10px;
  margin: 16px 0;
}

.auth-tabs button {
  border: none;
  background: transparent;
  color: var(--mut);
}

.auth-tabs button.on {
  background: var(--surface);
  color: var(--fg);
  box-shadow: var(--shadow);
}

.sub-tabs {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 6px;
  background: var(--surface-2);
  padding: 4px;
  border-radius: 10px;
  border: 1px solid var(--bd);
  margin-bottom: 14px;
}

.sub-tabs button {
  border: none;
  background: transparent;
  color: var(--mut);
  font-weight: 500;
  padding: 7px 14px;
  border-radius: 7px;
}

.sub-tabs button.on {
  background: var(--surface);
  color: var(--fg);
  font-weight: 600;
  box-shadow: var(--shadow);
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* Modal */
.modal-bg {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 50;
}

.modal {
  width: 100%;
  max-width: 480px;
  background: var(--surface);
  border: 1px solid var(--bd);
  border-radius: 14px;
  padding: 18px;
  box-shadow: var(--shadow);
  animation: modalIn 0.16s ease-out;
}

@keyframes modalIn {
  from {
    opacity: 0;
    transform: translateY(6px) scale(0.985);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.dialog-card {
  max-width: 440px;
  padding: 20px;
}

.dialog-hd {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 12px;
}

.dialog-ic {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  background: var(--p-soft);
  color: var(--p);
}

.dialog-ic.danger {
  background: rgba(220, 38, 38, 0.12);
  color: var(--bad);
}

.dialog-title {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
  line-height: 1.3;
}

.dialog-sub {
  margin: 4px 0 0;
  font-size: 13px;
  color: var(--m);
  line-height: 1.45;
  word-break: break-word;
}

.dialog-note {
  background: var(--surface-2);
  border: 1px solid var(--bd);
  border-radius: 9px;
  padding: 10px 12px;
  font-size: 12.5px;
  color: var(--m);
  line-height: 1.45;
  margin: 10px 0 0;
}

.dialog-err {
  font-size: 12px;
  color: var(--bad);
  margin-top: 6px;
}

.dialog-foot {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 16px;
}

/* Search results */
.sr {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-top: 8px;
}

.sr button {
  justify-content: space-between;
  text-align: left;
  width: 100%;
}

/* Searchable Combobox */
.combo {
  position: relative;
  min-width: 260px;
  flex: 1 1 260px;
  max-width: 360px;
}

.combo-input-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.combo-input-wrap input {
  width: 100%;
  padding-right: 46px;
}

.combo-actions {
  position: absolute;
  right: 6px;
  display: inline-flex;
  align-items: center;
  gap: 2px;
}

.combo-btn {
  border: none;
  background: transparent;
  padding: 2px 4px;
  color: var(--mut);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  line-height: 1;
}

.combo-btn:hover {
  color: var(--fg);
  border-color: transparent;
}

.combo-menu {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  max-height: 250px;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--bd);
  border-radius: 10px;
  box-shadow: var(--shadow);
  z-index: 30;
  padding: 4px;
  display: none;
}

.combo-menu.open {
  display: block;
}

.combo-opt {
  width: 100%;
  justify-content: space-between;
  text-align: left;
  border: none;
  background: transparent;
  padding: 7px 10px;
  border-radius: 7px;
  font-weight: 500;
  gap: 8px;
}

.combo-opt:hover,
.combo-opt.on,
.combo-opt.hi {
  background: var(--ac-soft);
  color: var(--fg);
}

/* Right Slide-over Drawer */
.drawer-bg {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.48);
  display: flex;
  justify-content: flex-end;
  z-index: 45;
}

.drawer-right {
  width: min(520px, 100vw);
  height: 100vh;
  background: var(--surface);
  border-left: 1px solid var(--bd);
  box-shadow: -8px 0 32px rgba(2, 6, 23, 0.22);
  padding: 20px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
  animation: drawerIn 0.18s ease-out;
}

@keyframes drawerIn {
  from {
    opacity: 0;
    transform: translateX(24px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

.drawer-hd {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--bd);
}

.drawer-hd h2 {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.pager {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--bd);
}

/* SVG Chart helpers */
.donut-wrap {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 18px;
}

.legend {
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 1;
  min-width: 160px;
}

.legend-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 13px;
}

.dot {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  display: inline-block;
  margin-right: 6px;
}

@media (max-width: 860px) {
  .sidebar,
  .sidebar.collapsed {
    width: 248px;
    padding: 16px 12px;
    position: fixed;
    left: 0;
    top: 58px;
    height: calc(100vh - 58px);
    bottom: 0;
    transform: translateX(-105%);
    transition: transform 0.2s ease;
    box-shadow: 0 12px 30px rgba(15, 23, 42, 0.25);
  }
  .sidebar.collapsed .brand-text,
  .sidebar.collapsed .sidebar-label,
  .sidebar.collapsed .side-text,
  .sidebar.collapsed .side-badge,
  .sidebar.collapsed .sidebar-user-meta {
    display: initial;
  }
  .sidebar.collapsed .sidebar-head {
    flex-direction: row;
  }
  .sidebar.collapsed .side-link {
    justify-content: space-between;
    padding: 9px 11px;
  }
  .sidebar.collapsed .sidebar-footer-actions {
    flex-direction: row;
  }
  .sidebar-toggle {
    display: none;
  }
  .sidebar.open {
    transform: translateX(0);
  }
  .side-backdrop.open {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.45);
    z-index: 40;
  }
  .menu-btn {
    display: inline-flex;
  }
  .main-inner {
    padding: 12px;
  }
}

@media (max-width: 640px) {
  .shell {
    padding: 10px;
  }
  .topbar {
    padding: 10px 12px;
  }
  .topbar-full .topbar-divider,
  .topbar-full .topbar-title,
  .topbar-full .brand-sub {
    display: none;
  }
  .nav button {
    padding: 7px 10px;
    font-size: 13px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    transition: none !important;
  }
}
