/* ==========================================================================
   PHALANTIS ENTERPRISE CLOUD ERP — SHELL & LAYOUT ARCHITECTURE
   ========================================================================== */

/* Main Application Shell */
.app-container {
    display: flex;
    height: 100vh;
    width: 100vw;
    overflow: hidden;
    background-color: var(--bg-base);
}

/* ==========================================================================
   SIDEBAR NAVIGATION (JD Edwards / SAP Fiori Launchpad Sidebar)
   ========================================================================== */
.sidebar {
    width: 250px;
    background-color: var(--bg-surface);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    transition: width 0.22s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 100;
    flex-shrink: 0;
    user-select: none;
    overflow-x: hidden !important;
}

/* Sidebar Brand Header */
.sidebar-header {
    height: 64px;
    display: flex;
    align-items: center;
    padding: 0 20px;
    border-bottom: 1px solid var(--border-color);
    gap: 12px;
    flex-shrink: 0;
    overflow: hidden;
}

.brand-emblem {
    width: 36px;
    height: 36px;
    background: linear-gradient(135deg, #0F62FE 0%, #0043CE 100%);
    border-radius: var(--border-radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #FFFFFF;
    box-shadow: 0 0 12px rgba(15, 98, 254, 0.4);
    flex-shrink: 0;
}

.brand-emblem svg {
    width: 20px;
    height: 20px;
    stroke-width: 2.2;
}

.brand-meta {
    display: flex;
    align-items: center;
    overflow: hidden;
    white-space: nowrap;
}

.brand-title {
    font-size: 1.2rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    color: var(--text-primary);
    margin: 0;
    line-height: 1;
}

/* Navigation List & Categorization */
.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden !important;
    padding: 16px 10px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    scrollbar-width: thin;
}

.nav-category {
    font-size: 0.7rem;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    padding: 16px 12px 6px 12px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.nav-category:first-of-type {
    padding-top: 4px;
}

.nav-item {
    display: flex;
    align-items: center;
    padding: 10px 14px;
    color: var(--text-secondary);
    font-size: 0.9rem;
    font-weight: 500;
    border-radius: var(--border-radius-sm);
    position: relative;
    transition: all 0.15s ease;
    text-decoration: none;
    gap: 12px;
    white-space: nowrap;
    overflow: hidden;
}

.nav-item svg {
    width: 19px;
    height: 19px;
    color: var(--text-muted);
    transition: color 0.15s ease;
    flex-shrink: 0;
}

.nav-item:hover {
    background-color: var(--bg-surface-hover);
    color: var(--text-primary);
}

.nav-item:hover svg {
    color: var(--color-primary-light);
}

.nav-item.active {
    background: linear-gradient(90deg, rgba(15, 98, 254, 0.18) 0%, rgba(15, 98, 254, 0.04) 100%);
    color: var(--text-primary);
    font-weight: 600;
}

.nav-item.active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 6px;
    bottom: 6px;
    width: 3.5px;
    background: var(--color-primary);
    border-radius: 0 3px 3px 0;
    box-shadow: 0 0 8px var(--color-primary);
}

.nav-item.active svg {
    color: var(--color-primary-light);
}

/* Sidebar Footer & User Profile */
.sidebar-footer {
    height: 64px;
    padding: 0 16px;
    border-top: 1px solid var(--border-color);
    background-color: var(--bg-surface-elevated);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    flex-shrink: 0;
    overflow: hidden;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 10px;
    overflow: hidden;
}

.user-info .avatar {
    width: 34px;
    height: 34px;
    border-radius: var(--border-radius-sm);
    background: #1E293B;
    border: 1px solid rgba(255, 255, 255, 0.12);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #94A3B8;
    flex-shrink: 0;
}

.user-info .avatar svg {
    width: 17px;
    height: 17px;
}

.user-info .details {
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.user-info .details #current-user-name {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-info .details #current-user-role {
    font-size: 0.72rem;
    color: var(--text-muted);
    text-transform: capitalize;
}

/* ==========================================================================
   SIDEBAR COLLAPSED (DESKTOP STATE) - CLEAN, NO OVERFLOW, NO SCROLLBARS
   ========================================================================== */
.sidebar.collapsed {
    width: 68px !important;
    min-width: 68px !important;
    max-width: 68px !important;
    overflow-x: hidden !important;
}

.sidebar.collapsed .brand-meta {
    display: none !important;
}

.sidebar.collapsed .sidebar-header {
    justify-content: center !important;
    padding: 0 !important;
}

.sidebar.collapsed .nav-category {
    display: none !important;
}

.sidebar.collapsed .sidebar-nav {
    padding: 16px 6px !important;
    overflow-x: hidden !important;
}

.sidebar.collapsed .nav-item {
    justify-content: center !important;
    padding: 12px 0 !important;
    width: 100% !important;
    border-radius: var(--border-radius-sm) !important;
    gap: 0 !important;
}

.sidebar.collapsed .nav-item span {
    display: none !important;
}

.sidebar.collapsed .nav-item svg {
    margin: 0 auto !important;
    width: 22px !important;
    height: 22px !important;
}

.sidebar.collapsed .sidebar-footer {
    flex-direction: column !important;
    justify-content: center !important;
    align-items: center !important;
    padding: 14px 0 !important;
    height: auto !important;
    gap: 12px !important;
    width: 100% !important;
}

.sidebar.collapsed .user-info {
    margin: 0 !important;
    justify-content: center !important;
}

.sidebar.collapsed .user-info .details {
    display: none !important;
}

.sidebar.collapsed .user-info .avatar {
    margin: 0 auto !important;
}

.sidebar.collapsed #btn-logout {
    margin: 0 auto !important;
}

/* ==========================================================================
   MAIN CONTENT & TOPBAR (Enterprise Shell Bar)
   ========================================================================== */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    background-color: var(--bg-base);
    overflow: hidden;
    min-width: 0;
}

.topbar {
    height: 64px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 28px;
    background-color: var(--bg-surface);
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
    z-index: 50;
    gap: 20px;
}

.topbar-left {
    display: flex;
    align-items: center;
    gap: 18px;
    flex-shrink: 0;
}

.sidebar-toggle-btn {
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    background: var(--bg-surface-hover);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-sm);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.15s ease;
    flex-shrink: 0;
}

.sidebar-toggle-btn:hover {
    background: var(--color-primary-subtle);
    color: var(--color-primary);
    border-color: var(--color-primary);
}

.breadcrumb {
    display: flex;
    align-items: center;
}

.header-tenant-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 0.78rem;
    font-weight: 500;
    color: var(--text-secondary);
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border-color);
    padding: 4px 10px;
    border-radius: var(--border-radius-sm);
    margin-left: 14px;
    transition: all 0.2s ease;
    white-space: nowrap;
}

body.theme-light .header-tenant-badge {
    background: #F1F5F9;
    border-color: #CBD5E1;
    color: #334155;
}

.breadcrumb h1, #page-title {
    margin: 0;
    font-size: 1.35rem;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.01em;
    line-height: 1;
    white-space: nowrap;
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

/* Theme Switcher Button */
.theme-toggle-btn {
    width: 38px;
    height: 38px;
    border-radius: var(--border-radius-sm);
    border: 1px solid var(--border-color);
    background: var(--bg-surface-hover);
    color: var(--text-secondary);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.theme-toggle-btn:hover {
    background: var(--color-primary-subtle);
    color: var(--color-primary);
    border-color: var(--color-primary);
}

.theme-toggle-btn svg {
    width: 18px;
    height: 18px;
    transition: transform 0.25s ease;
}

.theme-toggle-btn:hover svg {
    transform: rotate(25deg);
}

.time-display {
    color: var(--text-secondary);
    font-family: var(--font-mono);
    font-size: 0.82rem;
    font-weight: 500;
    padding: 6px 14px;
    background: var(--bg-base);
    border-radius: var(--border-radius-sm);
    border: 1px solid var(--border-color);
    white-space: nowrap;
}

/* Page Workspace */
.page-container {
    flex: 1;
    padding: 28px 32px;
    overflow-y: auto;
    position: relative;
}

.page {
    display: none;
    animation: fadeIn 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.page.active {
    display: block;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ==========================================================================
   ENTERPRISE LOGIN OVERLAY (SAP / JD Edwards SaaS Single Sign-On Portal)
   ========================================================================== */
.login-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: radial-gradient(circle at 50% 25%, #10192A 0%, #06090E 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 20px;
}

.login-card {
    width: 100%;
    max-width: 440px;
    padding: 38px 36px 32px 36px;
    border-radius: var(--border-radius-lg);
    background: rgba(14, 20, 32, 0.92);
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.8), 0 0 0 1px rgba(15, 98, 254, 0.15);
    position: relative;
    overflow: hidden;
}

.login-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: linear-gradient(90deg, #0F62FE, #00D2FF, #0F62FE);
}

.login-logo {
    text-align: center;
    margin-bottom: 28px;
}

.login-emblem-wrap {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 52px;
    height: 52px;
    background: linear-gradient(135deg, #0F62FE 0%, #0043CE 100%);
    border-radius: var(--border-radius-md);
    color: #FFFFFF;
    margin-bottom: 14px;
    box-shadow: 0 0 25px rgba(15, 98, 254, 0.5);
}

.login-emblem-wrap svg {
    width: 28px;
    height: 28px;
    stroke-width: 2.2;
}

.login-logo h2 {
    font-size: 1.45rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    color: #FFFFFF;
    margin: 0;
    text-transform: uppercase;
}

.login-subtitle {
    font-size: 0.76rem;
    font-weight: 500;
    color: var(--text-muted);
    letter-spacing: 0.05em;
    margin-top: 4px;
}

.login-footer-security {
    margin-top: 24px;
    padding-top: 16px;
    border-top: 1px solid var(--border-color);
    text-align: center;
    font-size: 0.72rem;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    flex-wrap: wrap;
}

/* Alertas de Login y Seguridad */
.login-alert {
    padding: 12px 14px;
    border-radius: var(--border-radius-sm);
    font-size: 0.82rem;
    line-height: 1.45;
    margin-bottom: 18px;
    display: flex;
    align-items: flex-start;
    gap: 10px;
    background: rgba(218, 30, 40, 0.15);
    border: 1px solid rgba(218, 30, 40, 0.4);
    color: #FF8389;
    animation: fadeIn 0.25s ease-out;
}
.login-alert.warning {
    background: rgba(241, 194, 27, 0.15);
    border-color: rgba(241, 194, 27, 0.4);
    color: #F1C21B;
}
.login-alert.info {
    background: rgba(15, 98, 254, 0.15);
    border-color: rgba(15, 98, 254, 0.4);
    color: #78A9FF;
}

/* 2FA Step Components */
.step-2fa-header {
    text-align: center;
    margin-bottom: 18px;
}
.step-2fa-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 46px;
    height: 46px;
    border-radius: 50%;
    background: rgba(15, 98, 254, 0.15);
    color: #4589FF;
    border: 1px solid rgba(15, 98, 254, 0.35);
    margin-bottom: 10px;
}
.step-2fa-badge svg {
    width: 22px;
    height: 22px;
}
.step-2fa-header h4 {
    margin: 0 0 6px 0;
    font-size: 1.05rem;
    font-weight: 600;
    color: var(--text-main);
}
.step-2fa-desc {
    margin: 0;
    font-size: 0.78rem;
    color: var(--text-muted);
    line-height: 1.45;
}

.input-2fa-code {
    text-align: center;
    font-size: 1.55rem;
    font-weight: 700;
    letter-spacing: 0.25em;
    font-family: var(--font-mono, monospace);
    height: 52px;
    background: rgba(0, 0, 0, 0.3) !important;
    border: 1.5px solid var(--accent-blue) !important;
    box-shadow: 0 0 15px rgba(15, 98, 254, 0.2);
}

.btn-link-subtle {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 0.78rem;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: color 0.2s;
    padding: 6px 10px;
    border-radius: 4px;
}
.btn-link-subtle:hover {
    color: var(--text-main);
    background: rgba(255, 255, 255, 0.05);
}

.device-tag {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 0.68rem;
    color: var(--text-muted);
    background: rgba(255, 255, 255, 0.05);
    padding: 3px 8px;
    border-radius: 4px;
    border: 1px solid rgba(255, 255, 255, 0.08);
}
.security-status {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 0.7rem;
    color: var(--text-muted);
}


/* ==========================================================================
   LIGHT THEME OVERRIDES FOR SHELL & LOGIN (SAP FIORI / JD EDWARDS CLOUD)
   ========================================================================== */
body.theme-light .nav-item {
    color: #475569;
}

body.theme-light .nav-item:hover {
    background-color: #F1F5F9;
    color: #0F172A;
}

body.theme-light .nav-item:hover svg {
    color: var(--color-primary);
}

body.theme-light .nav-item.active {
    background: rgba(0, 102, 224, 0.08);
    color: var(--color-primary);
    font-weight: 600;
}

body.theme-light .nav-item.active svg {
    color: var(--color-primary);
}

body.theme-light .nav-item.active::before {
    background: var(--color-primary);
    box-shadow: 0 0 6px rgba(0, 102, 224, 0.4);
}

body.theme-light .sidebar-footer {
    background-color: #F8FAFC;
    border-top: 1px solid var(--border-color);
}

body.theme-light .user-info .avatar {
    background: #F1F5F9;
    border: 1px solid var(--border-color);
    color: #475569;
}

body.theme-light .time-display {
    background: #F1F5F9;
    color: #475569;
    border-color: var(--border-color);
}

body.theme-light .login-overlay {
    background: radial-gradient(circle at 50% 25%, #EDF2F7 0%, #CBD5E1 100%);
}

body.theme-light .login-card {
    background: #FFFFFF;
    border: 1px solid #E2E8F0;
    box-shadow: 0 20px 45px rgba(0, 0, 0, 0.08);
}

body.theme-light .login-card h2 {
    color: #0F172A;
}

body.theme-light .login-footer-security {
    border-top: 1px solid #E2E8F0;
    color: #64748B;
}

