:root {
    --moi-sky: #6DD0F7;
    --moi-sky-light: #E8F7FD;
    --moi-navy: #03447A;
    --moi-navy-mid: #045A9E;
    --moi-navy-light: #056BB8;
    --moi-gold: #BBA616;
    --moi-gold-light: #D4BE2A;
    --moi-gold-dark: #8F820F;
    --primary: #03447A;
    --primary-light: #056BB8;
    --primary-dark: #02325A;
    --accent: #BBA616;
    --accent-light: #D4BE2A;
    --success: #1E7B34;
    --danger: #CE1126;
    --warning: #c05621;
    --info: #6DD0F7;
    --bg: #F0FAFE;
    --surface: #ffffff;
    --border: #A8DDF0;
    --text: #03447A;
    --text-muted: #4A6278;
    --shadow: 0 1px 3px rgba(3, 68, 122, 0.1), 0 1px 2px rgba(3, 68, 122, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(3, 68, 122, 0.12), 0 4px 6px -2px rgba(3, 68, 122, 0.06);
    --radius: 8px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: 'Cairo', 'Tajawal', sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    line-height: 1.6;
}

/* Navbar */
.navbar {
    background: var(--primary);
    color: white;
    padding: 0.75rem 2rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: var(--shadow-lg);
    position: sticky;
    top: 0;
    z-index: 100;
}

.nav-brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.brand-icon { font-size: 1.8rem; }

.nav-brand strong { display: block; font-size: 1.1rem; }
.nav-brand small { display: block; font-size: 0.75rem; opacity: 0.8; }

.nav-links {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.nav-links a {
    color: rgba(255,255,255,0.85);
    text-decoration: none;
    padding: 0.4rem 0.9rem;
    border-radius: var(--radius);
    font-size: 0.9rem;
    transition: background 0.2s;
}

.nav-links a:hover, .nav-links a.active {
    background: rgba(255,255,255,0.15);
    color: white;
}

.nav-user {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: 0.9rem;
}

.user-badge {
    background: var(--accent);
    color: var(--primary-dark);
    padding: 0.2rem 0.6rem;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 700;
}

/* Container */
.container {
    max-width: 1200px;
    width: 100%;
    margin: 0 auto;
    padding: 2rem 1.5rem;
    flex: 1;
}

/* Cards */
.card {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
    border: 1px solid var(--border);
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.25rem;
    padding-bottom: 0.75rem;
    border-bottom: 2px solid var(--border);
}

.card-header h2, .card-header h3 {
    color: var(--primary);
    font-weight: 700;
}

/* Stats Grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    margin-bottom: 2rem;
}

.stat-card {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 1.25rem;
    box-shadow: var(--shadow);
    border-right: 4px solid var(--primary);
    text-align: center;
}

.stat-card.accent { border-right-color: var(--accent); }
.stat-card.success { border-right-color: var(--success); }
.stat-card.danger { border-right-color: var(--danger); }
.stat-card.warning { border-right-color: var(--warning); }

.stat-number {
    font-size: 2.5rem;
    font-weight: 800;
    color: var(--primary);
    line-height: 1;
}

.stat-label {
    color: var(--text-muted);
    font-size: 0.9rem;
    margin-top: 0.25rem;
}

/* Buttons */
.btn {
    display: inline-block;
    padding: 0.6rem 1.25rem;
    border-radius: var(--radius);
    font-family: inherit;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    border: 2px solid transparent;
    text-decoration: none;
    transition: all 0.2s;
    text-align: center;
}

.btn-primary {
    background: var(--primary);
    color: white;
}
.btn-primary:hover { background: var(--primary-light); }

.btn-accent {
    background: var(--accent);
    color: var(--primary-dark);
}
.btn-accent:hover { background: var(--accent-light); }

.btn-success { background: var(--success); color: white; }
.btn-danger { background: var(--danger); color: white; }
.btn-warning { background: var(--warning); color: white; }

.btn-outline {
    background: transparent;
    border-color: currentColor;
    color: inherit;
}

.btn-sm { padding: 0.35rem 0.75rem; font-size: 0.8rem; }
.btn-lg { padding: 0.85rem 2rem; font-size: 1rem; }

.btn-group { display: flex; gap: 0.5rem; flex-wrap: wrap; }

/* Forms */
.form-group {
    margin-bottom: 1.25rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.4rem;
    font-weight: 600;
    color: var(--primary);
    font-size: 0.9rem;
}

.form-control {
    width: 100%;
    padding: 0.65rem 0.9rem;
    border: 2px solid var(--border);
    border-radius: var(--radius);
    font-family: inherit;
    font-size: 0.95rem;
    transition: border-color 0.2s;
    background: white;
}

.form-control:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(26,54,93,0.1);
}

textarea.form-control { resize: vertical; min-height: 100px; }

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

@media (max-width: 768px) {
    .form-row { grid-template-columns: 1fr; }
}

/* Tables */
.table-wrapper { overflow-x: auto; }

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

thead { background: var(--primary); color: white; }

th, td {
    padding: 0.75rem 1rem;
    text-align: right;
    border-bottom: 1px solid var(--border);
}

tbody tr:hover { background: #f0f4f8; }

/* Badges */
.badge {
    display: inline-block;
    padding: 0.25rem 0.65rem;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 700;
}

.badge-success { background: #c6f6d5; color: var(--success); }
.badge-danger { background: #fed7d7; color: var(--danger); }
.badge-warning { background: #feebc8; color: var(--warning); }
.badge-info { background: #bee3f8; color: var(--info); }
.badge-secondary { background: #e2e8f0; color: var(--text-muted); }
.badge-primary { background: #bee3f8; color: var(--primary); }

/* Alerts */
.alert {
    padding: 0.85rem 1.25rem;
    border-radius: var(--radius);
    margin-bottom: 1rem;
    font-weight: 500;
    border-right: 4px solid;
}

.alert-success { background: #f0fff4; border-color: var(--success); color: var(--success); }
.alert-danger { background: #fff5f5; border-color: var(--danger); color: var(--danger); }
.alert-warning { background: #fffaf0; border-color: var(--warning); color: var(--warning); }
.alert-info { background: #ebf8ff; border-color: var(--info); color: var(--info); }

/* Auth Pages */
.auth-container {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--primary-dark) 0%, var(--primary) 50%, var(--primary-light) 100%);
    padding: 2rem;
}

.auth-card {
    background: white;
    border-radius: 12px;
    padding: 2.5rem;
    width: 100%;
    max-width: 440px;
    box-shadow: var(--shadow-lg);
    border-top: 4px solid var(--moi-gold, #BBA616);
}

.auth-logo {
    text-align: center;
    margin-bottom: 2rem;
}

.auth-logo .moi-brand-logo-lg {
    display: block;
    margin: 0 auto 0.75rem;
    object-fit: contain;
}

.auth-logo .auth-gold-line {
    width: 60px;
    height: 3px;
    background: linear-gradient(135deg, #9A7B1A 0%, #BBA616 50%, #D4BE2A 100%);
    border-radius: 2px;
    margin: 0 auto 1rem;
}

.auth-logo h1 { color: var(--primary); font-size: 1.4rem; margin-top: 0.5rem; }
.auth-logo p { color: var(--text-muted); font-size: 0.85rem; }
.auth-logo .moi-ministry { color: var(--moi-gold-dark, #9a7b1a); font-weight: 700; font-size: 0.9rem; }

/* Page Header */
.page-header {
    margin-bottom: 2rem;
}

.page-header h1 {
    color: var(--primary);
    font-size: 1.75rem;
    font-weight: 800;
}

.page-header p { color: var(--text-muted); margin-top: 0.25rem; }

/* Timeline / Approval Chain */
.approval-chain {
    display: flex;
    gap: 0;
    margin: 1.5rem 0;
    overflow-x: auto;
}

.approval-step {
    flex: 1;
    min-width: 120px;
    text-align: center;
    position: relative;
}

.approval-step:not(:last-child)::after {
    content: '←';
    position: absolute;
    left: -8px;
    top: 20px;
    color: var(--text-muted);
    font-size: 1.2rem;
}

.step-circle {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--border);
    color: var(--text-muted);
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 0.5rem;
    font-weight: 700;
    font-size: 0.85rem;
}

.approval-step.done .step-circle { background: var(--success); color: white; }
.approval-step.active .step-circle { background: var(--accent); color: var(--primary-dark); }
.approval-step.rejected .step-circle { background: var(--danger); color: white; }

.step-label { font-size: 0.75rem; color: var(--text-muted); }

/* QR Display */
.qr-display {
    text-align: center;
    padding: 1.5rem;
}

.qr-display img {
    max-width: 280px;
    width: 100%;
    height: auto;
    border: none;
    border-radius: 18px;
    padding: 0;
    background: white;
    box-shadow: 0 8px 24px rgba(3, 68, 122, 0.18);
}

/* Verification Result */
.verify-result {
    border-radius: var(--radius);
    padding: 2rem;
    text-align: center;
    margin: 1.5rem 0;
}

.verify-result.valid {
    background: #f0fff4;
    border: 2px solid var(--success);
}

.verify-result.invalid {
    background: #fff5f5;
    border: 2px solid var(--danger);
}

.verify-icon { font-size: 4rem; margin-bottom: 1rem; }

.verify-details {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
    text-align: right;
    margin-top: 1.5rem;
    background: white;
    padding: 1.25rem;
    border-radius: var(--radius);
}

.verify-details dt { font-weight: 700; color: var(--primary); }
.verify-details dd { color: var(--text); margin-bottom: 0.5rem; }

/* Footer */
.footer {
    background: var(--primary-dark);
    color: rgba(255,255,255,0.7);
    text-align: center;
    padding: 1rem;
    font-size: 0.85rem;
    margin-top: auto;
    border-top: 3px solid var(--moi-gold, #BBA616);
}

/* Scanner */
#qr-reader {
    width: 100%;
    max-width: 500px;
    margin: 0 auto;
}

/* Empty State */
.empty-state {
    text-align: center;
    padding: 3rem;
    color: var(--text-muted);
}

.empty-state .icon { font-size: 3rem; margin-bottom: 1rem; }

/* Grid Layout */
.grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
}

@media (max-width: 768px) {
    .grid-2 { grid-template-columns: 1fr; }
    .navbar { flex-direction: column; gap: 0.75rem; }
    .nav-links { justify-content: center; }
}

/* Permit Card */
.permit-card {
    border-right: 4px solid var(--primary);
    transition: transform 0.2s, box-shadow 0.2s;
}

.permit-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.permit-card.issued { border-right-color: var(--success); }
.permit-card.pending { border-right-color: var(--warning); }
.permit-card.rejected { border-right-color: var(--danger); }

/* Applicant attachments */
.form-hint {
    color: var(--text-muted);
    font-size: 0.9rem;
}

.employee-toggle {
    background: var(--moi-sky-light);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.85rem 1rem;
    margin-bottom: 1rem;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    cursor: pointer;
    font-weight: 600;
}

.checkbox-label input[type="checkbox"] {
    width: 1.1rem;
    height: 1.1rem;
    accent-color: var(--primary);
}

.attachment-upload-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 1rem 1.25rem;
}

.attachment-field.employee-only {
    display: none;
}

.required-star {
    color: var(--danger);
    margin-right: 0.15rem;
}

.attachment-preview {
    margin-top: 0.65rem;
}

.attachment-preview img {
    max-width: 100%;
    max-height: 140px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    object-fit: contain;
    background: #fff;
}

.attachment-gallery {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 1rem;
    padding: 1rem;
}

.attachment-item {
    background: var(--moi-sky-light);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.75rem;
    text-align: center;
}

.attachment-label {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--primary);
    margin-bottom: 0.65rem;
    min-height: 2.5rem;
}

.attachment-thumb-link {
    display: block;
}

.attachment-thumb {
    width: 100%;
    max-height: 160px;
    object-fit: contain;
    border-radius: 6px;
    border: 1px solid var(--border);
    background: #fff;
}

@media (max-width: 768px) {
    .attachment-upload-grid {
        grid-template-columns: 1fr;
    }
}
