﻿/* ===== المتغيرات الأساسية ===== */
:root {
    --primary-color: #2c3e50;
    --secondary-color: #3498db;
    --success-color: #27ae60;
    --warning-color: #f39c12;
    --danger-color: #e74c3c;
    --info-color: #17a2b8;
    --light-color: #f8f9fa;
    --dark-color: #343a40;
    --sidebar-width: 280px;
    --sidebar-collapsed-width: 70px;
    --header-height: 60px;
    --transition-speed: 0.3s;
}

/* ===== الخطوط ===== */
body {
    font-family: 'Cairo', sans-serif;
    background-color: #f4f6f9;
    min-height: 100vh;
}

/* ===== Wrapper ===== */
.wrapper {
    display: flex;
    width: 100%;
    min-height: 100vh;
}

/* ===== Sidebar ===== */
.sidebar {
    width: var(--sidebar-width);
    height: 100vh;
    background: linear-gradient(180deg, var(--primary-color) 0%, #1a252f 100%);
    position: fixed;
    top: 0;
    right: 0;
    z-index: 1000;
    transition: all var(--transition-speed);
    overflow-y: auto;
    overflow-x: hidden;
    display: flex;
    flex-direction: column;
}

.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding-bottom: 20px;
}

.sidebar.collapsed {
    width: var(--sidebar-collapsed-width);
}

.sidebar.collapsed .sidebar-header h4,
.sidebar.collapsed .sidebar-header small,
.sidebar.collapsed .nav-link span,
.sidebar.collapsed .submenu-icon {
    display: none !important;
}

.sidebar.collapsed .sidebar-header {
    padding: 15px 10px;
    text-align: center;
}

.sidebar.collapsed .nav-link {
    justify-content: center;
    padding: 15px 10px;
}

.sidebar.collapsed .nav-link i:first-child {
    width: auto;
    margin: 0;
}

.sidebar.collapsed .submenu {
    display: none !important;
}

.sidebar-header {
    padding: 20px;
    background: rgba(0, 0, 0, 0.1);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.sidebar-header h4 {
    color: #fff;
    margin: 0;
    font-size: 1.2rem;
    font-weight: 600;
    white-space: nowrap;
}

/* Sidebar nav is now defined above with flex */

.sidebar-nav .nav-item {
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.sidebar-nav .nav-link {
    display: flex;
    align-items: center;
    padding: 15px 20px;
    color: rgba(255, 255, 255, 0.8);
    text-decoration: none;
    transition: all 0.2s;
    cursor: pointer;
}

.sidebar-nav .nav-link:hover {
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
}

.sidebar-nav .nav-link.active {
    background: var(--secondary-color);
    color: #fff;
}

.sidebar-nav .nav-link i:first-child {
    width: 30px;
    font-size: 1.1rem;
}

.sidebar-nav .nav-link span {
    flex: 1;
    white-space: nowrap;
}

.sidebar-nav .submenu-icon {
    font-size: 0.8rem;
    transition: transform 0.2s;
}

.sidebar-nav .nav-link[aria-expanded="true"] .submenu-icon {
    transform: rotate(180deg);
}

/* Submenu */
.submenu {
    list-style: none;
    padding: 0;
    margin: 0;
    background: rgba(0, 0, 0, 0.2);
}

.submenu li a {
    display: block;
    padding: 12px 20px 12px 50px;
    color: rgba(255, 255, 255, 0.7);
    text-decoration: none;
    font-size: 0.9rem;
    transition: all 0.2s;
}

.submenu li a:hover {
    background: rgba(255, 255, 255, 0.05);
    color: #fff;
    padding-right: 55px;
}

.submenu li a.active {
    color: var(--secondary-color);
}

/* ===== Content ===== */
#content {
    width: calc(100% - var(--sidebar-width));
    margin-right: var(--sidebar-width);
    min-height: 100vh;
    transition: all var(--transition-speed);
}

#content.expanded {
    width: calc(100% - var(--sidebar-collapsed-width));
    margin-right: var(--sidebar-collapsed-width);
}

/* ===== Top Navbar ===== */
#content > .navbar {
    height: var(--header-height);
    padding: 0 20px;
}

#sidebarToggle {
    font-size: 1.2rem;
    color: var(--primary-color);
}

.notifications-dropdown {
    width: 300px;
    max-height: 400px;
    overflow-y: auto;
}

.notification-badge {
    font-size: 0.65rem;
}

/* ===== Main Content ===== */
.main-content {
    min-height: calc(100vh - var(--header-height));
}

/* ===== Cards ===== */
.card {
    border: none;
    border-radius: 10px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
    margin-bottom: 20px;
}

.card-header {
    background: #fff;
    border-bottom: 1px solid #eee;
    padding: 15px 20px;
    font-weight: 600;
}

.card-body {
    padding: 20px;
}

/* ===== Stats Cards ===== */
.stats-card {
    border-radius: 10px;
    padding: 20px;
    color: #fff;
    position: relative;
    overflow: hidden;
}

.stats-card .icon {
    position: absolute;
    left: 20px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 3rem;
    opacity: 0.3;
}

.stats-card .value {
    font-size: 2rem;
    font-weight: 700;
}

.stats-card .label {
    font-size: 0.9rem;
    opacity: 0.9;
}

.stats-card.primary { background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); }
.stats-card.success { background: linear-gradient(135deg, #11998e 0%, #38ef7d 100%); }
.stats-card.warning { background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%); }
.stats-card.info { background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%); }
.stats-card.danger { background: linear-gradient(135deg, #ff416c 0%, #ff4b2b 100%); }

/* ===== Tables ===== */
.table {
    margin-bottom: 0;
}

.table thead th {
    background: var(--light-color);
    border-bottom: 2px solid #dee2e6;
    font-weight: 600;
    white-space: nowrap;
}

.table tbody tr:hover {
    background-color: rgba(52, 152, 219, 0.05);
}

.table-actions {
    white-space: nowrap;
}

.table-actions .btn {
    padding: 5px 10px;
    font-size: 0.85rem;
}

/* ===== Badges ===== */
.badge {
    font-weight: 500;
    padding: 6px 12px;
}

.badge-status-open { background-color: var(--info-color); }
.badge-status-closed { background-color: var(--success-color); }
.badge-status-cancelled { background-color: var(--danger-color); }
.badge-status-draft { background-color: var(--secondary-color); }

.badge-payment-paid { background-color: var(--success-color); }
.badge-payment-unpaid { background-color: var(--danger-color); }
.badge-payment-partial { background-color: var(--warning-color); }

/* ===== Forms ===== */
.form-label {
    font-weight: 500;
    margin-bottom: 5px;
}

.form-control, .form-select {
    border-radius: 8px;
    padding: 10px 15px;
    border: 1px solid #ddd;
}

.form-control:focus, .form-select:focus {
    border-color: var(--secondary-color);
    box-shadow: 0 0 0 0.2rem rgba(52, 152, 219, 0.25);
}

.input-group-text {
    background: var(--light-color);
    border-color: #ddd;
}

/* ===== Buttons ===== */
.btn {
    border-radius: 8px;
    padding: 10px 20px;
    font-weight: 500;
    transition: all 0.2s;
}

.btn-primary {
    background: var(--secondary-color);
    border-color: var(--secondary-color);
}

.btn-primary:hover {
    background: #2980b9;
    border-color: #2980b9;
}

.btn-success {
    background: var(--success-color);
    border-color: var(--success-color);
}

.btn-danger {
    background: var(--danger-color);
    border-color: var(--danger-color);
}

.btn-outline-primary {
    color: var(--secondary-color);
    border-color: var(--secondary-color);
}

.btn-outline-primary:hover {
    background: var(--secondary-color);
    border-color: var(--secondary-color);
}

/* ===== Page Header ===== */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 25px;
    flex-wrap: wrap;
    gap: 15px;
}

.page-header h2 {
    margin: 0;
    font-weight: 600;
    color: var(--primary-color);
}

.page-header .breadcrumb {
    margin: 0;
    background: transparent;
    padding: 0;
}

/* ===== Filters ===== */
.filters-card {
    background: #fff;
    border-radius: 10px;
    padding: 20px;
    margin-bottom: 20px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
}

.date-filters {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    margin-bottom: 15px;
}

.date-filters .btn {
    padding: 5px 15px;
    font-size: 0.85rem;
}

/* ===== Pagination ===== */
.pagination {
    margin: 0;
}

.page-link {
    color: var(--primary-color);
    border-radius: 5px;
    margin: 0 2px;
}

.page-item.active .page-link {
    background: var(--secondary-color);
    border-color: var(--secondary-color);
}

/* ===== Modal ===== */
.modal-header {
    background: var(--primary-color);
    color: #fff;
}

.modal-header .btn-close {
    filter: invert(1);
}

/* ===== Login Page ===== */
.login-wrapper {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--primary-color) 0%, #1a252f 100%);
}

.login-card {
    background: #fff;
    border-radius: 15px;
    padding: 40px;
    width: 100%;
    max-width: 420px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
}

.login-card .logo {
    text-align: center;
    margin-bottom: 30px;
}

.login-card .logo i {
    font-size: 4rem;
    color: var(--secondary-color);
}

.login-card h3 {
    text-align: center;
    margin-bottom: 30px;
    color: var(--primary-color);
}



/* ===== Invoice ===== */
.invoice-header {
    background: var(--primary-color);
    color: #fff;
    padding: 20px;
    border-radius: 10px 10px 0 0;
}

.invoice-details {
    background: #f8f9fa;
    padding: 20px;
    border-radius: 0 0 10px 10px;
}

.invoice-items {
    margin-top: 20px;
}

.invoice-total {
    background: #f8f9fa;
    padding: 15px;
    border-radius: 10px;
    margin-top: 20px;
}

.invoice-total .row {
    margin-bottom: 10px;
}

.invoice-total .total-row {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--primary-color);
    border-top: 2px solid #ddd;
    padding-top: 10px;
    margin-top: 10px;
}

/* ===== Customer Account ===== */
.account-summary {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 15px;
    margin-bottom: 20px;
}

.account-summary-item {
    background: #fff;
    padding: 15px;
    border-radius: 10px;
    text-align: center;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
}

.account-summary-item .value {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary-color);
}

.account-summary-item .label {
    font-size: 0.85rem;
    color: #666;
}

/* ===== Tasks List ===== */
.tasks-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.tasks-list li {
    display: flex;
    align-items: center;
    padding: 12px 0;
    border-bottom: 1px solid #eee;
}

.tasks-list li:last-child {
    border-bottom: none;
}

.tasks-list li i {
    width: 30px;
    color: var(--warning-color);
}

.tasks-list li .badge {
    margin-right: auto;
}

/* ===== Sidebar Overlay (Mobile) ===== */
.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 999;
    opacity: 0;
    transition: opacity var(--transition-speed);
}

.sidebar-overlay.show {
    display: block;
    opacity: 1;
}

body.sidebar-open {
    overflow: hidden;
}

/* ===== Responsive ===== */
@media (max-width: 992px) {
    .sidebar {
        right: calc(-1 * var(--sidebar-width));
        box-shadow: none;
    }

    .sidebar.show {
        right: 0;
        box-shadow: -5px 0 25px rgba(0, 0, 0, 0.3);
    }

    #content,
    #content.expanded {
        width: 100%;
        margin-right: 0;
    }

    .stats-card .value {
        font-size: 1.5rem;
    }
}

@media (max-width: 768px) {
    /* منع التكبير التلقائي في iOS عند لمس الحقول */
    .form-control, .form-select, .input-group-text,
    input, select, textarea {
        font-size: 16px !important;
    }

    select.form-select, select {
        max-width: 100%;
    }

    .main-content {
        padding: 15px !important;
    }

    .page-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .page-header h2 {
        font-size: 1.3rem;
    }

    .filters-card {
        padding: 15px;
    }

    .filters-card .row > div {
        margin-bottom: 10px;
    }

    .card-body {
        padding: 15px;
    }

    /* ===== الجداول كبطاقات على الموبايل ===== */
    .table-responsive {
        font-size: 0.85rem;
        -webkit-overflow-scrolling: touch;
    }

    .table-responsive:has(> table.mobile-cards) {
        overflow-x: visible;
        background: transparent;
        padding: 10px;
    }

    table.mobile-cards {
        background: transparent !important;
    }

    table.mobile-cards thead {
        display: none;
    }

    table.mobile-cards tbody tr {
        display: block;
        background: #fff;
        border: 1px solid #e5e8ec;
        border-radius: 10px;
        margin-bottom: 12px;
        padding: 6px 14px;
        box-shadow: 0 1px 4px rgba(0, 0, 0, 0.05);
    }

    table.mobile-cards tbody td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        gap: 12px;
        padding: 8px 0;
        border: none;
        border-bottom: 1px dashed #eee;
        text-align: left;
        white-space: normal;
    }

    table.mobile-cards tbody td:last-child {
        border-bottom: none;
    }

    table.mobile-cards tbody td::before {
        content: attr(data-label);
        font-weight: 600;
        color: var(--primary-color);
        flex-shrink: 0;
        max-width: 45%;
    }

    table.mobile-cards tbody td[data-label=""]::before {
        display: none;
    }

    /* خانة الإجراءات والخلايا بدون عنوان تملأ العرض */
    table.mobile-cards tbody td[data-label=""] {
        justify-content: center;
    }

    table.mobile-cards tbody td[colspan] {
        display: block;
        text-align: center;
    }

    table.mobile-cards .table-actions {
        white-space: normal;
        display: flex;
        flex-wrap: wrap;
        gap: 6px;
    }

    table.mobile-cards tfoot {
        display: block;
        background: var(--light-color);
        border-radius: 10px;
        padding: 8px 14px;
    }

    table.mobile-cards tfoot tr {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 6px 0;
    }

    table.mobile-cards tfoot td {
        display: block;
        border: none;
        padding: 0;
    }

    .table-actions .btn {
        padding: 4px 8px;
        font-size: 0.8rem;
    }

    .btn {
        padding: 8px 16px;
    }

    .stats-card {
        padding: 15px;
    }

    .stats-card .icon {
        font-size: 2rem;
    }

    .pagination {
        flex-wrap: wrap;
        justify-content: center;
        row-gap: 5px;
    }

    .page-link {
        padding: 6px 10px;
        font-size: 0.85rem;
    }

    .modal-dialog {
        margin: 10px;
    }

    .modal-footer .btn {
        flex: 1;
    }

    .notifications-dropdown {
        width: 280px;
        max-width: calc(100vw - 40px);
    }

    #content > .navbar {
        padding: 0 10px;
    }

    #content > .navbar .dropdown-toggle {
        font-size: 0.85rem;
    }

    .login-card {
        padding: 25px;
        margin: 15px;
    }
}

@media (max-width: 480px) {
    .main-content {
        padding: 10px !important;
    }

    .page-header h2 {
        font-size: 1.15rem;
    }

    .stats-card .value {
        font-size: 1.3rem;
    }

    .date-filters .btn {
        padding: 4px 10px;
        font-size: 0.8rem;
    }
}

/* ===== Print Styles ===== */
@media print {
    .sidebar,
    #content > .navbar,
    .no-print {
        display: none !important;
    }
    
    #content {
        width: 100%;
        margin: 0;
    }
    
    .main-content {
        padding: 0 !important;
    }
    
    .card {
        box-shadow: none;
        border: 1px solid #ddd;
    }
}

/* ===== Utilities ===== */
.text-primary { color: var(--primary-color) !important; }
.text-secondary { color: var(--secondary-color) !important; }
.bg-primary { background-color: var(--primary-color) !important; }
.bg-secondary { background-color: var(--secondary-color) !important; }

.cursor-pointer { cursor: pointer; }
.font-weight-600 { font-weight: 600; }

/* ===== Loading ===== */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 4px solid #f3f3f3;
    border-top: 4px solid var(--secondary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* ===== Empty State ===== */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: #999;
}

.empty-state i {
    font-size: 4rem;
    margin-bottom: 20px;
    opacity: 0.5;
}

.empty-state h4 {
    margin-bottom: 10px;
}

/* ===== Scrollbar ===== */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: #f1f1f1;
}

::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: #a1a1a1;
}
