:root {
  --bg: #f4f6fa;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e3e8ef;
  --text: #0b2238;
  --muted: #64748b;
  --primary: #0043b4;
  --primary-hover: #00368f;
  --primary-soft: #e6eeff;
  --danger: #dc2626;
  --danger-soft: #fdecec;
  --sidebar: #003258;
  --sidebar-text: #c9d8e8;
  --sidebar-active: #0043b4;
  --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 1px 3px rgba(15, 23, 42, .08);
  --radius: 10px;

  --st-radicada: #475569;   --st-radicada-bg: #eef2f6;
  --st-estudio: #1d4ed8;    --st-estudio-bg: #e8efff;
  --st-docs: #b45309;       --st-docs-bg: #fdf3e2;
  --st-aprobada: #15803d;   --st-aprobada-bg: #e6f6ec;
  --st-negada: #b91c1c;     --st-negada-bg: #fdecec;
  --st-desistida: #6b21a8;  --st-desistida-bg: #f3e8fb;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1120; --surface: #111a2e; --surface-2: #0f172a; --border: #22304a;
    --text: #e5ebf5; --muted: #93a3bb; --primary: #4f7cff; --primary-hover: #6b91ff;
    --primary-soft: #16244a; --danger: #f87171; --danger-soft: #3a1618;
    --sidebar: #001f38; --shadow: 0 1px 2px rgba(0,0,0,.4);
    --st-radicada: #cbd5e1;  --st-radicada-bg: #243049;
    --st-estudio: #93b4ff;   --st-estudio-bg: #172a55;
    --st-docs: #fbbf24;      --st-docs-bg: #3a2a0c;
    --st-aprobada: #4ade80;  --st-aprobada-bg: #0f3320;
    --st-negada: #f87171;    --st-negada-bg: #3a1618;
    --st-desistida: #d8b4fe; --st-desistida-bg: #2e1745;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 22px; font-weight: 650; }
h2 { font-size: 16px; font-weight: 650; }
h3 { font-size: 14px; font-weight: 650; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.num { font-variant-numeric: tabular-nums; }
.hidden { display: none !important; }

/* ------------------------------------------------ layout */
.shell { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.sidebar {
  background: var(--sidebar); color: var(--sidebar-text); padding: 18px 12px;
  display: flex; flex-direction: column; gap: 4px; position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; padding: 8px 10px 20px; color: var(--sidebar-text); }
.brand img { width: 100%; max-width: 190px; height: auto; display: block; }
.brand small { font-size: 11px; letter-spacing: .08em; text-transform: uppercase; opacity: .8; }
.topbar img { height: 22px; width: auto; display: block; }
.login-logo { display: block; margin: 0 auto 24px; }
.login-logo img { width: 100%; max-width: 300px; height: auto; display: block; margin: 0 auto; }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 8px;
  color: var(--sidebar-text); font-weight: 500;
}
.nav a:hover { background: rgba(255,255,255,.06); text-decoration: none; color: #fff; }
.nav a.active { background: var(--sidebar-active); color: #fff; }
.nav svg { width: 18px; height: 18px; flex: none; }
.sidebar .spacer { flex: 1; }
.userbox { border-top: 1px solid rgba(255,255,255,.08); padding: 14px 10px 4px; font-size: 13px; }
.userbox .name { color: #fff; font-weight: 600; }
.userbox .role { font-size: 12px; opacity: .75; }
.userbox .links { display: flex; gap: 12px; margin-top: 8px; }
.userbox .links a { color: var(--sidebar-text); font-size: 12px; }

.main { min-width: 0; }
.topbar {
  display: none; align-items: center; justify-content: space-between; gap: 12px;
  background: var(--sidebar); color: #fff; padding: 10px 16px; position: sticky; top: 0; z-index: 20;
}
.topbar button { background: none; border: 0; color: #fff; padding: 6px; cursor: pointer; display: grid; }
.topbar svg { width: 24px; height: 24px; }
.content { padding: 28px 32px 60px; max-width: 1280px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head p { margin: 4px 0 0; }

@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: 260px; z-index: 30; transform: translateX(-100%); transition: transform .2s; }
  .shell.nav-open .sidebar { transform: none; box-shadow: 0 0 0 100vmax rgba(0,0,0,.4); }
  .topbar { display: flex; }
  .content { padding: 18px 16px 48px; }
}

/* ------------------------------------------------ componentes */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-pad { padding: 20px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
@media (max-width: 900px) { .grid-2, .grid-3 { grid-template-columns: 1fr; } }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 9px 16px; border-radius: 8px; border: 1px solid transparent; font: inherit; font-weight: 600;
  cursor: pointer; background: var(--primary); color: #fff; white-space: nowrap; text-decoration: none !important;
}
.btn:hover { background: var(--primary-hover); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn svg { width: 16px; height: 16px; }
.btn.secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn.secondary:hover { background: var(--surface-2); }
.btn.danger { background: var(--danger); }
.btn.ghost { background: none; color: var(--primary); padding: 6px 10px; }
.btn.ghost:hover { background: var(--primary-soft); }
.btn.sm { padding: 5px 10px; font-size: 13px; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field label { font-weight: 600; font-size: 13px; }
.field label .req { color: var(--danger); margin-left: 2px; }
.field .hint { font-size: 12px; color: var(--muted); }
.field .err { font-size: 12px; color: var(--danger); min-height: 0; }
.field.invalid input, .field.invalid select, .field.invalid .drop { border-color: var(--danger); }
input[type=text], input[type=email], input[type=tel], input[type=password], input[type=number], input[type=date], input[type=search], select, textarea {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: 9px 12px; width: 100%; min-width: 0;
}
textarea { resize: vertical; min-height: 80px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: -1px; border-color: var(--primary); }
input:disabled, select:disabled { background: var(--surface-2); color: var(--muted); }
.check { display: flex; gap: 10px; align-items: flex-start; cursor: pointer; }
.check input { width: 18px; height: 18px; margin-top: 1px; accent-color: var(--primary); }

.badge {
  display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px;
  font-size: 12px; font-weight: 600; white-space: nowrap;
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.st-0 { color: var(--st-radicada); background: var(--st-radicada-bg); }
.st-1 { color: var(--st-estudio); background: var(--st-estudio-bg); }
.st-2 { color: var(--st-docs); background: var(--st-docs-bg); }
.st-3 { color: var(--st-aprobada); background: var(--st-aprobada-bg); }
.st-4 { color: var(--st-negada); background: var(--st-negada-bg); }
.st-5 { color: var(--st-desistida); background: var(--st-desistida-bg); }
.tag { display: inline-block; padding: 2px 8px; border-radius: 6px; font-size: 12px; background: var(--surface-2); border: 1px solid var(--border); color: var(--muted); }

/* ------------------------------------------------ tablas */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 11px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 600; background: var(--surface-2); white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr.clickable { cursor: pointer; }
tbody tr.clickable:hover { background: var(--surface-2); }
td.right, th.right { text-align: right; }
.empty { padding: 40px 20px; text-align: center; color: var(--muted); }

.filters { display: flex; gap: 10px; flex-wrap: wrap; padding: 14px 16px; border-bottom: 1px solid var(--border); }
.filters > * { flex: 1 1 160px; }
.filters input[type=search] { flex: 3 1 240px; }
.pager { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; border-top: 1px solid var(--border); gap: 10px; flex-wrap: wrap; }

/* ------------------------------------------------ KPIs y gráficos */
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; margin-bottom: 16px; }
@media (max-width: 1000px) { .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.kpi { padding: 18px 20px; }
.kpi .label { font-size: 13px; color: var(--muted); font-weight: 500; }
.kpi .value { font-size: 28px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpi .sub { font-size: 12px; color: var(--muted); }
.bars { display: flex; flex-direction: column; gap: 12px; padding: 20px; }
.bar-row { display: grid; grid-template-columns: 170px 1fr 44px; align-items: center; gap: 12px; font-size: 13px; }
.bar-track { height: 10px; background: var(--surface-2); border-radius: 999px; overflow: hidden; border: 1px solid var(--border); }
.bar-fill { height: 100%; border-radius: 999px; background: currentColor; }
.spark { padding: 12px 20px 16px; }
.spark svg { width: 100%; height: 140px; display: block; }

/* ------------------------------------------------ formulario de solicitud */
.form-section { margin-bottom: 18px; }
.form-section .card-head { background: var(--surface-2); border-radius: var(--radius) var(--radius) 0 0; }
.section-num {
  width: 26px; height: 26px; border-radius: 50%; background: var(--primary); color: #fff;
  display: inline-grid; place-items: center; font-size: 13px; font-weight: 700; margin-right: 10px;
}
.form-body { padding: 20px; display: grid; gap: 18px; grid-template-columns: repeat(3, minmax(0, 1fr)); }
.form-body .span-2 { grid-column: span 2; }
.form-body .span-3 { grid-column: 1 / -1; }
@media (max-width: 900px) { .form-body { grid-template-columns: 1fr; } .form-body .span-2 { grid-column: auto; } }
.money { position: relative; }
.money span { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.money input { padding-left: 26px; }

.drop {
  border: 1.5px dashed var(--border); border-radius: 8px; padding: 14px; text-align: center;
  color: var(--muted); cursor: pointer; background: var(--surface-2); font-size: 13px; transition: border-color .15s, background .15s;
}
.drop:hover, .drop.over { border-color: var(--primary); background: var(--primary-soft); color: var(--primary); }
.drop input { display: none; }
.files { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; }
.file-chip {
  display: flex; align-items: center; gap: 8px; padding: 6px 10px; border: 1px solid var(--border);
  border-radius: 8px; background: var(--surface); font-size: 13px; min-width: 0;
}
.file-chip .fname { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-chip button { background: none; border: 0; color: var(--muted); cursor: pointer; padding: 2px 4px; font-size: 16px; line-height: 1; }
.file-chip button:hover { color: var(--danger); }
.file-chip .prog { width: 60px; height: 4px; background: var(--border); border-radius: 4px; overflow: hidden; }
.file-chip .prog i { display: block; height: 100%; background: var(--primary); width: 0; }
.file-chip.error { border-color: var(--danger); color: var(--danger); }
.sticky-actions {
  position: sticky; bottom: 0; background: var(--bg); padding: 14px 0; display: flex; justify-content: flex-end; gap: 10px;
  border-top: 1px solid var(--border); margin-top: 8px;
}

/* ------------------------------------------------ detalle */
.detail { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 16px; align-items: start; }
@media (max-width: 1100px) { .detail { grid-template-columns: 1fr; } }
.dl { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px 20px; padding: 18px 20px; }
@media (max-width: 700px) { .dl { grid-template-columns: 1fr 1fr; } }
.dl div { min-width: 0; }
.dl dt { font-size: 12px; color: var(--muted); }
.dl dd { margin: 2px 0 0; font-weight: 500; overflow-wrap: anywhere; }
.doc-group { padding: 14px 20px; border-bottom: 1px solid var(--border); }
.doc-group:last-child { border-bottom: 0; }
.doc-group-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 6px; }
.doc-list { display: flex; flex-wrap: wrap; gap: 8px; }
.doc-link { display: inline-flex; align-items: center; gap: 6px; padding: 5px 10px; border: 1px solid var(--border); border-radius: 8px; font-size: 13px; max-width: 100%; }
.doc-link span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.doc-missing { font-size: 13px; color: var(--muted); font-style: italic; }
.timeline { list-style: none; margin: 0; padding: 16px 20px; display: flex; flex-direction: column; gap: 16px; }
.timeline li { position: relative; padding-left: 22px; }
.timeline li::before { content: ""; position: absolute; left: 4px; top: 6px; width: 9px; height: 9px; border-radius: 50%; background: var(--primary); }
.timeline li::after { content: ""; position: absolute; left: 8px; top: 18px; bottom: -14px; width: 1px; background: var(--border); }
.timeline li:last-child::after { display: none; }
.timeline .when { font-size: 12px; color: var(--muted); }
.timeline .comment { margin-top: 4px; padding: 8px 10px; background: var(--surface-2); border-radius: 8px; border: 1px solid var(--border); white-space: pre-wrap; }
.stepper { display: flex; gap: 4px; padding: 16px 20px; }
.stepper div { flex: 1; height: 6px; border-radius: 4px; background: var(--border); }
.stepper div.on { background: var(--primary); }

/* ------------------------------------------------ login */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; background:
  radial-gradient(1200px 600px at 10% -10%, var(--primary-soft), transparent), var(--bg); }
.login { width: 100%; max-width: 400px; padding: 32px; }
.login form { display: grid; gap: 16px; }
.alert { padding: 10px 12px; border-radius: 8px; font-size: 13px; background: var(--danger-soft); color: var(--danger); }
.alert.info { background: var(--primary-soft); color: var(--primary); }

/* ------------------------------------------------ modal, toasts */
dialog#modal { border: 0; border-radius: 12px; padding: 0; width: min(520px, calc(100vw - 32px)); background: var(--surface); color: var(--text); box-shadow: 0 20px 50px rgba(0,0,0,.25); }
dialog#modal::backdrop { background: rgba(15, 23, 42, .45); }
.modal-head { padding: 18px 20px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }
.modal-body { padding: 20px; display: grid; gap: 14px; }
.modal-foot { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 10px; }
.x { background: none; border: 0; font-size: 22px; cursor: pointer; color: var(--muted); line-height: 1; }
#toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 100; }
.toast { background: var(--text); color: var(--bg); padding: 10px 14px; border-radius: 8px; box-shadow: var(--shadow); font-size: 13px; max-width: 340px; animation: in .2s; }
.toast.error { background: var(--danger); color: #fff; }
@keyframes in { from { transform: translateY(8px); opacity: 0; } }
.spinner { width: 22px; height: 22px; border: 3px solid var(--border); border-top-color: var(--primary); border-radius: 50%; animation: spin .8s linear infinite; margin: 40px auto; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ------------------------------------------------ impresión / PDF */
.print-toolbar {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding: 12px 20px; background: var(--sidebar); color: #fff;
}
.print-toolbar .check { color: #fff; font-size: 13px; align-items: center; }
.print-bg { background: #e9edf3; min-height: 100vh; padding: 24px 12px 60px; }
@media screen { .print-doc { min-height: 1056px; } }
.print-doc {
  --p-navy: #003258; --p-blue: #0043b4; --p-line: #cfd8e3; --p-soft: #f2f5f9;
  width: 100%; max-width: 816px; margin: 0 auto; background: #fff; color: #0b2238; padding: 44px 48px;
  box-shadow: 0 4px 20px rgba(0,0,0,.12); font-size: 12px; line-height: 1.45; color-scheme: light;
}
.pd-head { display: flex; justify-content: space-between; align-items: center; gap: 20px; padding-bottom: 14px; border-bottom: 3px solid var(--p-navy); }
.pd-head img { width: 240px; height: auto; }
.pd-head .meta { text-align: right; }
.pd-head .title { font-size: 15px; font-weight: 800; color: var(--p-navy); letter-spacing: .02em; }
.pd-head .nro { font-size: 20px; font-weight: 800; color: var(--p-blue); }
.pd-estado { display: inline-block; margin-top: 4px; padding: 2px 10px; border: 1.5px solid var(--p-navy); border-radius: 999px; font-weight: 700; font-size: 11px; text-transform: uppercase; }
.pd-sec { margin-top: 12px; break-inside: avoid; }
.pd-sec h3 { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: #fff; background: var(--p-navy); padding: 5px 10px; margin: 0; }
.pd-table { width: calc(100% - 1px); border-collapse: collapse; table-layout: fixed; }
.pd-table td, .pd-table th { border: 1px solid var(--p-line); padding: 4px 9px; overflow-wrap: anywhere; vertical-align: top; text-align: left; }
.pd-table th { background: var(--p-soft); width: 26%; font-weight: 600; color: #34506b; font-size: 11px; text-transform: none; letter-spacing: 0; }
.pd-table td { font-weight: 500; }
.pd-note { padding: 7px 10px; border: 1px solid var(--p-line); border-top: 0; color: #4a627a; font-style: italic; }
.pd-firmas { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 28px; margin-top: 40px; break-inside: avoid; }
.pd-firmas div { border-top: 1px solid #0b2238; padding-top: 4px; font-size: 11px; text-align: center; color: #34506b; }
.pd-foot { margin-top: 14px; padding-top: 8px; border-top: 1px solid var(--p-line); font-size: 10px; color: #6b7f93; display: flex; justify-content: space-between; gap: 10px; }
.pd-anexo { break-before: page; page-break-before: always; padding-top: 10px; }
.pd-anexo h4 { margin: 0 0 8px; font-size: 12px; color: var(--p-navy); }
.pd-anexo img { max-width: 100%; max-height: 900px; display: block; margin: 0 auto; border: 1px solid var(--p-line); }
@media (max-width: 700px) { .print-doc { padding: 24px 18px; } .pd-head { flex-direction: column; align-items: flex-start; } .pd-head .meta { text-align: left; } .pd-head img { width: 200px; } }

@media print {
  @page { size: letter; margin: 10mm 12mm; }
  .print-doc { font-size: 11px; }
  html, body { background: #fff !important; }
  #toasts, .print-toolbar, dialog { display: none !important; }
  .print-bg { background: #fff; padding: 0; min-height: 0; }
  .print-doc { box-shadow: none; max-width: none; padding: 0; }
  .pd-sec h3, .pd-table th { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
