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

:root,
[data-theme="dark"] {
  --bg:          #0F172A;
  --bg2:         #1E293B;
  --bg3:         #263348;
  --card:        #1E293B;
  --card-hover:  #263348;
  --border:      #334155;

  --accent:      #4C8DF0;
  --accent-solid:#4C8DF0;
  --accent-hover:#6FA6F5;
  --accent-dim:  rgba(76, 141, 240, 0.15);

  --receita:     #0B6E4F;
  --despesa:     #7F1D1D;
  --receita-bg:  rgba(11, 110, 79, 0.12);
  --despesa-bg:  rgba(127, 29, 29, 0.12);

    --val-positivo: #6BCB8F;
  --val-negativo: #F09595;
  --val-positivo-bg: rgba(107, 203, 143, 0.14);
  --val-negativo-bg: rgba(240, 149, 149, 0.14);

    --kpi-base-stripe:    #0F6E56;
  --kpi-comp-stripe:    #0876CC;
  --kpi-diffval-stripe: #B8790F;
  --kpi-diffpct-stripe: #6A3AA0;
  --kpi-base-badge:     #5DCAA5;
  --kpi-comp-badge:     #85B7EB;

  --text:        #F1F5F9;
  --text2:       #94A3B8;
  --text3:       #64748B;

  --shadow:      0 8px 24px rgba(0, 0, 0, 0.40);
  --shadow-sm:   0 2px 8px rgba(0, 0, 0, 0.25);
  --shadow-card: 0 1px 3px rgba(0, 0, 0, 0.30), 0 1px 2px rgba(0, 0, 0, 0.24);
  --radius:      12px;
  --sidebar-w:   220px;
  --sidebar-collapsed-w: 0px;

  --hover-bg:    rgba(255, 255, 255, 0.05);
  --topbar-bg:   rgba(15, 23, 42, 0.92);
  --scroll-thumb: #334155;
  --scroll-thumb-hover: #475569;
  --tfoot-bg:    #162032;
  --input-bg:    #0F172A;

  --chart-color: #60A5FA;

    --sidebar-bg:       #1E293B;
  --sidebar-border:   #334155;
  --sidebar-text:     #F1F5F9;
  --sidebar-text2:    #94A3B8;
  --sidebar-hover:    rgba(255, 255, 255, 0.06);
  --sidebar-input-bg: rgba(255,255,255,0.05);
  --sidebar-accent:   #4C8DF0;
  --sidebar-pill-active-bg: #4C8DF0;
  --sidebar-pill-active-c:  #fff;
}

[data-theme="light"] {
  --bg:          #F5F7FA;
  --bg2:         #EAEFF6;
  --bg3:         #DDE5F0;
  --card:        #FFFFFF;
  --card-hover:  #F4F7FB;
  --border:      #E2E8F0;

  --accent:      #0F52BA;
  --accent-solid:#0F52BA;
  --accent-hover:#0D47A1;
  --accent-dim:  rgba(15, 82, 186, 0.10);

  --receita:     #0B6E4F;
  --despesa:     #7F1D1D;
  --receita-bg:  rgba(11, 110, 79, 0.10);
  --despesa-bg:  rgba(127, 29, 29, 0.10);

    --val-positivo: #16803D;
  --val-negativo: #A32D2D;
  --val-positivo-bg: rgba(22, 128, 61, 0.10);
  --val-negativo-bg: rgba(163, 45, 45, 0.10);

    --kpi-base-stripe:    #0F6E56;
  --kpi-comp-stripe:    #0876CC;
  --kpi-diffval-stripe: #A8710F;
  --kpi-diffpct-stripe: #7A3FC0;
  --kpi-base-badge:     #0F6E56;
  --kpi-comp-badge:     #0876CC;

  --text:        #1A202C;
  --text2:       #6B7280;
  --text3:       #9CA3AF;

  --shadow:      0 8px 24px rgba(15, 82, 186, 0.10);
  --shadow-sm:   0 2px 8px rgba(15, 82, 186, 0.07);
  --shadow-card: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --radius:      12px;
  --sidebar-w:   220px;
  --sidebar-collapsed-w: 0px;

  --hover-bg:    rgba(15, 82, 186, 0.06);
  --topbar-bg:   rgba(255, 255, 255, 0.97);
  --scroll-thumb: #CBD5E1;
  --scroll-thumb-hover: #94A3B8;
  --tfoot-bg:    #EBF2FF;
  --input-bg:    #FFFFFF;

  --chart-color: #2563EB;

    --sidebar-bg:       #FFFFFF;
  --sidebar-border:   #E2E8F0;
  --sidebar-text:     #1A202C;
  --sidebar-text2:    #6B7280;
  --sidebar-hover:    rgba(15, 82, 186, 0.06);
  --sidebar-input-bg: #F5F7FA;
  --sidebar-accent:   #0F52BA;
  --sidebar-pill-active-bg: #0F52BA;
  --sidebar-pill-active-c:  #ffffff;
}

html { transition: background-color .3s ease; }
body, #sidebar, .top-bar, .kpi-card, .chart-card, .table-card, .login-card {
  transition: background-color .25s ease, border-color .25s ease, color .2s ease, box-shadow .2s ease;
}

html, body {
  height: 100%;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  line-height: 1.5;
  overflow-x: hidden;
}

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}

::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--scroll-thumb); border-radius: 6px; }
::-webkit-scrollbar-thumb:hover { background: var(--scroll-thumb-hover); }

button, select, input { font-family: inherit; }
button { cursor: pointer; background: none; border: none; color: inherit; font: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

#login-screen {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; padding: 24px; background: var(--bg);
  position: relative; overflow: hidden;
}

.login-bg-glow {
  position: absolute; top: 50%; left: 50%;
  width: 640px; height: 640px;
  transform: translate(-50%, -50%);
  background: radial-gradient(circle, var(--accent-dim) 0%, transparent 70%);
  pointer-events: none;
}

.login-card {
  width: 100%; max-width: 380px;
  background: var(--card); border: 1px solid var(--border);
  border-radius: 16px; padding: 44px 40px;
  box-shadow: var(--shadow);
  animation: fadeUp .5s ease;
  position: relative; z-index: 1;
}

.login-logo { text-align: center; margin-bottom: 28px; }
.login-mark {
  width: 46px; height: 46px; margin: 0 auto 14px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--accent-solid), var(--accent-hover));
  box-shadow: 0 6px 16px var(--accent-dim);
}
.login-logo .brand { font-size: 1.4rem; font-weight: 800; letter-spacing: 2px; color: var(--text); }
.login-card h1 { font-size: 1.1rem; font-weight: 600; margin-bottom: 8px; text-align: center; }
.login-card p  { font-size: .85rem; color: var(--text2); margin-bottom: 32px; text-align: center; }

.form-group { margin-bottom: 20px; }
.form-group label { display: block; font-size: .75rem; font-weight: 500; color: var(--text2); margin-bottom: 8px; letter-spacing: .5px; }

.input-with-icon { position: relative; display: flex; align-items: center; }
.input-with-icon .input-icon {
  position: absolute; left: 14px;
  color: var(--text3);
  pointer-events: none;
}

.form-group input {
  width: 100%; padding: 11px 14px 11px 40px; background: var(--input-bg);
  border: 1px solid var(--border); border-radius: 8px; color: var(--text);
  font-size: .9rem; transition: all .2s ease; outline: none;
}
.input-with-icon.has-toggle input { padding-right: 42px; }
.form-group input:hover { border-color: var(--text3); }
.form-group input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-dim); }
.form-group input:focus ~ .input-icon,
.input-with-icon:focus-within .input-icon { color: var(--accent-solid); }

.form-group input:-webkit-autofill,
.form-group input:-webkit-autofill:hover,
.form-group input:-webkit-autofill:focus {
  -webkit-text-fill-color: var(--text);
  caret-color: var(--text);
  -webkit-box-shadow: 0 0 0 1000px var(--input-bg) inset;
  box-shadow: 0 0 0 1000px var(--input-bg) inset;
  transition: background-color 9999s ease-in-out 0s;
}

.btn-toggle-pass {
  position: absolute; right: 8px;
  width: 28px; height: 28px;
  display: flex; align-items: center; justify-content: center;
  color: var(--text3); border-radius: 6px;
  transition: color .15s, background .15s;
}
.btn-toggle-pass:hover { color: var(--text2); background: var(--hover-bg); }

.btn-login {
  width: 100%; padding: 13px; background: var(--accent-solid); border: none;
  border-radius: 8px; color: #fff; font-size: .95rem; font-weight: 600;
  transition: filter .2s, transform .1s, box-shadow .2s; margin-top: 12px;
  box-shadow: 0 4px 14px var(--accent-dim);
}
.btn-login:hover { filter: brightness(1.08); box-shadow: 0 6px 18px var(--accent-dim); }
.btn-login:active { transform: scale(0.98); }
.login-error {
  margin-top: 16px; padding: 12px 16px; background: var(--despesa-bg);
  border: 1px solid var(--despesa); border-radius: 8px; font-size: .85rem;
  color: var(--despesa); display: none; text-align: center;
}

#app { display: none; height: 100vh; overflow: hidden; }
.layout { display: flex; height: 100%; position: relative; }

#sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--sidebar-bg);
  border-right: 1px solid var(--sidebar-border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  flex-shrink: 0;
    transition: width .28s cubic-bezier(0.4, 0, 0.2, 1),
              min-width .28s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 100;
  position: relative;
}

#sidebar.collapsed {
  width: 0;
  min-width: 0;
  border-right: none;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 16px 16px;
  border-bottom: 1px solid var(--sidebar-border);
  flex-shrink: 0;
  min-height: 64px;
  gap: 8px;
    overflow: hidden;
  white-space: nowrap;
}

.sidebar-brand-group {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  flex: 1;
  min-width: 0;
}

.sidebar-brand {
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: 1.5px;
  color: var(--sidebar-accent);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-sub {
  font-size: .6rem;
  color: var(--sidebar-text2);
  letter-spacing: 1px;
  text-transform: uppercase;
  white-space: nowrap;
  margin-top: 2px;
}

.sidebar-toggle {
  width: 28px;
  height: 28px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  background: transparent;
  border: 1px solid var(--sidebar-border);
  color: var(--sidebar-text2);
  transition: color .15s, background .15s, border-color .15s;
  padding: 0;
}
.sidebar-toggle:hover {
  color: var(--sidebar-accent);
  background: var(--sidebar-hover);
  border-color: var(--sidebar-accent);
}
.sidebar-toggle svg { width: 15px; height: 15px; display: block; }

.sidebar-content-scroll {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding-top: 14px;
  transition: opacity .2s ease;
}
#sidebar.collapsed .sidebar-content-scroll {
  opacity: 0;
  pointer-events: none;
}

.filter-group { padding: 0 16px 18px; }

.filter-group label,
.filter-group > span {
  display: block;
  font-size: .65rem;
  font-weight: 700;
  color: var(--sidebar-text2);
  margin-bottom: 6px;
  letter-spacing: .7px;
  text-transform: uppercase;
}

.filter-select {
  width: 100%;
  padding: 8px 10px;
  background: var(--sidebar-input-bg);
  border: 1px solid var(--sidebar-border);
  border-radius: 8px;
  color: var(--sidebar-text);
  font-size: .8rem;
  outline: none;
  cursor: pointer;
  transition: border-color .15s, box-shadow .15s;
  -webkit-appearance: none;
  appearance: none;
}
.filter-select:hover { border-color: var(--sidebar-accent); }
.filter-select:focus {
  border-color: var(--sidebar-accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}
.filter-select option { background: var(--bg2); color: var(--text); }

.filter-divider {
  height: 1px;
  background: var(--sidebar-border);
  margin: 0 16px 18px;
}

.nature-pills {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 5px;
  overflow: visible;
}

.pill {
  text-align: center;
  padding: 7px 4px;
  border-radius: 7px;
  font-size: .68rem;
  font-weight: 500;
  border: 1px solid var(--sidebar-border);
  background: transparent;
  color: var(--sidebar-text2);
  cursor: pointer;
  transition: all .15s;
  white-space: nowrap;
  overflow: visible;
  text-overflow: clip;
  min-width: 0;
  word-break: keep-all;
}
.pill:hover {
  border-color: var(--sidebar-accent);
  color: var(--sidebar-accent);
  background: var(--sidebar-hover);
}

.pill.active-all {
  background: var(--sidebar-pill-active-bg);
  border-color: var(--sidebar-pill-active-bg);
  color: var(--sidebar-pill-active-c);
  font-weight: 600;
}
.pill.active-receita {
  background: var(--receita);
  border-color: var(--receita);
  color: #fff;
  font-weight: 600;
}
.pill.active-despesa {
  background: var(--despesa);
  border-color: var(--despesa);
  color: #fff;
  font-weight: 600;
}

.filter-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 8px 16px 20px;
}
.filter-actions .btn-clear {
  margin: 0;
  flex: 1;
  padding: 8px;
  border: 1px solid var(--sidebar-border);
  border-radius: 8px;
  background: transparent;
  color: var(--sidebar-accent);
  font-size: .78rem;
  font-weight: 500;
  transition: all .15s ease;
}
.filter-actions .btn-clear:hover {
  background: var(--sidebar-hover);
  border-color: var(--sidebar-accent);
}

.filter-badge {
  font-size: .65rem;
  font-weight: 700;
  padding: 4px 8px;
  border-radius: 12px;
  background: var(--accent-dim);
  color: var(--sidebar-accent);
  border: 1px solid var(--sidebar-border);
  white-space: nowrap;
  letter-spacing: .3px;
}

.sidebar-footer {
  flex-shrink: 0;
  padding: 14px 16px;
  border-top: 1px solid var(--sidebar-border);
  display: flex;
  align-items: center;
  gap: 10px;
  overflow: hidden;
  white-space: nowrap;
}
#sidebar.collapsed .sidebar-footer {
  opacity: 0;
  pointer-events: none;
}

.user-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--accent-dim);
  border: 1px solid var(--sidebar-border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .75rem;
  font-weight: 700;
  color: var(--sidebar-accent);
  flex-shrink: 0;
}

.user-info { overflow: hidden; flex: 1; min-width: 0; }
.user-name {
  font-size: .78rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--sidebar-text);
}
.user-email {
  font-size: .67rem;
  color: var(--sidebar-text2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.btn-logout {
  background: none; border: none;
  color: var(--sidebar-text2);
  padding: 5px; border-radius: 7px;
  transition: color .15s, background .15s;
  flex-shrink: 0;
}
.btn-logout:hover { color: var(--despesa); background: var(--sidebar-hover); }

#btn-sidebar-open {
  position: static;
  width: 32px;
  height: 32px;
  display: none;              align-items: center;
  justify-content: center;
  border-radius: 7px;
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--text2);
  cursor: pointer;
  flex-shrink: 0;
  transition: color .15s, background .15s, border-color .15s;
}
#btn-sidebar-open:hover {
  color: var(--accent);
  border-color: var(--accent);
}
#btn-sidebar-open svg { width: 16px; height: 16px; display: block; }

.mobile-overlay {
  display: none; position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.55);
  backdrop-filter: blur(4px);
  z-index: 90;
}

#main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg);
  min-width: 0;
}

.top-bar {
  padding: 0 28px;
  height: 60px;
  background: var(--topbar-bg);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
  z-index: 10;
  flex-shrink: 0;
}

.mobile-sidebar-toggle {
  display: none;
  background: none; border: none;
  color: var(--text);
  font-size: 1.3rem;
  padding: 6px;
  border-radius: 8px;
  cursor: pointer;
  line-height: 1;
}
.mobile-sidebar-toggle:hover { background: var(--hover-bg); }

.top-bar h2 {
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: -0.3px;
  white-space: nowrap;
  color: var(--text);
}

.top-bar .period-badge {
  padding: 4px 12px;
  border-radius: 20px;
  background: var(--accent-dim);
  border: 1px solid var(--border);
  font-size: .72rem;
  font-weight: 600;
  color: var(--accent-solid);
  white-space: nowrap;
  letter-spacing: .3px;
}
[data-theme="dark"] .top-bar .period-badge { color: #7BB4F8; }

.topbar-left {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 12px; }

.error-banner {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--val-negativo-bg);
  border: 1px solid var(--val-negativo);
  color: var(--val-negativo);
  border-radius: var(--radius);
  padding: 12px 16px;
  margin-bottom: 16px;
  font-size: .82rem;
  font-weight: 600;
}
.error-banner svg { width: 18px; height: 18px; flex-shrink: 0; }

.btn-theme {
  background: var(--bg3); border: 1px solid var(--border); color: var(--text2);
  height: 32px; padding: 0 12px; border-radius: 8px;
  display: flex; align-items: center; justify-content: center; gap: 6px;
  flex-shrink: 0; transition: all .15s ease; white-space: nowrap;
}
.btn-theme:hover { color: var(--accent); border-color: var(--accent); background: var(--hover-bg); }
.btn-theme svg { width: 15px; height: 15px; flex-shrink: 0; }
.btn-theme .icon-sun { display: none; }
[data-theme="light"] .btn-theme .icon-moon { display: none; }
[data-theme="light"] .btn-theme .icon-sun  { display: block; }

.btn-theme .theme-label {
  font-size: .72rem;
  font-weight: 500;
  letter-spacing: .2px;
}

.content {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 24px 28px 48px;
  max-width: 1680px;
  margin: 0 auto;
  width: 100%;
}

.skeleton {
  background: linear-gradient(90deg, var(--bg3) 25%, var(--border) 50%, var(--bg3) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.6s infinite linear;
  border-radius: 4px;
  color: transparent !important;
}
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
  margin-bottom: 22px;
}

.kpi-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: flex; flex-direction: column;
  overflow: hidden;
  box-shadow: var(--shadow-card);
  min-width: 0;
  transition: transform .18s ease, box-shadow .18s ease;
}
.kpi-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.kpi-card.color-base:hover     { box-shadow: 0 8px 24px rgba(15, 110, 86, 0.20); }
.kpi-card.color-comp:hover     { box-shadow: 0 8px 24px rgba(8, 118, 204, 0.20); }
.kpi-card.color-diff-val:hover { box-shadow: 0 8px 24px rgba(184, 121, 15, 0.20); }
.kpi-card.color-diff-pct:hover { box-shadow: 0 8px 24px rgba(106, 58, 160, 0.20); }

.kpi-header {
  padding: 10px 16px;
  font-size: .82rem;
  font-weight: 700;
  color: #ffffff !important;
  letter-spacing: .3px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  text-transform: none;
  overflow-wrap: break-word;
  border-radius: calc(var(--radius) - 1px) calc(var(--radius) - 1px) 0 0;
  width: 100%;
}

.kpi-header .header-icon {
  width: 16px;
  height: 16px;
  opacity: 0.85;
  flex-shrink: 0;
}

.kpi-header span {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.kpi-card.color-base     .kpi-header { background: var(--kpi-base-stripe); }
.kpi-card.color-comp     .kpi-header { background: var(--kpi-comp-stripe); }
.kpi-card.color-diff-val .kpi-header { background: var(--kpi-diffval-stripe); }
.kpi-card.color-diff-pct .kpi-header { background: var(--kpi-diffpct-stripe); }

.kpi-value {
  padding: 16px 16px 4px;
  font-size: clamp(1.15rem, 3.2vw, 1.7rem);
  font-weight: 700;
  text-align: center;
  color: var(--text);
  letter-spacing: -0.5px;
  font-variant-numeric: tabular-nums;
  overflow-wrap: break-word;
  word-break: break-word;
  line-height: 1.15;
}

.kpi-card.color-diff-val .kpi-value,
.kpi-card.color-diff-pct .kpi-value {
  font-size: clamp(1.1rem, 3.2vw, 1.65rem);
}

.kpi-sub {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  font-size: .74rem;
  padding: 0 12px 14px;
  text-align: center;
  font-variant-numeric: tabular-nums;
  overflow-wrap: break-word;
}

.kpi-sub .sub-label {
  font-size: .67rem;
  color: var(--text3);
  font-weight: 500;
  letter-spacing: .3px;
}

.kpi-sub .sub-val {
  font-size: .88rem;
  font-weight: 600;
  color: var(--text);
}

.kpi-footer {
  padding: 10px 12px 10px;
  text-align: center;
  font-size: .8rem;
  font-weight: 700;
  background: transparent;
  border-top: 1px solid var(--border);
  letter-spacing: .5px;
  margin-top: auto;
  width: 100%;
}

.kpi-card.color-base .sub-val { color: var(--kpi-base-badge) !important; font-weight: 700; }
.kpi-card.color-base .kpi-footer { color: var(--kpi-base-badge) !important; font-weight: 700; }

.kpi-card.color-comp .sub-val { color: var(--kpi-comp-badge) !important; font-weight: 700; }
.kpi-card.color-comp .kpi-footer { color: var(--kpi-comp-badge) !important; font-weight: 700; }

.kpi-card.color-diff-val .sub-val,
.kpi-card.color-diff-pct .sub-val {
  font-weight: 700;
}

.kpi-card.color-diff-val .kpi-footer,
.kpi-card.color-diff-pct .kpi-footer {
  color: var(--text2);
}

.kpi-footer .foot-base { color: var(--kpi-base-badge) !important; font-weight: 700; }
.kpi-footer .foot-vs   { color: var(--text3); font-weight: 400; }
.kpi-footer .foot-comp { color: var(--kpi-comp-badge) !important; font-weight: 700; }

.val-bom {
  color: var(--val-positivo) !important;
  font-weight: 700;
}

.val-ruim {
  color: var(--val-negativo) !important;
  font-weight: 700;
}

.diff-neutral { color: var(--text2); }
.diff-bg-red   { background: rgba(127,29,29,0.10); }
.diff-bg-green { background: rgba(11,110,79,0.10); }

.pct-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 3px 10px;
  border-radius: 12px;
  font-size: .78rem;
  font-weight: 700;
  white-space: nowrap;
}
.pct-badge.val-bom {
  background: rgba(107, 203, 143, 0.15);
  color: var(--val-positivo) !important;
}
.pct-badge.val-ruim {
  background: rgba(240, 149, 149, 0.15);
  color: var(--val-negativo) !important;
}
[data-theme="light"] .pct-badge.val-bom {
  background: rgba(22, 128, 61, 0.10);
}
[data-theme="light"] .pct-badge.val-ruim {
  background: rgba(163, 45, 45, 0.10);
}

.projection-section {
  display: grid;
  grid-template-columns: minmax(240px, 0.37fr) minmax(400px, 1fr);
  gap: 16px;
  margin-bottom: 22px;
  align-items: stretch;
}

.projection-empty {
  display: none;
  align-items: center;
  gap: 16px;
  background: var(--card);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  padding: 20px 22px;
  margin-bottom: 22px;
}
.projection-empty-icon {
  width: 40px; height: 40px;
  border-radius: 50%;
  background: var(--bg3);
  color: var(--text3);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.projection-empty-icon svg { width: 20px; height: 20px; }
.projection-empty-text { min-width: 0; }
.projection-empty-title { font-size: .88rem; font-weight: 700; color: var(--text); margin-bottom: 3px; }
.projection-empty-desc { font-size: .78rem; color: var(--text3); line-height: 1.4; }

.projection-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: flex; flex-direction: column;
  overflow: hidden;
  box-shadow: var(--shadow-card);
  min-width: 0;
  transition: transform .18s ease, box-shadow .18s ease;
}
.projection-card:hover { transform: translateY(-2px); box-shadow: 0 8px 24px rgba(15, 110, 86, 0.20); }

.projection-header {
  padding: 12px 18px;
  font-size: .84rem;
  font-weight: 700;
  color: #ffffff !important;
  letter-spacing: .3px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: var(--kpi-base-stripe);
  border-radius: calc(var(--radius) - 1px) calc(var(--radius) - 1px) 0 0;
  width: 100%;
}
.projection-header span:first-child {
  flex: 1 1 auto;
  min-width: 0;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  line-height: 1.28;
}
.projection-header .mode-tag {
  font-size: .62rem;
  font-weight: 700;
  letter-spacing: .5px;
  text-transform: uppercase;
  padding: 3px 9px;
  border-radius: 10px;
  background: rgba(255,255,255,0.18);
  white-space: nowrap;
  flex-shrink: 0;
}
.projection-header .mode-tag.is-simulacao { background: var(--kpi-comp-stripe); }
.projection-header .header-icon { width: 17px; height: 17px; opacity: .85; flex-shrink: 0; align-self: flex-start; margin-top: 2px; }

.projection-value {
  padding: 22px 18px 4px;
  font-size: clamp(1.5rem, 3.2vw, 2.15rem);
  font-weight: 800;
  text-align: center;
  color: var(--kpi-base-badge);
  letter-spacing: -0.6px;
  font-variant-numeric: tabular-nums;
  overflow-wrap: break-word;
  word-break: break-word;
  line-height: 1.15;
}

.projection-sub {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  font-size: .78rem;
  padding: 0 14px 14px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}
.projection-sub .sub-label { font-size: .68rem; color: var(--text3); font-weight: 500; letter-spacing: .3px; }
.projection-sub .sub-val   { font-size: .92rem; font-weight: 700; color: var(--kpi-base-badge); }

.projection-breakdown {
  padding: 4px 18px 16px;
  display: flex;
  flex-direction: column;
  gap: 9px;
  flex: 1;
  justify-content: center;
}
.proj-bar {
  width: 100%;
  height: 6px;
  border-radius: 4px;
  background: var(--bg3);
  overflow: hidden;
}
.proj-bar-fill {
  height: 100%;
  border-radius: 4px;
  background: var(--kpi-base-badge);
  transition: width .4s ease;
}
.proj-breakdown-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.proj-mini {
  font-size: .72rem;
  color: var(--text2);
  display: flex;
  align-items: center;
  gap: 4px;
  min-width: 0;
}
.proj-mini strong { color: var(--text); font-weight: 700; }

.projection-footer {
  padding: 12px 16px;
  text-align: center;
  font-size: .78rem;
  font-weight: 600;
  color: var(--text2);
  border-top: 1px solid var(--border);
  margin-top: auto;
  width: 100%;
}

/* --- Gráfico de evolução acumulada (na mesma linha dos cards) --- */

.projection-chart {
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.projection-chart .chart-title { margin-bottom: 10px; }
.trend-legend {
  display: flex;
  gap: 18px;
  align-items: center;
  font-size: .72rem;
  color: var(--text2);
  margin-bottom: 10px;
  flex-shrink: 0;
  flex-wrap: wrap;
}
.trend-legend span { display: flex; align-items: center; gap: 6px; }
.trend-dot { width: 14px; height: 3px; border-radius: 2px; display: inline-block; }
.trend-dot.dashed { background: transparent; border-top: 2px dashed currentColor; height: 0; }
.trend-dot.dotted { background: transparent; border-top: 2px dotted currentColor; height: 0; }
.trend-chart-wrap {
  position: relative;
  width: 100%;
  flex: 1;
  min-height: 220px;
}

.charts-grid {
  display: grid;
  grid-template-columns: minmax(0,1fr) minmax(0,1fr);
  gap: 16px;
  margin-bottom: 22px;
}
.charts-grid .chart-full { grid-column: 1 / -1; }

.chart-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  min-width: 0; overflow: hidden;
  box-shadow: var(--shadow-card);
  transition: box-shadow .18s ease;
}
.chart-card:hover { box-shadow: var(--shadow); }

.chart-title {
  font-size: .88rem;
  font-weight: 600;
  margin-bottom: 16px;
  color: var(--text);
  overflow-wrap: break-word;
}
.chart-title .sub {
  display: none;
}

.chart-wrap-tall { position: relative; height: 295px; width: 100%; min-width: 0; }
.chart-wrap-tall canvas { max-width: 100%; }

.table-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 32px;
  box-shadow: var(--shadow-card);
}

.table-header {
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 16px;
}
.table-header h3 { font-size: .88rem; font-weight: 600; color: var(--text); }

.table-wrap { overflow-x: auto; max-height: 540px; overflow-y: auto; }

table { width: 100%; border-collapse: collapse; font-size: .83rem; }

th {
  padding: 10px 18px;
  font-size: .67rem;
  font-weight: 700;
  letter-spacing: .5px;
  text-transform: uppercase;
  color: #ffffff !important;
  background: #1e3a5f !important;
  position: sticky; top: 0; z-index: 2;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  text-align: center;
}
[data-theme="light"] th {
  background: #1e3a5f !important;
  color: #ffffff !important;
}

td {
  padding: 11px 18px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  text-align: center;
}

tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: var(--card-hover); }

.sticky-col { position: sticky; left: 0; background: var(--card); z-index: 1; }
tbody tr:hover td.sticky-col { background: var(--card-hover); }
thead th.sticky-col { z-index: 3; background: #1e3a5f !important; color: #ffffff !important; text-align: center; }

td[style*="text-align"] { text-align: center !important; }
th[style*="text-align"] { text-align: center !important; }

tfoot { position: sticky; bottom: 0; z-index: 2; }
tfoot td,
tfoot td.sticky-col {
  background: #1e3a5f !important;
  font-weight: 700 !important;
  color: #ffffff !important;
  border-top: 2px solid var(--border);
  padding: 11px 18px;
  font-variant-numeric: tabular-nums;
  text-align: center;
}

tfoot tr:hover td,
tfoot tr:hover td.sticky-col {
  background: #1e3a5f !important;
  color: #ffffff !important;
}

.empty-table { padding: 60px; text-align: center; color: var(--text3); font-size: .85rem; }

@keyframes fadeUp  { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
@keyframes pulse   { 0%, 100% { opacity: 1; transform: scale(1); } 50% { opacity: .4; transform: scale(.8); } }
.fade-in { animation: fadeUp .3s ease both; }

@media (max-width: 1200px) {
  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .charts-grid { grid-template-columns: minmax(0, 1fr); }
  .projection-section { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 768px) {
    .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .projection-section { gap: 10px; }
  .projection-header { padding: 10px 14px; font-size: .78rem; }
  .projection-header .header-icon { width: 15px; height: 15px; }
  .projection-value { font-size: 1.35rem !important; padding: 16px 12px 4px; }
  .projection-sub { font-size: .7rem; padding: 0 10px 14px; }
  .projection-sub .sub-val { font-size: .82rem; }
  .projection-footer { font-size: .7rem; padding: 9px 12px; }
  .trend-chart-wrap { min-height: 200px; }
  .mobile-sidebar-toggle { display: flex; align-items: center; justify-content: center; }
  #sidebar {
    position: absolute; left: -100%; height: 100%;
    transition: left 0.28s cubic-bezier(0.4,0,0.2,1), width .28s ease, min-width .28s ease;
    width: min(85vw, 260px); min-width: 0;
  }
  #sidebar.open { left: 0; box-shadow: 20px 0 50px rgba(0,0,0,0.45); }
  .mobile-overlay.open { display: block; }

  .top-bar {
    padding: 10px 14px;
    height: auto;
    min-height: 56px;
    gap: 8px 10px;
    flex-wrap: wrap;
    row-gap: 8px;
  }
  .top-bar h2 { font-size: .98rem; }
  .topbar-left { flex-wrap: nowrap; }
  .top-bar .period-badge { order: 3; width: 100%; text-align: center; box-sizing: border-box; }
  .topbar-right { margin-left: auto; }

  .content { padding: 14px 14px 40px; }

    .kpi-header { padding: 8px 10px; font-size: .68rem; }
  .kpi-header .header-icon { width: 13px; height: 13px; }
  .kpi-value { font-size: 1.05rem !important; padding: 10px 8px 2px; }
  .kpi-sub { font-size: .62rem; padding: 0 6px 10px; gap: 1px; }
  .kpi-sub .sub-val { font-size: .74rem; }
  .kpi-footer { font-size: .62rem; padding: 6px 8px; }

  .chart-card { padding: 14px; }
  .chart-title { margin-bottom: 12px; font-size: .84rem; }
  .chart-wrap-tall { height: 220px; }
  .charts-grid { gap: 12px; }

  th, td { padding: 9px 10px; }
  table { font-size: .78rem; }
  tfoot td, tfoot td.sticky-col { padding: 8px 10px; }
}

@media (max-width: 480px) {
  .kpi-grid { gap: 8px; }
  .kpi-value { font-size: .92rem !important; padding: 8px 6px 2px; }
  .kpi-sub { font-size: .58rem; padding: 0 4px 8px; }
  .kpi-sub .sub-val { font-size: .68rem; }
  .kpi-header { font-size: .6rem; padding: 8px 8px; }
  .kpi-header span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .kpi-footer { font-size: .6rem; padding: 6px; }
  .chart-wrap-tall { height: 190px; }
  .top-bar h2 { font-size: .9rem; }
  th, td { padding: 7px 8px; font-size: .7rem; }
  .table-header { padding: 10px 12px; }
  .content { padding: 10px 10px 36px; }
  .btn-theme .theme-label { display: none; }
}
