/* Import Premium Typography from Google Fonts */
@import url('https://fonts.googleapis.com/css2?family=Cairo:wght@300;400;600;700&family=Inter:wght@300;400;500;600;700&display=swap');

/* Color Variables and Layout Constants */
:root {
    --bg-primary: #0b0f19;
    --bg-surface: rgba(23, 30, 49, 0.7);
    --bg-surface-opaque: #131b2e;
    --border-color: rgba(255, 255, 255, 0.08);
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    
    /* Accents */
    --accent-indigo: #6366f1;
    --accent-emerald: #10b981;
    --accent-rose: #f43f5e;
    --accent-amber: #f59e0b;
    --accent-sky: #0ea5e9;
    
    /* Font Families based on Language */
    --font-ar: 'Cairo', sans-serif;
    --font-en: 'Inter', sans-serif;
    --transition-smooth: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Reset and Global Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    background-color: var(--bg-primary);
    color: var(--text-primary);
    font-size: 15px;
    line-height: 1.6;
    overflow-x: hidden;
}

body[dir="rtl"] {
    font-family: var(--font-ar);
}

body[dir="ltr"] {
    font-family: var(--font-en);
}

/* Layout Container */
.app-container {
    display: flex;
    min-height: 100vh;
}

/* Sidebar Navigation */
.sidebar {
    width: 280px;
    background: var(--bg-surface-opaque);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    padding: 24px;
    flex-shrink: 0;
}

body[dir="rtl"] .sidebar {
    border-right: none;
    border-left: 1px solid var(--border-color);
}

.sidebar-logo {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-bottom: 32px;
}

.sidebar-logo h1 {
    font-size: 20px;
    font-weight: 700;
    color: var(--text-primary);
}

.sidebar-logo span {
    font-size: 11px;
    color: var(--text-secondary);
    letter-spacing: 0.5px;
}

.sidebar-menu {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.sidebar-item a {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    color: var(--text-secondary);
    text-decoration: none;
    border-radius: 12px;
    font-weight: 500;
    transition: var(--transition-smooth);
}

.sidebar-item.active a,
.sidebar-item a:hover {
    background: rgba(99, 102, 241, 0.15);
    color: var(--text-primary);
    box-shadow: inset 0 0 12px rgba(99, 102, 241, 0.1);
}

.sidebar-item svg {
    width: 20px;
    height: 20px;
    stroke: currentColor;
    fill: none;
    stroke-width: 2;
}

.sidebar-footer {
    margin-top: auto;
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding-top: 24px;
    border-top: 1px solid var(--border-color);
}

.user-badge {
    display: flex;
    align-items: center;
    gap: 12px;
}

.user-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--accent-indigo);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    color: white;
}

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

.user-name {
    font-size: 14px;
    font-weight: 600;
}

.user-role {
    font-size: 11px;
    color: var(--text-secondary);
}

/* Main Dashboard Panel */
.main-content {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    padding: 32px;
    overflow-y: auto;
}

/* Top Navbar Header */
.top-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 32px;
    gap: 16px;
}

.page-title h2 {
    font-size: 26px;
    font-weight: 700;
}

.page-title p {
    font-size: 13px;
    color: var(--text-secondary);
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 16px;
}

/* Language and Tenant Selectors */
.lang-btn {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    padding: 8px 16px;
    border-radius: 8px;
    color: var(--text-primary);
    cursor: pointer;
    font-family: inherit;
    font-size: 13px;
    transition: var(--transition-smooth);
}

.lang-btn:hover {
    border-color: var(--accent-indigo);
}

/* Glassmorphism Card Panels */
.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 24px;
    margin-bottom: 32px;
}

.kpi-card {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    backdrop-filter: blur(12px);
    transition: var(--transition-smooth);
}

.kpi-card:hover {
    transform: translateY(-4px);
    border-color: rgba(255, 255, 255, 0.15);
}

.kpi-details h4 {
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.kpi-details span {
    font-size: 32px;
    font-weight: 700;
}

.kpi-icon {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.kpi-icon.indigo { background: rgba(99, 102, 241, 0.15); color: var(--accent-indigo); }
.kpi-icon.emerald { background: rgba(16, 185, 129, 0.15); color: var(--accent-emerald); }
.kpi-icon.rose { background: rgba(244, 63, 94, 0.15); color: var(--accent-rose); }
.kpi-icon.amber { background: rgba(245, 158, 11, 0.15); color: var(--accent-amber); }

/* Unified Glass Table styles */
.content-card {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 24px;
    backdrop-filter: blur(12px);
    margin-bottom: 32px;
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
}

.card-header h3 {
    font-size: 18px;
    font-weight: 600;
}

.table-responsive {
    width: 100%;
    overflow-x: auto;
}

.table-custom {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
}

body[dir="rtl"] .table-custom {
    text-align: right;
}

.table-custom th {
    padding: 14px 16px;
    font-size: 12px;
    text-transform: uppercase;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border-color);
    font-weight: 600;
}

.table-custom td {
    padding: 16px;
    border-bottom: 1px solid var(--border-color);
    font-size: 14px;
    color: var(--text-primary);
}

.table-custom tr:last-child td {
    border-bottom: none;
}

.table-custom tr:hover td {
    background: rgba(255, 255, 255, 0.02);
}

/* Form Styling */
.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 8px;
    font-weight: 500;
}

.form-control, select, textarea {
    width: 100%;
    background: rgba(15, 23, 42, 0.6);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    padding: 12px 16px;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 14px;
    outline: none;
    transition: var(--transition-smooth);
}

.form-control:focus, select:focus, textarea:focus {
    border-color: var(--accent-indigo);
    box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.2);
}

.row-form {
    display: flex;
    gap: 20px;
    flex-wrap: wrap;
}

.col-form {
    flex: 1;
    min-width: 250px;
}

/* Beautiful Action Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 20px;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    text-decoration: none;
    transition: var(--transition-smooth);
    border: none;
}

.btn-primary {
    background: var(--accent-indigo);
    color: white;
}

.btn-primary:hover {
    background: #4f46e5;
    box-shadow: 0 0 16px rgba(99, 102, 241, 0.4);
}

.btn-success {
    background: var(--accent-emerald);
    color: white;
}

.btn-success:hover {
    background: #059669;
    box-shadow: 0 0 16px rgba(16, 185, 129, 0.4);
}

.btn-outline {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-primary);
}

.btn-outline:hover {
    border-color: var(--text-primary);
}

.btn-sm {
    padding: 6px 12px;
    font-size: 12px;
    border-radius: 6px;
}

/* Status Badges */
.badge {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
}

.badge.pending { background: rgba(245, 158, 11, 0.15); color: var(--accent-amber); }
.badge.progress { background: rgba(14, 165, 233, 0.15); color: var(--accent-sky); }
.badge.success { background: rgba(16, 185, 129, 0.15); color: var(--accent-emerald); }
.badge.danger { background: rgba(244, 63, 94, 0.15); color: var(--accent-rose); }
.badge.gray { background: rgba(148, 163, 184, 0.15); color: var(--text-secondary); }

/* State-of-the-Art Workflow step timeline */
.workflow-timeline {
    display: flex;
    justify-content: space-between;
    position: relative;
    margin: 32px 0;
    padding: 0 40px;
}

.workflow-timeline::before {
    content: '';
    position: absolute;
    top: 20px;
    left: 40px;
    right: 40px;
    height: 3px;
    background: var(--border-color);
    z-index: 1;
}

.workflow-step {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    z-index: 2;
    position: relative;
}

.workflow-node {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--bg-primary);
    border: 3px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    color: var(--text-secondary);
    transition: var(--transition-smooth);
}

.workflow-step.completed .workflow-node {
    border-color: var(--accent-emerald);
    background: var(--accent-emerald);
    color: white;
}

.workflow-step.active .workflow-node {
    border-color: var(--accent-indigo);
    background: var(--accent-indigo);
    color: white;
    box-shadow: 0 0 16px rgba(99, 102, 241, 0.5);
}

.workflow-label {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
}

.workflow-step.active .workflow-label {
    color: var(--text-primary);
}

/* 5x5 Interactive Risk Matrix Heat Map */
.risk-heatmap-container {
    display: grid;
    grid-template-columns: 50px 1fr;
    gap: 16px;
    align-items: center;
    margin-bottom: 24px;
}

.risk-heatmap-y-label {
    writing-mode: vertical-lr;
    transform: rotate(180deg);
    text-align: center;
    color: var(--text-secondary);
    font-size: 13px;
    font-weight: 600;
    text-transform: uppercase;
}

body[dir="rtl"] .risk-heatmap-y-label {
    writing-mode: vertical-rl;
    transform: rotate(360deg);
}

.risk-grid {
    display: grid;
    grid-template-rows: repeat(5, 1fr);
    gap: 8px;
}

.risk-row {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 8px;
}

.risk-cell {
    aspect-ratio: 1;
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    position: relative;
    font-size: 11px;
    font-weight: 700;
    color: white;
    cursor: pointer;
    transition: var(--transition-smooth);
}

.risk-cell:hover {
    transform: scale(1.05);
    z-index: 10;
}

/* Cell Colors based on Risk level */
.cell-low { background: rgba(16, 185, 129, 0.4); border: 1px solid rgba(16, 185, 129, 0.6); }
.cell-med { background: rgba(245, 158, 11, 0.4); border: 1px solid rgba(245, 158, 11, 0.6); }
.cell-high { background: rgba(244, 63, 94, 0.4); border: 1px solid rgba(244, 63, 94, 0.6); }
.cell-critical { background: rgba(239, 68, 68, 0.85); border: 1px solid #ef4444; }

.risk-bubble {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: white;
    color: black;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 700;
    border: 2px solid var(--bg-primary);
    box-shadow: 0 4px 8px rgba(0,0,0,0.3);
}

.risk-heatmap-x-labels {
    display: grid;
    grid-template-columns: 50px repeat(5, 1fr);
    gap: 8px;
    margin-top: 12px;
    text-align: center;
    color: var(--text-secondary);
    font-size: 13px;
    font-weight: 600;
}

/* Multi-tenant Login Layout */
.login-body {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: radial-gradient(circle at 10% 20%, rgba(99, 102, 241, 0.15) 0%, transparent 45%), var(--bg-primary);
}

.login-wrapper {
    width: 100%;
    max-width: 440px;
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: 24px;
    padding: 40px;
    backdrop-filter: blur(16px);
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.4);
}

.login-header {
    text-align: center;
    margin-bottom: 32px;
}

.login-header h2 {
    font-size: 24px;
    font-weight: 700;
    margin-bottom: 8px;
}

.login-header p {
    font-size: 13px;
    color: var(--text-secondary);
}

/* System Alerts block */
.alert-box {
    padding: 16px 20px;
    border-radius: 12px;
    margin-bottom: 24px;
    font-size: 14px;
    display: flex;
    align-items: center;
    gap: 12px;
}

.alert-danger {
    background: rgba(244, 63, 94, 0.1);
    border-left: 4px solid var(--accent-rose);
    color: #fda4af;
}

body[dir="rtl"] .alert-danger {
    border-left: none;
    border-right: 4px solid var(--accent-rose);
}

.alert-success {
    background: rgba(16, 185, 129, 0.1);
    border-left: 4px solid var(--accent-emerald);
    color: #a7f3d0;
}

body[dir="rtl"] .alert-success {
    border-left: none;
    border-right: 4px solid var(--accent-emerald);
}

/* Mobile responsive fixes */
@media(max-width: 768px) {
    .app-container {
        flex-direction: column;
    }
    .sidebar {
        width: 100%;
        border-right: none;
        border-bottom: 1px solid var(--border-color);
    }
    body[dir="rtl"] .sidebar {
        border-left: none;
    }
    .main-content {
        padding: 16px;
    }
}
