/* ============================================================
   FinanzasApp - Main Stylesheet
   Paleta: blanco, gris frío, azul slate, negro suave
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=DM+Sans:wght@300;400;500;600&family=DM+Mono:wght@400;500&display=swap');

/* -- Variables -------------------------------------------- */
:root {
  --bg:         #f8fafc;
  --bg-card:    #ffffff;
  --bg-sidebar: #0f172a;
  --border:     #e2e8f0;
  --border-dark:#1e293b;

  --text:       #0f172a;
  --text-muted: #64748b;
  --text-light: #94a3b8;
  --text-inv:   #f1f5f9;

  --blue:       #3b82f6;
  --blue-dark:  #1d4ed8;
  --blue-soft:  #eff6ff;
  --green:      #10b981;
  --green-soft: #ecfdf5;
  --red:        #ef4444;
  --red-soft:   #fef2f2;
  --amber:      #f59e0b;
  --amber-soft: #fffbeb;

  --radius:     10px;
  --radius-lg:  16px;
  --shadow:     0 1px 3px rgba(0,0,0,.07), 0 1px 2px rgba(0,0,0,.04);
  --shadow-md:  0 4px 6px rgba(0,0,0,.05), 0 2px 4px rgba(0,0,0,.04);

  --sidebar-w:  240px;
  --font:       'DM Sans', system-ui, sans-serif;
  --font-mono:  'DM Mono', monospace;
}

/* -- Reset ------------------------------------------------ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; -webkit-font-smoothing: antialiased; }
body { font-family: var(--font); background: var(--bg); color: var(--text); min-height: 100vh; }
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font-family: inherit; font-size: inherit; }
img { max-width: 100%; }

/* -- Evitar scroll horizontal ----------------------------- */
html, body     { overflow-x: hidden; max-width: 100%; }
.app-shell     { overflow-x: hidden; }
.main-content  { overflow-x: hidden; min-width: 0; }
.page-body     { overflow-x: hidden; min-width: 0; }
.card          { min-width: 0; }
.stat-card     { min-width: 0; }
.stat-value    { word-break: break-all; }
.topbar        { max-width: 100%; overflow: hidden; }
.stats-grid, .grid-2, .grid-3 { min-width: 0; }

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

/* Sidebar */
.sidebar {
  width: var(--sidebar-w);
  background: var(--bg-sidebar);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
  padding: 0 0 24px;
}
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 24px 20px 20px;
  border-bottom: 1px solid var(--border-dark);
  color: var(--text-inv);
  font-weight: 600;
  font-size: 1rem;
  letter-spacing: -.2px;
}
.sidebar-brand span.dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--blue);
  flex-shrink: 0;
}
.sidebar-nav { flex: 1; padding: 16px 12px; overflow-y: auto; }
.nav-section-label {
  font-size: 0.68rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--text-light);
  padding: 8px 8px 4px;
  margin-top: 12px;
}
.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 8px;
  color: #94a3b8;
  font-size: 0.88rem;
  font-weight: 400;
  transition: background .15s, color .15s;
  margin-bottom: 2px;
}
.nav-link:hover { background: #1e293b; color: var(--text-inv); }
.nav-link.active { background: #1e3a5f; color: #93c5fd; font-weight: 500; }
.nav-link svg { width: 16px; height: 16px; flex-shrink: 0; opacity: .7; }
.nav-link.active svg, .nav-link:hover svg { opacity: 1; }

.sidebar-footer {
  padding: 0 12px;
  border-top: 1px solid var(--border-dark);
  padding-top: 16px;
}
.user-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 8px;
}
.user-avatar {
  width: 30px; height: 30px;
  border-radius: 50%;
  background: #1e3a5f;
  color: #93c5fd;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.75rem;
  font-weight: 600;
  flex-shrink: 0;
}
.user-name { font-size: 0.82rem; color: #94a3b8; }
.btn-logout {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 10px;
  border-radius: 8px;
  color: #94a3b8;
  font-size: 0.82rem;
  transition: background .15s, color .15s;
  width: 100%;
  margin-top: 4px;
}
.btn-logout:hover { background: #1e293b; color: #ef4444; }

/* Main content */
.main-content {
  margin-left: var(--sidebar-w);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}
.topbar {
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  padding: 14px 32px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 50;
}
.topbar-title { font-size: 1rem; font-weight: 600; color: var(--text); }
.topbar-subtitle { font-size: 0.78rem; color: var(--text-muted); margin-top: 1px; }
.page-body { padding: 28px 32px; flex: 1; }

/* -- Cards ------------------------------------------------ */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 22px;
  border-bottom: 1px solid var(--border);
}
.card-title {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text);
}
.card-body { padding: 22px; }

/* -- Stat cards ------------------------------------------- */
.stats-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }
.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow);
}
.stat-label { font-size: 0.75rem; color: var(--text-muted); font-weight: 500; text-transform: uppercase; letter-spacing: .05em; }
.stat-value {
  font-size: 1.6rem;
  font-weight: 600;
  color: var(--text);
  font-family: var(--font-mono);
  margin-top: 6px;
  line-height: 1;
}
.stat-value.positive { color: var(--green); }
.stat-value.negative { color: var(--red); }
.stat-badge {
  display: inline-block;
  font-size: 0.72rem;
  padding: 3px 8px;
  border-radius: 20px;
  font-weight: 500;
  margin-top: 8px;
}
.stat-badge.green { background: var(--green-soft); color: #065f46; }
.stat-badge.red   { background: var(--red-soft);   color: #991b1b; }
.stat-badge.blue  { background: var(--blue-soft);  color: #1e40af; }
.stat-badge.amber { background: var(--amber-soft); color: #78350f; }

/* -- Grids ------------------------------------------------ */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }

/* -- Buttons ---------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 0.84rem;
  font-weight: 500;
  cursor: pointer;
  border: none;
  transition: background .15s, transform .1s, box-shadow .15s;
  line-height: 1;
}
.btn:active { transform: translateY(1px); }
.btn-primary  { background: var(--blue);  color: #fff; }
.btn-primary:hover  { background: var(--blue-dark); }
.btn-danger   { background: var(--red);   color: #fff; }
.btn-danger:hover   { background: #dc2626; }
.btn-success  { background: var(--green); color: #fff; }
.btn-success:hover  { background: #059669; }
.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
}
.btn-ghost:hover { background: var(--bg); border-color: #cbd5e1; color: var(--text); }
.btn-sm { padding: 5px 11px; font-size: 0.78rem; border-radius: 6px; }
.btn-icon { padding: 7px; }

/* -- Forms ------------------------------------------------ */
.form-group { margin-bottom: 16px; }
.form-label {
  display: block;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 5px;
}
.form-control {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-card);
  color: var(--text);
  font-size: 0.88rem;
  transition: border-color .15s, box-shadow .15s;
  outline: none;
}
.form-control:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(59,130,246,.12);
}
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 14px; }

/* -- Tables ----------------------------------------------- */
.table-wrap { overflow-x: auto; }
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}
.table th {
  padding: 10px 14px;
  text-align: left;
  font-size: 0.73rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
}
.table td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
}
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr:hover td { background: #f8fafc; }
.table .mono { font-family: var(--font-mono); }

/* -- Badges ----------------------------------------------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: 20px;
  font-size: 0.73rem;
  font-weight: 500;
}
.badge-dot { width: 6px; height: 6px; border-radius: 50%; flex-shrink: 0; }

/* -- Progress bars ---------------------------------------- */
.progress-bar {
  width: 100%;
  height: 6px;
  background: var(--border);
  border-radius: 99px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  border-radius: 99px;
  background: var(--blue);
  transition: width .4s ease;
}
.progress-fill.green  { background: var(--green); }
.progress-fill.amber  { background: var(--amber); }
.progress-fill.red    { background: var(--red); }

/* -- Flash messages --------------------------------------- */
.flash {
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: 0.85rem;
  font-weight: 500;
  margin-bottom: 20px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.flash-success { background: var(--green-soft); color: #065f46; border: 1px solid #a7f3d0; }
.flash-error   { background: var(--red-soft);   color: #991b1b; border: 1px solid #fecaca; }

/* -- Modal ------------------------------------------------ */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s;
}
.modal-overlay.open { opacity: 1; pointer-events: auto; }
.modal {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  box-shadow: 0 20px 60px rgba(0,0,0,.2);
  width: 100%;
  max-width: 480px;
  padding: 28px;
  transform: translateY(8px);
  transition: transform .2s;
}
.modal-overlay.open .modal { transform: translateY(0); }
.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; cursor: pointer; color: var(--text-muted); font-size: 1.2rem; padding: 4px; }

/* -- Color dot for categories ----------------------------- */
.cat-dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; flex-shrink: 0; }

/* -- Quincena tabs ---------------------------------------- */
.tab-group { display: flex; gap: 4px; background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 4px; }
.tab-btn {
  padding: 6px 14px;
  border-radius: 6px;
  border: none;
  background: transparent;
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  transition: background .15s, color .15s;
}
.tab-btn.active { background: var(--bg-card); color: var(--text); box-shadow: var(--shadow); }

/* -- Empty state ------------------------------------------ */
.empty {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted);
  font-size: 0.88rem;
}
.empty-icon { font-size: 2rem; margin-bottom: 8px; opacity: .4; }

/* -- Auth layout ------------------------------------------ */
.auth-wrapper {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  padding: 24px;
}
.auth-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  width: 100%;
  max-width: 400px;
  padding: 36px;
}
.auth-logo { font-size: 1.1rem; font-weight: 700; color: var(--text); margin-bottom: 6px; display: flex; align-items: center; gap: 8px; }
.auth-logo .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--blue); }
.auth-subtitle { font-size: 0.85rem; color: var(--text-muted); margin-bottom: 28px; }
.auth-divider { text-align: center; font-size: 0.8rem; color: var(--text-light); margin: 16px 0; }

/* -- Chart container -------------------------------------- */
.chart-wrap { position: relative; height: 220px; }

/* -- Misc ------------------------------------------------- */
.text-right  { text-align: right; }
.text-center { text-align: center; }
.text-muted  { color: var(--text-muted); }
.text-sm     { font-size: 0.8rem; }
.mono        { font-family: var(--font-mono); }
.fw-500      { font-weight: 500; }
.fw-600      { font-weight: 600; }
.mt-4        { margin-top: 4px; }
.mt-8        { margin-top: 8px; }
.mt-16       { margin-top: 16px; }
.mt-20       { margin-top: 20px; }
.mt-24       { margin-top: 24px; }
.mb-16       { margin-bottom: 16px; }
.mb-20       { margin-bottom: 20px; }
.flex        { display: flex; }
.items-center { align-items: center; }
.gap-8       { gap: 8px; }
.gap-12      { gap: 12px; }
.gap-16      { gap: 16px; }
.justify-between { justify-content: space-between; }
.inline-form { display: inline; }

/* -- Botón hamburguesa (oculto en desktop) --------------- */
.menu-toggle {
  display: none;
  position: fixed;
  top: 12px;
  left: 14px;
  z-index: 300;
  background: var(--bg-sidebar);
  border: none;
  border-radius: 8px;
  padding: 9px 11px;
  cursor: pointer;
  color: #94a3b8;
  align-items: center;
  justify-content: center;
}
.menu-toggle svg { width: 20px; height: 20px; stroke: currentColor; fill: none; stroke-width: 2; }
.menu-toggle:hover { background: #1e293b; color: #fff; }

/* -- Overlay oscuro detrás del sidebar en móvil ---------- */
.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.55);
  z-index: 99;
}
.sidebar-backdrop.open { display: block; }

/* -- Responsive ------------------------------------------- */
@media (max-width: 1100px) {
  .stats-grid { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 900px) {
  /* Mostrar botón hamburguesa */
  .menu-toggle { display: flex; }

  /* Sidebar como drawer */
  .sidebar {
    transform: translateX(-100%);
    transition: transform .25s ease;
    z-index: 200;
  }
  .sidebar.open { transform: translateX(0); }

  /* Contenido ocupa todo el ancho */
  .main-content { margin-left: 0; }

  /* Topbar con espacio para el botón */
  .topbar { padding: 14px 16px 14px 62px; }

  .page-body { padding: 20px 16px; }
  .grid-2 { grid-template-columns: 1fr; }
  .grid-3 { grid-template-columns: 1fr; }
  .form-row { grid-template-columns: 1fr; }
  .form-row-3 { grid-template-columns: 1fr; }
}

@media (max-width: 540px) {
  .stats-grid { grid-template-columns: 1fr; }
  .stat-value { font-size: 1.3rem; }
  .table th, .table td { padding: 8px 10px; font-size: 0.78rem; }
}
