/* General & Reset - عمومی و بازنشانی */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    /* Dark Theme Colors - رنگ‌های تم تیره */
    --primary-bg-dark: #0c0032;
    --secondary-bg-dark: #1a002d;
    --card-bg-dark: rgba(30, 10, 60, 0.9);
    --border-dark: rgba(255, 255, 255, 0.1);
    --text-color-dark: #e0d7ff;
    --heading-color-dark: #d6cfff;
    --accent-color-dark: #9a7aff;
    --btn-primary-dark: linear-gradient(135deg, #7e57c2, #5e35b1);
    --btn-hover-dark: linear-gradient(135deg, #9a7aff, #7e57c2);
    --input-bg-dark: rgba(58, 0, 130, 0.45);
    --input-focus-dark: rgba(58, 0, 130, 0.75);
}

body[data-theme="light"] {
    /* Light Theme Colors - رنگ‌های تم روشن */
    --primary-bg-light: #f9f9fc;
    --secondary-bg-light: #e0e0f7;
    --card-bg-light: #f2f2ff;
    --border-light: rgba(0, 0, 0, 0.08);
    --text-color-light: #2c2c34;
    --heading-color-light: #5a4a9e;
    --accent-color-light: #7b68ee;
    --btn-primary-light: linear-gradient(135deg, #7b68ee, #6a5acd);
    --btn-hover-light: linear-gradient(135deg, #9a87ff, #7b68ee);
    --input-bg-light: #eaeaff;
    --input-focus-light: #d3d3ff;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    direction: rtl;
    background: var(--primary-bg-dark);
    color: var(--text-color-dark);
    transition: background-color 0.3s ease, color 0.3s ease;
}

body[data-theme="light"] {
    background: var(--primary-bg-light);
    color: var(--text-color-light);
}

/* Base Components - کامپوننت‌های اصلی */
.main-wrapper {
    padding: 2rem;
    max-width: 1200px;
    margin: 2rem auto;
    background: linear-gradient(135deg, var(--primary-bg-dark), var(--secondary-bg-dark));
    border-radius: 15px;
    box-shadow: 0 4px 30px rgba(58, 0, 130, 0.5);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--border-dark);
}

body[data-theme="light"] .main-wrapper {
    background: linear-gradient(135deg, var(--primary-bg-light), var(--secondary-bg-light));
    border: 1px solid var(--border-light);
    box-shadow: 0 4px 30px rgba(100, 100, 150, 0.15);
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
}

.main-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
    gap: 1rem;
}

.main-header h2 {
    font-size: 2.2rem;
    color: var(--heading-color-dark);
    text-shadow: 0 0 8px var(--accent-color-dark);
    margin: 0;
}

body[data-theme="light"] .main-header h2 {
    color: var(--heading-color-light);
    text-shadow: none;
}

.btn-primary {
    background: var(--btn-primary-dark);
    color: #eee;
    border: none;
    padding: 0.75rem 1.6rem;
    border-radius: 12px;
    cursor: pointer;
    font-size: 1.15rem;
    font-weight: 600;
    box-shadow: 0 0 15px #8e6fe3cc;
    transition: background 0.3s ease, box-shadow 0.3s ease;
}

.btn-primary:hover {
    background: var(--btn-hover-dark);
    box-shadow: 0 0 25px #b3a5ffcc;
}

body[data-theme="light"] .btn-primary {
    background: var(--btn-primary-light);
    box-shadow: 0 0 12px #7b68eeaa;
}

body[data-theme="light"] .btn-primary:hover {
    background: linear-gradient(135deg, #9a87ff, #7b68ee);
    box-shadow: 0 0 20px #9a87ffcc;
}

/* Card & Table Styles - استایل‌های کارت و جدول */
.card-item {
    background: rgba(58, 0, 130, 0.3);
    margin-bottom: 1.2rem;
    border-radius: 15px;
    box-shadow: 0 4px 12px rgba(58, 0, 130, 0.4);
    transition: background 0.3s ease, box-shadow 0.3s ease;
    overflow: hidden;
}

.card-item:hover {
    background: rgba(90, 35, 180, 0.5);
    box-shadow: 0 8px 24px #9a7affbb;
}

body[data-theme="light"] .card-item {
    background: rgba(230, 230, 255, 0.7);
    box-shadow: 0 4px 12px rgba(150, 150, 200, 0.3);
    color: #3a3a4d;
}

body[data-theme="light"] .card-item:hover {
    background: rgba(200, 200, 255, 0.9);
    box-shadow: 0 8px 24px #9a87ffbb;
}

.data-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0 10px;
    background: transparent;
    margin: 1rem 0 1.5rem 0;
    user-select: none;
}

.data-table thead tr {
    background: linear-gradient(135deg, #321e68, #3b0a66);
    box-shadow: 0 4px 10px #4b2ca9aa;
    border-radius: 15px;
}

.data-table th, .data-table td {
    padding: 0.8rem 1rem;
    text-align: center;
    font-size: 1rem;
    color: #ccc;
    vertical-align: middle;
    font-weight: 500;
    border: none;
}

.data-table th {
    font-weight: 700;
    color: #d3c7ff;
}

.data-table tbody tr {
    background: rgba(58, 0, 130, 0.3);
    box-shadow: 0 4px 12px rgba(58, 0, 130, 0.4);
    border-radius: 15px;
    transition: background 0.3s ease;
}

.data-table tbody tr:hover {
    background: rgba(90, 35, 180, 0.5);
    box-shadow: 0 8px 24px #9a7affbb;
}

body[data-theme="light"] .data-table thead tr {
    background: linear-gradient(135deg, #a1a1d6, #8c8cce);
    box-shadow: 0 4px 10px #7b68eeaa;
    color: #333366;
}

body[data-theme="light"] .data-table th, body[data-theme="light"] .data-table td {
    color: #4a4a6a;
}

body[data-theme="light"] .data-table tbody tr {
    background: rgba(230, 230, 255, 0.8);
    box-shadow: 0 4px 12px rgba(150, 150, 200, 0.3);
}

body[data-theme="light"] .data-table tbody tr:hover {
    background: rgba(210, 210, 255, 1);
    box-shadow: 0 8px 24px #b3a5ffbb;
}

/* Modal and Form Styles - استایل‌های مودال و فرم */
.form-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(10, 0, 40, 0.85);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 9999; /* افزایش z-index برای نمایش روی سایر لایه‌ها */
    backdrop-filter: blur(15px);
    -webkit-backdrop-filter: blur(15px);
}

.form-modal {
    background: var(--card-bg-dark);
    padding: 2.5rem 2rem;
    border-radius: 18px;
    box-shadow: 0 0 40px #7a64ffaa;
    width: 650px;
    max-width: 90%;
    color: var(--text-color-dark);
    font-size: 1rem;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    max-height: 90vh;
    overflow-y: auto;
}

body[data-theme="light"] .form-modal {
    background: var(--card-bg-light);
    color: var(--text-color-light);
    box-shadow: 0 0 40px #9a87ffcc;
}

.form-modal h3 {
    margin: 0;
    font-size: 1.8rem;
    color: var(--heading-color-dark);
    text-shadow: 0 0 8px var(--accent-color-dark);
    text-align: center;
    border-bottom: 2px solid #5a2db3;
    padding-bottom: 15px;
}

body[data-theme="light"] .form-modal h3 {
    color: var(--heading-color-light);
    text-shadow: none;
    border-bottom: 2px solid #a1a1d6;
}

.form-modal input[type="text"],
.form-modal input[type="number"],
.form-modal textarea {
    background: var(--input-bg-dark);
    border: none;
    border-radius: 12px;
    padding: 0.85rem 1.2rem;
    color: #ddd;
    font-size: 1.05rem;
    outline: none;
    box-shadow: inset 0 0 12px #7c64ffaa;
    transition: box-shadow 0.3s ease, background-color 0.3s ease;
    direction: rtl;
    width: 100%;
    resize: vertical;
}

.form-modal input[type="text"]:focus,
.form-modal input[type="number"]:focus,
.form-modal textarea:focus {
    box-shadow: 0 0 18px #a497ffcc;
    background: var(--input-focus-dark);
    color: #fff;
}

body[data-theme="light"] .form-modal input,
body[data-theme="light"] .form-modal textarea {
    background: var(--input-bg-light);
    color: #333366;
    box-shadow: inset 0 0 12px #b3a5ffcc;
}

body[data-theme="light"] .form-modal input:focus,
body[data-theme="light"] .form-modal textarea:focus {
    background: var(--input-focus-light);
    color: #1a1a5a;
    box-shadow: 0 0 18px #9a87ffcc;
}

.form-buttons {
    display: flex;
    justify-content: space-around;
    gap: 1rem;
    margin-top: 1rem;
}

.form-buttons button {
    flex: 1;
    padding: 0.75rem 0;
    border-radius: 12px;
    border: none;
    font-weight: 700;
    font-size: 1.1rem;
    cursor: pointer;
    transition: background 0.3s ease, box-shadow 0.3s ease;
    box-shadow: 0 0 15px transparent;
    color: #e0d7ff;
}

.form-buttons button.submit-btn {
    background: linear-gradient(135deg, #5a2db3, #4a2c92);
    box-shadow: 0 0 25px #916affcc;
    color: #fff;
}

.form-buttons button.submit-btn:hover {
    background: linear-gradient(135deg, #8e6fe3, #735bcc);
    box-shadow: 0 0 35px #b3a5ffcc;
}

.form-buttons button.cancel-btn {
    background: linear-gradient(135deg, #4a2a6f, #321e68);
    box-shadow: 0 0 15px #7345bbcc;
    color: #e0d7ff;
}

.form-buttons button.cancel-btn:hover {
    background: linear-gradient(135deg, #735bcc, #593ea9);
    box-shadow: 0 0 25px #9a7affcc;
}

body[data-theme="light"] .form-buttons button.submit-btn {
    background: linear-gradient(135deg, #6a5acd, #5a4a9e);
    box-shadow: 0 0 25px #7b68eecc;
    color: #fff;
}

body[data-theme="light"] .form-buttons button.submit-btn:hover {
    background: linear-gradient(135deg, #9a87ff, #7b68ee);
    box-shadow: 0 0 35px #b3a5ffcc;
}

body[data-theme="light"] .form-buttons button.cancel-btn {
    background: linear-gradient(135deg, #7b68ee, #5a4a9e);
    box-shadow: 0 0 15px #7b68eecc;
    color: #fff;
}

body[data-theme="light"] .form-buttons button.cancel-btn:hover {
    background: linear-gradient(135deg, #9a87ff, #7b68ee);
    box-shadow: 0 0 25px #b3a5ffcc;
}

/* Specific Styles for Invoices - استایل‌های خاص فاکتورها */
.invoices-tabs {
    display: flex;
    border-bottom: 2px solid #5a2db3;
    margin-bottom: 20px;
}

.tab-btn {
    flex: 1;
    background-color: transparent;
    border: none;
    padding: 10px 0;
    font-size: 1.15rem;
    cursor: pointer;
    transition: all 0.3s ease;
    color: #d3c7ff;
    position: relative;
    font-weight: 600;
}

.tab-btn.active {
    color: #9a7aff;
    font-weight: bold;
}

.tab-btn.active::after {
    content: '';
    position: absolute;
    bottom: -2px;
    left: 0;
    width: 100%;
    height: 2px;
    background-color: #9a7aff;
}

body[data-theme="light"] .invoices-tabs {
    border-bottom: 2px solid #a1a1d6;
}

body[data-theme="light"] .tab-btn {
    color: #4b4b65;
}

body[data-theme="light"] .tab-btn.active {
    color: #7b68ee;
}

body[data-theme="light"] .tab-btn.active::after {
    background-color: #7b68ee;
}

#items-list {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    overflow-y: auto;
    max-height: 30vh;
    padding-right: 10px;
}

.invoice-item-row {
    display: grid;
    grid-template-columns: 2fr 1fr 1fr 50px;
    gap: 15px;
    align-items: center;
    padding: 10px;
    background: rgba(58, 0, 130, 0.2);
    border-radius: 10px;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

body[data-theme="light"] .invoice-item-row {
    background: rgba(230, 230, 255, 0.8);
    border: 1px solid rgba(0, 0, 0, 0.1);
}

.invoice-item-row input {
    margin: 0;
}

.invoice-item-row .remove-item-btn {
    background: linear-gradient(135deg, #dc3545, #b92c3a);
    color: #fff;
    padding: 8px 12px;
    border-radius: 8px;
    border: none;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 600;
    white-space: nowrap;
    transition: background 0.3s ease;
}

.invoice-item-row .remove-item-btn:hover {
    background: linear-gradient(135deg, #e4606d, #dc3545);
}

body[data-theme="light"] .invoice-item-row .remove-item-btn {
    background: linear-gradient(135deg, #d9534f, #c94a45);
}

/* Specific Styles for Menu - استایل‌های خاص منو */
.category-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.9rem 1.4rem;
    font-weight: 600;
    font-size: 1.25rem;
    color: #d3c7ff;
}

body[data-theme="light"] .category-header {
    color: #4b4b65;
}

.category-actions button {
    margin-left: 0.5rem;
    padding: 0.35rem 1rem;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    font-size: 1rem;
    font-weight: 600;
    color: #f5f3ff;
    background: linear-gradient(135deg, #6a4bc9, #4a3693);
    box-shadow: 0 0 10px transparent;
    transition: all 0.3s ease;
}

.category-actions button:hover {
    transform: scale(1.07);
    background: linear-gradient(135deg, #9a7aff, #7e57c2);
    box-shadow: 0 0 20px #b3a5ffcc;
}

body[data-theme="light"] .category-actions button {
    background: linear-gradient(135deg, #8a7fe9, #6e6ad1);
    color: #fff;
}

body[data-theme="light"] .category-actions button:hover {
    background: linear-gradient(135deg, #b3a5ff, #9a87ff);
    box-shadow: 0 0 18px #b3a5ffcc;
}

.btn-add-product {
    display: inline-block;
    background: linear-gradient(135deg, #7e57c2, #5e35b1);
    color: #eee;
    padding: 0.85rem 1.8rem;
    font-size: 1.15rem;
    font-weight: 700;
    border: none;
    border-radius: 14px;
    cursor: pointer;
    box-shadow: 0 0 18px #8e6fe3cc;
    transition: background 0.3s ease, box-shadow 0.3s ease, transform 0.25s ease;
    text-align: center;
    margin-bottom: 1rem;
    margin-right: 1rem;
}

.btn-add-product:hover {
    background: linear-gradient(135deg, #9a7aff, #7e57c2);
    box-shadow: 0 0 30px #b3a5ffcc;
    transform: scale(1.07);
}

body[data-theme="light"] .btn-add-product {
    background: linear-gradient(135deg, #7b68ee, #6a5acd);
    color: #fff;
    box-shadow: 0 0 18px #7b68eecc;
}

body[data-theme="light"] .btn-add-product:hover {
    background: linear-gradient(135deg, #9a87ff, #7b68ee);
    box-shadow: 0 0 30px #9a87ffcc;
}

/* Other Specific Buttons - دکمه‌های خاص دیگر */
.btn-view, .btn-print {
    background: linear-gradient(135deg, #7e57c2, #5e35b1);
}

.btn-edit {
    background: linear-gradient(135deg, #ffc107, #e6a000);
}

.btn-delete {
    background: linear-gradient(135deg, #dc3545, #b92c3a);
}

/* Responsive - ریسپانسیو */
@media (max-width: 768px) {
    .main-wrapper {
        padding: 1rem 1.2rem;
        margin: 1rem;
    }

    .main-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .main-header h2 {
        font-size: 1.8rem;
    }

    .main-header button {
        width: 100%;
        text-align: center;
        margin-top: 0.8rem;
    }

    .data-table th, .data-table td {
        font-size: 0.9rem;
        padding: 0.6rem 0.8rem;
    }

    .form-modal {
        width: 95%;
        padding: 1.5rem 1.2rem;
    }

    .form-buttons {
        flex-direction: column;
    }

    .form-buttons button {
        width: 100%;
    }

    .invoice-item-row {
        grid-template-columns: 1fr;
    }
}