/* ============================================================
   FinOps CRM - App Layout
   Sidebar + Header + Content
   ============================================================ */

/* ---------- IMPERSONATION BAR ---------- */
.impersonation-bar {
    background: var(--danger);
    color: white;
    text-align: center;
    padding: 8px 16px;
    font-size: 0.85rem;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 6000;
}

/* ---------- SIDEBAR ---------- */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: var(--sidebar-width);
    background: var(--gray-900);
    color: white;
    z-index: 4000;
    display: flex;
    flex-direction: column;
    transition: transform 0.25s ease;
    overflow: hidden;
}

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 18px;
    border-bottom: 1px solid rgba(255,255,255,0.08);
}

.sidebar-logo {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 1.15rem;
    font-weight: 700;
    color: white;
}

.sidebar-logo i {
    color: var(--primary-light);
    font-size: 1.3rem;
}

.sidebar-close {
    display: none;
    background: none;
    border: none;
    color: var(--gray-400);
    font-size: 1.2rem;
    cursor: pointer;
    padding: 4px;
}

.sidebar-close:hover { color: white; }

/* Sidebar User */
.sidebar-user {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 18px;
    border-bottom: 1px solid rgba(255,255,255,0.08);
}

.sidebar-user-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--primary);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.9rem;
    flex-shrink: 0;
}

.sidebar-user-info { min-width: 0; }

.sidebar-user-name {
    font-size: 0.85rem;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-user-role {
    margin-top: 2px;
}

.sidebar-user-role .badge {
    font-size: 0.65rem;
    padding: 1px 6px;
}

/* Sidebar Navigation */
.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: 8px 0;
}

.sidebar-nav::-webkit-scrollbar { width: 4px; }
.sidebar-nav::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 2px; }

.nav-section-label {
    padding: 14px 18px 6px;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--gray-500);
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 18px;
    font-size: 0.875rem;
    color: var(--gray-400);
    text-decoration: none;
    transition: all 0.15s;
    cursor: pointer;
    border-left: 3px solid transparent;
}

.nav-item:hover {
    color: white;
    background: rgba(255,255,255,0.05);
    text-decoration: none;
}

.nav-item.active {
    color: white;
    background: rgba(59,130,246,0.15);
    border-left-color: var(--primary-light);
}

.nav-item i {
    width: 20px;
    text-align: center;
    font-size: 0.9rem;
    flex-shrink: 0;
}

.nav-badge {
    margin-left: auto;
    background: var(--primary);
    color: white;
    font-size: 0.7rem;
    padding: 1px 6px;
    border-radius: 10px;
    font-weight: 600;
    min-width: 20px;
    text-align: center;
}

.nav-badge-warning {
    background: var(--warning);
    color: #000;
}

.nav-badge:empty { display: none; }

/* Sidebar Footer */
.sidebar-footer {
    border-top: 1px solid rgba(255,255,255,0.08);
    padding: 4px 0;
}

.nav-logout:hover {
    color: var(--danger) !important;
    background: rgba(239,68,68,0.1);
}

/* ---------- MAIN WRAPPER ---------- */
.main-wrapper {
    margin-left: var(--sidebar-width);
    min-height: 100vh;
    transition: margin-left 0.25s ease;
}

/* ---------- HEADER ---------- */
.app-header {
    position: sticky;
    top: 0;
    z-index: 3000;
    background: var(--white);
    border-bottom: 1px solid var(--border-color);
    padding: 0 24px;
    height: var(--header-height);
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: var(--shadow-sm);
}

.header-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.hamburger {
    display: none;
    background: none;
    border: none;
    font-size: 1.2rem;
    color: var(--gray-600);
    cursor: pointer;
    padding: 6px;
}

.hamburger:hover { color: var(--gray-800); }

.page-title {
    font-size: 1.15rem;
    font-weight: 600;
    color: var(--gray-800);
}

.header-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

/* Header Search */
.header-search {
    position: relative;
    display: flex;
    align-items: center;
}

.header-search i {
    position: absolute;
    left: 10px;
    color: var(--gray-400);
    font-size: 0.85rem;
}

.header-search input {
    padding: 7px 12px 7px 32px;
    border: 1px solid var(--gray-200);
    border-radius: 20px;
    font-size: 0.85rem;
    width: 220px;
    background: var(--gray-50);
    transition: var(--transition);
    font-family: inherit;
}

.header-search input:focus {
    outline: none;
    width: 280px;
    border-color: var(--primary-500);
    background: white;
    box-shadow: 0 0 0 3px rgba(59,130,246,0.1);
}

/* Header Icon Button */
.header-icon-btn {
    position: relative;
    background: none;
    border: none;
    font-size: 1.1rem;
    color: var(--gray-500);
    cursor: pointer;
    padding: 6px;
    border-radius: 50%;
    transition: var(--transition);
}

.header-icon-btn:hover {
    background: var(--gray-100);
    color: var(--gray-700);
}

.notif-dot {
    position: absolute;
    top: 2px;
    right: 2px;
    width: 8px;
    height: 8px;
    background: var(--danger);
    border-radius: 50%;
    border: 2px solid white;
}

/* Header User Menu */
.header-user-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    background: none;
    border: 1px solid var(--gray-200);
    border-radius: 24px;
    padding: 4px 12px 4px 4px;
    cursor: pointer;
    transition: var(--transition);
    font-family: inherit;
}

.header-user-btn:hover {
    background: var(--gray-50);
    border-color: var(--gray-300);
}

.header-user-avatar {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: var(--primary);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.8rem;
}

.header-user-name {
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--gray-700);
}

.header-user-menu {
    position: relative;
}

.user-dropdown {
    position: absolute;
    right: 0;
    top: calc(100% + 8px);
    background: white;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    min-width: 200px;
    z-index: 3100;
    overflow: hidden;
}

.user-dropdown-header {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-color);
    background: var(--gray-50);
}

.user-dropdown-header strong {
    display: block;
    font-size: 0.875rem;
}

.user-dropdown-header span {
    font-size: 0.78rem;
    color: var(--text-muted);
}

.user-dropdown a {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 16px;
    font-size: 0.85rem;
    color: var(--gray-700);
    text-decoration: none;
    transition: background 0.15s;
}

.user-dropdown a:hover {
    background: var(--gray-50);
    text-decoration: none;
}

/* ---------- NOTIFICATIONS PANEL ---------- */
.notif-panel {
    position: fixed;
    top: var(--header-height);
    right: 20px;
    width: 360px;
    max-height: 70vh;
    background: white;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    z-index: 3200;
    overflow: hidden;
}

.notif-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border-color);
    background: var(--gray-50);
}

.notif-panel-header h4 {
    font-size: 0.95rem;
    display: flex;
    align-items: center;
    gap: 6px;
}

.notif-panel-body {
    overflow-y: auto;
    max-height: 60vh;
}

.notif-item {
    display: flex;
    gap: 10px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--gray-100);
    cursor: pointer;
    transition: background 0.15s;
}

.notif-item:hover { background: var(--primary-50); }

.notif-item .notif-icon {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    flex-shrink: 0;
}

.notif-icon.overdue { background: var(--danger-bg); color: var(--danger); }
.notif-icon.today   { background: var(--warning-bg); color: var(--warning); }
.notif-icon.upcoming { background: var(--info-bg); color: var(--info); }

.notif-info { min-width: 0; flex: 1; }
.notif-info strong { font-size: 0.85rem; display: block; }
.notif-info small { font-size: 0.78rem; color: var(--text-muted); }

/* ---------- MAIN CONTENT ---------- */
.main-content {
    padding: 24px;
    min-height: calc(100vh - var(--header-height));
}

/* Content Loading */
.content-loading {
    display: none;
    justify-content: center;
    align-items: center;
    gap: 10px;
    padding: 60px 0;
    color: var(--text-muted);
    font-size: 0.9rem;
}

.content-loading.show { display: flex; }

.loading-spinner {
    width: 24px;
    height: 24px;
    border: 3px solid var(--gray-200);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}

/* ---------- STAT CARDS ---------- */
.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.stat-card {
    background: var(--white);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 18px 20px;
    display: flex;
    align-items: center;
    gap: 14px;
    transition: var(--transition);
    cursor: default;
}

.stat-card:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-1px);
}

.stat-card-icon {
    width: 46px;
    height: 46px;
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    flex-shrink: 0;
}

.stat-card-icon.blue    { background: var(--primary-100); color: var(--primary-700); }
.stat-card-icon.green   { background: #d1fae5; color: #065f46; }
.stat-card-icon.yellow  { background: #fef3c7; color: #92400e; }
.stat-card-icon.red     { background: #fee2e2; color: #991b1b; }
.stat-card-icon.purple  { background: #ede9fe; color: #5b21b6; }
.stat-card-icon.cyan    { background: #cffafe; color: #155e75; }

.stat-card-data h3 {
    font-size: 1.5rem;
    font-weight: 700;
    line-height: 1.2;
    color: var(--gray-800);
}

.stat-card-data p {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-top: 2px;
}

/* ---------- TOOLBAR (above tables) ---------- */
.content-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 16px;
}

.toolbar-left {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.toolbar-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

.toolbar-search {
    position: relative;
}

.toolbar-search i {
    position: absolute;
    left: 10px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--gray-400);
    font-size: 0.8rem;
}

.toolbar-search input {
    padding: 7px 12px 7px 30px;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius);
    font-size: 0.85rem;
    width: 200px;
    font-family: inherit;
}

.toolbar-search input:focus {
    outline: none;
    border-color: var(--primary-500);
    box-shadow: 0 0 0 3px rgba(59,130,246,0.1);
}

/* ---------- WHATSAPP BUTTON ---------- */
.btn-whatsapp {
    background: #25d366;
    color: white;
    border: none;
}

.btn-whatsapp:hover { background: #1fb855; }

/* ---------- EMPTY STATE ---------- */
.empty-state {
    text-align: center;
    padding: 48px 20px;
    color: var(--text-muted);
}

.empty-state i {
    font-size: 3rem;
    margin-bottom: 12px;
    color: var(--gray-300);
}

.empty-state h3 {
    color: var(--gray-500);
    font-size: 1.1rem;
    margin-bottom: 6px;
}

.empty-state p {
    font-size: 0.875rem;
}

/* ---------- RESPONSIVE ---------- */
@media (max-width: 992px) {
    .sidebar {
        transform: translateX(-100%);
    }

    .sidebar.open {
        transform: translateX(0);
        box-shadow: 4px 0 20px rgba(0,0,0,0.3);
    }

    .sidebar-close { display: block; }
    .hamburger { display: block; }

    .main-wrapper {
        margin-left: 0;
    }

    .header-search input { width: 160px; }
    .header-search input:focus { width: 200px; }
    .header-user-name { display: none; }
}

@media (max-width: 768px) {
    .app-header { padding: 0 14px; }
    .main-content { padding: 16px; }
    .stat-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
    .stat-card { padding: 14px; gap: 10px; }
    .stat-card-icon { width: 38px; height: 38px; font-size: 1rem; }
    .stat-card-data h3 { font-size: 1.2rem; }

    .content-toolbar { flex-direction: column; align-items: stretch; }
    .toolbar-search input { width: 100%; }

    .notif-panel { left: 10px; right: 10px; width: auto; }
}

@media (max-width: 480px) {
    .stat-grid { grid-template-columns: repeat(2, 1fr); }
    .header-search { display: none; }
    .page-title { font-size: 1rem; }
}
