:root {
    --primary-color: #007bff;
    --primary-hover-color: #0056b3;
    --secondary-color: #6c757d;
    --success-color: #28a745;
    --danger-color: #dc3545;
    --dark-color: #343a40;
    --light-color: #f8f9fa;
    --white-color: #ffffff;
    --border-color: #dee2e6;
    --text-color: #212529;
    --bg-color: #f4f6f9;
    --shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    --border-radius: 8px;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: "Cairo", sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    direction: rtl;
    line-height: 1.6;
}

.container {
    display: flex;
    min-height: 100vh;
}

/* --- Sidebar --- */
.sidebar {
    width: 250px;
    background-color: var(--dark-color);
    color: var(--light-color);
    padding: 20px 0;
    transition: transform 0.3s ease-in-out;
    position: fixed;
    right: 0;
    top: 0;
    bottom: 0;
    z-index: 1000;
}

.sidebar-header {
    padding: 0 20px 20px 20px;
    text-align: center;
    border-bottom: 1px solid #4a535c;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.sidebar-header h3 {
    color: var(--white-color);
}

.sidebar nav ul {
    list-style: none;
    margin-top: 20px;
}

.sidebar nav li a {
    display: block;
    padding: 12px 20px;
    color: var(--light-color);
    text-decoration: none;
    transition: background-color 0.2s;
    border-right: 3px solid transparent;
}

.sidebar nav a:hover {
    background-color: #4a535c;
}

.sidebar nav a.active {
    background-color: var(--primary-color);
    border-right-color: var(--white-color);
    color: var(--white-color);
}

.sidebar nav a i {
    margin-left: 10px;
}

/* --- Main Content --- */
.main-content {
    flex-grow: 1;
    padding: 20px;
    transition: margin-right 0.3s ease-in-out;
    margin-right: 250px;
}

.main-header {
    display: none;
    align-items: center;
    margin-bottom: 20px;
}

.main-header h1 {
    font-size: 1.5rem;
}

.page {
    display: none;
    animation: fadeIn 0.5s;
}

.page.active {
    display: block;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

h2 {
    color: var(--dark-color);
    margin-bottom: 20px;
}

h2 i {
    margin-left: 8px;
}

/* --- Responsive Design --- */
@media (max-width: 768px) {
    .sidebar {
        transform: translateX(100%);
    }
    .sidebar.open {
        transform: translateX(0);
        box-shadow: -5px 0 15px rgba(0,0,0,0.2);
    }
    .main-content {
        margin-right: 0;
    }
    .main-header {
        display: flex;
        justify-content: space-between;
        align-items: center;
        background: var(--white-color);
        padding: 10px 15px;
        border-radius: var(--border-radius);
        box-shadow: var(--shadow);
        position: sticky;
        top: 0;
        z-index: 99;
    }
    .sidebar-header .close-btn {
        display: block;
    }
    .invoice-creator {
        flex-direction: column;
    }
}

.menu-toggle-btn {
    background: none;
    border: none;
    color: var(--dark-color);
    font-size: 24px;
    cursor: pointer;
}

.sidebar .close-btn {
    color: var(--white-color);
}

/* --- Components --- */
.btn {
    padding: 10px 15px;
    border: none;
    border-radius: var(--border-radius);
    cursor: pointer;
    font-family: "Cairo", sans-serif;
    font-size: 1rem;
    transition: background-color 0.2s;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.btn-primary { background-color: var(--primary-color); color: var(--white-color); }
.btn-primary:hover { background-color: var(--primary-hover-color); }
.btn-secondary { background-color: var(--secondary-color); color: var(--white-color); }
.btn-success { background-color: var(--success-color); color: var(--white-color); }
.btn-danger { background-color: var(--danger-color); color: var(--white-color); }
.btn-block { display: block; width: 100%; }
.btn-sm { padding: 5px 8px; font-size: 0.8rem; }

.table-container {
    background-color: var(--white-color);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    overflow-x: auto;
    padding: 20px;
}

table {
    width: 100%;
    border-collapse: collapse;
}

th, td {
    padding: 12px;
    text-align: right;
    border-bottom: 1px solid var(--border-color);
    white-space: nowrap;
}

th {
    background-color: var(--light-color);
    font-weight: 600;
}

tbody tr:hover {
    background-color: #f1f3f5;
}

.actions {
    margin-bottom: 20px;
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

/* --- Dashboard --- */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 20px;
    margin-bottom: 30px;
}
.stat-card {
    background-color: var(--white-color);
    padding: 20px;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    display: flex;
    align-items: center;
    gap: 20px;
}
.stat-card .icon {
    font-size: 2.5rem;
    color: var(--primary-color);
}
.stat-card h4 {
    color: var(--secondary-color);
    font-size: 1rem;
    margin-bottom: 5px;
}
.stat-card p {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--dark-color);
}
.section h3 {
    margin-bottom: 15px;
}
.card-list {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 15px;
}
.best-selling-card {
    background-color: var(--white-color);
    padding: 15px;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.best-selling-card .name {
    font-weight: 600;
}
.best-selling-card .sales {
    color: var(--success-color);
    font-size: 0.9rem;
}

/* --- Modals --- */
.modal {
    display: none;
    position: fixed;
    z-index: 1001;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(0, 0, 0, 0.5);
    animation: fadeIn 0.3s;
}
.modal-content {
    background-color: #fefefe;
    margin: 10vh auto;
    padding: 30px;
    border: 1px solid #888;
    width: 90%;
    max-width: 500px;
    border-radius: var(--border-radius);
    position: relative;
    animation: slideIn 0.3s;
}
#invoice-details-modal .modal-content {
    max-width: 800px;
}
@keyframes slideIn {
    from { transform: translateY(-50px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

.modal .close-btn {
    color: #aaa;
    position: absolute;
    left: 15px;
    top: 10px;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
}
.modal .close-btn:hover {
    color: #000;
}

/* Forms in modals */
.modal form {
    display: flex;
    flex-direction: column;
    gap: 15px;
}
.modal form input, .modal form textarea {
    width: 100%;
    padding: 10px;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    font-family: 'Cairo', sans-serif;
}
.bundle-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px;
    border-bottom: 1px solid var(--border-color);
}
.bundle-item:last-child {
    border-bottom: none;
}
.bundle-item-qty {
    width: 60px;
    text-align: center;
    margin-left: 10px;
    padding: 5px;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
}
.modal-actions {
    margin-top: 20px;
    display: flex;
    gap: 10px;
    justify-content: flex-end;
}

/* --- New Invoice Page --- */
.invoice-creator {
    display: flex;
    gap: 20px;
}
.invoice-form {
    flex: 1;
}
.invoice-preview {
    flex: 1;
    background-color: var(--white-color);
    padding: 20px;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
}
.search-box {
    position: relative;
}
#product-search, #bundle-product-search {
    width: 100%;
    padding: 10px;
    border-radius: var(--border-radius);
    border: 1px solid var(--border-color);
    margin-bottom: 10px;
}
#search-results, #bundle-search-results {
    position: absolute;
    width: 100%;
    background: var(--white-color);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    max-height: 200px;
    overflow-y: auto;
    z-index: 100;
}
.search-result-item {
    padding: 10px;
    cursor: pointer;
}
.search-result-item:hover {
    background-color: var(--light-color);
}
.invoice-items-list {
    flex-grow: 1;
    margin: 15px 0;
    overflow-y: auto;
    min-height: 150px;
}
.invoice-item {
    display: flex;
    align-items: center;
    padding: 10px 0;
    border-bottom: 1px solid var(--border-color);
}
.invoice-item .desc { flex-grow: 1; }
.invoice-item .qty { width: 60px; text-align: center; margin: 0 10px; }
.invoice-item .price { width: 100px; text-align: left; }
.invoice-item .remove-item { color: var(--danger-color); cursor: pointer; margin-right: 15px; }
.empty-invoice {
    color: var(--secondary-color);
    text-align: center;
    padding: 20px;
}
.invoice-summary {
    border-top: 2px solid var(--border-color);
    padding-top: 10px;
}
.summary-row {
    display: flex;
    justify-content: space-between;
    padding: 8px 0;
}
.summary-row select {
    border: none;
    background: transparent;
    direction: ltr;
}
.summary-row.total {
    font-size: 1.2em;
    font-weight: bold;
    color: var(--primary-color);
}