:root {
  --bg: #f4f6f9;
  --card: #ffffff;
  --ink: #1f2933;
  --muted: #6b7280;
  --line: #e2e8f0;
  --brand: #0f2b46;
  --brand-2: #c9a227;
  --primary: #2563eb;
  --danger: #dc2626;
  --ok: #16a34a;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(15, 23, 42, .08), 0 1px 2px rgba(15, 23, 42, .04);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: var(--bg);
  line-height: 1.45;
}
h1 { font-size: 1.6rem; margin: 0; }
h2 { font-size: 1.05rem; margin: 0 0 .75rem; }
h3 { font-size: .95rem; margin: 0 0 .5rem; }
a { color: var(--primary); text-decoration: none; }
.muted { color: var(--muted); font-weight: 400; font-size: .85rem; }
.hidden { display: none !important; }

/* ---------- Topbar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 1rem; padding: .6rem 1.25rem; background: var(--brand); color: #fff;
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: .55rem; color: #fff; }
.brand-mark {
  display: inline-grid; place-items: center; width: 34px; height: 34px;
  border: 2px solid var(--brand-2); color: var(--brand-2);
  font-weight: 800; border-radius: 8px; font-size: .85rem;
}
.brand-text { font-weight: 700; letter-spacing: .3px; }
.brand-text em { color: var(--brand-2); font-style: normal; }
.topnav { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; }
.topnav a { color: #dbe4ee; font-size: .9rem; }
.topnav a:hover { color: #fff; }
.nav-user { color: var(--brand-2); font-size: .85rem; font-weight: 600; }
.inline { display: inline; }

/* ---------- Layout ---------- */
.container { max-width: 1000px; margin: 1.5rem auto; padding: 0 1.25rem; }
.container.narrow { max-width: 620px; }
.page-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1.25rem; gap: 1rem; flex-wrap: wrap; }
.inline-actions { display: flex; gap: .5rem; }

.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 1.1rem 1.25rem; box-shadow: var(--shadow); margin-bottom: 1.1rem;
}

/* ---------- Forms ---------- */
label { display: block; font-size: .82rem; font-weight: 600; color: #374151; margin-bottom: .3rem; }
input, select, textarea {
  width: 100%; padding: .5rem .6rem; border: 1px solid var(--line); border-radius: 8px;
  font: inherit; color: var(--ink); background: #fff; margin-top: .2rem;
}
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(37,99,235,.35); border-color: var(--primary); }
label.check, label.radio-inline { display: inline-flex; align-items: center; gap: .4rem; font-weight: 600; }
label.check input, label.radio-inline input { width: auto; margin: 0; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: .85rem; }
.full { grid-column: 1 / -1; }
textarea { resize: vertical; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  padding: .5rem .9rem; border: 1px solid transparent; border-radius: 8px;
  font: inherit; font-weight: 600; cursor: pointer; background: #eef2f7; color: var(--ink);
}
.btn:hover { filter: brightness(.97); }
.btn:disabled { opacity: .6; cursor: default; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-secondary { background: var(--brand); color: #fff; }
.btn-ghost { background: transparent; border-color: var(--line); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-sm { padding: .3rem .6rem; font-size: .8rem; }
.btn-lg { padding: .7rem 1.6rem; font-size: 1.05rem; }

/* ---------- Segmented service type ---------- */
.seg { display: grid; grid-template-columns: 1fr 1fr; gap: .6rem; margin-bottom: 1rem; }
.seg-opt { display: block; border: 1px solid var(--line); border-radius: 10px; padding: .7rem .8rem; cursor: pointer; font-weight: 600; margin: 0; }
.seg-opt input { width: auto; margin-right: .4rem; }
.seg-opt small { display: block; color: var(--muted); font-weight: 400; margin-top: .2rem; }
.seg-opt:has(input:checked) { border-color: var(--primary); box-shadow: 0 0 0 2px rgba(37,99,235,.15); }

/* ---------- Map / locations ---------- */
.loc-list { display: flex; flex-direction: column; gap: .6rem; margin-bottom: .8rem; }
.loc-block { border: 1px solid var(--line); border-radius: 10px; padding: .7rem .8rem; }
.stop-block { border-left: 3px solid #f59e0b; background: #fffdf7; }
.loc-head { display: flex; align-items: center; justify-content: space-between; gap: .6rem; margin-bottom: .5rem; flex-wrap: wrap; }
.loc-head h3 { margin: 0; }
.loc-head-actions { display: flex; align-items: center; gap: .6rem; }
#stops-container { display: flex; flex-direction: column; gap: .6rem; }
#add-stop { align-self: flex-start; }
.addr-row { display: flex; gap: .4rem; align-items: flex-start; }
.addr-row input { flex: 1; }
.coords { font-size: .8rem; color: var(--muted); margin-top: .4rem; font-variant-numeric: tabular-nums; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: .3rem; vertical-align: middle; }
.dot-origin { background: #2563eb; } .dot-end { background: #16a34a; } .dot-stop { background: #f59e0b; }
.map-toolbar { display: flex; align-items: center; gap: 1rem; margin: .5rem 0; flex-wrap: wrap; }
.map { height: 340px; border-radius: 10px; border: 1px solid var(--line); margin-bottom: .9rem; z-index: 0; }
.km-line { display: flex; align-items: flex-end; gap: .8rem; flex-wrap: wrap; grid-column: 1 / -1; }
.km-field { margin: 0; }
.pin span { display: block; width: 16px; height: 16px; border-radius: 50%; border: 2px solid #fff; box-shadow: 0 0 3px rgba(0,0,0,.5); }

/* ---------- Total ---------- */
.total-card { position: sticky; bottom: 0; }
.total-box { display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.total-computed strong { display: block; font-size: 2rem; color: var(--brand); }
.total-computed .breakdown { font-size: .8rem; color: var(--muted); }
.override { max-width: 220px; }
.actions { margin-top: 1rem; }

/* ---------- Table ---------- */
.table-wrap { overflow-x: auto; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.table { width: 100%; border-collapse: collapse; min-width: 640px; }
.table th, .table td { text-align: left; padding: .65rem .8rem; border-bottom: 1px solid var(--line); font-size: .9rem; }
.table th { background: #f8fafc; font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.table tbody tr:hover, .table tr:hover { background: #f8fafc; }
.num { text-align: right; }
.table input, .table select { margin: 0; }

.tag { display: inline-block; padding: .15rem .5rem; border-radius: 999px; font-size: .75rem; font-weight: 700; }
.tag.sinistrado { background: #fee2e2; color: #b91c1c; }
.tag.assistencia { background: #dbeafe; color: #1d4ed8; }

.empty { background: var(--card); border: 1px dashed var(--line); border-radius: var(--radius); padding: 2.5rem; text-align: center; color: var(--muted); }

.base-row { display: flex; gap: .5rem; flex-wrap: wrap; align-items: flex-end; margin-bottom: .6rem; }
.base-row .f { flex: 1; min-width: 120px; margin: 0; }
.base-select-label { display: block; max-width: 320px; margin-bottom: .8rem; }

.filters { display: flex; align-items: flex-end; gap: .75rem; flex-wrap: wrap; }
.filters label { margin: 0; }
.filters input { width: auto; }
.filters .btn { margin-left: 0; }
.filters #export-btn { margin-left: auto; }

/* ---------- Alerts ---------- */
.alert { padding: .6rem .8rem; border-radius: 8px; font-size: .88rem; margin: .5rem 0; }
.alert-error { background: #fef2f2; color: #b91c1c; border: 1px solid #fecaca; }
.alert-ok { background: #f0fdf4; color: #15803d; border: 1px solid #bbf7d0; }

/* ---------- Login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; background: linear-gradient(135deg, #0f2b46, #1e3a5f); padding: 1rem; }
.login-card { background: #fff; padding: 2rem; border-radius: 16px; width: 100%; max-width: 360px; box-shadow: 0 10px 40px rgba(0,0,0,.25); }
.login-brand { text-align: center; margin-bottom: 1.2rem; }
.login-brand h1 { font-size: 1.3rem; margin: .6rem 0 .1rem; }
.login-brand em { color: var(--brand-2); font-style: normal; }
.login-brand .brand-mark { margin: 0 auto; width: 46px; height: 46px; font-size: 1.05rem; }
.login-card label { margin-bottom: .8rem; }
.login-card .btn { width: 100%; margin-top: .4rem; }

/* ---------- Detail ---------- */
.detail-sheet { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.5rem; box-shadow: var(--shadow); }
.detail-head { display: flex; align-items: center; justify-content: space-between; padding-bottom: 1rem; border-bottom: 2px solid var(--line); margin-bottom: 1rem; }
.detail-total { font-size: 1.5rem; font-weight: 800; color: var(--brand); }
.detail-sub { margin: 1.4rem 0 .6rem; padding-bottom: .3rem; border-bottom: 1px solid var(--line); color: var(--brand); }
.detail-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: .3rem .9rem; }
.drow { display: flex; justify-content: space-between; gap: 1rem; padding: .35rem 0; border-bottom: 1px dotted var(--line); font-size: .9rem; }
.dlabel { color: var(--muted); }
.dval { font-weight: 600; text-align: right; }
.obs { background: #f8fafc; padding: .8rem; border-radius: 8px; white-space: pre-wrap; }
.detail-foot { display: flex; justify-content: space-between; align-items: flex-end; margin-top: 1.5rem; padding-top: 1rem; border-top: 2px solid var(--line); flex-wrap: wrap; gap: 1rem; }
.signature { border-top: 1px solid var(--ink); padding-top: .3rem; min-width: 220px; text-align: center; font-size: .85rem; }

@media (max-width: 640px) {
  .seg, .loc-grid { grid-template-columns: 1fr; }
}
@media print {
  .topbar, .page-head .inline-actions, .btn { display: none !important; }
  body { background: #fff; }
  .detail-sheet { border: none; box-shadow: none; }
}
