:root {
    --bg: #07121d;
    --bg-2: #0e1a27;
    --panel: rgba(16, 22, 33, 0.78);
    --panel-hover: rgba(24, 34, 52, 0.88);
    --border: rgba(255, 255, 255, 0.08);
    --text: #f4f8fb;
    --muted: #b7c4d5;
    --cyan: #38bdf8;
    --green: #22c55e;
    --amber: #f59e0b;
    --red: #ef4444;
    --shadow: 0 20px 50px rgba(0, 0, 0, 0.45);
}

* {
    box-sizing: border-box;
}

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

button,
input {
    font: inherit;
}

button {
    cursor: pointer;
}

button:focus-visible,
input:focus-visible {
    outline: 2px solid var(--cyan);
    outline-offset: 2px;
}

.eyebrow {
    margin: 0 0 8px;
    color: var(--cyan);
    font-size: 13px;
    font-weight: 700;
    text-transform: uppercase;
}

.login-shell {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
    background:
        linear-gradient(135deg, rgba(7, 18, 29, 0.94), rgba(7, 18, 29, 0.56)),
        url("https://images.unsplash.com/photo-1544989164-31dc3c645987?auto=format&fit=crop&w=1800&q=82") center/cover;
}

.login-card,
.side-panel,
.kpi,
.search-box,
.search-results {
    border: 1px solid var(--border);
    background: var(--panel);
    box-shadow: var(--shadow);
    backdrop-filter: blur(18px);
}

.login-card {
    width: min(520px, 100%);
    padding: 32px;
    border-radius: 20px;
}

.brand-mark {
    width: 48px;
    height: 48px;
    display: grid;
    place-items: center;
    margin-bottom: 24px;
    border-radius: 16px;
    background: linear-gradient(135deg, #38bdf8, #2563eb);
    color: #fff;
}

.login-card h1 {
    margin: 0;
    font-size: 36px;
    line-height: 1.05;
}

.login-card p {
    color: var(--muted);
}

.notice {
    margin: 24px 0;
    padding: 16px;
    border: 1px solid rgba(245, 158, 11, 0.28);
    border-radius: 14px;
    background: rgba(245, 158, 11, 0.12);
    color: #ffd89a;
}

.login-form {
    display: grid;
    gap: 16px;
    margin-top: 24px;
}

.login-form label {
    display: grid;
    gap: 8px;
    color: var(--muted);
    font-size: 15px;
    font-weight: 600;
}

.login-form input,
.search-box input {
    width: 100%;
    min-width: 0;
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.06);
    color: var(--text);
    outline: none;
}

.login-form input {
    height: 44px;
    padding: 0 14px;
}

.login-form button,
.search-box button[type="submit"],
.secondary-button {
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    border: 0;
    border-radius: 14px;
    background: linear-gradient(135deg, #38bdf8, #2563eb);
    color: #fff;
    font-weight: 700;
}

.login-form button:disabled,
.login-form input:disabled {
    opacity: 0.48;
    cursor: not-allowed;
}

.form-message {
    min-height: 20px;
    margin: 0;
    color: #fecaca;
    font-size: 13px;
    font-weight: 700;
}

.app-shell {
    min-height: 100vh;
    display: grid;
    grid-template-rows: auto auto minmax(0, 1fr);
    background:
        radial-gradient(circle at 15% 10%, rgba(56, 189, 248, 0.14), transparent 28%),
        linear-gradient(180deg, #07121d, #0b1521 55%, #07121d);
}

.topbar {
    min-height: 88px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
    padding: 16px 24px 8px;
}

.brand-block h1 {
    margin: 0;
    font-size: 28px;
    line-height: 1.08;
}

.brand-block span,
.status-item span {
    color: var(--muted);
    font-size: 13px;
}

.status-block {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 12px;
    flex-wrap: wrap;
}

.status-item {
    min-width: 104px;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.04);
}

.status-item strong {
    display: block;
    margin-top: 3px;
    font-size: 15px;
}

.icon-button {
    width: 44px;
    height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.06);
    color: var(--text);
}

.icon-button:disabled {
    opacity: 0.42;
    cursor: not-allowed;
}

.kpi-strip {
    display: grid;
    grid-template-columns: repeat(6, minmax(150px, 1fr));
    gap: 12px;
    padding: 8px 24px 16px;
    overflow-x: auto;
}

.kpi {
    min-height: 88px;
    padding: 15px 16px 13px;
    border-radius: 20px;
    transition: transform 250ms ease-out, background 250ms ease-out;
}

.kpi:hover {
    transform: translateY(-2px);
    background: var(--panel-hover);
}

.kpi span {
    display: block;
    margin-top: 8px;
    color: var(--muted);
    font-size: 13px;
    font-weight: 600;
}

.kpi strong {
    display: block;
    font-size: 28px;
    line-height: 1;
}

.skeleton strong,
.skeleton span {
    color: transparent;
    border-radius: 10px;
    background: linear-gradient(90deg, rgba(255,255,255,.06), rgba(255,255,255,.16), rgba(255,255,255,.06));
    background-size: 220% 100%;
    animation: shimmer 1.2s ease-out infinite;
}

@keyframes shimmer {
    to {
        background-position-x: -220%;
    }
}

.workspace {
    min-height: 0;
    display: grid;
    grid-template-columns: minmax(0, 70fr) minmax(380px, 30fr);
    gap: 16px;
    padding: 0 24px 24px;
    transition: grid-template-columns 300ms ease-out;
}

body.pdf-open .workspace {
    grid-template-columns: minmax(0, 58fr) minmax(460px, 42fr);
}

.map-zone {
    position: relative;
    min-height: 0;
    overflow: hidden;
    border: 1px solid var(--border);
    border-radius: 20px;
    background: #0e1a27;
    box-shadow: var(--shadow);
}

#map {
    position: absolute;
    inset: 0;
    background: #eef3f7;
}

.leaflet-container {
    background: #eef3f7;
    font-family: inherit;
}

.search-dock {
    position: absolute;
    z-index: 500;
    top: 16px;
    left: 16px;
    width: min(660px, calc(100% - 32px));
}

.search-box {
    display: grid;
    grid-template-columns: 24px minmax(0, 1fr) 44px 96px;
    align-items: center;
    gap: 12px;
    min-height: 56px;
    padding: 6px 8px 6px 14px;
    border-radius: 18px;
    box-shadow: 0 14px 34px rgba(7, 18, 29, 0.26);
}

.search-box input {
    height: 44px;
    border: 0;
    background: transparent;
    padding: 0;
}

.search-box input::placeholder {
    color: rgba(183, 196, 213, 0.72);
}

.search-clear[hidden] {
    display: none;
}

.search-results {
    max-height: 360px;
    margin-top: 12px;
    overflow: auto;
    border-radius: 20px;
}

.filter-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 10px;
}

.chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-height: 30px;
    padding: 0 10px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: rgba(16, 22, 33, 0.82);
    color: var(--text);
    font-size: 13px;
    font-weight: 700;
}

.chip button {
    width: 18px;
    height: 18px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 0;
    border-radius: 50%;
    background: rgba(255,255,255,.1);
    color: var(--text);
}

.result-row,
.laudo-row {
    width: 100%;
    display: grid;
    gap: 6px;
    padding: 12px 16px;
    border: 0;
    border-bottom: 1px solid var(--border);
    background: transparent;
    color: var(--text);
    text-align: left;
    transition: background 200ms ease-out;
}

.result-row:hover,
.result-row.is-active,
.laudo-row:hover,
.laudo-row.is-active {
    background: rgba(56, 189, 248, 0.12);
}

.result-group {
    position: sticky;
    top: 0;
    z-index: 2;
    padding: 8px 16px;
    border-bottom: 1px solid var(--border);
    background: rgba(7, 18, 29, 0.92);
    color: var(--cyan);
    font-size: 13px;
    font-weight: 800;
}

.row-main {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    font-size: 15px;
    font-weight: 700;
}

.row-sub {
    color: var(--muted);
    font-size: 13px;
}

mark {
    border-radius: 4px;
    background: rgba(56, 189, 248, 0.22);
    color: var(--text);
}

.map-tools {
    position: absolute;
    right: 16px;
    bottom: 16px;
    z-index: 500;
    display: flex;
    gap: 8px;
}

.floating-menu,
.filter-drawer {
    position: absolute;
    z-index: 650;
    right: 16px;
    border: 1px solid var(--border);
    border-radius: 20px;
    background: rgba(16, 22, 33, 0.92);
    box-shadow: var(--shadow);
    backdrop-filter: blur(18px);
}

.floating-menu {
    bottom: 72px;
    display: grid;
    overflow: hidden;
    min-width: 150px;
}

.floating-menu button {
    min-height: 40px;
    border: 0;
    border-bottom: 1px solid var(--border);
    background: transparent;
    color: var(--text);
    text-align: left;
    padding: 0 14px;
}

.floating-menu button:hover {
    background: rgba(56, 189, 248, 0.12);
}

.filter-drawer {
    top: 16px;
    width: min(360px, calc(100% - 32px));
    display: grid;
    gap: 12px;
    padding: 16px;
}

.filter-drawer[hidden],
.floating-menu[hidden] {
    display: none;
}

.filter-drawer label {
    display: grid;
    gap: 6px;
    color: var(--muted);
    font-size: 13px;
    font-weight: 700;
}

.filter-drawer select,
.filter-drawer input,
.laudo-toolbar input {
    min-height: 40px;
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.06);
    color: var(--text);
    padding: 0 12px;
}

.filter-drawer option {
    color: #0e1a27;
}

.range-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.drawer-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.drawer-actions button[type="submit"] {
    min-height: 44px;
    border: 0;
    border-radius: 14px;
    background: linear-gradient(135deg, #38bdf8, #2563eb);
    color: #fff;
    font-weight: 700;
}

.side-panel {
    min-height: 0;
    display: grid;
    grid-template-rows: minmax(0, 1fr) auto;
    overflow: hidden;
    border-radius: 20px;
}

.sheet-handle {
    display: none;
}

.empty-panel {
    display: grid;
    place-items: center;
    align-content: center;
    gap: 16px;
    padding: 32px;
    color: var(--muted);
    text-align: center;
}

.empty-panel svg {
    color: var(--cyan);
}

.panel-content {
    min-height: 0;
    overflow: auto;
    padding: 18px 20px 20px;
}

.panel-header h2 {
    margin: 0;
    font-size: 24px;
    line-height: 1.16;
    letter-spacing: 0;
}

.panel-header > p:not(.eyebrow) {
    margin: 8px 0 0;
    color: var(--muted);
    font-size: 14px;
}

.badge-row {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 12px;
}

.badge-row .badge.is-warn {
    background: rgba(245, 158, 11, 0.14);
    color: #fbbf24;
}

.composition-card {
    margin: 18px 0 20px;
}

.metric-grid,
.detail-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin: 14px 0 22px;
}

.metric,
.detail-card,
.elementos-box {
    border: 1px solid var(--border);
    border-radius: 16px;
    background: rgba(255, 255, 255, 0.04);
    padding: 13px 12px;
}

.metric span,
.detail-card span {
    display: block;
    color: var(--muted);
    font-size: 13px;
    font-weight: 600;
}

.metric strong,
.detail-card strong {
    display: block;
    margin-top: 6px;
    overflow-wrap: anywhere;
    font-size: 15px;
    line-height: 1.25;
}

.section-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin: 22px 0 12px;
}

.panel-tabs {
    position: sticky;
    top: -20px;
    z-index: 10;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 6px;
    margin: 0 0 16px;
    padding: 8px;
    border: 1px solid var(--border);
    border-radius: 16px;
    background: rgba(7, 18, 29, 0.88);
    backdrop-filter: blur(18px);
}

.panel-tabs button,
.segmented button {
    min-height: 40px;
    border: 0;
    border-radius: 12px;
    background: transparent;
    color: var(--muted);
    font-weight: 700;
}

.panel-tabs button.is-active,
.segmented button.is-active {
    background: rgba(56, 189, 248, 0.16);
    color: #e0f6ff;
    box-shadow: inset 0 0 0 1px rgba(56, 189, 248, 0.22);
}

.panel-tab-panel {
    display: none;
}

.panel-tab-panel.is-active {
    display: block;
}

.section-title h3 {
    margin: 0;
    font-size: 18px;
}

.section-title > span {
    min-width: 32px;
    max-width: 190px;
    padding: 4px 8px;
    border-radius: 999px;
    background: rgba(56, 189, 248, 0.12);
    color: var(--cyan);
    text-align: center;
    font-size: 13px;
    font-weight: 700;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.secondary-button {
    min-height: 36px;
    padding: 0 12px;
    border: 1px solid rgba(255, 255, 255, 0.12);
    background: rgba(255, 255, 255, 0.06);
    font-size: 13px;
}

.secondary-button:disabled {
    opacity: 0.44;
    cursor: not-allowed;
}

.laudo-list {
    display: grid;
    max-height: min(54vh, 560px);
    overflow: auto;
    border: 1px solid var(--border);
    border-radius: 16px;
}

.laudo-toolbar {
    position: sticky;
    top: 50px;
    z-index: 8;
    display: grid;
    gap: 10px;
    margin-bottom: 12px;
    padding: 10px;
    border: 1px solid var(--border);
    border-radius: 16px;
    background: rgba(7, 18, 29, 0.88);
    backdrop-filter: blur(18px);
}

.segmented {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
}

.load-more {
    width: 100%;
    margin-top: 12px;
}

.badge {
    display: inline-flex;
    align-items: center;
    padding: 4px 8px;
    border-radius: 999px;
    background: rgba(56, 189, 248, 0.12);
    color: var(--cyan);
    font-size: 13px;
    font-weight: 700;
}

.laudo-detail {
    display: grid;
    gap: 16px;
}

.detail-section h4 {
    margin: 0 0 12px;
    color: var(--cyan);
    font-size: 13px;
    text-transform: uppercase;
}

.elementos-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.elementos-table th,
.elementos-table td {
    height: 44px;
    padding: 8px;
    border-bottom: 1px solid var(--border);
    text-align: left;
}

.elementos-table th {
    position: sticky;
    top: 0;
    background: #111928;
    color: var(--muted);
}

.pdf-panel {
    min-height: min(52vh, 620px);
    border-top: 1px solid var(--border);
    background: rgba(7, 18, 29, 0.84);
}

.pdf-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px;
    border-bottom: 1px solid var(--border);
}

.pdf-heading {
    min-width: 120px;
    display: grid;
    gap: 3px;
}

.pdf-heading span {
    color: var(--muted);
    font-size: 13px;
}

.pdf-controls {
    display: flex;
    align-items: center;
    gap: 8px;
    max-width: 100%;
    overflow-x: auto;
}

#pdfPageLabel {
    min-width: 70px;
    color: var(--muted);
    text-align: center;
    font-size: 13px;
}

.pdf-stage {
    position: relative;
    height: min(44vh, 540px);
    overflow: auto;
    padding: 16px;
}

#pdfCanvas {
    display: block;
    max-width: 100%;
    margin: 0 auto;
    background: #fff;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.45);
}

.pdf-empty {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    color: var(--muted);
    gap: 10px;
    text-align: center;
}

.pdf-skeleton {
    width: 140px;
    height: 180px;
    display: block;
    border-radius: 12px;
    background: linear-gradient(90deg, rgba(255,255,255,.06), rgba(255,255,255,.16), rgba(255,255,255,.06));
    background-size: 220% 100%;
    animation: shimmer 1.2s ease-out infinite;
}

.pdf-error {
    display: grid;
    justify-items: center;
    gap: 12px;
}

.toast {
    position: fixed;
    right: 24px;
    bottom: 24px;
    z-index: 1000;
    max-width: 360px;
    padding: 12px 16px;
    border: 1px solid var(--border);
    border-radius: 16px;
    background: rgba(16, 22, 33, 0.94);
    color: var(--text);
    box-shadow: var(--shadow);
}

.map-zone.is-fullscreen {
    position: fixed;
    inset: 16px;
    z-index: 1200;
}

.selected-geometry {
    filter: drop-shadow(0 0 8px rgba(56, 189, 248, 0.92)) drop-shadow(0 0 18px rgba(14, 165, 233, 0.36));
    transition: filter 240ms ease-out;
}

.selection-label {
    min-width: 92px;
    padding: 7px 10px 8px;
    border: 1px solid rgba(255, 255, 255, 0.16);
    border-radius: 12px;
    background: rgba(7, 18, 29, 0.84);
    color: var(--text);
    box-shadow: 0 10px 28px rgba(0, 0, 0, 0.32);
    text-align: center;
    pointer-events: none;
    backdrop-filter: blur(12px);
}

.selection-label strong,
.selection-label span {
    display: block;
    font-size: 13px;
    line-height: 1.2;
}

.selection-label span {
    color: var(--muted);
}

.pdf-panel:fullscreen {
    display: grid;
    grid-template-rows: 56px 1fr;
    background: #07121d;
}

.pdf-panel:fullscreen .pdf-stage {
    height: calc(100vh - 56px);
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.001ms !important;
        scroll-behavior: auto !important;
        transition-duration: 0.001ms !important;
    }
}

@media (max-width: 1180px) {
    .workspace,
    body.pdf-open .workspace {
        grid-template-columns: minmax(0, 65fr) minmax(360px, 35fr);
    }

    .kpi-strip {
        grid-template-columns: repeat(6, minmax(180px, 1fr));
    }
}

@media (max-width: 820px) {
    .topbar {
        align-items: flex-start;
        flex-direction: column;
    }

    .status-block {
        width: 100%;
        justify-content: flex-start;
    }

    .workspace,
    body.pdf-open .workspace {
        grid-template-columns: 1fr;
        grid-template-rows: minmax(58vh, 1fr) auto;
    }

    .side-panel {
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 900;
        min-height: auto;
        height: 36vh;
        border-radius: 20px 20px 0 0;
        transition: height 300ms ease-out;
    }

    .side-panel.sheet-mid {
        height: 58vh;
    }

    .side-panel.sheet-expanded {
        height: 88vh;
    }

    .sheet-handle {
        display: block;
        width: 48px;
        height: 5px;
        margin: 10px auto 0;
        border-radius: 999px;
        background: rgba(255, 255, 255, 0.22);
    }

    .search-box {
        grid-template-columns: 24px 1fr 44px;
    }

    .search-box button[type="submit"] {
        grid-column: 1 / -1;
    }

    .search-clear {
        grid-column: auto;
    }

    .metric-grid,
    .detail-grid {
        grid-template-columns: 1fr;
    }

    .filter-drawer {
        left: 16px;
        right: 16px;
        width: auto;
    }

    body.pdf-open .side-panel {
        height: 96vh;
    }

    .panel-tabs {
        display: flex;
        overflow-x: auto;
        scroll-snap-type: x mandatory;
    }

    .panel-tabs button {
        min-width: 112px;
        scroll-snap-align: start;
    }

    .pdf-toolbar {
        align-items: flex-start;
        flex-direction: column;
    }

    .pdf-stage {
        height: 70vh;
    }
}
