:root {
    --bg: #f4f7fb;
    --surface: #ffffff;
    --surface-soft: #f8fafc;
    --text: #142033;
    --muted: #68758a;
    --border: #dce3ed;
    --primary: #1d4ed8;
    --primary-dark: #173fae;
    --danger: #b42318;
    --success: #067647;
    --shadow: 0 16px 45px rgba(15, 23, 42, 0.10);
    --radius: 18px;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    min-height: 100%;
    color: var(--text);
    background: var(--bg);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button, input, select, textarea { font: inherit; }

a { color: var(--primary); }

h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 4px; font-size: clamp(1.45rem, 3vw, 2rem); }
h2 { margin-bottom: 0; font-size: 1.25rem; }

.eyebrow {
    color: var(--primary);
    font-size: .72rem;
    font-weight: 800;
    letter-spacing: .12em;
    text-transform: uppercase;
}

.muted, .field-help { color: var(--muted); }
.field-help { margin: -4px 0 8px; font-size: .82rem; }

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.button {
    appearance: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 42px;
    padding: 10px 15px;
    border: 1px solid var(--border);
    border-radius: 11px;
    background: var(--surface);
    color: var(--text);
    text-decoration: none;
    font-weight: 750;
    cursor: pointer;
    transition: .18s ease;
}

.button:hover { border-color: #afbbca; transform: translateY(-1px); }
.button:disabled { opacity: .55; cursor: not-allowed; transform: none; }
.button.primary { border-color: var(--primary); background: var(--primary); color: #fff; }
.button.primary:hover { background: var(--primary-dark); }
.button.ghost { background: transparent; }
.button.danger { color: var(--danger); }
.button.small { min-height: 34px; padding: 7px 10px; font-size: .84rem; }
.button.wide { width: 100%; }

input, select, textarea {
    width: 100%;
    border: 1px solid var(--border);
    border-radius: 11px;
    background: #fff;
    color: var(--text);
    padding: 11px 12px;
    outline: none;
    transition: border-color .15s, box-shadow .15s;
}

input:focus, select:focus, textarea:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(29, 78, 216, .12);
}

textarea { resize: vertical; }

label {
    display: grid;
    gap: 7px;
    color: #344054;
    font-size: .88rem;
    font-weight: 700;
}

code, pre {
    font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
}

.app-shell { min-height: 100vh; }

.topbar, .admin-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    padding: 18px clamp(16px, 4vw, 48px);
    background: rgba(255, 255, 255, .94);
    border-bottom: 1px solid var(--border);
}

.topbar-actions {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
}

.user-chip {
    padding: 8px 12px;
    border-radius: 999px;
    background: #eef4ff;
    color: #254ca3;
    font-weight: 750;
    font-size: .86rem;
}

.search-panel {
    position: relative;
    z-index: 500;
    display: grid;
    gap: 10px;
    padding: 14px clamp(16px, 4vw, 48px);
    background: #fff;
    border-bottom: 1px solid var(--border);
}

.search-row {
    display: grid;
    grid-template-columns: minmax(200px, 1fr) minmax(170px, 260px) auto;
    gap: 10px;
}

.search-row.address-row { grid-template-columns: minmax(200px, 1fr) auto; }
.search-row.compact { grid-template-columns: minmax(160px, 1fr) minmax(150px, 220px) auto; margin-bottom: 16px; }

.geocode-results {
    display: grid;
    gap: 6px;
    max-height: 250px;
    overflow: auto;
    padding: 8px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: #fff;
    box-shadow: var(--shadow);
}

.geocode-option {
    width: 100%;
    padding: 10px 12px;
    border: 0;
    border-radius: 8px;
    background: var(--surface-soft);
    color: var(--text);
    text-align: left;
    cursor: pointer;
}

.geocode-option:hover { background: #eaf1ff; }
.loading-line { padding: 10px; color: var(--muted); }

.map-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(290px, 380px);
    gap: 16px;
    padding: 16px clamp(16px, 4vw, 48px);
    min-height: calc(100vh - 230px);
}

.map-card, .results-card, .panel, .install-card, .login-card {
    overflow: hidden;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    box-shadow: var(--shadow);
}

.map-card { position: relative; min-height: 580px; }
#map { width: 100%; height: 100%; min-height: 580px; }

.map-status {
    position: absolute;
    z-index: 600;
    left: 50%;
    bottom: 22px;
    transform: translateX(-50%);
    max-width: calc(100% - 32px);
    padding: 9px 13px;
    border-radius: 999px;
    background: rgba(20, 32, 51, .90);
    color: #fff;
    font-size: .86rem;
    box-shadow: 0 8px 24px rgba(0, 0, 0, .18);
}

.map-status.error { background: rgba(180, 35, 24, .94); }

.results-card { display: flex; flex-direction: column; min-height: 580px; }
.results-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    padding: 16px;
    border-bottom: 1px solid var(--border);
}
.results-header strong { display: block; margin-top: 3px; }

.point-list {
    display: grid;
    align-content: start;
    gap: 8px;
    padding: 12px;
    overflow: auto;
}

.point-card {
    display: grid;
    gap: 5px;
    width: 100%;
    padding: 13px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: #fff;
    color: var(--text);
    text-align: left;
    cursor: pointer;
}

.point-card:hover { border-color: #aebbd0; background: #f9fbff; }
.point-card > span:last-child { color: var(--muted); font-size: .86rem; line-height: 1.4; }

.category-badge {
    display: inline-flex;
    width: fit-content;
    padding: 3px 8px;
    border-radius: 999px;
    background: #eef4ff;
    color: #254ca3;
    font-size: .70rem;
    font-weight: 800;
}

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

.popup-card { min-width: 220px; }
.popup-card img { display: block; width: 100%; max-height: 180px; object-fit: cover; border-radius: 8px; }
.popup-content { padding-top: 9px; }
.popup-content h3 { margin: 7px 0; }
.popup-content p { color: #475467; line-height: 1.45; }
.popup-links { display: flex; flex-wrap: wrap; gap: 9px; font-weight: 750; }

.footer {
    display: flex;
    justify-content: space-between;
    gap: 20px;
    padding: 14px clamp(16px, 4vw, 48px) 24px;
    color: var(--muted);
    font-size: .82rem;
}

.admin-shell { padding: 18px clamp(14px, 3vw, 36px) 42px; }
.admin-grid {
    display: grid;
    grid-template-columns: minmax(350px, .86fr) minmax(500px, 1.4fr);
    gap: 18px;
}
.admin-grid.lower-grid { grid-template-columns: 1fr 1fr; margin-top: 18px; }

.panel { padding: 18px; overflow: visible; }
.panel-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 18px;
}

.stack-form { display: grid; gap: 14px; }
.two-columns { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.inline-input { display: flex; align-items: stretch; gap: 8px; }
.inline-input input { flex: 1; }
.checkbox-row { display: flex; align-items: center; gap: 9px; }
.checkbox-row input { width: auto; }

.admin-map {
    width: 100%;
    min-height: 300px;
    border: 1px solid var(--border);
    border-radius: 13px;
    overflow: hidden;
}

.table-wrap { overflow: auto; }
.data-table { width: 100%; border-collapse: collapse; min-width: 720px; }
.data-table th, .data-table td {
    padding: 11px 10px;
    border-bottom: 1px solid var(--border);
    text-align: left;
    vertical-align: middle;
    font-size: .86rem;
}
.data-table th { color: #475467; background: var(--surface-soft); }
.data-table small { color: var(--muted); }
.table-actions { display: flex; gap: 7px; }

.status-pill {
    display: inline-flex;
    padding: 4px 8px;
    border-radius: 999px;
    font-size: .72rem;
    font-weight: 800;
}
.status-pill.active { background: #ecfdf3; color: var(--success); }
.status-pill.inactive { background: #f2f4f7; color: #667085; }

.pagination {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 14px;
    color: var(--muted);
    font-size: .86rem;
}

.code-output {
    display: block;
    max-width: 100%;
    overflow: auto;
    padding: 13px;
    border-radius: 12px;
    background: #101828;
    color: #e4e7ec;
    line-height: 1.5;
    white-space: pre-wrap;
}
.text-link { display: inline-block; margin-top: 12px; font-weight: 750; }

.alert {
    display: grid;
    gap: 3px;
    margin-bottom: 14px;
    padding: 11px 13px;
    border: 1px solid #bfd7c9;
    border-radius: 11px;
    background: #ecfdf3;
    color: var(--success);
}
.alert.error { border-color: #f6c5c0; background: #fef3f2; color: var(--danger); }
.alert.success { border-color: #b7dfc8; background: #ecfdf3; color: var(--success); }

.install-page, .login-page {
    min-height: 100vh;
    background:
        radial-gradient(circle at top left, rgba(29, 78, 216, .14), transparent 35%),
        var(--bg);
}

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

.install-card { width: min(100%, 930px); padding: clamp(20px, 4vw, 38px); }
.login-card { width: min(100%, 430px); padding: 30px; }
.back-link { display: inline-block; margin-bottom: 24px; text-decoration: none; font-weight: 750; }

.form-grid { display: grid; gap: 18px; }
fieldset {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
    padding: 18px;
    border: 1px solid var(--border);
    border-radius: 14px;
}
legend { padding: 0 8px; font-weight: 850; }
.button-row { display: flex; flex-wrap: wrap; gap: 10px; }

@media (max-width: 1000px) {
    .map-layout { grid-template-columns: 1fr; }
    .map-card, #map { min-height: 520px; }
    .results-card { min-height: auto; max-height: 430px; }
    .admin-grid, .admin-grid.lower-grid { grid-template-columns: 1fr; }
}

@media (max-width: 680px) {
    .topbar, .admin-header { align-items: flex-start; flex-direction: column; }
    .search-row, .search-row.address-row, .search-row.compact { grid-template-columns: 1fr; }
    .map-layout { padding: 10px; gap: 10px; }
    .map-card, #map { min-height: 58vh; }
    .two-columns, fieldset { grid-template-columns: 1fr; }
    .inline-input { flex-wrap: wrap; }
    .inline-input .button { flex: 1; }
    .footer { flex-direction: column; }
    .admin-shell { padding: 10px 10px 32px; }
    .panel { padding: 14px; }
}


/* Renderização local MapLibre/PMTiles */
.map-point-marker,
.map-search-marker {
    position: relative;
    width: 28px;
    height: 28px;
    padding: 0;
    border: 3px solid #fff;
    border-radius: 50% 50% 50% 0;
    background: var(--marker-color, #1d4ed8);
    box-shadow: 0 3px 10px rgba(15, 23, 42, .35);
    cursor: pointer;
    transform: rotate(-45deg);
}

.map-point-marker::after,
.map-search-marker::after {
    content: "";
    position: absolute;
    width: 8px;
    height: 8px;
    left: 50%;
    top: 50%;
    border-radius: 50%;
    background: #fff;
    transform: translate(-50%, -50%);
}

.map-search-marker { --marker-color: #b45309; }

.map-point-marker:focus-visible,
.map-search-marker:focus-visible {
    outline: 3px solid rgba(37, 99, 235, .4);
    outline-offset: 4px;
}

.map-user-marker {
    width: 18px;
    height: 18px;
    border: 3px solid #fff;
    border-radius: 50%;
    background: #2563eb;
    box-shadow: 0 0 0 5px rgba(37, 99, 235, .22), 0 3px 9px rgba(15, 23, 42, .3);
}

.maplibregl-popup-content {
    min-width: 220px;
    padding: 0;
    border-radius: 14px;
    overflow: hidden;
    box-shadow: 0 12px 32px rgba(15, 23, 42, .24);
}

.maplibregl-popup-close-button {
    z-index: 2;
    padding: 4px 9px;
    font-size: 22px;
    background: rgba(255, 255, 255, .9);
}

.maplibregl-ctrl-attrib { font-size: 10px; }
.maplibregl-canvas:focus { outline: none; }

.status-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 14px;
    margin: 18px 0;
}

.status-card {
    padding: 16px;
    border: 1px solid var(--border, #dbe2ea);
    border-radius: 14px;
    background: #fff;
}

.status-card strong { display: block; margin-bottom: 6px; }
.status-card.ok { border-color: #86efac; background: #f0fdf4; }
.status-card.warn { border-color: #fcd34d; background: #fffbeb; }
.status-card.error { border-color: #fca5a5; background: #fef2f2; }

.step-list {
    margin: 14px 0;
    padding-left: 22px;
}
.step-list li { margin: 10px 0; }

.test-output {
    min-height: 52px;
    white-space: pre-wrap;
}
