/* ============================================================
   HS FINANCEIRO V2 — Design System
   Plus Jakarta Sans + Teal #0d9488 + Navy #0d1b2a
   HS Informática DF — financeiro.declaranotafiscal.com.br
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:ital,wght@0,300;0,400;0,500;0,600;0,700;0,800;1,400&display=swap');

/* ─── TOKENS ─────────────────────────────────────────────── */
:root {
  /* Brand */
  --primary:        #0d9488;
  --primary-dark:   #0f766e;
  --primary-light:  #14b8a6;
  --primary-pale:   #ccfbf1;
  --primary-glow:   rgba(13,148,136,.18);

  /* Neutrals */
  --navy:           #0d1b2a;
  --navy-mid:       #122336;
  --navy-light:     #1a3347;
  --navy-border:    rgba(255,255,255,.08);

  /* Backgrounds */
  --bg-page:        #f5f7fa;
  --bg-surface:     #ffffff;
  --bg-subtle:      #f1f4f8;
  --bg-hover:       #eef2f7;

  /* Text */
  --txt-primary:    #111827;
  --txt-secondary:  #4b5563;
  --txt-muted:      #9ca3af;
  --txt-inverse:    #ffffff;

  /* Borders */
  --border:         #e5e8ee;
  --border-strong:  #d1d5db;

  /* Semantic */
  --success:        #22c55e;
  --success-bg:     #f0fdf4;
  --success-pale:   #dcfce7;
  --danger:         #ef4444;
  --danger-bg:      #fef2f2;
  --danger-pale:    #fee2e2;
  --warning:        #f59e0b;
  --warning-bg:     #fffbeb;
  --warning-pale:   #fef3c7;
  --info:           #3b82f6;
  --info-bg:        #eff6ff;
  --info-pale:      #dbeafe;

  /* KPI card accents */
  --kpi-receita:    var(--success);
  --kpi-despesa:    var(--danger);
  --kpi-saldo:      var(--primary);
  --kpi-pendente:   var(--warning);

  /* Shadows */
  --shadow-xs:      0 1px 2px rgba(0,0,0,.05);
  --shadow-sm:      0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
  --shadow-md:      0 4px 12px rgba(0,0,0,.08), 0 2px 4px rgba(0,0,0,.04);
  --shadow-lg:      0 8px 24px rgba(0,0,0,.10), 0 4px 8px rgba(0,0,0,.05);
  --shadow-xl:      0 16px 40px rgba(0,0,0,.12);
  --shadow-teal:    0 4px 14px rgba(13,148,136,.30);
  --shadow-inset:   inset 0 1px 2px rgba(0,0,0,.06);

  /* Radius */
  --radius-xs:      4px;
  --radius-sm:      6px;
  --radius-md:      10px;
  --radius-lg:      14px;
  --radius-xl:      20px;
  --radius-full:    9999px;

  /* Spacing scale */
  --sp-1:  4px;
  --sp-2:  8px;
  --sp-3:  12px;
  --sp-4:  16px;
  --sp-5:  20px;
  --sp-6:  24px;
  --sp-8:  32px;
  --sp-10: 40px;
  --sp-12: 48px;
  --sp-16: 64px;

  /* Typography */
  --font-sans:  'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono:  'JetBrains Mono', 'Fira Code', monospace;

  --text-xs:   11px;
  --text-sm:   13px;
  --text-base: 14px;
  --text-md:   15px;
  --text-lg:   16px;
  --text-xl:   18px;
  --text-2xl:  22px;
  --text-3xl:  28px;
  --text-4xl:  36px;

  /* Sidebar */
  --sidebar-w: 240px;
  --sidebar-w-collapsed: 64px;

  /* Header */
  --header-h: 60px;

  /* Z-index layers */
  --z-base:    1;
  --z-dropdown: 100;
  --z-sticky:  200;
  --z-overlay: 300;
  --z-modal:   400;
  --z-toast:   500;

  /* Transitions */
  --t-fast:  120ms ease;
  --t-base:  200ms ease;
  --t-slow:  350ms ease;
  --t-spring: 280ms cubic-bezier(.34,1.56,.64,1);
}

/* ─── RESET ──────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: 1.6;
  color: var(--txt-primary);
  background: var(--bg-page);
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
img, svg { display: block; max-width: 100%; }
button, input, select, textarea { font: inherit; }
ul, ol { list-style: none; }
table { border-collapse: collapse; width: 100%; }

/* ─── SCROLLBAR ──────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: var(--radius-full); }
::-webkit-scrollbar-thumb:hover { background: var(--txt-muted); }

/* ─── APP LAYOUT ─────────────────────────────────────────── */
.app-shell {
  display: flex;
  min-height: 100vh;
}

/* ─── SIDEBAR ────────────────────────────────────────────── */
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: var(--sidebar-w);
  height: 100vh;
  background: var(--navy);
  display: flex;
  flex-direction: column;
  transition: width var(--t-slow);
  z-index: var(--z-sticky);
  overflow: hidden;
}
.sidebar.collapsed { width: var(--sidebar-w-collapsed); }

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-5) var(--sp-4);
  border-bottom: 1px solid var(--navy-border);
  min-height: var(--header-h);
  overflow: hidden;
}
.sidebar-logo img { width: 32px; height: 32px; object-fit: contain; flex-shrink: 0; }
.sidebar-logo-text {
  display: flex;
  flex-direction: column;
  opacity: 1;
  transition: opacity var(--t-base);
  white-space: nowrap;
}
.sidebar.collapsed .sidebar-logo-text { opacity: 0; pointer-events: none; }
.sidebar-logo-title {
  font-size: var(--text-sm);
  font-weight: 700;
  color: var(--txt-inverse);
  letter-spacing: -.01em;
}
.sidebar-logo-sub {
  font-size: var(--text-xs);
  color: rgba(255,255,255,.45);
  font-weight: 500;
  letter-spacing: .02em;
  text-transform: uppercase;
}

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: var(--sp-3) 0;
}
.sidebar-section-label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: rgba(255,255,255,.30);
  padding: var(--sp-4) var(--sp-4) var(--sp-2);
  white-space: nowrap;
  transition: opacity var(--t-base);
}
.sidebar.collapsed .sidebar-section-label { opacity: 0; }

.nav-item {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: 10px var(--sp-4);
  margin: 2px var(--sp-2);
  border-radius: var(--radius-md);
  color: rgba(255,255,255,.60);
  font-size: var(--text-sm);
  font-weight: 500;
  cursor: pointer;
  transition: background var(--t-fast), color var(--t-fast);
  white-space: nowrap;
  position: relative;
}
.nav-item i {
  width: 18px;
  text-align: center;
  font-size: 15px;
  flex-shrink: 0;
}
.nav-item span {
  opacity: 1;
  transition: opacity var(--t-base);
  overflow: hidden;
}
.sidebar.collapsed .nav-item span { opacity: 0; }

.nav-item:hover {
  background: rgba(255,255,255,.07);
  color: rgba(255,255,255,.90);
}
.nav-item.active {
  background: rgba(13,148,136,.20);
  color: var(--primary-light);
}
.nav-item.active i { color: var(--primary-light); }

.nav-item .nav-badge {
  margin-left: auto;
  background: var(--danger);
  color: white;
  font-size: 10px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: var(--radius-full);
  flex-shrink: 0;
}

.sidebar-footer {
  border-top: 1px solid var(--navy-border);
  padding: var(--sp-3) 0;
}

.sidebar-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--navy-border);
  background: transparent;
  color: rgba(255,255,255,.50);
  cursor: pointer;
  margin: var(--sp-2) var(--sp-4);
  transition: background var(--t-fast), color var(--t-fast);
}
.sidebar-toggle:hover { background: rgba(255,255,255,.08); color: white; }

/* ─── MAIN CONTENT ───────────────────────────────────────── */
.main-content {
  margin-left: var(--sidebar-w);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  transition: margin-left var(--t-slow);
}
.main-content.sidebar-collapsed { margin-left: var(--sidebar-w-collapsed); }

/* ─── HEADER ─────────────────────────────────────────────── */
.header {
  position: sticky;
  top: 0;
  height: var(--header-h);
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--sp-6);
  z-index: var(--z-sticky);
  gap: var(--sp-4);
}
.header-left {
  display: flex;
  align-items: center;
  gap: var(--sp-4);
}
.header-right {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
}
.header-title {
  font-size: var(--text-lg);
  font-weight: 700;
  color: var(--txt-primary);
  letter-spacing: -.02em;
}
.header-company {
  font-size: var(--text-sm);
  color: var(--txt-muted);
  font-weight: 500;
}

.header-period-selector {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: 6px var(--sp-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-page);
  color: var(--txt-secondary);
  font-size: var(--text-sm);
  font-weight: 500;
  cursor: pointer;
  transition: border-color var(--t-fast), background var(--t-fast);
}
.header-period-selector:hover { border-color: var(--primary); background: var(--bg-surface); }
.header-period-selector i { color: var(--txt-muted); }

/* ─── PAGE CONTENT ───────────────────────────────────────── */
.page-content {
  flex: 1;
  padding: var(--sp-6);
  max-width: 1600px;
  width: 100%;
  margin: 0 auto;
}
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: var(--sp-6);
  gap: var(--sp-4);
}
.page-header-info h1 {
  font-size: var(--text-2xl);
  font-weight: 800;
  color: var(--txt-primary);
  letter-spacing: -.03em;
  line-height: 1.2;
}
.page-header-info p {
  margin-top: 4px;
  font-size: var(--text-sm);
  color: var(--txt-muted);
}
.page-header-actions {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  flex-shrink: 0;
}

/* ─── CARDS ──────────────────────────────────────────────── */
.card {
  background: var(--bg-surface);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  padding: var(--sp-6);
}
.card-sm { padding: var(--sp-4); }
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--sp-5);
}
.card-title {
  font-size: var(--text-md);
  font-weight: 700;
  color: var(--txt-primary);
  letter-spacing: -.01em;
}
.card-subtitle {
  font-size: var(--text-sm);
  color: var(--txt-muted);
  margin-top: 2px;
}

/* ─── KPI CARDS ──────────────────────────────────────────── */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--sp-4);
  margin-bottom: var(--sp-6);
}
.kpi-card {
  background: var(--bg-surface);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  padding: var(--sp-5);
  position: relative;
  overflow: hidden;
  transition: box-shadow var(--t-base), transform var(--t-base);
}
.kpi-card:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); }
.kpi-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}
.kpi-card.receita::before  { background: var(--success); }
.kpi-card.despesa::before  { background: var(--danger); }
.kpi-card.saldo::before    { background: var(--primary); }
.kpi-card.pendente::before { background: var(--warning); }

.kpi-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: var(--sp-3);
}
.kpi-icon {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 17px;
}
.kpi-card.receita  .kpi-icon { background: var(--success-pale); color: #16a34a; }
.kpi-card.despesa  .kpi-icon { background: var(--danger-pale);  color: #dc2626; }
.kpi-card.saldo    .kpi-icon { background: var(--primary-pale); color: var(--primary-dark); }
.kpi-card.pendente .kpi-icon { background: var(--warning-pale); color: #d97706; }

.kpi-label {
  font-size: var(--text-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--txt-muted);
  margin-bottom: 6px;
}
.kpi-value {
  font-size: var(--text-2xl);
  font-weight: 800;
  letter-spacing: -.03em;
  color: var(--txt-primary);
  line-height: 1;
}
.kpi-delta {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: var(--text-xs);
  font-weight: 600;
  margin-top: var(--sp-2);
}
.kpi-delta.up   { color: var(--success); }
.kpi-delta.down { color: var(--danger); }
.kpi-delta i { font-size: 10px; }
.kpi-delta-desc {
  color: var(--txt-muted);
  font-weight: 400;
}

/* ─── BUTTONS ────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  padding: 9px var(--sp-4);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background var(--t-fast), box-shadow var(--t-fast), transform var(--t-fast), color var(--t-fast), border-color var(--t-fast);
  white-space: nowrap;
  line-height: 1;
  text-decoration: none;
}
.btn:active { transform: translateY(1px); }
.btn i { font-size: 13px; }

.btn-primary {
  background: var(--primary);
  color: white;
  border-color: var(--primary-dark);
}
.btn-primary:hover {
  background: var(--primary-dark);
  box-shadow: var(--shadow-teal);
  transform: translateY(-1px);
}
.btn-secondary {
  background: var(--bg-surface);
  color: var(--txt-secondary);
  border-color: var(--border);
}
.btn-secondary:hover { background: var(--bg-hover); border-color: var(--border-strong); }

.btn-danger {
  background: var(--danger);
  color: white;
  border-color: #dc2626;
}
.btn-danger:hover { background: #dc2626; box-shadow: 0 4px 14px rgba(239,68,68,.28); transform: translateY(-1px); }

.btn-outline {
  background: transparent;
  color: var(--primary);
  border-color: var(--primary);
}
.btn-outline:hover { background: var(--primary-pale); }

.btn-ghost {
  background: transparent;
  color: var(--txt-secondary);
  border-color: transparent;
}
.btn-ghost:hover { background: var(--bg-hover); color: var(--txt-primary); }

.btn-sm { padding: 6px var(--sp-3); font-size: var(--text-xs); }
.btn-lg { padding: 12px var(--sp-6); font-size: var(--text-md); }
.btn-full { width: 100%; }
.btn-icon { padding: 9px; }
.btn-icon.btn-sm { padding: 6px; }

.btn:disabled {
  opacity: .5;
  cursor: not-allowed;
  transform: none !important;
}
.btn.loading { pointer-events: none; }
.btn.loading .btn-spinner { display: inline-block; }
.btn-spinner {
  display: none;
  width: 14px; height: 14px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 600ms linear infinite;
}

/* ─── BADGES ─────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 9px;
  border-radius: var(--radius-full);
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: .01em;
  line-height: 1.4;
}
.badge i { font-size: 9px; }
.badge-dot::before {
  content: '';
  width: 6px; height: 6px;
  border-radius: 50%;
  background: currentColor;
  display: inline-block;
}

.badge-success  { background: var(--success-pale);  color: #16a34a; }
.badge-danger   { background: var(--danger-pale);   color: #dc2626; }
.badge-warning  { background: var(--warning-pale);  color: #d97706; }
.badge-info     { background: var(--info-pale);     color: #2563eb; }
.badge-primary  { background: var(--primary-pale);  color: var(--primary-dark); }
.badge-neutral  { background: var(--bg-subtle);     color: var(--txt-secondary); }

.badge-pago     { background: var(--success-pale);  color: #16a34a; }
.badge-pendente { background: var(--warning-pale);  color: #d97706; }
.badge-vencido  { background: var(--danger-pale);   color: #dc2626; }
.badge-receita  { background: #f0fdf4; color: #16a34a; }
.badge-despesa  { background: #fef2f2; color: #dc2626; }

/* ─── FORMS ──────────────────────────────────────────────── */
.form-group { display: flex; flex-direction: column; gap: var(--sp-2); }
.form-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: var(--sp-4); }
.form-grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: var(--sp-4); }

.form-label {
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--txt-secondary);
  text-transform: uppercase;
  letter-spacing: .05em;
}
.form-label .required { color: var(--danger); margin-left: 2px; }

.input, .select, textarea {
  width: 100%;
  padding: 9px var(--sp-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-surface);
  color: var(--txt-primary);
  font-size: var(--text-sm);
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
  outline: none;
  appearance: none;
}
.input:focus, .select:focus, textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-glow);
}
.input::placeholder, textarea::placeholder { color: var(--txt-muted); }
.input.error, .select.error { border-color: var(--danger); }
.input.error:focus { box-shadow: 0 0 0 3px rgba(239,68,68,.12); }

.input-with-icon { position: relative; }
.input-with-icon .input { padding-left: 36px; }
.input-with-icon .input-icon {
  position: absolute;
  left: var(--sp-3);
  top: 50%; transform: translateY(-50%);
  color: var(--txt-muted);
  font-size: 14px;
  pointer-events: none;
}
.input-with-icon .input-icon-right {
  left: auto;
  right: var(--sp-3);
  pointer-events: auto;
  cursor: pointer;
  transition: color var(--t-fast);
}
.input-with-icon .input-icon-right:hover { color: var(--txt-primary); }
.input-with-icon.has-icon-right .input { padding-right: 36px; }

select.select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%239ca3af' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right var(--sp-3) center;
  padding-right: 36px;
}

.form-hint {
  font-size: var(--text-xs);
  color: var(--txt-muted);
  margin-top: 2px;
}
.form-error {
  font-size: var(--text-xs);
  color: var(--danger);
  margin-top: 2px;
  display: flex;
  align-items: center;
  gap: 4px;
}

.checkbox-group {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  cursor: pointer;
}
.checkbox-group input[type="checkbox"] {
  width: 16px; height: 16px;
  border-radius: 4px;
  accent-color: var(--primary);
  cursor: pointer;
}
.checkbox-label { font-size: var(--text-sm); color: var(--txt-secondary); }

.toggle {
  position: relative;
  width: 40px; height: 22px;
  display: inline-block;
}
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
  position: absolute;
  inset: 0;
  background: var(--border-strong);
  border-radius: var(--radius-full);
  cursor: pointer;
  transition: background var(--t-base);
}
.toggle-slider::before {
  content: '';
  position: absolute;
  width: 16px; height: 16px;
  left: 3px; top: 3px;
  background: white;
  border-radius: 50%;
  transition: transform var(--t-base);
  box-shadow: var(--shadow-xs);
}
.toggle input:checked + .toggle-slider { background: var(--primary); }
.toggle input:checked + .toggle-slider::before { transform: translateX(18px); }

/* ─── TABLE ──────────────────────────────────────────────── */
.table-wrapper {
  overflow-x: auto;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  background: var(--bg-surface);
}
.table {
  width: 100%;
  font-size: var(--text-sm);
}
.table thead tr {
  border-bottom: 1px solid var(--border);
}
.table thead th {
  padding: var(--sp-3) var(--sp-4);
  text-align: left;
  font-size: var(--text-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--txt-muted);
  white-space: nowrap;
  background: var(--bg-subtle);
}
.table thead th:first-child { border-radius: var(--radius-lg) 0 0 0; }
.table thead th:last-child  { border-radius: 0 var(--radius-lg) 0 0; }
.table tbody tr {
  border-bottom: 1px solid var(--border);
  transition: background var(--t-fast);
}
.table tbody tr:last-child { border-bottom: none; }
.table tbody tr:hover { background: var(--bg-subtle); }
.table tbody td {
  padding: var(--sp-3) var(--sp-4);
  color: var(--txt-primary);
  vertical-align: middle;
}
.table tbody td.muted { color: var(--txt-muted); }
.table tbody td.amount-positive { color: var(--success); font-weight: 600; }
.table tbody td.amount-negative { color: var(--danger);  font-weight: 600; }
.table-actions { display: flex; align-items: center; gap: var(--sp-2); }

/* ─── MODAL ──────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: var(--z-modal);
  padding: var(--sp-4);
  opacity: 0;
  visibility: hidden;
  transition: opacity var(--t-base), visibility var(--t-base);
}
.modal-overlay.open { opacity: 1; visibility: visible; }
.modal {
  background: var(--bg-surface);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-xl);
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  transform: scale(.96) translateY(8px);
  transition: transform var(--t-spring);
}
.modal.modal-lg { max-width: 720px; }
.modal-overlay.open .modal { transform: scale(1) translateY(0); }
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--sp-5) var(--sp-6);
  border-bottom: 1px solid var(--border);
}
.modal-title {
  font-size: var(--text-lg);
  font-weight: 700;
  color: var(--txt-primary);
  letter-spacing: -.01em;
}
.modal-close {
  width: 30px; height: 30px;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--radius-sm);
  background: transparent;
  border: none;
  color: var(--txt-muted);
  cursor: pointer;
  transition: background var(--t-fast), color var(--t-fast);
}
.modal-close:hover { background: var(--bg-hover); color: var(--txt-primary); }
.modal-body {
  padding: var(--sp-6);
  overflow-y: auto;
  flex: 1;
}
.modal-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--sp-3);
  padding: var(--sp-4) var(--sp-6);
  border-top: 1px solid var(--border);
  background: var(--bg-subtle);
  border-radius: 0 0 var(--radius-xl) var(--radius-xl);
}

/* ─── TOAST ──────────────────────────────────────────────── */
.toast-container {
  position: fixed;
  top: var(--sp-5);
  right: var(--sp-5);
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
  pointer-events: none;
}
.toast {
  display: flex;
  align-items: flex-start;
  gap: var(--sp-3);
  padding: var(--sp-4);
  background: var(--bg-surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border);
  min-width: 280px;
  max-width: 380px;
  pointer-events: auto;
  animation: toastIn 280ms var(--t-spring) forwards;
}
.toast.hiding { animation: toastOut 200ms ease forwards; }

.toast-icon {
  width: 32px; height: 32px;
  border-radius: var(--radius-md);
  display: flex; align-items: center; justify-content: center;
  font-size: 14px;
  flex-shrink: 0;
}
.toast-success .toast-icon { background: var(--success-pale); color: #16a34a; }
.toast-danger  .toast-icon { background: var(--danger-pale);  color: #dc2626; }
.toast-warning .toast-icon { background: var(--warning-pale); color: #d97706; }
.toast-info    .toast-icon { background: var(--info-pale);    color: #2563eb; }

.toast-body { flex: 1; min-width: 0; }
.toast-title {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--txt-primary);
  margin-bottom: 2px;
}
.toast-msg {
  font-size: var(--text-xs);
  color: var(--txt-muted);
}
.toast-close {
  background: none; border: none;
  color: var(--txt-muted);
  cursor: pointer;
  padding: 2px;
  border-radius: var(--radius-xs);
  transition: color var(--t-fast);
}
.toast-close:hover { color: var(--txt-primary); }

/* ─── TABS ───────────────────────────────────────────────── */
.tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  margin-bottom: var(--sp-6);
  gap: 0;
}
.tab {
  padding: var(--sp-3) var(--sp-5);
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--txt-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: color var(--t-fast), border-color var(--t-fast);
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: var(--sp-2);
}
.tab:hover { color: var(--txt-secondary); }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ─── FILTER BAR ─────────────────────────────────────────── */
.filter-bar {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  flex-wrap: wrap;
  margin-bottom: var(--sp-5);
}
.filter-group {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
}
.filter-label {
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--txt-muted);
  white-space: nowrap;
  text-transform: uppercase;
  letter-spacing: .04em;
}
.filter-bar .input, .filter-bar .select {
  min-width: 0;
  width: auto;
}
.filter-divider { width: 1px; height: 24px; background: var(--border); margin: 0 var(--sp-2); }

/* ─── SEARCH INPUT ───────────────────────────────────────── */
.search-input {
  position: relative;
  flex: 1;
  min-width: 200px;
  max-width: 320px;
}
.search-input input {
  width: 100%;
  padding: 8px var(--sp-3) 8px 34px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-surface);
  color: var(--txt-primary);
  font-size: var(--text-sm);
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
  outline: none;
}
.search-input input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-glow); }
.search-input i {
  position: absolute;
  left: 10px; top: 50%; transform: translateY(-50%);
  color: var(--txt-muted);
  font-size: 13px;
  pointer-events: none;
}

/* ─── PAGINATION ─────────────────────────────────────────── */
.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--sp-4) var(--sp-5);
  border-top: 1px solid var(--border);
}
.pagination-info {
  font-size: var(--text-xs);
  color: var(--txt-muted);
}
.pagination-controls {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
}
.page-btn {
  width: 30px; height: 30px;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-surface);
  color: var(--txt-secondary);
  cursor: pointer;
  font-size: var(--text-xs);
  font-weight: 600;
  transition: background var(--t-fast), border-color var(--t-fast), color var(--t-fast);
}
.page-btn:hover { background: var(--bg-hover); border-color: var(--border-strong); }
.page-btn.active { background: var(--primary); border-color: var(--primary); color: white; }
.page-btn:disabled { opacity: .4; cursor: not-allowed; }

/* ─── SKELETON LOADING ───────────────────────────────────── */
.skeleton {
  background: linear-gradient(90deg, var(--bg-subtle) 25%, var(--bg-hover) 50%, var(--bg-subtle) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: var(--radius-sm);
}
.skeleton-text { height: 14px; margin-bottom: 6px; }
.skeleton-text.w-3\/4 { width: 75%; }
.skeleton-text.w-1\/2 { width: 50%; }
.skeleton-text.w-1\/4 { width: 25%; }
.skeleton-title { height: 22px; margin-bottom: 8px; }
.skeleton-kpi {
  height: 88px;
  border-radius: var(--radius-lg);
}
.skeleton-chart { height: 280px; border-radius: var(--radius-lg); }
.skeleton-row { height: 48px; margin-bottom: 1px; }

/* ─── CHART CONTAINERS ───────────────────────────────────── */
.chart-container {
  position: relative;
  width: 100%;
}
.chart-container canvas { display: block; }
.chart-legend {
  display: flex;
  align-items: center;
  gap: var(--sp-5);
  flex-wrap: wrap;
  margin-top: var(--sp-4);
}
.chart-legend-item {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  font-size: var(--text-xs);
  color: var(--txt-secondary);
  font-weight: 500;
}
.chart-legend-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
}

/* ─── EMPTY STATE ────────────────────────────────────────── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: var(--sp-16) var(--sp-8);
}
.empty-icon {
  width: 56px; height: 56px;
  border-radius: var(--radius-xl);
  background: var(--bg-subtle);
  display: flex; align-items: center; justify-content: center;
  font-size: 24px;
  color: var(--txt-muted);
  margin-bottom: var(--sp-4);
}
.empty-title {
  font-size: var(--text-lg);
  font-weight: 700;
  color: var(--txt-primary);
  margin-bottom: var(--sp-2);
}
.empty-desc { font-size: var(--text-sm); color: var(--txt-muted); max-width: 320px; margin-bottom: var(--sp-6); }

/* ─── ALERT BANNER ───────────────────────────────────────── */
.alert {
  display: flex;
  align-items: flex-start;
  gap: var(--sp-3);
  padding: var(--sp-4);
  border-radius: var(--radius-md);
  border: 1px solid;
  font-size: var(--text-sm);
}
.alert i { font-size: 15px; flex-shrink: 0; margin-top: 1px; }
.alert-success { background: var(--success-bg); border-color: #bbf7d0; color: #15803d; }
.alert-danger   { background: var(--danger-bg);  border-color: #fecaca; color: #b91c1c; }
.alert-warning  { background: var(--warning-bg); border-color: #fde68a; color: #b45309; }
.alert-info     { background: var(--info-bg);    border-color: #bfdbfe; color: #1d4ed8; }

/* ─── SECTION DIVIDER ────────────────────────────────────── */
.section-divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: var(--sp-5) 0;
}

/* ─── AVATAR ─────────────────────────────────────────────── */
.avatar {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: var(--primary-pale);
  color: var(--primary-dark);
  display: flex; align-items: center; justify-content: center;
  font-size: var(--text-sm);
  font-weight: 700;
  letter-spacing: -.01em;
  flex-shrink: 0;
}
.avatar-sm { width: 28px; height: 28px; font-size: var(--text-xs); }
.avatar-lg { width: 48px; height: 48px; font-size: var(--text-md); }

/* ─── DROPDOWN ───────────────────────────────────────────── */
.dropdown { position: relative; display: inline-block; }
.dropdown-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  min-width: 160px;
  z-index: var(--z-dropdown);
  padding: var(--sp-2) 0;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-4px);
  transition: opacity var(--t-base), visibility var(--t-base), transform var(--t-base);
}
.dropdown.open .dropdown-menu { opacity: 1; visibility: visible; transform: translateY(0); }
.dropdown-item {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: 8px var(--sp-4);
  font-size: var(--text-sm);
  color: var(--txt-secondary);
  cursor: pointer;
  transition: background var(--t-fast), color var(--t-fast);
}
.dropdown-item:hover { background: var(--bg-hover); color: var(--txt-primary); }
.dropdown-item.danger:hover { background: var(--danger-bg); color: var(--danger); }
.dropdown-divider { border-top: 1px solid var(--border); margin: var(--sp-2) 0; }

/* ─── CATEGORY COLORS ────────────────────────────────────── */
.cat-tag {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: var(--radius-full);
  font-size: var(--text-xs);
  font-weight: 600;
}
.cat-tag::before {
  content: '';
  width: 6px; height: 6px;
  border-radius: 50%;
  background: currentColor;
}

/* ─── AI INSIGHT CARDS ───────────────────────────────────── */
.insight-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--sp-4) var(--sp-5);
  display: flex;
  align-items: flex-start;
  gap: var(--sp-3);
  transition: box-shadow var(--t-base);
}
.insight-card:hover { box-shadow: var(--shadow-md); }
.insight-icon {
  width: 38px; height: 38px;
  border-radius: var(--radius-md);
  display: flex; align-items: center; justify-content: center;
  font-size: 17px;
  flex-shrink: 0;
}
.insight-card.alert .insight-icon   { background: var(--danger-pale); }
.insight-card.warning .insight-icon { background: var(--warning-pale); }
.insight-card.positive .insight-icon{ background: var(--success-pale); }
.insight-card.info .insight-icon    { background: var(--info-pale); }
.insight-body { flex: 1; }
.insight-title { font-size: var(--text-sm); font-weight: 700; color: var(--txt-primary); margin-bottom: 3px; }
.insight-desc  { font-size: var(--text-xs); color: var(--txt-muted); line-height: 1.5; }

/* ─── CHAT INTERFACE ─────────────────────────────────────── */
.chat-container {
  display: flex;
  flex-direction: column;
  height: 500px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  background: var(--bg-subtle);
}
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: var(--sp-5);
  display: flex;
  flex-direction: column;
  gap: var(--sp-4);
}
.chat-msg {
  display: flex;
  gap: var(--sp-3);
  max-width: 85%;
}
.chat-msg.user { align-self: flex-end; flex-direction: row-reverse; }
.chat-msg-avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px;
  font-weight: 700;
}
.chat-msg.user .chat-msg-avatar { background: var(--primary); color: white; }
.chat-msg.ai   .chat-msg-avatar { background: var(--navy); color: white; }
.chat-msg-bubble {
  padding: var(--sp-3) var(--sp-4);
  border-radius: var(--radius-lg);
  font-size: var(--text-sm);
  line-height: 1.6;
}
.chat-msg.user .chat-msg-bubble {
  background: var(--primary);
  color: white;
  border-radius: var(--radius-lg) var(--radius-sm) var(--radius-lg) var(--radius-lg);
}
.chat-msg.ai .chat-msg-bubble {
  background: var(--bg-surface);
  color: var(--txt-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm) var(--radius-lg) var(--radius-lg) var(--radius-lg);
}
.chat-input-bar {
  padding: var(--sp-3) var(--sp-4);
  border-top: 1px solid var(--border);
  background: var(--bg-surface);
  display: flex;
  gap: var(--sp-3);
}
.chat-input-bar input {
  flex: 1;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 9px var(--sp-3);
  font-size: var(--text-sm);
  outline: none;
  transition: border-color var(--t-fast);
  background: var(--bg-page);
}
.chat-input-bar input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-glow); }
.chat-typing {
  display: flex;
  gap: 4px;
  align-items: center;
  padding: var(--sp-2) var(--sp-3);
}
.chat-typing span {
  width: 6px; height: 6px;
  background: var(--txt-muted);
  border-radius: 50%;
  animation: typing 1.2s infinite;
}
.chat-typing span:nth-child(2) { animation-delay: .2s; }
.chat-typing span:nth-child(3) { animation-delay: .4s; }

/* ─── SETTINGS SECTION ───────────────────────────────────── */
.settings-section {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  margin-bottom: var(--sp-5);
}
.settings-section-header {
  padding: var(--sp-4) var(--sp-6);
  border-bottom: 1px solid var(--border);
  background: var(--bg-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.settings-section-title {
  font-size: var(--text-md);
  font-weight: 700;
  color: var(--txt-primary);
  display: flex;
  align-items: center;
  gap: var(--sp-3);
}
.settings-section-title i { color: var(--primary); }
.settings-section-body { padding: var(--sp-6); }
.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--sp-4) 0;
  border-bottom: 1px solid var(--border);
}
.settings-row:last-child { border-bottom: none; }
.settings-row-info { flex: 1; }
.settings-row-label { font-size: var(--text-sm); font-weight: 600; color: var(--txt-primary); }
.settings-row-desc  { font-size: var(--text-xs); color: var(--txt-muted); margin-top: 2px; }

/* ─── UTILITIES ──────────────────────────────────────────── */
.flex   { display: flex; }
.flex-col { display: flex; flex-direction: column; }
.items-center { align-items: center; }
.items-start  { align-items: flex-start; }
.justify-between { justify-content: space-between; }
.justify-center  { justify-content: center; }
.justify-end     { justify-content: flex-end; }
.flex-wrap { flex-wrap: wrap; }
.flex-1  { flex: 1; }
.gap-1   { gap: var(--sp-1); }
.gap-2   { gap: var(--sp-2); }
.gap-3   { gap: var(--sp-3); }
.gap-4   { gap: var(--sp-4); }
.gap-5   { gap: var(--sp-5); }
.gap-6   { gap: var(--sp-6); }
.mt-1    { margin-top: var(--sp-1); }
.mt-2    { margin-top: var(--sp-2); }
.mt-3    { margin-top: var(--sp-3); }
.mt-4    { margin-top: var(--sp-4); }
.mt-5    { margin-top: var(--sp-5); }
.mt-6    { margin-top: var(--sp-6); }
.mb-2    { margin-bottom: var(--sp-2); }
.mb-4    { margin-bottom: var(--sp-4); }
.mb-5    { margin-bottom: var(--sp-5); }
.mb-6    { margin-bottom: var(--sp-6); }
.ml-auto { margin-left: auto; }
.p-4     { padding: var(--sp-4); }
.p-5     { padding: var(--sp-5); }
.p-6     { padding: var(--sp-6); }
.w-full  { width: 100%; }
.hidden  { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); }
.text-xs   { font-size: var(--text-xs); }
.text-sm   { font-size: var(--text-sm); }
.text-base { font-size: var(--text-base); }
.text-lg   { font-size: var(--text-lg); }
.font-medium { font-weight: 500; }
.font-semibold { font-weight: 600; }
.font-bold { font-weight: 700; }
.text-muted { color: var(--txt-muted); }
.text-secondary { color: var(--txt-secondary); }
.text-primary-brand { color: var(--primary); }
.text-success { color: var(--success); }
.text-danger  { color: var(--danger); }
.text-warning { color: var(--warning); }
.text-right { text-align: right; }
.text-center { text-align: center; }
.truncate { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: var(--sp-5); }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--sp-5); }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--sp-4); }

/* ─── ANIMATIONS ─────────────────────────────────────────── */
@keyframes spin {
  to { transform: rotate(360deg); }
}
@keyframes shimmer {
  0%   { background-position: -200% 0; }
  100% { background-position:  200% 0; }
}
@keyframes toastIn {
  from { opacity: 0; transform: translateX(20px); }
  to   { opacity: 1; transform: translateX(0); }
}
@keyframes toastOut {
  from { opacity: 1; transform: translateX(0); }
  to   { opacity: 0; transform: translateX(20px); }
}
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes typing {
  0%, 80%, 100% { transform: scale(1);   opacity: .5; }
  40%           { transform: scale(1.2); opacity: 1;  }
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: .4; }
}

.animate-fade-in { animation: fadeIn 280ms ease forwards; }

/* ─── RESPONSIVE ─────────────────────────────────────────── */
@media (max-width: 1200px) {
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .grid-4   { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 900px) {
  :root { --sidebar-w: var(--sidebar-w-collapsed); }
  .sidebar-logo-text { display: none; }
  .nav-item span { display: none; }
  .sidebar-section-label { display: none; }
  .page-content { padding: var(--sp-4); }
}
@media (max-width: 640px) {
  .kpi-grid { grid-template-columns: 1fr 1fr; }
  .grid-3   { grid-template-columns: 1fr; }
  .grid-2   { grid-template-columns: 1fr; }
  .form-grid-2, .form-grid-3 { grid-template-columns: 1fr; }
  .page-header { flex-direction: column; align-items: flex-start; }
  .filter-bar { flex-direction: column; align-items: stretch; }
  .search-input { max-width: 100%; }
  .modal { max-height: 100vh; border-radius: var(--radius-lg) var(--radius-lg) 0 0; }
  .modal-overlay { align-items: flex-end; padding: 0; }
}
