:root {
    color-scheme: light;
    font-family: Arial, Helvetica, sans-serif;
    --bg: #f6f7f9;
    --surface: #ffffff;
    --text: #17202a;
    --muted: #667085;
    --line: #d9dee7;
    --accent: #0f766e;
    --accent-dark: #115e59;
    --danger: #be123c;
    --danger-bg: #fff1f2;
    --danger-line: #fecdd3;
    --paused: #1d4ed8;
    --paused-bg: #eff6ff;
    --paused-line: #bfdbfe;
    --warning-bg: #fffbeb;
    --warning-line: #fde68a;
    --warning-text: #92400e;
    --neutral-bg: #f8fafc;
    --neutral-line: #cbd5e1;
    --neutral-text: #475569;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    background: var(--bg);
    color: var(--text);
}

button,
input,
select {
    font: inherit;
}

.app-shell {
    width: min(100%, 900px);
    margin: 0 auto;
    padding: 12px;
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 1;
    display: flex;
    flex-direction: column;
    gap: 10px;
    align-items: stretch;
    padding: 10px 0;
    background: var(--bg);
}

.tabs,
.userbar {
    display: flex;
    gap: 8px;
    align-items: center;
}

.userbar {
    min-width: 0;
    justify-content: space-between;
    font-size: 14px;
}

.limit-group,
.account-group {
    display: flex;
    gap: 6px;
    align-items: center;
}

.account-group {
    justify-content: flex-end;
}

.tabs {
    width: 100%;
}

.tab {
    flex: 1;
    text-align: center;
}

.tab,
.button {
    min-height: 42px;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 10px 14px;
    background: var(--surface);
    color: var(--text);
    text-decoration: none;
}

.tab-active,
.button {
    border-color: var(--accent);
    background: var(--accent);
    color: #ffffff;
}

.button {
    cursor: pointer;
}

.button:hover {
    background: var(--accent-dark);
}

.button-secondary {
    min-height: 36px;
    padding: 8px 10px;
    background: var(--surface);
    color: var(--text);
}

.button-secondary:hover {
    background: #eef2f6;
}

.panel,
.login-panel {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    padding: 18px;
}

.panel h1,
.login-panel h1 {
    margin: 0 0 14px;
    font-size: 24px;
}

.section-heading {
    display: flex;
    gap: 12px;
    align-items: flex-start;
    justify-content: space-between;
    margin-bottom: 14px;
}

.section-heading h1,
.section-heading p {
    margin: 0;
}

.settings-panel {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
    margin-bottom: 14px;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 10px;
    background: #ffffff;
}

.checkbox-row,
.setting-field {
    display: flex;
    gap: 8px;
    align-items: center;
    color: var(--text);
    font-size: 14px;
    font-weight: 700;
}

.checkbox-row input {
    width: 18px;
    height: 18px;
}

.setting-field input,
.setting-field select {
    width: 72px;
    min-height: 36px;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 6px 8px;
    background: #ffffff;
}

.setting-field select {
    width: auto;
}

.address-search {
    position: relative;
    display: grid;
    gap: 8px;
    margin-bottom: 14px;
}

.field-label {
    font-weight: 700;
}

.address-input {
    width: 100%;
    min-height: 48px;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 10px 12px;
    background: #ffffff;
}

.suggestions {
    position: absolute;
    top: calc(100% - 2px);
    right: 0;
    left: 0;
    z-index: 3;
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #ffffff;
    box-shadow: 0 12px 26px rgb(16 24 40 / 12%);
}

.suggestion-item {
    display: block;
    width: 100%;
    border: 0;
    border-bottom: 1px solid var(--line);
    padding: 12px;
    background: #ffffff;
    color: var(--text);
    cursor: pointer;
    text-align: left;
}

.suggestion-item:last-child {
    border-bottom: 0;
}

.suggestion-item:hover {
    background: #eef2f6;
}

.form-message {
    margin: 0;
    color: var(--muted);
    font-size: 14px;
}

.form-message-error {
    color: var(--danger);
}

.muted,
.dadata-counter {
    color: var(--muted);
}

.username {
    color: var(--text);
    font-weight: 700;
}

.address-list {
    display: grid;
    gap: 10px;
    margin: 0;
    padding: 0;
    list-style: none;
}

.address-card {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 10px;
    align-items: start;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 12px;
    background: #ffffff;
}

.address-card-warning {
    border-color: var(--danger-line);
    background: var(--danger-bg);
}

.address-card-warning .address-text,
.address-card-warning .address-meta:last-of-type {
    color: var(--danger);
}

.address-card-paused {
    border-color: var(--paused-line);
    background: var(--paused-bg);
}

.address-card-paused .address-text,
.address-card-paused .address-meta:last-of-type {
    color: var(--paused);
}

.address-main {
    min-width: 0;
}

.address-text,
.address-normalized,
.address-meta,
.empty-state {
    margin: 0;
}

.address-text {
    font-weight: 700;
    line-height: 1.3;
}

.address-normalized,
.address-meta,
.empty-state {
    color: var(--muted);
    font-size: 14px;
}

.address-normalized {
    margin-top: 6px;
}

.address-meta {
    margin-top: 8px;
}

.trip-list,
.unpaired-list {
    display: grid;
    gap: 10px;
    margin: 0;
    padding: 0;
    list-style: none;
}

.trip-card {
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 12px;
    background: #ffffff;
}

.trip-card-direction {
    border-color: var(--neutral-line);
    background: var(--neutral-bg);
}

.trip-card-direction .trip-distance {
    color: var(--neutral-text);
}

.trip-card h2,
.trip-card h3,
.unpaired-section h2 {
    margin: 0 0 10px;
    font-size: 18px;
}

.trip-address {
    font-weight: 700;
    line-height: 1.3;
}

.trip-distance,
.trip-leg {
    margin: 10px 0;
    color: var(--accent);
    font-weight: 700;
}

.trip-leg {
    margin: 6px 0;
    color: var(--muted);
}

.unpaired-section {
    margin-top: 18px;
}

.unpaired-list li {
    display: grid;
    gap: 4px;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 12px;
    background: #ffffff;
    font-weight: 700;
}

.debug-panel {
    margin-top: 32px;
    border: 1px dashed rgb(217 222 231 / 70%);
    border-radius: 8px;
    padding: 10px 12px;
    background: rgb(248 250 252 / 55%);
}

.debug-panel summary {
    cursor: pointer;
    color: rgb(102 112 133 / 70%);
    font-size: 13px;
    font-weight: 400;
}

.debug-panel pre {
    overflow-x: auto;
    margin: 12px 0 0;
    border-radius: 8px;
    padding: 12px;
    background: rgb(15 23 42 / 88%);
    color: rgb(226 232 240 / 88%);
    font-size: 12px;
    line-height: 1.45;
    white-space: pre-wrap;
}

.address-actions {
    display: grid;
    gap: 8px;
    justify-items: end;
}

.timer-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    justify-content: flex-end;
}

.timer-button {
    min-width: 48px;
    min-height: 36px;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 6px 8px;
    background: #ffffff;
    color: var(--text);
    cursor: pointer;
    font-size: 14px;
}

.timer-toggle {
    min-width: 64px;
}

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

.timer-button:disabled {
    cursor: wait;
    opacity: 0.65;
}

.icon-button {
    display: grid;
    width: 42px;
    height: 42px;
    place-items: center;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #ffffff;
    color: var(--danger);
    cursor: pointer;
    font-size: 26px;
    line-height: 1;
}

.icon-button:hover {
    background: var(--danger-bg);
    border-color: var(--danger-line);
}

.login-page {
    display: grid;
    min-height: 100vh;
    place-items: center;
    padding: 18px;
}

.login-panel {
    width: min(100%, 380px);
}

.login-form {
    display: grid;
    gap: 10px;
}

.login-form input {
    width: 100%;
    min-height: 46px;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 10px 12px;
    background: #ffffff;
}

.form-errors,
.errorlist {
    margin: 0;
    padding: 10px 12px;
    border-radius: 8px;
    background: var(--danger-bg);
    color: var(--danger);
    list-style-position: inside;
}

@media (max-width: 640px) {
    .userbar {
        justify-content: space-between;
    }

    .dadata-counter {
        font-size: 13px;
    }

    .address-card {
        grid-template-columns: 1fr;
    }

    .address-actions {
        grid-template-columns: 1fr 42px;
        align-items: center;
        justify-items: stretch;
    }

    .timer-actions {
        justify-content: flex-start;
    }
}
