/* ================================================================
   PAINEL CSP — 2026 PREMIUM DARK SAAS
   Real significant redesign: deep modern dark, strong elevation,
   generous spacing, confident typography, high-quality interactions.
   No 2000s vibes. Clean, expensive, professional.
   ================================================================ */

:root {
    /* Deep, rich dark base — modern 2026 SaaS */
    --bg: #020617;
    --bg-elev: #0a0f1e;
    --surface: #0f1625;
    --surface-2: #161f32;
    --surface-3: #1e293b;

    --border: #1f2937;
    --border-light: #334155;

    --text: #f1f5f9;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;

    --accent: #0ea5e9;
    --accent-600: #0284c7;
    --accent-ring: rgba(14, 165, 233, 0.25);

    --success: #22c55e;
    --success-bg: rgba(34, 197, 94, 0.12);
    --warning: #f59e0b;
    --warning-bg: rgba(245, 158, 11, 0.12);
    --danger: #f43f5e;
    --danger-bg: rgba(244, 63, 94, 0.12);

    --radius: 16px;
    --radius-sm: 10px;
    --radius-lg: 20px;

    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.2);
    --shadow: 0 10px 15px -3px rgb(0 0 0 / 0.25), 0 4px 6px -4px rgb(0 0 0 / 0.25);
    --shadow-lg: 0 20px 25px -5px rgb(0 0 0 / 0.3), 0 10px 10px -5px rgb(0 0 0 / 0.2);
    --shadow-xl: 0 25px 50px -12px rgb(0 0 0 / 0.4);

    --transition: 200ms cubic-bezier(0.4, 0, 0.2, 1);
}

/* Global reset + premium base */
*, *::before, *::after { box-sizing: border-box; }

html, body {
    font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 14.5px;
    line-height: 1.65;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    min-height: 100vh;
}

/* ====================== TYPOGRAPHY — CONFIDENT & MODERN ====================== */
h1 {
    font-size: 28px;
    font-weight: 700;
    letter-spacing: -0.04em;
    line-height: 1.15;
    margin: 0 0 4px;
}
h2 {
    font-size: 20px;
    font-weight: 600;
    letter-spacing: -0.025em;
}
h3 {
    font-size: 16px;
    font-weight: 600;
    letter-spacing: -0.01em;
}

.text-secondary { color: var(--text-secondary); }
.text-muted { color: var(--text-muted); }

.page-subtitle {
    color: var(--text-secondary);
    font-size: 15px;
    margin-top: 4px;
}

/* ====================== LAYOUT (defensive + consistent) ====================== */
.main-wrapper {
    margin-left: 260px;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Support for older pages that used manual flex wrapper — prevent double margins and broken alignment */
body > .flex.min-h-screen {
    /* When pages still use the old <div class="flex min-h-screen"> pattern, make the inner content area behave like main-wrapper */
}

@media (max-width: 768px) {
    .main-wrapper { margin-left: 0; }
}

/* Global defensive rules so old Tailwind-heavy HTML doesn't look completely broken during transition */
body.bg-gray-900,
body.text-gray-100 {
    background: var(--bg) !important;
    color: var(--text) !important;
}

/* ====================== CARDS — STRONG ELEVATION ====================== */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    transition: transform var(--transition), box-shadow var(--transition), border-color var(--transition);
}

.card:hover {
    border-color: var(--border-light);
    box-shadow: var(--shadow-lg);
    transform: translateY(-1px);
}

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

.card-body {
    padding: 24px;
}

.stat-card {
    min-height: 92px;
}
.stat-card .stat-number {
    font-size: 28px;
    font-weight: 700;
    letter-spacing: -0.04em;
    line-height: 1.1;
}

/* ====================== BUTTONS — PREMIUM FEEL ====================== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 11px 20px;
    border-radius: 12px;
    font-weight: 600;
    font-size: 14px;
    letter-spacing: -0.01em;
    line-height: 1;
    transition: all var(--transition);
    border: 1px solid transparent;
    cursor: pointer;
    white-space: nowrap;
    user-select: none;
}

.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0) scale(0.985); }

.btn-primary {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
    box-shadow: 0 4px 6px -1px rgb(14 165 233 / 0.3);
}
.btn-primary:hover {
    background: var(--accent-600);
    border-color: var(--accent-600);
    box-shadow: 0 10px 15px -3px rgb(14 165 233 / 0.35);
}

.btn-secondary {
    background: var(--surface-2);
    color: var(--text);
    border-color: var(--border);
}
.btn-secondary:hover {
    background: var(--surface-3);
    border-color: var(--border-light);
}

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
    border-color: transparent;
}
.btn-ghost:hover {
    background: var(--surface-2);
    color: var(--text);
}

.btn-danger {
    background: var(--danger);
    color: white;
    border-color: var(--danger);
}
.btn-danger:hover {
    background: #e11d48;
}

.btn-sm {
    padding: 7px 14px;
    font-size: 13px;
    border-radius: 10px;
}

/* ====================== FORMS ====================== */
.input, .select, textarea {
    width: 100%;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 12px 16px;
    color: var(--text);
    font-size: 14.5px;
    transition: border-color .15s, box-shadow .15s, background .15s;
}
.input:focus, .select:focus, textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 4px var(--accent-ring);
    background: var(--surface);
}
.input::placeholder { color: var(--text-muted); }

label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 6px;
    letter-spacing: -0.01em;
}

/* ====================== TABLES — CLEAN MODERN ====================== */
.table-wrapper {
    overflow: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

thead th {
    background: var(--surface-2);
    color: var(--text-secondary);
    font-weight: 600;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    padding: 14px 20px;
    text-align: left;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

tbody td {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
    color: var(--text);
}

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

tbody tr:hover {
    background: rgba(15, 22, 37, 0.6);
}

tbody tr td:first-child,
thead th:first-child { padding-left: 24px; }
tbody tr td:last-child,
thead th:last-child { padding-right: 24px; }

/* ====================== BADGES & PILLS ====================== */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 3px 12px;
    border-radius: 9999px;
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.02em;
    border: 1px solid transparent;
}

.badge-success { background: var(--success-bg); color: #4ade80; border-color: rgba(34,197,94,.25); }
.badge-danger  { background: var(--danger-bg); color: #fb7185; border-color: rgba(244,63,94,.25); }
.badge-warning { background: var(--warning-bg); color: #fbbf24; border-color: rgba(245,158,11,.25); }
.badge-info    { background: rgba(14,165,233,.12); color: #7dd3fc; border-color: rgba(14,165,233,.25); }
.badge-neutral { background: rgba(148,163,184,.12); color: var(--text-secondary); border-color: rgba(148,163,184,.2); }

/* ====================== ACTION ICON BUTTONS ====================== */
.action-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border-radius: 10px;
    color: var(--text-secondary);
    transition: all .15s ease;
}
.action-btn:hover {
    color: var(--text);
    background: var(--surface-3);
}
.action-btn.danger:hover {
    color: #fb7185;
    background: var(--danger-bg);
}

/* ====================== MODALS — PREMIUM ====================== */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(2, 6, 23, 0.82);
    backdrop-filter: blur(6px);
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
}

.modal {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-xl);
    width: 100%;
    max-width: 620px;
    max-height: 92vh;
    overflow: auto;
}

.modal-header {
    padding: 18px 24px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-weight: 600;
    font-size: 17px;
}

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

/* ====================== SIDEBAR — REFINED ====================== */
.sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    width: 260px;
    background: var(--bg-elev);
    border-right: 1px solid var(--border);
    z-index: 50;
    display: flex;
    flex-direction: column;
}

.sidebar-logo {
    padding: 22px 24px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
}

.sidebar nav {
    flex: 1;
    padding: 12px;
    overflow-y: auto;
}

.sidebar a {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    margin: 2px 4px;
    border-radius: 10px;
    color: var(--text-secondary);
    font-weight: 500;
    font-size: 14px;
    transition: all .15s ease;
    border-left: 3px solid transparent;
}
.sidebar a:hover {
    background: var(--surface-2);
    color: var(--text);
}
.sidebar a.active,
.sidebar a[aria-current="page"] {
    background: rgba(14, 165, 233, 0.1);
    color: var(--accent);
    font-weight: 600;
    border-left-color: var(--accent);
}

.sidebar .nav-section-title {
    padding: 16px 14px 6px;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--text-muted);
}

/* ====================== TOP NAV / HEADER ====================== */
.topbar {
    background: var(--bg-elev);
    border-bottom: 1px solid var(--border);
    min-height: 68px;
    padding: 0 24px;
    display: flex;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 40;
}

.page-header {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 24px;
    flex-wrap: wrap;
}
.page-header .title-wrap h1 { margin-bottom: 2px; }

/* ====================== EMPTY STATE ====================== */
.empty-state {
    text-align: center;
    padding: 72px 24px;
    color: var(--text-muted);
}
.empty-state .icon {
    width: 64px;
    height: 64px;
    margin: 0 auto 16px;
    opacity: .5;
}
.empty-state h3 {
    color: var(--text-secondary);
    margin-bottom: 6px;
}

/* ====================== MISC ====================== */
.section-title {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 12px;
    letter-spacing: -.01em;
}

:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* Subtle premium motion */
.card,
.btn,
.input,
table tr {
    transition: all var(--transition);
}

/* Scrollbars — refined */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-thumb {
    background: #334155;
    border-radius: 20px;
}
::-webkit-scrollbar-thumb:hover { background: #475569; }

/* ====================== HAMBURGER + OVERLAY (mobile) ====================== */
.sidebar-toggle {
    display: none; /* escondido no desktop; exibido no mobile via @media */
    align-items: center;
    justify-content: center;
    width: 42px;
    height: 42px;
    margin-right: 10px;
    flex-shrink: 0;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--surface);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition);
}
.sidebar-toggle:hover {
    color: var(--text);
    background: var(--surface-2);
}
.sidebar-toggle svg {
    width: 22px;
    height: 22px;
}

.sidebar-overlay {
    display: none; /* só aparece quando o menu abre no mobile */
    position: fixed;
    inset: 0;
    background: rgba(2, 6, 23, 0.6);
    -webkit-backdrop-filter: blur(2px);
    backdrop-filter: blur(2px);
    z-index: 45; /* abaixo da sidebar (50), acima do conteúdo */
}

/* Responsive sidebar */
@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
        transition: transform .25s cubic-bezier(0.4,0,0.2,1);
        width: 82%;
        max-width: 300px;
    }
    /* O JS (nav_bar.php) alterna body.sidebar-open. Mantemos .sidebar.open por compatibilidade. */
    body.sidebar-open .sidebar,
    .sidebar.open { transform: translateX(0); }
    body.sidebar-open .sidebar-overlay { display: block; }

    .main-wrapper { margin-left: 0; }
    .sidebar-toggle { display: inline-flex; }
}

/* ====================== TABELAS RESPONSIVAS (viram cards no mobile) ====================== */
@media (max-width: 768px) {
    /* esconde o cabeçalho visualmente (mantém p/ leitores de tela) */
    .responsive-table thead {
        position: absolute;
        width: 1px; height: 1px;
        padding: 0; margin: -1px;
        overflow: hidden;
        clip: rect(0, 0, 0, 0);
        white-space: nowrap;
        border: 0;
    }
    .responsive-table,
    .responsive-table tbody,
    .responsive-table tr,
    .responsive-table td {
        display: block;
        width: 100%;
    }
    .responsive-table tr {
        margin: 0 0 14px;
        background: var(--surface-2);
        border: 1px solid var(--border);
        border-radius: var(--radius-sm);
        overflow: hidden;
    }
    .responsive-table td {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 16px;
        text-align: right;
        padding: 9px 14px !important;
        border: 0 !important;
        border-bottom: 1px solid var(--border) !important;
    }
    .responsive-table tr td:last-child { border-bottom: 0 !important; }
    /* rótulo da coluna (preenchido via JS em nav_bar.php) */
    .responsive-table td::before {
        content: attr(data-label);
        font-size: 11px;
        font-weight: 700;
        text-transform: uppercase;
        letter-spacing: .04em;
        color: var(--text-muted);
        text-align: left;
        flex-shrink: 0;
    }
    /* célula de ações: ocupa a linha inteira, botões alinhados */
    .responsive-table td[data-label=""] { justify-content: flex-end; }
    /* só o container DIRETO da célula alinha à direita/quebra linha
       (não os flex internos, como o círculo do avatar que centraliza a inicial) */
    .responsive-table td > .flex { flex-wrap: wrap; justify-content: flex-end; }
    .responsive-table td > div { min-width: 0; }
}

/* Small polish for forms in cards */
.card .grid { gap: 18px; }

/* Make old common card patterns look decent even without .card class during transition */
.bg-gray-800.rounded-xl,
.bg-gray-800.rounded-lg,
.bg-gray-900.rounded-lg,
.bg-gray-900\/50 {
    background: var(--surface) !important;
    border-color: var(--border) !important;
}

/* Better default for old stat-like pills and small boxes */
.text-2xl.font-bold {
    letter-spacing: -0.02em;
}

/* End of 2026 Premium Dark SaaS design system.
   Everything above is the single source of truth for the modern look. */