:root {
  --bg: #061c26;
  --bg-elev: #0a2836;
  --panel: #0d3243;
  --panel-2: #113c50;
  --glass: rgba(255, 255, 255, 0.045);
  --glass-hover: rgba(255, 255, 255, 0.08);
  --line: rgba(255, 255, 255, 0.11);
  --line-strong: rgba(255, 255, 255, 0.22);
  --ink: #f4f7f9;
  --ink-2: #c9d8e0;
  --muted: #8aa5b4;
  --accent: #ef9122;
  --accent-2: #c9760f;
  --accent-soft: rgba(239, 145, 34, 0.15);
  --danger: #e5534b;
  --danger-soft: rgba(229, 83, 75, 0.16);
  --success: #3fb984;
  --success-soft: rgba(63, 185, 132, 0.16);
  --shadow: 0 20px 50px rgba(2, 12, 18, 0.45);
  --radius: 18px;
}

:root[data-theme="light"] {
  --bg: #edf1f5;
  --bg-elev: #ffffff;
  --panel: #ffffff;
  --panel-2: #f6f9fb;
  --glass: rgba(13, 58, 77, 0.04);
  --glass-hover: rgba(13, 58, 77, 0.08);
  --line: rgba(13, 58, 77, 0.12);
  --line-strong: rgba(13, 58, 77, 0.22);
  --ink: #0a2936;
  --ink-2: #2b4a59;
  --muted: #5a7482;
  --accent-soft: rgba(239, 145, 34, 0.14);
  --shadow: 0 16px 36px rgba(10, 41, 54, 0.08);
}

*, *::before, *::after {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  font-family: 'IBM Plex Sans Arabic', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.logo-light-only { display: none; }
:root[data-theme="light"] .logo-dark-only { display: none; }
:root[data-theme="light"] .logo-light-only { display: block; }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-family: inherit;
  font-weight: 600;
  font-size: 14px;
  padding: 10px 18px;
  border-radius: 12px;
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
  transition: transform 0.15s ease, opacity 0.15s ease, background 0.15s ease, border-color 0.15s ease;
  white-space: nowrap;
}
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn:active:not(:disabled) { transform: scale(0.98); }
.btn-sm { padding: 8px 14px; font-size: 13px; border-radius: 10px; }
.btn-full { width: 100%; padding: 13px 20px; }

.btn-primary {
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-2) 100%);
  color: #fff;
  box-shadow: 0 8px 22px rgba(239, 145, 34, 0.28);
}
.btn-primary:hover:not(:disabled) { filter: brightness(1.06); }

.btn-secondary {
  background: var(--glass);
  border-color: var(--line);
  color: var(--ink);
}
.btn-secondary:hover:not(:disabled) { background: var(--glass-hover); border-color: var(--line-strong); }

.btn-ghost {
  background: transparent;
  color: var(--ink-2);
}
.btn-ghost:hover:not(:disabled) { background: var(--glass); color: var(--ink); }

.btn-danger {
  background: var(--danger);
  color: #fff;
}
.btn-danger-soft {
  background: var(--danger-soft);
  color: #ff8a82;
  border-color: rgba(229, 83, 75, 0.25);
}
:root[data-theme="light"] .btn-danger-soft { color: #b92b24; }
.btn-danger-text { color: #ff8a82; }
:root[data-theme="light"] .btn-danger-text { color: #b92b24; }

.icon-btn {
  background: var(--glass);
  border: 1px solid var(--line);
  color: var(--ink);
  width: 38px;
  height: 38px;
  border-radius: 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 16px;
}

/* Login */
.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(circle at 80% 10%, rgba(239, 145, 34, 0.14), transparent 40%),
    radial-gradient(circle at 15% 85%, rgba(97, 162, 188, 0.16), transparent 45%),
    var(--bg);
}

.login-card {
  width: 100%;
  max-width: 460px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 26px;
  padding: 36px 32px;
  box-shadow: var(--shadow);
}

.login-brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  margin-bottom: 24px;
}
.login-brand img { height: 52px; width: auto; }

.badge-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
  background: var(--accent-soft);
  border: 1px solid rgba(239, 145, 34, 0.32);
  padding: 4px 12px;
  border-radius: 999px;
}

.login-title {
  margin: 0 0 8px;
  font-size: 22px;
  text-align: center;
}
.login-sub {
  margin: 0 0 24px;
  font-size: 13.5px;
  color: var(--muted);
  text-align: center;
}

.form-stack { display: flex; flex-direction: column; gap: 16px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 13px; font-weight: 500; color: var(--ink-2); }

input[type="text"],
input[type="password"],
input[type="email"],
input[type="url"],
select,
textarea {
  width: 100%;
  font-family: inherit;
  font-size: 14px;
  color: var(--ink);
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 14px;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(239, 145, 34, 0.16);
}
textarea { min-height: 92px; resize: vertical; line-height: 1.75; }

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13.5px;
  color: var(--ink-2);
  cursor: pointer;
}
.checkbox-row input { width: 16px; height: 16px; accent-color: var(--accent); }

.inline-alert {
  padding: 11px 14px;
  border-radius: 12px;
  font-size: 13px;
}
.inline-alert-error {
  background: var(--danger-soft);
  border: 1px solid rgba(229, 83, 75, 0.35);
  color: #ffb0ab;
}
:root[data-theme="light"] .inline-alert-error { color: #a11f19; }

.help-box {
  margin-top: 22px;
  padding: 12px 14px;
  border-radius: 14px;
  background: var(--glass);
  border: 1px solid var(--line);
  font-size: 12.5px;
  color: var(--muted);
}
.help-box summary {
  cursor: pointer;
  color: var(--ink-2);
  font-weight: 500;
}
.help-box ol { margin: 10px 0 0; padding-inline-start: 20px; }
.help-box li { margin-bottom: 6px; }
.help-box code {
  background: var(--bg-elev);
  padding: 1px 6px;
  border-radius: 6px;
  color: var(--accent);
}

/* App Shell */
.app-shell {
  display: grid;
  grid-template-columns: 270px 1fr;
  min-height: 100vh;
}

.sidebar {
  background: var(--bg-elev);
  border-inline-end: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  z-index: 40;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 20px 16px;
  border-bottom: 1px solid var(--line);
}
.sidebar-logo { height: 38px; width: auto; }

.sidebar-nav {
  padding: 14px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
}

.nav-group-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  padding: 14px 12px 6px;
  letter-spacing: 0.02em;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  background: transparent;
  border: 1px solid transparent;
  color: var(--ink-2);
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  padding: 10px 12px;
  border-radius: 12px;
  cursor: pointer;
  text-align: right;
  transition: background 0.15s ease, color 0.15s ease;
}
.nav-item:hover { background: var(--glass); color: var(--ink); }
.nav-item.active {
  background: var(--accent-soft);
  border-color: rgba(239, 145, 34, 0.35);
  color: var(--ink);
  font-weight: 600;
}
.nav-item.active .nav-icon { color: var(--accent); }
.nav-icon { font-size: 14px; width: 18px; text-align: center; color: var(--muted); }
.nav-count {
  margin-inline-start: auto;
  font-size: 11.5px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--glass);
  color: var(--muted);
}

.sidebar-footer {
  padding: 14px 16px 18px;
  border-top: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.user-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12.5px;
  color: var(--muted);
  padding: 6px 10px;
  background: var(--glass);
  border-radius: 10px;
}
.user-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--success);
}
.sidebar-footer-actions {
  display: flex;
  justify-content: space-between;
  gap: 8px;
}

/* Main Column & Topbar */
.main-column {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
  padding: 14px 26px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}
.topbar-right { display: flex; align-items: center; gap: 12px; }
.topbar-title { margin: 0; font-size: 19px; font-weight: 700; }
.topbar-sub { margin: 0; font-size: 12.5px; color: var(--muted); }
.topbar-sub.dirty { color: var(--accent); font-weight: 600; }
.topbar-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }

.editor-root {
  padding: 26px;
  max-width: 1120px;
  width: 100%;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* Cards & Grids */
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px;
}

.section-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}
.section-head h2 { margin: 0; font-size: 17px; }
.section-head p { margin: 4px 0 0; font-size: 13px; color: var(--muted); }

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(175px, 1fr));
  gap: 14px;
}
.stat-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 20px;
  cursor: pointer;
  transition: transform 0.15s ease, border-color 0.15s ease;
  text-align: right;
  font-family: inherit;
  color: inherit;
}
.stat-card:hover { transform: translateY(-2px); border-color: var(--accent); }
.stat-num { font-size: 30px; font-weight: 700; color: var(--accent); line-height: 1.2; }
.stat-label { font-size: 13.5px; color: var(--ink-2); margin-top: 4px; }

.item-list { display: flex; flex-direction: column; gap: 14px; }

.item-card {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.item-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
}
.item-badge {
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
  background: var(--accent-soft);
  padding: 3px 10px;
  border-radius: 999px;
}
.item-tools { display: flex; align-items: center; gap: 6px; }

.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }

.tabs-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
}
.tab-btn {
  background: var(--glass);
  border: 1px solid var(--line);
  color: var(--ink-2);
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  padding: 8px 14px;
  border-radius: 999px;
  cursor: pointer;
}
.tab-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}

.upload-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}
.upload-label {
  position: relative;
  overflow: hidden;
}
.upload-label input[type="file"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.partner-preview {
  width: 72px;
  height: 52px;
  border-radius: 10px;
  background: #fff;
  border: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 6px;
  flex-shrink: 0;
}
.partner-preview img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.bulk-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 12px;
  padding: 16px;
  border-radius: 14px;
  background: var(--accent-soft);
  border: 1px solid rgba(239, 145, 34, 0.3);
  margin-bottom: 18px;
}
.bulk-bar .field { flex: 1; min-width: 220px; }

/* Native Modal Dialog (per modern-web-guidance `dialog` guide) */
dialog:modal {
  overscroll-behavior: contain;
}
dialog::backdrop {
  overflow: hidden;
  overscroll-behavior: contain;
  background: rgba(3, 14, 20, 0.68);
  backdrop-filter: blur(5px);
}
.modal-dialog {
  width: min(420px, calc(100vw - 32px));
  background: var(--panel);
  color: var(--ink);
  border: 1px solid var(--line-strong);
  border-radius: 22px;
  padding: 26px 24px;
  box-shadow: var(--shadow);
}
.modal-title { margin: 0 0 8px; font-size: 18px; font-weight: 700; }
.modal-desc { margin: 0 0 22px; font-size: 14px; color: var(--ink-2); }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; }

/* Popover Toast Notifications (per modern-web-guidance `persistent-toast-notifications` guide) */
@supports not selector(:popover-open) {
  [popover]:not(.\:popover-open) {
    display: none;
  }
}

.toast-region {
  position: fixed;
  inset-block-end: 20px;
  inset-inline-start: 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 90;
  pointer-events: none;
  max-width: min(380px, calc(100vw - 40px));
}

.toast-item[popover] {
  position: fixed;
  inset: auto auto 20px 20px;
  margin: 0;
  padding: 13px 16px;
  max-width: min(380px, calc(100vw - 40px));
  background: var(--panel);
  color: var(--ink);
  border: 1px solid var(--line-strong);
  border-inline-start: 4px solid var(--accent);
  border-radius: 14px;
  box-shadow: var(--shadow);
  pointer-events: auto;
  font-size: 13.5px;
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 0.2s ease, transform 0.2s ease, display 0.2s ease, overlay 0.2s ease;
  transition-behavior: allow-discrete;
}
.toast-item[popover]:is(:popover-open, .\:popover-open) {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  opacity: 1;
  transform: translateY(0);
}
.toast-item.toast-success { border-inline-start-color: var(--success); }
.toast-item.toast-error { border-inline-start-color: var(--danger); }

.toast-close {
  background: transparent;
  border: 0;
  color: var(--muted);
  cursor: pointer;
  font-size: 15px;
  padding: 4px 6px;
  border-radius: 6px;
}
.toast-close:hover { color: var(--ink); background: var(--glass); }

@media (prefers-reduced-motion: reduce) {
  .toast-item[popover], .btn, .stat-card {
    transition: none;
  }
}

.mobile-only { display: none; }

@media (max-width: 900px) {
  .app-shell { grid-template-columns: 1fr; }
  .mobile-only { display: inline-flex; }
  .sidebar {
    position: fixed;
    inset-block: 0;
    inset-inline-start: 0;
    width: 280px;
    transform: translateX(105%);
    transition: transform 0.22s ease;
    box-shadow: var(--shadow);
  }
  .sidebar.open { transform: translateX(0); }
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
  .topbar { padding: 12px 16px; }
  .editor-root { padding: 16px; }
}
