/**
 * University of Kerbala - Department of Information Technology Engineering
 * Native Mobile App Stylesheet (PWA / Mobile-First Experience)
 * 2026 - 2027
 */

@import url('https://fonts.googleapis.com/css2?family=Cairo:wght@400;600;700;800;900&display=swap');

:root {
    --primary: #0a2540;
    --primary-light: #153e6c;
    --primary-dark: #06182b;
    --secondary: #10b981;
    --secondary-hover: #059669;
    --accent: #f59e0b;
    --bg-page: #0f172a;
    --app-bg: #f8fafc;
    --card-bg: #ffffff;
    --text-primary: #0f172a;
    --text-secondary: #64748b;
    --text-muted: #94a3b8;
    --border-light: #e2e8f0;
    --border-subtle: #cbd5e1;
    --shadow-sm: 0 2px 4px rgba(0,0,0,0.04);
    --shadow-md: 0 4px 14px rgba(0,0,0,0.08);
    --shadow-lg: 0 10px 30px rgba(0,0,0,0.12);
    --safe-bottom: env(safe-area-inset-bottom, 16px);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

html, body {
    width: 100%;
    height: 100%;
    overflow-x: hidden;
    background-color: var(--bg-page);
    font-family: 'Cairo', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    direction: rtl;
    text-align: right;
    color: var(--text-primary);
}

/* ======================================================== */
/* MOBILE APP CONTAINER SHELL                               */
/* ======================================================== */
.mobile-app-shell {
    width: 100%;
    max-width: 500px;
    height: 100vh;
    height: 100dvh;
    margin: 0 auto;
    background-color: var(--app-bg);
    display: flex;
    flex-direction: column;
    position: relative;
    box-shadow: 0 0 50px rgba(0, 0, 0, 0.5);
    overflow: hidden;
}

@media (max-width: 520px) {
    .mobile-app-shell {
        max-width: 100%;
        border-radius: 0;
        box-shadow: none;
    }
}

/* Top App Header */
.app-top-header {
    background: linear-gradient(135deg, #06182b 0%, #0a2540 100%);
    color: #ffffff;
    padding: 14px 18px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.15);
    z-index: 40;
    flex-shrink: 0;
}

.app-brand {
    display: flex;
    align-items: center;
    gap: 12px;
}

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

.app-brand-text h1 {
    font-size: 1rem;
    font-weight: 800;
    line-height: 1.25;
    color: #ffffff;
    margin: 0;
}

.app-brand-text p {
    font-size: 0.75rem;
    color: #94a3b8;
    margin: 2px 0 0;
}

.app-header-pill {
    background: rgba(245, 158, 11, 0.18);
    border: 1px solid rgba(245, 158, 11, 0.4);
    color: #f59e0b;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 0.72rem;
    font-weight: 800;
    white-space: nowrap;
}

/* Scrollable Views Container */
.app-scroll-content {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 16px 16px 85px; /* bottom pad for bottom dock */
}

/* Views Navigation Switching */
.app-view {
    display: none;
    animation: fadeInView 0.25s ease forwards;
}

.app-view.active-view {
    display: block;
}

@keyframes fadeInView {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Bottom App Navigation Dock (iOS / Android Style) */
.bottom-app-dock {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-top: 1px solid rgba(226, 232, 240, 0.8);
    display: flex;
    justify-content: space-around;
    align-items: center;
    padding: 8px 6px calc(var(--safe-bottom) + 4px);
    z-index: 50;
    box-shadow: 0 -4px 16px rgba(0,0,0,0.05);
}

.bottom-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-family: inherit;
    font-size: 0.72rem;
    font-weight: 700;
    padding: 4px 8px;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.2s ease;
    position: relative;
    text-decoration: none;
    min-width: 60px;
}

.bottom-nav-item svg {
    width: 22px;
    height: 22px;
    margin-bottom: 2px;
    stroke-width: 2;
    transition: all 0.2s ease;
}

.bottom-nav-item.active {
    color: var(--primary-light);
}

.bottom-nav-item.active svg {
    stroke: var(--primary-light);
    transform: scale(1.1);
}

.nav-badge-pill {
    position: absolute;
    top: -2px;
    right: 10px;
    background: var(--accent);
    color: #000;
    font-size: 0.65rem;
    font-weight: 800;
    padding: 2px 6px;
    border-radius: 10px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.15);
}

.nav-badge-pill.complete {
    background: var(--secondary);
    color: #fff;
}

/* App Native Cards */
.mobile-card {
    background: var(--card-bg);
    border-radius: 16px;
    padding: 18px;
    margin-bottom: 14px;
    border: 1px solid var(--border-light);
    box-shadow: var(--shadow-sm);
}

.mobile-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 14px;
    padding-bottom: 8px;
    border-bottom: 1.5px solid #f1f5f9;
}

.mobile-card-title {
    font-size: 0.98rem;
    font-weight: 800;
    color: var(--primary);
    display: flex;
    align-items: center;
    gap: 8px;
}

.badge-step-dot {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--primary);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    font-weight: 800;
}

/* Home Welcome Banner */
.home-hero-card {
    background: linear-gradient(135deg, #0a2540 0%, #153e6c 100%);
    color: #fff;
    border-radius: 18px;
    padding: 22px 18px;
    margin-bottom: 16px;
    box-shadow: var(--shadow-md);
    position: relative;
    overflow: hidden;
}

.home-hero-card h2 {
    font-size: 1.25rem;
    font-weight: 900;
    margin-bottom: 6px;
    line-height: 1.35;
}

.home-hero-card p {
    font-size: 0.86rem;
    color: #cbd5e1;
    line-height: 1.5;
}

.app-feature-row {
    display: flex;
    align-items: center;
    gap: 10px;
    background: rgba(255, 255, 255, 0.1);
    padding: 10px 14px;
    border-radius: 12px;
    margin-top: 10px;
    font-size: 0.82rem;
    font-weight: 700;
}

.app-feature-row svg {
    color: #34d399;
    flex-shrink: 0;
}

.app-btn-primary {
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
    color: #fff;
    border: none;
    width: 100%;
    padding: 14px 20px;
    border-radius: 14px;
    font-size: 1rem;
    font-weight: 800;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    cursor: pointer;
    box-shadow: 0 4px 14px rgba(16, 185, 129, 0.35);
    transition: all 0.2s;
    font-family: inherit;
    text-decoration: none;
}

.app-btn-primary:active {
    transform: scale(0.98);
}

/* Document Slots Grid (Mobile Friendly) */
.docs-slots-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.doc-slot-card {
    background: #ffffff;
    border: 1.5px solid var(--border-light);
    border-radius: 14px;
    padding: 14px;
    display: flex;
    align-items: center;
    gap: 14px;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: var(--shadow-sm);
}

.doc-slot-card:active {
    background: #f1f5f9;
}

.doc-slot-card.captured {
    border-color: #10b981;
    background: #f0fdf4;
}

.slot-icon-box {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    background: #f1f5f9;
    color: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all 0.2s;
}

.doc-slot-card.captured .slot-icon-box {
    background: #d1fae5;
    color: #059669;
}

.slot-details {
    flex: 1;
    min-width: 0;
}

.slot-title {
    font-size: 0.92rem;
    font-weight: 800;
    color: var(--text-primary);
    margin-bottom: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.slot-subtitle {
    font-size: 0.76rem;
    color: var(--text-secondary);
}

.slot-thumb-container {
    width: 60px;
    height: 48px;
    border-radius: 8px;
    overflow: hidden;
    flex-shrink: 0;
    position: relative;
    border: 1px solid var(--border-light);
    background: #e2e8f0;
}

.slot-preview-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: none;
}

.slot-status-badge {
    font-size: 0.72rem;
    padding: 3px 8px;
    border-radius: 12px;
    font-weight: 700;
    white-space: nowrap;
}

.badge-pending {
    background: #f1f5f9;
    color: var(--text-secondary);
}

.badge-success {
    background: #d1fae5;
    color: #065f46;
}

/* Form Groups & Inputs */
.form-group {
    margin-bottom: 14px;
}

.form-label {
    font-size: 0.85rem;
    font-weight: 800;
    color: var(--text-primary);
    margin-bottom: 6px;
    display: block;
}

.form-label .req {
    color: #ef4444;
}

.form-control {
    width: 100%;
    padding: 12px 14px;
    border: 1.5px solid var(--border-light);
    border-radius: 12px;
    font-size: 0.92rem;
    color: var(--text-primary);
    font-family: inherit;
    background: #ffffff;
    transition: border-color 0.2s, box-shadow 0.2s;
}

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

.autofilled-highlight {
    animation: flashAutofill 2.5s ease;
    border-color: #10b981 !important;
    background-color: #ecfdf5 !important;
}

@keyframes flashAutofill {
    0% { background: #fef08a; }
    50% { background: #d1fae5; }
    100% { background: #ffffff; }
}

/* Radio chips */
.option-chips-container {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.option-chip {
    flex: 1;
    min-width: 90px;
    position: relative;
}

.option-chip input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.option-chip label {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 10px 12px;
    background: #f8fafc;
    border: 1.5px solid var(--border-light);
    border-radius: 12px;
    font-size: 0.85rem;
    font-weight: 700;
    cursor: pointer;
    text-align: center;
    color: var(--text-secondary);
    transition: all 0.2s;
}

.option-chip input:checked + label {
    background: #ecfdf5;
    border-color: #10b981;
    color: #065f46;
    box-shadow: 0 2px 6px rgba(16, 185, 129, 0.15);
}

/* ======================================================== */
/* SMART CAMERA SCANNER MODAL                               */
/* ======================================================== */
.scanner-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    background-color: #000000;
    z-index: 9999;
    display: none;
    flex-direction: column;
}

.scanner-modal.active {
    display: flex;
}

.scanner-top-bar {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    z-index: 20;
    background: linear-gradient(to bottom, rgba(0,0,0,0.85) 0%, rgba(0,0,0,0) 100%);
    padding: 16px 18px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: #ffffff;
}

.scanner-step-counter {
    font-size: 0.75rem;
    color: #f59e0b;
    font-weight: 800;
}

.scanner-step-title {
    font-size: 1rem;
    font-weight: 900;
}

.scanner-top-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.scanner-auto-pill {
    background: rgba(16, 185, 129, 0.2);
    border: 1px solid rgba(16, 185, 129, 0.5);
    color: #ffffff;
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 800;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    backdrop-filter: blur(8px);
    font-family: inherit;
    transition: all 0.2s;
}

.scanner-auto-pill:active {
    transform: scale(0.96);
}

.btn-scanner-icon {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: #fff;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    backdrop-filter: blur(8px);
}

.scanner-viewfinder-container {
    position: relative;
    flex: 1;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

#scannerVideo {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.scanner-frame-guide {
    position: absolute;
    border-radius: 16px;
    border: 2px dashed rgba(255, 255, 255, 0.6);
    box-shadow: 0 0 0 4000px rgba(0, 0, 0, 0.65);
    pointer-events: none;
    transition: all 0.3s ease;
}

.scanner-frame-guide.guide-card {
    width: 86vw;
    max-width: 460px;
    height: calc(86vw / 1.585);
    max-height: calc(460px / 1.585);
}

.scanner-frame-guide.guide-document {
    width: 82vw;
    max-width: 400px;
    height: calc(82vw * 1.35);
    max-height: calc(400px * 1.35);
}

.scanner-frame-guide.guide-portrait {
    width: 65vw;
    max-width: 280px;
    height: calc(65vw * 1.25);
    max-height: calc(280px * 1.25);
    border-radius: 50%;
}

.scanner-prompt-badge {
    position: absolute;
    bottom: 110px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(10, 24, 43, 0.85);
    color: #ffffff;
    padding: 8px 18px;
    border-radius: 30px;
    font-size: 0.82rem;
    font-weight: 700;
    text-align: center;
    max-width: 85%;
    backdrop-filter: blur(6px);
    border: 1px solid rgba(255,255,255,0.15);
    z-index: 10;
}

.scanner-bottom-bar {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    z-index: 20;
    background: linear-gradient(to top, rgba(0,0,0,0.85) 0%, rgba(0,0,0,0) 100%);
    padding: 20px 20px 32px;
    display: flex;
    justify-content: space-around;
    align-items: center;
}

.btn-shutter-capture {
    width: 72px;
    height: 72px;
    border-radius: 50%;
    background: #ffffff;
    border: 4px solid rgba(255, 255, 255, 0.5);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 0 20px rgba(255, 255, 255, 0.4);
}

.btn-shutter-capture::after {
    content: '';
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: #10b981;
    transition: all 0.15s ease;
}

.btn-shutter-capture:active {
    transform: scale(0.92);
}

/* ======================================================== */
/* 4-CORNER PERSPECTIVE CROP EDITOR MODAL (CamScanner style)*/
/* ======================================================== */
.crop-editor-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    background-color: #0b1320;
    z-index: 10000;
    display: none;
    flex-direction: column;
}

.crop-editor-modal.active {
    display: flex;
}

.crop-top-bar {
    background: #06182b;
    padding: 14px 18px;
    color: #fff;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid #1e293b;
    z-index: 30;
}

.crop-top-bar h3 {
    font-size: 0.98rem;
    font-weight: 800;
}

.crop-canvas-container {
    flex: 1;
    position: relative;
    width: 100%;
    height: 100%;
    overflow: hidden;
    touch-action: none;
    background: #020617;
}

#cropCanvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

/* Magnifying Loupe Container */
.crop-loupe-container {
    position: absolute;
    width: 130px;
    height: 130px;
    border-radius: 50%;
    border: 3.5px solid #10b981;
    box-shadow: 0 8px 24px rgba(0,0,0,0.6);
    overflow: hidden;
    pointer-events: none;
    display: none;
    z-index: 100;
    background: #000;
}

#cropLoupeCanvas {
    width: 100%;
    height: 100%;
}

/* Crop Controls Toolbar */
.crop-bottom-toolbar {
    background: #06182b;
    padding: 12px 16px calc(var(--safe-bottom) + 8px);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    border-top: 1px solid #1e293b;
    z-index: 30;
}

.crop-tool-btn {
    background: #1e293b;
    color: #cbd5e1;
    border: 1px solid #334155;
    padding: 10px 14px;
    border-radius: 10px;
    font-size: 0.8rem;
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    font-family: inherit;
    transition: all 0.2s;
}

.crop-tool-btn:active {
    background: #334155;
}

.crop-apply-btn {
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
    color: #fff;
    border: none;
    padding: 12px 22px;
    border-radius: 12px;
    font-size: 0.95rem;
    font-weight: 800;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-family: inherit;
    box-shadow: 0 4px 14px rgba(16, 185, 129, 0.4);
}

/* 3D Flip Notice */
.scanner-flip-notice {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(6, 24, 43, 0.95);
    z-index: 50;
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 30px;
    text-align: center;
    color: #ffffff;
    backdrop-filter: blur(10px);
}

.scanner-flip-notice.active {
    display: flex;
}

.flip-card-graphic {
    width: 180px;
    height: 115px;
    margin-bottom: 24px;
    perspective: 1000px;
}

.flip-card-inner {
    width: 100%;
    height: 100%;
    position: relative;
    transform-style: preserve-3d;
    animation: flipCard3D 2.5s infinite ease-in-out;
}

@keyframes flipCard3D {
    0% { transform: rotateY(0deg); }
    50% { transform: rotateY(180deg); }
    100% { transform: rotateY(360deg); }
}

.flip-card-face {
    position: absolute;
    width: 100%;
    height: 100%;
    border-radius: 12px;
    backface-visibility: hidden;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    box-shadow: 0 8px 24px rgba(0,0,0,0.4);
    border: 2px solid rgba(255,255,255,0.3);
}

.flip-card-front {
    background: linear-gradient(135deg, #1e3a8a, #3b82f6);
}

.flip-card-back {
    background: linear-gradient(135deg, #065f46, #10b981);
    transform: rotateY(180deg);
}

.flip-card-chip {
    width: 24px;
    height: 18px;
    background: #fbbf24;
    border-radius: 3px;
    margin-bottom: 6px;
}

.flip-card-line {
    width: 70%;
    height: 5px;
    background: rgba(255,255,255,0.4);
    border-radius: 2px;
    margin: 2px 0;
}

.scanner-flip-notice h3 {
    font-size: 1.3rem;
    font-weight: 800;
    color: #34d399;
    margin-bottom: 8px;
}

.scanner-flip-notice p {
    font-size: 0.92rem;
    color: #cbd5e1;
    margin-bottom: 20px;
    max-width: 340px;
}

/* Loading Overlays */
.scanner-loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    z-index: 60;
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: #fff;
    backdrop-filter: blur(5px);
}

.scanner-loading-overlay.active {
    display: flex;
}

.spinner-border {
    width: 44px;
    height: 44px;
    border: 4px solid rgba(255,255,255,0.2);
    border-top-color: #10b981;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin-bottom: 14px;
}

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

/* Success Modal */
.custom-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    z-index: 9999;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 16px;
    backdrop-filter: blur(5px);
}

.custom-modal.active {
    display: flex;
}

.modal-dialog {
    background: #ffffff;
    border-radius: 20px;
    width: 100%;
    max-width: 460px;
    padding: 28px 20px;
    text-align: center;
    box-shadow: var(--shadow-lg);
}

.success-icon-box {
    width: 64px;
    height: 64px;
    background: #d1fae5;
    color: #059669;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 14px;
}

.registration-code-display {
    background: #f8fafc;
    border: 2px dashed #94a3b8;
    border-radius: 14px;
    padding: 16px;
    margin: 18px 0;
}

.registration-code-display span {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.registration-code-display h3 {
    font-size: 1.6rem;
    color: var(--primary);
    font-family: monospace;
    letter-spacing: 2px;
    margin-top: 4px;
}

/* Toast */
.global-toast {
    position: fixed;
    bottom: calc(var(--safe-bottom) + 75px);
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: #0a2540;
    color: #fff;
    padding: 12px 20px;
    border-radius: 30px;
    font-size: 0.85rem;
    font-weight: 700;
    box-shadow: var(--shadow-lg);
    z-index: 10000;
    opacity: 0;
    transition: all 0.3s ease;
    pointer-events: none;
    white-space: nowrap;
    border: 1px solid rgba(255,255,255,0.15);
}

.global-toast.visible {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}
