/* ─── Reset & Base ─── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --blue:    #3b82f6;
    --blue-d:  #2563eb;
    --green:   #22c55e;
    --orange:  #f97316;
    --orange-d:#ea580c;
    --gray-50: #f8fafc;
    --gray-100:#f1f5f9;
    --gray-200:#e2e8f0;
    --gray-400:#94a3b8;
    --gray-500:#64748b;
    --gray-700:#334155;
    --gray-900:#0f172a;
    --radius:  10px;
    --shadow:  0 1px 4px rgba(0,0,0,.08), 0 4px 16px rgba(0,0,0,.04);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--gray-50);
    color: var(--gray-900);
    min-height: 100vh;
    font-size: 15px;
    line-height: 1.5;
}

/* ─── Header ─── */
.header {
    background: #fff;
    border-bottom: 1px solid var(--gray-200);
    position: sticky;
    top: 0;
    z-index: 100;
}
.header-inner {
    max-width: 900px;
    margin: 0 auto;
    padding: 0 20px;
    height: 56px;
    display: flex;
    align-items: center;
}
.logo { display: flex; align-items: center; gap: 8px; }
.logo-icon { font-size: 22px; }
.logo-text { font-size: 17px; font-weight: 700; color: var(--gray-900); }

/* ─── Main ─── */
.main {
    max-width: 900px;
    margin: 0 auto;
    padding: 40px 20px 60px;
}

/* ─── Hero ─── */
.hero { text-align: center; margin-bottom: 32px; }
.hero h1 {
    font-size: clamp(22px, 4vw, 34px);
    font-weight: 800;
    letter-spacing: -0.5px;
    line-height: 1.2;
    margin-bottom: 10px;
    color: var(--gray-900);
}
.hero-sub { color: var(--gray-500); font-size: 14px; }

/* ─── Card ─── */
.card {
    background: #fff;
    border-radius: 16px;
    box-shadow: var(--shadow);
    padding: 24px;
    margin-bottom: 20px;
}

/* ─── Form ─── */
label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .5px;
    color: var(--gray-500);
    margin-bottom: 6px;
}

input[type="text"],
input[type="number"] {
    width: 100%;
    padding: 11px 14px;
    border: 1.5px solid var(--gray-200);
    border-radius: var(--radius);
    font-size: 15px;
    color: var(--gray-900);
    background: var(--gray-50);
    transition: border-color .15s, box-shadow .15s, background .15s;
    -moz-appearance: textfield;
}
input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button { -webkit-appearance: none; }
input[type="text"]:focus,
input[type="number"]:focus {
    outline: none;
    border-color: var(--blue);
    background: #fff;
    box-shadow: 0 0 0 3px rgba(59,130,246,.12);
}

/* ─── Cities Row ─── */
.cities-row {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    margin-bottom: 16px;
}
.city-group { flex: 1; min-width: 0; }

.swap-btn {
    flex-shrink: 0;
    width: 40px;
    height: 40px;
    margin-bottom: 1px; /* align with input bottom */
    border: 1.5px solid var(--gray-200);
    border-radius: var(--radius);
    background: #fff;
    color: var(--gray-500);
    font-size: 18px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: border-color .15s, color .15s, background .15s;
}
.swap-btn:hover {
    border-color: var(--blue);
    color: var(--blue);
    background: rgba(59,130,246,.05);
}

/* ─── Params Row ─── */
.params-row {
    display: flex;
    align-items: flex-end;
    gap: 12px;
    flex-wrap: wrap;
}
.param-group--weight { width: 110px; flex-shrink: 0; }

.dimensions-group { flex: 1; min-width: 200px; }
.dim-label { display: block; }
.optional { font-weight: 400; text-transform: none; color: var(--gray-400); font-size: 11px; }
.dim-inputs {
    display: flex;
    align-items: center;
    gap: 6px;
}
.dim-inputs input { text-align: center; }
.dim-sep { color: var(--gray-400); font-size: 16px; flex-shrink: 0; }

/* ─── Calc Button ─── */
.calc-btn {
    flex-shrink: 0;
    height: 44px;
    padding: 0 28px;
    background: var(--blue);
    color: #fff;
    border: none;
    border-radius: var(--radius);
    font-size: 15px;
    font-weight: 700;
    cursor: pointer;
    transition: background .15s, transform .1s;
    white-space: nowrap;
}
.calc-btn:hover  { background: var(--blue-d); }
.calc-btn:active { transform: scale(.98); }
.calc-btn:disabled { background: #93c5fd; cursor: not-allowed; transform: none; }

/* ─── Autocomplete ─── */
.autocomplete-wrap { position: relative; }
.ac-list {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    background: #fff;
    border: 1.5px solid var(--gray-200);
    border-radius: var(--radius);
    box-shadow: 0 8px 24px rgba(0,0,0,.10);
    list-style: none;
    z-index: 200;
    max-height: 220px;
    overflow-y: auto;
    display: none;
}
.ac-list.open { display: block; }
.ac-list li {
    padding: 10px 14px;
    cursor: pointer;
    font-size: 14px;
    transition: background .1s;
}
.ac-list li:hover,
.ac-list li.focused { background: var(--gray-100); }
.ac-list li mark {
    background: transparent;
    color: var(--blue);
    font-weight: 700;
}

/* ─── Spinner ─── */
.spinner {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 14px;
    padding: 40px;
    color: var(--gray-500);
}
.spinner-ring {
    width: 28px; height: 28px;
    border: 3px solid var(--gray-200);
    border-top-color: var(--blue);
    border-radius: 50%;
    animation: spin .7s linear infinite;
    flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ─── Errors ─── */
.errors-block {
    background: #fef2f2;
    border: 1px solid #fecaca;
    border-radius: var(--radius);
    padding: 12px 16px;
    margin-bottom: 16px;
    color: #991b1b;
    font-size: 13px;
    line-height: 1.6;
}

/* ─── Sort Bar ─── */
.sort-bar {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 14px;
    flex-wrap: wrap;
}
.sort-label { font-size: 13px; color: var(--gray-500); font-weight: 500; }
.sort-tabs { display: flex; gap: 6px; flex-wrap: wrap; }
.sort-tab {
    padding: 6px 14px;
    border: 1.5px solid var(--gray-200);
    border-radius: 20px;
    background: #fff;
    font-size: 13px;
    font-weight: 600;
    color: var(--gray-500);
    cursor: pointer;
    transition: all .15s;
}
.sort-tab:hover { border-color: var(--blue); color: var(--blue); }
.sort-tab.active {
    background: var(--blue);
    border-color: var(--blue);
    color: #fff;
}

/* ─── Results ─── */
.results { display: flex; flex-direction: column; gap: 10px; }

.quote-card {
    background: #fff;
    border-radius: 14px;
    padding: 18px 22px;
    box-shadow: var(--shadow);
    display: grid;
    grid-template-columns: 1fr auto auto;
    align-items: center;
    gap: 20px;
    border: 1.5px solid transparent;
    transition: box-shadow .15s, border-color .15s;
}
.quote-card:hover { box-shadow: 0 4px 20px rgba(0,0,0,.10); }
.quote-card.best { border-color: var(--green); }
.quote-card.best .quote-carrier-name::after {
    content: " 🏆";
    font-size: 13px;
}

.quote-carrier-name {
    font-weight: 700;
    font-size: 16px;
    color: var(--gray-900);
}
.quote-service {
    font-size: 12px;
    color: var(--gray-400);
    margin-top: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 220px;
}
.quote-rating { font-size: 12px; color: #f59e0b; margin-top: 4px; }

.quote-stats {
    display: flex;
    gap: 28px;
    align-items: center;
}
.quote-stat { text-align: center; }
.quote-stat-value { font-size: 20px; font-weight: 700; }
.quote-stat-label { font-size: 11px; color: var(--gray-400); margin-top: 1px; }
.quote-price .quote-stat-value { color: #059669; }

.quote-action a {
    display: inline-block;
    background: var(--orange);
    color: #fff;
    text-decoration: none;
    padding: 9px 22px;
    border-radius: var(--radius);
    font-weight: 700;
    font-size: 14px;
    transition: background .15s;
    white-space: nowrap;
}
.quote-action a:hover { background: var(--orange-d); }

/* ─── Carrier group (accordion) ─── */
.carrier-group {
    display: flex;
    flex-direction: column;
}
.carrier-group + .carrier-group { margin-top: 10px; }

/* Убираем скругление снизу у первой карточки, если за ней следует кнопка аккордиона */
.carrier-group .quote-card:first-child:not(:only-child) {
    border-radius: 14px 14px 0 0;
    box-shadow: 0 1px 4px rgba(0,0,0,.08);
}

.accordion-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    width: 100%;
    padding: 8px 16px;
    background: var(--gray-100);
    border: 1.5px solid var(--gray-200);
    border-top: none;
    border-radius: 0 0 12px 12px;
    color: var(--gray-500);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: background .15s, color .15s;
}
.accordion-toggle:hover {
    background: var(--gray-200);
    color: var(--gray-700);
}
.accordion-arrow {
    font-size: 11px;
    display: inline-block;
    transition: transform .2s ease;
    line-height: 1;
}

.accordion-body {
    display: none;
    flex-direction: column;
    gap: 4px;
    padding-top: 4px;
}
.accordion-body.open { display: flex; }

.accordion-body .quote-card {
    border-radius: 10px;
    padding: 14px 18px;
}
.accordion-body .quote-card:last-child {
    border-radius: 10px 10px 12px 12px;
}

/* ─── No results ─── */
.no-results {
    text-align: center;
    padding: 48px 20px;
    color: var(--gray-400);
}
.no-results p { margin-top: 8px; font-size: 14px; }

/* ─── Util ─── */
.hidden { display: none !important; }

/* ─── Mobile ─── */
@media (max-width: 640px) {
    .cities-row { flex-wrap: wrap; }
    .swap-btn { align-self: center; margin-top: 18px; }

    .params-row { flex-direction: column; align-items: stretch; }
    .param-group--weight { width: 100%; }
    .calc-btn { width: 100%; }

    .quote-card {
        grid-template-columns: 1fr;
        gap: 12px;
    }
    .quote-stats { justify-content: flex-start; }
    .quote-action a { width: 100%; display: block; text-align: center; }
}
