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

:root {
    --primary: #0e4834;
    --primary-light: #0e4834;
    --primary-glow: rgba(14, 72, 52, 0.4);
    --secondary: #b9975b;
    --bg-dark: rgb(235, 230, 223);
    --card-bg: rgba(255, 255, 255, 0.95);
    --card-border: rgba(100, 100, 100, 0.2);
    --text-slate: rgb(100, 100, 100);
    --text-light: rgb(64, 68, 70);
    --success: #0e4834;
    --error: #b9975b;
}

.back-home-btn {
    position: absolute;
    top: 1rem;
    right: 1.5rem;
    background: rgba(14, 72, 52, 0.1);
    border: 1px solid rgba(14, 72, 52, 0.2);
    color: #0e4834;
    width: 45px;
    height: 45px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    transition: all 0.3s ease;
    backdrop-filter: blur(5px);
    z-index: 100;
}

.back-home-btn:hover {
    background: #0e4834;
    color: white;
    transform: scale(1.1);
}

.back-home-btn, .back-home-btn:visited {
    color: #0e4834 !important;
}

.back-home-btn:hover:visited {
    color: white !important;
}

@media (max-width: 600px) {
    .back-home-btn {
        width: 30px;
        height: 30px;
        top: 0.5rem;
        right: 0.5rem;
        font-size: 0.75rem;
    }
}

body {
    margin: 0;
    font-family: 'Cairo', 'Tajawal', sans-serif;
    background: rgb(235, 230, 223);
    background-image: 
        radial-gradient(at 0% 0%, rgba(14, 72, 52, 0.15) 0px, transparent 50%),
        radial-gradient(at 100% 100%, rgba(185, 151, 91, 0.15) 0px, transparent 50%),
        radial-gradient(at 50% 0%, rgba(100, 100, 100, 0.1) 0px, transparent 50%);
    color: rgb(64, 68, 70);
    direction: rtl;
    line-height: 1.6;
    min-height: 100vh;
    overflow-x: hidden;
}

/* App Wrapper */
.app-wrapper {
    padding-bottom: 50px;
}

/* Header */
.main-header {
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid rgba(100, 100, 100, 0.2);
    padding: 3rem 5%;
    position: relative;
    overflow: hidden;
    margin-bottom: 30px;
}

.brand {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 25px;
    z-index: 1;
}

.brand i {
    background: #0e4834;
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    filter: drop-shadow(0 0 10px rgba(14, 72, 52, 0.4));
}

.brand-text h1 {
    margin: 0;
    font-weight: 900;
    font-size: 2.2rem;
    background: #0e4834;
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    background-size: 200% auto;
    animation: shine 4s linear infinite;
}

.brand-text p {
    margin: 8px 0 0;
    color: var(--text-slate);
    font-size: 1.1rem;
    font-weight: 500;
}

@keyframes shine {
    to { background-position: 200% center; }
}

/* Layout */
.grid-container {
    display: grid;
    grid-template-columns: 1fr 420px;
    gap: 40px;
    padding: 20px 5%;
    max-width: 1400px;
    margin: auto;
}

/* Cards */
.glass-card {
    background: var(--card-bg);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid rgba(100, 100, 100, 0.3);
    border-radius: 24px;
    box-shadow: 0 4px 30px rgba(0, 0, 0, 0.1);
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    margin-bottom: 30px;
    overflow: hidden;
}

.glass-card:hover {
    transform: translateY(-5px) scale(1.01);
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.12);
    border-color: var(--primary-light);
}

.card-header {
    padding: 20px 30px;
    background: rgba(255, 255, 255, 0.03);
    border-bottom: 1px solid rgba(100, 100, 100, 0.2);
    font-weight: 800;
    color: var(--primary-light);
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 1.1rem;
}

.card-header i { 
    color: var(--secondary); 
    filter: drop-shadow(0 0 5px var(--secondary));
}

.card-body { padding: 30px; }

/* Inputs */
.row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 25px;
}

.dynamic-row {
    margin-bottom: 25px;
    padding-bottom: 15px;
    border-bottom: 1px dashed rgba(100, 100, 100, 0.2);
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.dynamic-inputs-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 25px;
    align-items: end; /* Aligns inputs to the same bottom line */
}

.dynamic-inputs-grid > div {
    display: flex;
    flex-direction: column;
}

.btn-remove-row {
    display: flex;
    justify-content: flex-end; /* Aligns to left in RTL */
    border-top: 1px solid rgba(100, 100, 100, 0.05);
    padding-top: 10px;
}

.btn-remove-icon {
    background: rgba(185, 151, 91, 0.1);
    color: #b9975b;
    border: 1px solid rgba(185, 151, 91, 0.3);
    padding: 6px 12px;
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.3s;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.05); /* Slight elevation */
}

.btn-remove-icon:hover {
    background: rgba(220, 53, 69, 0.1);
    color: rgb(220, 53, 69);
    border-color: rgba(220, 53, 69, 0.3);
    transform: translateY(-2px);
}

.field { margin-bottom: 25px; }

label {
    display: block;
    margin-bottom: 10px;
    font-weight: 600;
    font-size: 0.95rem;
    color: var(--text-slate);
    transition: 0.3s;
}

.styled-input, select {
    width: 100%;
    max-width: 100%;
    padding: 14px 20px;
    background: rgb(255, 255, 255);
    border: 1px solid rgba(100, 100, 100, 0.3);
    border-radius: 12px;
    color: rgb(64, 68, 70);
    font-family: inherit;
    font-size: 1rem;
    transition: all 0.3s ease;
}

.styled-input:focus, select:focus {
    outline: none;
    border-color: #0e4834;
    background: rgba(255, 255, 255, 1);
    box-shadow: 0 0 15px rgba(14, 72, 52, 0.2);
}

select option {
    background: rgb(255, 255, 255);
    color: rgb(64, 68, 70);
}

/* Checkbox specific styles */
input[type="checkbox"] {
    accent-color: var(--primary);
    width: 18px;
    height: 18px;
    cursor: pointer;
}

/* Sticky Sidebar Result Card */
.sticky-card {
    position: sticky;
    top: 40px;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.95) 0%, rgba(248, 250, 252, 0.98) 100%);
    backdrop-filter: blur(20px);
    border: 1px solid rgba(100, 100, 100, 0.25);
    color: rgb(64, 68, 70);
    padding: 60px 30px;
    border-radius: 32px;
    text-align: center;
    box-shadow: 0 25px 50px -12px rgba(0,0,0,0.1), 0 0 30px rgba(14, 72, 52, 0.2);
}

#grand-total {
    font-size: 7rem;
    font-weight: 900;
    background: #0e4834;
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    line-height: 1;
    margin: 20px 0;
    text-shadow: 0 10px 30px rgba(129, 140, 248, 0.3);
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

#grand-total.updated {
    animation: pulseScore 0.4s ease-out;
}

@keyframes pulseScore {
    0% { transform: scale(1); }
    50% { transform: scale(1.1); filter: brightness(1.3); }
    100% { transform: scale(1); }
}

.total-label {
    text-transform: uppercase;
    letter-spacing: 2px;
    font-size: 0.85rem;
    color: var(--text-slate);
    font-weight: 800;
}

.breakdown {
    margin: 40px 0;
    text-align: right;
    border-top: 1px solid rgba(100, 100, 100, 0.2);
    padding-top: 30px;
}

.b-item {
    display: flex;
    justify-content: space-between;
    margin-bottom: 18px;
    padding-bottom: 12px;
    border-bottom: 1px solid rgba(100, 100, 100, 0.2);
}

.b-item span:first-child {
    color: var(--text-slate);
}

.b-item span:last-child {
    font-weight: 800;
    color: var(--primary-light);
}

/* Buttons */
.btn-premium {
    width: 100%;
    padding: 18px;
    border: none;
    border-radius: 14px;
    background: #b9975b;
    color: white;
    font-weight: 800;
    font-size: 1.1rem;
    cursor: pointer;
    transition: all 0.4s;
    box-shadow: 0 10px 20px rgba(14, 72, 52, 0.3);
}

.btn-premium:hover {
    transform: translateY(-4px);
    filter: brightness(1.1);
    box-shadow: 0 20px 30px rgba(14, 72, 52, 0.4);
}

.btn-add {
    background: rgba(14, 72, 52, 0.15);
    color: #0e4834;
    border: 1px solid rgba(14, 72, 52, 0.3);
    padding: 12px 24px;
    border-radius: 10px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.3s;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    margin-top: 10px;
}

.btn-add:hover { 
    background: rgba(14, 72, 52, 0.25);
    box-shadow: 0 0 15px rgba(14, 72, 52, 0.2);
}

.btn-remove {
    background: rgba(185, 151, 91, 0.1);
    color: #b9975b;
    border: 1px solid rgba(185, 151, 91, 0.2);
    padding: 8px 16px;
    border-radius: 8px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.3s;
}

.btn-remove:hover { background: rgba(185, 151, 91, 0.2); }

/* Alerts / Notes */
.info-note {
    margin-top: 20px;
    padding: 16px;
    background: rgba(185, 151, 91, 0.1);
    border-right: 4px solid #b9975b;
    border-radius: 8px;
    font-size: 0.9rem;
    color: rgb(100, 100, 100);
}

.live-info {
    margin-top: 25px;
    padding: 20px;
    background: rgba(14, 72, 52, 0.05);
    border-radius: 16px;
    border: 1px solid rgba(14, 72, 52, 0.2);
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: 800;
}

.live-info span {
    color: var(--primary-light);
    font-size: 1.3rem;
}

/* Scientific Field Exception Box */
#is_st_field_box {
    background: rgba(185, 151, 91, 0.05) !important;
    border: 1px solid rgba(185, 151, 91, 0.2) !important;
}

/* Animations */
@keyframes slideUp {
    from { opacity: 0; transform: translateY(30px); }
    to { opacity: 1; transform: translateY(0); }
}

.glass-card { 
    opacity: 0;
    animation: slideUp 0.8s cubic-bezier(0.22, 1, 0.36, 1) forwards; 
}

.glass-card:nth-child(1) { animation-delay: 0.1s; }
.glass-card:nth-child(2) { animation-delay: 0.2s; }
.glass-card:nth-child(3) { animation-delay: 0.3s; }
.glass-card:nth-child(4) { animation-delay: 0.4s; }

/* Responsive */
@media (max-width: 1100px) {
    .grid-container { grid-template-columns: 1fr; }
    .sticky-card { position: static; margin-top: 40px; padding: 40px 20px; }
}

@media (max-width: 600px) {
    .row { grid-template-columns: 1fr; gap: 15px; }
    .dynamic-inputs-grid { grid-template-columns: 1fr; gap: 15px; }
    .brand { flex-direction: column; gap: 15px; }
    .brand i { font-size: 3rem; }
    .brand-text h1 { font-size: 1.25rem; padding: 0 5px; line-height: 1.4; }
    .brand-text p { font-size: 0.95rem; }
    .main-header { padding: 1.5rem 5%; }
    #grand-total { font-size: 2.5rem; margin: 10px 0; }
    .card-body { padding: 15px; }
    .card-header { padding: 15px 20px; font-size: 0.95rem; }
    .sticky-card { padding: 40px 15px; border-radius: 20px; }
    .total-label { font-size: 0.75rem; }
    .col { width: 100%; }
}

.flatpickr-calendar {
    background: rgb(255, 255, 255) !important;
    border: 1px solid var(--card-border) !important;
    box-shadow: 0 20px 40px rgba(0,0,0,0.1) !important;
}
.flatpickr-day {
    color: var(--text-light) !important;
}
.flatpickr-day:hover {
    background: rgba(14, 72, 52, 0.1) !important;
}
.flatpickr-day.selected {
    background: var(--primary) !important;
    border-color: var(--primary) !important;
    color: rgb(255, 255, 255) !important;
}
.flatpickr-current-month, .flatpickr-weekday,
.flatpickr-months .flatpickr-month,
.flatpickr-current-month .flatpickr-monthDropdown-months,
.flatpickr-current-month input.cur-year {
    color: var(--text-light) !important;
    background: transparent !important;
}
.flatpickr-months .flatpickr-prev-month svg, 
.flatpickr-months .flatpickr-next-month svg {
    fill: var(--text-light) !important;
}
.flatpickr-current-month .flatpickr-monthDropdown-months option {
    color: var(--text-slate) !important;
    background: rgb(255, 255, 255) !important;
}

/* Helper Classes */
.d-none {
    display: none !important;
}

/* --- حالة الطباعة --- */
@media screen {
    .print-only {
        display: none !important;
    }
}
@media print {
    /* 1. إخفاء كل شيء باستخدام visibility */
    body * {
        visibility: hidden !important;
    }

    /* 2. إظهار التقرير وأبنائه فقط */
    #print-report, #print-report * {
        visibility: visible !important;
    }

    /* 3. تنسيق التقرير وتوسيطه */
    #print-report {
        display: block !important;
        position: absolute !important;
        left: 0 !important;
        right: 0 !important;
        top: 0 !important;
        width: 100% !important;
        padding: 60px 80px !important;
        direction: rtl !important;
        box-sizing: border-box !important;
        margin: 0 auto !important;
        background: white !important;
    }
    
    @page {
        size: A4;
        margin: 0 !important;
    }

    .report-title { font-size: 24px !important; color: #0e4834 !important; text-align: center !important; }
    .report-hr { border: 1px solid #0e4834 !important; margin-bottom: 20px !important; }
    .report-intro { font-size: 14px !important; line-height: 1.6 !important; margin-bottom: 30px !important; }
    .report-grid { display: flex !important; gap: 20px !important; margin-bottom: 20px !important; flex-wrap: wrap !important; }
    .report-box { flex: 1; min-width: 45% !important; border: 1px solid rgb(100, 100, 100) !important; padding: 15px !important; border-radius: 8px !important; box-sizing: border-box !important; }
    .report-box-label { font-weight: bold !important; margin-bottom: 10px !important; color: rgb(64, 68, 70) !important; }
    .report-box-value { font-size: 18px !important; font-weight: 900 !important; color: #0e4834 !important; }
    .report-total-box { border: 2px solid #0e4834 !important; background: rgba(14, 72, 52, 0.1) !important; -webkit-print-color-adjust: exact !important; print-color-adjust: exact !important; padding: 20px !important; font-size: 20px !important; font-weight: bold !important; border-radius: 8px !important; text-align: center !important; margin-top: 30px !important; box-sizing: border-box !important; }
}

/* ===== FAB: Floating Action Button ===== */
.fab-container {
    position: fixed;
    bottom: 30px;
    right: 30px;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 15px;
}

.fab-button {
    width: 65px;
    height: 65px;
    background: #0e4834;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 24px;
    box-shadow: 0 10px 25px rgba(14, 72, 52, 0.4);
    cursor: pointer;
    transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    border: 2px solid rgba(255, 255, 255, 0.2);
}

.fab-button:hover {
    transform: scale(1.1) rotate(15deg);
    box-shadow: 0 15px 35px rgba(14, 72, 52, 0.6);
}

.fab-menu {
    display: flex;
    flex-direction: column;
    gap: 10px;
    opacity: 0;
    transform: translateY(20px) scale(0.8);
    pointer-events: none;
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    transform-origin: bottom right;
}

.fab-container.active .fab-menu {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: all;
}

.fab-item {
    display: flex;
    align-items: center;
    gap: 12px;
    background: white;
    padding: 10px 18px;
    border-radius: 16px;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
    cursor: pointer;
    transition: all 0.2s;
    border: 1px solid rgba(14, 72, 52, 0.1);
    white-space: nowrap;
    color: rgb(64, 68, 70);
    text-decoration: none;
}

.fab-item:hover {
    background: #0e4834;
    color: white;
    transform: translateX(-10px);
}

.fab-item i {
    font-size: 1.2rem;
    color: #b9975b;
}

.fab-item:hover i {
    color: white;
}

.fab-label {
    font-weight: 700;
    font-size: 0.85rem;
}
