/* ===================================================================
 *  ProcureFlow - Design System & Stylesheet
 * =================================================================== */

:root {
    --bg-body: #fdfbf7;
    --bg-card: rgba(255, 255, 255, 0.85);
    --bg-card-hover: rgba(255, 255, 255, 0.98);
    --border-color: rgba(214, 211, 209, 0.8);
    --glass-border: rgba(255, 255, 255, 0.7);
    
    /* Procurement Theme: Earthy Greens and Ambers */
    --primary: #166534;       /* deep green */
    --primary-hover: #14532d;
    --secondary: #b45309;     /* amber/orange */
    --gradient-primary: linear-gradient(135deg, #166534 0%, #15803d 100%);
    
    --text-main: #1c1917;
    --text-muted: #57534e;
    --text-light: #a8a29e;
    
    --success: #15803d;
    --success-bg: rgba(21, 128, 61, 0.1);
    --warning: #d97706;
    --warning-bg: rgba(217, 119, 6, 0.1);
    --danger: #dc2626;
    --danger-bg: rgba(220, 38, 38, 0.1);
    --info: #0369a1;
    --info-bg: rgba(3, 105, 161, 0.1);
    
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-full: 9999px;
    
    --shadow-sm: 0 1px 3px rgba(28, 25, 23, 0.05);
    --shadow-md: 0 4px 12px rgba(28, 25, 23, 0.05);
    --shadow-lg: 0 12px 24px rgba(28, 25, 23, 0.08);
    
    --font-en: 'Outfit', -apple-system, sans-serif;
    --font-ar: 'Cairo', -apple-system, sans-serif;
}

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

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

body {
    background-color: var(--bg-body);
    background-image: 
        radial-gradient(circle at 0% 0%, rgba(22, 101, 52, 0.03) 0%, transparent 50%),
        radial-gradient(circle at 100% 100%, rgba(180, 83, 9, 0.03) 0%, transparent 50%);
    background-attachment: fixed;
    color: var(--text-main);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    -webkit-font-smoothing: antialiased;
}

/* Glassmorphism */
.glass-panel {
    background: var(--bg-card);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--glass-border);
    box-shadow: var(--shadow-md);
    border-radius: var(--radius-md);
    transition: all 0.2s ease;
}

/* Loading */
.loading-screen {
    height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    color: var(--text-muted);
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border-color);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* Layout: Header */
.app-header {
    position: sticky;
    top: 0;
    z-index: 100;
    background: rgba(253, 251, 247, 0.9);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border-color);
    padding: 0 24px;
}

.header-container {
    max-width: 1400px;
    margin: 0 auto;
    height: 64px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.brand-logo {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 700;
    font-size: 18px;
    color: var(--text-main);
    text-decoration: none;
}

.brand-icon {
    width: 32px;
    height: 32px;
    background: var(--gradient-primary);
    color: white;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
}

.nav-links {
    display: flex;
    align-items: center;
    gap: 4px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 14px;
    border-radius: var(--radius-full);
    color: var(--text-muted);
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.2s;
}

.nav-item:hover {
    color: var(--primary);
    background: rgba(22, 101, 52, 0.05);
}

.nav-item.active {
    color: white;
    background: var(--gradient-primary);
    box-shadow: 0 4px 10px rgba(22, 101, 52, 0.2);
}

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

.user-badge {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 4px 12px 4px 4px;
    background: rgba(245, 245, 244, 0.8);
    border-radius: var(--radius-full);
    border: 1px solid var(--border-color);
}

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

.user-info { display: flex; flex-direction: column; }
.user-name { font-size: 13px; font-weight: 600; line-height: 1.2; }
.user-role { font-size: 11px; color: var(--text-muted); }

.btn-icon {
    background: none; border: none; color: var(--text-muted);
    cursor: pointer; padding: 6px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    transition: all 0.2s;
}
.btn-icon:hover { color: var(--danger); background: var(--danger-bg); }

/* Main Content */
.main-content {
    max-width: 1400px;
    width: 100%;
    margin: 0 auto;
    padding: 24px;
    flex: 1;
}

.page-title-row {
    display: flex; justify-content: space-between; align-items: center;
    margin-bottom: 24px; flex-wrap: wrap; gap: 16px;
}
.page-title-row h1 { font-size: 22px; font-weight: 700; display: flex; align-items: center; gap: 8px; }
.page-title-row h1 .material-symbols-outlined { color: var(--primary); }

/* Buttons */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    padding: 8px 16px; border-radius: var(--radius-sm);
    font-size: 14px; font-weight: 600; cursor: pointer; border: none;
    transition: all 0.2s; text-decoration: none;
}
.btn-primary { background: var(--gradient-primary); color: white; box-shadow: 0 2px 8px rgba(22, 101, 52, 0.2); }
.btn-primary:hover { opacity: 0.95; transform: translateY(-1px); }
.btn-secondary { background: white; color: var(--text-main); border: 1px solid var(--border-color); }
.btn-secondary:hover { background: #f5f5f4; }
.btn-danger { background: var(--danger); color: white; }

/* Data Tables */
.table-wrapper { overflow-x: auto; border-radius: var(--radius-md); }
.data-table { width: 100%; border-collapse: collapse; font-size: 14px; text-align: start; }
.data-table thead th {
    background: rgba(245, 245, 244, 0.8); padding: 12px 16px;
    font-weight: 600; color: var(--text-muted); border-bottom: 1px solid var(--border-color);
    white-space: nowrap;
}
.data-table tbody tr { border-bottom: 1px solid var(--border-color); transition: background 0.15s; }
.data-table tbody tr:hover { background: rgba(22, 101, 52, 0.02); }
.data-table td { padding: 12px 16px; color: var(--text-main); vertical-align: middle; }

/* Matrix Input Table (Sheet Detail) */
.matrix-table input {
    width: 60px;
    padding: 4px 8px;
    text-align: center;
    border: 1px solid var(--border-color);
    border-radius: 4px;
}
.matrix-table input:focus { border-color: var(--primary); outline: none; }
.matrix-table input:disabled { background: #f5f5f4; color: var(--text-muted); cursor: not-allowed; border-color: transparent;}
.matrix-col-group { border-left: 2px solid var(--border-color); }

/* Badges */
.badge {
    display: inline-flex; align-items: center; gap: 4px;
    padding: 4px 8px; border-radius: var(--radius-full);
    font-size: 12px; font-weight: 600; white-space: nowrap;
}
.badge.success { background: var(--success-bg); color: var(--success); }
.badge.warning { background: var(--warning-bg); color: var(--warning); }
.badge.danger { background: var(--danger-bg); color: var(--danger); }
.badge.info { background: var(--info-bg); color: var(--info); }
.badge.secondary { background: rgba(168, 162, 158, 0.15); color: var(--text-muted); }

/* Forms */
.form-group { margin-bottom: 16px; text-align: start; }
.form-group label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; }
.form-control {
    width: 100%; padding: 8px 12px; background: white;
    border: 1px solid var(--border-color); border-radius: var(--radius-sm);
    font-size: 14px; outline: none; transition: all 0.2s;
}
.form-control:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(22, 101, 52, 0.1); }

/* KPI Cards */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; margin-bottom: 24px; }
.kpi-card { padding: 20px; display: flex; align-items: center; gap: 16px; }
.kpi-icon { width: 48px; height: 48px; border-radius: var(--radius-md); display: flex; align-items: center; justify-content: center; font-size: 24px; }
.kpi-icon.primary { background: rgba(22, 101, 52, 0.1); color: var(--primary); }
.kpi-icon.warning { background: var(--warning-bg); color: var(--warning); }
.kpi-icon.info { background: var(--info-bg); color: var(--info); }
.kpi-val { font-size: 24px; font-weight: 700; }
.kpi-lbl { font-size: 13px; color: var(--text-muted); }

/* Filter Bar */
.filter-bar { padding: 16px; margin-bottom: 24px; display: flex; align-items: flex-end; gap: 12px; flex-wrap: wrap; }
.filter-bar .form-group { margin-bottom: 0; }

/* Modals */
.modal-overlay {
    position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(28, 25, 23, 0.6); backdrop-filter: blur(4px);
    z-index: 1000; display: flex; align-items: center; justify-content: center; padding: 20px;
}
.modal-overlay.hidden { display: none; }
.modal-box { width: 100%; max-width: 500px; background: white; border-radius: var(--radius-md); box-shadow: var(--shadow-lg); overflow: hidden; }
.modal-header { padding: 16px 20px; border-bottom: 1px solid var(--border-color); display: flex; justify-content: space-between; align-items: center; font-weight: 600; }
.modal-body { padding: 20px; max-height: 70vh; overflow-y: auto;}
.modal-footer { padding: 16px 20px; border-top: 1px solid var(--border-color); display: flex; justify-content: flex-end; gap: 12px; background: #fafaf9; }

/* Tabs */
.tabs-bar {
    display: flex; gap: 4px; padding: 4px; background: #f5f5f4;
    border-radius: var(--radius-md); margin-bottom: 20px; overflow-x: auto;
}
.tab-btn {
    padding: 8px 16px; border: none; background: none; color: var(--text-muted);
    font-size: 13px; font-weight: 600; border-radius: var(--radius-sm);
    cursor: pointer; white-space: nowrap; transition: all 0.2s;
}
.tab-btn:hover { color: var(--text-main); background: rgba(0,0,0,0.05); }
.tab-btn.active { color: white; background: var(--primary); box-shadow: var(--shadow-sm); }
.tab-panel { display: none; animation: fadeIn 0.3s ease; }
.tab-panel.active { display: block; }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

/* Login Page */
.login-wrapper { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.login-card { width: 100%; max-width: 400px; padding: 32px; text-align: center; }

/* Utility */
.mb-4 { margin-bottom: 16px; }
.text-right { text-align: right; }
.text-center { text-align: center; }
.hidden { display: none !important; }
.flex { display: flex; }
.gap-2 { gap: 8px; }

/* Print Styles for Manifests */
@media print {
    body { background: white !important; }
    .app-header, .filter-bar, .tabs-bar, .page-title-row button { display: none !important; }
    .glass-panel { border: none !important; box-shadow: none !important; padding: 0 !important; }
    .main-content { padding: 0 !important; margin: 0 !important; max-width: 100% !important; }
    
    .manifest-page {
        page-break-after: always;
        padding: 20px;
    }
    .manifest-page:last-child {
        page-break-after: avoid;
    }
    .manifest-header {
        border-bottom: 2px solid #000;
        margin-bottom: 20px;
        padding-bottom: 10px;
    }
    .manifest-table {
        width: 100%;
        border-collapse: collapse;
        margin-bottom: 30px;
    }
    .manifest-table th, .manifest-table td {
        border-bottom: 1px solid #ddd;
        padding: 8px;
        text-align: left;
    }
    .manifest-table th { border-bottom: 2px solid #000; }
    
    .signature-row {
        display: flex;
        justify-content: space-between;
        margin-top: 60px;
    }
    .sig-line {
        border-top: 1px solid #000;
        width: 200px;
        text-align: center;
        padding-top: 5px;
    }
}
