:root {
  --sidebar: #1a1a2e;
  --sidebar-hover: #2a2a4a;
  --primary: #6c63ff;
  --primary-dark: #554be8;
  --surface: #ffffff;
  --canvas: #f5f5f0;
  --border: #e8e8e4;
  --text: #1a1a1a;
  --muted: #777777;
  --danger: #dc3545;
  --success: #198754;
  --shadow: 0 8px 24px rgba(26, 26, 46, 0.06);
}

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body { font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; font-size: 15px; line-height: 1.5; color: var(--text); background: var(--canvas); }
a { color: inherit; }
button, input, select { font: inherit; }

.layout { display: flex; min-height: 100vh; }
.sidebar { width: 252px; flex: 0 0 252px; display: flex; flex-direction: column; color: #bbb; background: var(--sidebar); }
.sidebar-brand { display: flex; align-items: center; gap: 12px; padding: 18px 20px 16px; border-bottom: 1px solid #2a2a4a; }
.brand-mark { width: 42px; height: 42px; display: grid; place-items: center; flex: 0 0 42px; overflow: hidden; border-radius: 10px; background: #fff; }
.brand-mark img { width: 100%; height: 100%; object-fit: contain; }
.brand-title { color: #fff; font-size: 17px; font-weight: 650; line-height: 1.2; }
.brand-subtitle { margin-top: 2px; color: #8298ff; font-size: 12px; }
.sidebar nav { flex: 1; padding: 10px 0; }
.nav-section { padding: 14px 20px 5px; color: #68687f; font-size: 10px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; }
.nav-link { display: flex; align-items: center; gap: 10px; padding: 10px 20px; border-left: 3px solid transparent; color: #aaa; font-size: 14px; text-decoration: none; transition: .15s ease; }
.nav-link:hover { color: #fff; background: var(--sidebar-hover); }
.nav-link.active { color: #fff; border-left-color: var(--primary); background: var(--sidebar-hover); }
.nav-link.disabled { opacity: .65; cursor: default; }
.nav-icon { width: 17px; text-align: center; }
.sidebar-footer { padding: 14px 20px; border-top: 1px solid #2a2a4a; color: #7f7f95; font-size: 11px; }
.status-dot { display: inline-block; width: 7px; height: 7px; margin-right: 6px; border-radius: 50%; background: #31c48d; }

.main { min-width: 0; flex: 1; display: flex; flex-direction: column; }
.topbar { min-height: 68px; display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 11px 28px; border-bottom: 1px solid var(--border); background: var(--surface); }
.topbar-heading { display: flex; align-items: center; gap: 12px; }
.topbar-title { font-size: 17px; font-weight: 650; }
.topbar-subtitle { margin-top: 1px; color: #999; font-size: 12px; }
.topbar-actions { display: flex; gap: 8px; }
.menu-button { display: none; padding: 5px 8px; border: 1px solid var(--border); border-radius: 7px; background: #fff; cursor: pointer; }
.content { flex: 1; padding: 24px 28px 40px; overflow: auto; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 8px 14px; border: 1px solid #ddd; border-radius: 7px; color: #333; background: #fff; font-size: 13px; text-decoration: none; cursor: pointer; transition: .15s ease; }
.btn:hover { background: #f5f5f0; }
.btn-primary { border-color: var(--primary); color: #fff; background: var(--primary); }
.btn-primary:hover { background: var(--primary-dark); }

.notice { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 18px; padding: 12px 16px; border: 1px solid #cbd6ff; border-radius: 9px; color: #373083; background: #eef1ff; font-size: 13px; }
.notice-success { border-color: #b8e1c8; color: #146c43; background: #eaf7ee; }
.notice-error { border-color: #f1b8be; color: #8a1c27; background: #fff0f1; }
.badge { display: inline-flex; align-items: center; white-space: nowrap; padding: 3px 9px; border-radius: 999px; font-size: 11px; font-weight: 650; }
.badge-blue { color: #3d35b0; background: #dfe3ff; }
.badge-green { color: #146c43; background: #e5f5eb; }

.metrics-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 18px; }
.metric-card, .card { border: 1px solid var(--border); border-radius: 10px; background: var(--surface); box-shadow: var(--shadow); }
.metric-card { padding: 17px 20px; }
.metric-label { color: #888; font-size: 12px; }
.metric-value { margin-top: 3px; font-size: 28px; font-weight: 600; line-height: 1.25; }
.metric-value.compact { padding: 6px 0 5px; font-size: 18px; }
.metric-value.danger { color: var(--danger); }
.metric-sub { margin-top: 3px; color: #aaa; font-size: 11px; }

.dashboard-grid { display: grid; grid-template-columns: minmax(0, 1.45fr) minmax(280px, .75fr); gap: 16px; }
.card { padding: 20px 24px; }
.card-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 10px; padding-bottom: 14px; border-bottom: 1px solid #f0f0ec; }
.card-title { margin: 0; font-size: 15px; font-weight: 650; }
.card-description { margin: 3px 0 0; color: #999; font-size: 12px; }
.module-list { display: grid; }
.module-row { display: grid; grid-template-columns: 34px 1fr auto; align-items: center; gap: 10px; padding: 12px 2px; border-bottom: 1px solid #f5f5f1; }
.module-row:last-child { border-bottom: 0; }
.module-row strong { display: block; font-size: 13px; font-weight: 600; }
.module-row small { display: block; margin-top: 1px; color: #999; }
.module-icon { width: 32px; height: 32px; display: grid; place-items: center; border-radius: 8px; color: var(--primary); background: #efefff; }
.status-list { margin: 0; }
.status-list > div { display: flex; justify-content: space-between; gap: 16px; padding: 10px 0; border-bottom: 1px solid #f5f5f1; }
.status-list > div:last-child { border: 0; }
.status-list dt { color: #888; font-size: 12px; }
.status-list dd { margin: 0; font-size: 12px; font-weight: 600; text-align: right; }
.status-list a { color: var(--primary); text-decoration: none; }

.search-bar { display: flex; align-items: center; gap: 8px; margin-bottom: 16px; }
.search-bar input { min-width: 180px; flex: 1; }
.search-bar input, .search-bar select { padding: 8px 11px; border: 1px solid #ddd; border-radius: 7px; color: #333; background: #fff; font-size: 13px; }
.search-bar input:focus, .search-bar select:focus { outline: 2px solid rgba(108, 99, 255, .16); border-color: var(--primary); }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { padding: 9px 12px; border-bottom: 1px solid #f0f0ec; color: #888; font-size: 11px; font-weight: 650; letter-spacing: .04em; text-align: left; text-transform: uppercase; }
td { padding: 11px 12px; border-bottom: 1px solid #f8f8f5; font-size: 13px; }
tr:hover td { background: #fafaf7; }
.empty-row:hover td { background: transparent; }
.empty-row td { padding: 52px 20px; color: #777; text-align: center; }
.empty-row strong, .empty-row span { display: block; }
.empty-row span { margin-top: 4px; color: #aaa; font-size: 12px; }
.sidebar-backdrop { display: none; }

.report-links { margin-top: 18px; }
.print-heading { display: none; }
.detail-grid { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(300px, .85fr); gap: 16px; }
.stacked-grid { display: grid; grid-template-columns: 1fr; gap: 16px; }
.table-compact th, .table-compact td { padding: 8px 8px; }
.table-compact th { font-size: 10px; }
.table-compact td { font-size: 12.5px; }
.edit-form label { display: flex; flex-direction: column; gap: 5px; color: #666; font-size: 12px; font-weight: 600; }
.field-help { color: #999; font-size: 11px; font-weight: 400; }
.debt-summary { margin: 18px 0; padding: 16px; border: 1px solid #cbd6ff; border-radius: 10px; background: #f7f8ff; }
.debt-summary .card-header { margin-bottom: 10px; padding-bottom: 10px; }
.debt-summary-total { color: #373083; font-size: 20px; }
.debt-summary-clear { margin: 8px 0 0; color: #146c43; font-size: 13px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 13px; }
.form-grid input, .form-grid select, .form-grid textarea { width: 100%; padding: 9px 10px; border: 1px solid #ddd; border-radius: 7px; color: #333; background: #fff; font-size: 13px; font-weight: 400; }
.form-grid input:focus, .form-grid select:focus, .form-grid textarea:focus { outline: 2px solid rgba(108, 99, 255, .16); border-color: var(--primary); }
.form-grid input[readonly] { color: #888; background: #f5f5f0; }
.form-span-2 { grid-column: span 2; }
.form-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; padding-top: 16px; border-top: 1px solid #f0f0ec; }
.vehicle-detail { padding: 13px 0; border-bottom: 1px solid #f0f0ec; }
.vehicle-detail:last-child { border-bottom: 0; }
.vehicle-detail-heading { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.vehicle-meta { margin-top: 4px; color: #888; font-size: 12px; }
.driver-list { display: grid; gap: 4px; margin-top: 9px; color: #555; font-size: 12px; }
.badge-muted { color: #666; background: #ededed; }
.payment-summary { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-top: 18px; padding: 14px 16px; border: 1px solid #99f6e4; border-radius: 8px; color: #115e59; background: #f0fdfa; }
.payment-summary-label { display: block; font-size: 12px; }
.payment-summary-total { display: block; margin-top: 2px; font-size: 22px; }
.payment-summary p { margin: 0; color: #0f766e; font-size: 12px; text-align: right; }

@media print {
  .sidebar, .topbar, .no-print { display: none !important; }
  .layout, .main { display: block; min-height: auto; }
  .content { padding: 0; overflow: visible; }
  .card, .metric-card { border: 0; box-shadow: none; }
  .print-report { padding: 0; }
  .print-heading { display: flex; flex-direction: column; margin-bottom: 16px; color: #000; }
  .print-heading strong { font-size: 18px; }
  .print-heading span { font-size: 14px; }
  .print-heading small { margin-top: 8px; color: #555; }
  table { font-size: 10pt; }
  th, td { padding: 6px 8px; }
}

/* ---------- Tema por programa ----------
   El color principal cambia según el programa activo, para que se note de
   un vistazo en cuál de los dos se está trabajando. */
body[data-programa="remises"] {
  --primary: #0e9488;
  --primary-dark: #0b7d72;
}
body[data-programa="remises"] .brand-subtitle { color: #5fd8cc; }
body[data-programa="remises"] .module-icon { background: #e2f7f4; }
body[data-programa="remises"] .notice { border-color: #b6e6e0; color: #0b5b54; background: #e8f8f6; }
body[data-programa="remises"] .badge-blue { color: #0b5b54; background: #cfeeea; }
body[data-programa="remises"] .search-bar input:focus,
body[data-programa="remises"] .search-bar select:focus { outline-color: rgba(14, 148, 136, .18); }

.brand-initial { color: var(--primary); font-size: 20px; font-weight: 700; }
.badge-amber { color: #8a5a00; background: #fdf0d5; }

/* ---------- Botón para cambiar de programa ---------- */
.switch-program {
  display: flex; align-items: center; gap: 9px;
  margin: 12px 14px 4px; padding: 9px 12px;
  border: 1px solid #33334f; border-radius: 8px;
  color: #cfcfe4; background: #22223c;
  font-size: 12.5px; text-decoration: none;
  transition: .15s ease;
}
.switch-program:hover { color: #fff; border-color: var(--primary); background: #2a2a4a; }
.switch-icon { font-size: 14px; }

/* ---------- Pantalla de selección de programa ---------- */
.selector-body { position: relative; display: grid; place-items: center; min-height: 100vh; padding: 42px 20px 24px; background: var(--canvas); }
.selector-comuna-logo { position: absolute; top: 24px; left: 28px; width: 76px; height: 76px; display: grid; place-items: center; padding: 6px; border: 1px solid #e5e7eb; border-radius: 16px; background: #fff; box-shadow: 0 8px 22px rgba(26, 26, 46, .10); }
.selector-comuna-logo img { width: 100%; height: 100%; object-fit: contain; }
.selector { width: 100%; max-width: 1100px; }
.login-panel { width: 100%; max-width: 400px; padding: 30px 28px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); box-shadow: var(--shadow); }
.login-panel .selector-header { margin-bottom: 22px; }
.login-form { display: grid; gap: 14px; }
.login-form label { display: flex; flex-direction: column; gap: 5px; color: #666; font-size: 12px; font-weight: 600; }
.login-form input { width: 100%; padding: 10px 11px; border: 1px solid #ddd; border-radius: 7px; color: #333; background: #fff; font-size: 14px; font-weight: 400; }
.login-form input:focus { outline: 2px solid rgba(108, 99, 255, .16); border-color: var(--primary); }
.login-form .btn { width: 100%; }
.logout-form { display: flex; flex-direction: column; gap: 5px; margin-top: 10px; }
.logout-usuario { color: #8298ff; font-size: 11px; font-weight: 600; }
.logout-boton { padding: 6px 10px; border: 1px solid #3a3a5a; border-radius: 6px; color: #bbb; background: transparent; font-size: 11px; cursor: pointer; transition: .15s ease; }
.logout-boton:hover { color: #fff; background: var(--sidebar-hover); }
.selector-header { margin-bottom: 30px; text-align: center; }
.selector-crest {
  width: 82px; height: 82px; display: grid; place-items: center; margin: 0 auto 15px;
  border-radius: 22px; background: #fff; overflow: hidden;
  box-shadow: 0 8px 22px rgba(26, 26, 46, .12); border: 1px solid #e5e7eb;
}
.selector-crest img { width: 100%; height: 100%; object-fit: contain; }
.selector-eyebrow { margin: 0 0 4px; color: #697386; font-size: 12px; font-weight: 700; letter-spacing: .14em; text-transform: uppercase; }
.selector-header h1 { margin: 0; font-size: 30px; font-weight: 750; letter-spacing: -.02em; color: #1a1a2e; }
.selector-header p { margin: 7px 0 0; color: var(--muted); font-size: 14px; }

.selector-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.selector-card {
  display: flex; flex-direction: column; padding: 24px;
  border: 1px solid var(--border); border-top: 3px solid var(--primary); border-radius: 12px;
  background: var(--surface); box-shadow: var(--shadow);
  color: inherit; text-decoration: none;
  transition: transform .16s ease, box-shadow .16s ease;
}
.selector-card:hover { transform: translateY(-3px); box-shadow: 0 14px 32px rgba(26, 26, 46, .12); }
.selector-card-remises { --primary: #0e9488; }
.selector-mark {
  width: 52px; height: 52px; display: grid; place-items: center; margin-bottom: 14px;
  border: 1px solid var(--border); border-radius: 12px; background: #fff; overflow: hidden;
}
.selector-mark img { width: 100%; height: 100%; object-fit: contain; }
.selector-card h2 { margin: 0 0 6px; font-size: 19px; font-weight: 650; }
.selector-card > p { margin: 0 0 14px; color: var(--muted); font-size: 13px; }
.selector-card ul { margin: 0 0 18px; padding: 0; list-style: none; }
.selector-card li { position: relative; padding: 4px 0 4px 18px; color: #555; font-size: 12.5px; }
.selector-card li::before { position: absolute; left: 0; color: var(--primary); content: "▸"; }
.selector-go { margin-top: auto; color: var(--primary); font-size: 13px; font-weight: 650; }
.selector-footer { margin-top: 24px; color: #aaa; font-size: 12px; text-align: center; }

@media (max-width: 1024px) {
  .metrics-grid { grid-template-columns: repeat(2, 1fr); }
  .dashboard-grid { grid-template-columns: 1fr; }
  .detail-grid { grid-template-columns: 1fr; }
}

@media (max-width: 760px) {
  .selector-grid { grid-template-columns: 1fr; }
  .selector-header h1 { font-size: 22px; }
  .selector-comuna-logo { top: 14px; left: 14px; width: 58px; height: 58px; padding: 4px; }
}

@media (max-width: 760px) {
  .sidebar { position: fixed; inset: 0 auto 0 0; z-index: 30; transform: translateX(-100%); transition: transform .2s ease; }
  .sidebar-open .sidebar { transform: translateX(0); }
  .sidebar-open .sidebar-backdrop { display: block; position: fixed; inset: 0; z-index: 20; background: rgba(0, 0, 0, .38); }
  .menu-button { display: inline-flex; }
  .topbar { padding: 10px 16px; }
  .topbar-subtitle { display: none; }
  .content { padding: 18px 14px 30px; }
  .metrics-grid { grid-template-columns: 1fr; }
  .notice, .search-bar { align-items: stretch; flex-direction: column; }
  .payment-summary { align-items: flex-start; flex-direction: column; }
  .payment-summary p { text-align: left; }
  .card { padding: 17px 16px; }
  .module-row { grid-template-columns: 34px 1fr; }
  .module-row .badge { grid-column: 2; justify-self: start; }
  .form-grid { grid-template-columns: 1fr; }
  .form-span-2 { grid-column: auto; }
}

/* El backend guarda todo el texto en mayúsculas (ver app/db/base.py);
   esto solo adelanta el mismo efecto visualmente mientras se escribe. */
