/* ═══════════════════════════════════════════════
   نظام إدارة العهد — هدوء الشرق  |  app.css
═══════════════════════════════════════════════ */
@import url('https://fonts.googleapis.com/css2?family=Cairo:wght@400;500;600;700;900&display=swap');

:root {
  --primary:      #1a56db;
  --primary-dark: #1e2a3b;
  --success:      #10b981;
  --warning:      #f59e0b;
  --danger:       #ef4444;
  --purple:       #7c3aed;
  --accent:       #3b82f6;
  --bg:           #f1f5f9;
  --card:         #ffffff;
  --border:       #e5e7eb;
  --text:         #111827;
  --muted:        #6b7280;
  --sidebar-w:    240px;
  --sidebar-bg:   var(--primary-dark);
  --sidebar-text: #e2e8f0;
}

/* ─── Theme active button ─────────────────── */
.theme-btn.active { outline: 2px solid var(--primary); background: #eff6ff !important; }
.lang-btn.active  { background: var(--primary) !important; color: white !important; border-color: var(--primary) !important; }

/* ─── LTR support ────────────────────────── */
[dir="ltr"] .sidebar { right: auto; left: 0; }
[dir="ltr"] .main-content { margin-right: 0; margin-left: var(--sidebar-w); }
[dir="ltr"] .topbar { padding: 0 20px 0 0; }
[dir="ltr"] .notif-panel,
[dir="ltr"] #themePanel { left: auto; right: 0; }
[dir="ltr"] body { direction: ltr; }

/* ─── Sidebar uses CSS var for bg ─────────── */
.sidebar { background: var(--sidebar-bg, var(--primary-dark)); }

/* ─── Reset ─────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: 'Cairo', sans-serif;
  background: var(--bg);
  color: var(--text);
  direction: rtl;
  font-size: 14px;
  min-height: 100vh;
}
a { text-decoration: none; color: inherit; }

/* ─── Layout Shell ───────────────────────── */
.app-shell {
  display: flex;
  min-height: 100vh;
}

/* ─── Sidebar ────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  background: var(--sidebar-bg, var(--primary-dark));
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; right: 0; bottom: 0;
  z-index: 200;
  overflow-y: auto;
}
.sidebar-logo {
  padding: 18px 16px 14px;
  border-bottom: 1px solid rgba(255,255,255,.08);
  display: flex;
  align-items: center;
  gap: 10px;
}
.logo-icon-sm { font-size: 22px; }
.company-name {
  color: #fff;
  font-size: 14px;
  font-weight: 900;
  line-height: 1.2;
}
.company-sub {
  color: rgba(255,255,255,.4);
  font-size: 10px;
}
.sidebar-nav { flex: 1; padding: 8px 0; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 16px;
  color: rgba(255,255,255,.6);
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  transition: .15s;
  border: none;
  background: none;
  width: 100%;
  text-align: right;
}
.nav-item:hover  { background: rgba(255,255,255,.07); color: #fff; }
.nav-item.active { background: var(--primary); color: #fff; font-weight: 700; }
.nav-icon { font-size: 16px; width: 22px; text-align: center; flex-shrink: 0; }

/* ─── Main Content ───────────────────────── */
.main-content {
  margin-right: var(--sidebar-w);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-width: 0;
}

/* ─── Topbar ─────────────────────────────── */
.topbar {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 0 20px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
  gap: 12px;
}
.menu-toggle {
  background: none;
  border: none;
  font-size: 20px;
  cursor: pointer;
  padding: 4px 8px;
  display: none;
}
.topbar-title { font-size: 16px; font-weight: 800; color: var(--primary-dark); flex: 1; }
.topbar-actions { display: flex; align-items: center; gap: 8px; }
.notif-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 20px;
  padding: 4px 8px;
  position: relative;
  border-radius: 8px;
}
.notif-btn:hover { background: #f3f4f6; }
.badge {
  position: absolute;
  top: 0; left: 0;
  background: var(--danger);
  color: white;
  border-radius: 50%;
  width: 17px; height: 17px;
  font-size: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
}
.notif-panel { display: none; }
.notif-panel:not(.hidden) { display: block; }

/* ─── Page Content ───────────────────────── */
.page-content { padding: 20px; flex: 1; }

/* ─── Login ──────────────────────────────── */
.login-page {
  min-height: 100vh;
  background: linear-gradient(135deg, #1e2a3b 0%, #1a56db 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.login-card {
  background: white;
  border-radius: 20px;
  padding: 36px 32px;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 20px 60px rgba(0,0,0,.25);
}
.login-logo { text-align: center; margin-bottom: 24px; }
.login-logo .logo-icon { font-size: 40px; margin-bottom: 8px; }
.login-logo h1 { font-size: 22px; font-weight: 900; color: var(--primary-dark); }
.login-logo p  { font-size: 12px; color: var(--muted); margin-top: 4px; }
.btn-full { width: 100%; justify-content: center; padding: 12px; font-size: 15px; }

/* ─── Cards ──────────────────────────────── */
.card {
  background: var(--card);
  border-radius: 12px;
  border: 1px solid var(--border);
  box-shadow: 0 1px 4px rgba(0,0,0,.05);
  padding: 18px;
}
.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  flex-wrap: wrap;
  gap: 8px;
}
.card-title { font-size: 15px; font-weight: 800; color: var(--primary-dark); }

/* ─── Page Header ────────────────────────── */
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 20px;
  flex-wrap: wrap;
  gap: 12px;
}
.page-header h1 { font-size: 20px; font-weight: 900; color: var(--primary-dark); }
.page-header p  { font-size: 12px; color: var(--muted); margin-top: 3px; }

/* ─── Stats Grid ─────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 12px;
}
.stat-card {
  background: var(--card);
  border-radius: 12px;
  border: 1px solid var(--border);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: default;
  transition: .15s;
  box-shadow: 0 1px 4px rgba(0,0,0,.05);
}
.stat-card:hover { box-shadow: 0 4px 12px rgba(0,0,0,.1); transform: translateY(-1px); }
.stat-icon {
  width: 42px; height: 42px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
}
.stat-icon.blue   { background: #eff6ff; }
.stat-icon.green  { background: #f0fdf4; }
.stat-icon.orange { background: #fffbeb; }
.stat-icon.purple { background: #faf5ff; }
.stat-icon.red    { background: #fff1f2; }
.stat-value { font-size: 22px; font-weight: 900; color: var(--primary-dark); line-height: 1; }
.stat-label { font-size: 11px; color: var(--muted); margin-top: 2px; }

/* ─── Forms ──────────────────────────────── */
.form-group { margin-bottom: 14px; }
.form-group label {
  display: block;
  font-size: 12px;
  font-weight: 700;
  color: #374151;
  margin-bottom: 5px;
}
.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-family: 'Cairo', sans-serif;
  font-size: 13px;
  transition: .15s;
  outline: none;
  background: white;
  color: var(--text);
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(26,86,219,.1);
}
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* ─── Buttons ────────────────────────────── */
.btn {
  padding: 9px 18px;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  font-family: 'Cairo', sans-serif;
  font-size: 13px;
  font-weight: 700;
  transition: .15s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  white-space: nowrap;
}
.btn:hover    { filter: brightness(1.07); }
.btn:disabled { opacity: .5; cursor: not-allowed; filter: none; }
.btn-primary { background: var(--primary); color: white; }
.btn-success { background: var(--success); color: white; }
.btn-danger  { background: var(--danger);  color: white; }
.btn-warning { background: var(--warning); color: white; }
.btn-outline {
  background: transparent;
  border: 1.5px solid var(--border);
  color: var(--text);
}
.btn-outline:hover { border-color: var(--primary); color: var(--primary); filter: none; }
.btn-sm { padding: 5px 10px; font-size: 11px; border-radius: 6px; }
.btn-group { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }

/* ─── Tables ─────────────────────────────── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 500px; }
thead tr { background: #f8fafc; border-bottom: 2px solid var(--border); }
th {
  padding: 10px 12px;
  text-align: right;
  font-size: 11px;
  font-weight: 800;
  color: #374151;
  white-space: nowrap;
  letter-spacing: .3px;
}
td {
  padding: 10px 12px;
  font-size: 13px;
  border-bottom: 1px solid #f3f4f6;
  vertical-align: middle;
}
tr:hover td { background: #f9fafb; }

/* ─── Status Badges ──────────────────────── */
.status {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
}
.status-open     { background: #eff6ff; color: #1a56db; }
.status-sent     { background: #fffbeb; color: #92400e; }
.status-reviewed { background: #faf5ff; color: #6d28d9; }
.status-approved,
.status-accepted,
.status-settled  { background: #f0fdf4; color: #065f46; }
.status-rejected { background: #fff1f2; color: #991b1b; }
.status-vat      { background: #f5f3ff; color: #5b21b6; }
.status-pending  { background: #fef9c3; color: #854d0e; }

/* ─── Modal ──────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 500;
  padding: 16px;
}
.modal-overlay.hidden { display: none; }
.modal-box {
  background: white;
  border-radius: 16px;
  width: 100%;
  max-width: 580px;
  box-shadow: 0 20px 60px rgba(0,0,0,.25);
  max-height: 90vh;
  display: flex;
  flex-direction: column;
}
.modal-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-shrink: 0;
}
.modal-header h3 { font-size: 16px; font-weight: 800; }
.modal-close {
  background: none;
  border: none;
  font-size: 20px;
  cursor: pointer;
  color: var(--muted);
  padding: 4px 8px;
  border-radius: 6px;
}
.modal-close:hover { background: #f3f4f6; }
#modalBody { overflow-y: auto; padding: 16px 20px; flex: 1; }

/* ─── Alerts ─────────────────────────────── */
.alert {
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 13px;
  margin-bottom: 12px;
}
.alert-danger  { background: #fff1f2; color: #991b1b; border: 1px solid #fecaca; }
.alert-success { background: #f0fdf4; color: #065f46; border: 1px solid #6ee7b7; }
.alert-warning { background: #fffbeb; color: #92400e; border: 1px solid #fde68a; }

/* ─── Hidden ─────────────────────────────── */
.hidden { display: none !important; }

/* ─── Toast ──────────────────────────────── */
.toast {
  background: #1e2a3b;
  color: white;
  padding: 11px 18px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 600;
  box-shadow: 0 4px 14px rgba(0,0,0,.2);
  max-width: 320px;
  animation: fadeIn .3s ease;
}
.toast-hide    { opacity: 0; transition: opacity .4s; }
.toast-error   { background: #dc2626; }
.toast-warning { background: #d97706; }
.toast-success { background: #059669; }

/* ─── Empty State ────────────────────────── */
.empty-state { text-align: center; padding: 60px 20px; color: var(--muted); }
.empty-icon  { font-size: 52px; margin-bottom: 12px; }
.empty-state h3 { font-size: 16px; font-weight: 800; color: #374151; margin-bottom: 6px; }
.empty-state p  { font-size: 13px; margin-bottom: 16px; }

/* ─── Tabs ───────────────────────────────── */
.tabs {
  display: flex;
  gap: 0;
  border-bottom: 2px solid var(--border);
  margin-bottom: 16px;
  overflow-x: auto;
}
.tab-btn {
  padding: 10px 20px;
  border: none;
  background: none;
  cursor: pointer;
  font-family: 'Cairo', sans-serif;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  border-bottom: 3px solid transparent;
  margin-bottom: -2px;
  transition: .15s;
  white-space: nowrap;
}
.tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 800; }

/* ─── Progress ───────────────────────────── */
.progress { background: #e5e7eb; border-radius: 999px; height: 8px; overflow: hidden; }
.progress-bar { height: 100%; border-radius: 999px; background: var(--primary); transition: width .4s; }

/* ─── Autocomplete ───────────────────────── */
.ac-dropdown {
  position: absolute;
  top: 100%; right: 0; left: 0;
  z-index: 100;
  background: white;
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0,0,0,.1);
  max-height: 160px;
  overflow-y: auto;
}
.ac-item {
  padding: 9px 12px;
  cursor: pointer;
  font-size: 13px;
  border-bottom: 1px solid #f3f4f6;
}
.ac-item:hover { background: #eff6ff; }

/* ─── Spinner ────────────────────────────── */
.spinner {
  width: 32px; height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

/* ─── Animations ─────────────────────────── */
@keyframes spin    { to { transform: rotate(360deg); } }
@keyframes fadeIn  { from { opacity:0; transform:translateY(-6px); } to { opacity:1; transform:translateY(0); } }

/* ─── Responsive ─────────────────────────── */
@media (max-width: 768px) {
  .sidebar { transform: translateX(100%); transition: transform .25s; }
  .sidebar.open { transform: translateX(0); }
  .main-content { margin-right: 0; }
  .menu-toggle { display: block; }
  .stats-grid  { grid-template-columns: 1fr 1fr; }
  .form-row    { grid-template-columns: 1fr; }
  table        { min-width: 600px; }
}

/* ═══════════════════════════════════════════
   Mobile Responsive — تحسينات الجوال
═══════════════════════════════════════════ */
@media (max-width: 768px) {

  /* صفحات متناسبة مع الجوال */
  .page-content { padding: 12px; padding-bottom: 80px; }

  /* بطاقات أصغر */
  .card { padding: 12px; border-radius: 10px; }
  .stats-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
  .stat-card  { padding: 10px 12px; gap: 8px; }
  .stat-value { font-size: 18px; }
  .stat-icon  { width: 36px; height: 36px; font-size: 16px; }

  /* Page header */
  .page-header { flex-direction: column; margin-bottom: 12px; }
  .page-header h1 { font-size: 17px; }

  /* Topbar */
  .topbar { padding: 0 12px; height: 50px; }
  .topbar-title { font-size: 14px; }

  /* Forms */
  .form-row { grid-template-columns: 1fr; }
  .form-group input,
  .form-group select { padding: 10px 12px; font-size: 14px; }

  /* Buttons */
  .btn { padding: 10px 14px; font-size: 13px; }
  .btn-group { flex-wrap: wrap; gap: 6px; }

  /* Tables — horizontal scroll */
  .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  table { min-width: 580px; }
  th, td { padding: 8px 10px; font-size: 12px; }

  /* Modal */
  .modal-overlay { padding: 8px; align-items: flex-end; }
  .modal-box {
    border-radius: 16px 16px 0 0;
    max-height: 92vh;
    max-width: 100%;
  }

  /* Grids */
  div[style*="grid-template-columns:minmax(0,1fr) minmax(0,1fr)"],
  div[style*="grid-template-columns: 1fr 1fr"] {
    grid-template-columns: 1fr !important;
  }
  div[style*="grid-template-columns:repeat(auto-fill,minmax(300px"] {
    grid-template-columns: 1fr !important;
  }

  /* Tabs — scrollable */
  .tabs { overflow-x: auto; white-space: nowrap; }
  .tab-btn { padding: 8px 14px; font-size: 12px; }

  /* Notif panel */
  #notifPanel { width: 95vw !important; left: 50% !important;
    transform: translateX(-50%); right: auto !important; }

  /* Login */
  .login-card { padding: 24px 20px; border-radius: 16px; }
  .login-logo h1 { font-size: 20px; }
}

/* iPhone safe area */
@supports (padding: env(safe-area-inset-bottom)) {
  .mobile-nav { padding-bottom: env(safe-area-inset-bottom); }
}

/* ═══════════════════════════════════════════════════════════════
   Dark Mode + Theme System
═══════════════════════════════════════════════════════════════ */

/* ── CSS transitions for smooth theme switching ── */
body, .card, .sidebar, .topbar, input, select, textarea, table, .modal-box {
  transition: background-color .25s ease, color .2s ease, border-color .2s ease;
}

/* ── Dark mode overrides ── */
[data-theme="dark"] body {
  background: var(--bg);
  color: var(--text);
}
[data-theme="dark"] .card {
  background: var(--card);
  border-color: var(--border);
  box-shadow: var(--shadow);
}
[data-theme="dark"] .topbar {
  background: var(--topbar-bg);
  border-color: var(--border);
}
[data-theme="dark"] input,
[data-theme="dark"] select,
[data-theme="dark"] textarea {
  background: var(--input-bg) !important;
  color: var(--text) !important;
  border-color: var(--border) !important;
}
[data-theme="dark"] input::placeholder,
[data-theme="dark"] textarea::placeholder {
  color: var(--muted) !important;
}
[data-theme="dark"] table thead tr {
  background: var(--card2) !important;
  color: var(--text2) !important;
}
[data-theme="dark"] table tbody tr:nth-child(even) {
  background: var(--table-stripe) !important;
}
[data-theme="dark"] table tbody tr:hover {
  background: var(--hover) !important;
}
[data-theme="dark"] table td,
[data-theme="dark"] table th {
  border-color: var(--border) !important;
  color: var(--text);
}
[data-theme="dark"] .modal-box {
  background: var(--card) !important;
  color: var(--text) !important;
  border-color: var(--border) !important;
}
[data-theme="dark"] .modal-header {
  border-color: var(--border) !important;
  background: var(--card2) !important;
}
[data-theme="dark"] .modal-overlay {
  background: rgba(0,0,0,.65) !important;
}
[data-theme="dark"] .btn-outline {
  border-color: var(--border);
  color: var(--text);
  background: transparent;
}
[data-theme="dark"] .btn-outline:hover {
  background: var(--hover);
}
[data-theme="dark"] .stat-card {
  background: var(--card);
  border-color: var(--border);
}
[data-theme="dark"] .stat-label { color: var(--muted); }
[data-theme="dark"] .page-header h1 { color: var(--text); }
[data-theme="dark"] .page-header p  { color: var(--muted); }
[data-theme="dark"] .card-title      { color: var(--text); }
[data-theme="dark"] label            { color: var(--text2); }
[data-theme="dark"] .nav-item        { color: var(--sidebar-text); }
[data-theme="dark"] .login-card      { background: var(--card) !important; border-color: var(--border) !important; }
[data-theme="dark"] #themePanel      { background: var(--card) !important; border-color: var(--border) !important; }
[data-theme="dark"] #notifPanel      { background: var(--card) !important; border-color: var(--border) !important; }

/* styles that use hardcoded white/light colors — override in dark */
[data-theme="dark"] div[style*="background:white"],
[data-theme="dark"] div[style*="background:#fff"],
[data-theme="dark"] div[style*="background: white"],
[data-theme="dark"] div[style*="background: #fff"] {
  background: var(--card) !important;
  color: var(--text) !important;
}
[data-theme="dark"] div[style*="background:#f8fafc"],
[data-theme="dark"] div[style*="background:#f9fafb"],
[data-theme="dark"] div[style*="background:#f1f5f9"] {
  background: var(--card2) !important;
}
[data-theme="dark"] div[style*="color:#374151"],
[data-theme="dark"] div[style*="color:#1f2937"],
[data-theme="dark"] div[style*="color:#111827"] {
  color: var(--text) !important;
}
[data-theme="dark"] div[style*="color:#6b7280"],
[data-theme="dark"] span[style*="color:#6b7280"] {
  color: var(--muted) !important;
}
[data-theme="dark"] .status-open,
[data-theme="dark"] .status-sent,
[data-theme="dark"] .status-reviewed,
[data-theme="dark"] .status-pending {
  opacity: .9;
}
[data-theme="dark"] .table-wrap { background: var(--card); }

/* ── Theme color button active state ── */
.theme-color-btn { transition: outline .15s, transform .15s; }
.theme-color-btn:hover { transform: scale(1.15); }
.theme-mode-btn  { transition: border-color .2s, background .2s, color .2s; }
.theme-mode-btn:hover { background: var(--hover) !important; }
