/* ===== نظام إدارة الطلبات — تصميم عصري واحترافي ===== */

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

:root {
    --primary: #6366f1;
    --primary-dark: #4f46e5;
    --primary-deeper: #3730a3;
    --primary-light: #818cf8;
    --primary-bg: #eef2ff;
    --accent: #f59e0b;
    --success: #10b981;
    --success-bg: #ecfdf5;
    --warning: #f59e0b;
    --warning-bg: #fffbeb;
    --danger: #ef4444;
    --danger-bg: #fef2f2;
    --info: #6366f1;
    --info-bg: #eef2ff;
    --bg: #f8fafc;
    --bg-alt: #f1f5f9;
    --card: #ffffff;
    --text: #1e293b;
    --text-secondary: #475569;
    --text-muted: #94a3b8;
    --border: #e2e8f0;
    --border-light: #f1f5f9;
    --radius: 14px;
    --radius-sm: 10px;
    --radius-xs: 6px;
    --shadow-xs: 0 1px 2px rgba(0,0,0,0.04);
    --shadow: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
    --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.07), 0 2px 4px -2px rgba(0,0,0,0.05);
    --shadow-lg: 0 10px 25px -5px rgba(0,0,0,0.08), 0 8px 10px -6px rgba(0,0,0,0.04);
    --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.en-num, .audit-date, [data-en-num] {
    font-variant-numeric: normal;
    direction: ltr;
    unicode-bidi: embed;
}

img, iframe, video { max-width: 100%; height: auto; }
html { -webkit-text-size-adjust: 100%; overflow-x: hidden; width: 100%; }

body {
    font-family: 'Tajawal', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg);
    min-height: 100vh;
    color: var(--text);
    line-height: 1.65;
    overflow-x: hidden;
    font-size: 15px;
}

/* ===== صفحة تسجيل الدخول ===== */
.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
    background: linear-gradient(135deg, #312e81 0%, #4f46e5 50%, #6366f1 100%);
    position: relative;
}
.login-page::before {
    content: '';
    position: absolute;
    inset: 0;
    background: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23ffffff' fill-opacity='0.04'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
}

.login-box {
    background: white;
    padding: 2.75rem 2.5rem;
    border-radius: 20px;
    box-shadow: 0 25px 60px rgba(0,0,0,0.15);
    max-width: 400px;
    width: 100%;
    position: relative;
    z-index: 1;
}

.login-icon {
    text-align: center;
    margin-bottom: 1rem;
    color: var(--primary-dark);
}

.login-box h1 {
    color: var(--primary-deeper);
    margin-bottom: 0.25rem;
    text-align: center;
    font-size: 1.4rem;
    font-weight: 800;
}

.login-box .login-subtitle {
    text-align: center;
    color: var(--text-muted);
    font-size: 0.88rem;
    margin-bottom: 1.75rem;
}

.login-field {
    position: relative;
    margin-bottom: 0.85rem;
}
.login-field svg {
    position: absolute;
    right: 0.85rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    pointer-events: none;
}
.login-field input {
    width: 100%;
    min-height: 48px;
    font-size: 16px;
    border-radius: var(--radius-sm);
    padding: 0 1rem 0 1rem;
    padding-right: 2.75rem;
    border: 1.5px solid var(--border);
    background: var(--bg);
    transition: var(--transition);
    margin-bottom: 0;
}
.login-field input:focus {
    border-color: var(--primary);
    background: white;
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.12);
    outline: none;
}
.login-field input:focus + svg,
.login-field input:focus ~ svg { color: var(--primary); }

.login-box input {
    width: 100%;
    margin-bottom: 1rem;
    min-height: 48px;
    font-size: 16px;
    border-radius: var(--radius-sm);
    padding: 0 1rem;
    border: 1.5px solid var(--border);
    background: var(--bg);
    transition: var(--transition);
}
.login-box input:focus {
    border-color: var(--primary);
    background: white;
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.12);
    outline: none;
}

.login-box button {
    width: 100%;
    padding: 0.85rem;
    min-height: 48px;
    margin-top: 0.5rem;
    background: var(--primary-dark);
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 1rem;
    font-weight: 700;
    font-family: inherit;
    cursor: pointer;
    transition: var(--transition);
}
.login-box button:hover {
    background: var(--primary-deeper);
    transform: translateY(-1px);
    box-shadow: 0 4px 15px rgba(79, 70, 229, 0.35);
}

.login-error {
    color: var(--danger);
    margin-bottom: 1rem;
    text-align: center;
    font-size: 0.9rem;
    padding: 0.6rem;
    background: var(--danger-bg);
    border-radius: var(--radius-xs);
}

/* ===== التطبيق الرئيسي ===== */
.app {
    max-width: 1360px;
    margin: 0 auto;
    padding: 0 1.5rem 2rem;
}

/* ===== الهيدر ===== */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
    padding: 1rem 0;
    margin-bottom: 1.5rem;
    position: sticky;
    top: 0;
    z-index: 50;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
}

.header h1 {
    font-size: 1.35rem;
    font-weight: 800;
    color: var(--primary-deeper);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.header-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    align-items: center;
}

.header-actions .btn,
.header-actions a {
    min-height: 38px;
    padding: 0.4rem 0.85rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    font-size: 0.85rem;
    gap: 0.35rem;
}

/* ===== الأزرار ===== */
.btn {
    padding: 0.55rem 1.15rem;
    min-height: 40px;
    border: none;
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
    white-space: nowrap;
}

.btn-primary {
    background: var(--primary-dark);
    color: white;
}
.btn-primary:hover {
    background: var(--primary-deeper);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(79, 70, 229, 0.3);
}

.btn-secondary {
    background: white;
    color: var(--text-secondary);
    border: 1px solid var(--border);
}
.btn-secondary:hover {
    background: var(--bg-alt);
    color: var(--text);
    border-color: #cbd5e1;
}

.btn-sm {
    padding: 0.35rem 0.75rem;
    font-size: 0.8rem;
    min-height: 34px;
    border-radius: 8px;
}

.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover { background: #dc2626; }

.btn-logout {
    background: transparent;
    color: var(--danger);
    border: 1px solid var(--danger);
    text-decoration: none;
}
.btn-logout:hover {
    background: var(--danger);
    color: white;
}

/* ===== شريط البحث والفلاتر ===== */
.filters { margin: 0 0 1.5rem; }

.search-bar {
    position: relative;
    margin-bottom: 0.75rem;
}
.search-bar svg {
    position: absolute;
    right: 0.85rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    pointer-events: none;
}
.search-bar input {
    width: 100%;
    padding-right: 2.75rem;
    margin-bottom: 0;
}

.filter-row {
    display: flex;
    gap: 0.75rem;
    align-items: stretch;
    flex-wrap: wrap;
}
.filter-row .filter-tabs { flex: 1; min-width: 0; }

.date-filters {
    display: flex;
    gap: 0.4rem;
    align-items: center;
}
.date-filters input[type="date"] {
    width: 140px;
    margin-bottom: 0;
    min-height: 40px;
    font-size: 0.85rem;
}

/* ===== إحصائيات لوحة التحكم ===== */
.dashboard-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 0.75rem;
    margin-bottom: 1.25rem;
}
.dashboard-stats .stat-card {
    padding: 1rem;
}
.dashboard-stats .stat-card h3 {
    font-size: 0.78rem;
    margin-bottom: 0.25rem;
}
.dashboard-stats .stat-number {
    font-size: 1.4rem;
}
.dashboard-stats .stat-number small {
    font-size: 0.7rem;
    color: var(--text-muted);
}

/* ===== زر واتساب ===== */
.btn-whatsapp {
    background: #25d366;
    color: white;
    border: none;
}
.btn-whatsapp:hover {
    background: #1da851;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(37, 211, 102, 0.3);
}

.filter-tabs {
    display: flex;
    background: var(--card);
    padding: 4px;
    border-radius: var(--radius-sm);
    gap: 4px;
    box-shadow: var(--shadow-xs);
    border: 1px solid var(--border);
}

.filter-tab {
    flex: 1;
    padding: 0.6rem 1rem;
    border: none;
    background: transparent;
    border-radius: 8px;
    cursor: pointer;
    font-family: inherit;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-muted);
    transition: var(--transition);
}
.filter-tab:hover { color: var(--primary-dark); background: var(--primary-bg); }
.filter-tab.active {
    background: var(--primary-dark);
    color: white;
    box-shadow: 0 2px 8px rgba(79, 70, 229, 0.25);
}

/* ===== بطاقات الطلبات ===== */
.orders-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 1rem;
}

.order-card {
    background: var(--card);
    border-radius: var(--radius);
    padding: 1.25rem;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    transition: var(--transition);
    position: relative;
}
.order-card:hover {
    box-shadow: var(--shadow-lg);
    border-color: var(--primary-light);
    transform: translateY(-2px);
}

.order-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.85rem;
    padding-bottom: 0.85rem;
    border-bottom: 1px solid var(--border-light);
}

.order-id {
    font-weight: 800;
    font-size: 0.95rem;
    color: var(--primary-deeper);
}

.status-badge {
    padding: 0.2rem 0.65rem;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.01em;
}
.status-in-progress { background: #fef3c7; color: #92400e; }
.status-done { background: #d1fae5; color: #065f46; }
.status-complete { background: #dbeafe; color: #1e40af; }

.order-card-body p {
    margin: 0.3rem 0;
    color: var(--text-secondary);
    font-size: 0.88rem;
}
.order-card-body strong { color: var(--text); font-weight: 600; }

.order-total {
    font-size: 1.15rem;
    font-weight: 800;
    color: var(--primary-deeper);
    margin: 0.85rem 0 0.25rem;
    padding: 0.6rem 0.85rem;
    background: var(--primary-bg);
    border-radius: var(--radius-xs);
    display: inline-block;
}

.order-card-actions {
    display: flex;
    gap: 0.4rem;
    flex-wrap: wrap;
    margin-top: 0.85rem;
    padding-top: 0.85rem;
    border-top: 1px solid var(--border-light);
}

/* ===== النوافذ المنبثقة (Modals) ===== */
.modal {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.6);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    backdrop-filter: blur(6px);
}
.modal.active { display: flex; }

.modal-content {
    background: var(--card);
    border-radius: 18px;
    padding: 2rem;
    max-width: 500px;
    width: 100%;
    max-height: 92vh;
    overflow-y: auto;
    box-shadow: 0 25px 60px rgba(0,0,0,0.15);
    position: relative;
    animation: modalIn 0.25s ease-out;
}
@keyframes modalIn {
    from { opacity: 0; transform: scale(0.96) translateY(10px); }
    to { opacity: 1; transform: scale(1) translateY(0); }
}

.modal-large { max-width: 750px; }

.modal-close {
    position: absolute;
    top: 1rem;
    left: 1rem;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.3rem;
    cursor: pointer;
    color: var(--text-muted);
    border-radius: 8px;
    transition: var(--transition);
    line-height: 1;
}
.modal-close:hover { color: var(--danger); background: var(--danger-bg); }

.modal h2 {
    margin-bottom: 1.25rem;
    color: var(--text);
    font-size: 1.15rem;
    font-weight: 700;
}

.form-section { margin-bottom: 1.25rem; }
.form-section h3 {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.65rem;
}

input, select, textarea {
    min-height: 44px;
    padding: 0.6rem 0.9rem;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 15px;
    margin-bottom: 0.65rem;
    width: 100%;
    background: var(--bg);
    color: var(--text);
    transition: var(--transition);
}
input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--primary);
    background: white;
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

select { cursor: pointer; }
textarea { min-height: 80px; resize: vertical; }
.full-width { width: 100%; }

.product-row {
    display: grid;
    grid-template-columns: 2fr 1.5fr 70px 90px 36px;
    gap: 0.4rem;
    margin-bottom: 0.4rem;
    align-items: center;
}
.product-row input { margin-bottom: 0; font-size: 14px; padding: 0.5rem 0.7rem; min-height: 38px; }

.btn-remove-prod {
    min-height: 34px;
    width: 34px;
    padding: 0;
    font-size: 1.1rem;
    line-height: 1;
    color: var(--danger);
    background: var(--danger-bg);
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: var(--transition);
}
.btn-remove-prod:hover { background: var(--danger); color: white; }

.permission-row { margin: 0.75rem 0; }
.permission-row label { display: flex; align-items: center; gap: 0.5rem; cursor: pointer; }

.theme-file-row { margin: 0.75rem 0; }
.theme-file-row label { display: block; margin-bottom: 0.25rem; }
.theme-file-row input[type="file"] { width: 100%; }

.modal-actions {
    display: flex;
    gap: 0.65rem;
    margin-top: 1.25rem;
}
.modal-actions .btn { flex: 1; }

#invoiceContent { margin-bottom: 1.25rem; }
#invoiceContent iframe {
    width: 100%;
    min-height: 440px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
}

/* ===== التحميل والفراغ ===== */
.loading {
    text-align: center;
    color: var(--text-muted);
    padding: 4rem 2rem;
    font-size: 1rem;
}

.empty-state {
    text-align: center;
    padding: 4rem 2rem;
    color: var(--text-muted);
}
.empty-state p { margin: 1rem 0; }

.status-select {
    padding: 0.25rem 0.5rem;
    font-size: 0.78rem;
    border: 1.5px solid var(--border);
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
    min-height: 30px;
}

/* ===== المالية ===== */
.finance-summary {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    margin-bottom: 2rem;
}

.finance-card {
    background: var(--card);
    padding: 1.25rem;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    text-align: center;
    border: 1px solid var(--border);
    position: relative;
    overflow: hidden;
}
.finance-card::before {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    left: 0;
    height: 3px;
}
.finance-card.income::before { background: var(--success); }
.finance-card.expense::before { background: var(--danger); }
.finance-card.balance::before { background: var(--primary); }

.finance-card h3 { font-size: 0.85rem; color: var(--text-muted); margin-bottom: 0.4rem; }
.finance-card .amount { font-size: 1.4rem; font-weight: 800; }
.finance-card .amount.positive { color: var(--success); }
.finance-card .amount.negative { color: var(--danger); }
.finance-card small { color: var(--text-muted); font-size: 0.8rem; }

.finance-section h2 { color: var(--text); margin-bottom: 1rem; font-size: 1.1rem; }

.expenses-tabs {
    display: flex;
    background: var(--card);
    padding: 4px;
    border-radius: var(--radius-sm);
    gap: 4px;
    margin-bottom: 1.5rem;
    border: 1px solid var(--border);
}
.expenses-tabs .tab-btn {
    flex: 1;
    padding: 0.6rem 1rem;
    border: none;
    background: transparent;
    border-radius: 8px;
    cursor: pointer;
    font-family: inherit;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-muted);
    transition: var(--transition);
}
.expenses-tabs .tab-btn:hover { color: var(--primary-dark); background: var(--primary-bg); }
.expenses-tabs .tab-btn.active { background: var(--primary-dark); color: white; }

.expense-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.85rem 1rem;
    background: var(--card);
    border-radius: var(--radius-sm);
    margin-bottom: 0.4rem;
    border: 1px solid var(--border);
    transition: var(--transition);
}
.expense-item:hover { border-color: var(--primary-light); }

.expense-item .badge {
    font-size: 0.72rem;
    padding: 0.15rem 0.45rem;
    background: var(--bg-alt);
    border-radius: var(--radius-xs);
    margin-right: 0.4rem;
    font-weight: 600;
}

.expense-amount { font-weight: 700; color: var(--danger); }
.expense-actions { display: flex; align-items: center; gap: 0.65rem; }

/* ===== الإعدادات ===== */
.settings-card {
    background: var(--card);
    padding: 1.75rem;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    max-width: 560px;
    border: 1px solid var(--border);
}
.settings-card h2 { margin-bottom: 0.4rem; color: var(--text); font-size: 1.15rem; }
.settings-desc { color: var(--text-muted); margin-bottom: 1rem; font-size: 0.9rem; }
.settings-card .form-row { display: flex; gap: 0.65rem; align-items: center; }
.settings-card .form-row input { flex: 1; }
.save-msg { margin-top: 1rem; font-size: 0.9rem; color: var(--success); }

/* ===== الإحصائيات والتقارير ===== */
.stats-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 1rem;
    margin-bottom: 2rem;
}

.stat-card {
    background: var(--card);
    padding: 1.25rem;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    text-align: center;
    border: 1px solid var(--border);
}
.stat-card h3 { color: var(--text-muted); font-size: 0.85rem; margin-bottom: 0.4rem; }
.stat-number { font-size: 1.65rem; font-weight: 800; color: var(--primary-deeper); }
.stat-label { color: var(--text-muted); font-size: 0.8rem; }
.stat-amount { font-size: 1.1rem; font-weight: 700; color: var(--success); margin-top: 0.4rem; }

.report-section { margin-bottom: 2rem; }
.report-section h2 { color: var(--text); margin-bottom: 1rem; font-size: 1.1rem; }

.report-table-wrapper, .audit-table-wrapper {
    overflow-x: auto;
    background: var(--card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
}

.report-table, .audit-table {
    width: 100%;
    border-collapse: collapse;
}

.report-table th, .report-table td,
.audit-table th, .audit-table td {
    padding: 0.7rem 1rem;
    text-align: right;
    border-bottom: 1px solid var(--border-light);
    font-size: 0.88rem;
}

.report-table th, .audit-table th {
    background: var(--bg-alt);
    color: var(--text);
    font-weight: 700;
    font-size: 0.82rem;
    text-transform: uppercase;
    letter-spacing: 0.02em;
}

.report-table tbody tr:hover, .audit-table tbody tr:hover {
    background: var(--bg);
}

.audit-table-detailed td:nth-child(4) {
    max-width: 400px;
    white-space: normal;
    word-wrap: break-word;
}

/* ===== متجاوب ===== */
@media (max-width: 768px) {
    .app { padding: 0 1rem 1.5rem; }
    .header { flex-direction: column; align-items: stretch; position: relative; }
    .header h1 { text-align: center; font-size: 1.15rem; }
    .header-actions { justify-content: center; flex-wrap: wrap; }
    .form-row { grid-template-columns: 1fr; }
    .orders-grid { grid-template-columns: 1fr; gap: 0.85rem; }
    .order-card-actions { flex-direction: column; }
    .order-card-actions .btn, .order-card-actions a { width: 100%; }
    .modal-content { max-width: 100%; margin: 0.5rem; padding: 1.5rem; border-radius: 14px; }
    .modal-large { max-width: 100%; }
    #invoiceContent iframe { min-height: 320px; }
    .stats-cards, .finance-summary { grid-template-columns: 1fr 1fr; }
    .dashboard-stats { grid-template-columns: repeat(3, 1fr); }
    .settings-card .form-row { flex-direction: column; }
    .expense-item { flex-direction: column; align-items: flex-start; gap: 0.4rem; }
    .filter-row { flex-direction: column; }
    .date-filters { justify-content: center; }
    .date-filters input[type="date"] { width: 130px; }
}

@media (max-width: 480px) {
    .app { padding: 0 0.75rem 1.5rem; }
    .header h1 { font-size: 1rem; }
    .order-card { padding: 1rem; }
    .stats-cards, .finance-summary { grid-template-columns: 1fr; }
    .dashboard-stats { grid-template-columns: repeat(2, 1fr); }
    .product-row { grid-template-columns: 1fr 1fr 60px 70px 32px; gap: 0.3rem; }
    .date-filters input[type="date"] { width: 110px; }
}

@supports (padding: env(safe-area-inset-bottom)) {
    body { padding-left: env(safe-area-inset-left); padding-right: env(safe-area-inset-right); }
}

@media print {
    body { background: white !important; }
    .app .header, .app .filters, .filter-tabs, .order-card-actions { display: none !important; }
}
