/* نظام إدارة طباعة استيكرات UV - تصميم فخم وواضح وبسيط */

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

:root {
    --primary: #1e40af;
    --primary-dark: #1e3a8a;
    --primary-light: #3b82f6;
    --accent: #b45309;
    --accent-light: #f59e0b;
    --success: #059669;
    --warning: #d97706;
    --danger: #dc2626;
    --bg: #f8fafc;
    --bg-warm: #fafaf9;
    --card-bg: #ffffff;
    --text: #0f172a;
    --text-muted: #64748b;
    --border: #e5e7eb;
    --radius: 16px;
    --radius-sm: 10px;
    --shadow: 0 1px 3px rgba(0,0,0,0.04);
    --shadow-lg: 0 10px 40px rgba(0,0,0,0.08);
}

/* صفحة تسجيل الدخول */
.login-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 1.5rem; }
.login-box { background: white; padding: 2.5rem; border-radius: 16px; box-shadow: 0 10px 40px rgba(0,0,0,0.08); max-width: 400px; width: 100%; border: 1px solid var(--border); }
.login-box h1 { color: var(--primary-dark); margin-bottom: 1.5rem; text-align: center; font-size: 1.4rem; font-weight: 800; }
.login-box input { width: 100%; margin-bottom: 1rem; min-height: 44px; font-size: 16px; border-radius: 10px; padding: 0 1rem; border: 1px solid var(--border); }
.login-box button { width: 100%; padding: 0.75rem; min-height: 44px; }
.login-error { color: var(--danger); margin-bottom: 1rem; text-align: center; font-size: 0.9rem; }

/* الأرقام والتواريخ بالإنجليزي 0123456789 فقط */
.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-warm);
    min-height: 100vh;
    color: var(--text);
    line-height: 1.6;
    overflow-x: hidden;
    font-size: 15px;
}

.app {
    max-width: 1320px;
    margin: 0 auto;
    padding: 1.5rem;
}

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

.header h1 {
    font-size: 1.5rem;
    font-weight: 800;
    color: var(--primary-dark);
    letter-spacing: -0.02em;
}

.header-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    justify-content: flex-end;
}

.header-actions .btn, .header-actions a {
    min-height: 42px;
    padding: 0.5rem 1rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    font-size: 0.9rem;
}

/* ========== الأزرار ========== */
.btn {
    padding: 0.6rem 1.25rem;
    min-height: 42px;
    border: none;
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-primary {
    background: var(--primary-dark);
    color: white;
}

.btn-primary:hover {
    background: var(--primary);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(30, 64, 175, 0.3);
}

.btn-secondary {
    background: white;
    color: var(--text-muted);
    border: 1px solid var(--border);
}

.btn-secondary:hover {
    background: var(--bg);
    color: var(--text);
}

.btn-sm {
    padding: 0.4rem 0.9rem;
    font-size: 0.85rem;
    min-height: 36px;
}

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

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

.filter-tab {
    flex: 1;
    padding: 0.7rem 1rem;
    border: none;
    background: transparent;
    border-radius: 8px;
    cursor: pointer;
    font-family: inherit;
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-muted);
    transition: all 0.2s;
}

.filter-tab:hover { color: var(--primary-dark); background: var(--bg); }
.filter-tab.active {
    background: var(--primary-dark);
    color: white;
}

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

.order-card {
    background: white;
    border-radius: var(--radius);
    padding: 1.5rem;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    transition: all 0.2s;
}

.order-card:hover {
    box-shadow: var(--shadow-lg);
    border-color: var(--primary-light);
}

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

.order-id {
    font-weight: 700;
    font-size: 1.1rem;
    color: var(--primary-dark);
}

.status-badge {
    padding: 0.25rem 0.75rem;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 600;
}

.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.35rem 0;
    color: var(--text-muted);
    font-size: 0.95rem;
}

.order-card-body strong { color: var(--text); }

.order-total {
    font-size: 1.3rem;
    font-weight: 800;
    color: var(--primary-dark);
    margin: 1rem 0 0.5rem;
}

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

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

.modal.active { display: flex; }

.modal-content {
    background: white;
    border-radius: var(--radius);
    padding: 2rem;
    max-width: 480px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--border);
}

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

.modal-close {
    position: absolute;
    top: 1rem;
    left: 1rem;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-muted);
    line-height: 1;
}

.modal-close:hover { color: var(--danger); }

.modal h2 {
    margin-bottom: 1.5rem;
    color: var(--primary-dark);
    font-size: 1.25rem;
}

.form-section { margin-bottom: 1.5rem; }
.form-section h3 {
    font-size: 0.9rem;
    color: var(--text-muted);
    margin-bottom: 0.6rem;
    font-weight: 600;
}

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

input, select, textarea {
    min-height: 44px;
    padding: 0.65rem 1rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 16px;
    margin-bottom: 0.75rem;
    width: 100%;
}

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(30, 64, 175, 0.1);
}

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

.permission-row { margin: 0.75rem 0; }
.theme-file-row { margin: 0.75rem 0; }
.product-row {
    display: grid;
    grid-template-columns: 2fr 1.5fr 80px 100px 40px;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
    align-items: center;
}
.product-row input { margin-bottom: 0; }
.btn-remove-prod {
    min-height: 36px;
    padding: 0.25rem;
    font-size: 1.2rem;
    line-height: 1;
    color: var(--danger);
}
@media (max-width: 600px) {
    .product-row { grid-template-columns: 1fr 1fr 1fr 1fr 40px; }
}
.theme-file-row label { display: block; margin-bottom: 0.25rem; }
.theme-file-row input[type="file"] { width: 100%; }

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

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

/* الفاتورة في المودال */
#invoiceContent { margin-bottom: 1.5rem; }
#invoiceContent iframe {
    width: 100%;
    min-height: 420px;
    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.3rem 0.6rem;
    font-size: 0.8rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    cursor: pointer;
}

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

.finance-card {
    background: white;
    padding: 1.5rem;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    text-align: center;
    border: 1px solid var(--border);
}

.finance-card.income { border-top: 4px solid var(--success); }
.finance-card.expense { border-top: 4px solid var(--danger); }
.finance-card.balance { border-top: 4px solid var(--primary); }

.finance-card h3 { font-size: 0.9rem; color: var(--text-muted); margin-bottom: 0.5rem; }
.finance-card .amount { font-size: 1.5rem; 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.85rem; }

.finance-section h2 { color: var(--primary-dark); margin-bottom: 1rem; font-size: 1.2rem; }

/* تبويبات المصروفات */
.expenses-tabs {
    display: flex;
    background: white;
    padding: 0.25rem;
    border-radius: var(--radius-sm);
    gap: 0.25rem;
    margin-bottom: 1.5rem;
    border: 1px solid var(--border);
}

.expenses-tabs .tab-btn {
    flex: 1;
    padding: 0.7rem 1rem;
    border: none;
    background: transparent;
    border-radius: 8px;
    cursor: pointer;
    font-family: inherit;
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-muted);
    transition: all 0.2s;
}

.expenses-tabs .tab-btn:hover { color: var(--primary-dark); background: var(--bg); }
.expenses-tabs .tab-btn.active {
    background: var(--primary-dark);
    color: white;
}

.expense-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.25rem;
    background: white;
    border-radius: var(--radius-sm);
    margin-bottom: 0.5rem;
    border: 1px solid var(--border);
}

.expense-item .badge {
    font-size: 0.75rem;
    padding: 0.2rem 0.5rem;
    background: var(--bg);
    border-radius: 6px;
    margin-right: 0.5rem;
}

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

/* الإعدادات */
.settings-card {
    background: white;
    padding: 2rem;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    max-width: 560px;
    border: 1px solid var(--border);
}

.settings-card h2 { margin-bottom: 0.5rem; color: var(--primary-dark); font-size: 1.2rem; }
.settings-desc { color: var(--text-muted); margin-bottom: 1rem; font-size: 0.95rem; }
.settings-card .form-row { display: flex; gap: 0.75rem; align-items: center; }
.settings-card .form-row input { flex: 1; }
.save-msg { margin-top: 1rem; font-size: 0.95rem; color: var(--success); }

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

.stat-card {
    background: white;
    padding: 1.5rem;
    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.9rem; margin-bottom: 0.5rem; }
.stat-number { font-size: 1.75rem; font-weight: 800; color: var(--primary-dark); }
.stat-label { color: var(--text-muted); font-size: 0.85rem; }
.stat-amount { font-size: 1.2rem; font-weight: 700; color: var(--success); margin-top: 0.5rem; }

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

.report-table-wrapper, .audit-table-wrapper {
    overflow-x: auto;
    background: white;
    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.75rem 1rem;
    text-align: right;
    border-bottom: 1px solid var(--border);
}

.report-table th, .audit-table th {
    background: var(--bg);
    color: var(--primary-dark);
    font-weight: 600;
    font-size: 0.9rem;
}

.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: 1rem; }
    .header { flex-direction: column; align-items: stretch; }
    .header h1 { text-align: center; font-size: 1.25rem; }
    .header-actions { justify-content: stretch; flex-direction: column; }
    .header-actions .btn, .header-actions a { width: 100%; min-width: 0; }
    .form-row { grid-template-columns: 1fr; }
    .orders-grid { grid-template-columns: 1fr; gap: 1rem; }
    .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; }
    .modal-large { max-width: 100%; }
    #invoiceContent iframe { min-height: 320px; }
    .stats-cards, .finance-summary { grid-template-columns: 1fr; }
    .settings-card .form-row { flex-direction: column; }
    .expense-item { flex-direction: column; align-items: flex-start; gap: 0.5rem; }
    .filter-tab { min-width: calc(50% - 0.25rem); }
}

@media (max-width: 480px) {
    .app { padding: 0.75rem; }
    .header h1 { font-size: 1.1rem; }
    .order-card { padding: 1.25rem; }
    .filter-tab { min-width: 100%; }
}

@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; }
    .app .header, .app .filters, .filter-tabs, .order-card-actions { display: none !important; }
}
