:root {
  --ink: #16191D;
  --ink-2: #3F454B;
  --muted: #5B6168;
  --line: #DCDFE2;
  --line-2: #ECEEF0;
  --field: #C5CAD0;
  --bg: #F3F4F1;
  --panel: #FFFFFF;
  --soft: #F7F8F6;
  /* Azul de la marca Transportes Castillo López */
  --accent: #0A5BB0;
  --accent-dark: #084A8F;
  --accent-2: #3D8FE8;
  --accent-light: #9CC8F7;
  --accent-soft: #EBF3FD;
  --side: #16191D;
  --side-2: #2A2F35;
  --side-line: #3A4047;
  --side-text: #E7E9EB;
  --side-muted: #A3A9AF;
  --ok-bg: #ECFDF3; --ok: #166534;
  --warn-bg: #FEF3C7; --warn: #78350F; --warn-line: #FCD34D;
  --info-bg: #E8F0FE; --info: #1E3A8A;
  --off-bg: #EEF0F2; --off: #3F454B;
  --err-bg: #FEE2E2; --err: #991B1B;
  --mono: ui-monospace, "Cascadia Mono", "SF Mono", Consolas, "Liberation Mono", monospace;
  --sans: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  --r: 8px;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { font-family: var(--sans); color: var(--ink); background: var(--bg); font-size: 15px; line-height: 1.4; }
a { color: var(--accent); }
a:hover { color: var(--accent-dark); }
h1, h2, h3 { margin: 0; font-weight: 600; }
h1 { font-size: 26px; }
h2 { font-size: 16px; }
.mono { font-family: var(--mono); }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.right { text-align: right; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; top: 0; left: 0; }
.boot { padding: 48px; text-align: center; color: var(--muted); }
[hidden] { display: none !important; }

/* ---------- layout ---------- */
.shell { display: flex; min-height: 100vh; }
.side { width: 232px; flex: none; background: var(--side); color: var(--side-text); padding: 22px 14px; display: flex; flex-direction: column; gap: 4px; position: sticky; top: 0; height: 100vh; }
.brand, .brand:hover, .brand:visited, .brand:active { display: flex; align-items: center; gap: 10px; padding: 0 8px 18px; font-weight: 700; font-size: 15px; color: #fff; text-decoration: none; }
.brand small { display: block; font-weight: 400; font-size: 12px; color: var(--side-muted); }
.brand-logo { display: flex; flex-direction: column; gap: 8px; padding: 0 2px 18px; text-decoration: none; }
.logo-card { display: block; background: #fff; border-radius: 8px; padding: 10px 12px; }
.logo-card img { display: block; width: 100%; height: auto; }
.logo-card.lg { max-width: 340px; padding: 16px 20px; border-radius: 10px; }
.brand-sub { font-size: 12px; color: var(--side-muted); padding-left: 2px; }
.nav a { display: flex; align-items: center; justify-content: space-between; min-height: 44px; padding: 0 12px; border-radius: 6px; color: var(--side-text); text-decoration: none; font-size: 14px; }
.nav a:hover { background: var(--side-2); color: #fff; }
.nav a.active { background: var(--side-2); color: #fff; font-weight: 600; }
.nav a.active::after { content: ""; width: 8px; height: 8px; border-radius: 4px; background: var(--accent-2); }
.nav-label { font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: var(--side-muted); padding: 18px 12px 6px; }
.side-foot { margin-top: auto; border-top: 1px solid var(--side-line); padding: 14px 12px 0; display: flex; flex-direction: column; gap: 3px; font-size: 13px; }
.side-foot .role { color: var(--side-muted); }
.linkbtn { background: none; border: 0; padding: 6px 0; font: inherit; color: var(--accent-light); cursor: pointer; text-align: left; text-decoration: underline; }
.main { flex: 1; min-width: 0; padding: 26px 32px 56px; display: flex; flex-direction: column; gap: 18px; }
.page-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; }
.page-head .sub { font-size: 14px; color: var(--muted); margin-top: 4px; }
.row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.cols { display: flex; flex-wrap: wrap; gap: 20px; align-items: flex-start; }
.cols > .grow { flex: 999 1 520px; min-width: 0; display: flex; flex-direction: column; gap: 16px; }
.cols > .aside { flex: 1 1 320px; min-width: 0; display: flex; flex-direction: column; gap: 16px; }
.topbar { display: none; }

/* ---------- status pill ---------- */
.pill { display: inline-flex; align-items: center; gap: 8px; border-radius: 999px; padding: 7px 14px; font-size: 13px; font-weight: 500; border: 1px solid transparent; white-space: nowrap; }
.pill .dot { width: 8px; height: 8px; border-radius: 4px; background: currentColor; }
.pill.on { background: var(--ok-bg); color: var(--ok); border-color: #A7F3C4; }
.pill.off { background: var(--warn-bg); color: var(--warn); border-color: var(--warn-line); }
.pill.sync { background: var(--info-bg); color: var(--info); border-color: #BFD3FB; }
button.pill { cursor: pointer; font: inherit; font-size: 13px; }

.badge { display: inline-block; font-size: 12px; font-weight: 600; border-radius: 999px; padding: 3px 10px; white-space: nowrap; }
.b-ok { background: var(--ok-bg); color: var(--ok); }
.b-warn { background: var(--warn-bg); color: var(--warn); }
.b-info { background: var(--info-bg); color: var(--info); }
.b-off { background: var(--off-bg); color: var(--off); }
.b-err { background: var(--err-bg); color: var(--err); }

/* ---------- panels & forms ---------- */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 20px; display: flex; flex-direction: column; gap: 14px; }
.card-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 8px; }
.step { font-family: var(--mono); color: var(--accent); margin-right: 8px; }
.grid { display: grid; gap: 12px; grid-template-columns: repeat(var(--n, 3), minmax(0, 1fr)); }
.span2 { grid-column: span 2; }
.span-all { grid-column: 1 / -1; }
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field > label, .lbl { font-size: 12px; font-weight: 600; color: var(--ink-2); }
.hint { font-size: 12px; color: var(--muted); }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], input[type=search], select, textarea {
  height: 42px; padding: 0 11px; border: 1px solid var(--field); border-radius: 6px; font: inherit; font-size: 15px; background: #fff; color: var(--ink); width: 100%; min-width: 0;
}
textarea { height: auto; min-height: 80px; padding: 10px 11px; resize: vertical; }
input.num { font-family: var(--mono); font-size: 14px; }
input:focus, select:focus, textarea:focus, button:focus-visible, a:focus-visible { outline: 3px solid rgba(10, 91, 176, .35); outline-offset: 1px; border-color: var(--accent); }
input[type=number]::-webkit-inner-spin-button { opacity: .5; }
.check { display: flex; align-items: center; gap: 10px; min-height: 36px; font-size: 14px; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); margin: 0; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 42px; padding: 0 16px; border-radius: 6px; border: 1px solid var(--field); background: #fff; color: var(--ink); font: inherit; font-size: 14px; font-weight: 500; text-decoration: none; cursor: pointer; white-space: nowrap; }
.btn:hover { background: var(--soft); color: var(--ink); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn.primary:hover { background: var(--accent-dark); border-color: var(--accent-dark); color: #fff; }
.btn.dark { background: var(--ink); border-color: var(--ink); color: #fff; font-weight: 600; }
.btn.dark:hover { background: #000; color: #fff; }
.btn.danger { border-color: #F3B4B4; color: var(--err); }
.btn.danger:hover { background: var(--err-bg); color: var(--err); }
.btn.dashed { border: 1px dashed var(--accent); color: var(--accent); font-weight: 600; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.sm { min-height: 34px; padding: 0 12px; font-size: 13px; }
.btn.icon { width: 42px; padding: 0; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.btn.block { width: 100%; }

/* ---------- vehicle picker ---------- */
.pick { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); }
.pick label { display: flex; flex-direction: column; gap: 6px; border: 1px solid var(--field); border-radius: 8px; padding: 13px; cursor: pointer; }
.pick label:has(input:checked) { border: 2px solid var(--accent); background: var(--accent-soft); padding: 12px; }
.pick .t { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.pick input { width: 18px; height: 18px; accent-color: var(--accent); margin: 0; }

/* ---------- route editor ---------- */
.stop { display: flex; gap: 12px; align-items: center; }
.node { flex: none; width: 28px; height: 28px; border-radius: 14px; background: var(--ink); color: #fff; font-family: var(--mono); font-size: 13px; display: flex; align-items: center; justify-content: center; }
.node.last { background: var(--accent); }
.stop > input { flex: 1; }
.stop:has(.pt) { align-items: flex-end; }
.stop:has(.pt) > .node { margin-bottom: 7px; }
.pt { flex: 1; min-width: 0; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.3fr); gap: 10px; }
.pt .hint { grid-column: 1 / -1; }
.stop-gap { flex: none; width: 42px; }
.combo { position: relative; flex: 1; min-width: 0; }
.combo-list { position: absolute; left: 0; right: 0; top: calc(100% + 4px); z-index: 30; background: #fff; border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 10px 28px rgba(22, 25, 29, .14); max-height: 330px; overflow-y: auto; padding: 6px 0; }
.combo-item { padding: 9px 16px; cursor: pointer; display: flex; flex-direction: column; gap: 2px; }
.combo-item b { font-weight: 700; color: var(--ink); font-size: 15px; }
.combo-item span { font-size: 13px; color: var(--muted); }
.combo-item:hover, .combo-item.active { background: var(--accent-soft); }
.combo-empty { padding: 12px 16px; font-size: 13px; color: var(--muted); }
.leg { display: flex; gap: 12px; }
.leg .rail { flex: none; width: 28px; display: flex; justify-content: center; }
.leg .rail::before { content: ""; width: 2px; background: var(--field); }
.leg .box { flex: 1; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; background: var(--soft); border-radius: 8px; padding: 10px 12px; }
.indent { margin-left: 40px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.extra { display: grid; grid-template-columns: minmax(0, 1fr) 140px 42px; gap: 8px; align-items: center; }

/* ---------- summary ---------- */
.summary { background: var(--side); color: var(--side-text); border-radius: 10px; padding: 22px; display: flex; flex-direction: column; gap: 12px; position: sticky; top: 16px; max-height: calc(100vh - 32px); overflow-y: auto; }
/* El panel lateral ocupa todo el alto de la columna para que el resumen lo acompañe al hacer scroll. */
.cols > .aside:has(> .summary) { align-self: stretch; }
.summary h2 { color: #fff; }
.summary .ln { display: flex; justify-content: space-between; gap: 12px; font-size: 14px; }
.summary .ln span:first-child { color: #C9CDD1; }
.summary .ln .mono { color: #fff; }
.summary .ln small { display: block; font-size: 12px; color: var(--side-muted); }
.summary .sep { border-top: 1px solid var(--side-line); padding-top: 10px; }
.summary .mg span { color: var(--accent-light) !important; }
.summary .tot-l { font-size: 12px; letter-spacing: .08em; text-transform: uppercase; color: var(--side-muted); }
.summary .tot { font-family: var(--mono); font-size: 32px; font-weight: 600; color: #fff; }
.summary .tot small { font-size: 14px; color: var(--side-muted); }
.summary .btn:not(.primary) { background: transparent; color: var(--side-text); border-color: #5B6168; }
.summary .btn.primary { background: var(--accent-2); border-color: var(--accent-2); color: var(--ink); }
.summary .btn.primary:hover { background: var(--accent-light); border-color: var(--accent-light); color: var(--ink); }
.summary .note { font-size: 12px; color: var(--side-muted); margin: 0; line-height: 1.5; }
.summary .warn { color: #FCD34D; }

/* ---------- tables ---------- */
.table-wrap { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; overflow-x: auto; position: relative; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; font-size: 12px; font-weight: 600; color: var(--ink-2); background: var(--soft); padding: 11px 14px; white-space: nowrap; }
td { padding: 12px 14px; border-top: 1px solid var(--line-2); vertical-align: middle; }
tr.sel td { background: var(--accent-soft); }
tr.click { cursor: pointer; }
tr.click:hover td { background: var(--soft); }
tfoot td { font-weight: 700; border-top: 2px solid var(--line); }
.empty { padding: 28px; text-align: center; color: var(--muted); }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.lines { display: flex; flex-direction: column; gap: 8px; font-size: 14px; }
.lines .ln { display: flex; justify-content: space-between; gap: 12px; }
.lines .ln.sep { border-top: 1px solid var(--line-2); padding-top: 8px; }
.lines .ln.big { font-size: 18px; font-weight: 700; }

.tabs { display: flex; flex-wrap: wrap; gap: 2px; border-bottom: 1px solid var(--line); }
.tabs a { min-height: 44px; display: flex; align-items: center; padding: 0 16px; color: var(--ink-2); text-decoration: none; font-size: 14px; border-bottom: 3px solid transparent; }
.tabs a.active { border-bottom-color: var(--accent); color: var(--ink); font-weight: 600; }

.banner { display: flex; gap: 10px; align-items: flex-start; border-radius: 8px; padding: 12px 14px; font-size: 14px; line-height: 1.45; }
.banner.warn { background: var(--warn-bg); color: var(--warn); border: 1px solid var(--warn-line); }
.banner.info { background: var(--info-bg); color: var(--info); }
.banner.err { background: var(--err-bg); color: var(--err); }

.stats { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); }
.stat { background: var(--soft); border-radius: 8px; padding: 14px; display: flex; flex-direction: column; gap: 4px; }
.stat b { font-family: var(--mono); font-size: 22px; font-weight: 600; }

/* ---------- login ---------- */
.login { display: flex; flex-wrap: wrap; min-height: 100vh; }
.login .hero { flex: 1 1 420px; background: var(--side); color: var(--side-text); padding: 56px 48px; display: flex; flex-direction: column; justify-content: space-between; gap: 40px; }
.login .hero h1 { font-size: 38px; line-height: 1.12; color: #fff; max-width: 480px; }
.login .hero p { color: #C9CDD1; max-width: 460px; line-height: 1.6; }
.login .feats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; font-size: 13px; color: #C9CDD1; }
.login .feats div { border-top: 1px solid var(--side-line); padding-top: 12px; display: flex; flex-direction: column; gap: 6px; }
.login .feats span { font-family: var(--mono); color: var(--accent-2); }
.login .form-side { flex: 1 1 420px; display: flex; align-items: center; justify-content: center; padding: 48px 16px; }
.login form { width: 100%; max-width: 400px; display: flex; flex-direction: column; gap: 18px; }

/* ---------- toasts ---------- */
#toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 50; max-width: calc(100vw - 32px); }
.toast { background: var(--ink); color: #fff; border-radius: 8px; padding: 12px 16px; font-size: 14px; box-shadow: 0 6px 20px rgba(0, 0, 0, .2); max-width: 420px; }
.toast.err { background: var(--err); }
.toast.ok { background: var(--ok); }

/* ---------- responsive ---------- */
@media (max-width: 860px) {
  .shell { flex-direction: column; }
  .side { display: none; width: auto; height: auto; position: static; }
  .side.open { display: flex; }
  .topbar { display: flex; align-items: center; justify-content: space-between; gap: 8px; background: var(--side); color: #fff; padding: 8px 12px 8px 16px; position: sticky; top: 0; z-index: 10; }
  .topbar .brand { padding: 0; }
  .topbar button { background: transparent; border: 0; color: #fff; width: 44px; height: 44px; cursor: pointer; }
  .main { padding: 18px 16px 48px; }
  .page-head [data-status] { display: none; }
  .grid { --n: 2 !important; }
  .summary { position: static; max-height: none; }
  .login .hero { padding: 32px 20px; }
  .login .hero h1 { font-size: 28px; }
  .login .feats { grid-template-columns: 1fr; }
}
/* ---------- celular ---------- */
.mbar { display: none; }
@media (max-width: 860px) {
  /* Barra superior en una sola línea: logo · estado (compacto) · menú */
  .topbar { min-height: 56px; flex-wrap: nowrap; padding: 6px 6px 6px 14px !important; }
  .topbar .brand { flex: 0 1 auto; min-width: 0; gap: 8px; font-size: 16px; }
  .topbar .brand img { flex: none; }
  .topbar .brand span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .topbar .row { flex: none; flex-wrap: nowrap; gap: 2px; }
  .topbar .pill { font-size: 12px; padding: 5px 10px; gap: 6px; white-space: nowrap; }
  .topbar .pill-x { display: none; }
  /* Menú: se abre encima de la página, debajo de la barra superior */
  .side.open { position: fixed; top: 56px; left: 0; right: 0; bottom: 0; z-index: 40; overflow-y: auto; height: auto; padding-top: 12px; }
  .side .brand-logo { display: none; }
  .side .nav a { padding: 13px 12px; font-size: 16px; }
  .side-foot .linkbtn { padding: 10px 0; }
  /* Pestañas de Catálogos en una sola línea que se desliza */
  .tabs { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch; margin: 0 -16px; padding: 0 16px; }
  .tabs::-webkit-scrollbar { display: none; }
  .tabs a { white-space: nowrap; flex: none; padding: 0 12px; }
  /* Vehículos en dos columnas compactas */
  .pick { grid-template-columns: 1fr 1fr; gap: 8px; }
  .pick label { padding: 10px; gap: 4px; }
  .pick label:has(input:checked) { padding: 9px; }
  .pick .t { font-size: 14px; align-items: flex-start; }
  .pick .t input { margin-top: 1px; flex: none; }
  .pick .small { font-size: 12px; }
  /* Barra inferior con el total mientras se captura la cotización */
  .mbar { display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; align-items: center; justify-content: space-between; gap: 12px;
    background: var(--side); color: #fff; padding: 10px 16px calc(10px + env(safe-area-inset-bottom)); box-shadow: 0 -6px 18px rgba(0, 0, 0, .18); }
  .mbar.hide { display: none; }
  .mbar .tot-l { font-size: 11px; letter-spacing: .06em; text-transform: uppercase; color: var(--side-muted); }
  .mbar .tot { font-family: var(--mono); font-size: 20px; font-weight: 600; }
  .mbar .btn { background: var(--accent-2); border-color: var(--accent-2); color: var(--ink); min-height: 42px; white-space: nowrap; }
  .main:has(.mbar:not(.hide)) { padding-bottom: 90px; }
  body.has-mbar #toasts { bottom: 84px; }
}
/* Tablas como tarjetas en celular (una tarjeta por renglón, con el nombre de cada dato) */
@media (max-width: 760px) {
  .table-wrap.stack { overflow-x: visible; }
  .stack table, .stack tbody, .stack tfoot, .stack tr, .stack td { display: block; width: 100%; }
  .stack thead { display: none; }
  .stack tr { padding: 10px 14px; border-top: 1px solid var(--line-2); }
  .stack tbody tr:first-child { border-top: 0; }
  .stack td { display: grid; grid-template-columns: minmax(84px, 40%) minmax(0, 1fr); column-gap: 14px; align-items: center; padding: 4px 0; border: 0; text-align: right !important; min-height: 28px; }
  .stack td::before { content: attr(data-label); grid-column: 1; grid-row: 1 / span 4; text-align: left; font-family: var(--sans); font-size: 12px; font-weight: 500; color: var(--muted); letter-spacing: 0; }
  .stack td > * { grid-column: 2; justify-self: end; min-width: 0; max-width: 100%; }
  .stack td[data-label=""] { grid-template-columns: minmax(0, 1fr); }
  .stack td[data-label=""]::before { display: none; }
  .stack td[data-label=""] > * { grid-column: 1; }
  .stack td select { width: auto !important; min-width: 150px; max-width: 100%; }
  .stack tbody td:first-child { font-weight: 600; }
  .stack tfoot tr { border-top: 2px solid var(--line); background: var(--soft); border-radius: 0 0 10px 10px; }
  .stack tfoot td { font-weight: 700; }
  tr.click:hover td { background: transparent; }
}
@media (max-width: 480px) {
  .grid { --n: 1 !important; }
  .span2 { grid-column: auto; }
  .leg .box { grid-template-columns: 1fr 1fr; }
  .indent { margin-left: 0; }
  .extra { grid-template-columns: minmax(0, 1fr) 110px 42px; }
  .pt { grid-template-columns: 1fr; }
  .stop-gap { display: none; }
}

@media print {
  .side, .topbar, .no-print, #toasts { display: none !important; }
  body { background: #fff; }
  .main { padding: 0; }
  .table-wrap, .card { border: 0; }
}
