@import url('https://fonts.googleapis.com/css2?family=DM+Sans:wght@400;500;600;700&family=Manrope:wght@600;700;800&display=swap');

:root {
    --ink: #172038;
    --muted: #6b7386;
    --line: #e6e9ef;
    --surface: #ffffff;
    --canvas: #f4f6fa;
    --navy: #18284a;
    --blue: #2d5bea;
    --blue-dark: #1e45bf;
    --saffron: #f29d38;
    --green: #15866b;
    --danger: #c83f4d;
    --shadow: 0 14px 40px rgba(26, 40, 76, .08);
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--canvas); color: var(--ink); font-family: 'DM Sans', system-ui, sans-serif; font-size: 16px; }
button, input, textarea { font: inherit; }
button { cursor: pointer; }

.topbar { min-height: 78px; background: #fff; border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; padding: 13px clamp(18px, 4vw, 56px); position: sticky; top: 0; z-index: 500; }
.brand { display: flex; align-items: center; gap: 13px; }
.brand-icon { width: 45px; height: 45px; border-radius: 14px; display: grid; place-items: center; color: white; background: linear-gradient(145deg, var(--blue), var(--navy)); font-size: 30px; font-weight: 800; transform: rotate(-4deg); }
.brand span, .eyebrow { display: block; color: var(--blue); text-transform: uppercase; font-size: .73rem; font-weight: 800; letter-spacing: .11em; }
.brand h1 { font: 800 1.17rem/1.15 'Manrope', sans-serif; margin: 3px 0 0; }
.top-actions { display: flex; align-items: center; gap: 9px; }

.button { border: 0; border-radius: 10px; padding: 10px 15px; min-height: 41px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; font-weight: 700; transition: .18s ease; text-decoration: none; }
.button:hover { transform: translateY(-1px); }
.button-primary { background: var(--blue); color: #fff; box-shadow: 0 7px 16px rgba(45, 91, 234, .18); }
.button-primary:hover { background: var(--blue-dark); }
.button-secondary { background: #edf2ff; color: var(--blue-dark); border: 1px solid #dbe4ff; }
.button-quiet { background: #fff; color: var(--ink); border: 1px solid var(--line); }
.button-danger { background: var(--danger); color: white; }
.button:disabled { opacity: .48; cursor: not-allowed; transform: none; }
.grow { flex: 1; }

.app-shell { width: min(1500px, calc(100% - 36px)); margin: 22px auto 50px; }
.route-summary-strip { background: var(--navy); color: white; border-radius: 18px; display: grid; grid-template-columns: minmax(330px, 2fr) repeat(4, minmax(115px, .7fr)); padding: 16px 20px; box-shadow: var(--shadow); gap: 16px; align-items: center; }
.fixed-point { display: flex; gap: 13px; align-items: center; min-width: 0; }
.mandir-mark { flex: 0 0 47px; height: 47px; display: grid; place-items: center; background: var(--saffron); color: #342007; border-radius: 50% 50% 50% 13px; font: 800 .88rem 'Manrope'; transform: rotate(-3deg); }
.fixed-point span, .metric span { display: block; color: #aeb9d3; font-size: .73rem; letter-spacing: .05em; text-transform: uppercase; font-weight: 700; }
.fixed-point strong { display: block; font: 700 .98rem 'Manrope'; margin: 3px 0; }
.fixed-point small { color: #c9d0e1; display: block; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.metric { padding-left: 18px; border-left: 1px solid rgba(255,255,255,.13); }
.metric strong { display: block; font: 800 1.05rem 'Manrope'; margin-top: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.progress-panel { margin-top: 14px; display: grid; grid-template-columns: 260px 1fr 50px; align-items: center; gap: 20px; background: #fff; border: 1px solid #dfe6fb; border-radius: 13px; padding: 13px 16px; box-shadow: var(--shadow); }
.progress-panel strong { display: block; font-weight: 800; }
.progress-panel span { color: var(--muted); font-size: .86rem; }
.progress-track { height: 8px; border-radius: 999px; overflow: hidden; background: #e6ebf8; }
.progress-track i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--blue), #6f8ff5); transition: width .35s ease; }

.tabs { display: flex; align-items: center; gap: 4px; margin: 22px 0 13px; border-bottom: 1px solid var(--line); }
.tab { color: var(--muted); border: 0; border-bottom: 3px solid transparent; background: transparent; padding: 11px 15px; font-weight: 700; }
.tab span { background: #e8ebf2; border-radius: 99px; padding: 2px 7px; margin-left: 4px; font-size: .76rem; }
.tab.active { color: var(--blue); border-bottom-color: var(--blue); }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

.workspace-grid { display: grid; grid-template-columns: minmax(370px, .82fr) minmax(520px, 1.55fr); gap: 15px; align-items: start; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; box-shadow: 0 8px 28px rgba(26, 40, 76, .045); }
.panel-head { display: flex; justify-content: space-between; gap: 15px; align-items: center; padding: 19px 20px 15px; border-bottom: 1px solid var(--line); }
.panel-head.compact { padding-bottom: 12px; }
.panel-head h2, .section-heading h2, .modal h2 { font: 800 1.15rem 'Manrope'; margin: 4px 0 0; }
.limit-pill { border-radius: 99px; background: #edf2ff; color: var(--blue-dark); padding: 6px 10px; font-size: .84rem; font-weight: 700; }

.search-box { margin: 14px 16px 8px; border: 1px solid var(--line); background: #fafbfe; border-radius: 11px; display: flex; align-items: center; }
.search-box:focus-within { border-color: #9db2f5; box-shadow: 0 0 0 3px #edf2ff; }
.search-box input { border: 0; background: transparent; padding: 11px 12px; outline: 0; width: 100%; }
.icon-button { width: 42px; height: 40px; border: 0; background: transparent; color: var(--blue); font-size: 1.25rem; }
.search-results { margin: 0 16px 9px; border: 1px solid var(--line); border-radius: 11px; overflow: hidden; }
.search-result { display: flex; justify-content: space-between; align-items: center; gap: 8px; width: 100%; text-align: left; border: 0; border-bottom: 1px solid var(--line); background: white; padding: 10px 12px; }
.search-result:last-child { border-bottom: 0; }
.search-result:hover { background: #f5f7ff; }
.search-result strong, .search-result small { display: block; }
.search-result small { color: var(--muted); margin-top: 2px; }
.search-result b { color: var(--blue); font-size: 1.25rem; }

.route-anchor { margin: 11px 16px; display: flex; align-items: center; gap: 11px; padding: 10px; border-radius: 11px; background: #fff8ed; border: 1px solid #ffe4b9; }
.route-anchor.finish { margin-top: 8px; }
.route-anchor strong, .route-anchor small { display: block; }
.route-anchor small { color: var(--muted); }
.anchor-copy { min-width: 0; }
.anchor-copy strong, .anchor-copy small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.route-number { width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; background: var(--saffron); color: #35230c; font-weight: 800; flex: 0 0 auto; }
.route-number.finish { background: var(--navy); color: white; }
.anchor-edit { margin-left: auto; flex: 0 0 auto; border: 0; border-radius: 8px; background: #fff0d7; color: #865314; padding: 7px 9px; font-size: .75rem; font-weight: 800; }
.anchor-edit:hover { background: #ffe4b9; }
.stop-list { max-height: 520px; overflow-y: auto; padding: 0 16px; }
.stop-row { display: grid; grid-template-columns: 24px 34px 1fr auto; align-items: center; gap: 8px; min-height: 66px; border-bottom: 1px solid var(--line); }
.stop-row.dragging { opacity: .45; }
.drag-handle { color: #a6adba; cursor: grab; border: 0; background: transparent; padding: 0; font-size: 1.1rem; }
.stop-index { width: 30px; height: 30px; display: grid; place-items: center; border-radius: 50%; background: #edf2ff; color: var(--blue); font-weight: 800; font-size: .8rem; }
.stop-copy { min-width: 0; }
.stop-copy strong, .stop-copy small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stop-copy small { color: var(--muted); margin-top: 3px; font-size: .82rem; }
.row-actions { display: flex; gap: 3px; }
.mini-button { border: 0; background: transparent; color: var(--muted); border-radius: 7px; width: 30px; height: 30px; }
.mini-button:hover { background: #edf2ff; color: var(--blue); }
.mini-button.danger:hover { background: #fff0f1; color: var(--danger); }
.empty-state { margin: 16px; border: 1px dashed #ccd3df; border-radius: 13px; text-align: center; padding: 27px 16px; color: var(--muted); }
.empty-state h3 { color: var(--ink); margin: 7px 0 5px; }
.empty-state p { margin: 0 0 8px; font-size: .9rem; }
.empty-icon { font-size: 2rem; color: var(--blue); }
.text-button { color: var(--blue); border: 0; background: transparent; font-weight: 800; }
.panel-footer { padding: 14px 16px; display: flex; gap: 8px; border-top: 1px solid var(--line); }

.result-column { display: grid; gap: 15px; }
#route-map { height: 430px; background: #e9edf3; z-index: 1; }
.map-legend { display: flex; gap: 18px; align-items: center; padding: 10px 16px; color: var(--muted); font-size: .8rem; }
.map-legend span { display: flex; align-items: center; gap: 6px; }
.legend-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--blue); }
.legend-dot.mandir { background: var(--saffron); }
.legend-line { width: 24px; height: 3px; background: var(--blue); border-radius: 99px; }
.map-marker { width: 30px; height: 30px; border: 3px solid white; border-radius: 50% 50% 50% 10px; background: var(--blue); color: white; display: grid; place-items: center; box-shadow: 0 4px 14px rgba(18,36,82,.3); font-weight: 800; transform: rotate(-45deg); }
.map-marker span { transform: rotate(45deg); font-size: .72rem; }
.map-marker.mandir { background: var(--saffron); color: #38240b; width: 36px; height: 36px; }

.result-actions { display: flex; gap: 8px; }
.result-placeholder { min-height: 175px; display: grid; place-content: center; text-align: center; padding: 25px; color: var(--muted); }
.result-placeholder div { font-size: 2rem; color: var(--blue); }
.result-placeholder p { max-width: 540px; margin: 7px auto; }
.result-metrics { display: grid; grid-template-columns: repeat(auto-fit, minmax(118px, 1fr)); padding: 14px 20px; border-bottom: 1px solid var(--line); }
.result-metrics div { border-right: 1px solid var(--line); padding: 4px 15px; }
.result-metrics div:first-child { padding-left: 0; }
.result-metrics div:last-child { border-right: 0; }
.result-metrics span, .result-metrics strong { display: block; }
.result-metrics span { color: var(--muted); font-size: .78rem; }
.result-metrics strong { font: 800 .95rem 'Manrope'; margin-top: 5px; }
.optimized-sequence { list-style: none; padding: 4px 20px 14px; margin: 0; }
.optimized-sequence li { display: grid; grid-template-columns: 36px minmax(140px, 1fr) auto auto auto; align-items: center; gap: 10px; min-height: 54px; border-bottom: 1px solid var(--line); }
.optimized-sequence li:last-child { border-bottom: 0; }
.optimized-sequence .sequence-num { width: 29px; height: 29px; border-radius: 50%; display: grid; place-items: center; background: #edf2ff; color: var(--blue); font-size: .75rem; font-weight: 800; }
.optimized-sequence small { color: var(--muted); }
.optimized-sequence .sequence-eta { color: var(--blue); font-weight: 700; white-space: nowrap; }
.optimized-sequence .sequence-day { display: inline-block; margin-left: 8px; padding: 1px 7px; border-radius: 999px; background: #eef7f3; color: var(--green); font: 700 .68rem 'Manrope', sans-serif; vertical-align: middle; }
.optimized-sequence li[data-day] { border-left: 3px solid #eef7f3; padding-left: 9px; margin-left: -12px; }

/* ---------- Day planning ---------- */
.day-planner { border-top: 1px solid var(--line); padding: 12px 16px; }
.day-planner > summary { cursor: pointer; font: 700 .9rem 'Manrope', sans-serif; display: flex; justify-content: space-between; align-items: center; gap: 10px; list-style: none; }
.day-planner > summary::-webkit-details-marker { display: none; }
.day-planner > summary::after { content: '⌄'; color: var(--muted); font-size: 1.1rem; line-height: 1; }
.day-planner[open] > summary::after { content: '⌃'; }
.day-planner > summary small { color: var(--muted); font-weight: 600; margin-left: auto; }
.day-planner-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 12px; }
.day-planner-grid label { display: grid; gap: 4px; font-size: .78rem; color: var(--muted); }
.day-planner-grid input, .day-planner-grid select { width: 100%; padding: 8px 9px; border: 1px solid var(--line); border-radius: 9px; color: var(--ink); background: var(--surface); }
.day-planner-note { margin: 10px 0 0; font-size: .76rem; color: var(--muted); }

.day-summary { display: grid; gap: 10px; padding: 14px 20px 0; }
.day-summary[hidden] { display: none; }
.day-card { border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; background: #fbfcfe; }
.day-card header { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.day-card header strong { font: 800 .9rem 'Manrope', sans-serif; }
.day-card header small, .day-card > small { color: var(--muted); font-size: .78rem; }
.day-card p { margin: 6px 0 4px; font-size: .84rem; }
.warning-list { padding: 0 20px; }
.warning-item { background: #fff8e9; border: 1px solid #ffe4ad; color: #74511d; padding: 9px 11px; border-radius: 9px; margin-top: 12px; font-size: .87rem; }
.navigation-segments { padding: 0 20px 18px; display: flex; gap: 8px; flex-wrap: wrap; }
.navigation-segments a { text-decoration: none; color: var(--blue); background: #edf2ff; border-radius: 8px; padding: 7px 10px; font-size: .82rem; font-weight: 700; }

.section-heading { display: flex; align-items: center; justify-content: space-between; margin: 20px 2px 15px; }
.card-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.route-card { background: white; border: 1px solid var(--line); border-radius: 15px; padding: 17px; box-shadow: 0 7px 24px rgba(26,40,76,.045); }
.route-card h3 { font: 800 1rem 'Manrope'; margin: 0 0 4px; }
.route-card p { margin: 0 0 15px; color: var(--muted); font-size: .86rem; min-height: 35px; }
.route-card-metrics { display: grid; grid-template-columns: repeat(3, 1fr); gap: 7px; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); padding: 11px 0; margin-bottom: 12px; }
.route-card-metrics span, .route-card-metrics b { display: block; }
.route-card-metrics span { font-size: .72rem; color: var(--muted); }
.route-card-metrics b { font-size: .85rem; margin-top: 3px; }
.route-card-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.route-card-actions .button { padding: 8px 10px; min-height: 35px; font-size: .82rem; }
.large-empty { background: white; border: 1px dashed #cdd4df; border-radius: 15px; padding: 50px 20px; text-align: center; color: var(--muted); }
.large-empty h3 { color: var(--ink); margin: 0 0 5px; }
.large-empty p { margin: 0; }
.table-wrap { overflow-x: auto; background: white; border: 1px solid var(--line); border-radius: 15px; }
table { border-collapse: collapse; width: 100%; }
th, td { text-align: left; padding: 13px 15px; border-bottom: 1px solid var(--line); }
th { background: #f8f9fc; color: var(--muted); font-size: .75rem; letter-spacing: .04em; text-transform: uppercase; }
td { font-size: .9rem; }
.history-list { display: grid; gap: 10px; }
.history-card { background: white; border: 1px solid var(--line); border-radius: 12px; display: grid; grid-template-columns: 1fr repeat(3, minmax(120px, .3fr)); gap: 10px; align-items: center; padding: 14px 16px; }
.history-card span, .history-card small { display: block; color: var(--muted); }
.history-card strong { display: block; margin-top: 3px; }

.modal { border: 0; border-radius: 17px; padding: 0; width: min(560px, calc(100% - 26px)); box-shadow: 0 26px 80px rgba(19,30,61,.28); }
.modal::backdrop { background: rgba(18,27,50,.58); backdrop-filter: blur(3px); }
.modal form { padding: 22px; }
.modal-head { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 17px; }
.modal-close { border: 0; background: #f0f2f6; border-radius: 50%; width: 34px; height: 34px; font-size: 1.4rem; color: var(--muted); }
.modal label { display: block; color: var(--ink); font-size: .86rem; font-weight: 700; margin: 12px 0; }
.modal input, .modal textarea { width: 100%; margin-top: 6px; border: 1px solid #d9dde6; border-radius: 9px; padding: 10px 11px; outline: 0; }
.modal input:focus, .modal textarea:focus { border-color: #98aff2; box-shadow: 0 0 0 3px #edf2ff; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 11px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }
.confirm-modal { width: min(440px, calc(100% - 26px)); }
.confirm-modal p { color: var(--muted); }

.toast-stack { position: fixed; top: 92px; right: 18px; z-index: 2000; display: grid; gap: 8px; }
.toast { min-width: 280px; max-width: 390px; border-radius: 11px; background: #18284a; color: white; padding: 12px 14px; box-shadow: 0 14px 40px rgba(15,27,57,.25); animation: toast-in .22s ease; }
.toast.success { background: var(--green); }
.toast.error { background: var(--danger); }
@keyframes toast-in { from { opacity: 0; transform: translateY(-8px); } }

@media (max-width: 1050px) {
    .route-summary-strip { grid-template-columns: 2fr repeat(2, 1fr); }
    .route-summary-strip .metric:nth-last-child(-n+2) { display: none; }
    .workspace-grid { grid-template-columns: 1fr; }
    .stop-list { max-height: 420px; }
    .card-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 720px) {
    body { font-size: 15px; }
    .topbar { align-items: flex-start; padding: 11px 14px; position: static; }
    .top-actions { flex-wrap: wrap; justify-content: flex-end; }
    .top-actions .button { padding: 8px 10px; font-size: .8rem; }
    .brand span { display: none; }
    .brand h1 { font-size: .95rem; max-width: 150px; }
    .brand-icon { width: 38px; height: 38px; }
    .app-shell { width: min(100% - 18px, 1500px); margin-top: 10px; }
    .route-summary-strip { grid-template-columns: 1fr 72px; border-radius: 13px; padding: 12px; }
    .route-summary-strip .metric:not(:nth-child(2)) { display: none; }
    .fixed-point small { max-width: 210px; }
    .tabs { overflow-x: auto; }
    .tab { white-space: nowrap; padding: 10px; font-size: .86rem; }
    .progress-panel { grid-template-columns: 1fr 43px; gap: 10px; }
    .progress-track { grid-column: 1 / -1; grid-row: 2; }
    .workspace-grid { display: block; }
    .result-column { margin-top: 10px; }
    .panel-head { padding: 15px; align-items: flex-start; }
    .panel-footer { position: sticky; bottom: 0; background: white; z-index: 3; }
    #route-map { height: 340px; }
    .result-actions { flex-direction: column; }
    .result-metrics { grid-template-columns: 1fr 1fr; gap: 8px; }
    .result-metrics div { border: 0; padding: 5px 0; }
    .optimized-sequence li { grid-template-columns: 34px 1fr; padding: 8px 0; }
    .optimized-sequence li > small { grid-column: 2; }
    .day-planner-grid { grid-template-columns: 1fr; }
    .card-grid { grid-template-columns: 1fr; }
    .section-heading { align-items: flex-start; gap: 12px; }
    .history-card { grid-template-columns: 1fr 1fr; }
    .form-row { grid-template-columns: 1fr; }
}

/* ---------- Authentication ---------- */
.auth-shell { min-height: 100vh; display: grid; place-items: center; padding: 32px 18px; }
.auth-card { width: min(430px, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: 18px; box-shadow: var(--shadow); padding: 30px clamp(22px, 5vw, 34px) 26px; }
.auth-brand { display: flex; align-items: center; gap: 13px; }
.auth-brand h1 { font: 800 1.17rem/1.15 'Manrope', sans-serif; margin: 3px 0 0; }
.auth-brand span { display: block; color: var(--blue); text-transform: uppercase; font-size: .73rem; font-weight: 800; letter-spacing: .11em; }
.auth-intro { color: var(--muted); margin: 18px 0 0; font-size: .94rem; }
.auth-status { margin: 16px 0 0; padding: 10px 13px; border-radius: 11px; background: #e8f6f1; border: 1px solid #bfe5d9; color: var(--green); font-size: .89rem; font-weight: 600; }
.auth-error { margin: 16px 0 0; padding: 10px 13px; border-radius: 11px; background: #fdeef0; border: 1px solid #f2cdd2; color: var(--danger); font-size: .89rem; font-weight: 600; }
.auth-form { margin-top: 18px; display: grid; gap: 14px; }
.auth-field { display: block; }
.auth-field > span { display: block; font-size: .82rem; font-weight: 700; letter-spacing: .02em; margin-bottom: 6px; }
.auth-field input { width: 100%; border: 1px solid var(--line); background: #fafbfe; border-radius: 11px; padding: 11px 13px; outline: 0; transition: .18s ease; }
.auth-field input:focus { border-color: #9db2f5; box-shadow: 0 0 0 3px #edf2ff; background: #fff; }
.auth-field input[aria-invalid="true"] { border-color: #e4a8b0; background: #fffafb; }
.auth-field-error { display: block; margin-top: 6px; color: var(--danger); font-size: .82rem; font-weight: 600; }
.auth-remember { display: flex; align-items: center; gap: 9px; color: var(--muted); font-size: .89rem; }
.auth-remember input { width: 16px; height: 16px; accent-color: var(--blue); }
.auth-submit { width: 100%; margin-top: 4px; }
.auth-footnote { margin: 20px 0 0; padding-top: 16px; border-top: 1px solid var(--line); color: var(--muted); font-size: .82rem; line-height: 1.5; }
.user-chip { display: flex; align-items: center; gap: 9px; padding-left: 11px; margin-left: 2px; border-left: 1px solid var(--line); }
.user-chip strong { display: block; font: 700 .87rem 'Manrope', sans-serif; white-space: nowrap; }
.user-chip small { display: block; color: var(--muted); font-size: .74rem; }
@media (max-width: 720px) { .user-chip { padding-left: 0; margin-left: 0; border-left: 0; } .user-chip div { display: none; } }

/* ---------- Map: direction, layers, clustering ---------- */
.map-arrow { color: #1e45bf; font-size: 13px; line-height: 16px; text-align: center; text-shadow: 0 0 3px #fff, 0 0 3px #fff; pointer-events: none; }
.map-cluster { width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; background: var(--blue); color: #fff; border: 3px solid #fff; box-shadow: 0 4px 14px rgba(18,36,82,.3); font: 800 .82rem 'Manrope', sans-serif; }
.map-leg-estimated { stroke-dasharray: 9 7; }
.map-extra-control a { display: grid; place-items: center; width: 30px; height: 30px; font-size: 15px; color: var(--ink); background: #fff; text-decoration: none; }
.map-extra-control a:hover { background: #f4f6fa; }
.map-extra-control a.active { background: var(--blue); color: #fff; }
.leaflet-tooltip { font-family: 'DM Sans', system-ui, sans-serif; font-size: .82rem; }
.map-panel:fullscreen { background: var(--surface); display: flex; flex-direction: column; }
.map-panel:fullscreen #route-map { flex: 1; height: auto; }
