:root {
    --bg-page: #f4f5fb;
    --bg-panel: #ffffff;
    --bg-header: linear-gradient(135deg, #0052cc, #4c6fff);
    --border-soft: #dde1ea;
    --text-main: #1f2430;
    --text-muted: #6b7280;
    --accent: #2563eb;
    --accent-soft: rgba(37, 99, 235, 0.08);
    --error: #b91c1c;
    --shadow-soft: 0 18px 35px rgba(15, 23, 42, 0.08);
    --radius-lg: 18px;
    --radius-sm: 10px;
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    background: radial-gradient(circle at top, #e0e7ff 0, #f4f5fb 45%, #f9fafb 100%);
    color: var(--text-main);
}

/* SZERSZE UI */
.page {
    width: min(1600px, 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: 20px;
}

.page-header h1 {
    margin: 0 0 4px;
    font-size: 22px;
    letter-spacing: 0.01em;
}

.subtitle {
    margin: 0;
    font-size: 13px;
    opacity: 0.85;
}

.panel {
    background: var(--bg-panel);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-soft);
    padding: 18px 18px 20px;
}

.field-row {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 14px;
}

.field-row--wrap {
    flex-wrap: wrap;
    align-items: flex-end;
}

.field-group {
    display: flex;
    flex-direction: row;
    gap: 4px;
}

.field-group--grow {
    flex: 1 1 160px;
}
#geoportalBtn {
    margin-left: auto;
    visibility: hidden;
}

.field-group--button {
    display: flex;
    justify-content: space-between;
    width: 100%;
}

.field-group--objects {
    min-width: 220px;
}

label {
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
}

.field {
    font-size: 14px;
    padding: 7px 10px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-soft);
    background: #f9fafb;
    outline: none;
    min-width: 140px;
    transition: border-color 0.15s ease, box-shadow 0.15s ease, background-color 0.15s ease;
}

.field:focus {
    border-color: var(--accent);
    background: #ffffff;
    box-shadow: 0 0 0 1px var(--accent-soft);
}

#layerSelect {
    min-width: 320px;
}

button {
    font-size: 14px;
    padding: 8px 16px;
    border-radius: 999px;
    border: none;
    background: var(--accent);
    color: #ffffff;
    font-weight: 500;
    cursor: pointer;
    transition: background-color 0.15s ease, transform 0.05s ease, box-shadow 0.15s ease;
    box-shadow: 0 10px 20px rgba(37, 99, 235, 0.25);
}

button:disabled {
    opacity: 0.5;
    cursor: default;
    box-shadow: none;
}

button:not(:disabled):hover {
    background: #1d4ed8;
}

button:not(:disabled):active {
    transform: translateY(1px);
    box-shadow: 0 6px 14px rgba(37, 99, 235, 0.3);
}

.btn-secondary {
    background: #0f172a;
    box-shadow: 0 10px 20px rgba(15, 23, 42, 0.15);
}

.btn-secondary:not(:disabled):hover {
    background: #111c33;
}

.object-boxes {
    min-height: 36px;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 4px 10px;
    background: #f9fafb;
}

.object-placeholder {
    font-size: 12px;
    color: var(--text-muted);
}

.object-boxes label {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 13px;
    padding: 2px 6px;
    border-radius: 999px;
    background: #eef2ff;
    cursor: pointer;
}

.object-boxes input[type="checkbox"] {
    accent-color: var(--accent);
}

.info-row {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 8px;
}

.info-text {
    font-size: 11px;
    color: var(--text-muted);
}

.info-text--right {
    margin-left: auto;
}

/* .error {
    margin-top: 10px;
    font-size: 13px;
    color: var(--error);
    background: #fee2e2;
    border-radius: var(--radius-sm);
    padding: 6px 8px;
} */

.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: 6px 8px;
    border-bottom: 1px solid #edf0f7;
    text-align: left;
    white-space: nowrap;
}

th {
    background: #f9fafb;
    font-weight: 600;
    font-size: 12px;
    color: #4b5563;
}

tbody tr:nth-child(odd) {
    background: #fcfcff;
}

tbody tr:hover {
    background: #eef2ff;
}

/* NOWE: UI warunków */
.filters {
    margin-top: 10px;
    margin-bottom: 6px;
}

.filters-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 10px;
}

.filters-title {
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
    font-weight: 700;
}

.conditions {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

/* === WARUNKI: równe, proste, 1 wiersz = 1 obiekt === */

.cond-head {
    display: grid;
    grid-template-columns: 90px 360px 160px 1fr 44px;
    gap: 10px;
    padding: 0 10px 6px 10px;
    color: var(--text-muted);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: .06em;
    font-weight: 700;
}

.cond-row {
    display: grid;
    grid-template-columns: 90px 360px 160px 1fr 44px;
    gap: 10px;
    align-items: center;
    padding: 10px;
    border: 1px solid var(--border-soft);
    border-radius: var(--radius-sm);
    background: #fbfcff;
}

.cond-row .field-group {
    gap: 0;
}

.cond-row .field-group>label {
    display: none;
    /* etykiety są w .cond-head */
}

.cond-join,
.cond-attr,
.cond-op,
.cond-val {
    width: 100% !important;
    min-width: 0 !important;
}

.cond-val {
    height: 38px;
}

.icon-btn {
    all: unset;
    /* zdejmuje niebieskie style buttona */
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;

    background: #ef4444;
    /* czerwony */
    color: #ffffff;
}

/* mobile */
@media (max-width: 900px) {
    .cond-head {
        display: none;
    }

    .cond-row {
        grid-template-columns: 1fr;
    }

    .cond-row .field-group>label {
        display: block;
        margin-bottom: 4px;
    }

    .cond-row .field-group {
        gap: 4px;
    }

    .icon-btn {
        justify-self: start;
    }
}

/* na mniejszych ekranach łamie się sensownie */
@media (max-width: 900px) {
    .cond-row {
        flex-wrap: wrap;
    }

    .cond-attr {
        width: 100%;
    }

    .cond-val {
        width: 100%;
    }

    .icon-btn {
        margin-left: 0;
    }
}

.icon-btn i {
    font-size: 14px;
    line-height: 1;
}

.icon-btn:hover {
    background: #dc2626;
}

.icon-btn:disabled {
    opacity: 0.4;
    cursor: default;
}

/* status: loader / ok */
.status {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    color: var(--text-muted);
}

.status .ok {
    color: #16a34a;
    font-weight: 800;
}

.status .spin {
    animation: spin 1s linear infinite;
}

@keyframes spin {
    from {
        transform: rotate(0deg);
    }

    to {
        transform: rotate(360deg);
    }
}

@media (max-width: 720px) {
    .panel {
        padding: 14px 12px 16px;
    }

    .page {
        margin-top: 16px;
        width: 96vw;
    }

    #layerSelect {
        width: 100%;
    }

    .field-row {
        flex-direction: column;
        align-items: stretch;
    }

    .field-row--wrap {
        flex-direction: column;
        align-items: stretch;
    }

    .field-group--button {
        align-items: stretch;
    }

    button {
        width: 100%;
    }
}