/* الأساسيات */
* {
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    direction: rtl;
    background: #f6f6f6;
    margin: 0;
    padding: 0;
    line-height: 1.6;
}

.container {
    width: 95%;
    max-width: 1200px;
    margin: 10px auto;
    background: white;
    padding: 15px;
    border-radius: 10px;
    box-shadow: 0 0 5px rgba(0,0,0,0.2);
}

h2 {
    text-align: center;
    margin-top: 5px;
    margin-bottom: 15px;
    color: #333;
}

/* قسم الإعدادات */
.settings-section {
    background: #e8f4f8;
    padding: 5px;
    border-radius: 8px;
    margin-bottom: 3px;
    border: 2px solid #4a6fa5;
    max-height: 60px;
}

.setting-item {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.setting-item-display {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 15px;
}

.setting-item-display label {
    font-weight: bold;
    color: #333;
    font-size: 16px;
}

.setting-item-display span {
    font-size: 18px;
    color: #4a6fa5;
    font-weight: bold;
    background: white;
    padding: 5px 15px;
    border-radius: 5px;
    border: 2px solid #4a6fa5;
}

.btn-edit-start {
    background: #2196F3 !important;
    color: white;
    padding: 8px 20px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-weight: bold;
    font-size: 14px;
}

.btn-edit-start:hover {
    background: #1976D2 !important;
}

.setting-item label {
    font-weight: bold;
    color: #333;
}

.setting-item input {
    padding: 8px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
}

.setting-item button {
    padding: 8px 20px;
    background: #4a6fa5;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-weight: bold;
}

.setting-item button:hover {
    background: #3a5a80;
}

/* فلترة */
.filter-section {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 15px;
    padding: 10px;
    background: #f0f0f0;
    border-radius: 5px;
}

.filter-section select, .filter-section button {
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: 4px;
}

.filter-section button {
    background: #4a6fa5;
    color: white;
    cursor: pointer;
}

/* التقويم */
.calendar {
    margin: 3px 0;
    border: 1px solid #ddd;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}

.calendar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 5px;
    background: #4a6fa5;
    color: white;
    max-height: 50px;
}

.calendar-header button {
    background: rgba(255,255,255,0.2);
    color: white;
    border: none;
    padding: 5px 10px;
    border-radius: 4px;
    cursor: pointer;
}

.calendar-weekdays {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    background: #e9ecef;
    font-weight: bold;
}

.calendar-weekdays div {
    padding: 5px;
    text-align: center;
    border-right: 1px solid #ddd;
}

.calendar-weekdays div:last-child {
    border-right: none;
}

.calendar-days {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 1px;
    background: #ddd;
}

.calendar-days div {
    background: white;
    padding: 5px 2px;
    min-height: 10px;
    text-align: center;
    position: relative;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.calendar-days div:hover {
    background: #f8f9fa;
    transform: scale(1.02);
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

/* أنماط الأيام */
.day-holiday {
    background: #ffdddd !important;
    color: #d32f2f;
    font-weight: bold;
}

.day-work {
    background: #dde8ff !important;
    color: #1976d2;
    font-weight: bold;
}

/* لون مميز لأيام العمل الإضافي (أخضر) */
.day-extra-work {
    background: #c8e6c9 !important;
    color: #2e7d32;
    font-weight: bold;
    border: 2px solid #4caf50 !important;
}

.day-overtime {
    border-bottom: 4px solid #ff9800 !important;
}

.day-none {
    background: #f8f9fa;
    color: #6c757d;
}

/* لون بنفسجي واضح لليوم الحالي */
.today {
    border: 3px solid #9c27b0 !important;
    box-shadow: 0 0 12px rgba(156, 39, 176, 0.6);
}

.day-number {
    font-size: 26px;
    font-weight: bold;
}

.day-status {
    font-size: 14px;
    margin-top: 5px;
    font-weight: bold;
}

.day-notes {
    font-size: 11px;
    margin-top: 4px;
    color: #666;
    font-style: italic;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.day-overtime-badge {
    background: #ff9800;
    color: white;
    padding: 3px 8px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: bold;
    margin-top: 4px;
}

/* النموذج */
.form {
    display: flex;
    flex-wrap: wrap;
    gap: 15px;
    margin-bottom: 20px;
    padding: 15px;
    background: #f9f9f9;
    border-radius: 8px;
}

.form-group {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-width: 150px;
}

.form-group label {
    margin-bottom: 5px;
    font-weight: bold;
    color: #555;
}

input, select, button {
    padding: 10px;
    font-size: 14px;
    border: 1px solid #ddd;
    border-radius: 4px;
}

button {
    cursor: pointer;
    background: #4a6fa5;
    color: white;
    border: none;
    transition: background 0.3s;
}

button:hover {
    background: #3a5a80;
}

/* تلوين الأزرار */
.btn-add {
    background: #4caf50 !important;
    font-weight: bold;
    padding: 12px 20px;
}

.btn-add:hover {
    background: #45a049 !important;
}

button[onclick^="editRec"] {
    background: #2196F3 !important;
}

button[onclick^="editRec"]:hover {
    background: #1976D2 !important;
}

button[onclick^="deleteRec"] {
    background: #f44336 !important;
}

button[onclick^="deleteRec"]:hover {
    background: #d32f2f !important;
}

#dayNameDisplay {
    margin-top: 5px;
    font-weight: bold;
    color: #4a6fa5;
}

/* الجدول */
table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 20px;
}

th, td {
    border: 1px solid #ddd;
    padding: 12px;
    text-align: center;
}

th {
    background: #4a6fa5;
    color: white;
}

tr:nth-child(even) {
    background: #f9f9f9;
}

/* حالة لونية */
.status-holiday {
    color: #d32f2f;
    font-weight: bold;
}

.status-work {
    color: #1976d2;
    font-weight: bold;
}

.overtime-cell {
    color: #ff9800;
    font-weight: bold;
}

/* الإحصائيات */
.stats {
    display: flex;
    flex-wrap: wrap;
    gap: 20px;
    justify-content: space-around;
    padding: 15px;
    background: #ffffff;
    border-radius: 8px;
    margin-bottom: 5px;
}

.stat-item {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.stat-item span:first-child {
    font-weight: bold;
    margin-bottom: 5px;
}

.stat-item span:last-child {
    font-size: 28px;
    font-weight: bold;
}

/* تلوين الإحصائيات */
.stat-work span {
    color: #1976d2 !important;
}

.stat-holiday span {
    color: #d32f2f !important;
}

.stat-extra span {
    color: #4caf50 !important;
}

.stat-overtime span {
    color: #ff9800 !important;
}

/* قسم النسخ الاحتياطي */
.backup-section {
    display: flex;
    gap: 15px;
    justify-content: center;
    padding: 10px;
    margin-bottom: 10px;
}

.btn-backup, .btn-restore, .btn-test-api {
    flex: 1;
    max-width: 300px;
    padding: 12px 20px;
    font-size: 16px;
    font-weight: bold;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s;
}

.btn-backup {
    background: #4caf50;
    color: white;
}

.btn-backup:hover {
    background: #45a049;
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(76, 175, 80, 0.3);
}

.btn-restore {
    background: #2196F3;
    color: white;
}

.btn-restore:hover {
    background: #1976D2;
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(33, 150, 243, 0.3);
}

.btn-test-api {
    background: #ff9800;
    color: white;
}

.btn-test-api:hover {
    background: #f57c00;
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(255, 152, 0, 0.3);
}

/* حاسبة الراتب */
.salary-calculator {
    background: #fff3e0;
    padding: 5px;
    border-radius: 8px;
    margin-bottom: 20px;
    border: 2px solid #ff9800;
}

.salary-calculator h3 {
    text-align: center;
    color: #e65100;
    margin-top: 0;
}

.salary-inputs {
    display: flex;
    gap: 15px;
    align-items: flex-end;
    flex-wrap: wrap;
    margin-bottom: 20px;
}

.salary-input-group {
    flex: 1;
    min-width: 200px;
}

.salary-input-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: bold;
    color: #555;
}

.salary-input-group input {
    width: 100%;
    padding: 10px;
    border: 2px solid #ff9800;
    border-radius: 4px;
    font-size: 16px;
}

#calculateSalary {
    background: #ff9800;
    color: white;
    padding: 10px 30px;
    font-weight: bold;
    font-size: 16px;
}

#calculateSalary:hover {
    background: #f57c00;
}

.salary-results {
    background: white;
    padding: 15px;
    border-radius: 8px;
    border: 2px solid #ff9800;
}

.salary-result-item {
    display: flex;
    justify-content: space-between;
    padding: 10px;
    border-bottom: 1px solid #ddd;
}

.salary-result-item span:first-child {
    font-weight: bold;
    color: #555;
}

.salary-result-item span:last-child {
    color: #ff9800;
    font-weight: bold;
    font-size: 18px;
}

.salary-result-item.total {
    background: #ff9800;
    color: white;
    margin-top: 10px;
    border-radius: 5px;
    border: none;
}

.salary-result-item.total span {
    color: white !important;
    font-size: 22px;
}

/* النافذة المنبثقة */
.popup-bg {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.65);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 999;
}

.popup {
    background: white;
    padding: 20px;
    border-radius: 10px;
    width: 90%;
    max-width: 500px;
    box-shadow: 0 5px 15px rgba(0,0,0,0.3);
    position: relative;
}

.popup-small {
    max-width: 400px;
}

.popup-close {
    position: absolute;
    top: 10px;
    left: 10px;
    background: #f44336;
    color: white;
    border: none;
    width: 35px;
    height: 35px;
    border-radius: 50%;
    font-size: 24px;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s;
}

.popup-close:hover {
    background: #d32f2f;
    transform: rotate(90deg);
}

.popup h3 {
    margin-top: 0;
    text-align: center;
    color: #333;
}

.popup-form-group {
    margin: 15px 0;
    text-align: center;
}

.popup-form-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: bold;
    color: #555;
}

.popup-form-group input {
    width: 100%;
    max-width: 200px;
    padding: 8px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
}

.popup-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    justify-content: center;
    margin-top: 15px;
}

.btn-holiday {
    background: #d32f2f !important;
}

.btn-work {
    background: #1976d2 !important;
}

.btn-cancel {
    background: #6c757d !important;
}

#missingNotice {
    color: #d32f2f;
    text-align: center;
    margin: 10px 0;
}

/* نافذة التعديل */
.edit-form {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.edit-form-group {
    display: flex;
    flex-direction: column;
}

.edit-form-group label {
    margin-bottom: 5px;
    font-weight: bold;
    color: #555;
}

.edit-form-group input,
.edit-form-group select {
    padding: 10px;
    border: 2px solid #4a6fa5;
    border-radius: 4px;
    font-size: 14px;
}

#editDayName {
    margin-top: 5px;
    font-weight: bold;
    color: #4a6fa5;
}

.edit-actions {
    display: flex;
    gap: 10px;
    margin-top: 10px;
}

.btn-save {
    flex: 2;
    background: #4caf50 !important;
    padding: 12px;
    font-weight: bold;
}

.btn-save:hover {
    background: #45a049 !important;
}

.btn-delete {
    flex: 1;
    background: #f44336 !important;
    padding: 12px;
    font-weight: bold;
}

.btn-delete:hover {
    background: #d32f2f !important;
}

/* نافذة التأكيد */
.confirm-actions {
    display: flex;
    gap: 15px;
    justify-content: center;
    margin-top: 20px;
}

.btn-confirm-yes {
    background: #4caf50 !important;
    padding: 12px 30px;
    font-weight: bold;
    font-size: 16px;
}

.btn-confirm-yes:hover {
    background: #45a049 !important;
}

.btn-confirm-no {
    background: #f44336 !important;
    padding: 12px 30px;
    font-weight: bold;
    font-size: 16px;
}

.btn-confirm-no:hover {
    background: #d32f2f !important;
}

/* تصميم متجاوب */
@media (max-width: 768px) {
    /* تكبير بسيط لجميع الخطوط */
    body {
        font-size: 15px;
    }

    .container {
        width: 100%;
        margin: 0;
        border-radius: 0;
        padding: 10px;
    }

    h2 {
        font-size: 20px;
    }

    /* تكبير خطوط الفلترة */
    .filter-section select,
    .filter-section button {
        font-size: 14px;
        padding: 9px 13px;
    }

    /* تعديل قسم تاريخ بداية العمل للموبايل */
    .setting-item-display {
        display: flex;
        flex-direction: row;
        align-items: center;
        justify-content: space-between;
        gap: 8px;
        padding: 1px 10px;
        flex-wrap: nowrap;
    }

    .setting-item-display label {
        font-size: 14px;
        white-space: nowrap;
        flex-shrink: 0;
    }

    .setting-item-display span {
        font-size: 15px;
        padding: 5px 10px;
        flex: 1;
        text-align: center;
        min-width: auto;
    }

    .btn-edit-start {
        padding: 5px 12px !important;
        font-size: 13px !important;
        flex-shrink: 0;
    }

    /* تكبير خطوط التقويم */
    .calendar-header h3 {
        font-size: 18px;
    }

    .calendar-header button {
        font-size: 14px;
        padding: 6px 12px;
    }

    .calendar-weekdays div {
        font-size: 13px;
    }

    .form {
        flex-direction: column;
    }

    .form-group {
        min-width: 100%;
    }

    .calendar-days div {
        min-height: 8px;
        padding: 4px 2px;
    }

    .day-number {
        font-size: 22px;
    }

    .day-status {
        font-size: 13px;
    }

    table {
        font-size: 13px;
    }

    th, td {
        padding: 7px 4px;
    }

    .stats {
        /* ترتيب grid: اثنتان في كل صف */
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 15px;
    }

    .stat-item {
        width: 100%;
    }

    .stat-item span:first-child {
        font-size: 14px;
    }

    .stat-item span:last-child {
        font-size: 30px;
    }

    .popup-actions {
        flex-direction: column;
    }

    .popup-actions button {
        width: 100%;
    }

    /* تحسين تصميم حاسبة الراتب للموبايل */
    .salary-calculator {
        padding: 5px;
    }

    .salary-calculator h3 {
        font-size: 17px;
        margin-bottom: 8px;
        text-align: center;
    }

    .salary-inputs {
        display: flex;
        flex-direction: column;
        gap: 8px;
    }

    .salary-input-group {
        display: flex;
        flex-direction: row;
        align-items: center;
        gap: 8px;
    }

    .salary-input-group label {
        font-size: 14px;
        white-space: nowrap;
        flex-shrink: 0;
    }

    .salary-input-group input {
        padding: 8px;
        font-size: 15px;
        flex: 1;
    }

    #calculateSalary {
        width: 100%;
        padding: 9px;
        font-size: 15px;
    }

    /* تحسين تصميم نموذج الإدخال للموبايل */
    .form {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 8px;
        padding: 5px;
    }

    .form-group {
        min-width: auto;
        display: flex;
        flex-direction: column;
    }

    .form-group label {
        font-size: 16px;
        margin-bottom: 3px;
    }

    .form-group input,
    .form-group select {
        padding: 7px;
        font-size: 15px;
    }

    /* التاريخ والحالة: كل واحد يأخذ عمود */
    .form-group:nth-child(1),
    .form-group:nth-child(2) {
        grid-column: span 1;
    }

    /* ساعات إضافية وبدل الطريق: كل واحد يأخذ عمود */
    .form-group:nth-child(3),
    .form-group:nth-child(4) {
        grid-column: span 1;
    }

    /* الملاحظات: تأخذ العرض الكامل */
    .form-group:nth-child(5) {
        grid-column: span 2;
    }

    /* زر الإضافة: يأخذ العرض الكامل */
    .btn-add {
        grid-column: span 2;
        width: 100%;
        padding: 9px !important;
        font-size: 15px !important;
    }

    /* أزرار النسخ الاحتياطي للموبايل */
    .backup-section {
        flex-direction: column;
        gap: 10px;
        padding: 10px;
    }

    .btn-backup, .btn-restore, .btn-test-api {
        max-width: 100%;
        width: 100%;
        padding: 10px;
        font-size: 15px;
    }
}

@media (max-width: 480px) {
    .calendar-header {
        /* إبقاء الأزرار على اليمين واليسار */
        gap: 5px;
    }

    .calendar-header button {
        font-size: 16px;
        padding: 5px 8px;
    }

    .calendar-header h3 {
        font-size: 16px;
    }

    .calendar-days div {
        min-height: 10px;
    }

    .day-number {
        font-size: 18px;
    }

    .day-status {
        font-size: 11px;
    }

    table {
        display: block;
        overflow-x: auto;
    }
}
