:root {
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --primary-light: #eff6ff;
    --bg-page: #f8fafc;
    --card-bg: #ffffff;
    --border-color: #e2e8f0;
    --text-main: #0f172a;
    --text-muted: #64748b;
    --accent-success: #16a34a;
    --accent-danger: #ef4444;
    --radius-md: 8px;
    --radius-lg: 12px;
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.07), 0 2px 4px -2px rgb(0 0 0 / 0.05);
    --table-hover: #f1f5f9;
    --input-bg: #ffffff;
}

/* Tryb ciemny */
body.dark-theme {
    --primary: #3b82f6;
    --primary-hover: #60a5fa;
    --primary-light: rgba(59, 130, 246, 0.15);
    --bg-page: #0b0f17;
    --card-bg: #161e2e;
    --border-color: #27354a;
    --text-main: #f1f5f9;
    --text-muted: #94a3b8;
    --table-hover: #1e293b;
    --input-bg: #1a2333;
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.3);
    --shadow-md: 0 4px 10px rgb(0 0 0 / 0.4);
}

/* Przyciemnienie kafelków mapy bez używania zewnętrznego API */
body.dark-theme .leaflet-tile-pane {
    filter: brightness(0.7) invert(1) contrast(1.1) hue-rotate(180deg) saturate(0.4);
}

* {
    box-sizing: border-box;
}

body {
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    background-color: var(--bg-page);
    color: var(--text-main);
    margin: 0;
    padding: 1.25rem 1.5rem;
    line-height: 1.4;
    transition: background-color 0.2s, color 0.2s;
}

.header-section {
    margin-bottom: 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 1rem;
}

h1 {
    font-size: 1.5rem;
    font-weight: 700;
    margin: 0;
    letter-spacing: -0.025em;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

/* Przełącznik motywu */
.theme-toggle-btn {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    color: var(--text-main);
    border-radius: var(--radius-md);
    padding: 0.4rem 0.75rem;
    cursor: pointer;
    font-size: 0.85rem;
    display: flex;
    align-items: center;
    gap: 0.4rem;
    transition: all 0.15s;
}

.theme-toggle-btn:hover {
    background: var(--table-hover);
}

/* Statystyki w nagłówku */
.stats {
    display: flex;
    gap: 0.75rem;
}

.stat-card {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    padding: 0.4rem 0.75rem;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    font-size: 0.8rem;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.stat-card strong {
    font-size: 1rem;
    font-weight: 700;
    color: var(--text-main);
}

/* Układ góra: Panel boczny + Mapa */
.top-row {
    display: grid;
    grid-template-columns: 360px 1fr;
    gap: 1.25rem;
    align-items: stretch;
    margin-bottom: 1.5rem;
}

@media (max-width: 1024px) {
    .top-row {
        grid-template-columns: 1fr;
    }
}

.sidebar {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 1.25rem;
    box-shadow: var(--shadow-sm);
    display: flex;
    flex-direction: column;
    gap: 1rem;
    height: 620px;
    overflow-y: auto;
}

.sidebar-section {
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 1rem;
}

.sidebar-section:last-child {
    border-bottom: none;
    padding-bottom: 0;
}

.sidebar-title {
    font-size: 0.8rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
    display: block;
}

.geocode-group {
    display: flex;
    gap: 0.4rem;
}

.geocode-group input {
    flex: 1;
}

.hint-text {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin: 0 0 0.5rem 0;
}

.mode-row {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    margin-bottom: 0.75rem;
}

.filter-block {
    margin-top: 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    font-size: 0.85rem;
}

.checkbox-group {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    max-height: 110px;
    overflow-y: auto;
    background: var(--bg-page);
    padding: 0.5rem;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
}

label {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    cursor: pointer;
    user-select: none;
    font-size: 0.85rem;
}

input[type="text"],
input[type="number"],
select {
    font-family: inherit;
    font-size: 0.85rem;
    padding: 0.4rem 0.6rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background: var(--input-bg);
    color: var(--text-main);
    outline: none;
    transition: border-color 0.15s, box-shadow 0.15s;
    width: 100%;
}

input[type="text"]:focus,
input[type="number"]:focus,
select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.2);
}

input[type="radio"],
input[type="checkbox"] {
    accent-color: var(--primary);
    width: 14px;
    height: 14px;
    cursor: pointer;
}

.button, button {
    font-family: inherit;
    font-size: 0.85rem;
    font-weight: 500;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.45rem 0.75rem;
    background: var(--primary);
    color: #fff;
    text-decoration: none;
    border-radius: var(--radius-md);
    border: none;
    cursor: pointer;
    transition: background 0.15s, transform 0.05s;
    box-shadow: var(--shadow-sm);
}

.button:hover, button:hover {
    background: var(--primary-hover);
}

.button:active, button:active {
    transform: scale(0.98);
}

#reset-btn {
    background: var(--card-bg);
    color: var(--text-muted);
    border: 1px solid var(--border-color);
}

#reset-btn:hover {
    background: var(--table-hover);
    color: var(--text-main);
}

#export-link {
    background: #10b981;
}

#export-link:hover {
    background: #059669;
}

.action-buttons {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem;
    margin-top: 0.75rem;
}

.action-buttons #search-btn {
    grid-column: 1 / -1;
    padding: 0.6rem;
    font-weight: 600;
}

#geocode-message {
    font-size: 0.8rem;
    color: var(--accent-danger);
    margin-top: 0.35rem;
}

#geocode-candidates {
    margin-top: 0.5rem;
    border-top: 1px solid var(--border-color);
    padding-top: 0.5rem;
}

#geocode-candidates button {
    background: var(--bg-page);
    color: var(--text-main);
    width: 100%;
    text-align: left;
    margin: 0.25rem 0;
    justify-content: flex-start;
    font-size: 0.8rem;
}

#geocode-candidates button:hover {
    background: var(--primary-light);
    color: var(--primary);
}

#selected-point {
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--accent-success);
    margin-top: 0.4rem;
    word-break: break-word;
}

/* Mapa */
#map {
    width: 100%;
    height: 620px;
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-md);
    z-index: 1;
}

/* Wyniki na dole */
.result-list {
    width: 100%;
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    padding: 1.25rem;
    display: none;
    flex-direction: column;
    gap: 1rem;
}

.result-list-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 0.75rem;
}

.result-list-header-left {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.result-list h3 {
    margin: 0;
    font-size: 1.15rem;
    font-weight: 700;
}

.result-count {
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--primary);
    background: var(--primary-light);
    padding: 0.2rem 0.6rem;
    border-radius: 9999px;
}

.stats-boxes {
    display: grid;
    grid-template-columns: 1.5fr 1fr;
    gap: 1rem;
}

@media (max-width: 900px) {
    .stats-boxes {
        grid-template-columns: 1fr;
    }
}

.result-summary, .result-breakdown {
    border: 1px solid var(--border-color);
    background: var(--bg-page);
    border-radius: var(--radius-md);
    padding: 0.75rem;
    font-size: 0.85rem;
    line-height: 1.45;
}

.result-breakdown {
    max-height: 150px;
    overflow-y: auto;
}

.result-table-wrapper {
    overflow-x: auto;
    max-height: 550px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
}

#result-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}

#result-table th, #result-table td {
    padding: 0.6rem 0.85rem;
    border-bottom: 1px solid var(--border-color);
    text-align: left;
}

#result-table th {
    position: sticky;
    top: 0;
    background: var(--card-bg);
    font-weight: 600;
    color: var(--text-muted);
    border-bottom: 2px solid var(--border-color);
    z-index: 2;
    white-space: nowrap;
}

#result-table tr {
    cursor: pointer;
    transition: background 0.1s;
}

#result-table tr:hover {
    background: var(--table-hover);
}

#result-table tr.active {
    background: var(--primary-light);
    color: var(--primary);
    font-weight: 600;
}

body.dark-theme .leaflet-popup-content-wrapper,
body.dark-theme .leaflet-popup-tip {
    background: #1e293b;
    color: #f1f5f9;
}

.leaflet-popup-content-wrapper {
    border-radius: var(--radius-md);
    font-family: inherit;
    box-shadow: var(--shadow-md);
}

.leaflet-popup-content {
    font-size: 0.82rem;
    line-height: 1.35;
}
