/*
 * PontoX — Design System
 * Sidebar layout, modern cards, polished typography
 */

/* =========================================================
   TOKENS
   ========================================================= */
:root {
    --sidebar-width:          240px;
    --sidebar-collapsed-width: 64px;
    --topbar-height:     60px;
    --sidebar-bg:        #0f172a;
    --sidebar-text:      #94a3b8;
    --sidebar-text-hover:#e2e8f0;
    --sidebar-active-bg: rgba(99,102,241,.18);
    --sidebar-active:    #818cf8;
    --sidebar-label:     #475569;
    --topbar-bg:         #ffffff;
    --topbar-border:     #e2e8f0;
    --content-bg:        #f1f5f9;
    --card-bg:           #ffffff;
    --card-border:       #e2e8f0;
    --card-shadow:       0 1px 3px rgba(0,0,0,.06), 0 4px 16px rgba(0,0,0,.04);
    --card-shadow-hover: 0 4px 12px rgba(0,0,0,.10), 0 12px 32px rgba(0,0,0,.06);
    --text-primary:      #0f172a;
    --text-secondary:    #64748b;
    --text-muted:        #94a3b8;
    --radius:            12px;
    --radius-sm:         8px;
    --radius-lg:         16px;
    --transition:        .18s ease;

    /* Bootstrap overrides */
    --bs-body-bg:        #f1f5f9;
    --bs-body-color:     #0f172a;
    --bs-border-radius:  var(--radius);
}

*,*::before,*::after { box-sizing: border-box; }

body {
    font-family: var(--app-font, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif);
    background: var(--content-bg);
    color: var(--text-primary);
    margin: 0;
}

/* =========================================================
   LAYOUT — WRAPPER + SIDEBAR + MAIN
   ========================================================= */
.app-wrapper {
    display: flex;
    min-height: 100vh;
}

/* ── SIDEBAR ─────────────────────────────────────────────── */
.app-sidebar {
    width: var(--sidebar-width);
    background: var(--sidebar-bg);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    position: fixed;
    top: 0; left: 0; bottom: 0;
    z-index: 1040;
    overflow-y: auto;
    overflow-x: hidden;
    transition: width .2s ease, transform var(--transition);
    scrollbar-width: thin;
    scrollbar-color: #1e293b transparent;
}
.app-sidebar::-webkit-scrollbar { width: 4px; }
.app-sidebar::-webkit-scrollbar-track { background: transparent; }
.app-sidebar::-webkit-scrollbar-thumb { background: #1e293b; border-radius: 4px; }

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    height: var(--topbar-height);
    border-bottom: 1px solid rgba(255,255,255,.06);
    flex-shrink: 0;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    text-decoration: none;
    color: #fff;
    font-weight: 700;
    font-size: 16px;
    letter-spacing: -.3px;
}

/* ── Logo compacta: crossfade ao colapsar ─────────────── */
.sidebar-brand-icon-img {
    display: block;
    flex-shrink: 0;
    opacity: 0;
    transform: scale(0.6) rotate(-15deg);
    transition: opacity .3s ease, transform .35s cubic-bezier(.34,1.56,.64,1);
}
.sidebar-brand-full-img {
    display: block;
    overflow: hidden;
    max-width: 140px;
    opacity: 1;
    transition: opacity .2s ease, max-width .3s ease;
}

/* ── Transições dos textos/labels do sidebar ──────────── */
.sidebar-brand-text {
    overflow: hidden;
    max-width: 160px;
    white-space: nowrap;
    opacity: 1;
    transition: opacity .18s ease, max-width .28s ease;
}
.sidebar-user-info {
    overflow: hidden;
    max-width: 140px;
    opacity: 1;
    transition: opacity .18s ease, max-width .28s ease;
}
.sidebar-nav-label {
    overflow: hidden;
    max-height: 32px;
    opacity: 1;
    white-space: nowrap;
    transition: opacity .15s ease, max-height .25s ease, padding .25s ease, margin .25s ease;
}
.sidebar-nav-item > span {
    overflow: hidden;
    max-width: 160px;
    white-space: nowrap;
    opacity: 1;
    transform: translateX(0);
    transition: opacity .18s ease, max-width .25s ease, transform .18s ease;
}
.sidebar-nav-item > .badge {
    overflow: hidden;
    max-width: 60px;
    opacity: 1;
    transform: scale(1);
    transition: opacity .15s ease, max-width .22s ease, transform .15s ease;
}

/* Ícone do botão toggle */
.sb-icon-close { display: none; }
/* Desktop: sidebar aberta (não colapsada) → X; colapsada → hambúrguer */
@media (min-width: 992px) {
    .app-wrapper:not(.sidebar-collapsed) .sb-icon-menu { display: none; }
    .app-wrapper:not(.sidebar-collapsed) .sb-icon-close { display: inline; }
}

/* Estado pré-colapsado (desktop): aplicado via <head> script antes do render */
html.sb-pre-collapsed #appSidebar { width: 64px; }
html.sb-pre-collapsed .app-main   { margin-left: 64px; }
html.sb-pre-collapsed .sidebar-brand-text,
html.sb-pre-collapsed .sidebar-user-info,
html.sb-pre-collapsed .sidebar-nav-label,
html.sb-pre-collapsed .sidebar-nav-item > span,
html.sb-pre-collapsed .sidebar-nav-item > .badge { opacity: 0 !important; max-width: 0 !important; max-height: 0 !important; }
html.sb-pre-collapsed .sidebar-brand-icon-img { opacity: 1 !important; transform: none !important; }
html.sb-pre-collapsed .sidebar-brand-full-img { opacity: 0 !important; max-width: 0 !important; }
/* Suprime TODAS as transições durante restauração inicial */
html.sb-pre-collapsed * { transition: none !important; }
.sidebar-brand-icon {
    font-size: 20px;
    color: #818cf8;
}
.sidebar-brand-text { color: #fff; }

.sidebar-close-btn {
    background: none;
    border: none;
    color: var(--sidebar-text);
    font-size: 18px;
    cursor: pointer;
    padding: 4px;
    line-height: 1;
}

.sidebar-user {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 16px;
    border-bottom: 1px solid rgba(255,255,255,.06);
    flex-shrink: 0;
}
.sidebar-user-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    overflow: hidden;
}
.sidebar-user-avatar img {
    width: 100%; height: 100%;
    object-fit: cover;
}
.sidebar-user-avatar span {
    color: #fff;
    font-size: 14px;
    font-weight: 700;
}
.sidebar-user-info { overflow: hidden; }
.sidebar-user-name {
    color: #e2e8f0;
    font-size: 13px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.sidebar-user-role {
    color: var(--sidebar-text);
    font-size: 11px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-nav {
    flex: 1;
    padding: 12px 8px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.sidebar-nav-label {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: var(--sidebar-label);
    padding: 8px 8px 4px;
}
.sidebar-nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 12px;
    border-radius: var(--radius-sm);
    color: var(--sidebar-text);
    text-decoration: none;
    font-size: 13.5px;
    font-weight: 500;
    transition: background var(--transition), color var(--transition);
    white-space: nowrap;
}
.sidebar-nav-item i { font-size: 15px; flex-shrink: 0; }
.sidebar-nav-item:hover {
    background: rgba(255,255,255,.07);
    color: var(--sidebar-text-hover);
}
.sidebar-nav-item.active {
    background: var(--sidebar-active-bg);
    color: var(--sidebar-active);
    font-weight: 600;
}
.sidebar-nav-item--danger { color: #f87171 !important; }
.sidebar-nav-item--danger:hover { background: rgba(239,68,68,.12) !important; }

.sidebar-footer {
    padding: 8px;
    border-top: 1px solid rgba(255,255,255,.06);
    display: flex;
    flex-direction: column;
    gap: 2px;
    flex-shrink: 0;
}

/* Overlay (mobile) */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.5);
    z-index: 1039;
    backdrop-filter: blur(2px);
}

/* ── MAIN AREA ─────────────────────────────────────────── */
.app-main {
    flex: 1;
    margin-left: var(--sidebar-width);
    min-width: 0;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    transition: margin-left .2s ease;
}

/* ── SIDEBAR COLAPSADA (desktop) ──────────────────────── */
@media (min-width: 992px) {
    .app-wrapper.sidebar-collapsed .app-sidebar {
        width: var(--sidebar-collapsed-width);
    }
    .app-wrapper.sidebar-collapsed .app-main {
        margin-left: var(--sidebar-collapsed-width);
    }

    /* Fade out textos com transição */
    .app-wrapper.sidebar-collapsed .sidebar-brand-text,
    .app-wrapper.sidebar-collapsed .sidebar-user-info { opacity: 0; max-width: 0; }
    .app-wrapper.sidebar-collapsed .sidebar-nav-label  { opacity: 0; max-height: 0; padding: 0; margin: 0; }
    .app-wrapper.sidebar-collapsed .sidebar-nav-item > span  { opacity: 0; max-width: 0; transform: translateX(-6px); }
    .app-wrapper.sidebar-collapsed .sidebar-nav-item > .badge { opacity: 0; max-width: 0; transform: scale(0.5); }

    /* Logo: crossfade full → mini */
    .app-wrapper.sidebar-collapsed .sidebar-brand-icon-img { opacity: 1; transform: scale(1) rotate(0deg); }
    .app-wrapper.sidebar-collapsed .sidebar-brand-full-img { opacity: 0; max-width: 0; }

    /* Centraliza ícones */
    .app-wrapper.sidebar-collapsed .sidebar-brand,
    .app-wrapper.sidebar-collapsed .sidebar-user {
        justify-content: center;
    }
    .app-wrapper.sidebar-collapsed .sidebar-nav-item {
        justify-content: center;
        padding: 10px 0;
    }
    .app-wrapper.sidebar-collapsed .sidebar-nav-item i {
        font-size: 18px;
    }

    /* Tooltip ao hover */
    .app-wrapper.sidebar-collapsed .sidebar-nav-item {
        position: relative;
    }
    .app-wrapper.sidebar-collapsed .sidebar-nav-item::after {
        content: attr(data-label);
        position: absolute;
        left: calc(var(--sidebar-collapsed-width) + 10px);
        top: 50%;
        transform: translateY(-50%);
        background: #1e293b;
        color: #e2e8f0;
        padding: 5px 12px;
        border-radius: 6px;
        font-size: 12px;
        font-weight: 500;
        white-space: nowrap;
        pointer-events: none;
        z-index: 1060;
        box-shadow: 0 4px 16px rgba(0,0,0,.25);
        opacity: 0;
        transition: opacity .15s ease;
    }
    .app-wrapper.sidebar-collapsed .sidebar-nav-item:hover::after {
        opacity: 1;
    }
}

/* ── TOP BAR ────────────────────────────────────────────── */
.app-topbar {
    height: var(--topbar-height);
    background: var(--topbar-bg);
    border-bottom: 1px solid var(--topbar-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    position: sticky;
    top: 0;
    z-index: 1030;
    flex-shrink: 0;
}
.topbar-left { display: flex; align-items: center; gap: 12px; }
.topbar-toggle {
    background: none;
    border: none;
    font-size: 22px;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 4px 6px;
    border-radius: var(--radius-sm);
    transition: background var(--transition);
}
.topbar-toggle:hover { background: #f1f5f9; }
.topbar-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0;
}
.topbar-right { display: flex; align-items: center; gap: 8px; }

.topbar-icon-btn {
    width: 36px; height: 36px;
    background: none;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 18px;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background var(--transition);
}
.topbar-icon-btn:hover { background: #f1f5f9; color: var(--text-primary); }

.topbar-user-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: var(--radius-sm);
    transition: background var(--transition);
}
.topbar-user-btn:hover { background: #f1f5f9; }
.topbar-avatar {
    width: 32px; height: 32px;
    border-radius: 50%;
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    flex-shrink: 0;
}
.topbar-avatar img { width: 100%; height: 100%; object-fit: cover; }
.topbar-avatar span { color: #fff; font-size: 12px; font-weight: 700; }
.topbar-user-name { font-size: 13.5px; font-weight: 500; color: var(--text-primary); }
.topbar-chevron { font-size: 11px; color: var(--text-muted); }

/* ── CONTENT ─────────────────────────────────────────────── */
.app-content {
    flex: 1;
    padding: 28px 24px;
}

/* =========================================================
   MOBILE RESPONSIVE
   ========================================================= */
@media (max-width: 991.98px) {
    .app-sidebar {
        transform: translateX(-100%);
    }
    .app-main {
        margin-left: 0;
    }
    .app-wrapper.sidebar-open .app-sidebar {
        transform: translateX(0);
        box-shadow: 4px 0 40px rgba(0,0,0,.3);
    }
    .app-wrapper.sidebar-open .sidebar-overlay {
        display: block;
    }
}

/* =========================================================
   CARDS
   ========================================================= */
.card {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: var(--radius);
    box-shadow: var(--card-shadow);
    transition: box-shadow var(--transition);
}
.card:hover { box-shadow: var(--card-shadow-hover); }
.card-header {
    background: var(--card-bg);
    border-bottom: 1px solid var(--card-border);
    padding: 16px 20px;
    font-weight: 600;
}
.card-body { padding: 20px; }
.card-footer {
    background: var(--card-bg);
    border-top: 1px solid var(--card-border);
    padding: 12px 20px;
}

/* Stat cards */
.stat-card {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 20px;
}
.stat-icon {
    width: 52px; height: 52px;
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    flex-shrink: 0;
}
.stat-icon--blue    { background: #eff6ff; color: #2563eb; }
.stat-icon--green   { background: #f0fdf4; color: #16a34a; }
.stat-icon--amber   { background: #fffbeb; color: #d97706; }
.stat-icon--purple  { background: #faf5ff; color: #9333ea; }
.stat-icon--red     { background: #fef2f2; color: #dc2626; }
.stat-icon--indigo  { background: #eef2ff; color: #4f46e5; }
.stat-value {
    font-size: 26px;
    font-weight: 800;
    color: var(--text-primary);
    line-height: 1;
    margin-bottom: 4px;
}
.stat-label { font-size: 12.5px; color: var(--text-secondary); }

/* =========================================================
   PAGE HEADER
   ========================================================= */
.page-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 24px;
    flex-wrap: wrap;
}
.page-header-info h4 {
    font-size: 20px;
    font-weight: 700;
    color: var(--text-primary);
    margin: 0 0 2px;
}
.page-header-info p {
    font-size: 13.5px;
    color: var(--text-secondary);
    margin: 0;
}
.page-header-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* =========================================================
   TABLES
   ========================================================= */
.table {
    --bs-table-hover-bg: #f8fafc;
    font-size: 13.5px;
}
.table th {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: var(--text-secondary);
    border-bottom-color: var(--card-border);
    padding: 10px 16px;
}
.table td { padding: 12px 16px; vertical-align: middle; }
.table-light th { background: #f8fafc; color: var(--text-secondary); }

/* =========================================================
   FORMS
   ========================================================= */
.form-label { font-size: 13px; font-weight: 600; color: var(--text-secondary); margin-bottom: 6px; }
.form-control, .form-select {
    border-color: var(--card-border);
    border-radius: var(--radius-sm);
    font-size: 14px;
    padding: 9px 13px;
    color: var(--text-primary);
    transition: border-color var(--transition), box-shadow var(--transition);
}
.form-control:focus, .form-select:focus {
    border-color: var(--app-primary, #2563eb);
    box-shadow: 0 0 0 3px rgba(37,99,235,.12);
}
textarea.form-control { min-height: 100px; }

/* =========================================================
   BUTTONS
   ========================================================= */
.btn {
    font-size: 13.5px;
    font-weight: 500;
    border-radius: var(--radius-sm);
    padding: 8px 16px;
    transition: all var(--transition);
}
.btn-primary {
    background: var(--app-primary, #2563eb);
    border-color: var(--app-primary, #2563eb);
    color: #fff;
}
.btn-primary:hover { filter: brightness(0.9); }
.btn-sm { padding: 5px 11px; font-size: 12.5px; }
.btn-lg { padding: 11px 22px; font-size: 15px; }
.btn-icon { width: 34px; height: 34px; padding: 0; display: inline-flex; align-items: center; justify-content: center; }

/* =========================================================
   BADGES
   ========================================================= */
.badge { font-size: 11px; font-weight: 600; padding: 4px 9px; }
.badge-ativo    { background: #dcfce7; color: #166534; }
.badge-inativo  { background: #fee2e2; color: #991b1b; }
.badge-pendente { background: #fef9c3; color: #854d0e; }
.badge-bloqueado{ background: #fee2e2; color: #991b1b; }

/* =========================================================
   ALERTS / FLASH
   ========================================================= */
.alert {
    border: none;
    border-radius: var(--radius-sm);
    font-size: 13.5px;
    padding: 12px 16px;
    margin-bottom: 20px;
}
.alert-success { background: #f0fdf4; color: #166534; border-left: 3px solid #22c55e; }
.alert-danger   { background: #fef2f2; color: #991b1b; border-left: 3px solid #ef4444; }
.alert-warning  { background: #fffbeb; color: #854d0e; border-left: 3px solid #f59e0b; }
.alert-info     { background: #eff6ff; color: #1e40af; border-left: 3px solid #3b82f6; }

/* =========================================================
   DROPDOWNS
   ========================================================= */
.dropdown-menu {
    border: 1px solid var(--card-border);
    border-radius: var(--radius);
    box-shadow: 0 8px 32px rgba(0,0,0,.12);
    font-size: 13.5px;
    padding: 6px;
}
.dropdown-item {
    border-radius: var(--radius-sm);
    padding: 8px 12px;
    color: var(--text-primary);
}
.dropdown-item:hover { background: #f1f5f9; }
.dropdown-item.active, .dropdown-item:active { background: #eff6ff; color: #2563eb; }
.dropdown-divider { margin: 4px 0; border-color: var(--card-border); }

/* Notification items */
.notif-item { border-left: 3px solid transparent; transition: background var(--transition); }
.notif-item:hover { background: #f8fafc; }
.notif-item.unread { border-left-color: #2563eb; background: #eff6ff; }
.notif-item.unread:hover { background: #dbeafe; }
.notif-time { font-size: 11px; color: var(--text-muted); }

/* =========================================================
   TOAST
   ========================================================= */
#toastContainer {
    position: fixed;
    top: 16px; right: 16px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.toast-app {
    min-width: 300px; max-width: 400px;
    padding: 14px 16px;
    border-radius: 14px;
    color: #fff;
    font-size: 13.5px;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 10px;
    box-shadow: 0 8px 32px rgba(0,0,0,.18);
    animation: toastIn .25s cubic-bezier(.34,1.56,.64,1);
}
@keyframes toastIn { from{opacity:0;transform:translateX(48px) scale(.95)} to{opacity:1;transform:translateX(0) scale(1)} }
.toast-success { background: linear-gradient(135deg, #16a34a, #15803d); }
.toast-danger  { background: linear-gradient(135deg, #dc2626, #b91c1c); }
.toast-warning { background: linear-gradient(135deg, #d97706, #b45309); }
.toast-info    { background: linear-gradient(135deg, #2563eb, #1d4ed8); }

/* =========================================================
   AUTH / GUEST LAYOUT
   ========================================================= */
.auth-page {
    min-height: 100vh;
    background: linear-gradient(135deg, #0f172a 0%, #1e3a8a 60%, #1d4ed8 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}
.auth-card {
    background: #fff;
    border-radius: var(--radius-lg);
    box-shadow: 0 24px 64px rgba(0,0,0,.3);
    width: 100%;
    max-width: 420px;
    padding: 40px;
}
.auth-logo {
    text-align: center;
    margin-bottom: 28px;
}
.auth-logo-icon {
    width: 56px; height: 56px;
    background: linear-gradient(135deg, #2563eb, #7c3aed);
    border-radius: 16px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 26px;
    color: #fff;
    margin-bottom: 12px;
}
.auth-title { font-size: 22px; font-weight: 800; color: var(--text-primary); margin: 0 0 4px; }
.auth-subtitle { font-size: 13.5px; color: var(--text-secondary); }

/* =========================================================
   MISC UTILITIES
   ========================================================= */
.section-title { font-size: 14px; font-weight: 700; color: var(--text-primary); margin-bottom: 16px; }
.text-body-secondary { color: var(--text-secondary) !important; }
.rounded-card { border-radius: var(--radius) !important; }
.shadow-card { box-shadow: var(--card-shadow) !important; }

/* Bootstrap overrides for consistency */
.text-primary { color: var(--app-primary, #2563eb) !important; }
.bg-primary   { background-color: var(--app-primary, #2563eb) !important; }
.btn-primary, .btn-primary:focus { background-color: var(--app-primary, #2563eb) !important; border-color: var(--app-primary, #2563eb) !important; }
.border-primary { border-color: var(--app-primary, #2563eb) !important; }
.link-primary { color: var(--app-primary, #2563eb) !important; }

/* =====================================================
   RODAPÉ MPX SOFTWARE
   ===================================================== */
.mpx-footer {
    background: #0f172a;
    border-top: 1px solid rgba(255,255,255,.07);
    padding: 10px 0;
    text-align: center;
    font-size: .78rem;
    color: rgba(255,255,255,.55);
}
.mpx-footer-inner {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    justify-content: center;
}
.mpx-footer-logo {
    height: 22px;
    width: auto;
    opacity: .85;
    filter: brightness(0) invert(1);
}
.mpx-footer-text { color: rgba(255,255,255,.5); }
.mpx-footer-text strong { color: rgba(255,255,255,.75); font-weight: 600; }
.mpx-footer-text em { font-style: normal; color: rgba(255,255,255,.4); }
