/* ========== CSS VARIABLES ========== */
:root {
  --primary: #1a5f3f;
  --primary-dark: #124a30;
  --primary-light: #e8f5ee;
  --secondary: #2563eb;
  --accent: #f59e0b;
  --danger: #dc2626;
  --success: #16a34a;
  --text: #1f2937;
  --text-light: #6b7280;
  --bg: #f3f4f6;
  --card: #ffffff;
  --border: #e5e7eb;
  --shadow: 0 1px 3px rgba(0,0,0,0.1);
  --shadow-lg: 0 10px 25px rgba(0,0,0,0.1);
  --radius: 12px;
  --radius-sm: 8px;
}

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

body {
  font-family: 'Tajawal', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

.app-container { max-width: 1200px; margin: 0 auto; padding: 0 20px; }

/* Header */
.header {
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
  color: white;
  padding: 24px 0;
  margin-bottom: 30px;
  border-radius: 0 0 var(--radius) var(--radius);
  box-shadow: var(--shadow-lg);
}
.header-content { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 16px; }
.logo { display: flex; align-items: center; gap: 16px; }
.logo-icon { font-size: 40px; background: rgba(255,255,255,0.2); width: 60px; height: 60px; display: flex; align-items: center; justify-content: center; border-radius: var(--radius); }
.logo h1 { font-size: 24px; font-weight: 800; margin-bottom: 2px; }
.domain { font-size: 14px; opacity: 0.8; font-weight: 500; }
.zatca-badge { background: rgba(255,255,255,0.15); backdrop-filter: blur(10px); padding: 10px 20px; border-radius: 50px; display: flex; align-items: center; gap: 8px; font-size: 14px; font-weight: 600; border: 1px solid rgba(255,255,255,0.2); }
.badge-icon { background: var(--success); width: 24px; height: 24px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 14px; }

/* Stats */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat-card { background: var(--card); border-radius: var(--radius); padding: 24px; box-shadow: var(--shadow); text-align: center; }
.stat-icon { font-size: 32px; margin-bottom: 8px; }
.stat-value { font-size: 28px; font-weight: 800; color: var(--primary); }
.stat-label { font-size: 14px; color: var(--text-light); margin-top: 4px; }

/* Tabs */
.tabs { display: flex; gap: 8px; margin-bottom: 24px; background: var(--card); padding: 6px; border-radius: var(--radius); box-shadow: var(--shadow); width: fit-content; }
.tab-btn { padding: 12px 24px; border: none; background: transparent; color: var(--text-light); font-family: inherit; font-size: 15px; font-weight: 600; border-radius: var(--radius-sm); cursor: pointer; transition: all 0.3s; }
.tab-btn:hover { background: var(--bg); color: var(--text); }
.tab-btn.active { background: var(--primary); color: white; box-shadow: 0 2px 8px rgba(26, 95, 63, 0.3); }

/* Tab Content */
.tab-content { display: none; }
.tab-content.active { display: block; animation: fadeIn 0.3s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

/* Card */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.card-header { padding: 24px 28px; border-bottom: 1px solid var(--border); }
.card-header h2 { font-size: 20px; font-weight: 700; margin-bottom: 6px; }
.subtitle { color: var(--text-light); font-size: 14px; }

/* Form */
form { padding: 24px 28px; }
.section { margin-bottom: 28px; }
.section h3 { font-size: 16px; font-weight: 700; margin-bottom: 16px; color: var(--primary); display: flex; align-items: center; gap: 8px; }
.section-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.section-header h3 { margin-bottom: 0; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 16px; }
.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-group label { font-size: 14px; font-weight: 600; }
.required { color: var(--danger); }
.form-group input, .form-group select, .form-group textarea {
  padding: 12px 14px; border: 2px solid var(--border); border-radius: var(--radius-sm);
  font-family: inherit; font-size: 15px; transition: all 0.2s; background: white;
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
  outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-light);
}
.form-group input::placeholder, .form-group textarea::placeholder { color: #9ca3af; }

/* Items */
.item-row { background: var(--bg); border-radius: var(--radius-sm); padding: 20px; margin-bottom: 16px; border: 2px solid var(--border); transition: all 0.2s; }
.item-row:hover { border-color: var(--primary); }
.item-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.item-header h4 { font-size: 15px; font-weight: 700; color: var(--primary); }
.item-number { background: var(--primary); color: white; width: 28px; height: 28px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 13px; font-weight: 700; }
.remove-item { background: var(--danger); color: white; border: none; width: 32px; height: 32px; border-radius: var(--radius-sm); cursor: pointer; font-size: 18px; display: flex; align-items: center; justify-content: center; transition: all 0.2s; }
.remove-item:hover { background: #b91c1c; transform: scale(1.05); }

/* Buttons */
.btn { padding: 10px 20px; border: none; border-radius: var(--radius-sm); font-family: inherit; font-size: 14px; font-weight: 600; cursor: pointer; transition: all 0.2s; display: inline-flex; align-items: center; gap: 8px; text-decoration: none; }
.btn-primary { background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%); color: white; box-shadow: 0 4px 12px rgba(26, 95, 63, 0.3); }
.btn-primary:hover { transform: translateY(-2px); box-shadow: 0 6px 20px rgba(26, 95, 63, 0.4); }
.btn-secondary { background: var(--secondary); color: white; }
.btn-secondary:hover { background: #1d4ed8; }
.btn-outline { background: transparent; color: var(--text-light); border: 2px solid var(--border); }
.btn-outline:hover { border-color: var(--primary); color: var(--primary); background: var(--primary-light); }
.btn-large { padding: 14px 32px; font-size: 16px; }
.form-actions { display: flex; gap: 12px; justify-content: center; padding-top: 20px; border-top: 1px solid var(--border); }

/* Totals */
.totals-preview { background: linear-gradient(135deg, var(--primary-light) 0%, #f0fdf4 100%); border-radius: var(--radius-sm); padding: 20px 24px; margin: 24px 0; border: 2px solid var(--primary); }
.total-row { display: flex; justify-content: space-between; padding: 8px 0; font-size: 15px; }
.total-row:not(:last-child) { border-bottom: 1px dashed rgba(26, 95, 63, 0.2); }
.grand-total { font-size: 20px; font-weight: 800; color: var(--primary); margin-top: 8px; padding-top: 12px; border-top: 2px solid var(--primary); }

/* Table */
.invoices-table { width: 100%; border-collapse: collapse; }
.invoices-table th, .invoices-table td { padding: 16px; text-align: right; border-bottom: 1px solid var(--border); }
.invoices-table th { background: var(--bg); font-weight: 700; font-size: 14px; color: var(--text-light); text-transform: uppercase; letter-spacing: 0.5px; }
.invoices-table tr:hover td { background: var(--primary-light); }
.status-badge { display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: 50px; font-size: 13px; font-weight: 600; }
.status-generated { background: #dbeafe; color: #1e40af; }
.invoice-actions { display: flex; gap: 8px; }
.invoice-actions .btn { padding: 6px 12px; font-size: 13px; }

/* Empty State */
.empty-state { text-align: center; padding: 60px 20px; color: var(--text-light); }
.empty-icon { font-size: 64px; margin-bottom: 16px; opacity: 0.5; }
.empty-state p { font-size: 18px; font-weight: 600; margin-bottom: 8px; color: var(--text); }

/* Integration Code */
.integration-code { padding: 24px 28px; }
.integration-code h3 { font-size: 18px; color: var(--primary); margin-bottom: 12px; }
.integration-code p { color: var(--text-light); margin-bottom: 16px; }
.code-block { background: #1e293b; color: #e2e8f0; padding: 20px; border-radius: var(--radius-sm); overflow-x: auto; margin-bottom: 20px; position: relative; }
.code-block pre { font-family: 'Consolas', 'Monaco', monospace; font-size: 13px; line-height: 1.6; direction: ltr; text-align: left; white-space: pre-wrap; word-break: break-all; }
.code-block .btn { position: absolute; top: 12px; left: 12px; font-size: 12px; padding: 6px 12px; }

/* Modal */
.modal { display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.5); z-index: 1000; align-items: center; justify-content: center; padding: 20px; }
.modal.active { display: flex; animation: fadeIn 0.2s ease; }
.modal-content { background: white; border-radius: var(--radius); max-width: 700px; width: 100%; max-height: 90vh; overflow: hidden; box-shadow: var(--shadow-lg); display: flex; flex-direction: column; }
.modal-header { padding: 20px 24px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }
.modal-header h2 { font-size: 20px; }
.modal-close { background: none; border: none; font-size: 28px; cursor: pointer; color: var(--text-light); width: 36px; height: 36px; display: flex; align-items: center; justify-content: center; border-radius: var(--radius-sm); transition: all 0.2s; }
.modal-close:hover { background: var(--bg); color: var(--danger); }
.modal-body { padding: 24px; overflow-y: auto; flex: 1; }
.modal-footer { padding: 16px 24px; border-top: 1px solid var(--border); display: flex; gap: 12px; justify-content: flex-end; }

/* Invoice Preview */
.invoice-preview { background: white; border: 2px solid var(--border); border-radius: var(--radius-sm); padding: 32px; }
.preview-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 24px; padding-bottom: 24px; border-bottom: 2px solid var(--primary); }
.preview-company h3 { font-size: 22px; color: var(--primary); margin-bottom: 4px; }
.preview-company p { color: var(--text-light); font-size: 14px; }
.preview-meta { text-align: left; }
.preview-meta p { font-size: 14px; margin-bottom: 4px; }
.preview-meta strong { color: var(--primary); }
.preview-totals { border-top: 2px solid var(--primary); padding-top: 16px; }
.preview-totals .total-row { padding: 6px 0; }
.preview-qr { text-align: center; margin-top: 24px; padding-top: 24px; border-top: 1px dashed var(--border); }
.preview-qr img { max-width: 200px; border: 2px solid var(--border); border-radius: var(--radius-sm); padding: 8px; }
.preview-qr p { margin-top: 8px; font-size: 13px; color: var(--text-light); }

/* Toast */
.toast { position: fixed; bottom: 30px; left: 50%; transform: translateX(-50%) translateY(100px); background: var(--text); color: white; padding: 14px 28px; border-radius: var(--radius-sm); font-weight: 600; box-shadow: var(--shadow-lg); z-index: 2000; opacity: 0; transition: all 0.3s ease; }
.toast.show { transform: translateX(-50%) translateY(0); opacity: 1; }
.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }

/* Footer */
.footer { text-align: center; padding: 30px 20px; margin-top: 40px; color: var(--text-light); font-size: 14px; }
.footer strong { color: var(--primary); }
.footer-note { margin-top: 4px; font-size: 12px; opacity: 0.7; }

/* Responsive */
@media (max-width: 768px) {
  .header-content { flex-direction: column; text-align: center; }
  .form-grid { grid-template-columns: 1fr; }
  .form-actions { flex-direction: column; }
  .tabs { width: 100%; }
  .tab-btn { flex: 1; text-align: center; padding: 10px 12px; font-size: 14px; }
  .stats-grid { grid-template-columns: 1fr; }
}
