:root {
  --primary: #6366f1; --primary-hover: #4f46e5; --primary-light: #eef2ff;
  --danger: #ef4444; --danger-hover: #dc2626;
  --warn: #f59e0b; --warn-hover: #d97706;
  --success: #22c55e; --success-bg: #f0fdf4;
  --bg: #f1f5f9; --card: #ffffff; --text: #0f172a; --text-sub: #64748b;
  --border: #e2e8f0; --radius: 16px; --shadow: 0 1px 3px rgba(0,0,0,0.04), 0 4px 16px rgba(0,0,0,0.06);
  --sidebar-w: 240px;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: 'Segoe UI', -apple-system, BlinkMacSystemFont, Tahoma, Arial, sans-serif;
  background: var(--bg); color: var(--text); direction: rtl; min-height: 100vh;
  line-height: 1.5;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── ENV BADGE ── */
.env-badge {
  position: fixed; top: 14px; left: 14px;
  padding: 3px 10px; border-radius: 20px;
  font-size: 0.68rem; font-weight: 700; letter-spacing: 1px; z-index: 300;
}
.env-badge.local  { background: #fef3c7; color: #92400e; border: 1px solid #fcd34d; }
.env-badge.server { background: #dcfce7; color: #166534; border: 1px solid #86efac; }

/* ── SIDEBAR ── */
.sidebar {
  position: fixed; top: 0; right: 0; width: var(--sidebar-w); height: 100vh;
  background: linear-gradient(180deg, #0f172a 0%, #1e293b 100%);
  color: #e2e8f0; z-index: 100; display: flex; flex-direction: column;
  box-shadow: -4px 0 24px rgba(0,0,0,0.15);
}
.sidebar-brand {
  padding: 22px 20px 18px; border-bottom: 1px solid rgba(255,255,255,0.08);
}
.sidebar-brand h1 { font-size: 1.1rem; font-weight: 700; color: #fff; margin-bottom: 4px; }
.sidebar-brand .brand-sub { font-size: 0.72rem; color: #94a3b8; }
.sidebar-nav { flex: 1; padding: 12px 10px; overflow-y: auto; }
.sidebar-nav-label {
  font-size: 0.65rem; font-weight: 700; color: #475569; text-transform: uppercase;
  letter-spacing: 1px; padding: 10px 12px 4px; margin-top: 8px;
}
.sidebar-link {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px; border-radius: 10px; color: #cbd5e1;
  font-size: 0.84rem; font-weight: 500; cursor: pointer;
  transition: all 0.15s; text-decoration: none; margin-bottom: 2px;
}
.sidebar-link:hover, .sidebar-link.active {
  background: rgba(255,255,255,0.08); color: #fff; text-decoration: none;
}
.sidebar-link.active { background: rgba(99,102,241,0.2); color: #a5b4fc; }
.sidebar-link .icon { font-size: 1rem; width: 22px; text-align: center; }
.sidebar-user {
  padding: 14px 16px; border-top: 1px solid rgba(255,255,255,0.08);
  display: flex; align-items: center; gap: 10px;
}
.sidebar-user .avatar {
  width: 34px; height: 34px; border-radius: 50%;
  background: var(--primary); color: #fff; display: flex; align-items: center;
  justify-content: center; font-weight: 700; font-size: 0.85rem;
}
.sidebar-user .user-meta { flex: 1; min-width: 0; }
.sidebar-user .user-email {
  font-size: 0.75rem; color: #94a3b8; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap;
}
.sidebar-user .user-role { font-size: 0.65rem; color: #6366f1; font-weight: 600; }
.btn-logout-sb {
  padding: 5px 12px; background: rgba(239,68,68,0.15); color: #fca5a5;
  border: none; border-radius: 6px; font-size: 0.72rem; cursor: pointer;
  font-weight: 600; transition: all 0.15s;
}
.btn-logout-sb:hover { background: rgba(239,68,68,0.3); color: #fff; }

/* ── MAIN CONTENT ── */
.main { margin-right: var(--sidebar-w); padding: 28px 32px; min-height: 100vh; }
.page-header { margin-bottom: 24px; }
.page-header h2 { font-size: 1.3rem; font-weight: 700; color: var(--text); margin-bottom: 4px; }
.page-header p { color: var(--text-sub); font-size: 0.85rem; }

/* ── STAT CARDS ── */
.stats-row {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px; margin-bottom: 24px;
}
.stat-card {
  background: var(--card); border-radius: var(--radius); padding: 20px;
  border: 1px solid var(--border); box-shadow: var(--shadow);
  display: flex; align-items: center; gap: 16px;
}
.stat-icon {
  width: 48px; height: 48px; border-radius: 12px;
  display: flex; align-items: center; justify-content: center; font-size: 1.3rem;
}
.stat-icon.blue { background: #eef2ff; }
.stat-icon.green { background: #f0fdf4; }
.stat-icon.orange { background: #fffbeb; }
.stat-val { font-size: 1.5rem; font-weight: 800; color: var(--text); }
.stat-label { font-size: 0.76rem; color: var(--text-sub); }

/* ── CARDS ── */
.card {
  background: var(--card); border-radius: var(--radius);
  padding: 24px; box-shadow: var(--shadow);
  border: 1px solid var(--border); margin-bottom: 20px;
}
.card.narrow { max-width: 440px; margin: 10vh auto 0; }
.card h2, .card-title {
  font-size: 0.95rem; margin-bottom: 18px; color: var(--text);
  border-bottom: 2px solid var(--bg); padding-bottom: 10px;
  display: flex; align-items: center; gap: 8px; font-weight: 700;
}

/* ── FORM ── */
label { display: block; font-size: 0.8rem; font-weight: 600; margin-bottom: 5px; color: var(--text-sub); }
input[type="email"], input[type="password"], input[type="text"], input[type="tel"], input[type="number"] {
  width: 100%; padding: 10px 14px;
  border: 1.5px solid var(--border); border-radius: 10px;
  font-size: 0.9rem; margin-bottom: 14px; direction: rtl;
  background: #f8fafc; transition: all 0.15s;
}
input:focus {
  outline: none; border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(99,102,241,0.12); background: #fff;
}
input[type="tel"] { direction: ltr; text-align: left; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }

/* ── BUTTONS ── */
.btn {
  display: inline-block; padding: 10px 22px;
  background: var(--primary); color: #fff; border: none; border-radius: 10px;
  font-size: 0.9rem; font-weight: 600; cursor: pointer;
  transition: all 0.15s; width: 100%;
}
.btn:hover { background: var(--primary-hover); transform: translateY(-1px); box-shadow: 0 4px 14px rgba(99,102,241,0.3); }
.btn:active { transform: translateY(0); }
.btn:disabled { background: #94a3b8; cursor: not-allowed; transform: none; box-shadow: none; }
.btn.orange { background: var(--warn); }
.btn.orange:hover { background: var(--warn-hover); box-shadow: 0 4px 14px rgba(245,158,11,0.3); }
.btn-sm {
  padding: 6px 14px; font-size: 0.76rem; width: auto;
  border-radius: 8px; background: var(--primary); color: #fff;
  border: none; cursor: pointer; font-weight: 600; transition: all 0.15s;
}
.btn-sm:hover { background: var(--primary-hover); }

/* ── MESSAGES ── */
.msg {
  margin-top: 14px; padding: 12px 16px; border-radius: 10px;
  font-size: 0.84rem; white-space: pre-wrap; word-break: break-word; display: none;
}
.msg.success { display: block; background: #f0fdf4; color: #166534; border: 1px solid #bbf7d0; }
.msg.error   { display: block; background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }
.msg.info    { display: block; background: #eff6ff; color: #1e40af; border: 1px solid #bfdbfe; }

/* ── TABLE ── */
.table-wrap { overflow-x: auto; border-radius: 10px; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 12px 14px; text-align: right; font-size: 0.84rem; }
th {
  background: #f8fafc; font-weight: 700; color: var(--text-sub);
  font-size: 0.73rem; text-transform: uppercase; letter-spacing: 0.4px;
  border-bottom: 2px solid var(--border); position: sticky; top: 0;
}
td { color: var(--text); border-bottom: 1px solid #f1f5f9; }
tr:hover td { background: #f8fafc; }
.count-badge {
  background: var(--primary-light); color: var(--primary); padding: 3px 12px;
  border-radius: 20px; font-size: 0.76rem; font-weight: 700;
}
.email-cell { font-size: 0.78rem; color: var(--text-sub); direction: ltr; text-align: right; }
.empty-state { color: #94a3b8; font-size: 0.9rem; text-align: center; padding: 40px 20px; }

.hidden { display: none !important; }

/* ── LOG ── */
.sev-info { color: #16a34a; font-weight: 600; }
.sev-warning { color: #d97706; font-weight: 600; }
.sev-error { color: #dc2626; font-weight: 600; }
.log-link {
  display: inline-flex; align-items: center; gap: 4px;
  margin-top: 12px; color: var(--primary);
  font-weight: 600; font-size: 0.82rem; transition: color 0.15s;
}
.log-link:hover { color: var(--primary-hover); }
.btn-copy-sm {
  padding: 4px 10px; font-size: 0.7rem; border-radius: 6px;
  background: var(--primary-light); color: var(--primary); border: none;
  cursor: pointer; font-weight: 600; transition: all 0.15s;
}
.btn-copy-sm:hover { background: #dbeafe; }
.btn-copy-sm.copied { background: #dcfce7; color: #166534; }

/* ── ACTION BTNS ── */
.btn-danger {
  padding: 6px 14px; font-size: 0.74rem; width: auto;
  border-radius: 8px; background: var(--danger); color: #fff;
  border: none; cursor: pointer; font-weight: 600; transition: all 0.15s;
}
.btn-danger:hover { background: var(--danger-hover); }
.btn-edit {
  padding: 6px 14px; font-size: 0.74rem; width: auto;
  border-radius: 8px; background: var(--warn); color: #fff;
  border: none; cursor: pointer; font-weight: 600; transition: all 0.15s;
}
.btn-edit:hover { background: var(--warn-hover); }
.actions-cell { display: flex; gap: 6px; justify-content: flex-end; }

/* ── MODAL ── */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(15,23,42,0.5);
  display: flex; align-items: center; justify-content: center; z-index: 200;
  backdrop-filter: blur(4px);
}
.modal {
  background: var(--card); border-radius: var(--radius); padding: 28px;
  max-width: 500px; width: 92%;
  box-shadow: 0 25px 60px rgba(0,0,0,0.25);
  direction: rtl; border: 1px solid var(--border);
  animation: modalIn 0.2s ease;
}
@keyframes modalIn { from { opacity: 0; transform: scale(0.96) translateY(10px); } to { opacity: 1; transform: none; } }
.modal h3 { margin-bottom: 18px; color: var(--text); font-size: 1.05rem; }
.modal-actions { display: flex; gap: 10px; margin-top: 18px; }
.modal-actions .btn { flex: 1; }
.btn-cancel { background: #94a3b8; }
.btn-cancel:hover { background: #64748b; }

/* ── QUICK ACTIONS ── */
.quick-actions {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 14px; margin-bottom: 24px;
}
.quick-action {
  display: flex; align-items: center; gap: 14px;
  padding: 18px 20px; background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  text-decoration: none; color: var(--text); transition: all 0.15s; cursor: pointer;
}
.quick-action:hover {
  border-color: var(--primary); box-shadow: 0 4px 20px rgba(99,102,241,0.12);
  transform: translateY(-2px); text-decoration: none;
}
.quick-action .qa-icon {
  width: 42px; height: 42px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center; font-size: 1.2rem;
}
.quick-action .qa-title { font-weight: 700; font-size: 0.88rem; }
.quick-action .qa-desc { font-size: 0.74rem; color: var(--text-sub); }

/* ── STATUS BADGES ── */
.status-badge {
  display: inline-block; padding: 3px 12px; border-radius: 20px;
  font-size: 0.72rem; font-weight: 700; letter-spacing: 0.3px;
}
.status-active { background: #f0fdf4; color: #16a34a; }
.status-inactive { background: #fef2f2; color: #dc2626; }
.status-online { background: #f0fdf4; color: #16a34a; }
.status-offline { background: #fef2f2; color: #b91c1c; }
.role-badge {
  display: inline-block; padding: 3px 12px; border-radius: 20px;
  font-size: 0.72rem; font-weight: 700;
}
.role-super { background: #fef3c7; color: #92400e; }
.role-admin { background: #eef2ff; color: #6366f1; }
.role-customer { background: #f0fdf4; color: #16a34a; }

/* ── TABS ── */
.tabs { display: flex; gap: 0; border-bottom: 2px solid var(--border); margin-bottom: 20px; }
.tab-btn {
  padding: 10px 20px; background: none; border: none;
  font-size: 0.84rem; font-weight: 600; color: var(--text-sub);
  cursor: pointer; border-bottom: 2px solid transparent;
  margin-bottom: -2px; transition: all 0.15s;
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ── FILTERS BAR ── */
.filters-bar {
  display: flex; gap: 12px; flex-wrap: wrap; align-items: center;
  margin-bottom: 20px; padding: 14px 18px;
  background: #f8fafc; border-radius: 12px; border: 1px solid var(--border);
}
.filters-bar select, .filters-bar input[type="text"] {
  padding: 8px 14px; border: 1.5px solid var(--border); border-radius: 8px;
  font-size: 0.82rem; background: #fff; min-width: 160px; margin-bottom: 0;
}
.filters-bar select:focus, .filters-bar input:focus {
  border-color: var(--primary); outline: none;
  box-shadow: 0 0 0 3px rgba(99,102,241,0.1);
}

/* ── DETAIL SECTIONS ── */
.detail-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 14px; margin-bottom: 20px;
}
.detail-item { padding: 14px 16px; background: #f8fafc; border-radius: 10px; border: 1px solid var(--border); }
.detail-item .dl { font-size: 0.72rem; color: var(--text-sub); font-weight: 600; margin-bottom: 4px; }
.detail-item .dv { font-size: 0.9rem; color: var(--text); font-weight: 600; }

/* ── SELECT (general) ── */
select {
  width: 100%; padding: 10px 14px;
  border: 1.5px solid var(--border); border-radius: 10px;
  font-size: 0.9rem; margin-bottom: 14px; direction: rtl;
  background: #f8fafc; appearance: auto; transition: all 0.15s;
}
select:focus {
  outline: none; border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(99,102,241,0.12); background: #fff;
}

/* ── RESPONSIVE ── */
@media (max-width: 860px) {
  .sidebar { display: none; }
  .main { margin-right: 0; padding: 16px; }
  .form-row { grid-template-columns: 1fr; }
  .stats-row { grid-template-columns: 1fr 1fr; }
  .quick-actions { grid-template-columns: 1fr; }
}
@media (max-width: 480px) {
  .stats-row { grid-template-columns: 1fr; }
}

/* ── STYLED MODAL (confirm/alert/prompt) ── */
.ui-modal-backdrop {
  position: fixed; inset: 0; background: rgba(15,23,42,0.55);
  display: flex; align-items: center; justify-content: center;
  z-index: 9999; opacity: 0; transition: opacity 0.18s ease;
  padding: 16px;
}
.ui-modal-backdrop.show { opacity: 1; }
.ui-modal {
  background: #fff; border-radius: 18px; max-width: 440px; width: 100%;
  box-shadow: 0 20px 60px rgba(0,0,0,0.25);
  transform: scale(0.92); transition: transform 0.2s ease; overflow: hidden;
  direction: rtl;
}
.ui-modal-backdrop.show .ui-modal { transform: scale(1); }
.ui-modal-header {
  padding: 22px 24px 8px; display: flex; align-items: center; gap: 12px;
}
.ui-modal-icon {
  width: 44px; height: 44px; border-radius: 12px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.4rem;
}
.ui-modal-icon.info    { background: #eef2ff; color: var(--primary); }
.ui-modal-icon.success { background: #f0fdf4; color: #16a34a; }
.ui-modal-icon.warning { background: #fef3c7; color: #d97706; }
.ui-modal-icon.danger  { background: #fee2e2; color: #dc2626; }
.ui-modal-title {
  font-size: 1.05rem; font-weight: 700; color: var(--text); margin: 0;
}
.ui-modal-body {
  padding: 4px 24px 20px; color: var(--text-sub); font-size: 0.9rem;
  line-height: 1.55; white-space: pre-wrap; word-break: break-word;
}
.ui-modal-input {
  width: 100%; padding: 10px 14px;
  border: 1.5px solid var(--border); border-radius: 10px;
  font-size: 0.9rem; margin-top: 12px; direction: rtl;
  background: #f8fafc; transition: all 0.15s; box-sizing: border-box;
}
.ui-modal-input:focus {
  outline: none; border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(99,102,241,0.12); background: #fff;
}
.ui-modal-footer {
  padding: 14px 24px 20px; display: flex; gap: 10px; justify-content: flex-end;
  background: #f8fafc; border-top: 1px solid #f1f5f9;
}
.ui-modal-btn {
  padding: 9px 22px; border-radius: 10px; border: none; cursor: pointer;
  font-size: 0.85rem; font-weight: 600; transition: all 0.15s;
}
.ui-modal-btn.primary { background: var(--primary); color: #fff; }
.ui-modal-btn.primary:hover { background: var(--primary-hover); }
.ui-modal-btn.danger  { background: var(--danger);  color: #fff; }
.ui-modal-btn.danger:hover  { background: var(--danger-hover);  }
.ui-modal-btn.cancel  { background: #fff; color: var(--text); border: 1.5px solid var(--border); }
.ui-modal-btn.cancel:hover { background: #f1f5f9; }

/* ── TOAST ── */
.ui-toast-stack {
  position: fixed; top: 24px; left: 50%; transform: translateX(-50%);
  display: flex; flex-direction: column; gap: 10px; z-index: 10000;
  pointer-events: none;
}
.ui-toast {
  background: #fff; border-radius: 12px; padding: 12px 18px 12px 14px;
  box-shadow: 0 6px 24px rgba(0,0,0,0.15);
  display: flex; align-items: center; gap: 10px;
  font-size: 0.85rem; font-weight: 600;
  border-right: 4px solid var(--primary);
  min-width: 260px; max-width: 420px; direction: rtl;
  transform: translateY(-12px); opacity: 0;
  transition: transform 0.22s ease, opacity 0.22s ease;
  pointer-events: auto;
}
.ui-toast.show { transform: translateY(0); opacity: 1; }
.ui-toast.success { border-color: #16a34a; color: #166534; background: #f0fdf4; }
.ui-toast.error   { border-color: #dc2626; color: #991b1b; background: #fef2f2; }
.ui-toast.warning { border-color: #d97706; color: #92400e; background: #fffbeb; }
.ui-toast.info    { border-color: var(--primary); color: #1e40af; background: #eef2ff; }
.ui-toast .ui-toast-icon { font-size: 1.05rem; }
