:root {
    --bg: #f3f6fa;
    --surface: #ffffff;
    --text: #122033;
    --muted: #64748b;
    --line: #dbe4ef;
    --primary: #0f766e;
    --primary-dark: #0b5e58;
    --danger: #b42318;
    --shadow: 0 12px 32px rgba(15, 23, 42, .08);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
    margin: 0;
    font-family: Tahoma, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
}
button, input, select { font: inherit; }

.app-shell {
    min-height: 100vh;
    display: grid;
    grid-template-rows: auto auto auto minmax(520px, 1fr) auto;
    gap: 14px;
    padding: 18px;
}

.topbar,
.toolbar,
.stats,
.map-wrap,
.footer-note {
    width: min(1600px, 100%);
    margin-inline: auto;
}

.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
}
.topbar h1 { margin: 0 0 6px; font-size: 24px; }
.topbar p { margin: 0; color: var(--muted); }
.provider-badge {
    padding: 9px 13px;
    border-radius: 999px;
    background: #e6fffb;
    color: var(--primary-dark);
    border: 1px solid #99f6e4;
    font-weight: 700;
    white-space: nowrap;
}

.toolbar {
    display: grid;
    grid-template-columns: 180px 1fr 1fr minmax(240px, 1.4fr) auto;
    gap: 12px;
    align-items: end;
    padding: 16px;
    border: 1px solid var(--line);
    border-radius: 16px;
    background: var(--surface);
    box-shadow: var(--shadow);
}
.field { min-width: 0; }
.field label {
    display: block;
    margin-bottom: 7px;
    font-size: 13px;
    font-weight: 700;
    color: #334155;
}
.field input,
.field select {
    width: 100%;
    height: 43px;
    padding: 0 12px;
    border: 1px solid #cbd5e1;
    border-radius: 10px;
    background: #fff;
    color: var(--text);
    outline: none;
}
.field input:focus,
.field select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(15, 118, 110, .12);
}
.field input:disabled { background: #f8fafc; color: #475569; }
.actions { display: flex; gap: 8px; }
.button {
    height: 43px;
    border: 1px solid #cbd5e1;
    border-radius: 10px;
    padding: 0 16px;
    background: #fff;
    cursor: pointer;
    white-space: nowrap;
}
.button:hover { background: #f8fafc; }
.button.primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.button.primary:hover { background: var(--primary-dark); }

.stats {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
}
.stat-card {
    padding: 14px 16px;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: var(--surface);
}
.stat-card span { display: block; color: var(--muted); font-size: 12px; margin-bottom: 7px; }
.stat-card strong { font-size: 21px; }
.stat-card.accent { border-color: #99f6e4; background: #f0fdfa; }

.map-wrap {
    position: relative;
    overflow: hidden;
    min-height: 520px;
    border: 1px solid var(--line);
    border-radius: 18px;
    background: #dce7ef;
    box-shadow: var(--shadow);
}
#map { width: 100%; height: 100%; min-height: 520px; }
.loading {
    position: absolute;
    z-index: 1000;
    top: 14px;
    right: 50%;
    transform: translateX(50%);
    padding: 10px 16px;
    border-radius: 999px;
    background: rgba(15, 23, 42, .9);
    color: #fff;
    box-shadow: 0 6px 18px rgba(15, 23, 42, .25);
}
.loading.hidden { display: none; }
.loading.error { background: var(--danger); }

.map-popup { min-width: 235px; direction: rtl; text-align: right; }
.map-popup h3 { margin: 0 0 10px; font-size: 16px; }
.map-popup dl { margin: 0; }
.map-popup .row { display: grid; grid-template-columns: 92px 1fr; gap: 8px; padding: 5px 0; border-bottom: 1px solid #edf2f7; }
.map-popup dt { color: var(--muted); }
.map-popup dd { margin: 0; font-weight: 700; overflow-wrap: anywhere; }
.map-popup .detail-link {
    display: block;
    margin-top: 12px;
    padding: 8px 10px;
    border-radius: 8px;
    background: var(--primary);
    color: #fff;
    text-align: center;
    text-decoration: none;
}

.footer-note { color: var(--muted); font-size: 12px; text-align: center; padding-bottom: 4px; }
.leaflet-control-attribution { direction: ltr; }

@media (max-width: 1100px) {
    .toolbar { grid-template-columns: repeat(2, 1fr); }
    .actions { grid-column: 1 / -1; }
}
@media (max-width: 720px) {
    .app-shell { padding: 10px; gap: 10px; grid-template-rows: auto auto auto minmax(480px, 1fr) auto; }
    .topbar { align-items: flex-start; }
    .topbar h1 { font-size: 19px; }
    .provider-badge { font-size: 12px; }
    .toolbar { grid-template-columns: 1fr; padding: 12px; }
    .actions { grid-column: auto; }
    .button { flex: 1; }
    .stats { grid-template-columns: repeat(2, 1fr); }
    #map, .map-wrap { min-height: 480px; }
}
