/* Invalci — hoja de estilo única. Sin estilos en línea: la CSP del proyecto los bloquea. */

:root {
  color-scheme: light;
  --ink: #14201b;
  --muted: #63716b;
  --faint: #8b978f;
  --brand: #176b4a;
  --brand-dark: #0f5238;
  --brand-soft: #e7f2ec;
  --nav: #0f3b2d;
  --nav-deep: #0a2b20;
  --paper: #f2f5f3;
  --surface: #ffffff;
  --line: #dde6e0;
  --line-soft: #ebf1ed;
  --danger: #9b2c2c;
  --danger-soft: #fdf0f0;
  --warning: #8a5a16;
  --info: #1d5b8f;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 1px 2px rgba(16, 40, 30, .05), 0 8px 24px rgba(16, 40, 30, .05);
  --shadow-lift: 0 2px 6px rgba(16, 40, 30, .07), 0 18px 40px rgba(16, 40, 30, .09);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--paper);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { line-height: 1.25; letter-spacing: -.01em; }
a { color: var(--brand-dark); }

/* ---------------------------------------------------------------- Acceso */

body.auth {
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(1100px 520px at 50% -12%, #dcece3 0%, transparent 62%),
    linear-gradient(180deg, #f4f7f5 0%, #eaf0ec 100%);
}

.auth-shell { width: min(420px, 100%); }

.auth-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 38px 32px 32px;
  box-shadow: var(--shadow-lift);
  text-align: center;
}

.auth-logo { display: block; width: 168px; max-width: 70%; height: auto; margin: 0 auto 22px; }

.auth-card h1 { margin: 0 0 24px; font-size: 19px; font-weight: 700; }

.auth-card form { display: grid; gap: 16px; text-align: left; }

.auth-card button { width: 100%; padding: 13px; font-size: 15px; margin-top: 4px; }

.auth-note {
  margin: 20px auto 0;
  max-width: 340px;
  color: var(--faint);
  font-size: 12px;
  text-align: center;
}

.auth .error { text-align: left; }

.auth-links { margin-top: 22px; text-align: center; font-size: 13px; }

/* ----------------------------------------------------------- Estructura */

.shell { display: grid; grid-template-columns: 244px 1fr; min-height: 100vh; }

aside {
  display: flex;
  flex-direction: column;
  gap: 22px;
  padding: 20px 16px 18px;
  background: linear-gradient(180deg, var(--nav) 0%, var(--nav-deep) 100%);
  color: #e8f2ed;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.brand {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px 14px;
  background: var(--surface);
  border-radius: 12px;
}

/* `.brand img` gana en especificidad, así que la variante oculta se escribe igual de específica. */
.brand img { display: block; max-width: 100%; max-height: 58px; width: auto; height: auto; }
.brand img.brand-mark { display: none; }

nav { display: grid; gap: 18px; align-content: start; flex: 1; }

.nav-group { display: grid; gap: 2px; }

.nav-title {
  margin: 0 0 4px 10px;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: .09em;
  text-transform: uppercase;
  color: #8fb3a4;
}

nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 11px;
  border-radius: var(--radius-sm);
  color: #cfe4da;
  text-decoration: none;
  font-weight: 500;
  transition: background .15s ease, color .15s ease;
}

.nav-icon {
  width: 7px;
  height: 7px;
  border-radius: 2px;
  background: #4b7c6a;
  flex: none;
  transition: background .15s ease, transform .15s ease;
}

nav a:hover { background: rgba(255, 255, 255, .08); color: #fff; }
nav a[aria-current="page"] { background: rgba(255, 255, 255, .14); color: #fff; font-weight: 600; }
nav a[aria-current="page"] .nav-icon { background: #6ee7b7; transform: scale(1.25); }

.signout button {
  width: 100%;
  background: rgba(255, 255, 255, .08);
  color: #d8ebe2;
  font-weight: 600;
  padding: 10px;
}

.signout button:hover { background: rgba(255, 255, 255, .16); color: #fff; }

main { min-width: 0; display: flex; flex-direction: column; }

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 72px;
  padding: 14px 30px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 5;
}

header h1 { margin: 0; font-size: 20px; font-weight: 700; }

.user { display: flex; align-items: center; gap: 10px; }

.avatar {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--brand-soft);
  color: var(--brand-dark);
  font-size: 12px;
  font-weight: 700;
  flex: none;
}

.user-text { display: grid; line-height: 1.25; }
.user-text strong { font-size: 13px; }
.user-text small { color: var(--muted); font-size: 11.5px; }

.content { padding: 30px 32px 56px; max-width: 1280px; width: 100%; }

/* --------------------------------------------------------------- Bloques */

.panel, .card, .chart-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.panel { padding: 22px; margin-bottom: 22px; }
.panel > h2 { margin: 0 0 4px; font-size: 16px; }
.panel > h2 + .hint { margin-top: 0; }

.hint, .empty { color: var(--muted); }
.hint { font-size: 13px; }
.empty { padding: 18px; text-align: center; }

.section-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
  margin: 34px 0 16px;
}

.section-head h2 { margin: 0; font-size: 16px; }
.section-head .hint { margin: 2px 0 0; }
.section-head:first-child { margin-top: 0; }

/* Formulario plegable: los datos guardados quedan arriba y el alta no estorba. */
details.collapsible {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 22px;
  overflow: hidden;
}

details.collapsible > summary {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 15px 20px;
  cursor: pointer;
  font-weight: 700;
  list-style: none;
  user-select: none;
}

details.collapsible > summary::-webkit-details-marker { display: none; }

details.collapsible > summary::before {
  content: "+";
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border-radius: 6px;
  background: var(--brand-soft);
  color: var(--brand-dark);
  font-size: 15px;
  font-weight: 700;
  flex: none;
}

details.collapsible[open] > summary::before { content: "−"; }
details.collapsible > summary:hover { background: var(--line-soft); }
details.collapsible > summary .summary-hint { margin-left: auto; color: var(--muted); font-weight: 500; font-size: 12.5px; }
.collapsible-body { padding: 4px 20px 20px; border-top: 1px solid var(--line-soft); }

/* ------------------------------------------------------------ Indicadores */

.cards { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; margin-bottom: 16px; }
.cards.cards-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.cards:last-child { margin-bottom: 0; }

.card { padding: 16px 18px; display: block; text-decoration: none; color: inherit; }
a.card:hover { border-color: #bcd4c8; box-shadow: var(--shadow-lift); }
.card small { display: block; color: var(--muted); font-size: 12.5px; }
.card strong { display: block; margin-top: 6px; font-size: 26px; font-weight: 700; letter-spacing: -.02em; }
.card .card-foot { display: block; margin-top: 4px; font-size: 12px; color: var(--faint); }
.card.accent { border-left: 3px solid var(--brand); }
.card.accent-warn { border-left: 3px solid var(--warning); }
.card.accent-danger { border-left: 3px solid var(--danger); }
.card.accent-info { border-left: 3px solid var(--info); }

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

.stat {
  display: block;
  padding: 16px 18px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  text-decoration: none;
  color: inherit;
}

.stat span { display: block; color: var(--muted); font-size: 12.5px; }
.stat strong { display: block; margin-top: 6px; font-size: 26px; }
.stat:hover { border-color: #bcd4c8; box-shadow: var(--shadow-lift); }

.money-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 16px; margin-bottom: 16px; }
.money-grid:last-child { margin-bottom: 0; }

.money {
  padding: 16px 18px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.money small { display: block; color: var(--muted); font-size: 12.5px; }
.money strong { display: block; margin-top: 6px; font-size: 20px; font-variant-numeric: tabular-nums; }
.money .currency { color: var(--faint); font-size: 12px; font-weight: 600; }

/* ---------------------------------------------------------------- Gráficos */

.chart-row { display: grid; grid-template-columns: 1.65fr 1fr; gap: 16px; margin-bottom: 16px; align-items: start; }
.chart-row:last-child { margin-bottom: 0; }
.chart-card { padding: 18px 20px 20px; }
.chart-card h2 { margin: 0 0 2px; font-size: 15px; }
.chart-card .hint { margin: 0 0 14px; font-size: 12.5px; }
.chart { display: block; width: 100%; height: auto; overflow: visible; }
.chart-empty { padding: 40px 18px; }

.chart-grid { stroke: var(--line-soft); stroke-width: 1; }
.chart-axis-line { stroke: var(--line); stroke-width: 1; }
.chart-axis { fill: var(--faint); font-size: 11px; font-family: inherit; }
.chart-value { fill: var(--muted); font-size: 10.5px; font-weight: 600; font-family: inherit; }
.chart-bar { transition: opacity .15s ease; }
.chart-bar:hover { opacity: .82; }

.donut-wrap { display: grid; grid-template-columns: 160px 1fr; gap: 18px; align-items: center; }
.donut { display: block; width: 160px; height: 160px; }
.donut-track { fill: none; stroke: var(--line-soft); stroke-width: 20; }
.donut-slice { fill: none; stroke-width: 20; }
.donut-total { fill: var(--ink); font-size: 30px; font-weight: 700; font-family: inherit; }
.donut-caption { fill: var(--muted); font-size: 11px; font-family: inherit; }

.legend { display: flex; flex-wrap: wrap; gap: 8px 18px; margin: 14px 0 0; padding: 0; list-style: none; font-size: 12.5px; color: var(--muted); }
.legend li { display: flex; align-items: center; gap: 7px; }
.legend-block { display: grid; gap: 10px; margin: 0; }
.legend-name { flex: 1; color: var(--ink); }
.legend-value { color: var(--muted); font-variant-numeric: tabular-nums; }
.dot { width: 10px; height: 10px; border-radius: 3px; flex: none; }

.chart-subtitle { margin: 18px 0 10px; font-size: 12px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: var(--faint); }
.chart-subtitle:first-of-type { margin-top: 4px; }

.hbars { display: grid; gap: 12px; margin: 4px 0 0; padding: 0; list-style: none; }
.hbars li { display: grid; grid-template-columns: 116px 1fr 40px; align-items: center; gap: 12px; font-size: 13px; }
.hbar-label { color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hbar-track { height: 10px; border-radius: 999px; background: var(--line-soft); overflow: hidden; }
.hbar-fill { display: block; height: 100%; border-radius: 999px; }
.hbar-value { text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; font-weight: 600; }

/* Paleta compartida por barras, anillos y viñetas. */
.tone-1 { fill: #176b4a; stroke: #176b4a; }
.tone-2 { fill: #3f9d78; stroke: #3f9d78; }
.tone-3 { fill: #1d5b8f; stroke: #1d5b8f; }
.tone-4 { fill: #b8860b; stroke: #b8860b; }
.tone-5 { fill: #9b2c2c; stroke: #9b2c2c; }
.dot.tone-1, .hbar-fill.tone-1 { background: #176b4a; }
.dot.tone-2, .hbar-fill.tone-2 { background: #3f9d78; }
.dot.tone-3, .hbar-fill.tone-3 { background: #1d5b8f; }
.dot.tone-4, .hbar-fill.tone-4 { background: #b8860b; }
.dot.tone-5, .hbar-fill.tone-5 { background: #9b2c2c; }

/* Anchos discretos: evitan el atributo `style` que la CSP rechaza. */
.fill-2 { width: 2%; } .fill-5 { width: 5%; } .fill-10 { width: 10%; } .fill-15 { width: 15%; }
.fill-20 { width: 20%; } .fill-25 { width: 25%; } .fill-30 { width: 30%; } .fill-35 { width: 35%; }
.fill-40 { width: 40%; } .fill-45 { width: 45%; } .fill-50 { width: 50%; } .fill-55 { width: 55%; }
.fill-60 { width: 60%; } .fill-65 { width: 65%; } .fill-70 { width: 70%; } .fill-75 { width: 75%; }
.fill-80 { width: 80%; } .fill-85 { width: 85%; } .fill-90 { width: 90%; } .fill-95 { width: 95%; }
.fill-100 { width: 100%; }

/* ------------------------------------------------------------ Formularios */

form.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 15px; align-items: start; }
form.grid > button, form.grid > .form-actions { grid-column: 1 / -1; justify-self: start; }
.full { grid-column: 1 / -1; }

label { display: block; font-size: 12.5px; font-weight: 700; color: #2c3a33; }

input, select, textarea {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 10px 12px;
  border: 1px solid #c9d6cf;
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  transition: border-color .15s ease, box-shadow .15s ease;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(23, 107, 74, .14);
}

input:disabled, select:disabled { background: #f4f7f5; color: var(--muted); }
textarea { min-height: 88px; resize: vertical; }
input::placeholder, textarea::placeholder { color: #a8b4ad; }

input:user-invalid, select:user-invalid, textarea:user-invalid { border-color: var(--danger); }
input:user-invalid:focus, textarea:user-invalid:focus { box-shadow: 0 0 0 3px rgba(155, 44, 44, .13); }

.req { color: var(--danger); text-decoration: none; margin-left: 2px; font-weight: 700; }

.field-hint { display: block; margin-top: 5px; color: var(--muted); font-size: 11.5px; font-weight: 500; }

/* Plazo: unidad de calendario + cantidad en un solo control. */
.combo { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.combo > * { margin-top: 6px; }

.form-legend { margin: 0 0 14px; color: var(--muted); font-size: 12.5px; }
.form-actions { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }

button, .button {
  display: inline-block;
  border: 0;
  border-radius: var(--radius-sm);
  background: var(--brand);
  color: #fff;
  padding: 10px 17px;
  font: inherit;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  transition: background .15s ease, transform .05s ease;
}

button:hover, .button:hover { background: var(--brand-dark); }
button:active { transform: translateY(1px); }
button:focus-visible, a:focus-visible, summary:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
.danger { background: var(--danger); }
.danger:hover { background: #7f2323; }
.ghost { background: transparent; color: var(--brand-dark); border: 1px solid #c9d6cf; }
.ghost:hover { background: var(--brand-soft); color: var(--brand-dark); }

/* Filtro de fechas del resumen. */
.filter-bar {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  flex-wrap: wrap;
  padding: 14px 18px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 22px;
}

.filter-bar label { font-size: 11.5px; }
.filter-bar input { margin-top: 4px; width: auto; min-width: 160px; }
.filter-bar .quick { display: flex; gap: 8px; margin-left: auto; flex-wrap: wrap; }
.filter-bar .quick a { font-size: 12.5px; padding: 8px 12px; }

/* --------------------------------------------------------------- Tablas */

.table-wrap {
  margin-bottom: 22px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: auto;
}

table { border-collapse: collapse; width: 100%; min-width: 640px; }
th, td { text-align: left; padding: 12px 14px; border-bottom: 1px solid var(--line-soft); font-size: 13px; }
th { color: var(--muted); background: #f8faf9; font-weight: 600; white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: #fafcfb; }
td.numeric, th.numeric { text-align: right; font-variant-numeric: tabular-nums; }

.tag {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
  background: var(--line-soft);
  color: var(--muted);
}

.tag-active { background: var(--brand-soft); color: var(--brand-dark); }
.tag-warn { background: #fdf4e3; color: var(--warning); }
.tag-danger { background: var(--danger-soft); color: var(--danger); }
.tag-info { background: #e8f1f9; color: var(--info); }

.notice {
  padding: 12px 14px;
  background: var(--brand-soft);
  border: 1px solid #c5ded2;
  border-radius: var(--radius-sm);
  color: var(--brand-dark);
  font-weight: 600;
  margin: 0 0 18px;
}

.panel-narrow { max-width: 560px; }

/* Formulario compacto dentro de una celda de tabla. */
.inline-form { display: flex; gap: 6px; align-items: center; }
.inline-form input { margin-top: 0; width: auto; min-width: 150px; padding: 7px 9px; font-size: 12.5px; }
.inline-form button { padding: 7px 11px; font-size: 12.5px; white-space: nowrap; }
td .inline-form { margin-top: 6px; }

.account { padding: 0 2px; }
.account a {
  display: block;
  padding: 9px 11px;
  border-radius: var(--radius-sm);
  color: #cfe4da;
  text-decoration: none;
  font-size: 13px;
}
.account a:hover { background: rgba(255, 255, 255, .08); color: #fff; }

.error {
  padding: 12px 14px;
  background: var(--danger-soft);
  border: 1px solid #f3d5d5;
  border-radius: var(--radius-sm);
  color: var(--danger);
  margin: 0 0 16px;
}

.row-links { display: grid; gap: 8px; }

/* ------------------------------------------------------------ Adaptación */

@media (max-width: 980px) {
  .chart-row { grid-template-columns: 1fr; }
  .cards, .cards.cards-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 860px) {
  .shell { grid-template-columns: 74px 1fr; }
  aside { padding: 14px 10px; }
  .brand { padding: 8px; }
  .brand img.brand-full { display: none; }
  .brand img.brand-mark { display: block; max-height: 38px; }
  .nav-title { display: none; }
  nav a { justify-content: center; padding: 11px 6px; font-size: 0; }
  .nav-icon { width: 9px; height: 9px; }
  .signout button { font-size: 0; padding: 12px 6px; }
  .signout button::after { content: "⏻"; font-size: 15px; }
  header, .content { padding-left: 16px; padding-right: 16px; }
}

@media (max-width: 620px) {
  .shell { display: block; }
  aside { position: static; height: auto; flex-direction: row; align-items: center; gap: 10px; padding: 10px 12px; }
  .brand { padding: 5px; }
  .brand img.brand-mark { max-height: 30px; }
  nav { display: flex; overflow-x: auto; gap: 6px; }
  .nav-group { display: flex; gap: 6px; }
  nav a { font-size: 12px; white-space: nowrap; }
  .nav-icon { display: none; }
  .signout button { font-size: 0; }
  .account { display: none; }
  header { min-height: 60px; }
  header h1 { font-size: 17px; }
  .user-text { display: none; }
  .cards, .cards.cards-3, form.grid, .combo, .donut-wrap { grid-template-columns: 1fr; }
  .donut { margin: 0 auto; }
  .hbars li { grid-template-columns: 92px 1fr 34px; }
  .filter-bar .quick { margin-left: 0; }
  .content { padding: 18px 16px 34px; }
}

@media print {
  aside, header, button, .filter-bar, details.collapsible, .inline-form { display: none; }
  .shell { display: block; }
  .content { padding: 0; max-width: none; }
  .panel, .card, .chart-card, .table-wrap { box-shadow: none; break-inside: avoid; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
