/* ============================================
   FinanzasPro SaaS - Estilos base
   ============================================ */

:root {
  --color-primary: #6366f1;
  --color-primary-dark: #4f46e5;
  --color-success: #10b981;
  --color-danger: #ef4444;
  --color-warning: #f59e0b;

  --bg-light: #f8fafc;
  --bg-card: #ffffff;
  --text-primary: #1e293b;
  --text-secondary: #64748b;
  --border-color: #e2e8f0;

  --radius: 12px;
  --shadow: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --bottom-nav-height: 68px;
}

[data-theme="dark"] {
  --bg-light: #0f172a;
  --bg-card: #1e293b;
  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --border-color: #334155;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg-light);
  color: var(--text-primary);
  transition: background 0.2s, color 0.2s;
}

/* ============ LAYOUT ============ */
.app-container {
  display: flex;
  min-height: 100vh;
}

/* ============ SIDEBAR (desktop) ============ */
.sidebar {
  width: 240px;
  background: var(--bg-card);
  border-right: 1px solid var(--border-color);
  padding: 24px 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.sidebar .logo {
  font-size: 20px;
  font-weight: 700;
  color: var(--color-primary);
  margin-bottom: 24px;
  padding: 0 8px;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: var(--radius);
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
}

.nav-link:hover, .nav-link.active {
  background: var(--color-primary);
  color: white;
}

.nav-link .nav-emoji { font-size: 18px; }

.sidebar-bottom {
  margin-top: auto;
  padding-top: 12px;
  border-top: 1px solid var(--border-color);
}

/* ============ MAIN CONTENT ============ */
.main-content {
  flex: 1;
  padding: 24px 32px;
  overflow-y: auto;
}

/* ============ BOTTOM NAV (mobile) ============ */
.bottom-nav {
  display: none;
}

/* ============ CARDS ============ */
.card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border-color);
  margin-bottom: 16px;
}

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

.stat-card h3 {
  font-size: 13px;
  color: var(--text-secondary);
  font-weight: 500;
  margin-bottom: 8px;
}

.stat-card .value {
  font-size: 28px;
  font-weight: 700;
}

.stat-card .value.income  { color: var(--color-success); }
.stat-card .value.expense { color: var(--color-danger); }
.stat-card .value.balance { color: var(--color-primary); }

/* ============ CHARTS ============ */
.charts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.chart-container {
  height: 260px;
  position: relative;
}

/* ============ BUTTONS ============ */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 18px;
  border-radius: var(--radius);
  border: none;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.1s;
}

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

.btn-primary   { background: var(--color-primary); color: white; }
.btn-primary:hover { background: var(--color-primary-dark); }
.btn-secondary { background: var(--bg-light); color: var(--text-primary); border: 1px solid var(--border-color); }
.btn-danger    { background: var(--color-danger); color: white; }
.btn-success   { background: var(--color-success); color: white; }

/* ============ FORMS ============ */
.form-group { margin-bottom: 16px; }

.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  margin-bottom: 6px;
  color: var(--text-secondary);
}

.form-control {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  font-size: 14px;
  background: var(--bg-card);
  color: var(--text-primary);
}

.form-control:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(99,102,241,0.1);
}

/* ============ TRANSACTION ITEMS ============ */
.transaction-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0;
  border-bottom: 1px solid var(--border-color);
  gap: 8px;
}

.transaction-item:last-child { border-bottom: none; }

.transaction-icon {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  margin-right: 12px;
  flex-shrink: 0;
}

/* ============ PROGRESS BARS ============ */
.progress-bar {
  width: 100%;
  height: 8px;
  background: var(--border-color);
  border-radius: 4px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  border-radius: 4px;
  transition: width 0.4s ease;
}

/* ============ TOASTS ============ */
.toast {
  position: fixed;
  bottom: 90px;
  right: 16px;
  background: var(--text-primary);
  color: var(--bg-card);
  padding: 12px 20px;
  border-radius: var(--radius);
  font-size: 14px;
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 0.3s, transform 0.3s;
  z-index: 2000;
  max-width: 300px;
}

.toast.show      { opacity: 1; transform: translateY(0); }
.toast-error     { background: var(--color-danger); }
.toast-success   { background: var(--color-success); }

/* ============ MODALS ============ */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  align-items: center;
  justify-content: center;
  z-index: 999;
  padding: 16px;
}

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

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

.modal-box h3 { margin-bottom: 16px; font-size: 18px; }

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

/* ============ TYPE TOGGLE ============ */
.type-toggle {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}

.type-toggle button {
  flex: 1;
  padding: 10px;
  border-radius: var(--radius);
  border: 1px solid var(--border-color);
  background: var(--bg-light);
  cursor: pointer;
  font-weight: 600;
  color: var(--text-secondary);
  transition: all 0.15s;
}

.type-toggle button.active.income  { background: var(--color-success); color: white; border-color: var(--color-success); }
.type-toggle button.active.expense { background: var(--color-danger);  color: white; border-color: var(--color-danger); }
.type-toggle button.active.transfer{ background: var(--color-primary); color: white; border-color: var(--color-primary);}

/* ============ HEADER ROW ============ */
.header-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  flex-wrap: wrap;
  gap: 12px;
}

.header-row h1 { font-size: 22px; font-weight: 700; }

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

.month-selector { display: flex; align-items: center; gap: 8px; font-size: 14px; font-weight: 600; }
.month-selector button {
  background: none;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 6px 10px;
  cursor: pointer;
  color: var(--text-primary);
  font-size: 16px;
}

.theme-toggle {
  background: none;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 8px 12px;
  cursor: pointer;
  font-size: 16px;
}

/* ============ VIEWS ============ */
.view { display: none; }
.view.active { display: block; }

/* ============ EMPTY STATE ============ */
.empty-state {
  text-align: center;
  padding: 48px 20px;
  color: var(--text-secondary);
}

.empty-state .empty-icon { font-size: 48px; margin-bottom: 12px; }
.empty-state p { font-size: 15px; }

/* ============ SETTINGS SECTIONS ============ */
.settings-section {
  background: var(--bg-card);
  border-radius: var(--radius);
  border: 1px solid var(--border-color);
  overflow: hidden;
  margin-bottom: 20px;
}

.settings-section-title {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-secondary);
  padding: 14px 20px 8px;
}

.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border-color);
  cursor: pointer;
  gap: 12px;
  transition: background 0.15s;
}

.settings-row:last-child { border-bottom: none; }
.settings-row:hover { background: var(--bg-light); }

.settings-row-left { display: flex; align-items: center; gap: 12px; }
.settings-row-icon { font-size: 20px; width: 32px; text-align: center; }
.settings-row-label { font-size: 15px; font-weight: 500; }
.settings-row-sub   { font-size: 12px; color: var(--text-secondary); margin-top: 2px; }
.settings-row-right { color: var(--text-secondary); font-size: 18px; }

/* ============ ACCOUNT CARD ============ */
.account-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 20px;
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow);
}

.account-card .acct-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 12px;
}

.account-card .acct-name { font-weight: 700; font-size: 16px; }
.account-card .acct-type { font-size: 12px; color: var(--text-secondary); margin-top: 2px; }
.account-card .acct-balance { font-size: 26px; font-weight: 800; margin-top: 8px; }
.account-card .acct-actions { display: flex; gap: 8px; margin-top: 12px; }

/* ============ FAB (mobile add button) ============ */
.fab {
  display: none;
  position: fixed;
  bottom: calc(var(--bottom-nav-height) + 16px);
  right: 20px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--color-primary);
  color: white;
  border: none;
  font-size: 28px;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(99,102,241,0.4);
  z-index: 100;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s;
}

.fab:active { transform: scale(0.93); }

/* ============ RESPONSIVE — MOBILE ============ */
@media (max-width: 768px) {
  .sidebar { display: none; }

  .main-content {
    padding: 16px 16px calc(var(--bottom-nav-height) + 16px);
    width: 100%;
  }

  /* Bottom navigation bar */
  .bottom-nav {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: var(--bottom-nav-height);
    background: var(--bg-card);
    border-top: 1px solid var(--border-color);
    z-index: 200;
    padding: 0 4px;
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }

  .bottom-nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    padding: 6px 2px;
    cursor: pointer;
    border: none;
    background: none;
    color: var(--text-secondary);
    font-size: 9px;
    font-weight: 500;
    border-radius: 10px;
    transition: color 0.15s;
    -webkit-tap-highlight-color: transparent;
  }

  .bottom-nav-item .nav-icon { font-size: 20px; line-height: 1; }
  .bottom-nav-item span     { font-size: 9px; }

  .bottom-nav-item.active {
    color: var(--color-primary);
  }

  .bottom-nav-item.active .nav-icon {
    transform: scale(1.15);
    transition: transform 0.2s;
  }

  /* FAB visible on mobile */
  .fab { display: flex; }

  /* Smaller stats on mobile */
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
  }

  .stat-card .value { font-size: 20px; }

  .charts-grid {
    grid-template-columns: 1fr;
  }

  .header-row { flex-direction: column; align-items: flex-start; }
  .header-row .btn-add-transaction { display: none; } /* use FAB instead */

  .modal-box {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    max-width: 100%;
    border-radius: var(--radius) var(--radius) 0 0;
    max-height: 92vh;
    padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  }

  .toast { bottom: calc(var(--bottom-nav-height) + 16px); }
}

@media (max-width: 400px) {
  .stats-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
  .stat-card { padding: 14px; }
}
