/* ===== متغيرات الألوان ===== */
:root {
  --primary: #1F4E79;
  --primary-light: #2E86C1;
  --accent: #F39C12;
  --success: #1E8449;
  --danger: #922B21;
  --bg: #F0F4F8;
  --card: #FFFFFF;
  --text: #2C3E50;
  --text-muted: #7F8C8D;
  --border: #D5D8DC;
  --radius: 12px;
  --shadow: 0 2px 12px rgba(0,0,0,0.08);
}

/* ===== أساسيات ===== */
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: "Segoe UI", "Tahoma", "Arial", sans-serif;
  background: var(--bg);
  color: var(--text);
  direction: rtl;
  min-height: 100vh;
}

/* ===== شريط التنقل ===== */
.navbar {
  background: var(--primary);
  color: white;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  padding: 10px 20px;
  min-height: 56px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
  position: sticky;
  top: 0;
  z-index: 100;
}
.nav-brand {
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: 0.5px;
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 12px;
}
.nav-brand span { opacity: .9; }
.back-home {
  color: rgba(255,255,255,0.75);
  text-decoration: none;
  font-size: 0.82rem;
  font-weight: 600;
  background: rgba(255,255,255,0.12);
  padding: 4px 10px;
  border-radius: 6px;
  transition: background .2s, color .2s;
  white-space: nowrap;
}
.back-home:hover { background: rgba(255,255,255,0.22); color: #fff; }
.nav-links {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  flex: 1;
  justify-content: center;
}
.nav-links a {
  color: rgba(255,255,255,0.8);
  text-decoration: none;
  padding: 6px 11px;
  border-radius: 7px;
  font-size: 0.85rem;
  transition: all 0.2s;
  white-space: nowrap;
}
.nav-links a:hover, .nav-links a.active {
  background: rgba(255,255,255,0.18);
  color: white;
}

/* ===== تخطيط المحادثة ===== */
.chat-layout {
  display: flex;
  height: calc(100vh - 60px);
  gap: 0;
}

.sidebar {
  width: 260px;
  background: var(--card);
  border-left: 1px solid var(--border);
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow-y: auto;
}
.sidebar h3 {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-muted);
  margin-bottom: 4px;
}
.suggestion {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 14px;
  text-align: right;
  cursor: pointer;
  font-size: 0.88rem;
  color: var(--text);
  transition: all 0.2s;
  line-height: 1.5;
}
.suggestion:hover {
  background: #EBF5FB;
  border-color: var(--primary-light);
  color: var(--primary);
}
.divider { height: 1px; background: var(--border); margin: 4px 0; }

.chat-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.chat-header {
  padding: 16px 24px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.chat-header h2 { font-size: 1rem; color: var(--text); }
.badge {
  background: linear-gradient(135deg, var(--primary), var(--primary-light));
  color: white;
  font-size: 0.75rem;
  padding: 4px 12px;
  border-radius: 20px;
}

/* ===== الرسائل ===== */
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.message {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  max-width: 85%;
}
.message.user { flex-direction: row-reverse; align-self: flex-end; }
.message.assistant { align-self: flex-start; }
.avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  flex-shrink: 0;
  border: 1px solid var(--border);
}
.bubble {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  line-height: 1.7;
  font-size: 0.93rem;
  box-shadow: var(--shadow);
}
.message.user .bubble {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
  border-radius: var(--radius) 4px var(--radius) var(--radius);
}
.message.assistant .bubble {
  border-radius: 4px var(--radius) var(--radius) var(--radius);
}

/* ===== منطقة الإدخال ===== */
.input-area {
  padding: 16px 24px;
  background: var(--card);
  border-top: 1px solid var(--border);
  display: flex;
  gap: 12px;
  align-items: flex-end;
}
.input-area textarea {
  flex: 1;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  padding: 12px 16px;
  font-family: inherit;
  font-size: 0.93rem;
  resize: none;
  outline: none;
  transition: border-color 0.2s;
  line-height: 1.5;
  direction: rtl;
}
.input-area textarea:focus { border-color: var(--primary-light); }

/* ===== أزرار ===== */
.btn-send {
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 10px;
  padding: 12px 24px;
  font-size: 0.93rem;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
  font-family: inherit;
}
.btn-send:hover { background: var(--primary-light); }
.btn-send:disabled { opacity: 0.6; cursor: default; }
.btn-primary {
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 8px;
  padding: 10px 20px;
  cursor: pointer;
  font-size: 0.9rem;
  font-family: inherit;
  transition: all 0.2s;
}
.btn-primary:hover { background: var(--primary-light); }
.btn-secondary {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 20px;
  cursor: pointer;
  font-size: 0.9rem;
  font-family: inherit;
  transition: all 0.2s;
}
.btn-secondary:hover { border-color: var(--primary-light); color: var(--primary); }
.btn-export {
  background: var(--success);
  color: white;
  border: none;
  border-radius: 8px;
  padding: 10px 20px;
  cursor: pointer;
  font-size: 0.9rem;
  font-family: inherit;
  transition: all 0.2s;
}
.btn-export:hover { opacity: 0.9; }
.btn-danger {
  background: transparent;
  color: var(--danger);
  border: 1px solid var(--danger);
  border-radius: 8px;
  padding: 10px 20px;
  cursor: pointer;
  font-size: 0.9rem;
  font-family: inherit;
  transition: all 0.2s;
  margin-top: 8px;
}
.btn-danger:hover { background: var(--danger); color: white; }
.btn-remove {
  background: none;
  border: none;
  color: var(--danger);
  cursor: pointer;
  font-size: 1rem;
  padding: 4px;
}

/* ===== تخطيط الصفحات ===== */
.page-layout {
  max-width: 1100px;
  margin: 0 auto;
  padding: 24px 20px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.page-header h2 { font-size: 1.3rem; color: var(--primary); }
.header-actions { display: flex; gap: 10px; }

/* ===== بطاقات ===== */
.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}
.card h3 { font-size: 1rem; color: var(--primary); margin-bottom: 16px; }
.card h4 { font-size: 0.9rem; color: var(--text-muted); margin: 12px 0 8px; }

/* ===== النماذج ===== */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 16px;
}
.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-group label { font-size: 0.85rem; color: var(--text-muted); font-weight: 600; }
.form-group input, .form-group select, .form-group textarea {
  border: 1.5px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  font-family: inherit;
  font-size: 0.9rem;
  outline: none;
  transition: border-color 0.2s;
  direction: rtl;
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
  border-color: var(--primary-light);
}
.form-actions { display: flex; gap: 10px; margin-top: 16px; }

/* ===== بنود الفاتورة ===== */
.item-row {
  display: flex;
  gap: 10px;
  margin-bottom: 10px;
  align-items: center;
}
.item-desc { flex: 3; }
.item-qty, .item-price { flex: 1; }
.item-total {
  min-width: 80px;
  text-align: center;
  font-weight: 600;
  color: var(--primary);
}
.item-row input {
  border: 1.5px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 0.88rem;
  font-family: inherit;
  outline: none;
  width: 100%;
  direction: rtl;
}
.item-row input:focus { border-color: var(--primary-light); }

/* ===== صندوق الإجماليات ===== */
.totals-box {
  background: var(--bg);
  border-radius: 10px;
  padding: 16px;
  margin-top: 12px;
}
.totals-row {
  display: flex;
  justify-content: space-between;
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}
.totals-row:last-child { border: none; }
.totals-row.total {
  font-size: 1rem;
  font-weight: 700;
  color: var(--primary);
}

/* ===== الجداول ===== */
.table-wrapper { overflow-x: auto; }
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}
thead tr {
  background: var(--primary);
  color: white;
}
th, td {
  padding: 12px 14px;
  text-align: center;
  border-bottom: 1px solid var(--border);
}
tbody tr:hover { background: #F0F4F8; }
tbody tr:last-child td { border-bottom: none; }
.table-toolbar {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.table-toolbar input, .table-toolbar select {
  border: 1.5px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 0.88rem;
  font-family: inherit;
  outline: none;
}
.table-toolbar input:focus, .table-toolbar select:focus {
  border-color: var(--primary-light);
}

/* ===== حالات الشارات ===== */
.status-badge {
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 0.8rem;
  font-weight: 600;
}
.status-مسودة { background: #FEF9E7; color: #D68910; border: 1px solid #F9E79F; }
.status-مرسلة { background: #EBF5FB; color: #1A5276; border: 1px solid #AED6F1; }
.status-مدفوعة { background: #EAFAF1; color: #1E8449; border: 1px solid #A9DFBF; }
.status-ملغاة { background: #FDEDEC; color: #922B21; border: 1px solid #F5B7B1; }
.cat-badge {
  background: var(--bg);
  border: 1px solid var(--border);
  padding: 3px 8px;
  border-radius: 6px;
  font-size: 0.8rem;
}

/* ===== الملخص ===== */
.summary-card { }
.summary-card h3 { font-size: 1rem; color: var(--primary); margin-bottom: 4px; }
.summary-meta { color: var(--text-muted); font-size: 0.85rem; margin-bottom: 12px; }
.summary-row {
  display: flex;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}
.summary-row:last-child { border: none; }
.summary-row.total { font-weight: 700; color: var(--primary); font-size: 1rem; }

/* ===== عرض الراتب الصافي ===== */
.net-preview {
  background: #EAFAF1;
  border: 2px solid var(--success);
  border-radius: 10px;
  padding: 14px 20px;
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--success);
  text-align: center;
  margin: 12px 0;
}
.net-preview.negative {
  background: #FDEDEC;
  border-color: var(--danger);
  color: var(--danger);
}

/* ===== تذييل الرواتب ===== */
.totals-footer {
  display: flex;
  justify-content: space-around;
  padding: 14px;
  background: var(--primary);
  color: white;
  border-radius: 0 0 var(--radius) var(--radius);
  margin: 0 -24px -24px;
  font-size: 0.9rem;
}

/* ===== حالة فارغة ===== */
.empty-state {
  text-align: center;
  padding: 48px;
  color: var(--text-muted);
  font-size: 1rem;
}

/* ===== منتقي العملة ===== */
.currency-picker {
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(255,255,255,0.12);
  border-radius: 8px;
  padding: 4px 10px;
  cursor: pointer;
  position: relative;
}
.currency-picker select {
  background: transparent;
  border: none;
  color: white;
  font-size: 0.88rem;
  font-family: inherit;
  cursor: pointer;
  outline: none;
  appearance: none;
  -webkit-appearance: none;
  padding-left: 4px;
}
.currency-picker select option { color: var(--text); background: white; }
.currency-flag { font-size: 1.1rem; }
.currency-symbol {
  font-weight: 700;
  font-size: 0.85rem;
  color: rgba(255,255,255,0.9);
  min-width: 28px;
}

/* ===== بطاقة العملة في الجداول ===== */
.currency-tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 2px 8px;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--primary);
}

/* ===== تمرير مخصص ===== */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }
