/* Balqis Technology Modern - Master Enterprise Design System */
@import url('https://fonts.googleapis.com/css2?family=Cairo:wght@400;500;600;700;800;900&family=Plus+Jakarta+Sans:wght@400;500;600;700;800&display=swap');

:root {
    /* Brand Colors */
    --primary: #990000;
    --primary-dark: #7a0000;
    --primary-light: #fff1f1;
    --primary-subtle: #fde8e8;
    --primary-gradient: linear-gradient(135deg, #990000 0%, #b91c1c 100%);
    
    --secondary: #1e293b;
    --accent: #f59e0b;
    
    /* Backgrounds */
    --bg-page: #f1f5f9;
    --bg-card: #ffffff;
    --bg-surface: #f8fafc;
    --bg-sidebar: #0b1329;
    --bg-sidebar-hover: rgba(255, 255, 255, 0.08);
    --bg-sidebar-active: #990000;
    
    /* Text Colors */
    --text-main: #0f172a;
    --text-muted: #64748b;
    --text-light: #94a3b8;
    --text-white: #ffffff;
    
    /* Borders & Lines */
    --border: #e2e8f0;
    --border-light: #f1f5f9;
    --border-focus: #990000;
    
    /* Status Colors */
    --success: #10b981;
    --success-bg: #ecfdf5;
    --success-border: #a7f3d0;
    --warning: #f59e0b;
    --warning-bg: #fffbeb;
    --warning-border: #fde68a;
    --danger: #ef4444;
    --danger-bg: #fef2f2;
    --danger-border: #fecaca;
    --info: #0284c7;
    --info-bg: #f0f9ff;
    --info-border: #bae6fd;
    
    /* Shadows */
    --shadow-xs: 0 1px 2px 0 rgba(0, 0, 0, 0.04);
    --shadow-sm: 0 1px 3px 0 rgba(0, 0, 0, 0.08), 0 1px 2px -1px rgba(0, 0, 0, 0.08);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.07), 0 2px 4px -2px rgba(0, 0, 0, 0.05);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.08), 0 4px 6px -4px rgba(0, 0, 0, 0.04);
    --shadow-card: 0 2px 8px 0 rgba(15, 23, 42, 0.04), 0 1px 2px 0 rgba(15, 23, 42, 0.02);
    
    /* Radius */
    --radius-xs: 4px;
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-full: 9999px;
    
    /* Layout Sizes */
    --sidebar-width: 270px;
    --header-height: 72px;
}

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

body {
    font-family: 'Cairo', 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background-color: var(--bg-page);
    color: var(--text-main);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    overflow-x: hidden;
}

/* Master Layout */
.app-layout {
    display: flex;
    min-height: 100vh;
    position: relative;
}

/* Sidebar */
.app-sidebar {
    width: var(--sidebar-width);
    background-color: var(--bg-sidebar);
    color: var(--text-white);
    position: fixed;
    top: 0;
    bottom: 0;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 4px 0 20px rgba(0, 0, 0, 0.15);
    overflow-y: auto;
}

.sidebar-header {
    padding: 24px 20px;
    display: flex;
    align-items: center;
    gap: 14px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    background: rgba(0, 0, 0, 0.2);
}

.sidebar-logo {
    height: 44px;
    width: auto;
    object-fit: contain;
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.3));
}

.sidebar-brand {
    font-size: 15px;
    font-weight: 800;
    letter-spacing: 0.5px;
    color: #ffffff;
    line-height: 1.2;
}

.sidebar-brand small {
    display: block;
    font-size: 11px;
    font-weight: 500;
    color: #94a3b8;
    letter-spacing: 1px;
    margin-top: 2px;
}

.sidebar-nav {
    padding: 18px 12px;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.nav-label {
    font-size: 11px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: #64748b;
    padding: 16px 14px 6px;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 11px 16px;
    color: #cbd5e1;
    text-decoration: none;
    font-size: 14px;
    font-weight: 600;
    border-radius: var(--radius-sm);
    transition: all 0.2s ease;
}

.nav-link:hover {
    background-color: var(--bg-sidebar-hover);
    color: #ffffff;
    transform: translateX(3px);
}

.nav-link.active {
    background: var(--primary-gradient);
    color: #ffffff;
    font-weight: 700;
    box-shadow: 0 4px 12px rgba(153, 0, 0, 0.35);
}

.nav-link svg {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
}

/* Sidebar Backdrop on Mobile */
.sidebar-backdrop {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(15, 23, 42, 0.65);
    backdrop-filter: blur(4px);
    z-index: 999;
}

/* Main Content Area */
.app-main {
    flex: 1;
    margin-inline-start: var(--sidebar-width);
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    min-width: 0;
}

/* Header */
.app-header {
    height: var(--header-height);
    background-color: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 28px;
    position: sticky;
    top: 0;
    z-index: 500;
}

.header-left, .header-right {
    display: flex;
    align-items: center;
    gap: 16px;
}

.menu-toggle-btn {
    display: none;
    background: none;
    border: none;
    cursor: pointer;
    padding: 8px;
    color: var(--text-main);
    border-radius: var(--radius-sm);
}

.menu-toggle-btn:hover {
    background: var(--bg-surface);
}

.page-title {
    font-size: 20px;
    font-weight: 800;
    color: var(--text-main);
}

.lang-switch {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    padding: 6px 12px;
    border-radius: var(--radius-full);
    font-size: 13px;
    font-weight: 700;
    color: var(--text-main);
    text-decoration: none;
    transition: all 0.2s ease;
}

.lang-switch:hover {
    background: var(--primary-light);
    color: var(--primary);
    border-color: var(--primary-subtle);
}

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

.user-avatar {
    width: 40px;
    height: 40px;
    background: var(--primary-gradient);
    color: #ffffff;
    border-radius: var(--radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    font-size: 16px;
    box-shadow: 0 2px 8px rgba(153, 0, 0, 0.25);
}

.app-content {
    padding: 28px;
    flex: 1;
    max-width: 1600px;
    width: 100%;
    margin: 0 auto;
}

/* Cards */
.card {
    background-color: var(--bg-card);
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-card);
    padding: 24px;
    margin-bottom: 24px;
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-bottom: 16px;
    margin-bottom: 20px;
    border-bottom: 1px solid var(--border);
    flex-wrap: wrap;
    gap: 12px;
}

.card-title {
    font-size: 18px;
    font-weight: 800;
    color: var(--text-main);
    display: flex;
    align-items: center;
    gap: 10px;
}

/* KPI Cards Grid */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 20px;
    margin-bottom: 28px;
}

.kpi-card {
    background: var(--bg-card);
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
    padding: 22px;
    display: flex;
    align-items: center;
    gap: 18px;
    box-shadow: var(--shadow-card);
    position: relative;
    overflow: hidden;
    transition: transform 0.2s, box-shadow 0.2s;
}

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

.kpi-card::before {
    content: '';
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    width: 4px;
    background: var(--primary);
}

.kpi-icon {
    width: 52px;
    height: 52px;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--primary-light);
    color: var(--primary);
    flex-shrink: 0;
}

.kpi-icon svg {
    width: 26px;
    height: 26px;
}

.kpi-info h3 {
    font-size: 24px;
    font-weight: 900;
    color: var(--text-main);
    line-height: 1.1;
}

.kpi-info p {
    font-size: 13px;
    color: var(--text-muted);
    font-weight: 600;
    margin-top: 4px;
}

/* Tables */
.table-responsive {
    overflow-x: auto;
    width: 100%;
    -webkit-overflow-scrolling: touch;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: #fff;
}

.table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
    text-align: start;
}

.table th {
    background-color: var(--bg-surface);
    color: #475569;
    font-weight: 700;
    padding: 14px 16px;
    border-bottom: 2px solid var(--border);
    white-space: nowrap;
}

.table td {
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}

.table tbody tr:hover {
    background-color: #f8fafc;
}

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

/* Badges */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 4px 12px;
    border-radius: var(--radius-full);
    font-size: 12px;
    font-weight: 700;
    white-space: nowrap;
}

.badge-success { background: var(--success-bg); color: var(--success); border: 1px solid var(--success-border); }
.badge-warning { background: var(--warning-bg); color: #b45309; border: 1px solid var(--warning-border); }
.badge-danger { background: var(--danger-bg); color: var(--danger); border: 1px solid var(--danger-border); }
.badge-info { background: var(--info-bg); color: var(--info); border: 1px solid var(--info-border); }
.badge-draft { background: #f1f5f9; color: #475569; border: 1px solid #cbd5e1; }
.badge-secondary { background: #f3f4f6; color: #4b5563; border: 1px solid #e5e7eb; }

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 18px;
    font-size: 14px;
    font-weight: 700;
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    cursor: pointer;
    text-decoration: none;
    transition: all 0.2s;
    white-space: nowrap;
    line-height: 1.2;
}

.btn-primary {
    background: var(--primary-gradient);
    color: #ffffff;
    box-shadow: 0 2px 6px rgba(153, 0, 0, 0.25);
}

.btn-primary:hover {
    background: linear-gradient(135deg, #7a0000 0%, #990000 100%);
    box-shadow: 0 4px 12px rgba(153, 0, 0, 0.35);
    transform: translateY(-1px);
}

.btn-secondary {
    background-color: #ffffff;
    color: #334155;
    border-color: #cbd5e1;
    box-shadow: var(--shadow-xs);
}

.btn-secondary:hover {
    background-color: #f8fafc;
    border-color: #94a3b8;
    color: #0f172a;
}

.btn-success {
    background-color: var(--success);
    color: #ffffff;
}

.btn-danger {
    background-color: var(--danger);
    color: #ffffff;
}

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

/* Forms */
.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 18px;
    margin-bottom: 20px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 16px;
}

.form-label {
    font-size: 13px;
    font-weight: 700;
    color: #334155;
}

.form-control {
    width: 100%;
    padding: 10px 14px;
    font-size: 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background-color: #ffffff;
    color: var(--text-main);
    font-family: inherit;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.form-control:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(153, 0, 0, 0.12);
}

/* Builder Table */
.builder-table {
    width: 100%;
    border-collapse: collapse;
    background: #fff;
    font-size: 13px;
}

.builder-table th {
    background-color: #990000;
    color: #ffffff;
    font-weight: 700;
    padding: 12px 10px;
    text-align: center;
    border: 1px solid #7a0000;
}

.builder-table td {
    padding: 8px;
    border: 1px solid var(--border);
    background: #ffffff;
}

.builder-table input, .builder-table textarea, .builder-table select {
    width: 100%;
    padding: 8px 10px;
    font-size: 13px;
    border: 1px solid var(--border);
    border-radius: var(--radius-xs);
    font-family: inherit;
    background: #fff;
}

.builder-table input:focus, .builder-table textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(153, 0, 0, 0.1);
}

/* Autocomplete Dropdown */
.autocomplete-dropdown {
    position: absolute;
    background: #ffffff;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-lg);
    max-height: 280px;
    overflow-y: auto;
    z-index: 2000;
    width: 360px;
    display: none;
}

.autocomplete-item {
    padding: 10px 14px;
    cursor: pointer;
    border-bottom: 1px solid var(--border-light);
    font-size: 13px;
    transition: background 0.15s;
}

.autocomplete-item:hover {
    background-color: var(--primary-light);
    color: var(--primary);
}

.autocomplete-item .item-code {
    font-weight: 800;
    color: #0f172a;
    display: block;
}

.autocomplete-item .item-desc {
    font-size: 12px;
    color: var(--text-muted);
    display: block;
    margin-top: 2px;
}

/* Totals Summary Box */
.totals-box {
    width: 380px;
    max-width: 100%;
    margin-inline-start: auto;
    background: #ffffff;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 20px;
    box-shadow: var(--shadow-sm);
}

.totals-row {
    display: flex;
    justify-content: space-between;
    padding: 8px 0;
    font-size: 14px;
    border-bottom: 1px dashed var(--border);
}

.totals-row.grand-total {
    font-size: 19px;
    font-weight: 900;
    color: var(--primary);
    border-bottom: none;
    padding-top: 14px;
}

/* Responsive Audit Log & Truncated Text */
.audit-details-cell {
    max-width: 320px;
    max-height: 80px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-family: monospace;
    font-size: 11px;
    background: var(--bg-surface);
    padding: 4px 8px;
    border-radius: 4px;
    border: 1px solid var(--border);
}

/* Alerts */
.alert {
    padding: 14px 20px;
    border-radius: var(--radius-sm);
    margin-bottom: 24px;
    font-size: 14px;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 12px;
    box-shadow: var(--shadow-xs);
}

.alert-success { background: var(--success-bg); color: #065f46; border: 1px solid var(--success-border); }
.alert-danger { background: var(--danger-bg); color: #991b1b; border: 1px solid var(--danger-border); }

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

.empty-state h4 {
    font-size: 16px;
    font-weight: 800;
    color: var(--text-main);
    margin-bottom: 6px;
}

/* Utilities */
.d-flex { display: flex; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.gap-4 { gap: 16px; }
.align-items-center { align-items: center; }
.justify-content-between { justify-content: space-between; }
.flex-wrap { flex-wrap: wrap; }
.font-bold { font-weight: 800; }
.text-center { text-align: center; }
.text-end { text-align: right; }
.text-muted { color: var(--text-muted); }

/* Responsive Media Queries (Mobile & Tablet) */
@media (max-width: 1024px) {
    :root {
        --sidebar-width: 0px;
    }
    .app-sidebar {
        transform: translateX(-100%);
        width: 280px;
    }
    html[dir="rtl"] .app-sidebar {
        transform: translateX(100%);
    }
    .app-sidebar.sidebar-open {
        transform: translateX(0);
    }
    .sidebar-backdrop.active {
        display: block;
    }
    .app-main {
        margin-inline-start: 0;
    }
    .menu-toggle-btn {
        display: inline-flex;
    }
    .app-header {
        padding: 0 16px;
    }
    .app-content {
        padding: 16px;
    }
    .kpi-grid {
        grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
        gap: 14px;
    }
}

@media (max-width: 640px) {
    .page-title {
        font-size: 17px;
    }
    .card {
        padding: 16px;
    }
    .totals-box {
        width: 100%;
    }
    .btn {
        padding: 8px 14px;
        font-size: 13px;
    }
}
