:root {
    --bg: #f4f7f8;
    --panel: #ffffff;
    --panel-subtle: #f8fafb;
    --text: #18232e;
    --muted: #637282;
    --soft: #8a98a6;
    --border: #dfe7ec;
    --border-strong: #c7d3db;
    --focus: #2a6f8f;
    --accent: #2f6f88;
    --accent-hover: #245a70;
    --accent-soft: #e7f1f5;
    --success: #2f7664;
    --success-soft: #edf7f3;
    --danger: #a8574f;
    --danger-soft: #f8eeee;
    --warning-bg: #fff8e6;
    --warning-text: #7a5a18;
    --radius: 6px;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}

* {
    box-sizing: border-box;
}

html {
    color-scheme: light;
}

body {
    min-height: 100vh;
    margin: 0;
    color: var(--text);
    font-family: "Source Sans 3", "Noto Sans Malayalam", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    font-size: 16px;
    line-height: 1.5;
    background:
        linear-gradient(180deg, #f7fafb 0%, var(--bg) 240px),
        var(--bg);
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}

button,
input,
select {
    font: inherit;
}

button {
    cursor: pointer;
    touch-action: manipulation;
}

button:focus-visible,
input:focus-visible,
select:focus-visible {
    outline: 2px solid var(--focus);
    outline-offset: 2px;
}

.app-shell {
    width: min(1280px, calc(100% - 48px));
    margin: 0 auto;
    padding: 32px 0;
    display: grid;
    grid-template-columns: 332px minmax(0, 1fr);
    gap: 24px;
    align-items: start;
}

.search-column {
    position: sticky;
    top: 24px;
    display: grid;
    gap: 12px;
}

.app-brand,
.search-card,
.results-column {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--panel);
    box-shadow: var(--shadow);
}

.app-brand {
    padding: 16px;
    display: flex;
    gap: 12px;
    align-items: center;
}

.brand-mark {
    width: 32px;
    height: 32px;
    flex: 0 0 auto;
    border: 1px solid var(--accent);
    border-radius: 50%;
    position: relative;
}

.brand-mark::before,
.brand-mark::after {
    content: "";
    position: absolute;
    left: 8px;
    right: 8px;
    height: 1px;
    background: var(--accent);
}

.brand-mark::before {
    top: 11px;
}

.brand-mark::after {
    bottom: 11px;
}

.app-brand p,
.section-label {
    margin: 0;
    color: #6f7f8d;
    font-size: 0.76rem;
    font-weight: 700;
    letter-spacing: 0;
    text-transform: uppercase;
}

h1,
h2,
h3 {
    margin: 0;
    letter-spacing: 0;
}

h1 {
    margin-top: 1px;
    font-size: 1.24rem;
    font-weight: 700;
    line-height: 1.2;
}

h2 {
    margin-top: 3px;
    font-size: clamp(1.5rem, 2vw, 2rem);
    font-weight: 700;
    line-height: 1.1;
}

h3 {
    font-size: 1rem;
    font-weight: 700;
}

.search-card {
    padding: 16px;
}

.form-section {
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border);
    display: grid;
    gap: 12px;
}

.form-section + .form-section {
    padding-top: 16px;
}

.field {
    display: grid;
    gap: 6px;
}

.field span {
    color: var(--text);
    font-size: 0.92rem;
    font-weight: 600;
}

input,
select {
    width: 100%;
    min-height: 42px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius);
    padding: 0 10px;
    color: var(--text);
    background: #fff;
    outline: none;
    font-variant-numeric: tabular-nums;
}

input::placeholder {
    color: var(--soft);
}

input:hover,
select:hover {
    border-color: #a3a3a3;
}

.swap-button {
    width: fit-content;
    min-height: 34px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0 10px;
    color: var(--text);
    background: #fff;
    font-size: 0.92rem;
    font-weight: 600;
}

.swap-button:hover,
.secondary-button:hover {
    border-color: var(--border-strong);
    background: var(--panel-subtle);
}

.swap-button span {
    margin-right: 6px;
    color: var(--muted);
}

.time-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.checkbox-row {
    min-height: 42px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0 10px;
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--text);
    background: #fff;
    font-weight: 600;
}

.checkbox-row input {
    width: 16px;
    height: 16px;
    min-height: auto;
    accent-color: var(--text);
}

.actions {
    padding-top: 16px;
    display: grid;
    grid-template-columns: 1fr 84px;
    gap: 10px;
}

.primary-button,
.secondary-button {
    min-height: 42px;
    border-radius: var(--radius);
    font-weight: 700;
}

.primary-button {
    border: 1px solid var(--accent);
    color: #fff;
    background: var(--accent);
}

.primary-button:hover {
    border-color: var(--accent-hover);
    background: var(--accent-hover);
}

.secondary-button {
    border: 1px solid var(--border-strong);
    color: var(--text);
    background: #fff;
}

.results-column {
    min-height: calc(100vh - 64px);
    padding: 20px;
}

.results-header {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    align-items: flex-start;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border);
}

.summary-pill {
    flex: 0 0 auto;
    min-width: 64px;
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 6px 10px;
    color: var(--accent-hover);
    background: var(--accent-soft);
    font-size: 0.92rem;
    font-weight: 700;
    text-align: center;
}

.results-list {
    margin-top: 16px;
    display: grid;
    gap: 10px;
}

.bus-card {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    background: #fff;
}

.bus-card.is-open {
    border-color: var(--border-strong);
}

.bus-summary {
    width: 100%;
    border: 0;
    padding: 14px 16px;
    display: grid;
    grid-template-columns: minmax(160px, 1fr) minmax(220px, 0.95fr) minmax(168px, auto) 24px;
    gap: 16px;
    align-items: center;
    text-align: left;
    background: #fff;
}

.bus-summary:hover {
    background: var(--panel-subtle);
}

.bus-title {
    min-width: 0;
    display: grid;
    gap: 1px;
}

.bus-name {
    color: var(--text);
    font-size: 1rem;
    font-weight: 700;
    overflow-wrap: anywhere;
}

.bus-number {
    color: var(--muted);
    font-size: 0.9rem;
    font-weight: 500;
    overflow-wrap: anywhere;
}

.time-pair {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    gap: 10px;
    align-items: center;
}

.time-pair strong,
.stop-time {
    font-variant-numeric: tabular-nums;
}

.time-pair strong {
    display: block;
    color: var(--text);
    font-size: 1rem;
    font-weight: 700;
}

.time-pair span {
    display: block;
    min-width: 0;
    color: var(--muted);
    font-size: 0.8rem;
    font-weight: 600;
    overflow-wrap: anywhere;
}

.arrow {
    color: var(--soft);
    font-weight: 700;
}

.bus-meta {
    display: flex;
    justify-content: flex-end;
    gap: 6px;
    flex-wrap: wrap;
}

.badge {
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 3px 8px;
    color: var(--accent-hover);
    background: var(--accent-soft);
    font-size: 0.8rem;
    font-weight: 600;
    white-space: nowrap;
}

.chevron {
    color: var(--muted);
    font-size: 1.1rem;
    transform: rotate(0deg);
    transition: transform 160ms ease;
}

.bus-card.is-open .chevron {
    transform: rotate(180deg);
}

.bus-detail {
    display: none;
    border-top: 1px solid var(--border);
    padding: 0;
    background: #fff;
}

.bus-card.is-open .bus-detail {
    display: block;
}

.route-map {
    position: relative;
    display: grid;
    max-width: none;
    padding: 10px 0;
}

.stop {
    position: relative;
    display: grid;
    grid-template-columns: 116px 20px minmax(0, 1fr);
    gap: 12px;
    min-height: 54px;
    padding: 9px 16px;
    border-bottom: 0;
}

.stop + .stop {
    margin-top: 2px;
}

.stop:not(:last-child)::before {
    content: "";
    position: absolute;
    left: 141px;
    top: 31px;
    bottom: -25px;
    width: 1px;
    background: var(--border);
}

.stop-time {
    color: var(--muted);
    font-size: 0.9rem;
    font-weight: 700;
    text-align: right;
    padding-top: 2px;
}

.stop-time small {
    display: block;
    color: var(--soft);
    font-size: 0.74rem;
    font-weight: 500;
}

.stop-dot {
    position: relative;
    z-index: 1;
    width: 10px;
    height: 10px;
    margin: 9px auto 0;
    border: 2px solid #fff;
    border-radius: 50%;
    background: #94a6b2;
    box-shadow: 0 0 0 1px #94a6b2;
}

.stop.start .stop-dot,
.stop.end .stop-dot {
    background: var(--accent);
    box-shadow: 0 0 0 1px var(--accent);
}

.stop.from-stop,
.stop.to-stop {
    background: var(--success-soft);
}

.stop.to-stop {
    background: var(--danger-soft);
}

.stop.from-stop::after,
.stop.to-stop::after {
    content: none;
}

.stop.from-stop .stop-dot,
.stop.to-stop .stop-dot {
    width: 14px;
    height: 14px;
    margin-top: 7px;
    background: var(--success);
    box-shadow: 0 0 0 1px var(--success);
}

.stop.to-stop .stop-dot {
    background: var(--danger);
    box-shadow: 0 0 0 1px var(--danger);
}

.stop-place {
    min-width: 0;
    padding: 2px 0;
}

.stop-place-line {
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}

.stop-place-line strong {
    color: var(--text);
    font-size: 0.94rem;
    font-weight: 700;
    overflow-wrap: anywhere;
}

.stop-meta-line {
    margin-top: 2px;
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}

.stop-note {
    color: var(--muted);
    font-size: 0.86rem;
}

.selected-stop-label,
.halt-note {
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 1px 6px;
    font-size: 0.7rem;
    font-weight: 700;
    line-height: 1.45;
    white-space: nowrap;
}

.selected-stop-label {
    color: var(--success);
    background: #fff;
    border-color: #b8d8ce;
}

.to-stop .selected-stop-label {
    color: var(--danger);
    background: #fff;
    border-color: #e4c3bf;
}

.halt-note {
    color: var(--warning-text);
    background: var(--warning-bg);
    border-color: #f3df9f;
}

.empty-state,
.loading-state {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 28px 18px;
    text-align: center;
    background: #fff;
}

.empty-state p {
    margin: 6px 0 0;
    color: var(--muted);
}

.loading-state {
    color: var(--muted);
    font-weight: 600;
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        scroll-behavior: auto !important;
        transition-duration: 0.01ms !important;
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
    }
}

@media (max-width: 980px) {
    .app-shell {
        grid-template-columns: 1fr;
    }

    .search-column {
        position: static;
    }
}

@media (max-width: 720px) {
    .app-shell {
        width: min(100% - 20px, 1280px);
        padding: 10px 0;
    }

    .time-grid,
    .actions {
        grid-template-columns: 1fr;
    }

    .results-header {
        flex-direction: column;
    }

    .bus-summary {
        grid-template-columns: 1fr 24px;
        gap: 12px;
    }

    .time-pair,
    .bus-meta {
        grid-column: 1 / -1;
        justify-content: flex-start;
    }

    .chevron {
        grid-column: 2;
        grid-row: 1;
        justify-self: end;
    }

    .stop {
        grid-template-columns: 78px 20px minmax(0, 1fr);
        gap: 10px;
        padding: 12px;
    }

    .stop:not(:last-child)::before {
        left: 99px;
    }
}
