:root {
  --bg: #f3f5f1; --card: #fff; --ink: #14201a; --soft: #55635b; --line: #d2dad1; --field: #fff;
  --num: #12372a; --go: #0f7a4b; --accent: #0b6b41; --urgent: #c22a12; --urgent-ink: #c22a12; --warn-bg: #fff1cc; --warn: #6b4700; --fab: #fff; --me: #1d63e0;
  --sheet: 150px; --top: env(safe-area-inset-top, 0px); --bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #0f1512; --card: #18211d; --ink: #eaf2ed; --soft: #a0b0a7; --line: #2d3a33; --field: #1f2a25;
  --num: #35594a; --go: #12804f; --accent: #54d39a; --urgent: #d8452c; --urgent-ink: #ff8d78; --warn-bg: #3a2d08; --warn: #ffdf8f; --fab: #18211d; --me: #4b8dff;
  color-scheme: dark;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; overflow: hidden; overscroll-behavior: none; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 17px/1.4 system-ui, sans-serif; -webkit-tap-highlight-color: transparent; }
h1, h2, h3, p { margin: 0; }
.i { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
button, input, textarea, select, .nav { font: inherit; border-radius: 12px; min-height: 48px; }
button, .nav { border: 1px solid var(--line); background: var(--card); color: var(--ink); padding: 8px 14px; cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; justify-content: center; gap: 8px; text-align: center; }
button.main, .nav { background: var(--go); border-color: var(--go); color: #fff; font-weight: 600; }
.nav.plain { background: var(--card); color: var(--ink); border-color: var(--go); }
button.danger { color: var(--urgent-ink); }
button[aria-pressed="true"] { border-color: var(--accent); color: var(--accent); }
.ico { border: 0; background: none; padding: 0; width: 48px; flex: none; }
input, textarea, select { border: 1px solid var(--soft); background: var(--field); color: var(--ink); padding: 10px 12px; }
input[type="radio"], input[type="checkbox"] { min-height: 0; width: 26px; height: 26px; accent-color: var(--go); flex: none; margin: 0; }
:focus-visible { outline: 3px solid #f0a500; outline-offset: 2px; }
small { color: var(--soft); font-weight: 400; display: block; font-size: .85rem; }
label { font-weight: 600; }
.tip { color: var(--soft); font-size: .92rem; }
.warn { background: var(--warn-bg); color: var(--warn); border-radius: 10px; padding: 8px 12px; }
.acts { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.acts.three { grid-template-columns: repeat(3, 1fr); }
.acts.three button { flex-direction: column; gap: 2px; color: var(--accent); }
.line { display: flex; flex-wrap: wrap; gap: 8px; }
.line > input { flex: 1 0 100%; }
.line > button { flex: 1; }
.hints { display: grid; gap: 6px; }
.hints:empty { display: none; }
.hints button { justify-content: flex-start; text-align: left; }
.hints button span { min-width: 0; overflow-wrap: anywhere; }

/* Mapa */
#map { position: fixed; inset: 0; z-index: 0; background: var(--bg); }
:root[data-theme="dark"] .streets { filter: invert(1) hue-rotate(180deg) saturate(.55) brightness(.85) contrast(.92); }
.leaflet-top { padding-top: var(--top); }
.leaflet-container .leaflet-control-attribution { font-size: 10px; background: color-mix(in srgb, var(--card) 75%, transparent); color: var(--soft); max-width: 60vw; }
.fab { border-radius: 50%; width: 52px; height: 52px; padding: 0; background: var(--fab); box-shadow: 0 2px 10px #0005; color: var(--accent); }
#menuBtn { position: fixed; top: calc(var(--top) + 14px); left: 14px; z-index: 3; color: var(--ink); }
#fabs { position: fixed; right: 14px; bottom: calc(var(--sheet) + 14px); z-index: 2; display: grid; gap: 10px; transition: bottom .25s; }
body.drag #fabs, body.drag #sheet { transition: none; }
body.sheet-full #fabs { visibility: hidden; }
.num, .pin { background: var(--num); color: #fff; font-weight: 700; font-variant-numeric: tabular-nums; display: grid; place-items: center; }
.pin { width: 30px; height: 30px; border-radius: 9px; border: 2px solid #fff; box-shadow: 0 1px 4px #0008; font-size: 14px; }
.pin.urgent { background: var(--urgent); }
.pin.depot { background: #1d4fd8; }
.pin.flag { background: #5b3cc4; }
.pin.gone { width: 14px; height: 14px; margin: 8px; opacity: .6; border-width: 1px; }
.me { width: 20px; height: 20px; border-radius: 50%; background: var(--me); border: 3px solid #fff; box-shadow: 0 0 0 8px color-mix(in srgb, var(--me) 25%, transparent); }
#pick { position: fixed; inset: 0; z-index: 4; pointer-events: none; }
#pick .cross { position: absolute; left: 50%; top: 50%; width: 46px; height: 46px; transform: translate(-50%, -92%); color: var(--urgent); fill: #fff; stroke-width: 1.6; }
.pickbar { pointer-events: auto; position: absolute; inset: auto 0 0; background: var(--bg); padding: 16px 16px calc(16px + var(--bottom)); border-radius: 20px 20px 0 0; display: grid; gap: 12px; box-shadow: 0 -4px 20px #0004; }

/* Panel */
#sheet { position: fixed; inset: auto 0 0; height: var(--sheet); z-index: 3; background: var(--bg); border-radius: 20px 20px 0 0; box-shadow: 0 -4px 20px #0004; display: flex; flex-direction: column; transition: height .25s; overflow: hidden; }
#head { touch-action: none; padding: 0 8px 6px 16px; flex: none; cursor: grab; }
#grip { display: block; width: 100%; min-height: 22px; border: 0; background: none; padding: 0; position: relative; }
#grip::after { content: ""; position: absolute; left: 50%; top: 9px; width: 52px; height: 4px; border-radius: 2px; background: var(--soft); transform: translateX(-50%); opacity: .6; }
.top { display: flex; align-items: center; }
.names { flex: 1; min-width: 0; }
#title { font-size: 1.15rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#summary { color: var(--soft); font-size: .95rem; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#progress { display: block; width: calc(100% - 8px); height: 5px; margin-top: 4px; accent-color: var(--go); }
#scroll { flex: 1; overflow-y: auto; overscroll-behavior: contain; padding: 8px 16px 16px; }
#bar { flex: none; padding: 10px 16px calc(10px + var(--bottom)); border-top: 1px solid var(--line); display: flex; gap: 8px; }
#bar button { flex: 1; padding: 8px 10px; }
#undoOrder { flex: 0 1 auto !important; }
#go { font-size: 1.05rem; }
body.planned #go { background: var(--card); color: var(--ink); border-color: var(--soft); }
body.sheet-peek #scroll, body.sheet-peek #bar { display: none; }
#empty { width: 100%; padding: 22px; border-style: dashed; color: var(--accent); }
[inert] { opacity: .65; }

#list, #loadList { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.stop { background: var(--card); border: 1px solid var(--line); border-radius: 14px; }
.stop > summary { list-style: none; cursor: pointer; display: grid; grid-template-columns: auto 1fr auto; gap: 12px; align-items: center; padding: 10px 12px; min-height: 64px; }
.stop > summary::-webkit-details-marker { display: none; }
.num { min-width: 38px; height: 38px; border-radius: 10px; }
.urgent .num { background: var(--urgent); }
.addr { overflow-wrap: anywhere; font-weight: 600; display: block; }
.badge { color: var(--urgent-ink); font-weight: 700; display: block; }
.badge:empty { display: none; }
.eta { font-size: 1.3rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.late .eta { color: var(--urgent-ink); }
body:not(.planned) .eta { visibility: hidden; }
.box { color: var(--ink); font-weight: 700; }
.note { display: block; border-left: 3px solid #f0a500; padding-left: 8px; margin-top: 4px; white-space: pre-line; overflow-wrap: anywhere; }
.body { padding: 0 12px 12px; display: grid; gap: 10px; }
.body label { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.body label textarea { flex: 1; min-height: 64px; min-width: 0; }
.edit > summary { padding: 12px 0; cursor: pointer; font-weight: 600; }
.edit > .body { padding: 0; }
.done { opacity: .65; }
.done .addr { text-decoration: line-through; }

#msg { position: fixed; z-index: 6; top: calc(var(--top) + 12px); left: 78px; right: 14px; max-width: 460px; margin: 0 auto; padding: 12px 14px; background: var(--warn-bg); color: var(--warn); border-radius: 14px; box-shadow: 0 2px 12px #0006; white-space: pre-line; overflow-wrap: anywhere; }
#msg:empty, .status:empty { display: none; }
#msg button, .status button { display: flex; margin-top: 8px; }
.status { padding: 10px 16px; background: var(--warn-bg); color: var(--warn); white-space: pre-line; overflow-wrap: anywhere; }

/* Pantallas */
dialog { border: 0; padding: 0; background: var(--bg); color: var(--ink); }
dialog::backdrop { background: #000a; }
dialog.full[open] { position: fixed; inset: 0; width: 100vw; height: 100dvh; max-width: none; max-height: none; margin: 0; display: flex; flex-direction: column; padding-top: var(--top); overflow: hidden; }
dialog.full form[method="dialog"] { display: contents; }
dialog header { display: flex; align-items: center; gap: 4px; padding: 8px; flex: none; }
dialog header h2 { flex: 1; font-size: 1.15rem; }
dialog .content { flex: 1; overflow-y: auto; overscroll-behavior: contain; padding: 4px 16px 24px; display: flex; flex-direction: column; gap: 10px; }
dialog .content > * { flex: none; }
dialog footer { flex: none; padding: 12px 16px calc(12px + var(--bottom)); border-top: 1px solid var(--line); display: grid; gap: 10px; }
dialog h3 { margin: 14px 0 0; font-size: .85rem; letter-spacing: .04em; color: var(--soft); text-transform: uppercase; }
fieldset { border: 0; margin: 8px 0 0; padding: 0; display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; min-width: 0; }
legend { font-weight: 600; padding: 0; margin-bottom: 6px; }
.pickrow, .set { display: flex; align-items: center; justify-content: space-between; gap: 12px; background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; min-height: 60px; font-weight: 500; }
.pickrow.col { flex-direction: column; align-items: stretch; }
.pickrow.col select { width: 100%; min-width: 0; }
.inline { display: flex; align-items: center; gap: 10px; }
.set select { max-width: 64%; min-width: 0; text-overflow: ellipsis; }
.set input[type="number"] { width: 92px; }
.search { flex: 1; display: flex; align-items: center; gap: 8px; border: 2px solid var(--accent); border-radius: 14px; padding: 0 10px; background: var(--field); min-width: 0; margin-left: 6px; }
.search .i { color: var(--soft); }
.search textarea { border: 0; background: none; flex: 1; min-width: 0; resize: none; padding: 11px 0; max-height: 34dvh; outline: none; field-sizing: content; }
.addrow { display: grid; grid-template-columns: auto auto 1fr; gap: 8px; align-items: center; }
.day { font-size: .9rem; font-weight: 700; color: var(--soft); margin: 14px 0 0; }
.route { display: flex; align-items: center; border-radius: 14px; border: 1px solid transparent; }
.route.on { background: var(--card); border-color: var(--accent); }
.route > button:first-child { flex: 1; border: 0; background: none; justify-content: flex-start; text-align: left; padding: 10px 12px; min-width: 0; gap: 12px; }
.route .when { color: var(--soft); min-width: 56px; font-variant-numeric: tabular-nums; }
.route .what { min-width: 0; overflow-wrap: anywhere; font-weight: 600; }
.route.on .what { color: var(--accent); }
.route.on small { color: var(--soft); }
#loadList li { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; align-items: center; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 10px; }
#loadList label { grid-column: 1 / -1; display: flex; align-items: center; gap: 10px; }
#loadList select { flex: 1; }
#menu { width: min(460px, calc(100vw - 24px)); border-radius: 20px; padding: 16px; margin: auto auto calc(12px + var(--bottom)); }
#menu[open] { display: grid; gap: 8px; }
#menu h2 { font-size: 1.05rem; padding: 0 4px 4px; overflow-wrap: anywhere; }
#menuItems { display: grid; gap: 8px; max-height: 66dvh; overflow-y: auto; }
#menuItems button { justify-content: flex-start; }

@media (min-width: 900px) {
  #map { left: 440px; }
  #sheet { inset: 0 auto 0 0; width: 440px; height: auto; border-radius: 0; transition: none; padding-top: 70px; }
  body.sheet-peek #scroll, body.sheet-peek #bar { display: flex; }
  body.sheet-peek #scroll { display: block; }
  #grip { display: none; }
  #head { cursor: default; }
  #fabs { bottom: 20px; visibility: visible !important; }
  #pick { left: 440px; }
  #msg { left: 470px; right: 80px; }
  dialog.full[open] { width: 460px; }
}
@media (prefers-reduced-motion: reduce) { #sheet, #fabs { transition: none; } }
