/* 
    Egypt Innovation Bank (EIB) - Global Styles 
    Theme Engine implementation using CSS Variables
*/

:root {
    /* Light Theme - Default (logo1.png) */
    --bg-color: #f8fafc;
    --card-bg: #ffffff;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --accent: #3b82f6;
    --border-color: #e2e8f0;
    --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --nav-bg: #ffffff;
    --nav-text: #1e293b;
    --input-bg: #ffffff;
    --input-border: #cbd5e1;
}

[data-theme="dark"] {
    /* Dark Theme (logo2.png) */
    --bg-color: #0f172a;
    --card-bg: #1e293b;
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --primary: #38bdf8;
    --primary-hover: #0ea5e9;
    --accent: #0284c7;
    --border-color: #334155;
    --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.3), 0 2px 4px -2px rgb(0 0 0 / 0.3);
    --nav-bg: #1e293b;
    --nav-text: #f8fafc;
    --input-bg: #0f172a;
    --input-border: #475569;
}

[data-theme="blue-innovation"] {
    /* Blue Innovation Theme (logo3.png) */
    --bg-color: #0c1427;
    --card-bg: #15203b;
    --text-primary: #e2e8f0;
    --text-secondary: #94a3b8;
    --primary: #00d4ff;
    --primary-hover: #00a3cc;
    --accent: #ffd700;
    --border-color: #1e293b;
    --shadow: 0 4px 15px rgba(0, 212, 255, 0.2);
    --nav-bg: #0c1427;
    --nav-text: #ffffff;
    --input-bg: #15203b;
    --input-border: #1e293b;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    transition: background-color 0.3s, color 0.3s, border-color 0.3s;
}

body {
    background-color: var(--bg-color);
    color: var(--text-primary);
    line-height: 1.6;
    overflow-x: hidden;
}

/* Auth Layout Enhancements */
.auth-container {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    background: radial-gradient(circle at top right, var(--primary) 0%, transparent 40%),
                radial-gradient(circle at bottom left, var(--accent) 0%, transparent 40%),
                var(--bg-color);
    position: relative;
    overflow: hidden;
}

.auth-container::before {
    content: "";
    position: absolute;
    inset: 0;
    background-image: url('https://www.transparenttextures.com/patterns/cubes.png');
    opacity: 0.05;
    pointer-events: none;
}

.auth-card {
    background-color: var(--card-bg);
    width: 100%;
    max-width: 480px;
    padding: 3rem;
    border-radius: 2rem;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
    border: 1px solid var(--border-color);
    text-align: center;
    position: relative;
    z-index: 1;
    backdrop-filter: blur(10px);
}

.auth-footer {
    position: absolute;
    bottom: 2rem;
    width: 100%;
    text-align: center;
    color: var(--text-secondary);
    font-size: 0.85rem;
    z-index: 1;
}

.logo-container {
    margin-bottom: 2rem;
}

.logo-container img {
    height: 80px;
    object-fit: contain;
    transition: transform 0.3s ease;
}

.logo-container img:hover {
    transform: scale(1.05);
}

h1 {
    font-size: 1.8rem;
    margin-bottom: 0.5rem;
    color: var(--text-primary);
}

p.subtitle {
    color: var(--text-secondary);
    margin-bottom: 2rem;
}

/* Forms */
.form-group {
    margin-bottom: 1.5rem;
    text-align: right;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    color: var(--text-primary);
}

.form-group input, .form-group select {
    width: 100%;
    padding: 0.75rem 1rem;
    border-radius: 0.75rem;
    border: 1px solid var(--input-border);
    background-color: var(--input-bg);
    color: var(--text-primary);
    outline: none;
    transition: border-color 0.3s, box-shadow 0.3s;
}

.form-group input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.btn {
    width: 100%;
    padding: 0.8rem;
    border-radius: 0.75rem;
    border: none;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
    margin-top: 1rem;
}

.btn-primary {
    background-color: var(--primary);
    color: white;
}

.btn-primary:hover {
    background-color: var(--primary-hover);
    transform: translateY(-2px);
}

/* Interactive Theme Options */
.theme-option {
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1) !important;
}

.theme-option:hover {
    transform: scale(1.05);
}

.theme-option:active {
    transform: scale(0.95);
}

.auth-links {
    margin-top: 1.5rem;
    color: var(--text-secondary);
}

.auth-links a {
    color: var(--primary);
    text-decoration: none;
    font-weight: 500;
}

.auth-links a:hover {
    text-decoration: underline;
}

/* Theme Switcher Floating */
.theme-switcher {
    position: fixed;
    top: 1rem;
    left: 1rem;
    z-index: 1000;
    background: var(--card-bg);
    padding: 0.5rem;
    border-radius: 2rem;
    box-shadow: var(--shadow);
    display: flex;
    gap: 0.5rem;
    border: 1px solid var(--border-color);
}

.theme-btn {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: 2px solid transparent;
    cursor: pointer;
    transition: transform 0.2s;
}

.theme-btn:hover {
    transform: scale(1.1);
}

.theme-btn.active {
    border-color: var(--primary);
}

.btn-light { background: #ffffff; border: 1px solid #ddd; }
.btn-dark { background: #1e293b; border: 1px solid #444; }
.btn-blue { background: #00d4ff; border: 1px solid #00a3cc; }

[dir="rtl"] {
    text-align: right;
}

/* Global Layout Unification */
.dashboard-container {
    display: flex;
    min-height: 100vh;
    background-color: var(--bg-color);
}

.main-content {
    flex: 1;
    margin-right: 260px;
    padding: 2rem;
    width: calc(100% - 260px);
    transition: margin-right 0.3s ease, width 0.3s ease;
}

.top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
    background: var(--card-bg);
    padding: 0 1.5rem;
    height: 70px;
    border-radius: 1rem;
    box-shadow: var(--shadow);
    border: 1px solid var(--border-color);
    position: sticky;
    top: 1rem;
    z-index: 80;
}

.page-info h1 {
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--text-primary);
}

/* Sidebar Refinement */
/* Sidebar Professional Refinement */
.sidebar {
    width: 260px;
    background-color: var(--card-bg);
    border-left: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    position: fixed;
    height: 100vh;
    right: 0;
    top: 0;
    z-index: 100;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 2px 0 10px rgba(0,0,0,0.02);
}

.sidebar-header {
    padding: 1.5rem;
    text-align: center;
    border-bottom: 1px solid var(--border-color);
    height: 80px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.sidebar-header img {
    height: 40px;
    width: auto;
    object-fit: contain;
}

.sidebar-menu {
    flex: 1;
    padding: 1rem 0.8rem;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.menu-item {
    display: flex;
    align-items: center;
    padding: 0.8rem 1.2rem;
    color: var(--text-secondary);
    text-decoration: none;
    transition: all 0.2s ease;
    gap: 12px;
    border-radius: 0.8rem;
    font-weight: 500;
    font-size: 0.95rem;
}

.menu-item i {
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    transition: transform 0.2s;
}

.menu-item:hover {
    background-color: var(--bg-color);
    color: var(--primary);
    transform: translateX(-5px); /* Move left slightly on hover in RTL */
}

.menu-item.active {
    background-color: var(--primary);
    color: white !important;
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.2);
}

.menu-item.active i {
    color: white;
}

.sidebar-footer {
    padding: 1rem 0.8rem;
    border-top: 1px solid var(--border-color);
    background: var(--card-bg);
}

/* Tablet View (1024px and below) */
@media (max-width: 1024px) {
    .sidebar { 
        width: 80px; 
    }
    .sidebar span { display: none; }
    .sidebar-header { padding: 1rem; }
    .sidebar-header img { height: 30px; }
    .menu-item { 
        padding: 0.8rem; 
        justify-content: center; 
    }
    .menu-item i { margin: 0; }
    .menu-item:hover { transform: none; }
    .main-content { margin-right: 80px; width: calc(100% - 80px); }
}

/* Mobile View (768px and below) */
@media (max-width: 768px) {
    .sidebar {
        width: 280px;
        right: -280px;
        box-shadow: -10px 0 30px rgba(0,0,0,0.1);
    }
    
    .sidebar.active {
        right: 0;
    }

    .sidebar span { display: inline; }
    .sidebar-header img { height: 40px; }
    .menu-item { justify-content: flex-start; }
    .main-content { 
        margin-right: 0; 
        width: 100%; 
        padding: 1rem;
        padding-top: 5.5rem;
    }

    .top-bar {
        position: fixed;
        top: 0;
        right: 0;
        left: 0;
        margin: 0;
        border-radius: 0;
        height: 65px;
        padding: 0 1rem !important;
        border-top: none;
        border-right: none;
        border-left: none;
        display: flex !important;
        flex-direction: row !important;
        justify-content: space-between !important;
        align-items: center !important;
        z-index: 90;
    }

    .top-actions {
        display: flex !important;
        align-items: center !important;
        gap: 0.5rem !important;
    }

    .theme-switcher-inline {
        display: none !important; /* Hide theme switcher on small mobile to save space */
    }

    .mobile-toggle {
        display: flex !important;
        order: -1; /* Keep at the very right (first in RTL) */
    }

    /* Force all grids to stack on mobile */
    [style*="display: grid"], 
    [style*="display:grid"],
    .grid-layout,
    .stats-grid,
    .charts-grid,
    .recent-grid {
        grid-template-columns: 1fr !important;
        gap: 1rem !important;
    }

    /* Fix table cards on mobile */
    .table-card {
        padding: 1rem !important;
        margin-bottom: 1rem;
    }

    .data-table th, .data-table td {
        padding: 0.8rem 0.5rem;
        font-size: 0.85rem;
    }
}

/* Card & Component Consistency */
.table-card, .chart-card, .stat-card {
    background: var(--card-bg);
    border-radius: 1rem;
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow);
}

.btn {
    border-radius: 0.8rem;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 0.7rem 1.2rem;
    width: auto; /* Default to auto instead of 100% */
}

.btn-primary {
    background-color: var(--primary);
    color: white;
}

/* Fix for full-width buttons in forms */
form .btn, .auth-card .btn {
    width: 100%;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.stat-card {
    background: var(--card-bg);
    padding: 1.5rem;
    border-radius: 1rem;
    box-shadow: var(--shadow);
    border: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.stat-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 10px 20px rgba(0,0,0,0.1);
}

.stat-icon {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    margin-bottom: 1rem;
}

.stat-info h3 {
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-bottom: 0.2rem;
}

.stat-info p {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-primary);
}

.charts-grid {
    display: grid;
    grid-template-columns: 1fr 2fr;
    gap: 1.5rem;
    margin-bottom: 1.5rem;
}

.chart-card {
    background: var(--card-bg);
    padding: 1.5rem;
    border-radius: 1rem;
    box-shadow: var(--shadow);
    border: 1px solid var(--border-color);
}

.chart-card h3 {
    margin-bottom: 1.5rem;
    font-size: 1.1rem;
    font-weight: 600;
}

.recent-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
}

/* Responsive Tables */
.table-card {
    background: var(--card-bg);
    padding: 1.5rem;
    border-radius: 1rem;
    box-shadow: var(--shadow);
    border: 1px solid var(--border-color);
    overflow-x: auto; /* Ensure tables can scroll horizontally */
    -webkit-overflow-scrolling: touch;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 1rem;
    min-width: 600px; /* Force minimum width to trigger scroll on small screens */
}

/* Responsive Modals */
.modal-content {
    background: var(--card-bg);
    padding: 2rem;
    border-radius: 1rem;
    width: 95%;
    max-width: 600px; /* Default max width */
    margin: 1rem;
    box-shadow: var(--shadow);
    max-height: 90vh;
    overflow-y: auto;
}

/* Responsive Grid Utilities */
.grid-layout {
    display: grid;
    gap: 1.5rem;
}

.grid-2-1 {
    grid-template-columns: 2fr 1fr;
}

.grid-1-1 {
    grid-template-columns: 1fr 1fr;
}

.grid-3 {
    grid-template-columns: repeat(3, 1fr);
}

@media (max-width: 992px) {
    .grid-2-1, .grid-3 {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 768px) {
    .grid-1-1 {
        grid-template-columns: 1fr;
    }
}

/* Fix for fixed-width style attributes in HTML */
[style*="grid-template-columns: 2fr 1fr"],
[style*="grid-template-columns: 1fr 1fr"],
[style*="grid-template-columns: 2fr 1fr;"] {
    display: grid !important;
}

@media (max-width: 992px) {
    div[style*="grid-template-columns"] {
        grid-template-columns: 1fr !important;
        gap: 1rem !important;
    }
}

/* Responsive Media Queries */
@media (max-width: 1024px) {
    .sidebar { 
        width: 80px; 
        transition: width 0.3s ease;
    }
    .sidebar span { display: none; }
    .sidebar-header { padding: 1rem; }
    .sidebar-header img { height: 30px; }
    .menu-item { padding: 1rem; justify-content: center; }
    .menu-item i { margin: 0; font-size: 1.3rem; }
    .main-content { margin-right: 80px; }
}

@media (max-width: 768px) {
    .sidebar {
        width: 260px;
        right: -260px; /* Hide off-screen */
        transition: right 0.3s ease;
        box-shadow: -5px 0 15px rgba(0,0,0,0.1);
    }
    
    .sidebar.active {
        right: 0; /* Show on active */
    }

    .sidebar span { display: inline; }
    .menu-item { justify-content: flex-start; }
    .menu-item i { margin-left: 12px; }

    .main-content { 
        margin-right: 0; 
        padding: 1rem;
        padding-top: 4.5rem; /* Adjusted for smaller header */
    }

    .top-bar {
        position: fixed;
        top: 0;
        right: 0;
        left: 0;
        z-index: 90;
        border-radius: 0;
        margin-bottom: 0;
        padding: 0 1rem !important; /* Smaller padding */
        height: 60px; /* Unified mobile height */
        flex-direction: row !important;
        justify-content: space-between !important;
        align-items: center !important;
    }

    .page-info h1 {
        font-size: 1.1rem; /* Smaller title */
        margin-bottom: 0;
    }

    .page-info p {
        display: none; /* Hide subtitle on mobile to save vertical space */
    }

    .mobile-toggle {
        display: flex !important;
        align-items: center;
        justify-content: center;
        width: 40px;
        height: 40px;
        background: var(--card-bg);
        border: 1px solid var(--border-color);
        border-radius: 8px;
        cursor: pointer;
        font-size: 1.2rem;
        color: var(--primary);
    }

    .charts-grid, .recent-grid {
        grid-template-columns: 1fr !important;
    }
    
    .stats-grid {
        grid-template-columns: 1fr 1fr !important;
    }
    
    .grid-2-1, .grid-3, .grid-layout {
        grid-template-columns: 1fr !important;
    }
}

@media (max-width: 480px) {
    .stats-grid {
        grid-template-columns: 1fr !important;
    }
    
    .top-bar {
        padding: 0.8rem 0.5rem !important;
    }
    
    .top-actions .user-info, 
    .top-actions .user-role {
        display: none !important; /* Save space on small phones */
    }

    .auth-card {
        padding: 1.5rem;
        margin: 1rem;
    }
    
    .main-content {
        padding: 0.8rem;
        padding-top: 4.5rem; /* Match 768px adjustment */
    }

    .page-info h1 {
        font-size: 1rem;
    }

    /* Force all grid style overrides to stack */
    div[style*="display: grid"], 
    div[style*="display:grid"] {
        grid-template-columns: 1fr !important;
        gap: 1rem !important;
    }
}

/* Sidebar Overlay for Mobile */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 95;
    backdrop-filter: blur(2px);
}

.sidebar-overlay.active {
    display: block;
}
