/* Prevent padding/border from ever pushing elements past 100% width (avoids horizontal scroll) */
*,
*::before,
*::after {
    box-sizing: border-box;
}

/* Define B Yekan font-face */
@font-face {
    font-family: 'BYekan';
    src: url('assets/fonts/Sahel-Bold.woff2') format('woff2'); /* Using Sahel-Bold as a common Persian web font, often used for B Yekan replacement. */
    font-weight: bold;
    font-style: normal;
}
@font-face {
    font-family: 'BYekan';
    src: url('assets/fonts/Sahel-Regular.woff2') format('woff2'); /* Using Sahel-Regular as a common Persian web font, often used for B Yekan replacement. */
    font-weight: normal;
    font-style: normal;
}


/* Custom styles for enhanced aesthetics */
body {
    font-family: 'BYekan', 'Inter', sans-serif; /* Apply BYekan first, then Inter as fallback */
    background: linear-gradient(to bottom right, #f3f4f6, #e5e7eb);
    /* Subtle gradient background */
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
}

.container {
    background-color: #ffffff;
    border-radius: 1.5rem;
    /* More rounded corners */
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
    /* Stronger shadow */
    padding: 2.5rem;
    /* More padding */
    max-width: 60rem;
    /* Wider container */
    width: 100%;
    border: 1px solid rgba(229, 231, 235, 0.6);
    /* Light border */
}

h1 {
    color: #1f2937;
    /* Darker gray for headings */
    font-size: 2.5rem;
    /* Larger heading */
    margin-bottom: 2rem;
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.05);
    /* Subtle text shadow */
}

h2 {
    color: #374151;
    /* Slightly lighter gray for subheadings */
    font-size: 1.75rem;
    margin-bottom: 1.5rem;
    border-bottom: 2px solid #e5e7eb;
    /* Subtle underline */
    padding-bottom: 0.75rem;
}

/* Card-like sections */
.card-section {
    background-color: #f9fafb;
    /* Lighter background for sections */
    border: 1px solid #e5e7eb;
    border-radius: 1rem;
    /* Rounded corners for cards */
    padding: 1.5rem;
    margin-bottom: 1.5rem;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
    /* Soft shadow for cards */
    transition: transform 0.2s ease-in-out, box-shadow 0.2s ease-in-out;
}

.card-section:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 12px rgba(0, 0, 0, 0.1);
}

label {
    font-weight: 600;
    /* Bolder labels */
    color: #4b5563;
    margin-bottom: 0.5rem;
}

input[type="text"],
input[type="number"],
select {
    padding: 0.75rem;
    /* More padding for inputs */
    border: 1px solid #d1d5db;
    border-radius: 0.75rem;
    /* More rounded inputs */
    background-color: #ffffff;
    box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.05);
    /* Inner shadow for depth */
    transition: border-color 0.2s ease-in-out, box-shadow 0.2s ease-in-out;
}

input[type="text"]:focus,
input[type="number"]:focus,
select:focus {
    border-color: #6366f1;
    /* Primary-500 */
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.2);
    /* Focus ring */
    outline: none;
}

/* Range input (slider) - Custom styling for thumb and track */
input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    background: transparent;
    cursor: pointer;
    height: 0.75rem;
    /* Slightly thicker track */
}

input[type="range"]::-webkit-slider-runnable-track {
    background: #d1d5db;
    /* Gray-300 */
    border-radius: 0.5rem;
    height: 0.75rem;
    box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.05);
}

input[type="range"]::-moz-range-track {
    background: #d1d5db;
    border-radius: 0.5rem;
    height: 0.75rem;
    box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.05);
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    margin-top: -0.625rem;
    /* Adjust to center thumb vertically (0.75/2 + 0.5rem) */
    background-color: #6366f1;
    /* Primary-500 */
    border: 4px solid #ffffff;
    /* Thicker white border */
    border-radius: 9999px;
    height: 1.5rem;
    /* Larger thumb */
    width: 1.5rem;
    box-shadow: 0 3px 6px rgba(0, 0, 0, 0.25);
    /* Stronger thumb shadow */
    transition: background-color 0.2s ease-in-out, box-shadow 0.2s ease-in-out;
}

input[type="range"]::-moz-range-thumb {
    background-color: #6366f1;
    border: 4px solid #ffffff;
    border-radius: 9999px;
    height: 1.5rem;
    width: 1.5rem;
    box-shadow: 0 3px 6px rgba(0, 0, 0, 0.25);
    transition: background-color 0.2s ease-in-out, box-shadow 0.2s ease-in-out;
}

input[type="range"]:focus::-webkit-slider-thumb {
    box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.4);
    /* Primary-500 focus ring */
}

input[type="range"]:focus::-moz-range-thumb {
    box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.4);
}

/* Buttons - Enhanced with custom shadows, gradients, and hover effects */
button {
    padding: 0.8rem 1.8rem;
    /* More padding */
    font-size: 1.1rem;
    /* Larger font size */
    font-weight: 700;
    /* Bolder text */
    border-radius: 0.75rem;
    /* More rounded */
    transition: all 0.3s ease-in-out;
    cursor: pointer;
    border: none;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
    /* Subtle text shadow on buttons */
}

#addSubjectButton {
    background-image: linear-gradient(to right, #22c55e, #16a34a);
    /* Accent-500 to Accent-600 */
    box-shadow: 0 6px 12px rgba(34, 197, 94, 0.4);
}

#addSubjectButton:hover {
    background-image: linear-gradient(to right, #16a34a, #15803d);
    box-shadow: 0 8px 16px rgba(34, 197, 94, 0.5);
    transform: translateY(-3px) scale(1.02);
    /* More pronounced hover effect */
}

/* Let the three action buttons wrap onto their own lines on narrow screens
   instead of forcing horizontal scroll on the whole page. */
.action-buttons-row {
    flex-wrap: wrap;
    row-gap: 0.75rem;
}

#calculateButton,
#savePlanButton,
#loadPlanButton {
    /* Common styles for all three buttons */
    padding: 0.8rem 1.8rem;
    font-size: 1.1rem;
    font-weight: 700;
    border-radius: 0.75rem;
    transition: all 0.3s ease-in-out;
    cursor: pointer;
    border: none;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
    color: white; /* Ensure text is white for contrast */
    flex: 1 1 100%; /* Full width by default (small screens) */
    min-width: 0;
}

@media (min-width: 480px) {
    #calculateButton,
    #savePlanButton,
    #loadPlanButton {
        flex: 1 1 0; /* Share the row equally once there's enough width */
    }
}

/* Specific styles for each button */
#calculateButton {
    background-image: linear-gradient(to right, #6366f1, #4f46e5); /* Primary-500 to Primary-600 (Blue) */
    box-shadow: 0 6px 12px rgba(99, 102, 241, 0.4);
}

#calculateButton:hover {
    background-image: linear-gradient(to right, #4f46e5, #4338ca); /* Darker blue on hover */
    box-shadow: 0 8px 16px rgba(99, 102, 241, 0.5);
    transform: translateY(-3px) scale(1.02);
}

#savePlanButton {
    background-image: linear-gradient(to right, #22c55e, #16a34a); /* Accent-500 to Accent-600 (Green) */
    box-shadow: 0 6px 12px rgba(34, 197, 94, 0.4);
}

#savePlanButton:hover {
    background-image: linear-gradient(to right, #16a34a, #15803d); /* Darker green on hover */
    box-shadow: 0 8px 16px rgba(34, 197, 94, 0.5);
    transform: translateY(-3px) scale(1.02);
}

#loadPlanButton {
    background-image: linear-gradient(to right, #ec4899, #db2777); /* Secondary-500 to Secondary-600 (Pink) */
    box-shadow: 0 6px 12px rgba(236, 72, 153, 0.4);
}

#loadPlanButton:hover {
    background-image: linear-gradient(to right, #db2777, #be185d); /* Darker pink on hover */
    box-shadow: 0 8px 16px rgba(236, 72, 153, 0.5);
    transform: translateY(-3px) scale(1.02);
}

#printButton {
    background-image: linear-gradient(to right, #ec4899, #db2777);
    /* Secondary-500 to Secondary-600 */
    box-shadow: 0 6px 12px rgba(236, 72, 153, 0.4);
    border-radius: 0.25rem; /* Made more rectangular */
}

#printButton:hover {
    background-image: linear-gradient(to right, #db2777, #be185d);
    box-shadow: 0 8px 16px rgba(236, 72, 153, 0.5);
    transform: translateY(-3px) scale(1.02);
}


/* Subject Box Styling */
.subject-box {
    background-color: #ffffff;
    border: 1px solid #e0e7ff;
    /* Lighter primary border */
    padding: 1.5rem;
    border-radius: 1rem;
    box-shadow: 0 5px 10px rgba(0, 0, 0, 0.08);
    transition: all 0.2s ease-in-out;
    position: relative;
    /* For remove button positioning */
}

.subject-box:hover {
    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.12);
    transform: translateY(-2px);
}

.subject-box h3 {
    font-size: 1.5rem;
    font-weight: 700;
    color: #374151;
    margin-bottom: 1rem;
    border-bottom: 2px solid #c7d2fe;
    /* Primary-200 underline */
    padding-bottom: 0.75rem;
}

.subject-box .remove-subject-button {
    position: absolute;
    top: 1rem;
    left: 1rem;
    /* Position on the left for RTL */
    background-color: #ef4444;
    /* Red-500 */
    color: white;
    padding: 0.5rem 0.8rem;
    font-size: 0.9rem;
    border-radius: 0.5rem;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    transition: background-color 0.2s ease-in-out, transform 0.2s ease-in-out;
}

.subject-box .remove-subject-button:hover {
    background-color: #dc2626;
    /* Red-600 */
    transform: scale(1.05);
}

.subject-box .resource-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    /* Spacing between buttons */
    margin-top: 1rem;
    margin-bottom: 1.5rem;
}

.subject-box .resource-buttons button {
    background-color: #4b5563;
    /* Gray-700 */
    color: white;
    padding: 0.7rem 1.2rem;
    border-radius: 0.6rem;
    font-weight: 600;
    font-size: 0.95rem;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.15);
    flex-grow: 1;
    /* Allow buttons to grow */
    text-align: center;
}

.subject-box .resource-buttons button:hover {
    background-color: #1f2937;
    /* Gray-800 */
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

/* Study Inputs within Subject Box */
.study-inputs {
    margin-top: 1.5rem;
    padding-top: 1.5rem;
    border-top: 2px dashed #e0e7ff;
    /* Primary-100 dashed border */
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 1.5rem;
    /* More gap */
    background-color: #f0f3ff;
    /* Lighter primary background */
    padding: 1.5rem;
    border-radius: 0.75rem;
}

.study-inputs .resource-box {
    background-color: #ffffff;
    border: 1px solid #d1d5db;
    border-radius: 0.75rem;
    padding: 1rem;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
    position: relative;
}

/* Small colored tag showing the resource type on its summary card */
.resource-type-badge {
    align-self: flex-start;
    background-color: #e0e7ff;
    /* Primary-100 */
    color: #4338ca;
    /* Primary-700 */
    font-size: 0.75rem;
    font-weight: 700;
    padding: 0.2rem 0.6rem;
    border-radius: 9999px;
}

.resource-summary-text {
    color: #374151;
    font-size: 0.9rem;
    line-height: 1.6;
    margin: 0;
}

.resource-box-actions {
    display: flex;
    gap: 0.6rem;
    margin-top: 0.25rem;
}

.study-inputs .resource-box .edit-resource-button,
.study-inputs .resource-box .remove-resource-button {
    padding: 0.5rem 1rem;
    font-size: 0.85rem;
    font-weight: 600;
    border-radius: 0.5rem;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    border: none;
    cursor: pointer;
    flex: 1;
    transition: background-color 0.2s ease-in-out, transform 0.2s ease-in-out;
}

.study-inputs .resource-box .edit-resource-button {
    background-color: #6366f1;
    /* Primary-500 */
    color: white;
}

.study-inputs .resource-box .edit-resource-button:hover {
    background-color: #4f46e5;
    /* Primary-600 */
    transform: scale(1.02);
}

.study-inputs .resource-box .remove-resource-button {
    background-color: #ef4444;
    /* Red-500 */
    color: white;
}

.study-inputs .resource-box .remove-resource-button:hover {
    background-color: #dc2626;
    /* Red-600 */
    transform: scale(1.02);
}


/* Table Styling */
#studyPlanTable {
    width: 100%;
    border-collapse: separate;
    /* For rounded corners */
    border-spacing: 0;
    margin-top: 2rem;
    border: 1px solid #e0e7ff; /* Primary-100 border */
    border-radius: 1rem;
    overflow: hidden;
    /* Ensures rounded corners apply */
    box-shadow: 0 10px 15px rgba(0, 0, 0, 0.1);
}

#studyPlanTable thead {
    background-color: #e0e7ff;
    /* Primary-100 */
}

#studyPlanTable th {
    padding: 1rem 1.25rem;
    border-bottom: 1px solid #c7d2fe;
    /* Primary-200 */
    text-align: right;
    font-size: 0.95rem;
    font-weight: 700;
    color: #4338ca;
    /* Primary-700 */
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

#studyPlanTable tbody tr:nth-child(even) {
    background-color: #f8faff;
}

#studyPlanTable tbody tr:hover {
    background-color: #eef2ff;
    /* Primary-50 on hover */
    transition: background-color 0.2s ease-in-out;
}

#studyPlanTable td {
    padding: 1rem 1.25rem;
    border-bottom: 1px solid #eef2ff;
    /* Primary-50 */
    color: #374151;
    font-size: 0.9rem;
}

/* Message Styling (for welcome and user feedback) */
.message {
    padding: 1rem 1.5rem;
    border-radius: 0.75rem;
    font-weight: 600;
    margin-top: 1.5rem;
    text-align: center;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    animation: fadeIn 0.5s ease-out;
}

.green-message {
    background-color: #dcfce7;
    /* Accent-100 */
    color: #14532d;
    /* Accent-800 */
    border: 1px solid #86efad;
    /* Accent-300 */
}

.yellow-message {
    background-color: #fffbeb;
    /* Yellow-100 */
    color: #b45309;
    /* Yellow-800 */
    border: 1px solid #fcd34d;
    /* Yellow-400 */
}

.red-message {
    background-color: #fee2e2;
    /* Red-100 */
    color: #991b1b;
    /* Red-800 */
    border: 1px solid #f87171;
    /* Red-400 */
}

/* Modal Styling */
.modal {
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.6);
    /* Darker overlay */
    display: flex;
    justify-content: center;
    align-items: center;
    /* Exactly 10px of breathing room from every screen edge */
    padding: 10px;
    box-sizing: border-box;
    animation: fadeIn 0.3s ease-out;
}

.modal-content {
    background-color: white;
    padding: 2.5rem;
    /* More padding */
    border-radius: 1.25rem;
    /* More rounded */
    box-shadow: 0 15px 30px rgba(0, 0, 0, 0.3);
    /* Stronger shadow */
    max-width: 600px;
    /* Wider modal */
    width: 100%;
    min-width: 0;
    /* Allow the flex item to shrink below its content's natural width on very narrow screens */
    /* Include padding/border in the width so it never overflows the 10px gutter */
    box-sizing: border-box;
    text-align: right;
    position: relative;
    /* Fits within the viewport height minus the 10px top/bottom gutter, scrolling only vertically if needed */
    max-height: calc(100vh - 20px);
    overflow-y: auto;
    overflow-x: hidden;
    animation: slideInFromTop 0.4s ease-out;
}

/* Tighter padding on small screens so form fields always fit without horizontal scroll */
@media (max-width: 480px) {
    .modal-content {
        padding: 1.25rem;
        border-radius: 1rem;
    }

    .modal-content h3 {
        font-size: 1.35rem;
        margin-bottom: 1.25rem;
    }
}

.modal-content h3 {
    font-size: 1.75rem;
    font-weight: 700;
    color: #333;
    margin-bottom: 2rem;
    text-align: center;
    border-bottom: 2px solid #e0e7ff;
    padding-bottom: 1rem;
}

.modal-content label {
    margin-bottom: 0.75rem;
    font-weight: 600;
    color: #555;
    display: block;
    /* Ensure label is block for proper spacing */
}

.modal-content input[type="text"],
input[type="number"],
select {
    margin-bottom: 1.5rem;
    padding: 0.8rem;
    border-radius: 0.75rem;
    border: 1px solid #d1d5db;
    width: 100%;
    box-sizing: border-box;
    /* Include padding and border in element's total width and height */
}

.modal-content .modal-buttons {
    display: flex;
    justify-content: flex-end;
    /* Align buttons to the left for RTL */
    gap: 1rem;
    margin-top: 2rem;
}

.modal-content .modal-buttons button {
    padding: 0.8rem 1.8rem;
    border-radius: 0.75rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease-in-out;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.modal-content .modal-buttons button.save-button {
    background-color: #22c55e;
    /* Accent-500 */
    color: white;
}

.modal-content .modal-buttons button.save-button:hover {
    background-color: #16a34a;
    /* Accent-600 */
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

.modal-content .modal-buttons button.close-button {
    background-color: #ef4444;
    /* Red-500 */
    color: white;
}

.modal-content .modal-buttons button.close-button:hover {
    background-color: #dc2626;
    /* Red-600 */
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

/* Animations */
@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

@keyframes slideInFromTop {
    from {
        transform: translateY(-50px);
        opacity: 0;
    }

    to {
        transform: translateY(0);
        opacity: 1;
    }
}

/* New style for deficit display */
.deficit-box {
    display: inline-block;
    background-color: #fee2e2;
    /* Red-100 */
    color: #991b1b;
    /* Red-800 */
    border: 1px solid #f87171;
    /* Red-400 */
    padding: 0.25rem 0.5rem;
    border-radius: 0.5rem;
    margin-right: 0.5rem;
    /* For RTL, margin-left for LTR */
    font-size: 0.85rem;
    font-weight: 600;
}

/* Slider container needs extra top room for the "above" labels row */
.slider-container {
    margin-top: 1.75rem;
    padding-bottom: 0.25rem;
}

/* Row holding the minus button, the slider, and the plus button */
.slider-with-steppers {
    display: flex;
    align-items: center;
    gap: 0.6rem;
}

.slider-with-steppers input[type="range"] {
    flex: 1 1 auto;
    min-width: 0;
    /* Prevents the range input from overflowing its flex container */
}

/* Plus/minus stepper buttons for all lever (اهرم) sliders */
.stepper-btn {
    flex: 0 0 auto;
    width: 2.25rem;
    height: 2.25rem;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
    line-height: 1;
    font-weight: 700;
    border-radius: 9999px;
    border: none;
    cursor: pointer;
    color: #ffffff;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.15);
    transition: transform 0.15s ease-in-out, box-shadow 0.15s ease-in-out, background-color 0.15s ease-in-out;
}

.stepper-btn:active {
    transform: scale(0.92);
}

.stepper-minus {
    background-color: #ef4444;
    /* Red-500 */
}

.stepper-minus:hover {
    background-color: #dc2626;
    /* Red-600 */
}

.stepper-plus {
    background-color: #22c55e;
    /* Accent-500 */
}

.stepper-plus:hover {
    background-color: #16a34a;
    /* Accent-600 */
}

/* Styles for slider labels */
.slider-labels {
    position: absolute;
    width: 100%;
    display: flex;
    justify-content: space-between;
    pointer-events: none;
    /* Allow clicks to pass through to slider if needed, but we'll add click handlers to labels themselves */
    font-size: 0.75rem;
    color: #16a34a;
    /* Changed to green (Accent-600) */
}

/* Half-hour marks (e.g. 0:30, 1:30) appear ABOVE the slider track */
.slider-labels-above {
    top: -1.6rem;
}

/* Whole-hour marks (e.g. 0:00, 1:00) appear BELOW the slider track */
.slider-labels-below {
    top: 1.6rem;
}

.slider-label {
    position: absolute;
    transform: translateX(50%);
    /* Adjusted for RTL to center correctly with 'right' */
    cursor: pointer;
    pointer-events: auto;
    /* Make labels clickable */
    background-color: transparent;
    /* Changed to transparent */
    padding: 0.2rem 0.4rem;
    border-radius: 0.3rem;
    border: 1px solid transparent;
    /* Changed to transparent */
    transition: background-color 0.2s, color 0.2s, border-color 0.2s;
}

.slider-label:hover {
    background-color: #dcfce7;
    /* Light green on hover */
    color: #15803d;
    /* Darker green on hover */
    border-color: #86efad;
    /* Green border on hover */
}

/* Style for PDF logo container */
.pdf-header-content {
    position: relative;
    /* Ensure absolute positioning of children works relative to this */
    width: 100%;
    padding-top: 1rem;
    /* Add some padding at the top */
    padding-bottom: 1rem;
    /* Add some padding at the bottom */
}

.pdf-logo-small {
    position: absolute;
    top: 1rem;
    /* Distance from the top */
    left: 1rem;
    /* Distance from the left (for RTL) */
    width: 50px;
    /* Smaller width */
    height: 50px;
    /* Smaller height */
    object-fit: contain;
    z-index: 10;
}
