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

:root {
  --bg: #f5f5f0;
  --surface: #ffffff;
  --surface2: #f9f9f7;
  --border: #e4e4de;
  --text: #1a1a18;
  --muted: #71716b;
  --faint: #b5b5ae;
  --primary: #01696f;
  --primary-hover: #0c4e54;
  --primary-light: #e0eeec;
  --success: #437a22;
  --success-light: #dff0d2;
  --error: #c0392b;
  --error-light: #fce8e6;
  --warning: #b7651e;
  --warning-light: #fdeedd;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.07), 0 4px 12px rgba(0, 0, 0, 0.05);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.1), 0 2px 8px rgba(0, 0, 0, 0.06);
  --radius: 14px;
  --radius-sm: 8px;
  --font: 'Satoshi', system-ui, sans-serif;
}

[data-theme="dark"] {
  --bg: #171614;
  --surface: #1e1d1b;
  --surface2: #252422;
  --border: #302f2d;
  --text: #d4d3d0;
  --muted: #7a7975;
  --faint: #4a4946;
  --primary: #4f98a3;
  --primary-hover: #3d8490;
  --primary-light: #1e3335;
  --success: #6daa45;
  --success-light: #1e3315;
  --error: #e36b5b;
  --error-light: #3a1f1c;
  --warning: #e09354;
  --warning-light: #3a2813;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.25), 0 4px 12px rgba(0, 0, 0, 0.2);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.35), 0 2px 8px rgba(0, 0, 0, 0.2);
}

html {
  scroll-behavior: smooth;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  transition: background 0.25s, color 0.25s;
}

/* ─── LOGIN ─── */
#login-screen {
  min-height: 100dvh;
  display: grid;
  grid-template-columns: 1fr 1fr;
}

.login-left {
  background: var(--primary);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 48px;
  position: relative;
  overflow: hidden;
}

.login-left::before {
  content: '';
  position: absolute;
  width: 500px;
  height: 500px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.05);
  top: -120px;
  left: -100px;
  pointer-events: none;
}

.login-left::after {
  content: '';
  position: absolute;
  width: 320px;
  height: 320px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.04);
  bottom: -60px;
  right: -80px;
  pointer-events: none;
}

.login-brand {
  position: relative;
  z-index: 1;
}

.login-brand-logo {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 40px;
}

.brand-icon {
  width: 44px;
  height: 44px;
  background: rgba(255, 255, 255, 0.15);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.login-brand h1 {
  font-size: 22px;
  font-weight: 700;
  color: #fff;
}

.login-tagline {
  font-size: 32px;
  font-weight: 700;
  color: #fff;
  line-height: 1.25;
  max-width: 340px;
}

.login-tagline span {
  opacity: 0.6;
}

.login-features {
  position: relative;
  z-index: 1;
}

.login-feature {
  display: flex;
  align-items: center;
  gap: 12px;
  color: rgba(255, 255, 255, 0.75);
  font-size: 14px;
  margin-bottom: 14px;
}

.login-feature-dot {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.12);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.login-right {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 48px;
  background: var(--surface);
}

.login-box {
  width: 100%;
  max-width: 380px;
}

.login-box-title {
  font-size: 24px;
  font-weight: 700;
  margin-bottom: 6px;
}

.login-box-sub {
  font-size: 14px;
  color: var(--muted);
  margin-bottom: 32px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 16px;
}

.field label {
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
}

.input-wrap {
  position: relative;
}

.input-wrap input {
  width: 100%;
  background: var(--surface2);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 11px 14px;
  font-size: 14px;
  color: var(--text);
  font-family: var(--font);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.input-wrap input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(1, 105, 111, 0.1);
}

.input-wrap input.error-input {
  border-color: var(--error);
}

.input-wrap .eye-btn {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  cursor: pointer;
  color: var(--faint);
  display: flex;
  padding: 4px;
  transition: color 0.15s;
}

.input-wrap .eye-btn:hover {
  color: var(--muted);
}

.field-error {
  font-size: 12px;
  color: var(--error);
  margin-top: 2px;
  display: none;
}

.field-error.show {
  display: block;
}

.login-options {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 22px;
}

.remember {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
}

.remember input[type=checkbox] {
  accent-color: var(--primary);
  width: 15px;
  height: 15px;
  cursor: pointer;
}

.forgot-link {
  font-size: 13px;
  color: var(--primary);
  text-decoration: none;
  font-weight: 500;
}

.forgot-link:hover {
  text-decoration: underline;
}

.btn-login {
  width: 100%;
  padding: 13px;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  font-family: var(--font);
  transition: background 0.15s, transform 0.1s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.btn-login:hover {
  background: var(--primary-hover);
}

.btn-login:active {
  transform: scale(0.98);
}

.btn-login:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.login-error-box {
  background: var(--error-light);
  border: 1px solid rgba(192, 57, 43, 0.2);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-size: 13px;
  color: var(--error);
  margin-bottom: 16px;
  display: none;
  align-items: center;
  gap: 8px;
}

.login-error-box.show {
  display: flex;
}


.theme-float {
  position: fixed;
  top: 20px;
  right: 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px;
  cursor: pointer;
  color: var(--muted);
  display: flex;
  align-items: center;
  box-shadow: var(--shadow);
  transition: all 0.15s;
  z-index: 100;
}

.theme-float:hover {
  color: var(--text);
  background: var(--surface2);
}

/* ─── APP ─── */
#app-screen {
  display: none;
}

.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  height: 100%;
  width: 220px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: 10;
  padding: 24px 0;
  transition: background 0.25s, border-color 0.25s;
}

.sidebar-logo {
  padding: 0 20px 20px;
  border-bottom: 1px solid var(--border);
}

.sidebar-logo h1 {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  line-height: 1.2;
}

.sidebar-logo p {
  font-size: 12px;
  color: var(--muted);
  margin-top: 3px;
}

.sidebar-nav {
  padding: 16px 12px;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.nav-section {
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--faint);
  font-weight: 600;
  padding: 12px 8px 6px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  color: var(--muted);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
  transition: all 0.15s;
}

.nav-item:hover {
  background: var(--surface2);
  color: var(--text);
}

.nav-item.active {
  background: var(--primary-light);
  color: var(--primary);
  font-weight: 600;
}

.main {
  margin-left: 220px;
  padding: 32px;
  min-height: 100vh;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 28px;
}

.topbar-title {
  font-size: 20px;
  font-weight: 700;
}

.topbar-sub {
  font-size: 13px;
  color: var(--muted);
  margin-top: 2px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 9px 16px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  border: none;
  cursor: pointer;
  font-family: var(--font);
  transition: all 0.15s;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}

.btn-primary:hover {
  background: var(--primary-hover);
}

.btn-ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
}

.btn-ghost:hover {
  background: var(--surface2);
  color: var(--text);
}

.btn-danger {
  background: var(--error-light);
  color: var(--error);
  border: 1px solid rgba(192, 57, 43, 0.15);
}

.btn-danger:hover {
  background: var(--error);
  color: #fff;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin-bottom: 24px;
}

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

.kpi-label {
  font-size: 12px;
  color: var(--muted);
  font-weight: 500;
}

.kpi-value {
  font-size: 24px;
  font-weight: 700;
  margin-top: 6px;
  font-variant-numeric: tabular-nums;
}

.kpi-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 99px;
  margin-top: 8px;
}

.badge-green {
  background: var(--success-light);
  color: var(--success);
}

.badge-red {
  background: var(--error-light);
  color: var(--error);
}

.badge-orange {
  background: var(--warning-light);
  color: var(--warning);
}

.badge-gray {
  background: var(--surface2);
  color: var(--muted);
  border: 1px solid var(--border);
}

.badge-blue {
  background: var(--primary-light);
  color: var(--primary);
}

.grid-3 {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 16px;
  margin-bottom: 24px;
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 24px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: var(--shadow);
}

.card-title {
  font-size: 14px;
  font-weight: 700;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.card-title span {
  color: var(--muted);
  font-weight: 500;
  font-size: 12px;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--faint);
  font-weight: 600;
  text-align: left;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
}

td {
  font-size: 13px;
  padding: 11px 12px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  vertical-align: middle;
}

tr:last-child td {
  border-bottom: none;
}

tr:hover td {
  background: var(--surface2);
}

.td-muted {
  color: var(--muted);
}

.td-amount-in {
  color: var(--success);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.td-amount-out {
  color: var(--error);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.progress-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.progress-label {
  font-size: 13px;
  flex: 1;
}

.progress-bar-bg {
  flex: 2;
  height: 6px;
  background: var(--border);
  border-radius: 99px;
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  border-radius: 99px;
  background: var(--primary);
}

.progress-value {
  font-size: 13px;
  font-weight: 600;
  min-width: 70px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.form-full {
  grid-column: 1 / -1;
}

.form-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-field label {
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
}

.form-field input,
.form-field select {
  background: var(--surface2);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 14px;
  color: var(--text);
  font-family: var(--font);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.form-field input:focus,
.form-field select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(1, 105, 111, 0.1);
}

.pill-toggle {
  display: flex;
  background: var(--surface2);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  overflow: hidden;
}

.pill-toggle button {
  flex: 1;
  padding: 9px;
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
  background: none;
  border: none;
  cursor: pointer;
  font-family: var(--font);
  transition: all 0.15s;
}

.pill-toggle button.on {
  background: var(--primary);
  color: #fff;
  font-weight: 600;
}

.pill-large button {
  padding: 12px;
  font-size: 15px;
}

.input-valor-destaque {
  font-size: 28px !important;
  font-weight: 700;
  text-align: center;
  padding: 16px !important;
  color: var(--primary) !important;
  background: var(--primary-light) !important;
  border: 2px solid transparent !important;
  border-radius: var(--radius) !important;
}

.input-valor-destaque:focus {
  border-color: var(--primary) !important;
  box-shadow: 0 0 0 4px rgba(1, 105, 111, 0.15) !important;
}

[data-theme="dark"] .input-valor-destaque {
  background: #39383D !important;
  color: #fff !important;
}

[data-theme="dark"] .input-valor-destaque:focus {
  border-color: #481A43 !important;
  box-shadow: 0 0 0 4px rgba(72, 26, 67, 0.4) !important;
}

[data-theme="dark"] .pill-toggle button.on {
  background: #481A43;
  color: #fff;
}

.divider {
  height: 1px;
  background: var(--border);
  margin: 20px 0;
}

.month-nav {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 12px;
  font-size: 13px;
  font-weight: 600;
}

.month-nav button {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--muted);
  display: flex;
  padding: 0;
}

.month-nav button:hover {
  color: var(--text);
}

.theme-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 7px;
  cursor: pointer;
  color: var(--muted);
  display: flex;
  align-items: center;
  transition: all 0.15s;
}

.theme-btn:hover {
  background: var(--surface2);
  color: var(--text);
}

.page {
  display: none;
}

.page.active {
  display: block;
}

/* ─── PERIOD SELECTOR ─── */
.period-selector {
  position: absolute;
  top: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 16px;
  box-shadow: var(--shadow-lg);
  width: 240px;
  z-index: 100;
}

.period-header {
  font-size: 13px;
  font-weight: 700;
  margin-bottom: 12px;
}

.period-options {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 16px;
}

.period-options label {
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  color: var(--text);
}

.period-inputs {
  display: none;
  flex-direction: column;
  gap: 8px;
}

.period-inputs.active {
  display: flex;
}

.form-input {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  font-size: 13px;
  color: var(--text);
  font-family: var(--font);
  outline: none;
  width: 100%;
}

.btn-block {
  width: 100%;
  justify-content: center;
}

/* spinner */
.spinner {
  width: 18px;
  height: 18px;
  border: 2.5px solid rgba(255, 255, 255, 0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* user chip */
.user-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px 10px 20px;
  border-top: 1px solid var(--border);
}

.user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  flex-shrink: 0;
}

.user-name {
  font-size: 13px;
  font-weight: 600;
}

.user-role {
  font-size: 11px;
  color: var(--muted);
}

.logout-btn {
  margin-left: auto;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--faint);
  padding: 4px;
  display: flex;
  transition: color 0.15s;
}

.logout-btn:hover {
  color: var(--error);
}

::-webkit-scrollbar {
  width: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 99px;
}

@media (max-width: 768px) {
  #login-screen {
    grid-template-columns: 1fr;
  }

  .login-left {
    display: none;
  }

  /* Responsive Dashboard */
  .sidebar {
    transform: translateX(-100%);
    transition: transform 0.3s;
    width: 260px;
    box-shadow: var(--shadow-lg);
  }
  .sidebar.open {
    transform: translateX(0);
  }
  .main {
    margin-left: 0;
    padding: 16px;
  }
  .topbar {
    flex-direction: column;
    align-items: flex-start;
    gap: 16px;
  }
  .topbar-actions {
    width: 100%;
    flex-wrap: wrap;
    justify-content: space-between;
  }
  .month-nav {
    width: 100%;
    justify-content: space-between;
  }
  .kpi-grid, .grid-3, .grid-2, .form-grid {
    grid-template-columns: 1fr;
  }
  .card-title {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }
  table {
    display: block;
    overflow-x: auto;
    white-space: nowrap;
  }
  .mobile-header {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 24px;
  }
  .mobile-menu-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 8px;
    cursor: pointer;
    color: var(--text);
  }
}

@media (min-width: 769px) {
  .mobile-menu-btn, .mobile-header {
    display: none;
  }
}

/* ─── PRINT (EXPORTAR PDF) ─── */
@media print {
  body {
    background: #fff !important;
    color: #000 !important;
  }
  .sidebar, .topbar-actions, .theme-float, .mobile-header {
    display: none !important;
  }
  .main {
    margin-left: 0 !important;
    padding: 0 !important;
  }
  .card, .kpi-card {
    border: 1px solid #ddd !important;
    box-shadow: none !important;
    break-inside: avoid;
    margin-bottom: 20px;
  }
  .progress-bar {
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
  .kpi-value, .progress-value, span[style*="color"] {
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
}