:root {
  --bg: #f3f5f8; --card: #fff; --text: #17202b; --muted: #5c6878; --line: #dde2e9;
  --pri: #1d4f91; --pri-2: #2c69bd; --pri-soft: #e6eef9; --ok: #1f8a4c; --ok-soft: #e3f4ea;
  --warn: #b26a00; --warn-soft: #fff3df; --bad: #c0352b; --bad-soft: #fde8e6;
  --r: 10px; --shadow: 0 1px 3px rgba(16,24,40,.08), 0 1px 2px rgba(16,24,40,.04);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: var(--text); background: var(--bg); -webkit-tap-highlight-color: transparent; }
a { color: var(--pri); }
h1 { font-size: 1.35rem; margin: 0 0 14px; }
h2 { font-size: 1.1rem; margin: 0 0 10px; }
h3 { font-size: 1rem; margin: 0 0 8px; }
.boot { padding: 40px; text-align: center; color: var(--muted); }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.hidden { display: none !important; }

/* Layout */
.shell { display: grid; grid-template-columns: 230px 1fr; min-height: 100vh; }
.side { background: #12345f; color: #dfe8f5; padding: 14px 10px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.side .brand { display: flex; gap: 10px; align-items: center; font-weight: 700; color: #fff; padding: 4px 8px 16px; font-size: 1rem; }
.side .brand img { width: 30px; height: 30px; }
.side nav a { display: flex; gap: 10px; align-items: center; padding: 9px 10px; border-radius: 8px; color: inherit; text-decoration: none; margin-bottom: 2px; }
.side nav a:hover { background: rgba(255,255,255,.08); }
.side nav a.on { background: var(--pri-2); color: #fff; }
.side nav .sep { height: 1px; background: rgba(255,255,255,.12); margin: 10px 6px; }
.side .me { margin-top: 16px; padding: 10px; font-size: .85rem; border-top: 1px solid rgba(255,255,255,.12); }
.side .me b { display: block; color: #fff; }
.main { padding: 22px 26px 80px; min-width: 0; }
.topbar { display: none; }
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: fixed; z-index: 1000; left: 0; top: 0; width: 260px; transform: translateX(-100%); transition: transform .2s; }
  .side.open { transform: none; box-shadow: 0 0 0 100vmax rgba(0,0,0,.35); }
  .topbar { display: flex; align-items: center; gap: 10px; position: sticky; top: 0; z-index: 900; background: var(--pri); color: #fff; padding: 10px 14px; padding-top: max(10px, env(safe-area-inset-top)); }
  .topbar button { background: none; border: 0; color: #fff; font-size: 1.4rem; padding: 2px 6px; cursor: pointer; }
  .topbar .t { font-weight: 600; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .main { padding: 14px 12px 90px; }
}

/* Components */
.card { background: var(--card); border-radius: var(--r); box-shadow: var(--shadow); padding: 16px; margin-bottom: 14px; border: 1px solid #e8ecf1; }
.grid { display: grid; gap: 14px; }
.g2 { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.g3 { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.g4 { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.grow { flex: 1; }
.stat { text-align: center; }
.stat b { display: block; font-size: 1.8rem; color: var(--pri); }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--line); background: #fff; color: var(--text); padding: 9px 14px; border-radius: 8px; font: inherit; font-weight: 500; cursor: pointer; text-decoration: none; min-height: 40px; }
.btn:hover { border-color: #b8c1cd; }
.btn.pri { background: var(--pri); border-color: var(--pri); color: #fff; }
.btn.pri:hover { background: var(--pri-2); }
.btn.ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn.bad { color: var(--bad); border-color: #f0c4bf; }
.btn.big { padding: 14px 18px; font-size: 1.05rem; min-height: 52px; width: 100%; }
.btn.sm { padding: 5px 10px; min-height: 32px; font-size: .88rem; }
.btn:disabled { opacity: .55; cursor: default; }

label.f { display: block; margin-bottom: 10px; }
label.f > span { display: block; font-size: .85rem; color: var(--muted); margin-bottom: 3px; font-weight: 500; }
input, select, textarea { font: inherit; color: inherit; width: 100%; padding: 9px 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff; min-height: 40px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--pri-soft); border-color: var(--pri-2); }
input[type=checkbox], input[type=radio] { width: 20px; height: 20px; min-height: 0; accent-color: var(--pri); margin: 0; flex: none; }
textarea { min-height: 70px; resize: vertical; }
.check { display: flex; gap: 10px; align-items: center; padding: 6px 0; cursor: pointer; }
.checks { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 0 12px; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.toolbar input, .toolbar select { width: auto; min-width: 150px; }
.toolbar .grow input { width: 100%; }

.tbl-wrap { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; font-size: .93rem; }
.tbl th, .tbl td { padding: 9px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.tbl th { font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 600; background: #f8fafc; }
.tbl tr.click { cursor: pointer; }
.tbl tr.click:hover td { background: #f8fafc; }
.tbl tr.off td { color: #98a2b0; }
.tbl tfoot td { font-weight: 600; }

.pill { display: inline-block; padding: 2px 8px; border-radius: 99px; font-size: .78rem; font-weight: 600; background: #eef1f5; color: var(--muted); }
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.bad { background: var(--bad-soft); color: var(--bad); }
.pill.pri { background: var(--pri-soft); color: var(--pri); }

.map { height: 380px; border-radius: var(--r); border: 1px solid var(--line); z-index: 0; }
.map.tall { height: 60vh; min-height: 320px; }
.map.small { height: 260px; }
.leaflet-container { font: inherit; }
.num-marker { background: var(--pri); color: #fff; border: 2px solid #fff; border-radius: 50%; width: 28px !important; height: 28px !important; margin: -14px 0 0 -14px !important; display: grid; place-items: center; font-weight: 700; font-size: 13px; box-shadow: 0 1px 4px rgba(0,0,0,.4); }
.num-marker.done { background: var(--ok); }
.num-marker.cur { background: #e8590c; transform: scale(1.2); }
.me-marker { width: 18px !important; height: 18px !important; margin: -9px 0 0 -9px !important; border-radius: 50%; background: #1a73e8; border: 3px solid #fff; box-shadow: 0 0 0 6px rgba(26,115,232,.25); }
.veh-marker { background: #fff; border: 2px solid var(--pri); border-radius: 8px; padding: 1px 5px; font-size: 12px; font-weight: 700; white-space: nowrap; width: auto !important; height: auto !important; color: var(--pri); }

/* Weather */
.wx { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.wx > div { background: var(--pri-soft); border-radius: 8px; padding: 10px; text-align: center; }
.wx > div.today { background: var(--pri); color: #fff; }
.wx .ic { font-size: 1.8rem; line-height: 1.2; }
.wx .t { font-weight: 700; font-size: 1.05rem; }
.wx .d { font-size: .8rem; opacity: .85; }
.wx-now { margin-top: 10px; font-size: .9rem; }

/* Run view */
.run-head { position: sticky; top: 0; z-index: 5; }
.progress { height: 8px; border-radius: 99px; background: var(--line); overflow: hidden; margin: 8px 0; }
.progress > i { display: block; height: 100%; background: var(--ok); transition: width .3s; }
.stop-card h2 { font-size: 1.25rem; margin-bottom: 2px; }
.svc { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 12px 0; }
.svc label { display: flex; gap: 10px; align-items: center; border: 2px solid var(--line); border-radius: 10px; padding: 12px; font-weight: 600; cursor: pointer; user-select: none; }
.svc label:has(input:checked) { border-color: var(--ok); background: var(--ok-soft); }
.stops { list-style: none; padding: 0; margin: 0; }
.stops li { display: flex; gap: 10px; align-items: center; padding: 9px 4px; border-bottom: 1px solid var(--line); }
.stops li .n { width: 28px; height: 28px; border-radius: 50%; background: var(--pri-soft); color: var(--pri); display: grid; place-items: center; font-weight: 700; flex: none; font-size: .85rem; }
.stops li.done .n { background: var(--ok); color: #fff; }
.stops li.cur { background: #fff4ec; }
.stops li .x { flex: 1; min-width: 0; }
.stops li .x b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.gps-dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: #999; margin-right: 5px; }
.gps-dot.on { background: #2fb344; box-shadow: 0 0 0 3px rgba(47,179,68,.25); }

.thumbs { display: flex; gap: 10px; flex-wrap: wrap; }
.thumbs .th { width: 130px; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: #fff; font-size: .78rem; position: relative; }
.thumbs .th img { width: 100%; height: 95px; object-fit: cover; display: block; background: #eee; }
.thumbs .th .pdf { height: 95px; display: grid; place-items: center; font-weight: 700; color: var(--bad); background: #fafafa; }
.thumbs .th div.c { padding: 4px 6px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.thumbs .th button { position: absolute; top: 4px; right: 4px; border: 0; background: rgba(0,0,0,.6); color: #fff; border-radius: 6px; cursor: pointer; padding: 2px 7px; }

/* Modal + toast */
.modal-bg { position: fixed; inset: 0; background: rgba(15,23,42,.45); z-index: 2000; display: grid; place-items: center; padding: 14px; overflow-y: auto; }
.modal { background: #fff; border-radius: 12px; width: 100%; max-width: 560px; padding: 20px; box-shadow: 0 20px 50px rgba(0,0,0,.25); max-height: calc(100vh - 28px); overflow-y: auto; }
.modal.wide { max-width: 900px; }
.modal .actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 14px; flex-wrap: wrap; }
.modal .actions .left { margin-right: auto; }
#toast { position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%); z-index: 3000; display: grid; gap: 8px; width: min(92vw, 420px); }
#toast div { background: #1f2937; color: #fff; padding: 11px 16px; border-radius: 8px; box-shadow: 0 6px 20px rgba(0,0,0,.25); animation: tin .2s; }
#toast div.err { background: var(--bad); }
@keyframes tin { from { opacity: 0; transform: translateY(8px); } }

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; background: linear-gradient(160deg, #12345f, #2c69bd); }
.login .card { width: 100%; max-width: 380px; padding: 26px; }
.login .logo { display: flex; gap: 12px; align-items: center; margin-bottom: 18px; }
.login .logo img { width: 44px; }

/* Import */
.imp-table td { padding: 2px; }
.imp-table td[contenteditable] { padding: 6px 8px; min-width: 90px; outline: none; }
.imp-table td[contenteditable]:focus { background: var(--pri-soft); }
.imp-table select { min-width: 130px; font-size: .85rem; padding: 4px; min-height: 32px; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 14px; flex-wrap: wrap; }
.tabs button { border: 0; background: none; padding: 10px 14px; font: inherit; cursor: pointer; border-bottom: 3px solid transparent; color: var(--muted); font-weight: 500; }
.tabs button.on { border-color: var(--pri); color: var(--pri); }
.drop { border: 2px dashed #b8c4d4; border-radius: 10px; padding: 26px; text-align: center; color: var(--muted); cursor: pointer; background: #fafcff; }
.drop:hover { border-color: var(--pri-2); }
