:root {
    --bg: #f3f6fb;
    --surface: #ffffff;
    --surface-muted: #f0f2f8;
    --text: #1c2434;
    --text-muted: #5b6478;
    --border: #e3e7ef;
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --primary-soft: #e8f0ff;
    --success: #16a34a;
    --warning: #b45309;
    --shadow: 0 4px 20px rgba(28, 36, 52, 0.08);
    --radius: 12px;
    --radius-sm: 8px;
    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue",
        Arial, "Noto Sans", sans-serif;
}

* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    padding: 0;
    height: 100%;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font);
    font-size: 14px;
    line-height: 1.5;
}

body {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px;
    padding: 14px 24px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow);
    z-index: 10;
}

.app-header__brand {
    display: flex;
    align-items: center;
    gap: 14px;
}

.app-header__logo {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    background: linear-gradient(135deg, var(--primary) 0%, #5b8cff 100%);
    color: #fff;
    font-weight: 700;
    font-size: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    letter-spacing: 0.5px;
}

.app-header__titles h1 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
}

.app-header__titles p {
    margin: 2px 0 0;
    color: var(--text-muted);
    font-size: 12px;
}

.app-header__stats {
    text-align: right;
}

.app-header__right {
    display: flex;
    align-items: center;
    gap: 14px;
}

.mode-switch {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px;
    background: var(--surface-muted);
    border-radius: var(--radius);
    border: 1px solid var(--border);
}

.mode-switch__btn {
    padding: 8px 14px;
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    text-decoration: none;
    font-size: 13px;
    font-weight: 500;
    white-space: nowrap;
    transition: background 0.15s, color 0.15s;
}

.mode-switch__btn:hover {
    color: var(--text);
    background: rgba(255, 255, 255, 0.7);
}

.mode-switch__btn.is-active {
    background: var(--surface);
    color: var(--primary);
    box-shadow: 0 1px 4px rgba(28, 36, 52, 0.08);
}

.mode-banner {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 24px;
    background: var(--primary-soft);
    border-bottom: 1px solid var(--border);
    font-size: 13px;
}

.mode-banner__label {
    color: var(--text-muted);
}

.mode-banner__value {
    color: var(--primary-dark);
}

.stats-grid {
    display: flex;
    flex-direction: row;
    align-items: flex-end;
    gap: 16px;
}

.stats-grid__item {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    min-width: 52px;
}

.stats-grid__item span {
    font-size: 18px;
    font-weight: 700;
    color: var(--primary);
    line-height: 1;
}

.stats-grid__item small {
    color: var(--text-muted);
    font-size: 10px;
    margin-top: 2px;
    text-transform: uppercase;
    letter-spacing: 0.4px;
}

.logout-button {
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text-muted);
    font-family: inherit;
    font-size: 12px;
    font-weight: 700;
    cursor: pointer;
}

.logout-button:hover {
    color: var(--text);
    border-color: var(--text-muted);
}

.logout-button:focus-visible,
.mode-switch__btn:focus-visible,
.sync-action:focus-visible,
.quick-filter:focus-visible,
.btn:focus-visible,
.installation-item:focus-visible,
.skipped-item__link:focus-visible,
.balloon__link:focus-visible {
    outline: 3px solid var(--primary);
    outline-offset: 2px;
}

.login-page {
    min-height: 100vh;
    background:
        radial-gradient(circle at top left, rgba(37, 99, 235, 0.16), transparent 34rem),
        linear-gradient(180deg, #f8fbff 0%, var(--bg) 100%);
}

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

.login-card {
    width: min(420px, 100%);
    padding: 32px;
    border: 1px solid var(--border);
    border-radius: 22px;
    background: rgba(255, 255, 255, 0.96);
    box-shadow: 0 22px 60px rgba(28, 36, 52, 0.14);
}

.login-card__logo {
    width: 48px;
    height: 48px;
    display: grid;
    place-items: center;
    border-radius: 14px;
    background: linear-gradient(135deg, var(--primary) 0%, #5b8cff 100%);
    color: #fff;
    font-size: 15px;
    font-weight: 800;
}

.login-card h1 {
    margin: 18px 0 4px;
    font-size: 24px;
    line-height: 1.2;
}

.login-card p {
    margin: 0 0 22px;
    color: var(--text-muted);
}

.login-error {
    margin-bottom: 16px;
    padding: 10px 12px;
    border: 1px solid #fecaca;
    border-radius: var(--radius-sm);
    background: #fef2f2;
    color: #991b1b;
    font-size: 13px;
    font-weight: 700;
}

.login-form {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.field input[type="text"],
.field input[type="password"] {
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text);
    font-family: inherit;
    font-size: 14px;
}

.field input[type="text"]:focus,
.field input[type="password"]:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-soft);
}

.login-form__submit {
    margin-top: 4px;
    min-height: 42px;
}

.app-main {
    flex: 1;
    display: grid;
    grid-template-columns: 380px 1fr;
    min-height: 0;
}

.sidebar {
    background: var(--surface);
    border-right: 1px solid var(--border);
    padding: 20px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.filters {
    background: var(--surface);
}

.filters__title,
.legend__title {
    margin: 0 0 10px;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.6px;
}

.sync-action {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    margin: 0 0 14px;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface-muted);
    color: var(--text);
    font-family: inherit;
    font-size: 13px;
    font-weight: 600;
    line-height: 1.2;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s, color 0.15s, box-shadow 0.15s;
}

.sync-action:hover:not(:disabled) {
    background: var(--primary-soft);
    border-color: #c7d9ff;
    color: var(--primary-dark);
}

.sync-action:disabled {
    opacity: 0.75;
    cursor: not-allowed;
}

.sync-action__icon {
    display: inline-flex;
    flex-shrink: 0;
    color: var(--primary);
}

.sync-action:disabled .sync-action__icon {
    opacity: 0.6;
}

.sync-action .btn__spinner {
    flex-shrink: 0;
}

.btn__spinner {
    width: 14px;
    height: 14px;
    border: 2px solid rgba(37, 99, 235, 0.2);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

.sync-toast {
    position: fixed;
    top: 84px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 1000;
    max-width: min(560px, calc(100vw - 24px));
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    background: #1c2434;
    color: #fff;
    font-size: 13px;
    line-height: 1.45;
    box-shadow: 0 10px 30px rgba(28, 36, 52, 0.25);
}

.sync-toast--success {
    background: #166534;
}

.sync-toast--error {
    background: #b91c1c;
}

.filters__form {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.quick-filters {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
}

.quick-filter {
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface-muted);
    color: var(--text);
    font-family: inherit;
    font-size: 12px;
    font-weight: 700;
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s, color 0.15s;
}

.quick-filter:hover {
    border-color: var(--primary);
    background: var(--primary-soft);
    color: var(--primary-dark);
}

.quick-filter.is-active {
    border-color: var(--primary);
    background: var(--primary-soft);
    color: var(--primary-dark);
}

.field {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.field span {
    font-size: 12px;
    color: var(--text-muted);
    font-weight: 500;
}

.field input[type="date"] {
    padding: 9px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 14px;
    background: var(--surface);
    color: var(--text);
    transition: border-color 0.15s, box-shadow 0.15s;
}

.field input[type="date"]:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-soft);
}

.filters__actions {
    display: flex;
    gap: 8px;
    margin-top: 4px;
}

.btn {
    flex: 1;
    padding: 9px 14px;
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    border: 1px solid transparent;
    transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.btn--primary {
    background: var(--primary);
    color: #fff;
}

.btn--primary:hover {
    background: var(--primary-dark);
}

.btn--ghost {
    background: transparent;
    color: var(--text-muted);
    border-color: var(--border);
}

.btn--ghost:hover {
    color: var(--text);
    border-color: var(--text-muted);
}

.installations-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.installation-item {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    background: var(--surface);
    color: inherit;
    font: inherit;
    text-align: left;
    transition: border-color 0.15s, background 0.15s, transform 0.05s;
}

.installation-item:hover {
    border-color: var(--primary);
    background: var(--primary-soft);
}

.installation-item:active {
    transform: scale(0.99);
}

.installation-item__title {
    font-weight: 600;
    font-size: 14px;
    line-height: 1.3;
    color: var(--text);
}

.installation-item__responsible {
    margin-top: 4px;
    color: var(--text-muted);
    font-size: 12px;
}

.installation-item__meta {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-top: 6px;
    gap: 8px;
}

.installation-item__date {
    display: inline-block;
    padding: 2px 8px;
    background: var(--primary-soft);
    color: var(--primary-dark);
    border-radius: 999px;
    font-size: 11px;
    font-weight: 600;
    white-space: nowrap;
}

.installation-item__address {
    flex: 1;
    color: var(--text-muted);
    font-size: 12px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.muted {
    color: var(--text-muted);
    font-size: 13px;
}

.empty-state {
    padding: 24px 12px;
    text-align: center;
    color: var(--text-muted);
    border: 1px dashed var(--border);
    border-radius: var(--radius-sm);
}

.empty-state--compact {
    padding: 16px 10px;
}

.skipped {
    padding-top: 4px;
}

.skipped__summary {
    margin: -6px 0 12px;
    color: var(--text-muted);
    font-size: 12px;
}

.skipped__summary span {
    color: var(--warning);
    font-weight: 700;
}

.skipped-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.skipped-item {
    padding: 11px 12px;
    border: 1px solid #fed7aa;
    border-radius: var(--radius-sm);
    background: #fff7ed;
}

.skipped-item__title {
    color: var(--text);
    font-size: 13px;
    font-weight: 700;
    line-height: 1.3;
}

.skipped-item__meta {
    display: flex;
    flex-wrap: wrap;
    gap: 6px 10px;
    margin-top: 5px;
    color: var(--text-muted);
    font-size: 11px;
}

.skipped-item__reason {
    margin-top: 7px;
    color: #7c2d12;
    font-size: 12px;
    line-height: 1.35;
}

.skipped-item__link {
    display: inline-flex;
    margin-top: 9px;
    color: var(--primary-dark);
    font-size: 12px;
    font-weight: 700;
    text-decoration: none;
}

.skipped-item__link:hover {
    text-decoration: underline;
}

.map-wrapper {
    position: relative;
    min-height: 0;
}

.map {
    width: 100%;
    height: 100%;
}

.map-error {
    position: absolute;
    inset: 50% auto auto 50%;
    width: min(420px, calc(100% - 32px));
    transform: translate(-50%, -50%);
    padding: 14px 16px;
    border: 1px solid #fed7aa;
    border-radius: var(--radius);
    background: #fff7ed;
    color: #7c2d12;
    text-align: center;
    z-index: 4;
}

.map-error[hidden] {
    display: none;
}

.map-loader {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.6);
    backdrop-filter: blur(2px);
    z-index: 5;
}

.map-loader[hidden] {
    display: none;
}

.spinner {
    width: 36px;
    height: 36px;
    border: 3px solid var(--primary-soft);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* Балун Яндекс.Карт — содержимое карточки */
.balloon {
    font-family: var(--font);
    max-width: 360px;
    padding: 4px 2px;
}

.balloon__top {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 8px;
}

.balloon__title {
    margin: 0;
    font-size: 15px;
    font-weight: 700;
    line-height: 1.3;
    color: var(--text);
}

.balloon__badge {
    display: inline-flex;
    width: fit-content;
    padding: 2px 8px;
    border-radius: 999px;
    background: #fff7ed;
    color: var(--warning);
    font-size: 11px;
    font-weight: 700;
}

.balloon__badge--ok {
    background: #dcfce7;
    color: var(--success);
}

.balloon__row {
    display: flex;
    gap: 6px;
    margin-bottom: 4px;
    font-size: 12px;
    line-height: 1.4;
}

.balloon__label {
    color: var(--text-muted);
    flex-shrink: 0;
    min-width: 92px;
}

.balloon__value {
    color: var(--text);
    word-break: break-word;
}

.balloon__details {
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid var(--border);
}

.balloon__link {
    display: inline-block;
    margin-top: 8px;
    padding: 7px 12px;
    background: var(--primary);
    color: #fff !important;
    border-radius: var(--radius-sm);
    text-decoration: none;
    font-size: 12px;
    font-weight: 600;
}

.balloon__link:hover {
    background: var(--primary-dark);
}

@media (max-width: 880px) {
    html,
    body {
        height: auto;
        min-height: 100%;
    }

    body {
        min-height: 100dvh;
        background: linear-gradient(180deg, #f8fbff 0%, var(--bg) 220px);
    }

    .app-header {
        position: sticky;
        top: 0;
        align-items: flex-start;
        flex-wrap: wrap;
        padding: 12px 14px 14px;
        gap: 10px;
        box-shadow: 0 6px 18px rgba(28, 36, 52, 0.08);
    }

    .app-header__right {
        order: 2;
        width: 100%;
        flex-direction: column;
        align-items: stretch;
        gap: 0;
    }

    .app-header__right form {
        position: absolute;
        top: 12px;
        right: 14px;
        margin: 0;
        z-index: 1;
    }

    .stats-grid {
        display: grid;
        grid-template-columns: repeat(3, 1fr);
        gap: 8px;
        width: 100%;
        padding: 10px;
        background: var(--surface-muted);
        border: 1px solid var(--border);
        border-radius: var(--radius);
    }

    .stats-grid__item {
        align-items: center;
        min-width: 0;
        padding: 8px 4px;
        background: var(--surface);
        border: 1px solid var(--border);
        border-radius: 10px;
        text-align: center;
    }

    .stats-grid__item span {
        font-size: 18px;
    }

    .stats-grid__item small,
    .app-header__stats small {
        display: block;
        max-width: none;
        margin-top: 4px;
        font-size: 10px;
        line-height: 1.2;
        text-align: center;
        letter-spacing: 0.2px;
    }

    .app-header__brand {
        order: 1;
        min-width: 0;
        gap: 10px;
        padding-right: 72px;
    }

    .mode-switch {
        order: 3;
        width: 100%;
    }

    .mode-switch__btn {
        flex: 1;
        text-align: center;
        padding: 10px 8px;
        font-size: 12px;
    }

    .mode-banner {
        padding: 8px 14px;
    }

    .app-header__logo {
        width: 34px;
        height: 34px;
        border-radius: 9px;
        font-size: 12px;
        flex: 0 0 auto;
    }

    .app-header__titles {
        min-width: 0;
    }

    .app-header__titles h1 {
        font-size: 15px;
        line-height: 1.2;
    }

    .app-header__titles p {
        max-width: none;
        font-size: 11px;
        line-height: 1.25;
    }

    .app-main {
        flex: initial;
        display: flex;
        flex-direction: column;
        min-height: auto;
        padding: 12px;
        gap: 12px;
    }

    .sidebar {
        display: flex;
        order: 1;
        max-height: none;
        padding: 0;
        overflow: visible;
        background: transparent;
        border-right: none;
        border-bottom: none;
        gap: 12px;
    }

    .filters {
        order: 1;
        padding: 14px;
        border: 1px solid var(--border);
        border-radius: 18px;
        background: rgba(255, 255, 255, 0.96);
        box-shadow: 0 10px 28px rgba(28, 36, 52, 0.08);
    }

    .filters__title,
    .legend__title {
        margin-bottom: 8px;
        font-size: 11px;
        letter-spacing: 0.7px;
    }

    .sync-action {
        margin-bottom: 12px;
        min-height: 42px;
        border-radius: 12px;
        font-size: 12px;
    }

    .sync-toast {
        top: 72px;
        font-size: 12px;
    }

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

    .quick-filters,
    .filters__actions {
        grid-column: 1 / -1;
    }

    .quick-filter,
    .btn {
        min-height: 42px;
        border-radius: 12px;
        font-size: 12px;
    }

    .field input[type="date"] {
        min-height: 42px;
        border-radius: 12px;
        font-size: 13px;
    }

    .map-wrapper {
        order: 2;
        height: 58dvh;
        min-height: 390px;
        overflow: hidden;
        border: 1px solid var(--border);
        border-radius: 20px;
        background: var(--surface);
        box-shadow: 0 14px 34px rgba(28, 36, 52, 0.12);
    }

    .legend {
        order: 3;
        padding: 14px;
        border: 1px solid var(--border);
        border-radius: 18px;
        background: rgba(255, 255, 255, 0.96);
        box-shadow: 0 10px 28px rgba(28, 36, 52, 0.08);
    }

    .skipped {
        order: 4;
        padding: 14px;
        border: 1px solid var(--border);
        border-radius: 18px;
        background: rgba(255, 255, 255, 0.96);
        box-shadow: 0 10px 28px rgba(28, 36, 52, 0.08);
    }

    .installations-list {
        gap: 10px;
    }

    .installation-item {
        padding: 13px 14px;
        border-radius: 15px;
        box-shadow: 0 4px 14px rgba(28, 36, 52, 0.04);
    }

    .installation-item__title {
        font-size: 14px;
    }

    .installation-item__meta {
        flex-direction: column;
        align-items: flex-start;
        gap: 6px;
    }

    .installation-item__date {
        order: 1;
        padding: 3px 9px;
    }

    .installation-item__address {
        order: 2;
        width: 100%;
        white-space: normal;
        display: -webkit-box;
        -webkit-box-orient: vertical;
        -webkit-line-clamp: 2;
    }

    .balloon {
        max-width: min(320px, calc(100vw - 48px));
    }

    .balloon__row {
        flex-direction: column;
        gap: 1px;
        margin-bottom: 7px;
    }

    .balloon__label {
        min-width: 0;
        font-size: 11px;
    }
}

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

@media (max-width: 520px) {
    .app-main {
        padding: 10px;
        gap: 10px;
    }

    .app-header__titles p {
        display: none;
    }

    .stats-grid {
        gap: 6px;
        padding: 8px;
    }

    .stats-grid__item {
        padding: 7px 2px;
    }

    .stats-grid__item span {
        font-size: 17px;
    }

    .stats-grid__item small,
    .app-header__stats small {
        font-size: 9px;
    }

    .logout-button {
        padding: 7px 9px;
        font-size: 11px;
    }

    .filters__form {
        grid-template-columns: 1fr;
    }

    .quick-filters {
        grid-template-columns: 1fr 1fr 1fr;
        gap: 6px;
    }

    .quick-filter {
        padding-inline: 6px;
        font-size: 11px;
    }

    .filters__actions {
        display: grid;
        grid-template-columns: 1fr 1fr;
    }

    .map-wrapper {
        height: 56dvh;
        min-height: 340px;
        border-radius: 18px;
    }
}
