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

html { font-size: var(--font-size-base); }

body {
  font-family: var(--font-family);
  background: var(--bg-app);
  color: var(--color-text);
  line-height: 1.5;
  min-height: 100vh;
}

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

.sidebar {
  width: 200px;
  flex-shrink: 0;
  background: var(--bg-app);
  border-right: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
}

.sidebar-logo {
  padding: 24px 20px 16px;
  font-size: 1.1rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--color-text);
  border-bottom: 1px solid var(--color-border);
}

.sidebar-logo span {
  color: var(--color-primary);
}

.sidebar-nav {
  flex: 1;
  padding: 16px 0;
  overflow-y: auto;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 20px;
  color: var(--color-muted);
  text-decoration: none;
  font-size: 0.9rem;
  transition: color 0.15s, background 0.15s;
  border-radius: 0;
}

.nav-item:hover,
.nav-item.active {
  color: var(--color-text);
  background: var(--bg-card);
}

.nav-item.active {
  border-left: 2px solid var(--color-primary);
  padding-left: 18px;
}

.nav-icon {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  opacity: 0.7;
}

.nav-item.active .nav-icon,
.nav-item:hover .nav-icon { opacity: 1; }

.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--color-border);
  font-size: 0.8rem;
}

.sidebar-user {
  color: var(--color-text);
  font-weight: 500;
  margin-bottom: 4px;
}

.sidebar-email {
  color: var(--color-muted);
  margin-bottom: 10px;
  word-break: break-all;
}

.main {
  margin-left: 200px;
  flex: 1;
  min-width: 0;
}

.page {
  padding: 32px;
  max-width: 1100px;
}

/* ── Page header ── */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 28px;
  gap: 16px;
}

.page-title {
  font-size: 1.3rem;
  font-weight: 600;
  letter-spacing: -0.02em;
}

/* ── Cards ── */
.card {
  background: var(--bg-card);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 20px;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 28px;
}

.kpi {
  background: var(--bg-card);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 18px 20px;
}

.kpi-label {
  font-size: 0.75rem;
  color: var(--color-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 6px;
}

.kpi-value {
  font-size: 1.5rem;
  font-weight: 600;
  letter-spacing: -0.03em;
}

.kpi-value.income  { color: var(--color-success); }
.kpi-value.expense { color: var(--color-danger);  }
.kpi-value.net     { color: var(--color-primary); }

/* ── Chart ── */
.chart-wrap {
  background: var(--bg-card);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 28px;
}

.chart-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.chart-title {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--color-muted);
}

/* ── View toggle ── */
.toggle-group {
  display: inline-flex;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  overflow: hidden;
}

.toggle-btn {
  padding: 6px 14px;
  font-size: 0.8rem;
  background: transparent;
  color: var(--color-muted);
  border: none;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

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

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  font-size: 0.85rem;
  font-weight: 500;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: transparent;
  color: var(--color-text);
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s, border-color 0.15s;
}

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

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

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

.btn-danger {
  background: transparent;
  border-color: var(--color-danger);
  color: var(--color-danger);
}

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

.btn-ghost {
  border-color: transparent;
  color: var(--color-muted);
}

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

.btn-sm { padding: 4px 10px; font-size: 0.78rem; }

/* ── Table ── */
.table-wrap {
  background: var(--bg-card);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  overflow: hidden;
}

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

thead th {
  padding: 10px 16px;
  text-align: left;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--color-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid var(--color-border);
  background: var(--bg-app);
}

tbody tr { border-bottom: 1px solid var(--color-border); }
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: rgba(255,255,255,0.02); }

td {
  padding: 11px 16px;
  vertical-align: middle;
}

.text-right { text-align: right; }
.text-muted  { color: var(--color-muted); }

/* ── Badges ── */
.badge {
  display: inline-block;
  padding: 2px 8px;
  font-size: 0.72rem;
  font-weight: 500;
  border-radius: 20px;
  border: 1px solid currentColor;
}

.badge-success { color: var(--color-success); }
.badge-danger  { color: var(--color-danger);  }
.badge-warning { color: var(--color-warning); }
.badge-muted   { color: var(--color-muted);   }
.badge-primary { color: var(--color-primary); }

/* ── Forms ── */
.form-group { margin-bottom: 16px; }

label {
  display: block;
  font-size: 0.8rem;
  color: var(--color-muted);
  margin-bottom: 5px;
}

input, select, textarea {
  width: 100%;
  padding: 8px 12px;
  background: var(--bg-input);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  color: var(--color-text);
  font-family: var(--font-family);
  font-size: 0.88rem;
  transition: border-color 0.15s;
  outline: none;
  box-shadow: none;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--color-primary);
  box-shadow: none;
}

select {
  appearance: none;
  -webkit-appearance: none;
  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='%238b949e' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 32px;
  cursor: pointer;
}

select option {
  background: var(--bg-card);
  color: var(--color-text);
  box-shadow: none;
}

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

.form-note {
  font-size: 0.78rem;
  color: var(--color-muted);
  margin-top: 4px;
}

/* ── Modal ── */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 200;
  align-items: center;
  justify-content: center;
}

.modal-overlay.open { display: flex; }

.modal {
  background: var(--bg-card);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 24px;
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.modal-title {
  font-size: 1rem;
  font-weight: 600;
}

.modal-close {
  background: none;
  border: none;
  color: var(--color-muted);
  cursor: pointer;
  padding: 2px;
  line-height: 1;
  font-size: 1.2rem;
}

.modal-close:hover { color: var(--color-text); }

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 20px;
}

/* ── Amortization table ── */
.amort-modal { max-width: 680px; }

/* ── Toast ── */
#toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  padding: 10px 16px;
  border-radius: var(--radius);
  font-size: 0.85rem;
  background: var(--bg-card);
  border: 1px solid var(--color-border);
  color: var(--color-text);
  animation: slide-in 0.2s ease;
}

.toast.success { border-color: var(--color-success); color: var(--color-success); }
.toast.error   { border-color: var(--color-danger);  color: var(--color-danger);  }

@keyframes slide-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── Tema page ── */
.tema-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
}

.color-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px solid var(--color-border);
}

.color-row:last-child { border-bottom: none; }

.color-label { font-size: 0.85rem; }

.color-input-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.color-swatch {
  width: 28px;
  height: 28px;
  border-radius: 4px;
  border: 1px solid var(--color-border);
  padding: 0;
  cursor: pointer;
  overflow: hidden;
}

.color-hex {
  width: 90px;
  font-size: 0.82rem;
  font-family: monospace;
  padding: 5px 8px;
}

.range-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px solid var(--color-border);
}

.range-row:last-child { border-bottom: none; }

input[type=range] {
  width: 140px;
  accent-color: var(--color-primary);
  padding: 0;
  border: none;
  background: transparent;
}

.range-value {
  font-size: 0.82rem;
  color: var(--color-muted);
  min-width: 36px;
  text-align: right;
  font-family: monospace;
}

/* ── Login ── */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.login-card {
  background: var(--bg-card);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 36px 32px;
  width: 100%;
  max-width: 360px;
}

.login-logo {
  font-size: 1.4rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  margin-bottom: 28px;
  color: var(--color-text);
}

.login-logo span { color: var(--color-primary); }

.login-error {
  font-size: 0.82rem;
  color: var(--color-danger);
  margin-bottom: 12px;
}

/* ── Empty state ── */
.empty {
  padding: 48px 24px;
  text-align: center;
  color: var(--color-muted);
  font-size: 0.88rem;
}

/* ── Divider ── */
.divider { border: none; border-top: 1px solid var(--color-border); margin: 20px 0; }

/* ── Utility ── */
.flex { display: flex; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.mt-4 { margin-top: 4px; }
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mb-16 { margin-bottom: 16px; }
.w-full { width: 100%; }
.hidden { display: none; }

/* ── Responsive ── */
@media (max-width: 768px) {
  .sidebar { display: none; }
  .sidebar.open { display: flex; }
  .main { margin-left: 0; }
  .page { padding: 20px 16px; }
  .kpi-grid { grid-template-columns: 1fr 1fr; }
  .form-row { grid-template-columns: 1fr; }
  .tema-grid { grid-template-columns: 1fr; }
  .mobile-menu-btn { display: flex; }
}

.mobile-menu-btn {
  display: none;
  position: fixed;
  top: 12px; left: 12px;
  z-index: 150;
  background: var(--bg-card);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 8px;
  cursor: pointer;
}
