* {
    box-sizing: border-box;
}

:root {
    --bg: #f4f6f8;
    --surface: #ffffff;
    --sidebar: #111827;
    --sidebar-soft: #1f2937;
    --text: #111827;
    --muted: #6b7280;
    --line: #e5e7eb;
    --accent: #2563eb;
    --success: #16a34a;
}

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

body {
    min-height: 100vh;
}

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

.sidebar {
    width: 245px;
    background: var(--sidebar);
    color: #fff;
    display: flex;
    flex-direction: column;
    padding: 24px 18px;
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 8px 26px;
}

.brand-mark {
    width: 40px;
    height: 40px;
    border-radius: 11px;
    background: var(--accent);
    display: grid;
    place-items: center;
    font-weight: 800;
    font-size: 20px;
}

.brand strong,
.brand span {
    display: block;
}

.brand strong {
    font-size: 18px;
}

.brand span {
    color: #9ca3af;
    font-size: 11px;
    margin-top: 2px;
}

.navigation {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.nav-item {
    color: #cbd5e1;
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    border-radius: 9px;
    font-size: 14px;
    font-weight: 500;
}

.nav-item:hover {
    background: var(--sidebar-soft);
    color: #fff;
}

.nav-item.active {
    background: #263244;
    color: #fff;
}

.nav-icon {
    width: 20px;
    text-align: center;
    font-size: 18px;
}

.sidebar-footer {
    margin-top: auto;
    color: #9ca3af;
    font-size: 12px;
    padding: 16px 8px 0;
    border-top: 1px solid #263244;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
    margin-right: 6px;
}

.status-dot.online {
    background: #22c55e;
}

.status-dot.offline {
    background: #ef4444;
}

.main-content {
    flex: 1;
    padding: 34px;
    min-width: 0;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 28px;
}

.eyebrow {
    margin: 0 0 5px;
    color: var(--muted);
    font-size: 11px;
    letter-spacing: .12em;
    font-weight: 700;
}

h1,
h2,
p {
    margin-top: 0;
}

h1 {
    margin-bottom: 0;
    font-size: 27px;
}

h2 {
    margin-bottom: 0;
    font-size: 19px;
}

.environment {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 999px;
    padding: 8px 13px;
    font-size: 12px;
    color: var(--muted);
}

.environment span {
    width: 7px;
    height: 7px;
    background: var(--success);
    border-radius: 50%;
    display: inline-block;
    margin-right: 5px;
}

.metrics {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 16px;
    margin-bottom: 20px;
}

.metric-card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 20px;
}

.metric-card.highlight {
    border-top: 3px solid var(--accent);
}

.metric-label {
    color: var(--muted);
    font-size: 12px;
    font-weight: 600;
}

.metric-value {
    font-size: 32px;
    font-weight: 750;
    margin: 7px 0 2px;
}

.metric-description {
    color: #9ca3af;
    font-size: 11px;
}

.workspace {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 14px;
    overflow: hidden;
}

.workspace-header {
    min-height: 78px;
    padding: 18px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--line);
}

.workspace-status {
    color: var(--muted);
    font-size: 11px;
    border: 1px solid var(--line);
    padding: 6px 9px;
    border-radius: 7px;
}

.map-placeholder {
    height: 480px;
    position: relative;
    overflow: hidden;
    background: #eef1f4;
    display: grid;
    place-items: center;
}

.map-grid {
    position: absolute;
    inset: 0;
    opacity: .7;
    background-image:
        linear-gradient(#dfe4e9 1px, transparent 1px),
        linear-gradient(90deg, #dfe4e9 1px, transparent 1px);
    background-size: 32px 32px;
}

.map-message {
    position: relative;
    z-index: 1;
    width: min(340px, 90%);
    text-align: center;
    background: rgba(255,255,255,.92);
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 26px;
}

.map-symbol {
    font-size: 31px;
    margin-bottom: 8px;
}

.map-message strong {
    display: block;
    margin-bottom: 7px;
}

.map-message p {
    color: var(--muted);
    font-size: 13px;
    line-height: 1.55;
    margin-bottom: 0;
}

@media (max-width: 900px) {
    .sidebar {
        width: 78px;
        padding-left: 10px;
        padding-right: 10px;
    }

    .brand > div:not(.brand-mark),
    .nav-item:not(.active) {
    }

    .brand strong,
    .brand span,
    .nav-item {
        font-size: 0;
    }

    .nav-icon {
        font-size: 20px;
        margin: auto;
    }

    .sidebar-footer {
        display: none;
    }

    .metrics {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 600px) {
    .sidebar {
        display: none;
    }

    .main-content {
        padding: 20px 14px;
    }

    .metrics {
        grid-template-columns: 1fr 1fr;
        gap: 10px;
    }

    .metric-card {
        padding: 15px;
    }

    .metric-value {
        font-size: 27px;
    }

    .map-placeholder {
        height: 420px;
    }
}

/* CRUD / formulários */

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

.button {
    appearance: none;
    border: 1px solid transparent;
    border-radius: 9px;
    padding: 10px 14px;
    font: inherit;
    font-size: 13px;
    font-weight: 650;
    line-height: 1;
    text-decoration: none;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.button-primary {
    background: var(--accent);
    color: #fff;
}

.button-secondary {
    background: var(--surface);
    border-color: var(--line);
    color: var(--text);
}

.form-panel {
    padding: 24px;
}

.form-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 2fr);
    gap: 20px;
    max-width: 900px;
}

.field {
    display: flex;
    flex-direction: column;
    gap: 7px;
}

.field label {
    font-size: 12px;
    font-weight: 700;
}

.field input {
    width: 100%;
    border: 1px solid #d1d5db;
    border-radius: 9px;
    background: #fff;
    color: var(--text);
    padding: 11px 12px;
    font: inherit;
    outline: none;
}

.field input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, .10);
}

.field small {
    color: var(--muted);
    font-size: 11px;
}

.field-small {
    max-width: 150px;
}

.form-actions {
    max-width: 900px;
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    padding-top: 24px;
    margin-top: 24px;
    border-top: 1px solid var(--line);
}

.alert {
    max-width: 900px;
    padding: 13px 15px;
    border-radius: 9px;
    margin-bottom: 20px;
    font-size: 13px;
}

.alert ul {
    margin: 8px 0 0;
    padding-left: 18px;
}

.alert-success {
    background: #f0fdf4;
    border: 1px solid #bbf7d0;
    color: #166534;
}

.alert-error {
    background: #fef2f2;
    border: 1px solid #fecaca;
    color: #991b1b;
}

@media (max-width: 700px) {
    .form-grid {
        grid-template-columns: 1fr;
    }

    .field-small {
        max-width: none;
    }

    .workspace-header,
    .workspace-actions {
        align-items: flex-start;
    }

    .workspace-actions {
        flex-direction: column;
    }
}

/* Territórios - gestão */

.table-wrapper {
    width: 100%;
    overflow-x: auto;
}

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

.data-table th,
.data-table td {
    padding: 14px 12px;
    border-bottom: 1px solid var(--line);
    text-align: left;
    vertical-align: middle;
}

.data-table th {
    color: var(--muted);
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .04em;
}

.data-table tbody tr:hover {
    background: #f8fafc;
}

.table-actions-heading {
    width: 210px;
}

.row-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.row-actions form {
    margin: 0;
}

.button-small {
    padding: 8px 10px;
    font-size: 12px;
}

.button-danger-soft {
    background: #fff;
    border-color: #fecaca;
    color: #b91c1c;
}

.button-success-soft {
    background: #fff;
    border-color: #bbf7d0;
    color: #15803d;
}

.status-badge {
    display: inline-flex;
    align-items: center;
    border-radius: 999px;
    padding: 5px 9px;
    font-size: 11px;
    font-weight: 700;
}

.status-active {
    background: #dcfce7;
    color: #166534;
}

.status-inactive {
    background: #f1f5f9;
    color: #64748b;
}

.code-label {
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    font-size: 12px;
    color: #475569;
}

@media (max-width: 700px) {
    .data-table {
        min-width: 720px;
    }
}

/* ===== MAPALOG: SETORES E REFERÊNCIAS ===== */

.split-workspace {
    display: grid;
    grid-template-columns: minmax(280px, 340px) minmax(0, 1fr);
    gap: 24px;
    align-items: start;
}

.compact-form-card {
    padding: 20px;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 14px;
}

.compact-form-card h3,
.form-section h3 {
    margin: 0 0 8px;
}

.compact-form-card > p {
    margin: 0 0 20px;
    color: #64748b;
    font-size: 14px;
}

.field select,
.field textarea {
    width: 100%;
    box-sizing: border-box;
    border: 1px solid #d7dee8;
    border-radius: 9px;
    background: #fff;
    color: #10233f;
    font: inherit;
    outline: none;
}

.field select {
    min-height: 44px;
    padding: 0 12px;
}

.field textarea {
    padding: 12px;
    resize: vertical;
}

.field select:focus,
.field textarea:focus {
    border-color: #2f67e8;
    box-shadow: 0 0 0 3px rgba(47, 103, 232, .10);
}

.button-full {
    width: 100%;
    justify-content: center;
}

.table-wrap {
    width: 100%;
    overflow-x: auto;
}

.table-meta {
    display: block;
    margin-top: 4px;
    color: #718096;
    font-size: 11px;
}

.status-pill,
.validation-pill {
    display: inline-flex;
    align-items: center;
    min-height: 25px;
    padding: 4px 10px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 700;
    white-space: nowrap;
}

.status-pill.is-active {
    background: #dcfce7;
    color: #15803d;
}

.status-pill.is-inactive {
    background: #f1f5f9;
    color: #64748b;
}

.validation-pending {
    background: #fef3c7;
    color: #92400e;
}

.validation-validated {
    background: #dcfce7;
    color: #15803d;
}

.validation-review {
    background: #fee2e2;
    color: #b91c1c;
}

.inline-form {
    display: inline;
    margin: 0;
}

.action-group {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
}

.form-workspace {
    overflow: visible;
}

.form-section {
    padding: 22px 0;
    border-bottom: 1px solid #e7ecf2;
}

.form-section:last-of-type {
    border-bottom: 0;
}

.form-section h3 {
    margin-bottom: 18px;
    color: #17304f;
    font-size: 15px;
}

.field-span-2 {
    grid-column: span 2;
}

input[readonly] {
    background: #f1f5f9;
    color: #52657c;
    cursor: not-allowed;
}

.empty-state {
    display: flex;
    min-height: 180px;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 7px;
    padding: 30px;
    color: #64748b;
    text-align: center;
}

.empty-state strong {
    color: #17304f;
}

.workspace-actions {
    display: flex;
    gap: 12px;
    align-items: center;
    flex-wrap: wrap;
}

@media (max-width: 980px) {
    .split-workspace {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 700px) {
    .field-span-2 {
        grid-column: span 1;
    }

    .data-table {
        min-width: 760px;
    }
}
