/* APAM v2 - hoja de estilos propia, sin CDN ni dependencias externas. */

:root {
  --bg: #0f1419;
  --surface: #161d26;
  --surface-2: #1d2735;
  --surface-3: #243044;
  --line: #2e3b4f;
  --line-soft: #26313f;
  --text: #e8eef7;
  --muted: #96a4bb;
  --accent: #4a9eff;
  --accent-dark: #1b4d80;
  --ok: #35c98a;
  --warn: #f0b429;
  --danger: #f2545b;
  --info: #6bb8ff;
  --radius: 8px;
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.28);
  --sidebar-w: 254px;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  font-size: 14px;
  line-height: 1.55;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0 0 12px; line-height: 1.25; font-weight: 650; }
h1 { font-size: 22px; }
h2 { font-size: 18px; }
h3 { font-size: 15px; }
p { margin: 0 0 10px; }

/* Accesibilidad: salto al contenido, ausente en la v1. */
.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  background: var(--accent);
  color: #05121f;
  padding: 10px 16px;
  z-index: 999;
  border-radius: 0 0 var(--radius) 0;
  font-weight: 700;
}
.skip-link:focus { left: 0; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

/* ---------------------------------------------------------------- layout */

.layout { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  flex: 0 0 var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.brand {
  padding: 18px 18px 14px;
  border-bottom: 1px solid var(--line-soft);
}
.brand strong { display: block; font-size: 17px; letter-spacing: 0.2px; }
.brand span { display: block; color: var(--muted); font-size: 12px; margin-top: 2px; }

.nav { padding: 10px 10px 18px; flex: 1; }
.nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 11px;
  border-radius: 6px;
  color: var(--text);
  margin-bottom: 2px;
  border: 1px solid transparent;
}
.nav a:hover { background: var(--surface-2); text-decoration: none; }
.nav a.active { background: var(--surface-3); border-color: var(--line); font-weight: 600; }
.nav .tag {
  font-size: 10px;
  text-transform: uppercase;
  background: var(--surface-3);
  border: 1px solid var(--line);
  color: var(--muted);
  border-radius: 4px;
  padding: 2px 5px;
  min-width: 34px;
  text-align: center;
  letter-spacing: 0.4px;
}
.nav a.active .tag { background: var(--accent-dark); border-color: var(--accent); color: #dbeeff; }
.nav .label { font-size: 13px; }
.nav .badge-count {
  margin-left: auto;
  background: var(--danger);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  border-radius: 10px;
  padding: 1px 7px;
}

.session {
  padding: 12px 16px;
  border-top: 1px solid var(--line-soft);
  font-size: 12px;
  color: var(--muted);
}
.session strong { display: block; color: var(--text); font-size: 13px; }

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

.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px 22px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar .titles { flex: 1; min-width: 0; }
.topbar .eyebrow {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--muted);
}
.topbar h1 { margin: 2px 0 0; font-size: 19px; }
.topbar .actions { display: flex; gap: 8px; flex-wrap: wrap; }

.content { padding: 20px 22px 48px; max-width: 1500px; width: 100%; }

/* ------------------------------------------------------------- componentes */

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
}
.card > header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin: -4px 0 14px;
  flex-wrap: wrap;
}
.card > header h2 { margin: 0; }
.card > header .sub { color: var(--muted); font-size: 12px; }

.grid { display: grid; gap: 14px; }
.grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }

.kpi {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
}
.kpi .k-label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.6px; }
.kpi .k-value { font-size: 26px; font-weight: 700; margin-top: 6px; line-height: 1.1; }
.kpi .k-value.small { font-size: 18px; }
.kpi .k-note { color: var(--muted); font-size: 12px; margin-top: 4px; }
.kpi.ok .k-value { color: var(--ok); }
.kpi.warning .k-value, .kpi.warn .k-value { color: var(--warn); }
.kpi.danger .k-value { color: var(--danger); }
/* "sin dato" nunca se pinta como si fuera un valor bueno */
.k-value.nodata { color: var(--muted); font-size: 16px; font-weight: 500; font-style: italic; }

/* ---------------------------------------------------------------- tablas */

.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
thead th {
  background: var(--surface-2);
  text-align: left;
  padding: 10px 12px;
  font-weight: 600;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
tbody td { padding: 10px 12px; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--surface-2); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.empty { padding: 26px; text-align: center; color: var(--muted); font-style: italic; }

/* --------------------------------------------------------------- chips */

.chip {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 650;
  border: 1px solid;
  white-space: nowrap;
}
.chip.ok { color: var(--ok); border-color: rgba(53, 201, 138, 0.45); background: rgba(53, 201, 138, 0.12); }
.chip.warning { color: var(--warn); border-color: rgba(240, 180, 41, 0.45); background: rgba(240, 180, 41, 0.12); }
.chip.danger { color: var(--danger); border-color: rgba(242, 84, 91, 0.45); background: rgba(242, 84, 91, 0.12); }
.chip.info { color: var(--info); border-color: rgba(107, 184, 255, 0.4); background: rgba(107, 184, 255, 0.12); }
.chip.muted { color: var(--muted); border-color: var(--line); background: var(--surface-2); }

/* -------------------------------------------------------------- botones */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--text);
  font-size: 13px;
  font-weight: 550;
  cursor: pointer;
  font-family: inherit;
  line-height: 1.3;
}
.btn:hover { background: var(--surface-3); text-decoration: none; }
.btn.primary { background: var(--accent-dark); border-color: var(--accent); color: #eaf5ff; }
.btn.primary:hover { background: #235f9c; }
.btn.danger { border-color: rgba(242, 84, 91, 0.5); color: #ffc9cc; background: rgba(242, 84, 91, 0.14); }
.btn.danger:hover { background: rgba(242, 84, 91, 0.24); }
.btn.small { padding: 5px 10px; font-size: 12px; }
.btn[disabled] { opacity: 0.45; cursor: not-allowed; }

/* ------------------------------------------------------------ formularios */

.form-grid { display: grid; gap: 14px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form-grid.one { grid-template-columns: 1fr; }
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field.wide { grid-column: 1 / -1; }
.field label { font-size: 12px; color: var(--muted); font-weight: 600; }
.field .hint { font-size: 11px; color: var(--muted); }

input[type="text"], input[type="number"], input[type="password"], input[type="date"],
input[type="datetime-local"], input[type="search"], select, textarea {
  width: 100%;
  padding: 9px 11px;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
  font-size: 13px;
}
textarea { resize: vertical; min-height: 78px; }
input:disabled, select:disabled { opacity: 0.55; }

.checkbox { flex-direction: row; align-items: center; gap: 8px; }
.checkbox input { width: auto; }
.checkbox label { font-size: 13px; color: var(--text); }

.filters {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: flex-end;
  margin-bottom: 14px;
}
.filters .field { min-width: 150px; }

/* --------------------------------------------------------------- avisos */

.flashes { margin-bottom: 16px; display: grid; gap: 8px; }
.alert {
  padding: 11px 14px;
  border-radius: 6px;
  border: 1px solid;
  font-size: 13px;
}
.alert.success { background: rgba(53, 201, 138, 0.12); border-color: rgba(53, 201, 138, 0.42); color: #a9edcd; }
.alert.danger { background: rgba(242, 84, 91, 0.12); border-color: rgba(242, 84, 91, 0.42); color: #ffc4c7; }
.alert.warning { background: rgba(240, 180, 41, 0.12); border-color: rgba(240, 180, 41, 0.42); color: #ffe0a3; }
.alert.info { background: rgba(107, 184, 255, 0.12); border-color: rgba(107, 184, 255, 0.4); color: #c4e3ff; }

/* ------------------------------------------------------------- calendario */

.calendar { width: 100%; border-collapse: collapse; table-layout: fixed; }
.calendar th {
  background: var(--surface-2);
  padding: 8px;
  font-size: 11px;
  text-transform: uppercase;
  color: var(--muted);
  border: 1px solid var(--line);
}
.calendar td {
  border: 1px solid var(--line-soft);
  vertical-align: top;
  height: 104px;
  padding: 5px 6px;
  width: 14.28%;
}
.calendar td.out { background: rgba(0, 0, 0, 0.18); opacity: 0.5; }
.calendar td.today { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.calendar .daynum { font-size: 12px; color: var(--muted); font-weight: 700; margin-bottom: 4px; }
.calendar td.today .daynum { color: var(--accent); }
.cal-item {
  display: block;
  font-size: 11px;
  padding: 2px 5px;
  border-radius: 4px;
  margin-bottom: 3px;
  border-left: 3px solid var(--muted);
  background: var(--surface-2);
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.cal-item.vencido { border-left-color: var(--danger); background: rgba(242, 84, 91, 0.14); }
.cal-item.por_vencer { border-left-color: var(--warn); background: rgba(240, 180, 41, 0.14); }
.cal-item.al_dia { border-left-color: var(--ok); background: rgba(53, 201, 138, 0.12); }
.cal-item.ot { border-left-color: var(--info); background: rgba(107, 184, 255, 0.12); }

/* -------------------------------------------------------------- tendencia */

.trend { width: 100%; height: 190px; display: block; }
.trend-legend { display: flex; gap: 14px; font-size: 12px; color: var(--muted); margin-top: 6px; flex-wrap: wrap; }
.trend-legend span { display: inline-flex; align-items: center; gap: 5px; }
.swatch { width: 11px; height: 11px; border-radius: 2px; display: inline-block; }

/* ----------------------------------------------------------------- login */

.login-page { display: grid; place-items: center; min-height: 100vh; padding: 20px; }
.login-box { width: min(400px, 100%); }
.login-box .card { padding: 26px; }
.login-brand { text-align: center; margin-bottom: 20px; }
.login-brand strong { font-size: 21px; display: block; }
.login-brand span { color: var(--muted); font-size: 13px; }

/* ------------------------------------------------------- informe de la IA */

/* Prosa para leer, no una tabla mas: medida de linea corta y aire entre
   parrafos. El informe se lee de arriba a abajo. */
/* Eleccion de modo del informe: dos opciones con su explicacion, no dos
   palabras sueltas. Quien decide tiene que poder ver que gana con cada una. */
.modes { border: 0; padding: 0; margin: 0 0 18px; }
.modes legend { padding: 0 0 8px; }
.mode-option {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 6px;
  margin-bottom: 8px;
  cursor: pointer;
}
.mode-option:hover { border-color: var(--accent); }
.mode-option input { margin-top: 3px; }
.mode-option > span { display: block; }
.mode-option .small { display: block; margin-top: 4px; }
.mode-option:has(input:checked) {
  border-color: var(--accent);
  background: rgba(255, 255, 255, 0.02);
}

/* Una lectura derivada de los datos. El borde de color la ordena de un vistazo
   sin obligar a leerlas todas. */
.senal {
  border-left: 3px solid var(--line);
  padding: 10px 0 10px 14px;
  margin: 12px 0;
}
.senal.critica { border-left-color: var(--danger); }
.senal.advertencia { border-left-color: var(--warning); }
.senal.positiva { border-left-color: var(--ok); }
.senal.informativa { border-left-color: var(--accent); }
.senal p { margin: 6px 0 0; }

.steps { margin: 0 0 12px; padding-left: 22px; font-size: 13.5px; line-height: 1.9; }
.steps li { color: var(--muted); }
.steps li.done { color: var(--text); font-weight: 600; }

.ai-report {
  max-width: 74ch;
  font-size: 15px;
  line-height: 1.7;
}
.ai-report h2 {
  font-size: 19px;
  margin: 28px 0 10px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--line);
}
.ai-report h3 {
  font-size: 16px;
  margin: 24px 0 8px;
  color: var(--accent);
}
.ai-report h3:first-child, .ai-report h2:first-child { margin-top: 0; }
.ai-report h4 { font-size: 14px; margin: 18px 0 6px; }
.ai-report p { margin: 0 0 14px; }
.ai-report ul { margin: 0 0 14px; padding-left: 22px; }
.ai-report li { margin-bottom: 7px; }
.ai-report strong { color: #fff; font-weight: 650; }
.ai-report code {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 3px;
  padding: 1px 5px;
  font-family: ui-monospace, Consolas, monospace;
  font-size: 12.5px;
}

@media print {
  .ai-report { max-width: none; color: #000; }
  .ai-report h2, .ai-report h3 { color: #000; }
}

/* ----------------------------------------------------------------- varios */

.stack { display: grid; gap: 10px; }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-family: ui-monospace, "Cascadia Code", Consolas, monospace; font-size: 12px; }
.nowrap { white-space: nowrap; }
.mt { margin-top: 16px; }
.inline-form { display: inline; }
dl.detail { display: grid; grid-template-columns: 180px 1fr; gap: 7px 14px; margin: 0; }
dl.detail dt { color: var(--muted); font-size: 12px; }
dl.detail dd { margin: 0; overflow-wrap: anywhere; }
pre.data {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 12px;
  overflow-x: auto;
  font-size: 12px;
  margin: 0;
}
details.danger-zone { border: 1px solid rgba(242, 84, 91, 0.35); border-radius: 6px; padding: 10px 12px; }
details.danger-zone summary { cursor: pointer; color: #ffc4c7; font-weight: 600; font-size: 13px; }

.pager { display: flex; gap: 8px; align-items: center; justify-content: center; margin-top: 14px; }

/* ------------------------------------------------------------- responsive */

@media (max-width: 1100px) {
  .grid.cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid.cols-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 820px) {
  .layout { flex-direction: column; }
  .sidebar {
    width: 100%;
    flex: none;
    height: auto;
    position: static;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
  .nav { display: flex; flex-wrap: wrap; gap: 4px; padding: 10px; }
  .nav a { flex: 1 1 auto; min-width: 118px; }
  .nav .label { font-size: 12px; }
  .session { display: none; }
  .grid.cols-2, .grid.cols-3, .grid.cols-4 { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .content { padding: 14px; }
  .topbar { padding: 12px 14px; }
  dl.detail { grid-template-columns: 1fr; }
  dl.detail dd { margin-bottom: 6px; }
  .calendar td { height: 76px; font-size: 11px; }
}

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

@media print {
  .sidebar, .topbar .actions, .btn, .filters { display: none !important; }
  body { background: #fff; color: #000; }
  .card { border-color: #ccc; background: #fff; }
}
