@import url('https://fonts.googleapis.com/css2?family=Urbanist:wght@400;500;600;700&family=Playfair+Display:wght@400&display=swap');

:root {
    --bg: #F4F3F0;
    --surface: #FFFFFF;
    --accent: #577569;
    --accent-hover: #37454B;
    --accent-soft: rgba(87, 117, 105, 0.12);
    --text: #101010;
    --text-muted: rgba(16, 16, 16, 0.58);
    --dark: #101010;
    --border: rgba(16, 16, 16, 0.08);
    --shadow: 0 2px 16px rgba(16, 16, 16, 0.05);
    --shadow-sm: 0 1px 4px rgba(16, 16, 16, 0.04);
    --radius: 16px;
    --sidebar-w: 248px;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: 'Urbanist', sans-serif;
    font-weight: 400;
    line-height: 1.5;
}

h1,
h2,
h3 {
    font-family: 'Urbanist', sans-serif;
    font-weight: 400;
    margin: 0 0 0.5em;
}

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

/* ---------------------------------------------------------------
   Shell: sidebar fixa + área de conteúdo
   --------------------------------------------------------------- */

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

.sidebar {
    width: var(--sidebar-w);
    flex-shrink: 0;
    background: var(--surface);
    border-right: 1px solid var(--border);
    padding: 28px 20px;
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
}

.sidebar .brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0 8px;
    margin-bottom: 36px;
}

.sidebar .brand img {
    width: 130px;
    height: auto;
}

.sidebar .brand span {
    font-family: 'Urbanist', sans-serif;
    font-size: 19px;
}

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

.sidebar nav .nav-section {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
    margin: 18px 8px 8px;
}

.sidebar nav .nav-section:first-child {
    margin-top: 0;
}

.sidebar nav a {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border-radius: 10px;
    font-weight: 500;
    font-size: 14.5px;
    color: var(--text);
    opacity: 0.7;
}

.sidebar nav a .icon {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.sidebar nav a:hover {
    opacity: 1;
    background: rgba(16, 16, 16, 0.03);
}

.sidebar nav a.active {
    opacity: 1;
    background: var(--accent);
    color: #fff;
}

.nav-dropdown-toggle {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 10px 12px;
    border: none;
    background: transparent;
    border-radius: 10px;
    font-family: 'Urbanist', sans-serif;
    font-weight: 500;
    font-size: 14.5px;
    color: var(--text);
    opacity: 0.7;
    cursor: pointer;
    text-align: left;
}

.nav-dropdown-toggle .icon {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.nav-dropdown-toggle:hover {
    opacity: 1;
    background: rgba(16, 16, 16, 0.03);
}

.nav-dropdown-toggle.active {
    opacity: 1;
    background: var(--accent-soft);
    color: var(--accent-hover);
    font-weight: 600;
}

.nav-dropdown-arrow {
    margin-left: auto;
    display: inline-flex;
    transition: transform 0.15s ease;
}

.nav-dropdown-toggle.expandido .nav-dropdown-arrow {
    transform: rotate(180deg);
}

.nav-dropdown {
    display: grid;
    grid-template-rows: 0fr;
    transition: grid-template-rows 0.2s ease;
}

.nav-dropdown.aberto {
    grid-template-rows: 1fr;
}

.nav-dropdown-inner {
    overflow: hidden;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.nav-dropdown a {
    padding-left: 42px;
    font-size: 14px;
}

.sidebar-footer {
    margin-top: auto;
    padding-top: 16px;
    border-top: 1px solid var(--border);
    font-size: 12px;
    color: var(--text-muted);
}

.main {
    flex: 1;
    min-width: 0;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 22px 40px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 5;
}

.topbar .page-title {
    font-family: 'Urbanist', sans-serif;
    font-size: 22px;
}

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

.avatar {
    position: relative;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: var(--accent-soft);
    color: var(--accent-hover);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 14px;
    flex-shrink: 0;
    overflow: hidden;
}

.avatar-fallback {
    line-height: 1;
}

.avatar img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.container {
    max-width: 1180px;
    margin: 0 auto;
    padding: 36px 40px;
}

/* ---------------------------------------------------------------
   Componentes
   --------------------------------------------------------------- */

.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 28px;
    gap: 16px;
    flex-wrap: wrap;
}

.btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 10px;
    padding: 12px 22px;
    font-family: 'Urbanist', sans-serif;
    font-weight: 600;
    font-size: 14px;
    cursor: pointer;
    transition: background 0.15s ease;
}

.btn svg { flex-shrink: 0; }

.btn:hover {
    background: var(--accent-hover);
}

.btn-secondary {
    background: var(--surface);
    color: var(--text);
    border: 1px solid rgba(16, 16, 16, 0.16);
    box-shadow: var(--shadow-sm);
}

.btn-secondary:hover {
    background: rgba(16, 16, 16, 0.05);
    border-color: rgba(16, 16, 16, 0.26);
}

.btn-danger {
    background: #8a3b3b;
}

.btn-danger:hover {
    background: #6e2e2e;
}

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    padding: 24px;
}

table {
    width: 100%;
    border-collapse: collapse;
    background: var(--surface);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border);
}

th,
td {
    text-align: left;
    padding: 14px 18px;
    border-bottom: 1px solid var(--border);
    font-size: 14px;
}

th {
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    font-size: 11px;
    letter-spacing: 0.04em;
    background: rgba(16, 16, 16, 0.015);
}

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

tr:hover td {
    background: rgba(87, 117, 105, 0.04);
}

.badge {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
}

.badge-entrada {
    background: #37454b;
    color: #fff;
}

.badge-saida {
    background: rgba(138, 59, 59, 0.1);
    color: #6e2e2e;
}

.badge-tipo-variavel,
.badge-tipo-simples {
    border-radius: 6px;
    text-transform: uppercase;
    font-size: 10.5px;
    letter-spacing: 0.03em;
    padding: 3px 8px;
    margin-left: 6px;
    vertical-align: middle;
}

.badge-tipo-variavel {
    background: rgba(127, 84, 179, 0.12);
    color: #7f54b3;
}

.badge-tipo-simples {
    background: rgba(16, 16, 16, 0.06);
    color: var(--text-muted);
}

.status-cell {
    display: flex;
    align-items: center;
    gap: 8px;
}

.status-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.status-icon-on {
    color: #7f54b3;
}

.status-icon-off {
    color: var(--text-muted);
    opacity: 0.4;
}

.status-dot {
    display: inline-block;
    width: 9px;
    height: 9px;
    border-radius: 50%;
    flex-shrink: 0;
}

.status-dot-ok {
    background: #3f9142;
}

.status-dot-erro {
    background: #c0453f;
}

.status-dot-parcial {
    background: #3b6dc0;
}

.form-group {
    margin-bottom: 18px;
}

.form-group label {
    display: block;
    font-weight: 600;
    font-size: 13px;
    margin-bottom: 6px;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 18px;
}

input,
select,
textarea {
    width: 100%;
    padding: 14px 14px;
    border: 1px solid var(--border);
    border-radius: 10px;
    font-family: 'Urbanist', sans-serif;
    font-size: 14px;
    background: var(--surface);
    color: var(--text);
}

input:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: var(--accent);
}

.alert {
    padding: 14px 18px;
    border-radius: 10px;
    margin-bottom: 20px;
    font-size: 14px;
}

.alert-error {
    background: rgba(138, 59, 59, 0.08);
    color: #6e2e2e;
    border: 1px solid rgba(138, 59, 59, 0.2);
}

.alert-success {
    background: rgba(87, 117, 105, 0.1);
    color: var(--accent-hover);
    border: 1px solid rgba(87, 117, 105, 0.2);
}

/* ---------------------------------------------------------------
   KPI cards (estilo dashboard)
   --------------------------------------------------------------- */

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

.kpi-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    padding: 20px 22px;
}

.kpi-card .kpi-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 14px;
}

.kpi-card .kpi-label {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-muted);
}

.kpi-card .kpi-icon {
    width: 30px;
    height: 30px;
    border-radius: 8px;
    background: var(--accent-soft);
    color: var(--accent-hover);
    display: flex;
    align-items: center;
    justify-content: center;
}

.kpi-card .kpi-value {
    font-family: 'Urbanist', sans-serif;
    font-size: 30px;
    line-height: 1.1;
}

.kpi-card .kpi-sub {
    margin-top: 8px;
    font-size: 12.5px;
    color: var(--text-muted);
}

.kpi-card .kpi-pill {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 11.5px;
    font-weight: 700;
}

.kpi-pill-up {
    background: rgba(87, 117, 105, 0.14);
    color: var(--accent-hover);
}

.kpi-pill-down {
    background: rgba(138, 59, 59, 0.1);
    color: #6e2e2e;
}

.kpi-pill-neutral {
    background: rgba(16, 16, 16, 0.06);
    color: var(--text-muted);
}

.stat-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 14px;
    margin: 24px 0;
}

.detail-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 18px 24px;
}

.detail-item .detail-label {
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
    margin-bottom: 4px;
}

.detail-item .detail-value {
    font-size: 15px;
    font-weight: 500;
}

.stat-tile {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 18px;
    text-align: center;
}

.stat-tile .value {
    font-family: 'Urbanist', sans-serif;
    font-size: 28px;
    color: var(--accent-hover);
}

.stat-tile .label {
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    opacity: 0.6;
    margin-top: 4px;
}

.panel-grid {
    display: grid;
    grid-template-columns: 1.4fr 1fr;
    gap: 16px;
    margin-bottom: 16px;
}

.panel-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 18px;
}

.panel-head h3 {
    margin: 0;
    font-size: 17px;
}

.panel-head .muted {
    margin-top: 2px;
}

.filter-tabs {
    display: flex;
    gap: 4px;
    background: var(--bg);
    border-radius: 10px;
    padding: 4px;
    flex-shrink: 0;
}

.filter-tab {
    padding: 7px 14px;
    border-radius: 7px;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-muted);
}

.filter-tab:hover {
    color: var(--text);
}

.filter-tab.active {
    background: var(--surface);
    color: var(--text);
    box-shadow: var(--shadow-sm);
}

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

.mini-row:last-child {
    border-bottom: none;
}

.mini-row .mini-name {
    font-weight: 600;
    font-size: 14px;
}

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

.muted {
    opacity: 0.6;
    font-size: 13px;
}

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

.empty-state {
    text-align: center;
    padding: 60px 20px;
    opacity: 0.6;
}

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

    .kpi-grid,
    .stat-grid,
    .detail-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .panel-grid {
        grid-template-columns: 1fr;
    }

    .container {
        padding: 24px 20px;
    }
}

/* ---------------------------------------------------------------
   Indicador de carregamento (barra no topo + spinner em botões)
   --------------------------------------------------------------- */

#loading-bar {
    position: fixed;
    top: 0;
    left: 0;
    height: 3px;
    width: 0%;
    background: var(--accent);
    z-index: 999;
    opacity: 0;
    transition: width 0.3s ease, opacity 0.2s ease;
}

#loading-bar.active {
    opacity: 1;
    width: 70%;
    transition: width 8s cubic-bezier(0.1, 0.6, 0.2, 1), opacity 0.2s ease;
}

.btn[disabled] {
    opacity: 0.75;
    cursor: default;
    pointer-events: none;
}

.btn .btn-spinner {
    width: 14px;
    height: 14px;
    border: 2px solid rgba(255, 255, 255, 0.4);
    border-top-color: #fff;
    border-radius: 50%;
    display: none;
    animation: btn-spin 0.6s linear infinite;
}

.btn-secondary .btn-spinner {
    border-color: rgba(16, 16, 16, 0.2);
    border-top-color: var(--text);
}

.btn[disabled] .btn-spinner {
    display: inline-block;
}

.btn[disabled] .btn-label {
    opacity: 0.85;
}

@keyframes btn-spin {
    to {
        transform: rotate(360deg);
    }
}

/* ---------------------------------------------------------------
   Tela de login
   --------------------------------------------------------------- */

.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
}

.login-shell {
    width: 100%;
    max-width: 380px;
    padding: 20px;
}

.login-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 36px 32px;
    text-align: center;
}

.login-logo {
    width: 110px;
    height: auto;
    margin: 0 auto 20px;
}

.login-card h1 {
    font-size: 22px;
    margin-bottom: 4px;
}

.login-card form {
    text-align: left;
}