:root {
    --bg: #f4f7fb;
    --surface: #ffffff;
    --surface-2: #f8fbff;
    --text: #1e293b;
    --text-muted: #64748b;
    --primary: #2563eb;
    --primary-soft: #dbeafe;
    --border: #e2e8f0;
    --sidebar-bg: #ffffff;
    --sidebar-text: #334155;
    --sidebar-active-bg: #2563eb;
    --sidebar-active-text: #ffffff;
    --shadow: 0 10px 30px rgba(15, 23, 42, 0.08);
}

html {
    background: #f4f7fb;
}

html[data-theme="dark"] {
    background: #0f172a;
    --bg: #0f172a;
    --surface: #111827;
    --surface-2: #172033;
    --text: #e5e7eb;
    --text-muted: #94a3b8;
    --primary: #3b82f6;
    --primary-soft: rgba(59, 130, 246, 0.15);
    --border: #243041;
    --sidebar-bg: #111827;
    --sidebar-text: #cbd5e1;
    --sidebar-active-bg: #3b82f6;
    --sidebar-active-text: #ffffff;
    --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
}

/* =========================
   BASE
========================= */

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body.sidebar-open {
    overflow: hidden;
    touch-action: none;
}

.app-wrapper {
    display: flex;
    min-height: 100vh;
}

/* =========================
   SIDEBAR
========================= */

.sidebar {
    width: 270px;
    background: var(--sidebar-bg);
    border-right: 1px solid var(--border);
    padding: 20px 16px;
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 1040;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow);
    transition: transform 0.3s ease;
    overflow: hidden;
}

.sidebar-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 24px;
    flex-shrink: 0;
}

.brand-box {
    display: flex;
    align-items: center;
    gap: 12px;
}

.brand-icon {
    width: 46px;
    height: 46px;
    border-radius: 14px;
    background: linear-gradient(135deg, var(--primary), #60a5fa);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 20px;
    flex-shrink: 0;
}

.brand-title {
    color: var(--text);
    font-weight: 700;
}

.brand-subtitle {
    color: var(--text-muted);
}

.btn-close-sidebar,
.btn-menu {
    border: none;
    background: transparent;
    color: var(--text);
    font-size: 26px;
    line-height: 1;
    cursor: pointer;
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 8px;
    flex: 1 1 auto;
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 12px;
    text-decoration: none;
    color: var(--sidebar-text);
    padding: 12px 14px;
    border-radius: 14px;
    transition: all 0.25s ease;
    font-weight: 500;
}

.sidebar-link:hover {
    background: var(--primary-soft);
    color: var(--primary);
}

.sidebar-link.active {
    background: var(--sidebar-active-bg);
    color: var(--sidebar-active-text);
    box-shadow: 0 8px 20px rgba(37, 99, 235, 0.25);
}

.sidebar-footer {
    margin-top: auto;
    padding-top: 20px;
    flex-shrink: 0;
}

.theme-toggle-wrap {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
}

.theme-toggle-label {
    font-size: 18px;
    line-height: 1;
}

.theme-toggle {
    border: none;
    background: transparent;
    padding: 0;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
}

.theme-toggle-track {
    width: 62px;
    height: 34px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 999px;
    position: relative;
    transition: all 0.25s ease;
    box-shadow: inset 0 1px 4px rgba(15, 23, 42, 0.08);
}

.theme-toggle-thumb {
    width: 26px;
    height: 26px;
    background: var(--primary);
    border-radius: 50%;
    position: absolute;
    top: 3px;
    left: 4px;
    transition: all 0.25s ease;
    box-shadow: 0 4px 10px rgba(37, 99, 235, 0.25);
}

html[data-theme="dark"] .theme-toggle-track {
    background: rgba(59, 130, 246, 0.14);
    border-color: var(--primary);
}

html[data-theme="dark"] .theme-toggle-thumb {
    left: 30px;
}

.theme-btn {
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    border-radius: 12px;
    padding: 10px 12px;
    text-align: left;
    cursor: pointer;
    transition: all 0.25s ease;
    font-weight: 600;
}

.theme-btn.active,
.theme-btn:hover {
    border-color: var(--primary);
    background: var(--primary-soft);
    color: var(--primary);
}

.sidebar-logout-btn {
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    border-radius: 12px;
    padding: 10px 12px;
    text-align: left;
    cursor: pointer;
    transition: all 0.25s ease;
    font-weight: 600;
}

.sidebar-logout-btn:hover {
    border-color: var(--primary);
    background: var(--primary-soft);
    color: var(--primary);
}

.sidebar-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.45);
    z-index: 1035;
    display: none;
}

/* =========================
   MAIN
========================= */

.main-content {
    flex: 1;
    margin-left: 270px;
    min-width: 0;
}

.topbar {
    padding: 20px 28px;
    border-bottom: 1px solid var(--border);
    background: rgba(255, 255, 255, 0.6);
    backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 1030;
}

html[data-theme="dark"] .topbar {
    background: rgba(17, 24, 39, 0.7);
}

.topbar-left {
    display: flex;
    align-items: center;
    gap: 14px;
}

.page-title {
    font-weight: 700;
    color: var(--text);
}

.page-subtitle {
    color: var(--text-muted);
}

.theme-badge {
    background: var(--surface);
    border: 1px solid var(--border);
    padding: 8px 14px;
    border-radius: 999px;
    color: var(--text-muted);
    font-size: 14px;
}

.content-area {
    padding: 28px;
}

/* =========================
   ALERTAS
========================= */

.custom-alert {
    border: none;
    border-radius: 14px;
    box-shadow: var(--shadow);
}

/* =========================
   CARDS
========================= */

.card {
    border: 1px solid var(--border);
    border-radius: 26px;
    box-shadow: 0 14px 35px rgba(15, 23, 42, 0.08);
    background: var(--surface);
    overflow: hidden;
}

.card-header {
    background: var(--surface-2);
    border-bottom: 1px solid var(--border);
    color: var(--text);
    font-weight: 600;
}

.card-body {
    color: var(--text);
    padding: 1.25rem;
}

/* =========================
   STATS
========================= */

.stats-card {
    background: linear-gradient(135deg, var(--surface), var(--surface-2));
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 20px;
    box-shadow: var(--shadow);
    height: 100%;
}

.stats-label {
    font-size: 14px;
    color: var(--text-muted);
    margin-bottom: 8px;
}

.stats-value {
    font-size: 32px;
    font-weight: 700;
    color: var(--text);
}

.stats-icon {
    width: 48px;
    height: 48px;
    border-radius: 14px;
    background: var(--primary-soft);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    margin-bottom: 16px;
}

/* =========================
   TABELAS
========================= */

.table-responsive {
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    border-radius: 20px;
}

.table-responsive::-webkit-scrollbar {
    height: 10px;
}

.table-responsive::-webkit-scrollbar-thumb {
    background: rgba(100, 116, 139, 0.35);
    border-radius: 999px;
}

.table {
    color: var(--text);
    margin-bottom: 0;
    min-width: 900px;
    width: max-content;
    white-space: nowrap;
}

.table thead th {
    border-bottom: 1px solid var(--border);
    background: var(--surface-2);
    color: var(--text-muted);
    font-size: 14px;
    font-weight: 600;
    white-space: nowrap;
    padding: 14px 16px;
}

.table tbody td {
    white-space: nowrap;
    padding: 14px 16px;
}

.table td,
.table th {
    border-color: var(--border);
    vertical-align: middle;
}

.actions-nowrap {
    white-space: nowrap;
    min-width: 210px;
}

.actions-nowrap .btn {
    margin-right: 6px;
    margin-bottom: 4px;
}

/* =========================
   FORMULÁRIOS
========================= */

.form-control,
.form-select {
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 12px;
    min-height: 46px;
}

.form-control:focus,
.form-select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 0.2rem rgba(37, 99, 235, 0.15);
    background: var(--surface);
    color: var(--text);
}

/* =========================
   BOTÕES
========================= */

.btn {
    border-radius: 14px;
    font-weight: 600;
    padding: 0.55rem 0.95rem;
}

.btn-sm {
    border-radius: 12px;
    padding: 0.42rem 0.75rem;
}

.btn-primary {
    background: var(--primary);
    border-color: var(--primary);
}

.btn-secondary {
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
}

.btn-secondary:hover {
    background: var(--surface-2);
    color: var(--text);
}

.badge {
    padding: 8px 10px;
    border-radius: 999px;
}

/* =========================
   PAGINAÇÃO
========================= */

.pagination {
    margin-top: 16px;
}

.page-link {
    border-radius: 10px !important;
    margin: 0 3px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
}

.page-item.active .page-link {
    background: var(--primary);
    border-color: var(--primary);
}

/* =========================
   MODAL
========================= */

.modal-content {
    border: 1px solid var(--border);
    border-radius: 24px;
    background: var(--surface);
    box-shadow: 0 18px 50px rgba(15, 23, 42, 0.2);
}

.modal-header,
.modal-footer {
    border-color: var(--border);
}

.modal-title {
    color: var(--text);
    font-weight: 700;
}

.modal-body,
.modal-footer,
.modal-header {
    color: var(--text);
}

/* =========================
   CABEÇALHO DE PÁGINA
========================= */

.page-header-custom {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 18px;
    flex-wrap: wrap;
}

.page-header-custom h1 {
    margin: 0;
    font-size: 28px;
    font-weight: 700;
    color: var(--text);
}

/* =========================
   TABLET / MOBILE
========================= */

@media (max-width: 991.98px) {
    .sidebar {
        transform: translateX(-100%);
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        height: 100dvh;
        max-height: 100dvh;
    }

    .sidebar.show {
        transform: translateX(0);
    }

    .sidebar-overlay.show {
        display: block;
    }

    .main-content {
        margin-left: 0;
    }

    .topbar {
        padding: 16px 18px;
    }

    .content-area {
        padding: 18px;
    }

    .page-title {
        font-size: 20px;
    }
}

@media (max-width: 767.98px) {
    .card {
        border-radius: 22px;
    }

    .card-body {
        padding: 1rem;
    }

    .page-header-custom {
        align-items: stretch;
    }

    .page-header-custom .btn {
        width: 100%;
    }

    .table {
        min-width: 760px;
    }

    .actions-nowrap {
        min-width: 230px;
    }

    .modal-footer {
        flex-direction: column;
        gap: 10px;
    }

    .modal-footer form,
    .modal-footer button,
    .modal-footer .btn {
        width: 100%;
    }
}

@media (max-width: 575.98px) {
    .content-area {
        padding: 14px;
    }

    .card {
        border-radius: 22px;
    }

    .table-responsive {
        border-radius: 16px;
        overflow-x: auto;
        overflow-y: hidden;
        -webkit-overflow-scrolling: touch;
    }

    .theme-badge {
        display: none;
    }
}

/* =========================
   FLASH ALERTS
========================= */

.flash-messages {
    display: flex;
    flex-direction: column;
    gap: 14px;
    margin-bottom: 18px;
}

.flash-alert {
    position: relative;
    overflow: hidden;
    border-radius: 18px;
    padding: 16px 48px 16px 18px;
    border: 1px solid var(--border);
    background: var(--surface);
    box-shadow: 
    0 8px 20px rgba(37, 99, 235, 0.15),
    0 2px 6px rgba(37, 99, 235, 0.1);
    animation: flashFadeIn 0.25s ease;
}

.flash-alert-success,
.flash-alert-danger {
    border-left: 5px solid var(--primary);
}

.flash-content {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.flash-title {
    font-size: 15px;
    font-weight: 700;
    color: var(--text);
}

.flash-text {
    font-size: 14px;
    color: var(--text-muted);
    line-height: 1.55;
}

.flash-text ul {
    color: var(--text-muted);
}

.flash-close {
    position: absolute;
    top: 10px;
    right: 12px;
    width: 28px;
    height: 28px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    font-size: 20px;
    line-height: 1;
    cursor: pointer;
    border-radius: 50%;
    transition: all 0.2s ease;
}

.flash-close:hover {
    background: var(--surface-2);
    color: var(--text);
}

.flash-progress {
    position: absolute;
    left: 0;
    bottom: 0;
    height: 4px;
    width: 100%;
    background: var(--primary);
    opacity: 0.7;
    transform-origin: left center;
}

.flash-alert-success .flash-progress,
.flash-alert-danger .flash-progress {
    background: var(--primary);
}

.flash-alert.is-hiding {
    animation: flashFadeOut 0.25s ease forwards;
}

@keyframes flashFadeIn {
    from {
        opacity: 0;
        transform: translateY(-8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes flashFadeOut {
    from {
        opacity: 1;
        transform: translateY(0);
        max-height: 200px;
        margin-bottom: 0;
    }
    to {
        opacity: 0;
        transform: translateY(-8px);
        max-height: 0;
        margin-bottom: -8px;
        padding-top: 0;
        padding-bottom: 0;
    }
}
.table-danger-subtle {
    background: rgba(220, 38, 38, 0.08);
}