/* ============================================================
   Controle Na Prática — estilos globais
   Tema escuro azul-marinho (mesma identidade da tela de login)
   ============================================================ */

:root {
    --bg-body: oklch(0.15 0.035 259);
    --bg-surface: oklch(0.185 0.05 259);
    --bg-card: oklch(0.235 0.05 259);
    --bg-card-alt: oklch(0.285 0.055 259);
    --border-subtle: oklch(1 0 0 / 8%);
    --text-primary: oklch(0.97 0.008 259);
    --text-secondary: oklch(0.74 0.03 259);
    --text-muted: oklch(0.56 0.03 259);
    --accent: oklch(0.55 0.19 259);
    --accent-hover: oklch(0.60 0.185 259);
    --accent-active: oklch(0.47 0.19 259);
    --success: oklch(0.72 0.16 152);
    --danger: oklch(0.62 0.19 25);
    --radius-md: 10px;
    --radius-lg: 14px;
    --radius-pill: 999px;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--bg-body);
    color: var(--text-primary);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

h1, h2, h3, h4 { font-weight: 700; margin: 0 0 8px; }
p { margin: 0 0 8px; color: var(--text-secondary); }
a { color: inherit; text-decoration: none; }

/* ---------- Layout: rail de ícones (expande no hover) + barra superior ---------- */
.app-layout {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.rail {
    background: var(--bg-surface);
    border-right: 1px solid var(--border-subtle);
    display: flex;
    flex-direction: column;
    padding: 18px 0;
    z-index: 50;
}

.rail-brand {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-md);
    background: var(--accent);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 13px;
    flex-shrink: 0;
    margin: 0 0 22px 24px;
}

.rail-nav {
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex: 1;
    width: 100%;
}

.rail-link {
    display: flex;
    align-items: center;
    gap: 14px;
    height: 44px;
    margin: 0 8px;
    padding: 0 16px;
    border-radius: 10px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    transition: background 150ms ease-out, color 150ms ease-out;
}

.rail-link svg { flex-shrink: 0; }

.rail-label {
    font-size: 13px;
    font-weight: 600;
    opacity: 0;
    transition: opacity 150ms ease-out;
}

.rail-link:hover { background: var(--bg-card); color: var(--text-primary); }
.rail-link.active { background: var(--accent); color: #fff; }

.app-body {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Acima de 760px: rail vira uma coluna fixa que expande no hover
   (peek/flyout), sem empurrar o conteúdo — só o app-body reserva
   os 72px de espaço da largura "em repouso". */
@media (min-width: 761px) {
    .rail {
        position: fixed;
        left: 0;
        top: 0;
        height: 100vh;
        width: 72px;
        overflow: hidden;
        transition: width 200ms cubic-bezier(0.16, 1, 0.3, 1);
    }

    .rail:hover { width: 232px; }
    .rail:hover .rail-label { opacity: 1; transition-delay: 60ms; }

    .app-body { flex: 1; min-width: 0; margin-left: 72px; }
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 18px 32px;
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border-subtle);
}

.topbar-title {
    font-size: 19px;
    font-weight: 700;
    margin: 0;
}

.topbar-user {
    display: flex;
    align-items: center;
    gap: 14px;
    flex-shrink: 0;
}

.topbar-user-info {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    line-height: 1.25;
}

.user-name { font-weight: 600; font-size: 13px; }
.user-email { font-size: 11px; color: var(--text-muted); }

.topbar-logout {
    padding: 8px 16px;
    border-radius: var(--radius-pill);
    background: var(--bg-card);
    color: var(--text-secondary);
    font-weight: 600;
    font-size: 13px;
    border: 1px solid var(--border-subtle);
    transition: color 150ms ease-out, border-color 150ms ease-out;
}

.topbar-logout:hover { color: var(--text-primary); border-color: var(--text-secondary); }

.main-content {
    flex: 1;
    padding: 28px 32px;
    max-width: 100%;
    overflow-x: hidden;
}

/* Espaçamento vertical consistente entre QUALQUER bloco de topo
   (card, kpi-grid, charts-grid, totals-grid, table-wrapper, alert...),
   não só entre dois .card consecutivos. */
.main-content > * + * {
    margin-top: 18px;
}

/* ---------- Cards ---------- */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    padding: 20px;
}

.card-title {
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

/* ---------- KPI grid ---------- */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 20px;
}

.kpi-card {
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    padding: 18px 20px;
}

.kpi-label {
    font-size: 12px;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: 8px;
}

.kpi-value {
    font-size: 26px;
    font-weight: 700;
    color: var(--text-primary);
}

.kpi-value.negative { color: var(--danger); }

/* ---------- Charts ---------- */
.charts-grid {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 16px;
    margin-bottom: 20px;
}

.chart-card { min-height: 320px; }

/* ---------- Filters ---------- */
.filter-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: flex-end;
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    padding: 16px;
    margin-bottom: 18px;
}

.filter-field {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.filter-field label {
    font-size: 12px;
    color: var(--text-secondary);
}

.period-shortcuts {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.period-btn {
    padding: 7px 14px;
    border-radius: var(--radius-pill);
    background: var(--bg-card-alt);
    border: 1px solid var(--border-subtle);
    color: var(--text-secondary);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: background 150ms ease-out, color 150ms ease-out;
}

.period-btn:hover { color: var(--text-primary); }
.period-btn.active { background: var(--accent); color: #fff; border-color: transparent; }

/* ---------- Forms ---------- */
.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 14px;
}

label { font-size: 13px; color: var(--text-secondary); font-weight: 600; margin-bottom: 4px; display: inline-block; }

input, select, textarea {
    width: 100%;
    background: var(--bg-card-alt);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    padding: 10px 12px;
    color: var(--text-primary);
    font-size: 14px;
    font-family: inherit;
}

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--accent);
}

textarea { resize: vertical; min-height: 70px; }

.form-actions {
    display: flex;
    gap: 10px;
    margin-top: 18px;
}

/* ---------- Buttons ---------- */
.btn-primary, .btn-secondary, .btn-danger {
    padding: 10px 22px;
    border-radius: var(--radius-pill);
    border: none;
    font-weight: 700;
    font-size: 14px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: background 150ms ease-out, border-color 150ms ease-out;
}

.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:active { background: var(--accent-active); }

.btn-secondary { background: var(--bg-card-alt); color: var(--text-primary); border: 1px solid var(--border-subtle); }
.btn-secondary:hover { border-color: var(--text-secondary); }

.btn-danger { background: transparent; color: var(--danger); border: 1px solid var(--danger); }
.btn-danger:hover { background: oklch(0.62 0.19 25 / 10%); }

.btn-sm { padding: 6px 14px; font-size: 12px; }

/* ---------- Tables ---------- */
.table-wrapper {
    overflow-x: auto;
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
}

table { width: 100%; border-collapse: collapse; min-width: 720px; }

th, td {
    padding: 11px 14px;
    text-align: left;
    font-size: 13px;
    border-bottom: 1px solid var(--border-subtle);
    white-space: nowrap;
}

th {
    color: var(--text-secondary);
    text-transform: uppercase;
    font-size: 11px;
    letter-spacing: 0.03em;
    background: var(--bg-card-alt);
}

tbody tr:hover { background: oklch(1 0 0 / 3%); }

.table-actions { display: flex; gap: 8px; }

/* ---------- Totals summary ---------- */
.totals-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 12px;
    margin-bottom: 18px;
}

.totals-item {
    background: var(--bg-card-alt);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    padding: 12px 14px;
}

.totals-item .label { font-size: 11px; color: var(--text-muted); text-transform: uppercase; }
.totals-item .value { font-size: 18px; font-weight: 700; margin-top: 4px; }

/* ---------- Alerts ---------- */
.alert {
    padding: 12px 16px;
    border-radius: var(--radius-md);
    font-size: 14px;
    margin-bottom: 16px;
}

.alert-error { background: oklch(0.62 0.19 25 / 14%); color: oklch(0.85 0.09 25); border: 1px solid oklch(0.62 0.19 25 / 35%); }
.alert-success { background: oklch(0.72 0.16 152 / 14%); color: oklch(0.85 0.11 152); border: 1px solid oklch(0.72 0.16 152 / 35%); }

/* Estilos da tela de login vivem em login.css (carregado só por login.php) */

/* ---------- Badges ---------- */
.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: var(--radius-pill);
    font-size: 11px;
    font-weight: 700;
}

.badge-active { background: oklch(0.72 0.16 152 / 16%); color: oklch(0.85 0.11 152); }
.badge-suspended { background: oklch(0.62 0.19 25 / 16%); color: oklch(0.85 0.09 25); }

/* ---------- Modal (confirmação de exclusão) ---------- */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: oklch(0 0 0 / 55%);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 100;
}

.modal-overlay.open { display: flex; }

.modal-box {
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    padding: 24px;
    max-width: 360px;
    width: 90%;
}

.modal-actions { display: flex; gap: 10px; margin-top: 18px; justify-content: flex-end; }

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
    .charts-grid { grid-template-columns: 1fr; }
}

@media (max-width: 760px) {
    .rail {
        flex-direction: row;
        align-items: center;
        justify-content: center;
        border-right: none;
        border-bottom: 1px solid var(--border-subtle);
        padding: 10px;
        gap: 4px;
        flex-wrap: wrap;
    }

    .rail-brand { margin: 0 14px 0 0; }
    .rail-nav { flex-direction: row; flex: none; width: auto; gap: 4px; flex-wrap: wrap; justify-content: center; }

    .rail-link {
        width: 44px;
        height: 44px;
        margin: 0;
        padding: 0;
        justify-content: center;
    }

    .rail-label { display: none; }

    .topbar { padding: 14px 18px; }
    .topbar-user-info { display: none; }
    .main-content { padding: 18px; }
}

@media (max-width: 480px) {
    .topbar-title { font-size: 16px; }
}