:root {
    --bg: #eef2f6;
    --surface: #ffffff;
    --surface-2: #f8fafc;
    --text: #16202b;
    --muted: #5f6b7a;
    --line: #d7e0ea;
    --line-strong: #bcc9d6;
    --accent: #1d4ed8;
    --accent-2: #1e40af;
    --accent-soft: #dbeafe;
    --success-bg: #ecfdf3;
    --success-text: #166534;
    --warning-bg: #fff7ed;
    --warning-text: #c2410c;
    --danger-bg: #fef2f2;
    --danger-text: #b91c1c;
    --info-bg: #eff6ff;
    --info-text: #1d4ed8;
    --neutral-bg: #eef2f7;
    --neutral-text: #475569;
    --footer-bg: #0f172a;
    --footer-text: #cbd5e1;
    --shadow: 0 8px 24px rgba(15, 23, 42, 0.08);
}

body.dark {
    --bg: #0f172a;
    --surface: #111827;
    --surface-2: #1f2937;
    --text: #f3f4f6;
    --muted: #9ca3af;
    --line: #334155;
    --line-strong: #475569;
    --accent: #60a5fa;
    --accent-2: #3b82f6;
    --accent-soft: #172554;
    --success-bg: #052e16;
    --success-text: #86efac;
    --warning-bg: #431407;
    --warning-text: #fdba74;
    --danger-bg: #450a0a;
    --danger-text: #fca5a5;
    --info-bg: #172554;
    --info-text: #93c5fd;
    --neutral-bg: #1e293b;
    --neutral-text: #cbd5e1;
    --footer-bg: #020617;
    --footer-text: #94a3b8;
    --shadow: 0 12px 30px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
    font-family: Arial, sans-serif;
    background: linear-gradient(180deg, var(--bg) 0%, color-mix(in srgb, var(--bg) 88%, white 12%) 100%);
    color: var(--text);
}

a { color: inherit; }

.top-header {
    background: var(--surface);
    border-bottom: 1px solid var(--line);
    padding: 12px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    position: sticky;
    top: 0;
    z-index: 20;
}

.header-content {
    display: flex;
    align-items: center;
    min-width: 0;
    gap: 16px;
}

.logo { height: 48px; width: auto; object-fit: contain; }
.header-text { display: flex; flex-direction: column; }
.top-header .title { font-size: 24px; font-weight: 700; line-height: 1.05; }
.top-header .subtitle { font-size: 12px; margin-top: 2px; color: var(--muted); }

.navbar {
    background: var(--surface-2);
    border-bottom: 1px solid var(--line);
    padding: 9px 24px;
    display: flex;
    gap: 18px;
    flex-wrap: wrap;
    position: sticky;
    top: var(--sticky-nav-top, 95px);
    z-index: 19;
    box-shadow: 0 1px 0 var(--line), 0 10px 18px rgba(0, 0, 0, 0.08);
}

.navbar a { text-decoration: none; font-weight: 700; }
.navbar a:hover { color: var(--accent); }

.container { max-width: 1240px; margin: 0 auto 28px; padding: 18px 20px 0; }
.container-wide { max-width: 1720px; }
.actions { margin-bottom: 18px; }
.split-actions { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }

.panel {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 16px;
    padding: 24px;
    margin-bottom: 22px;
    box-shadow: var(--shadow);
}

.hero-panel {
    display: flex;
    justify-content: space-between;
    gap: 18px;
    align-items: center;
}
 .compact-hero { align-items: flex-start; }

.listing-sticky-block .panel {
    padding: 18px 22px;
    margin-bottom: 0;
}

.listing-sticky-block .text-muted {
    font-size: 13px;
    line-height: 1.35;
}
.panel h2, .page-title { margin: 0 0 10px; }
.panel h2 { font-size: 22px; }
.page-title { font-size: 26px; }
.panel-header-flex {
    display: flex;
    justify-content: space-between;
    align-items: end;
    gap: 10px;
    margin-bottom: 12px;
    flex-wrap: wrap;
}

.listing-sticky-block {
    position: sticky;
    top: var(--sticky-block-top, 150px);
    z-index: 18;
    display: grid;
    gap: 10px;
    margin-bottom: 10px;
    padding-top: 0;
    padding-bottom: 4px;
    isolation: isolate;
}

.listing-sticky-block::before {
    content: "";
    position: absolute;
    left: calc(50% - 50vw);
    right: calc(50% - 50vw);
    top: -18px;
    bottom: -4px;
    background: var(--bg);
    z-index: -1;
}

.listado-panel, .table-head-panel {
    position: relative;
    z-index: 1;
}

.sticky-list-header {
    position: relative;
    z-index: 1;
    background: var(--surface);
    margin: 0;
    padding: 0;
}

.listado-panel-header .panel-header-flex {
    margin-bottom: 0;
}

.eyebrow {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: var(--muted);
    margin-bottom: 6px;
    font-weight: 700;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(120px, 1fr));
    gap: 14px;
    min-width: 360px;
}

.stats-grid-4 {
    grid-template-columns: repeat(4, minmax(120px, 1fr));
    min-width: 500px;
}

.stat-card {
    background: var(--surface-2);
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 12px 14px;
}

.stat-card-active {
    background: color-mix(in srgb, var(--warning-bg) 70%, var(--surface) 30%);
    border-color: color-mix(in srgb, var(--warning-text) 20%, var(--line));
}

.stat-card-closed {
    background: color-mix(in srgb, var(--success-bg) 70%, var(--surface) 30%);
    border-color: color-mix(in srgb, var(--success-text) 20%, var(--line));
}

.stat-card-active .stat-value { color: var(--warning-text); }
.stat-card-closed .stat-value { color: var(--success-text); }

.stat-card-cancelled {
    background: color-mix(in srgb, var(--danger-bg) 72%, var(--surface) 28%);
    border-color: color-mix(in srgb, var(--danger-text) 20%, var(--line));
}

.stat-card-cancelled .stat-value { color: var(--danger-text); }

.stat-label {
    display: block;
    font-size: 11px;
    text-transform: uppercase;
    color: var(--muted);
    margin-bottom: 6px;
}

.stat-value { font-size: 22px; }
.quick-meta { display: grid; gap: 10px; min-width: 280px; }

.login-wrapper { max-width: 720px; margin: 64px auto; padding: 0 20px; }
.wide-login { max-width: 860px; }
.login-box {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 18px;
    padding: 34px;
    box-shadow: var(--shadow);
}
.login-box h1 { font-size: 34px; margin: 0 0 10px; }
.desc { color: var(--muted); margin-bottom: 24px; max-width: 70ch; }
.stack-lg { display: grid; gap: 18px; }
.form-grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.form-group { margin: 0; }
.form-group label { display: block; margin-bottom: 8px; font-weight: 700; }
.form-control {
    width: 100%;
    min-height: 46px;
    padding: 12px 14px;
    border: 1px solid var(--line-strong);
    border-radius: 12px;
    background: var(--surface);
    color: var(--text);
    font-size: 15px;
}
.form-control-lg { min-height: 56px; font-size: 18px; }
.form-control:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 18%, transparent);
}
.table-filter { min-width: 320px; max-width: 400px; min-height: 40px; padding-block: 9px; }
.actions-inline {
    display: flex;
    align-items: center;
    gap: 14px;
    flex-wrap: wrap;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 40px;
    text-decoration: none;
    padding: 9px 15px;
    border: 1px solid var(--line-strong);
    background: var(--surface);
    color: var(--text);
    border-radius: 12px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 700;
}
.btn:hover { transform: translateY(-1px); }
.btn-lg { min-height: 50px; padding-inline: 18px; font-size: 16px; }
.btn-primary {
    background: linear-gradient(180deg, var(--accent) 0%, var(--accent-2) 100%);
    color: #fff;
    border-color: transparent;
}
.btn-ghost { background: var(--surface-2); }

.table-wrap {
    border: 1px solid var(--line);
    border-radius: 14px;
    background: var(--surface);
    position: relative;
    overflow: hidden;
}

.table-wrap-head {
    box-shadow: var(--shadow);
}

.table-wrap-body {
    background: var(--surface);
}

.table-head-panel {
    margin: 0;
    padding: 0 22px;
}

.listado-panel-table {
    padding: 22px;
    overflow: hidden;
}

.listado-panel-table .table-wrap-body {
    margin: 0;
}

.table-scroll-x {
    overflow-x: auto;
    overflow-y: hidden;
    position: relative;
    background: var(--surface);
}

.table-scroll-x::-webkit-scrollbar { height: 12px; }

.portal-table { width: 100%; border-collapse: separate; border-spacing: 0; min-width: 1580px; table-layout: fixed; }
.col-fecha { width: 110px; }
.col-hora { width: 95px; }
.col-matricula { width: 130px; }
.col-expediente { width: 130px; }
.col-estado { width: 135px; }
.col-facturacion { width: 145px; }
.col-flota { width: 230px; }
.col-cif { width: 128px; }
.col-poblacion { width: 180px; }
.col-provincia { width: 120px; }
.col-acciones { width: 132px; }
.portal-table th,
.portal-table td {
    padding: 13px 10px;
    text-align: left;
    border-bottom: 1px solid var(--line);
    vertical-align: middle;
    white-space: nowrap;
}

.portal-table td:last-child,
.portal-table th:last-child {
    padding-right: 10px;
}

.portal-table td .btn {
    min-height: 36px;
    padding: 7px 10px;
    min-width: 108px;
}


.td-ellipsis {
    overflow: hidden;
}

.cell-ellipsis {
    display: block;
    width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.td-flota .cell-ellipsis,
.td-poblacion .cell-ellipsis,
.td-provincia .cell-ellipsis {
    font-size: 14px;
}

.td-cif .cell-ellipsis {
    letter-spacing: 0;
}


.portal-table thead th {
    background: var(--surface-2);
    background-clip: padding-box;
    z-index: 1;
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: .03em;
    box-shadow: inset 0 -1px 0 var(--line), 0 1px 0 var(--line);
}

.portal-table-headonly thead th {
    position: relative;
}

.portal-table-body tbody tr:first-child td {
    border-top: 0;
}
.portal-table tbody td { background: var(--surface); }
.portal-table-headonly tbody td { background: var(--surface-2); }
.portal-table tbody tr:hover td { background: color-mix(in srgb, var(--accent-soft) 35%, var(--surface) 65%); }
.portal-table tbody tr:last-child td { border-bottom: 0; }

.badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 7px 12px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 700;
}
.badge-success { background: var(--success-bg); color: var(--success-text); }
.badge-warning { background: var(--warning-bg); color: var(--warning-text); }
.badge-danger { background: var(--danger-bg); color: var(--danger-text); }
.badge-info { background: var(--info-bg); color: var(--info-text); }
.badge-neutral { background: var(--neutral-bg); color: var(--neutral-text); }

.status-pill {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    border-radius: 999px;
    font-size: 13px;
    font-weight: 700;
    border: 1px solid transparent;
    line-height: 1;
}

.status-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: currentColor;
    flex: 0 0 10px;
    box-shadow: 0 0 0 4px color-mix(in srgb, currentColor 16%, transparent);
}

.status-pill-active {
    background: var(--warning-bg);
    color: var(--warning-text);
    border-color: color-mix(in srgb, var(--warning-text) 22%, transparent);
}

.status-pill-closed {
    background: var(--success-bg);
    color: var(--success-text);
    border-color: color-mix(in srgb, var(--success-text) 22%, transparent);
}

.status-pill-cancelled {
    background: var(--danger-bg);
    color: var(--danger-text);
    border-color: color-mix(in srgb, var(--danger-text) 22%, transparent);
}

.status-pill-neutral {
    background: var(--neutral-bg);
    color: var(--neutral-text);
    border-color: color-mix(in srgb, var(--neutral-text) 20%, transparent);
}

.grid-detail {
    display: grid;
    grid-template-columns: minmax(220px, 280px) minmax(0, 1fr);
    gap: 14px 24px;
}
.grid-detail-enhanced > div:nth-child(4n+1),
.grid-detail-enhanced > div:nth-child(4n+2) {
    padding-top: 4px;
}
.detail-value {
    min-width: 0;
    line-height: 1.45;
    overflow-wrap: anywhere;
}
.detail-multiline {
    white-space: pre-wrap;
}
.detail-amount {
    font-weight: 700;
}
.label { font-weight: 700; }
.text-muted { color: var(--muted); }
.mt-8 { margin-top: 8px; }
.mono { font-family: Consolas, 'Courier New', monospace; }
.error-box {
    margin-top: 10px;
    padding: 12px 14px;
    background: var(--danger-bg);
    color: var(--danger-text);
    border: 1px solid color-mix(in srgb, var(--danger-text) 20%, transparent);
    border-radius: 12px;
}

.footer {
    background: var(--footer-bg);
    color: var(--footer-text);
    padding: 14px 20px;
    font-size: 13px;
    margin-top: 34px;
}

@media (max-width: 980px) {
    .hero-panel,
    .panel-header-flex,
    .split-actions,
    .actions-inline,
    .top-header { align-items: flex-start; }
    .hero-panel,
    .top-header,
    .panel-header-flex { flex-direction: column; }
    .stats-grid,
    .form-grid-2 { grid-template-columns: 1fr; min-width: 100%; }
    .table-filter { min-width: 100%; max-width: none; }
    }

@media (max-width: 720px) {
    .container { padding: 0 14px; }
    .top-header, .navbar { padding-left: 16px; padding-right: 16px; }
    .panel, .login-box { padding: 18px; border-radius: 14px; }
    .page-title { font-size: 26px; }
    .login-box h1 { font-size: 28px; }
    .grid-detail { grid-template-columns: 1fr; gap: 8px; }
    .portal-table { min-width: 920px; }
    }


.footer-version {
    font-weight: 700;
}


.table-wrap-head, .table-head-panel, .listing-sticky-block, .listado-panel-header {
    background: var(--bg);
}

/* v4.2 — botón exportar */
.sticky-list-header .export-btn { margin-left: 8px; white-space: nowrap; }
@media (max-width: 640px) {
  .sticky-list-header .export-btn { margin-left: 0; margin-top: 8px; width: 100%; }
}
