/* Design tokens — ver dataviz skill (palette.md) para el origen de estos valores */
:root {
  --font-sans: system-ui, -apple-system, "Segoe UI", sans-serif;

  --surface-page: #f9f9f7;
  --surface-card: #fcfcfb;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --border: rgba(11, 11, 11, 0.10);
  --gridline: #e1e0d9;

  --accent: #2a78d6;

  --good: #0ca30c;
  --warning: #fab219;
  --warning-text: #8a5a00;
  --critical: #d03b3b;
  --delta-good: #006300;

  --radius-sm: 8px;
  --radius-md: 14px;
  --shadow-card: 0 1px 2px rgba(11, 11, 11, 0.04), 0 8px 24px -12px rgba(11, 11, 11, 0.12);
}

@media (prefers-color-scheme: dark) {
  :root {
    --surface-page: #0d0d0d;
    --surface-card: #1a1a19;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #898781;
    --border: rgba(255, 255, 255, 0.10);
    --gridline: #2c2c2a;

    --accent: #3987e5;
    --warning-text: #fab219;
    --delta-good: #0ca30c;
    --shadow-card: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px -12px rgba(0, 0, 0, 0.5);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font-sans);
  background: var(--surface-page);
  color: var(--text-primary);
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { margin: 0; font-weight: 600; }
p { margin: 0; }
a { color: inherit; }
ul { margin: 0; }

/* Header / navegación */
.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--surface-card);
  border-bottom: 1px solid var(--border);
}
.app-header__inner {
  max-width: 1180px;
  margin: 0 auto;
  padding: 14px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
}
.app-brand {
  font-weight: 700;
  font-size: 16px;
  text-decoration: none;
  white-space: nowrap;
}
.app-brand span { color: var(--text-muted); font-weight: 500; }
.app-nav {
  display: flex;
  gap: 4px;
  overflow-x: auto;
  scrollbar-width: none;
}
.app-nav::-webkit-scrollbar { display: none; }
.nav-link {
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  color: var(--text-secondary);
  text-decoration: none;
  white-space: nowrap;
  transition: background 0.15s ease, color 0.15s ease;
}
.nav-link:hover { background: var(--gridline); color: var(--text-primary); }
.nav-link[aria-current="page"] { color: #ffffff; background: var(--accent); }

/* Layout general */
.page {
  max-width: 1180px;
  margin: 0 auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* Barra de mes */
.month-bar {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  background: var(--surface-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 20px;
}
.month-bar__nav { display: flex; align-items: center; gap: 8px; }
.month-bar__label {
  font-weight: 600;
  font-size: 15px;
  min-width: 140px;
  text-align: center;
  text-transform: capitalize;
}
.month-bar__cotizacion {
  display: flex;
  gap: 8px;
  align-items: baseline;
  color: var(--text-secondary);
  font-size: 14px;
}
.month-bar__cotizacion-valor { font-weight: 600; color: var(--text-primary); }
.month-bar > .btn { margin-left: auto; }

.icon-btn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-primary);
  font-size: 16px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.icon-btn:hover { background: var(--gridline); }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 16px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  text-decoration: none;
  border: 1px solid var(--border);
  cursor: pointer;
  background: var(--surface-card);
  color: var(--text-primary);
}
.btn--primary { background: var(--accent); color: #ffffff; border-color: transparent; }
.btn--primary:hover { filter: brightness(1.08); }

/* Advertencias */
.alerts { display: flex; flex-direction: column; gap: 8px; }
.alert {
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  background: rgba(250, 178, 25, 0.14);
  border: 1px solid rgba(250, 178, 25, 0.4);
  font-size: 13px;
  color: var(--text-primary);
}

/* Métricas hero (stat tiles) */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
}
.stat-tile {
  background: var(--surface-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  box-shadow: var(--shadow-card);
}
.stat-tile__label { font-size: 13px; color: var(--text-secondary); font-weight: 500; }
.stat-tile__value { font-size: 26px; font-weight: 600; letter-spacing: -0.01em; }
.stat-tile__value--good { color: var(--delta-good); }
.stat-tile__value--critical { color: var(--critical); }

/* Cards */
.card {
  background: var(--surface-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-card);
  overflow: hidden;
}
.card__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.card__header h2 { font-size: 15px; }
.card__header-total { font-size: 14px; font-weight: 600; color: var(--text-secondary); white-space: nowrap; }
.card__body { padding: 16px 20px; display: flex; flex-direction: column; gap: 4px; }

.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 16px; }

/* Semáforo (badge de estado) */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}
.badge--good { background: rgba(12, 163, 12, 0.14); color: var(--good); }
.badge--warning { background: rgba(250, 178, 25, 0.18); color: var(--warning-text); }
.badge--critical { background: rgba(208, 59, 59, 0.14); color: var(--critical); }
.badge--muted { background: var(--gridline); color: var(--text-muted); }

/* Meter / barra de progreso — el relleno también lleva el color de estado */
.meter {
  height: 8px;
  border-radius: 999px;
  background: var(--gridline);
  overflow: hidden;
}
.meter__fill { height: 100%; border-radius: 999px; transition: width 0.3s ease; }
.meter__fill--good { background: var(--good); }
.meter__fill--warning { background: var(--warning); }
.meter__fill--critical { background: var(--critical); }
.meter__fill--muted { background: var(--text-muted); }

/* Rubros de presupuesto */
.rubro {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}
.rubro:last-child { border-bottom: none; }
.rubro--inactivo { opacity: 0.5; }
.rubro__header { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.rubro__nombre { font-weight: 600; font-size: 14px; }
.tag-off {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 5px;
  margin-left: 6px;
}
.rubro__cifras { display: flex; justify-content: space-between; font-size: 12px; color: var(--text-secondary); }
.rubro__subrubros { font-size: 12px; color: var(--text-secondary); }
.rubro__subrubros ul { list-style: none; margin: 8px 0 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.rubro__subrubros li { display: flex; justify-content: space-between; }

/* Detalle expandible (Cuentas / Cuentas Corrientes) */
.detail-row { border-bottom: 1px solid var(--border); }
.detail-row:last-child { border-bottom: none; }
.detail-row__toggle {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: none;
  border: none;
  cursor: pointer;
  padding: 10px 0;
  font-size: 14px;
  color: var(--text-primary);
  font-family: inherit;
}
.detail-row__valor { font-weight: 600; }
.detail-row.is-open .detail-row__toggle { color: var(--accent); }
.detail-row__panel { padding: 0 0 12px; }

.mini-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.mini-table th { text-align: left; color: var(--text-muted); font-weight: 500; padding: 4px 8px; border-bottom: 1px solid var(--gridline); }
.mini-table td { padding: 6px 8px; border-bottom: 1px solid var(--gridline); font-variant-numeric: tabular-nums; }
.mini-table tr:last-child td { border-bottom: none; }

/* Listas simples (Inversiones / Reservados / No presupuestados) */
.simple-list { list-style: none; margin: 8px 0 0; padding: 0; display: flex; flex-direction: column; gap: 6px; font-size: 13px; }
.simple-list li { display: flex; justify-content: space-between; gap: 12px; }
details summary { cursor: pointer; color: var(--accent); font-weight: 500; font-size: 13px; }
details summary::marker { color: var(--text-muted); }

.empty-state { color: var(--text-muted); font-size: 13px; padding: 8px 0; }
.empty-state--error { color: var(--critical); }

/* Placeholder de módulos aún no implementados en el frontend */
.placeholder-card {
  background: var(--surface-card);
  border: 1px dashed var(--border);
  border-radius: var(--radius-md);
  padding: 48px 24px;
  text-align: center;
  color: var(--text-secondary);
}
.placeholder-card h2 { margin-bottom: 8px; color: var(--text-primary); }

@media (max-width: 640px) {
  .month-bar { flex-direction: column; align-items: stretch; }
  .month-bar > .btn { margin-left: 0; }
}
