/* ── IBM Plex Sans Arabic ────────────────────────────────────────────────── */
@font-face {
  font-family: 'IBM Plex Sans Arabic';
  src: url('../fonts/IBMPlexSansArabic-Regular.ttf') format('truetype');
  font-weight: 400; font-style: normal; font-display: swap;
}
@font-face {
  font-family: 'IBM Plex Sans Arabic';
  src: url('../fonts/IBMPlexSansArabic-Medium.ttf') format('truetype');
  font-weight: 500; font-style: normal; font-display: swap;
}
@font-face {
  font-family: 'IBM Plex Sans Arabic';
  src: url('../fonts/IBMPlexSansArabic-SemiBold.ttf') format('truetype');
  font-weight: 600; font-style: normal; font-display: swap;
}
@font-face {
  font-family: 'IBM Plex Sans Arabic';
  src: url('../fonts/IBMPlexSansArabic-Bold.ttf') format('truetype');
  font-weight: 700; font-style: normal; font-display: swap;
}

/* ── Reset & Variables ──────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --sb-w: 240px;
  --sb-bg: #0f172a;
  --sb-text: #94a3b8;
  --sb-hover: #1e293b;
  --sb-active-bg: #1d4ed8;
  --sb-active-text: #fff;

  --brand: #1d4ed8;
  --brand-dark: #1e40af;
  --brand-light: #dbeafe;

  --green: #16a34a; --green-bg: #f0fdf4;
  --red:   #dc2626; --red-bg:   #fef2f2;
  --amber: #d97706; --amber-bg: #fffbeb;
  --sky:   #0284c7; --sky-bg:   #f0f9ff;
  --slate: #475569; --slate-bg: #f8fafc;

  --bg: #f1f5f9;
  --surface: #fff;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --faint: #94a3b8;

  --r: 8px;
  --sh: 0 1px 3px rgba(0,0,0,.1);
  --sh-md: 0 4px 12px rgba(0,0,0,.08);
  --sh-lg: 0 8px 24px rgba(0,0,0,.1);

  --font: 'IBM Plex Sans Arabic', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'SF Mono', Consolas, monospace;
}

html, body { height: 100%; }
body { font-family: var(--font); font-size: 14px; color: var(--text); background: var(--bg); line-height: 1.5; }

a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

input, select, textarea, button { font-family: inherit; font-size: 14px; }

/* ── Loading ─────────────────────────────────────────────────────────────── */
#app-loading {
  position: fixed; inset: 0; display: flex; align-items: center;
  justify-content: center; background: var(--bg); z-index: 9999;
}
.spin {
  width: 40px; height: 40px; border: 3px solid var(--border);
  border-top-color: var(--brand); border-radius: 50%;
  animation: spin .7s linear infinite;
}
.spin-sm { width: 18px; height: 18px; border-width: 2px; display: inline-block; vertical-align: middle; }
@keyframes spin { to { transform: rotate(360deg); } }

.hidden { display: none !important; }

/* ── Auth ────────────────────────────────────────────────────────────────── */
.auth-bg {
  min-height: 100vh; background: linear-gradient(135deg, #0f172a 0%, #1e3a5f 100%);
  display: flex; align-items: center; justify-content: center; padding: 24px;
}
.auth-panel { width: 100%; max-width: 420px; }
.auth-brand { text-align: center; margin-bottom: 32px; }
.auth-brand p { color: #94a3b8; font-size: 13px; margin-top: 10px; }
.auth-logo { width: 220px; max-width: 100%; filter: drop-shadow(0 4px 16px rgba(0,0,0,.4)); }
.auth-card {
  background: var(--surface); border-radius: 16px; padding: 32px;
  box-shadow: var(--sh-lg);
}
.auth-card h2 { font-size: 20px; font-weight: 600; margin-bottom: 6px; }
.auth-card .subtitle { color: var(--muted); font-size: 13px; margin-bottom: 24px; }

/* ── App Shell ───────────────────────────────────────────────────────────── */
#app-shell { display: flex; height: 100vh; overflow: hidden; }

/* Sidebar */
#sidebar {
  width: var(--sb-w); background: var(--sb-bg); display: flex; flex-direction: column;
  flex-shrink: 0; overflow: hidden; transition: width .2s;
}
.sb-header {
  padding: 14px 16px; border-bottom: 1px solid #1e293b;
  display: flex; align-items: center; gap: 10px;
}
.sb-icon { width: 32px; height: 32px; object-fit: contain; flex-shrink: 0; }
.sb-name  { font-size: 17px; font-weight: 700; color: #fff; letter-spacing: -0.3px; }

#sb-nav { flex: 1; overflow-y: auto; padding: 8px 0; }
.nav-section { padding: 6px 12px 2px; font-size: 10px; font-weight: 600;
  color: #475569; text-transform: uppercase; letter-spacing: .08em; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 16px; color: var(--sb-text); cursor: pointer;
  border-radius: 0; transition: background .15s, color .15s;
  font-size: 13.5px; font-weight: 500; border: none; background: none; width: 100%; text-align: left;
}
.nav-item:hover { background: var(--sb-hover); color: #e2e8f0; }
.nav-item.active { background: var(--sb-active-bg); color: var(--sb-active-text); }
.nav-item .nav-icon { font-size: 16px; width: 20px; text-align: center; flex-shrink: 0; }

#sb-footer {
  padding: 12px 16px; border-top: 1px solid #1e293b; font-size: 12px;
  color: var(--sb-text);
}
.sb-user-name { font-weight: 500; color: #e2e8f0; font-size: 13px; }
.sb-logout-btn {
  margin-top: 8px; font-size: 12px; color: #ef4444; background: none;
  border: none; cursor: pointer; padding: 0;
}
.sb-logout-btn:hover { text-decoration: underline; }

/* App body */
#app-body { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
#app-header {
  background: var(--surface); border-bottom: 1px solid var(--border);
  padding: 0 24px; height: 56px; display: flex; align-items: center; gap: 16px;
  flex-shrink: 0; box-shadow: var(--sh);
}
#menu-toggle { display: none; }
.page-title { font-size: 17px; font-weight: 600; flex: 1; }
#header-right { display: flex; gap: 8px; align-items: center; }
#page-content { flex: 1; overflow-y: auto; padding: 24px; }

/* ── Cards ───────────────────────────────────────────────────────────────── */
.card {
  background: var(--surface); border-radius: var(--r); box-shadow: var(--sh);
  border: 1px solid var(--border);
}
.card-header {
  padding: 16px 20px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.card-header h3 { font-size: 15px; font-weight: 600; }
.card-body { padding: 20px; }

/* Stats grid */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px,1fr)); gap: 16px; margin-bottom: 24px; }
.stat-card {
  background: var(--surface); border-radius: var(--r); padding: 20px;
  border: 1px solid var(--border); box-shadow: var(--sh);
}
.stat-label { font-size: 12px; color: var(--muted); font-weight: 500; text-transform: uppercase; letter-spacing: .05em; }
.stat-value { font-size: 26px; font-weight: 700; margin: 4px 0 2px; color: var(--text); }
.stat-sub { font-size: 12px; color: var(--faint); }
.stat-card.brand { border-color: var(--brand); background: var(--brand-light); }
.stat-card.brand .stat-value { color: var(--brand-dark); }
.stat-card.green { border-color: var(--green); background: var(--green-bg); }
.stat-card.green .stat-value { color: var(--green); }

/* ── Tables ──────────────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th {
  text-align: left; padding: 10px 14px; font-size: 11px; font-weight: 600;
  color: var(--muted); text-transform: uppercase; letter-spacing: .05em;
  border-bottom: 1px solid var(--border); white-space: nowrap; background: var(--bg);
}
td { padding: 11px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: #f8fafc; }
.td-actions { display: flex; gap: 6px; }
.no-data { text-align: center; padding: 40px; color: var(--faint); }

/* Pagination */
.pagination { display: flex; align-items: center; gap: 8px; padding: 12px 20px; justify-content: flex-end; border-top: 1px solid var(--border); }
.pagination span { color: var(--muted); font-size: 13px; }

/* ── Forms ───────────────────────────────────────────────────────────────── */
.form-group { margin-bottom: 16px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
label { display: block; font-size: 13px; font-weight: 500; margin-bottom: 5px; color: var(--text); }
label .req { color: var(--red); }
input[type=text], input[type=email], input[type=password], input[type=number],
input[type=tel], input[type=url], select, textarea {
  width: 100%; padding: 9px 12px; border: 1px solid var(--border); border-radius: var(--r);
  background: var(--surface); color: var(--text); outline: none;
  transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--brand); box-shadow: 0 0 0 3px rgba(29,78,216,.12);
}
textarea { resize: vertical; min-height: 80px; }
.form-hint { font-size: 12px; color: var(--muted); margin-top: 4px; }
.form-actions { display: flex; gap: 10px; justify-content: flex-end; padding-top: 8px; }

/* File input */
.file-input-wrap { border: 2px dashed var(--border); border-radius: var(--r); padding: 16px; text-align: center; cursor: pointer; }
.file-input-wrap:hover { border-color: var(--brand); background: var(--brand-light); }
.file-input-wrap input[type=file] { display: none; }
.current-file { font-size: 12px; color: var(--muted); margin-top: 6px; }
.current-file a { color: var(--brand); }

/* ── Buttons ─────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 9px 18px;
  border-radius: var(--r); font-size: 13.5px; font-weight: 500; cursor: pointer;
  border: 1px solid transparent; transition: all .15s; white-space: nowrap;
}
.btn:disabled { opacity: .6; cursor: not-allowed; }
.btn-primary { background: var(--brand); color: #fff; border-color: var(--brand); }
.btn-primary:hover:not(:disabled) { background: var(--brand-dark); }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-secondary:hover:not(:disabled) { background: var(--bg); }
.btn-success { background: var(--green); color: #fff; }
.btn-success:hover:not(:disabled) { background: #15803d; }
.btn-danger { background: var(--red); color: #fff; }
.btn-danger:hover:not(:disabled) { background: #b91c1c; }
.btn-ghost { background: transparent; color: var(--muted); border-color: transparent; padding: 6px 10px; }
.btn-ghost:hover { background: var(--bg); color: var(--text); }
.btn-sm { padding: 5px 12px; font-size: 12.5px; }
.btn-icon {
  background: none; border: none; cursor: pointer; padding: 6px; border-radius: var(--r);
  color: var(--muted); font-size: 16px; display: inline-flex; align-items: center;
}
.btn-icon:hover { background: var(--bg); color: var(--text); }
.btn-link { background: none; border: none; color: var(--brand); cursor: pointer; padding: 0; font-size: 13px; }
.btn-link:hover { text-decoration: underline; }
.btn-full { width: 100%; justify-content: center; }

/* ── Badges / Status ─────────────────────────────────────────────────────── */
.badge {
  display: inline-block; padding: 2px 9px; border-radius: 999px;
  font-size: 11.5px; font-weight: 600; white-space: nowrap;
}
.badge-green  { background: var(--green-bg);  color: var(--green); }
.badge-red    { background: var(--red-bg);    color: var(--red); }
.badge-amber  { background: var(--amber-bg);  color: var(--amber); }
.badge-sky    { background: var(--sky-bg);    color: var(--sky); }
.badge-slate  { background: var(--slate-bg);  color: var(--slate); }
.badge-brand  { background: var(--brand-light); color: var(--brand-dark); }

/* ── Alerts / Banners ────────────────────────────────────────────────────── */
.alert {
  padding: 12px 16px; border-radius: var(--r); margin-bottom: 20px;
  display: flex; gap: 10px; align-items: flex-start; font-size: 13.5px;
}
.alert-info    { background: var(--sky-bg);   border-left: 4px solid var(--sky);   color: #075985; }
.alert-success { background: var(--green-bg); border-left: 4px solid var(--green); color: #14532d; }
.alert-warning { background: var(--amber-bg); border-left: 4px solid var(--amber); color: #78350f; }
.alert-danger  { background: var(--red-bg);   border-left: 4px solid var(--red);   color: #7f1d1d; }

/* ── Modal ───────────────────────────────────────────────────────────────── */
#modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.5);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000; padding: 16px; backdrop-filter: blur(2px);
}
.modal-box {
  background: var(--surface); border-radius: 12px; box-shadow: var(--sh-lg);
  width: 100%; max-width: 560px; max-height: 90vh; display: flex; flex-direction: column;
}
.modal-box.modal-lg { max-width: 760px; }
.modal-head {
  padding: 16px 20px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  font-size: 15px; font-weight: 600; flex-shrink: 0;
}
.modal-body { padding: 20px; overflow-y: auto; }

/* ── Toasts ──────────────────────────────────────────────────────────────── */
#toast-stack {
  position: fixed; bottom: 24px; right: 24px; z-index: 2000;
  display: flex; flex-direction: column; gap: 8px;
}
.toast {
  padding: 12px 18px; border-radius: var(--r); box-shadow: var(--sh-md);
  font-size: 13.5px; font-weight: 500; color: #fff; min-width: 240px;
  animation: slideIn .2s ease; display: flex; align-items: center; gap: 8px;
}
.toast-success { background: var(--green); }
.toast-error   { background: var(--red); }
.toast-info    { background: var(--sky); }
.toast-warning { background: var(--amber); }
@keyframes slideIn { from { opacity: 0; transform: translateX(20px); } }

/* ── Tabs ────────────────────────────────────────────────────────────────── */
.tabs { display: flex; border-bottom: 2px solid var(--border); margin-bottom: 20px; }
.tab-btn {
  padding: 10px 18px; font-size: 13.5px; font-weight: 500; color: var(--muted);
  cursor: pointer; border: none; background: none; border-bottom: 2px solid transparent;
  margin-bottom: -2px; transition: all .15s;
}
.tab-btn.active { color: var(--brand); border-bottom-color: var(--brand); }
.tab-pane { display: none; }
.tab-pane.active { display: block; }

/* ── Filters bar ─────────────────────────────────────────────────────────── */
.filters { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 16px; }
.filters select, .filters input { width: auto; padding: 7px 10px; }
.filters .filter-label { font-size: 12px; color: var(--muted); font-weight: 500; }

/* ── Detail grid ─────────────────────────────────────────────────────────── */
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.detail-item label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.detail-item p { font-size: 14px; font-weight: 500; margin-top: 2px; word-break: break-all; }

/* ── Code / Key display ──────────────────────────────────────────────────── */
.code-block {
  background: #0f172a; color: #e2e8f0; padding: 14px 16px; border-radius: var(--r);
  font-family: var(--font-mono); font-size: 12.5px; word-break: break-all;
  position: relative;
}
.copy-btn {
  position: absolute; top: 8px; right: 8px; font-size: 11px; padding: 3px 8px;
  background: #1e293b; color: #94a3b8; border: 1px solid #334155;
  border-radius: 4px; cursor: pointer;
}
.copy-btn:hover { color: #fff; }

/* ── Divider ─────────────────────────────────────────────────────────────── */
.divider { border: none; border-top: 1px solid var(--border); margin: 20px 0; }

/* ── Responsive sidebar ──────────────────────────────────────────────────── */
@media (max-width: 768px) {
  #sidebar { position: fixed; inset-block: 0; left: 0; z-index: 500; transform: translateX(-100%); transition: transform .2s; }
  #sidebar.open { transform: translateX(0); }
  #menu-toggle { display: flex; }
  #app-body { width: 100%; }
  .form-row { grid-template-columns: 1fr; }
  .detail-grid { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
}

/* ── Utilities ───────────────────────────────────────────────────────────── */
.mt-0 { margin-top: 0; }
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; }
.mb-16 { margin-bottom: 16px; }
.text-muted { color: var(--muted); }
.text-sm { font-size: 12px; }
.font-mono { font-family: var(--font-mono); font-size: 12px; }
.text-right { text-align: right; }
.flex { display: flex; }
.flex-center { display: flex; align-items: center; }
.gap-8 { gap: 8px; }
.gap-16 { gap: 16px; }
.flex-1 { flex: 1; }
.fw-600 { font-weight: 600; }
.img-thumb { width: 40px; height: 40px; object-fit: cover; border-radius: 6px; border: 1px solid var(--border); }
