:root {
  --navy: #12375a;
  --navy-2: #0c2944;
  --blue: #2563a6;
  --blue-soft: #eaf2fb;
  --teal: #16877b;
  --teal-soft: #e7f6f3;
  --amber: #b7791f;
  --amber-soft: #fff7df;
  --red: #bc3d45;
  --red-soft: #feedef;
  --green: #21845a;
  --green-soft: #eaf7f0;
  --ink: #162536;
  --muted: #657486;
  --line: #dce3ea;
  --surface: #ffffff;
  --canvas: #f4f7fa;
  --shadow: 0 6px 24px rgba(18, 55, 90, .07);
  --radius: 12px;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body { margin: 0; color: var(--ink); background: var(--canvas); font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; font-size: 15px; line-height: 1.5; }
a { color: var(--blue); text-decoration: none; }
button, input, select, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button { cursor: pointer; }
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 6px; font-size: clamp(1.6rem, 3vw, 2.15rem); letter-spacing: -.035em; line-height: 1.15; }
h2 { margin-bottom: 4px; font-size: 1.08rem; }
h3 { margin: 5px 0 6px; font-size: 1rem; }
small { color: var(--muted); }
.muted { color: var(--muted); }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
.grow { flex: 1; }

.sidebar { position: fixed; inset: 0 auto 0 0; width: 252px; z-index: 30; display: flex; flex-direction: column; padding: 24px 16px; color: #e7eff7; background: linear-gradient(180deg, var(--navy-2), var(--navy)); box-shadow: 8px 0 30px rgba(10, 35, 59, .12); }
.brand { display: flex; align-items: center; gap: 12px; padding: 0 8px 26px; }
.brand > span:last-child { display: flex; flex-direction: column; }
.brand strong { font-size: .96rem; }
.brand small { color: #9eb5ca; font-size: .72rem; text-transform: uppercase; letter-spacing: .11em; }
.brand-mark { display: grid; place-items: center; flex: 0 0 auto; width: 40px; height: 40px; border-radius: 11px; color: white; background: linear-gradient(135deg, #2e87c8, #1fa18e); font-weight: 800; box-shadow: 0 4px 14px rgba(0,0,0,.18); }
.brand-mark.large { width: 54px; height: 54px; font-size: 1.15rem; }
.sidebar nav { display: grid; gap: 5px; }
.nav-link { display: flex; gap: 11px; align-items: center; padding: 11px 12px; color: #c5d5e4; border-radius: 9px; font-weight: 600; transition: .15s ease; }
.nav-link span { width: 21px; font-size: 1.05rem; text-align: center; }
.nav-link:hover, .nav-link.active { color: white; background: rgba(255,255,255,.11); }
.nav-link.active { box-shadow: inset 3px 0 #45b9a7; }
.sidebar-footer { display: grid; gap: 12px; margin-top: auto; padding: 16px 8px 0; border-top: 1px solid rgba(255,255,255,.11); }
.sidebar-footer small { color: #9eb5ca; text-align: center; }

.app-shell { min-height: 100vh; margin-left: 252px; }
.topbar { position: sticky; top: 0; z-index: 20; height: 68px; display: flex; align-items: center; gap: 20px; padding: 0 clamp(18px, 3vw, 36px); background: rgba(255,255,255,.94); border-bottom: 1px solid var(--line); backdrop-filter: blur(10px); }
.topbar-title { flex: 1; color: var(--navy); font-weight: 750; }
.menu-button { display: none; width: 38px; height: 38px; border: 1px solid var(--line); border-radius: 8px; color: var(--navy); background: white; }
.user-menu { display: flex; align-items: center; gap: 10px; }
.user-menu > span { display: flex; flex-direction: column; text-align: right; font-size: .84rem; line-height: 1.2; }
.user-menu summary { display: grid; place-items: center; width: 32px; height: 32px; list-style: none; color: var(--teal); background: var(--teal-soft); border-radius: 50%; cursor: pointer; }
.user-menu summary::-webkit-details-marker { display: none; }
.user-menu details { position: relative; }
.popover { position: absolute; top: 40px; right: 0; min-width: 190px; padding: 7px; background: white; border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow); }
.popover a, .popover button { display: block; width: 100%; padding: 9px 10px; text-align: left; color: var(--ink); background: none; border: 0; border-radius: 6px; }
.popover a:hover, .popover button:hover { background: var(--canvas); }
.content { max-width: 1560px; margin: 0 auto; padding: 30px clamp(18px, 3vw, 38px) 60px; }

.page-header { display: flex; justify-content: space-between; align-items: flex-end; gap: 24px; margin-bottom: 24px; }
.page-header p:not(.eyebrow) { max-width: 690px; margin-bottom: 0; color: var(--muted); }
.eyebrow { margin-bottom: 6px; color: var(--teal); font-size: .72rem; font-weight: 800; letter-spacing: .13em; text-transform: uppercase; }
.header-actions { display: flex; align-items: center; gap: 10px; }

.button { display: inline-flex; align-items: center; justify-content: center; gap: 7px; min-height: 39px; padding: 8px 14px; border: 1px solid transparent; border-radius: 8px; font-weight: 700; font-size: .88rem; transition: transform .12s ease, background .12s ease, box-shadow .12s ease; }
.button:hover { transform: translateY(-1px); }
.button.primary { color: white; background: var(--blue); box-shadow: 0 4px 12px rgba(37, 99, 166, .2); }
.button.primary:hover { background: #1d558f; }
.button.secondary { color: var(--navy); background: white; border-color: var(--line); }
.button.success { color: white; background: var(--green); }
.button.warning { color: #69430b; background: var(--amber-soft); border-color: #efd394; }
.button.text { color: var(--muted); background: transparent; }
.button.ghost { color: white; background: rgba(255,255,255,.07); border-color: rgba(255,255,255,.18); }
.button.tiny { min-height: 30px; padding: 4px 9px; font-size: .76rem; }
.button.full { width: 100%; }

.panel { margin-bottom: 22px; padding: 22px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.panel.narrow { max-width: 620px; }
.panel-heading { display: flex; align-items: center; justify-content: space-between; gap: 20px; margin-bottom: 18px; }
.panel-heading p { margin: 0; color: var(--muted); font-size: .86rem; }
.table-panel { padding: 0; overflow: hidden; }
.table-panel .panel-heading { padding: 20px 22px 0; }

.stats-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; margin-bottom: 22px; }
.stat-card { position: relative; min-height: 139px; padding: 19px; overflow: hidden; color: var(--ink); background: white; border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.stat-card::after { content: ""; position: absolute; right: -18px; bottom: -26px; width: 84px; height: 84px; border-radius: 50%; opacity: .45; }
.stat-card span, .stat-card small, .stat-card strong { position: relative; z-index: 1; display: block; }
.stat-card span { font-weight: 700; }
.stat-card strong { margin: 8px 0 0; color: var(--navy); font-size: 2.15rem; line-height: 1; }
.stat-card small { margin-top: 7px; }
.stat-card.blue { border-top: 3px solid var(--blue); }.stat-card.blue::after { background: var(--blue-soft); }
.stat-card.teal { border-top: 3px solid var(--teal); }.stat-card.teal::after { background: var(--teal-soft); }
.stat-card.amber { border-top: 3px solid var(--amber); }.stat-card.amber::after { background: var(--amber-soft); }
.stat-card.red { border-top: 3px solid var(--red); }.stat-card.red::after { background: var(--red-soft); }

.two-column { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(360px, .8fr); gap: 22px; }
.record-list { margin: 0 -8px; }
.record-item { display: flex; align-items: center; gap: 12px; padding: 12px 8px; color: var(--ink); border-bottom: 1px solid #edf1f4; border-radius: 7px; }
.record-item:last-child { border-bottom: 0; }.record-item:hover { background: var(--canvas); }
.record-main { display: flex; flex: 1; min-width: 0; flex-direction: column; }
.record-main small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.record-meta { max-width: 105px; color: var(--muted); font-size: .76rem; text-align: right; }
.priority-dot { width: 9px; height: 9px; flex: 0 0 auto; background: #95a3b1; border-radius: 50%; }
.priority-dot.alta { background: var(--amber); }.priority-dot.urgente { background: var(--red); }
.timeline.compact { display: grid; }
.timeline-row { display: grid; grid-template-columns: 32px 1fr auto; align-items: center; gap: 10px; padding: 10px 0; color: var(--ink); border-bottom: 1px solid #edf1f4; }
.timeline-row:last-child { border-bottom: 0; }
.timeline-row > span:nth-child(2) { display: flex; min-width: 0; flex-direction: column; }
.timeline-row small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.timeline-row time { color: var(--muted); font-size: .75rem; }
.timeline-icon { display: grid; place-items: center; width: 28px; height: 28px; color: var(--teal); background: var(--teal-soft); border-radius: 50%; font-size: .74rem; font-weight: 800; }

.filter-bar { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; }
.filter-bar .search-field { flex: 1; }
.filter-bar input, .filter-bar select { min-height: 41px; }
.table-wrap { width: 100%; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 13px 15px; text-align: left; vertical-align: middle; border-bottom: 1px solid #e8edf2; }
th { color: #536476; background: #f7f9fb; font-size: .73rem; letter-spacing: .055em; text-transform: uppercase; }
td { font-size: .87rem; }
td strong, td small { display: block; }
tbody tr:last-child td { border-bottom: 0; }
.clickable-row:hover td { background: #f8fbfd; }
.strong-link { color: var(--navy); font-weight: 800; }

.badge { display: inline-flex; align-items: center; width: fit-content; margin-top: 5px; padding: 3px 8px; color: #536476; background: #edf1f4; border-radius: 999px; font-size: .7rem; font-weight: 800; white-space: nowrap; }
.badge.large { padding: 6px 11px; font-size: .78rem; }
.badge.event { color: var(--blue); background: var(--blue-soft); }
.priority-alta { color: #8a5a14; background: var(--amber-soft); }.priority-urgente { color: #9f2831; background: var(--red-soft); }.priority-normal { color: #3d617f; background: var(--blue-soft); }
.status-cerrado, .status-atendido, .status-pagado, .success-badge { color: #176843; background: var(--green-soft); }
.status-en-atencion, .status-en-proceso, .status-abierto { color: #20588c; background: var(--blue-soft); }
.status-en-espera, .status-pendiente { color: #875711; background: var(--amber-soft); }
.status-cancelado, .status-no-aplica, .badge.neutral { color: #586574; background: #edf1f4; }
.danger-text { color: var(--red) !important; font-weight: 700; }

label { display: grid; gap: 6px; color: #3b4d5f; font-size: .82rem; font-weight: 700; }
label > span { color: var(--red); }
input, select, textarea { width: 100%; min-height: 42px; padding: 9px 11px; color: var(--ink); background: white; border: 1px solid #cbd5df; border-radius: 7px; outline: none; }
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(37, 99, 166, .12); }
input[type="file"] { padding: 7px; background: #f8fafc; }
.form-stack { display: grid; gap: 16px; }
.form-panel { padding: 26px; }
fieldset { margin: 0 0 25px; padding: 0 0 23px; border: 0; border-bottom: 1px solid var(--line); }
fieldset:last-of-type { border-bottom: 0; }
legend { margin-bottom: 15px; color: var(--navy); font-size: 1rem; font-weight: 800; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px 18px; }
.span-2 { grid-column: span 2; }
.form-actions { display: flex; justify-content: flex-end; align-items: center; gap: 10px; margin-top: 20px; }
.file-input small { font-weight: 400; }
.inline-form { margin: 0 0 22px; padding: 20px; background: #f7fafc; border: 1px dashed #b9c8d6; border-radius: 10px; }
.compact-form { display: flex; align-items: end; gap: 12px; }
.compact-form > label { min-width: 230px; }
.payment-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }

.case-summary { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 0; padding: 0; overflow: hidden; }
.case-summary > div { display: flex; min-height: 100px; flex-direction: column; justify-content: center; padding: 18px 20px; border-right: 1px solid var(--line); }
.case-summary > div:last-child { border-right: 0; }
.case-summary span { color: var(--muted); font-size: .72rem; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; }
.case-summary strong { margin-top: 5px; }
.case-summary small { margin-top: 2px; }
.case-description p { margin: 8px 0 0; white-space: pre-wrap; }
.section-nav { position: sticky; top: 77px; z-index: 8; display: flex; gap: 5px; width: fit-content; margin: 0 0 16px; padding: 5px; background: white; border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow); }
.section-nav a { padding: 7px 12px; color: var(--ink); border-radius: 7px; font-size: .8rem; font-weight: 750; }
.section-nav a:hover { background: var(--blue-soft); }
.section-nav span { color: var(--muted); }

.followup-tree { margin-top: 12px; }
.followup-card { position: relative; display: grid; grid-template-columns: 32px 1fr; margin-left: min(calc(var(--depth) * 34px), 170px); }
.followup-line { position: relative; display: flex; justify-content: center; }
.followup-line::before { content: ""; position: absolute; top: 0; bottom: 0; width: 2px; background: #d5e0e9; }
.followup-node { position: relative; z-index: 1; display: grid; place-items: center; width: 26px; height: 26px; margin-top: 19px; color: var(--blue); background: var(--blue-soft); border: 2px solid white; border-radius: 50%; font-size: .68rem; font-weight: 800; box-shadow: 0 0 0 1px #cbd8e4; }
.followup-body { margin: 7px 0 8px 4px; padding: 16px; background: #fbfcfd; border: 1px solid var(--line); border-radius: 10px; }
.followup-card.child .followup-body { border-left: 3px solid #a7c8df; }
.followup-heading { display: flex; justify-content: space-between; gap: 12px; }
.followup-heading .badge { margin: 0; }
.metadata-row { display: flex; flex-wrap: wrap; gap: 7px 18px; color: var(--muted); font-size: .78rem; }
.metadata-row strong { color: #415467; }
.followup-notes { margin: 11px 0 0; padding: 9px 11px; white-space: pre-wrap; background: white; border-left: 3px solid #c4d8e8; border-radius: 4px; }
.inline-status { display: flex; align-items: end; gap: 8px; margin-top: 12px; }
.inline-status label { display: flex; align-items: center; gap: 8px; }
.inline-status select { min-height: 31px; padding: 3px 7px; }

.document-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.document-card { display: flex; align-items: center; gap: 12px; padding: 13px; color: var(--ink); border: 1px solid var(--line); border-radius: 9px; }
.document-card:hover { border-color: #9eb8ce; background: #f9fbfd; }
.document-card > span:nth-child(2) { display: flex; min-width: 0; flex: 1; flex-direction: column; }
.document-card strong, .document-card small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.document-icon { display: grid; place-items: center; width: 43px; height: 43px; color: var(--red); background: var(--red-soft); border-radius: 8px; font-size: .7rem; font-weight: 900; }
.download { color: var(--blue); font-size: 1.25rem; }
.closure-panel { border-top: 3px solid var(--green); }

.report-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 22px; }
.bar-list { display: grid; gap: 13px; }
.bar-list > div { display: grid; grid-template-columns: 105px 1fr 34px; align-items: center; gap: 10px; font-size: .82rem; }
progress { width: 100%; height: 9px; overflow: hidden; border: 0; border-radius: 999px; background: #e9eef3; }
progress::-webkit-progress-bar { background: #e9eef3; border-radius: 999px; }
progress::-webkit-progress-value { background: var(--teal); border-radius: 999px; }
progress::-moz-progress-bar { background: var(--teal); border-radius: 999px; }
.payment-total { display: flex; flex-direction: column; text-align: right; }
.payment-total span, .payment-total small { color: var(--muted); font-size: .72rem; }
.payment-total strong { color: var(--green); font-size: 1.3rem; }

.admin-grid { grid-template-columns: 1.25fr .75fr; }
.user-list { display: grid; }
.user-row { display: flex; align-items: center; gap: 10px; padding: 11px 0; border-bottom: 1px solid var(--line); }
.user-row:last-child { border-bottom: 0; }
.user-row .grow { display: flex; min-width: 0; flex-direction: column; }
.avatar { display: grid; place-items: center; width: 36px; height: 36px; color: var(--blue); background: var(--blue-soft); border-radius: 50%; font-weight: 800; }
.backup-card { display: grid; gap: 16px; justify-items: center; text-align: center; }
.backup-icon { display: grid; place-items: center; width: 74px; height: 74px; color: var(--green); background: var(--green-soft); border-radius: 20px; font-weight: 900; }

.empty-state { padding: 36px 18px; color: var(--muted); text-align: center; }
.empty-state strong { display: block; color: var(--ink); font-size: 1rem; }
.empty-state p { margin: 4px 0; }.empty-state.large { padding: 70px 20px; }.empty-state.large .button { margin-top: 14px; }
.flash-stack { position: fixed; top: 80px; right: 22px; z-index: 50; display: grid; gap: 8px; max-width: 420px; }
.flash { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 12px 14px; color: #24425d; background: white; border: 1px solid var(--line); border-left: 4px solid var(--blue); border-radius: 8px; box-shadow: 0 8px 28px rgba(20,40,60,.16); }
.flash.success { border-left-color: var(--green); }.flash.error { border-left-color: var(--red); }
.flash button { padding: 0; color: var(--muted); background: none; border: 0; font-size: 1.2rem; }

.auth-body { min-height: 100vh; background: radial-gradient(circle at 20% 20%, rgba(41,133,179,.16), transparent 35%), radial-gradient(circle at 80% 80%, rgba(31,161,142,.12), transparent 35%), #edf3f7; }
.auth-main { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card { width: min(430px, 100%); padding: 34px; background: rgba(255,255,255,.96); border: 1px solid white; border-radius: 17px; box-shadow: 0 18px 55px rgba(17,53,85,.14); }
.login-heading { display: flex; align-items: center; gap: 15px; margin-bottom: 13px; }
.login-heading h1 { margin: 0; font-size: 1.55rem; }
.login-heading .eyebrow { margin: 0 0 3px; }
.local-note { margin-top: 24px; padding-top: 16px; color: var(--muted); border-top: 1px solid var(--line); font-size: .8rem; text-align: center; }
.local-note span { color: var(--green); }
.error-page { display: grid; min-height: 60vh; place-content: center; justify-items: center; text-align: center; }
.error-page > strong { color: #c8d6e2; font-size: 5rem; line-height: 1; }.error-page p { color: var(--muted); }

@media (max-width: 1100px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .two-column, .admin-grid { grid-template-columns: 1fr; }
  .case-summary { grid-template-columns: repeat(2, 1fr); }
  .case-summary > div:nth-child(2) { border-right: 0; }
  .case-summary > div:nth-child(-n+2) { border-bottom: 1px solid var(--line); }
}

@media (max-width: 800px) {
  .sidebar { transform: translateX(-100%); transition: transform .2s ease; }
  .sidebar.open { transform: translateX(0); }
  .app-shell { margin-left: 0; }
  .menu-button { display: grid; place-items: center; }
  .content { padding-top: 22px; }
  .page-header, .detail-header { align-items: stretch; flex-direction: column; }
  .header-actions { flex-wrap: wrap; }
  .filter-bar { align-items: stretch; flex-direction: column; }
  .form-grid, .payment-fields, .report-grid, .document-grid { grid-template-columns: 1fr; }
  .span-2 { grid-column: auto; }
  .compact-form { align-items: stretch; flex-direction: column; }
  .compact-form > label { min-width: 0; }
  .followup-card { margin-left: min(calc(var(--depth) * 14px), 56px); grid-template-columns: 24px 1fr; }
  .followup-heading { flex-direction: column; }
  .user-menu > span { display: none; }
  .section-nav { max-width: 100%; overflow-x: auto; }
}

@media (max-width: 520px) {
  .stats-grid, .case-summary { grid-template-columns: 1fr; }
  .case-summary > div { border-right: 0; border-bottom: 1px solid var(--line); }
  .topbar { padding: 0 14px; }
  .content { padding-inline: 12px; }
  .panel, .form-panel { padding: 17px; }
  .table-panel { padding: 0; }
  .login-card { padding: 25px; }
  .flash-stack { right: 12px; left: 12px; }
}

@media print {
  .sidebar, .topbar, .button, .filter-bar, .section-nav, .inline-status, .flash-stack { display: none !important; }
  .app-shell { margin: 0; }.content { max-width: none; padding: 0; }.panel { break-inside: avoid; box-shadow: none; }
}
