:root {
    --bg-page: #f4f5fb;
    --bg-panel: #ffffff;
    --bg-header: linear-gradient(135deg, #0b5cff, #5b7cff);

    --border-soft: rgba(15, 23, 42, 0.10);
    --border-strong: rgba(15, 23, 42, 0.14);

    --text-main: #0f172a;
    --text-muted: #6b7280;

    --accent: #2563eb;
    --accent-hover: #1d4ed8;
    --accent-soft: rgba(37, 99, 235, 0.14);

    --danger: #ef4444;
    --danger-hover: #dc2626;

    --shadow-soft: 0 18px 35px rgba(15, 23, 42, 0.08);
    --shadow-tight: 0 10px 20px rgba(15, 23, 42, 0.08);

    --radius-lg: 18px;
    --radius-sm: 12px;

    --control-h: 40px;
    --label-w: 160px;

    --gap: 12px;
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

body {
    margin: 0;
    min-height: 100vh;
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    color: var(--text-main);
    background: radial-gradient(circle at top, #e0e7ff 0, #f4f5fb 45%, #f9fafb 100%);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

.page {
    width: min(1200px, 96vw);
    margin: 28px auto;
    padding: 0 16px;
}

.page-header {
    background: var(--bg-header);
    color: #f9fafb;
    padding: 20px 22px;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-soft);
    margin-bottom: 18px;
}

.page-header h1 {
    margin: 0 0 4px;
    font-size: 22px;
    letter-spacing: 0.01em;
}

.subtitle {
    margin: 0;
    font-size: 13px;
    opacity: 0.88;
}

.panel {
    background: var(--bg-panel);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-soft);
    padding: 18px 18px 20px;
}


.field-row {
    display: grid;
    grid-template-columns: 1fr;
    gap: var(--gap);
    margin-bottom: 14px;
}

.field-row--wrap {
    grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
    align-items: start;
}

.field-group {
    display: grid;
    grid-template-columns: var(--label-w) 1fr;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.field-group--grow {
    min-width: 0;
}

.field-group--objects {
    min-width: 260px;
    align-items: start;
}

.field-group--button {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
    justify-content: flex-start;
    width: 100%;
}

.filters-head {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 10px;
}

.filters-head>* {
    min-width: 0;
}

.filters-title {
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
    font-weight: 800;
}

.filters-head button,
.filters-head .btn,
.filters-head .btn-secondary {
    margin-left: auto;
}

#geoportalBtn {
    margin-left: auto;
    visibility: hidden;
}


label {
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
    line-height: 1.1;
    white-space: nowrap;
}

.field {
    width: 100%;
    min-width: 0;
    height: var(--control-h);

    font-size: 14px;
    padding: 8px 10px;

    border-radius: var(--radius-sm);
    border: 1px solid var(--border-soft);
    background: #f9fafb;

    outline: none;
    transition: border-color 0.15s ease, box-shadow 0.15s ease, background-color 0.15s ease;
}

.field::placeholder {
    color: rgba(107, 114, 128, 0.85);
}

.field:focus {
    border-color: var(--accent);
    background: #ffffff;
    box-shadow: 0 0 0 4px var(--accent-soft);
}

#layerSelect {
    width: 100%;
}

button {
    height: var(--control-h);
    font-size: 14px;
    padding: 0 16px;

    border-radius: 999px;
    border: 1px solid transparent;
    background: var(--accent);
    color: #ffffff;

    font-weight: 600;
    cursor: pointer;

    transition: background-color 0.15s ease, transform 0.05s ease, box-shadow 0.15s ease, border-color 0.15s ease;
    box-shadow: 0 10px 18px rgba(37, 99, 235, 0.22);
    white-space: nowrap;
}

button:disabled {
    opacity: 0.55;
    cursor: default;
    box-shadow: none;
}

button:not(:disabled):hover {
    background: var(--accent-hover);
}

button:not(:disabled):active {
    transform: translateY(1px);
    box-shadow: 0 6px 14px rgba(37, 99, 235, 0.28);
}

.btn-secondary {
    background: #0f172a;
    box-shadow: 0 10px 18px rgba(15, 23, 42, 0.14);
}

.btn-secondary:not(:disabled):hover {
    background: #111c33;
}

.object-boxes {
    min-height: var(--control-h);
    height: auto;
    max-height: none;
    overflow: visible;

    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    gap: 8px 10px;

    padding: 8px 10px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-soft);
    background: #f9fafb;
}

.object-boxes::-webkit-scrollbar {
    height: 10px;
    width: 10px;
}

.object-boxes::-webkit-scrollbar-thumb {
    background: rgba(15, 23, 42, 0.18);
    border-radius: 999px;
}

.object-boxes::-webkit-scrollbar-track {
    background: transparent;
}

.object-placeholder {
    font-size: 12px;
    color: var(--text-muted);
}

.object-boxes label {
    display: inline-flex;
    align-items: center;
    gap: 8px;

    font-size: 13px;
    padding: 6px 12px;
    border-radius: 999px;

    background: #eef2ff;
    border: 1px solid rgba(37, 99, 235, 0.18);
    cursor: pointer;
    user-select: none;
}

.object-boxes input[type="checkbox"] {
    accent-color: var(--accent);
}

.info-row {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 10px;
}

.info-text {
    font-size: 11px;
    color: var(--text-muted);
}

.info-text--right {
    margin-left: auto;
}

.table-container {
    margin-top: 14px;
    max-height: 520px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-soft);
    overflow: auto;
    background: #ffffff;
}

table {
    border-collapse: collapse;
    width: 100%;
    font-size: 13px;
}

thead {
    position: sticky;
    top: 0;
    z-index: 1;
}

th,
td {
    padding: 8px 10px;
    border-bottom: 1px solid rgba(237, 240, 247, 0.9);
    text-align: left;
    white-space: nowrap;
}

th {
    background: #f9fafb;
    font-weight: 800;
    font-size: 12px;
    color: #4b5563;
}

tbody tr:nth-child(odd) {
    background: #fcfcff;
}

tbody tr:hover {
    background: #eef2ff;
}


.filters {
    margin-top: 10px;
    margin-bottom: 6px;
}

.conditions {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.cond-head {
    display: grid;
    grid-template-columns: 120px 360px 160px 1fr 44px;
    gap: 10px;
    padding: 6px 10px 6px 10px;
    margin-top: 6px;
    margin-bottom: 2px;

    color: var(--text-muted);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: .06em;
    font-weight: 900;
}

.cond-row {
    display: grid;
    grid-template-columns: 120px 360px 160px 1fr 44px;
    gap: 10px;
    align-items: start;
    padding: 10px;

    border: 1px solid var(--border-soft);
    border-radius: var(--radius-sm);
    background: #fbfcff;
    box-shadow: var(--shadow-tight);
}

.cond-row>* {
    min-width: 0;
}

.cond-row>* {
    min-width: 0;
}

.cond-row .field-group {
    display: block;
    min-width: 0;
}

.cond-row .field-group>label {
    display: none;
}

.cond-join,
.cond-attr,
.cond-op,
.cond-val {
    width: 100% !important;
    min-width: 0 !important;
}

.cond-join {
    text-align: center;
}

.cond-val {
    height: var(--control-h);
}
.cond-join--first {
    display: flex;
    align-items: center;
    justify-content: center;
    color: rgba(107, 114, 128, 0.9);
    background: #f3f4f6;
    border: 1px dashed rgba(15, 23, 42, 0.18);
    font-weight: 700;
}
.icon-btn {
    all: unset;
    width: 36px;
    height: 36px;
    border-radius: 999px;

    display: flex;
    align-items: center;
    justify-content: center;

    cursor: pointer;
    background: var(--danger);
    color: #ffffff;

    box-shadow: 0 10px 18px rgba(239, 68, 68, 0.18);
    transition: background-color 0.15s ease, transform 0.05s ease, box-shadow 0.15s ease;
}

.icon-btn i {
    font-size: 14px;
    line-height: 1;
}

.icon-btn:hover {
    background: var(--danger-hover);
}

.icon-btn:active {
    transform: translateY(1px);
    box-shadow: 0 6px 12px rgba(239, 68, 68, 0.22);
}

.icon-btn:disabled {
    opacity: 0.45;
    cursor: default;
    box-shadow: none;
}

.status {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    color: var(--text-muted);
}

.status .ok {
    color: #16a34a;
    font-weight: 900;
}

.status .spin {
    animation: spin 1s linear infinite;
}

@keyframes spin {
    from {
        transform: rotate(0deg);
    }

    to {
        transform: rotate(360deg);
    }
}

@media (max-width: 980px) {
    :root {
        --label-w: 140px;
    }

    .field-row--wrap {
        grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    }

    .cond-head,
    .cond-row {
        grid-template-columns: 80px 1.2fr 140px 1fr 44px;
    }
}

@media (max-width: 720px) {
    .panel {
        padding: 14px 12px 16px;
    }

    .page {
        margin-top: 16px;
        width: 96vw;
    }

    .field-group {
        grid-template-columns: 1fr;
        gap: 6px;
        align-items: stretch;
    }

    label {
        white-space: normal;
    }

    .field-row--wrap {
        grid-template-columns: 1fr;
    }

    button {
        width: 100%;
    }

    .object-boxes {
        max-height: 180px;
    }

    .cond-head {
        display: none;
    }

    .cond-row {
        grid-template-columns: 1fr;
        gap: 10px;
    }

    .cond-row .field-group>label {
        display: block;
        margin-bottom: 4px;
    }

    .cond-row .field-group {
        gap: 6px;
    }

    .icon-btn {
        justify-self: start;
    }
}

@media (max-width: 360px) {
    .page-header h1 {
        font-size: 20px;
    }
}