:root {
    /* Light theme (pastel green + pastel blue) */
    --bg: #f6fbf8;
    --surface: #ffffff;
    --surface-2: #eef7f4;
    --text: #173129;
    --muted: #4b6b60;
    --primary: #7ed7b6; /* pastel green */
    --primary-2: #4fbf9a;
    --accent: #86c8ff; /* pastel blue */
    --accent-2: #4ea5ff;
    --border: rgba(20, 60, 45, 0.12);
    --shadow: 0 10px 30px rgba(0,0,0,0.06);
    --danger: #ff6b6b;
    --warning: #ffcc66;
    --radius: 16px;
    --radius-sm: 12px;
    --pad: 18px;
    --focus: 0 0 0 4px rgba(134, 200, 255, 0.35);
    --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Arial;
}

html[data-theme="dark"] {
    /* Dark theme (moss green + petroleum blue) */
    --bg: #0b1412;
    --surface: #0f1c19;
    --surface-2: #122723;
    --text: #d6f0e7;
    --muted: #92b6aa;
    --primary: #5aa07e; /* moss green */
    --primary-2: #3f8768;
    --accent: #1f6f84; /* petroleum blue */
    --accent-2: #2c8aa3;
    --border: rgba(214, 240, 231, 0.12);
    --shadow: 0 10px 30px rgba(0,0,0,0.35);
    --danger: #ff7a7a;
    --warning: #ffd07a;
    --focus: 0 0 0 4px rgba(31, 111, 132, 0.35);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    overflow-x: hidden;
    position: relative;
}

body::before {
    content: "";
    position: fixed;
    inset: 0;
    z-index: -1;
    pointer-events: none;
    /* Gradiente "único" para a tela toda (sem repetição) */
    background: radial-gradient(900px 520px at 14% 6%, rgba(126, 215, 182, 0.30), transparent 62%), radial-gradient(820px 520px at 86% 10%, rgba(134, 200, 255, 0.26), transparent 58%), radial-gradient(1100px 700px at 50% 120%, rgba(126, 215, 182, 0.10), transparent 55%), linear-gradient(180deg, rgba(0,0,0,0.00) 0%, rgba(0,0,0,0.08) 55%, rgba(0,0,0,0.16) 100%);
}

/* No tema escuro, ajusta os tons */
html[data-theme="dark"] body::before {
    background: radial-gradient(900px 520px at 14% 6%, rgba(90, 160, 126, 0.22), transparent 62%), radial-gradient(820px 520px at 86% 10%, rgba(31, 111, 132, 0.24), transparent 58%), radial-gradient(1100px 700px at 50% 120%, rgba(90, 160, 126, 0.12), transparent 55%), linear-gradient(180deg, rgba(0,0,0,0.10) 0%, rgba(0,0,0,0.28) 55%, rgba(0,0,0,0.45) 100%);
}


a {
    color: inherit;
    text-decoration: none;
}

    a:hover {
        text-decoration: underline;
    }

.container {
    max-width: 1100px;
    margin: 0 auto;
    padding: 18px;
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 30;
    backdrop-filter: blur(10px);
    background: color-mix(in srgb, var(--bg) 70%, transparent);
    border-bottom: 1px solid var(--border);
}

.topbar-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    padding: 14px 22px;
    max-width: 1600px;
    margin: 0 auto;
}

/* Sidebar toggle (hamburger) */
.sidebar-toggle {
    display: inline-flex;
    flex-direction: column;
    justify-content: center;
    gap: 4px;
    width: 38px;
    height: 38px;
    padding: 9px 8px;
    border-radius: 12px;
    border: 1px solid var(--border);
    background: color-mix(in srgb, var(--surface) 85%, transparent);
    cursor: pointer;
}

.sidebar-toggle span {
    display: block;
    height: 2px;
    width: 100%;
    border-radius: 2px;
    background: var(--text);
    transition: transform .2s ease, opacity .2s ease;
}

.sidebar-toggle:hover {
    background: color-mix(in srgb, var(--surface) 60%, var(--accent) 15%);
}

body.sidebar-open .sidebar-toggle span:nth-child(1) {
    transform: translateY(6px) rotate(45deg);
}

body.sidebar-open .sidebar-toggle span:nth-child(2) {
    opacity: 0;
}

body.sidebar-open .sidebar-toggle span:nth-child(3) {
    transform: translateY(-6px) rotate(-45deg);
}

/* Sidebar lateral */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    width: 280px;
    z-index: 40;
    transform: translateX(-100%);
    transition: transform .25s ease;
    background: color-mix(in srgb, var(--surface) 96%, transparent);
    border-right: 1px solid var(--border);
    backdrop-filter: blur(12px);
    overflow-y: auto;
    padding: 80px 14px 24px;
    box-shadow: var(--shadow);
}

.sidebar.open {
    transform: translateX(0);
}

.sidebar-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 35;
    opacity: 0;
    pointer-events: none;
    transition: opacity .2s ease;
}

.sidebar-backdrop.open {
    opacity: 1;
    pointer-events: auto;
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 18px;
}

.sidebar-section {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.sidebar-title {
    font-size: 11px;
    font-weight: 800;
    letter-spacing: 0.8px;
    text-transform: uppercase;
    color: var(--muted);
    padding: 0 12px 6px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 4px;
}

.sidebar-link {
    display: block;
    padding: 9px 12px;
    border-radius: 10px;
    border: 1px solid transparent;
    color: var(--text);
    font-weight: 600;
    font-size: 14px;
    text-decoration: none;
    transition: background .15s ease, border-color .15s ease;
}

.sidebar-link:hover {
    background: color-mix(in srgb, var(--surface) 60%, var(--accent) 14%);
    border-color: var(--border);
    text-decoration: none;
}

.sidebar-link.active {
    background: color-mix(in srgb, var(--primary) 22%, var(--surface));
    border-color: color-mix(in srgb, var(--primary-2) 40%, var(--border));
    color: var(--text);
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 800;
    letter-spacing: 0.2px;
}

.badge {
    font-size: 12px;
    padding: 4px 10px;
    border-radius: 999px;
    background: color-mix(in srgb, var(--accent) 20%, var(--surface));
    border: 1px solid var(--border);
}

.nav {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

    .nav a {
        padding: 9px 12px;
        border-radius: 999px;
        border: 1px solid var(--border);
        background: color-mix(in srgb, var(--surface) 85%, transparent);
        box-shadow: 0 1px 0 rgba(0,0,0,0.02);
    }

        .nav a:hover {
            background: color-mix(in srgb, var(--surface) 60%, var(--accent) 15%);
            text-decoration: none;
        }

.card {
    background: color-mix(in srgb, var(--surface) 88%, transparent);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

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

.card-body {
    padding: var(--pad);
}

.h1 {
    font-size: 22px;
    margin: 0;
}

.actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: color-mix(in srgb, var(--surface) 85%, transparent);
    cursor: pointer;
    font-weight: 650;
}

    .btn:hover {
        background: color-mix(in srgb, var(--surface) 60%, var(--accent) 12%);
    }

    .btn:focus {
        outline: none;
        box-shadow: var(--focus);
    }

.btn-primary {
    background: linear-gradient(135deg, color-mix(in srgb, var(--primary) 70%, white), color-mix(in srgb, var(--accent) 65%, white));
    border-color: color-mix(in srgb, var(--accent) 40%, var(--border));
}

html[data-theme="dark"] .btn-primary {
    background: linear-gradient(135deg, color-mix(in srgb, var(--primary) 80%, black), color-mix(in srgb, var(--accent) 70%, black));
}

.btn-danger {
    background: color-mix(in srgb, var(--danger) 18%, var(--surface));
    border-color: color-mix(in srgb, var(--danger) 45%, var(--border));
}

.btn-ghost {
    background: transparent;
}

.table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    overflow: hidden;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
}

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

    .table th {
        text-align: left;
        font-size: 13px;
        color: var(--muted);
        background: color-mix(in srgb, var(--surface-2) 75%, transparent);
    }

    .table tr:last-child td {
        border-bottom: none;
    }

.grid {
    display: grid;
    gap: 14px;
    grid-template-columns: repeat(12, 1fr);
}

.col-6 {
    grid-column: span 6;
}

.col-12 {
    grid-column: span 12;
}

@media (max-width: 800px) {
    .col-6 {
        grid-column: span 12;
    }

    .topbar-inner {
        padding: 12px 14px;
    }

    .sidebar {
        width: 86vw;
        max-width: 320px;
    }
}

.field label {
    display: block;
    font-size: 13px;
    color: var(--muted);
    margin-bottom: 6px;
    font-weight: 650;
}

.input, select.input, textarea.input {
    width: 100%;
    padding: 11px 12px;
    border-radius: 12px;
    border: 1px solid var(--border);
    background: color-mix(in srgb, var(--surface) 88%, transparent);
    color: var(--text);
}

    .input:focus {
        outline: none;
        box-shadow: var(--focus);
    }

.help {
    font-size: 12px;
    color: var(--muted);
    margin-top: 6px;
}

.validation {
    color: color-mix(in srgb, var(--danger) 75%, var(--text));
    font-size: 12px;
    margin-top: 6px;
}

.pill {
    font-size: 12px;
    padding: 4px 10px;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: color-mix(in srgb, var(--primary) 18%, var(--surface));
}

    .pill.off {
        background: color-mix(in srgb, var(--danger) 15%, var(--surface));
    }

.footer {
    margin: 18px 0 40px;
    color: var(--muted);
    font-size: 12px;
}

/* Dropdown menus (navbar por Area) */
.nav {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
}

.menu {
    position: relative;
}

.menu-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 9px 12px;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: color-mix(in srgb, var(--surface) 85%, transparent);
    box-shadow: 0 1px 0 rgba(0,0,0,0.02);
    cursor: pointer;
    font-weight: 700;
    color: var(--text);
}

    .menu-btn:hover {
        background: color-mix(in srgb, var(--surface) 60%, var(--accent) 15%);
    }

    .menu-btn:focus {
        outline: none;
        box-shadow: var(--focus);
    }

.chev {
    opacity: 0.8;
    font-size: 12px;
    transform: translateY(-1px);
}

.menu-panel {
    position: absolute;
    top: calc(100% + 10px);
    left: 0;
    min-width: 210px;
    padding: 8px;
    border-radius: 14px;
    border: 1px solid var(--border);
    background: color-mix(in srgb, var(--surface) 92%, transparent);
    box-shadow: var(--shadow);
    backdrop-filter: blur(10px);
    display: none;
    z-index: 20;
}

.menu.open .menu-panel {
    display: grid;
    gap: 6px;
}

.menu.open .menu-btn {
    background: color-mix(in srgb, var(--surface) 55%, var(--accent) 16%);
}

.menu.open .chev {
    transform: translateY(-1px) rotate(180deg);
}

.menu-panel a {
    padding: 10px 12px;
    border-radius: 12px;
    border: 1px solid transparent;
    color: var(--text);
    text-decoration: none;
    font-weight: 650;
    background: color-mix(in srgb, var(--surface-2) 75%, transparent);
}

    .menu-panel a:hover {
        border-color: var(--border);
        background: color-mix(in srgb, var(--surface) 60%, var(--primary) 16%);
    }

/* Mobile: dropdown ocupa a largura */
@media (max-width: 800px) {
    .menu-panel {
        position: static;
        min-width: unset;
        width: 100%;
    }

    .menu {
        width: 100%;
    }

    .menu-btn {
        width: 100%;
        justify-content: space-between;
    }
}

/* Unidade selector */
.unidade-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    border-radius: 999px;
    background: color-mix(in srgb, var(--accent) 20%, var(--surface));
    border: 1px solid var(--border);
    font-weight: 700;
    font-size: 13px;
    cursor: pointer;
}

.unidade-chip:hover {
    background: color-mix(in srgb, var(--accent) 30%, var(--surface));
}

.unidade-chip .dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--primary-2);
}

.unidade-chip.empty .dot {
    background: var(--warning);
}

/* Modal */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    z-index: 100;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.modal-backdrop.open {
    display: flex;
}

.modal {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    width: 100%;
    max-width: 520px;
    max-height: 80vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.modal-header {
    padding: 16px 18px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h2 {
    margin: 0;
    font-size: 17px;
}

.modal-body {
    padding: 16px 18px;
    overflow-y: auto;
}

.modal-footer {
    padding: 12px 18px;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

.unidade-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.unidade-list-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: color-mix(in srgb, var(--surface-2) 80%, transparent);
}

.unidade-list-item.selected {
    border-color: var(--primary-2);
    background: color-mix(in srgb, var(--primary) 18%, var(--surface));
}

.unidade-list-item .info {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.unidade-list-item .info strong {
    font-size: 14px;
}

.unidade-list-item .info small {
    color: var(--muted);
}

.unidade-banner {
    background: color-mix(in srgb, var(--warning) 30%, var(--surface));
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px 16px;
    margin-bottom: 14px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
}

/* ===== Ferramentas de tabela (pesquisa / ordenação / filtro) ===== */
.table-tools {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    margin-bottom: 12px;
}

.table-tools-search {
    flex: 1 1 220px;
    min-width: 180px;
    max-width: 360px;
}

.table-tools-filter {
    width: auto;
    min-width: 140px;
}

.table-tools-spacer {
    flex: 1 1 auto;
}

.table-tools-count {
    color: var(--muted);
    font-size: 13px;
    white-space: nowrap;
}

table.js-table-tools th.sortable {
    cursor: pointer;
    user-select: none;
    white-space: nowrap;
}

table.js-table-tools th.sortable:hover {
    color: var(--primary-2);
}

table.js-table-tools th.sortable::after {
    content: "\2195"; /* ↕ */
    display: inline-block;
    margin-left: 6px;
    opacity: 0.35;
    font-size: 0.85em;
}

table.js-table-tools th.sortable[aria-sort="ascending"]::after {
    content: "\2191"; /* ↑ */
    opacity: 1;
    color: var(--primary-2);
}

table.js-table-tools th.sortable[aria-sort="descending"]::after {
    content: "\2193"; /* ↓ */
    opacity: 1;
    color: var(--primary-2);
}

table.js-table-tools th.sortable:focus-visible {
    outline: none;
    box-shadow: var(--focus);
}
