/* ============================================================
   TOKENS — paleta "cantera": basalto, caliza, óxido mineral
   ============================================================ */
:root {
  --basalto:      #20242A;   /* superficie oscura / sidebar */
  --basalto-2:    #2A3038;
  --caliza:       #F4F2ED;   /* fondo principal claro */
  --caliza-card:  #FFFFFF;
  --slate:        #5B6168;   /* texto secundario / bordes */
  --slate-light:  #DCD9D1;
  --ocre:         #B8752E;   /* marca / acento */
  --ocre-dark:    #96601F;
  --verde:        #2E7D5B;   /* favorable / ingresos */
  --verde-bg:     #E4F1EA;
  --rojo:         #B23A2E;   /* desfavorable / egresos */
  --rojo-bg:      #F8E7E5;
  --texto:        #21252B;

  --font-display: 'Big Shoulders Display', sans-serif;
  --font-body:    'IBM Plex Sans', system-ui, sans-serif;
  --font-mono:    'IBM Plex Mono', ui-monospace, monospace;

  --radius: 10px;
  --shadow-1: 0 1px 2px rgba(32,36,42,0.06), 0 1px 1px rgba(32,36,42,0.04);
  --shadow-2: 0 4px 16px rgba(32,36,42,0.08);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font-body);
  background: var(--caliza);
  color: var(--texto);
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4 { font-family: var(--font-display); font-weight: 700; letter-spacing: 0.01em; margin: 0; }
button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; }
:focus-visible { outline: 2px solid var(--ocre); outline-offset: 2px; }

/* ============================================================
   LAYOUT
   ============================================================ */
.app-shell { display: grid; grid-template-columns: 250px 1fr; min-height: 100vh; }

.sidebar {
  background: var(--basalto);
  color: #EDEAE2;
  display: flex;
  flex-direction: column;
  padding: 1.5rem 1.1rem;
  position: sticky;
  top: 0;
  height: 100vh;
}
.sidebar__brand { display: flex; align-items: center; gap: 0.7rem; margin-bottom: 2rem; }
.sidebar__logo { width: 40px; height: 40px; border-radius: 9px; }
.sidebar__brand-name { display: block; font-family: var(--font-display); font-size: 1.15rem; font-weight: 700; line-height: 1.1; }
.sidebar__brand-sub { display: block; font-size: 0.72rem; color: #9AA3AB; margin-top: 2px; }

.sidebar__nav { display: flex; flex-direction: column; gap: 0.3rem; }
.nav-link {
  display: flex; align-items: center; gap: 0.65rem;
  background: transparent; border: none; color: #C8CDD2;
  padding: 0.65rem 0.75rem; border-radius: 8px; font-size: 0.92rem; font-weight: 500;
  text-align: left; transition: background 0.15s, color 0.15s;
}
.nav-link__icon { width: 18px; height: 18px; flex-shrink: 0; }
.nav-link:hover { background: rgba(255,255,255,0.06); color: #fff; }
.nav-link--active { background: var(--ocre); color: #fff; }

.sidebar__catalogs {
  margin-top: 1.4rem; display: flex; align-items: center; gap: 0.65rem;
  background: rgba(255,255,255,0.05); border: 1px solid rgba(255,255,255,0.1); color: #C8CDD2;
  padding: 0.6rem 0.75rem; border-radius: 8px; font-size: 0.86rem;
}
.sidebar__catalogs:hover { background: rgba(255,255,255,0.1); }

.sidebar__status { margin-top: auto; display: flex; align-items: center; gap: 0.5rem; font-size: 0.76rem; color: #9AA3AB; padding-top: 1rem; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: #9AA3AB; flex-shrink: 0; }
.status-dot--ok { background: var(--verde); }
.status-dot--error { background: var(--rojo); }

.main { padding: 1.6rem 2rem 3rem; min-width: 0; }

.topbar { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 1.4rem; }
.topbar__title { font-size: 1.9rem; color: var(--basalto); }
.topbar__date { margin: 0.15rem 0 0; color: var(--slate); font-size: 0.9rem; text-transform: capitalize; }

/* ============================================================
   TAB PANELS
   ============================================================ */
.tab-panel { display: none; }
.tab-panel--active { display: block; animation: fadein 0.2s ease; }
@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }

/* ============================================================
   TOOLBAR / FILTROS DE FECHA
   ============================================================ */
.toolbar { display: flex; flex-wrap: wrap; gap: 0.9rem; justify-content: space-between; align-items: center; margin-bottom: 1.3rem; }
.date-range { display: flex; flex-wrap: wrap; align-items: center; gap: 0.4rem; background: var(--caliza-card); border: 1px solid var(--slate-light); border-radius: 9px; padding: 0.4rem 0.5rem; }
.date-range button[data-quick] {
  background: transparent; border: 1px solid transparent; color: var(--slate);
  font-size: 0.78rem; padding: 0.35rem 0.6rem; border-radius: 6px; font-weight: 500;
}
.date-range button[data-quick]:hover { background: var(--caliza); border-color: var(--slate-light); }
.date-range input[type="date"], .date-range input[type="number"] {
  border: 1px solid var(--slate-light); border-radius: 6px; padding: 0.35rem 0.5rem; font-size: 0.82rem; color: var(--texto);
}
.date-range span { color: var(--slate); font-size: 0.8rem; }
.year-label { font-size: 0.85rem; color: var(--slate); margin-right: 0.3rem; }

.toolbar__actions { display: flex; flex-wrap: wrap; gap: 0.6rem; }

.btn { border: none; border-radius: 8px; padding: 0.55rem 1rem; font-size: 0.86rem; font-weight: 600; transition: transform 0.1s, background 0.15s; }
.btn:active { transform: translateY(1px); }
.btn--primary { background: var(--ocre); color: #fff; }
.btn--primary:hover { background: var(--ocre-dark); }
.btn--secondary { background: var(--caliza-card); color: var(--basalto); border: 1px solid var(--slate-light); }
.btn--secondary:hover { background: var(--caliza); }
.btn--ghost { background: transparent; color: var(--slate); }
.btn--ghost:hover { color: var(--texto); }

.btn-icon { background: transparent; border: none; color: var(--slate); font-size: 0.95rem; padding: 0.2rem 0.4rem; border-radius: 6px; line-height: 1; }
.btn-icon--danger:hover { background: var(--rojo-bg); color: var(--rojo); }

/* ============================================================
   KPI CARDS
   ============================================================ */
.kpi-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 0.9rem; margin-bottom: 1.4rem; }
.kpi-card {
  background: var(--caliza-card); border-radius: var(--radius); padding: 1.1rem 1.2rem;
  box-shadow: var(--shadow-1); border-left: 4px solid var(--slate-light);
  display: flex; flex-direction: column; gap: 0.25rem;
}
.kpi-card--accent { border-left-color: var(--ocre); }
.kpi-card--positive { border-left-color: var(--verde); }
.kpi-card--negative { border-left-color: var(--rojo); }
.kpi-card__label { font-size: 0.78rem; color: var(--slate); font-weight: 500; }
.kpi-card__value { font-family: var(--font-mono); font-size: 1.55rem; font-weight: 600; color: var(--texto); }
.kpi-card__sub { font-size: 0.74rem; color: var(--slate); }

.text-verde { color: var(--verde) !important; }
.text-rojo { color: var(--rojo) !important; }

/* ============================================================
   GRÁFICOS
   ============================================================ */
.chart-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 0.9rem; margin-bottom: 1.6rem; }
.chart-card { background: var(--caliza-card); border-radius: var(--radius); box-shadow: var(--shadow-1); padding: 1.1rem 1.2rem; }
.chart-card--wide { grid-column: 1 / -1; }
.chart-card h3 { font-size: 0.95rem; color: var(--basalto); font-weight: 600; font-family: var(--font-body); margin-bottom: 0.7rem; }
.chart-canvas-wrap { position: relative; height: 260px; }
.chart-card--wide .chart-canvas-wrap { height: 300px; }

/* ============================================================
   TABLAS DE DATOS
   ============================================================ */
.data-section { background: var(--caliza-card); border-radius: var(--radius); box-shadow: var(--shadow-1); padding: 1.1rem 1.2rem; margin-bottom: 1rem; }
.data-section h3 { font-size: 0.95rem; color: var(--basalto); font-weight: 600; font-family: var(--font-body); margin-bottom: 0.8rem; }

.table-scroll { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: 0.83rem; min-width: 640px; }
.data-table thead th {
  text-align: left; font-weight: 600; color: var(--slate); text-transform: none;
  border-bottom: 2px solid var(--slate-light); padding: 0.5rem 0.6rem; white-space: nowrap;
}
.data-table tbody td { padding: 0.55rem 0.6rem; border-bottom: 1px solid #EFEDE7; white-space: nowrap; }
.data-table tbody tr:hover { background: var(--caliza); }
.ta-right { text-align: right; }
.num { font-family: var(--font-mono); }

.empty-state { color: var(--slate); font-size: 0.85rem; padding: 1rem 0; text-align: center; }

.tag { display: inline-block; background: var(--caliza); border: 1px solid var(--slate-light); color: var(--slate); font-size: 0.72rem; padding: 0.15rem 0.5rem; border-radius: 20px; }
.tag--verde { background: var(--verde-bg); color: var(--verde); border-color: transparent; }
.tag--rojo { background: var(--rojo-bg); color: var(--rojo); border-color: transparent; }

/* ============================================================
   MODALES
   ============================================================ */
.modal-root { position: fixed; inset: 0; z-index: 60; pointer-events: none; }
.modal-root--open { pointer-events: auto; }
.modal-overlay {
  position: fixed; inset: 0; background: rgba(32,36,42,0.55);
  display: flex; align-items: center; justify-content: center; padding: 1.5rem;
  opacity: 0; animation: overlay-in 0.15s forwards;
}
@keyframes overlay-in { to { opacity: 1; } }
.modal {
  background: var(--caliza-card); border-radius: 14px; width: 100%; max-width: 560px;
  max-height: 88vh; overflow-y: auto; box-shadow: var(--shadow-2);
  transform: translateY(6px); animation: modal-in 0.18s forwards;
}
.modal--wide { max-width: 920px; }
@keyframes modal-in { to { transform: translateY(0); } }
.modal__header { display: flex; justify-content: space-between; align-items: center; padding: 1.1rem 1.3rem; border-bottom: 1px solid var(--slate-light); position: sticky; top: 0; background: var(--caliza-card); }
.modal__header h3 { font-size: 1.1rem; color: var(--basalto); }
.modal__close { background: transparent; border: none; font-size: 1.4rem; color: var(--slate); line-height: 1; }
.modal__body { padding: 1.3rem; }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0.9rem; }
.form-grid label { display: flex; flex-direction: column; gap: 0.3rem; font-size: 0.8rem; color: var(--slate); font-weight: 500; }
.form-grid input, .form-grid select, .form-grid textarea {
  border: 1px solid var(--slate-light); border-radius: 7px; padding: 0.5rem 0.6rem; font-size: 0.88rem; color: var(--texto); background: #fff;
}
.form-grid textarea { resize: vertical; }
.span-2 { grid-column: 1 / -1; }
.form-actions { display: flex; justify-content: flex-end; gap: 0.6rem; margin-top: 0.3rem; }

/* Catálogos */
.catalog-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 1.2rem; }
.catalog-section h4 { font-size: 0.9rem; color: var(--basalto); margin-bottom: 0.6rem; }
.catalog-list { list-style: none; margin: 0 0 0.8rem; padding: 0; display: flex; flex-direction: column; gap: 0.3rem; max-height: 160px; overflow-y: auto; }
.catalog-list li { display: flex; justify-content: space-between; align-items: center; font-size: 0.82rem; padding: 0.3rem 0.4rem; border-radius: 6px; background: var(--caliza); }
.catalog-form { display: flex; flex-direction: column; gap: 0.5rem; }
.catalog-form label { font-size: 0.76rem; color: var(--slate); display: flex; flex-direction: column; gap: 0.2rem; }
.catalog-form input, .catalog-form select { border: 1px solid var(--slate-light); border-radius: 6px; padding: 0.4rem 0.5rem; font-size: 0.82rem; }
.catalog-form button { margin-top: 0.2rem; }

/* ============================================================
   TOASTS
   ============================================================ */
.toast-container { position: fixed; bottom: 1.2rem; right: 1.2rem; display: flex; flex-direction: column; gap: 0.5rem; z-index: 80; }
.toast {
  background: var(--basalto); color: #fff; padding: 0.7rem 1rem; border-radius: 8px; font-size: 0.85rem;
  box-shadow: var(--shadow-2); opacity: 0; transform: translateY(8px); transition: opacity 0.2s, transform 0.2s;
  max-width: 320px;
}
.toast--visible { opacity: 1; transform: translateY(0); }
.toast--success { border-left: 4px solid var(--verde); }
.toast--error { border-left: 4px solid var(--rojo); }

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 980px) {
  .chart-grid { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
}

@media (max-width: 760px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: relative; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; padding: 1rem; }
  .sidebar__brand { margin-bottom: 0; margin-right: auto; }
  .sidebar__nav { flex-direction: row; }
  .sidebar__catalogs { margin-top: 0; }
  .sidebar__status { display: none; }
  .main { padding: 1.2rem 1rem 2.5rem; }
  .topbar__title { font-size: 1.5rem; }
}
