/* Route Builder -- screen styles. Accent color: --primary (Settings). */
:root {
    color-scheme: light;
    --bg: #fbfaf7;
    --card: #ffffff;
    --text: #141413;
    --text-2: #3d3c37;
    --muted: #66655f;
    --border: #e6e4dd;
    --border-strong: #d2d0c8;
    --fill: #f1f0ec;
    --primary: #c62828;
    --dark: #1c1c1a;
    --ok-bg: #dcefe1; --ok: #1d6b3a;
    --warn-bg: #fdebd3; --warn: #8a4b0f;
    --error-bg: #f7dedc; --error: #8f1d17;
    --info-bg: #e3ebf6; --info: #1f4e8c;
    --radius: 14px;
    --radius-sm: 10px;
    --topbar-h: 60px;
    --bottomnav-h: 0px;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
    margin: 0;
    font-family: 'Figtree', system-ui, -apple-system, "Segoe UI", sans-serif;
    font-size: 16px;
    line-height: 1.45;
    background: var(--bg);
    color: var(--text);
}
a { color: var(--primary); }
h1 { font-size: 1.55rem; margin: 0 0 4px; letter-spacing: -.01em; line-height: 1.2; }
h2 { font-size: 1.1rem; margin: 0 0 10px; }
h3 { font-size: 1rem; margin: 14px 0 8px; }
p { margin: 0 0 8px; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.icon { flex-shrink: 0; display: block; }
[hidden] { display: none !important; }
code { background: var(--fill); padding: 1px 5px; border-radius: 5px; font-size: .9em; }

/* ---- Top bar ------------------------------------------------------------ */
.topbar {
    position: sticky; top: 0; z-index: 30;
    height: var(--topbar-h);
    display: flex; align-items: center; gap: 24px;
    padding: 0 20px;
    background: var(--dark); color: #fff;
}
.brand { display: flex; align-items: center; gap: 10px; color: #fff; text-decoration: none; font-weight: 700; min-width: 0; }
.brand-mark { width: 34px; height: 34px; border-radius: 10px; background: var(--primary); display: grid; place-items: center; }
.brand-text { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-sub { color: #b8b7b0; font-weight: 500; }
.topnav { display: flex; gap: 4px; height: 100%; }
.topnav a {
    display: flex; align-items: center; padding: 0 14px; color: #b8b7b0; text-decoration: none; font-weight: 600;
    border-bottom: 3px solid transparent; border-top: 3px solid transparent;
}
.topnav a:hover { color: #fff; }
.topnav a.active { color: #fff; border-bottom-color: var(--primary); }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 14px; }
.topbar-right form { margin: 0; }
.who { color: #b8b7b0; font-size: .9rem; }
.link-btn { background: none; border: 0; color: inherit; font: inherit; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; padding: 6px; }
.topbar .link-btn { color: #fff; }
.list-tools .link-btn { color: var(--primary); font-weight: 600; }

/* ---- Bottom tabs (phones) ----------------------------------------------- */
.bottomnav { display: none; }
@media (max-width: 760px) {
    :root { --bottomnav-h: 64px; --topbar-h: 54px; }
    .topnav, .who { display: none; }
    .topbar { padding: 0 14px; }
    .topbar-right .link-btn span { display: none; }
    .bottomnav {
        display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
        height: calc(var(--bottomnav-h) + env(safe-area-inset-bottom));
        padding-bottom: env(safe-area-inset-bottom);
        background: #fff; border-top: 1px solid var(--border);
    }
    .bottomnav a {
        flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
        color: var(--muted); text-decoration: none; font-size: .75rem; font-weight: 600;
    }
    .bottomnav a.active { color: var(--primary); }
    body { padding-bottom: calc(var(--bottomnav-h) + env(safe-area-inset-bottom)); }
}

/* ---- Page --------------------------------------------------------------- */
.page { max-width: 1080px; margin: 0 auto; padding: 22px 20px 40px; }
.page-wide { max-width: 1400px; }
.page-narrow { max-width: 720px; margin: 0 auto; }
@media (max-width: 760px) { .page { padding: 16px 16px 32px; } }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 16px; flex-wrap: wrap; }
.head-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.back-link { display: inline-flex; align-items: center; gap: 6px; text-decoration: none; font-weight: 600; margin-bottom: 10px; }
.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; }
.stack > * + * { margin-top: 12px; }
.empty { text-align: center; padding: 32px 18px; }
.section-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.section-head h2 { margin: 0; }
.section-head form { margin: 0; }

/* ---- Forms -------------------------------------------------------------- */
label { display: block; font-weight: 600; font-size: .9rem; color: var(--text-2); }
input, select, textarea {
    display: block; width: 100%; margin-top: 5px;
    font: inherit; font-weight: 400; color: var(--text);
    padding: 10px 12px; min-height: 44px;
    border: 1px solid var(--border-strong); border-radius: var(--radius-sm); background: #fff;
}
input[type=checkbox], input[type=radio] { width: auto; min-height: 0; display: inline-block; margin: 0; accent-color: var(--primary); }
input[type=color] { padding: 4px; height: 44px; }
textarea { min-height: 80px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: 0; border-color: transparent; }
label.check { display: flex; align-items: center; gap: 10px; font-weight: 500; }
label.check input { width: 20px; height: 20px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid-3 { display: grid; grid-template-columns: 2fr 1fr 1fr; gap: 12px; }
.grid-2 > *, .grid-3 > * { margin-top: 0 !important; }
@media (max-width: 520px) { .grid-3 { grid-template-columns: 1fr 1fr; } .grid-3 > :first-child { grid-column: 1 / -1; } }
fieldset { border: 0; padding: 0; margin: 0; }
legend { font-weight: 600; font-size: .9rem; color: var(--text-2); margin-bottom: 8px; padding: 0; }
.day-picks { display: block; }
.day-picks label { display: inline-block; margin: 0 4px 6px 0; }
.day-picks input { position: absolute; opacity: 0; pointer-events: none; }
.day-picks label span {
    display: inline-block; min-width: 54px; text-align: center; padding: 9px 10px;
    border: 1px solid var(--border-strong); border-radius: 999px; font-weight: 600; cursor: pointer; background: #fff;
}
.day-picks label input:checked + span { background: var(--primary); border-color: var(--primary); color: #fff; }
.day-picks label input:focus-visible + span { outline: 2px solid var(--primary); outline-offset: 2px; }
.form-actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.inline-form { display: flex; gap: 8px; margin-top: 8px; }
.inline-form input { margin: 0; min-height: 38px; padding: 7px 10px; }

/* ---- Buttons ------------------------------------------------------------ */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 7px;
    min-height: 44px; padding: 0 16px; border-radius: 999px;
    border: 1px solid var(--border-strong); background: #fff; color: var(--text);
    font: inherit; font-weight: 600; text-decoration: none; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--fill); color: var(--text); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary); color: #fff; filter: brightness(.92); }
.btn-primary:disabled { opacity: .45; cursor: not-allowed; filter: none; }
.btn-small { min-height: 36px; padding: 0 12px; font-size: .875rem; }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-danger { color: var(--error); }
.btn-done { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn-done:hover { background: var(--ok); color: #fff; filter: brightness(.92); }
.btn-block { width: 100%; }

/* ---- Alerts ------------------------------------------------------------- */
.alert { padding: 12px 14px; border-radius: var(--radius-sm); margin: 0 0 12px; font-size: .95rem; }
.alert-ok { background: var(--ok-bg); color: var(--ok); }
.alert-warn { background: var(--warn-bg); color: var(--warn); }
.alert-error { background: var(--error-bg); color: var(--error); }
.alert-info { background: var(--info-bg); color: var(--info); }
.alert-link { display: flex; gap: 10px; align-items: center; text-decoration: none; }
.ok-text { color: var(--ok); }
.error-text { color: var(--error); }
.note { background: var(--info-bg); color: var(--info); padding: 10px 12px; border-radius: var(--radius-sm); font-size: .9rem; }

/* ---- Chips -------------------------------------------------------------- */
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.chip {
    display: inline-flex; align-items: center; gap: 4px; padding: 3px 9px; border-radius: 999px;
    background: var(--fill); color: var(--text-2); font-size: .8rem; font-weight: 600; white-space: nowrap;
}
.chip-rule { background: var(--info-bg); color: var(--info); }
.chip-orange { background: var(--warn-bg); color: var(--warn); }
.chip-red { background: var(--error-bg); color: var(--error); }
.chip-brand { background: var(--primary); color: #fff; }
.chip-blocked { background: #ecebe6; color: var(--muted); }
.badge { display: inline-flex; align-items: center; gap: 5px; margin-top: 6px; font-size: .85rem; font-weight: 600; }
.badge-back { color: var(--error); }

/* ---- Planner layout ----------------------------------------------------- */
.planner { display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); gap: 20px; align-items: start; }
.planner-map { position: sticky; top: calc(var(--topbar-h) + 16px); }
.route-map {
    width: 100%; height: calc(100vh - var(--topbar-h) - 120px); min-height: 380px;
    border-radius: var(--radius); overflow: hidden; background: #e8e6df; border: 1px solid var(--border);
}
.route-map-empty { display: grid; place-items: center; padding: 24px; text-align: center; color: var(--muted); }
.map-key { display: flex; align-items: center; flex-wrap: wrap; gap: 6px 12px; margin-top: 8px; }
.dot { display: inline-block; width: 12px; height: 12px; border-radius: 50%; border: 2px solid #fff; box-shadow: 0 0 0 1px var(--border-strong); vertical-align: -1px; }
.dot-waiting { background: #8a8983; }
.dot-selected { background: var(--primary); }
.dot-blocked { background: #c9c7bf; }
.home-key { display: inline-grid; place-items: center; width: 18px; height: 18px; border-radius: 5px; background: var(--dark); color: var(--primary); vertical-align: -4px; }
.maps-links { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.map-info { font-family: 'Figtree', sans-serif; font-size: 14px; max-width: 220px; }
@media (max-width: 900px) {
    .planner { grid-template-columns: 1fr; }
    .planner-map { position: static; }
    .route-map { height: 46vh; min-height: 280px; }
}
.planner-settings { margin-bottom: 18px; }
.planner-settings > * + * { margin-top: 12px; }

.list-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin: 6px 0 10px; flex-wrap: wrap; }
.list-head h2 { margin: 0; }
.count { display: inline-block; min-width: 26px; padding: 1px 8px; border-radius: 999px; background: var(--fill); font-size: .85rem; text-align: center; }
.list-tools { display: flex; align-items: center; gap: 10px; }
.search { position: relative; font-weight: 400; }
.search .icon { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.search input { margin: 0; padding-left: 34px; min-height: 38px; width: 170px; border-radius: 999px; }

.stop-list { list-style: none; margin: 0 0 16px; padding: 0; background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.stop-list:empty { display: none; }
.stop-row { display: flex; gap: 12px; padding: 14px 16px; border-top: 1px solid var(--border); align-items: flex-start; scroll-margin-top: 90px; }
.stop-row:first-child { border-top: 0; }
.stop-row.is-back { background: #fff8f7; box-shadow: inset 3px 0 0 var(--error); }
.stop-row.is-blocked .stop-name, .stop-row.is-blocked .stop-addr { color: var(--muted); }
.stop-row .pick { width: 22px; height: 22px; margin-top: 2px; flex-shrink: 0; cursor: pointer; }
.stop-row .pick:disabled { cursor: not-allowed; opacity: .4; }
.stop-main { flex: 1; min-width: 0; }
.stop-name { font-weight: 700; font-size: 1.02rem; color: var(--text); cursor: pointer; }
.stop-addr { color: var(--text-2); }
.stop-notes { margin: 8px 0 0; font-size: .9rem; color: var(--text-2); background: var(--fill); padding: 8px 10px; border-radius: 8px; white-space: normal; }
.geo-problem { margin: 6px 0 0; color: var(--warn); font-size: .875rem; font-weight: 600; }
.stop-actions { display: flex; gap: 4px; flex-shrink: 0; }
@media (max-width: 520px) { .stop-actions .btn span { display: none; } .stop-actions .btn { padding: 0 10px; } }

.action-bar {
    display: flex; justify-content: space-between; align-items: center; gap: 12px;
    margin: 24px auto 0; width: min(560px, 100%);
    padding: 10px 10px 10px 20px; border-radius: 999px; background: var(--dark); color: #fff; font-weight: 700;
}
.optimize-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; padding-top: 12px; border-top: 1px solid var(--border); }
.optimize-row .pick-count { font-weight: 700; }
.tl-right { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.move-btns { display: inline-flex; gap: 2px; }
.move-btn {
    width: 32px; height: 32px; display: grid; place-items: center; padding: 0; cursor: pointer;
    border: 1px solid var(--border-strong); border-radius: 8px; background: #fff; color: var(--text);
}
.move-btn:hover:not(:disabled) { background: var(--fill); }
.move-btn:disabled { opacity: .3; cursor: default; }
.reorder-actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0 6px; }
.summary .note { margin: 8px 0 0; }

.history summary, .past summary, details.danger-zone summary { cursor: pointer; font-weight: 600; }
.history { margin-bottom: 12px; }
.mini-list { list-style: none; margin: 0; padding: 0; }
.mini-list li { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 9px 0; border-top: 1px solid var(--border); flex-wrap: wrap; }
.mini-list li:first-child { border-top: 0; }
.mini-list form { margin: 0; }
.row-actions { display: flex; gap: 6px; }

/* ---- Route summary + timeline ------------------------------------------ */
.summary { margin-bottom: 14px; }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; text-align: center; margin-bottom: 8px; }
.stats strong { display: block; font-size: 1.15rem; }
.stats span { color: var(--muted); font-size: .8rem; }
@media (max-width: 520px) { .stats strong { font-size: .98rem; } }
.progress { height: 6px; background: var(--fill); border-radius: 99px; overflow: hidden; margin: 8px 0 4px; }
.progress span { display: block; height: 100%; background: var(--ok); }

.timeline { list-style: none; margin: 0 0 16px; padding: 0; }
.timeline > li { position: relative; display: flex; gap: 12px; padding: 0 0 18px; scroll-margin-top: 90px; }
.timeline > li::before { content: ""; position: absolute; left: 15px; top: 32px; bottom: 0; width: 2px; background: var(--border); }
.timeline > li:last-child::before { display: none; }
.tl-dot {
    width: 32px; height: 32px; border-radius: 50%; flex-shrink: 0; display: grid; place-items: center;
    background: var(--primary); color: #fff; font-weight: 800; font-size: .9rem; position: relative; z-index: 1;
}
.tl-home .tl-dot { background: var(--dark); color: var(--primary); border-radius: 9px; }
.timeline > li.is-done .tl-dot { background: var(--ok); }
.timeline > li.is-done .tl-body > :not(.stop-buttons):not(.tl-top) { opacity: .6; }
.tl-body { flex: 1; min-width: 0; background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; }
.is-late .tl-body { border-color: #e9b4ae; }
.tl-top { display: flex; justify-content: space-between; gap: 10px; align-items: baseline; }
.tl-time { font-weight: 800; white-space: nowrap; }
.stop-buttons { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.stop-buttons form { margin: 0; }
.send-back { margin-top: 8px; }
.send-back summary { cursor: pointer; color: var(--error); font-weight: 600; font-size: .9rem; display: inline-block; }
.danger-zone { margin-top: 16px; }

/* ---- Scheduled ---------------------------------------------------------- */
.day-head { margin: 22px 0 10px; }
.route-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 12px; }
.route-card { display: flex; align-items: center; gap: 12px; text-decoration: none; color: var(--text); }
.route-card:hover { border-color: var(--border-strong); box-shadow: 0 2px 10px rgba(0,0,0,.05); color: var(--text); }
.route-card.is-mine { border-color: var(--primary); }
.rc-main { flex: 1; min-width: 0; }
.rc-who { font-weight: 700; font-size: 1.05rem; display: flex; gap: 8px; align-items: center; }
.rc-go { width: 42px; height: 42px; border-radius: 50%; background: var(--fill); display: grid; place-items: center; color: var(--primary); }
.past { margin-top: 26px; }
.past .route-card { margin-bottom: 10px; }
.checkoff { border-color: #efc58f; background: #fffaf2; margin-bottom: 8px; }

/* ---- Settings ----------------------------------------------------------- */
.page-narrow > .card { margin-bottom: 16px; }
.user-list { list-style: none; margin: 0; padding: 0; }
.user-list > li { border-top: 1px solid var(--border); padding: 10px 0; }
.user-list > li:first-child { border-top: 0; }
.user-list summary { display: flex; gap: 10px; align-items: center; cursor: pointer; flex-wrap: wrap; }
.user-list summary > span:first-child { flex: 1; }
.sub-form { padding: 12px 0 4px; }
.add-user summary { list-style: none; }
.add-user summary::-webkit-details-marker { display: none; }
.status-list { list-style: none; margin: 0; padding: 0; }
.status-list li { padding: 4px 0; font-weight: 600; }
.status-list .on { color: var(--ok); }
.status-list .off { color: var(--error); }

/* ---- Login -------------------------------------------------------------- */
.login-body { display: grid; min-height: 100vh; place-items: center; }
.login-body .page { padding: 20px; width: 100%; }
.login-card { max-width: 400px; margin: 8vh auto 0; padding: 28px; text-align: left; }
.login-card h1 { margin-top: 12px; }
.login-mark { width: 52px; height: 52px; border-radius: 14px; background: var(--dark); color: var(--primary); display: grid; place-items: center; }

.small a .icon, p a .icon { display: inline-block; vertical-align: -2px; }
