:root {
  --navy: #071324;
  --navy-panel: #0d1e34;
  --navy-card: #122845;
  --navy-card-hover: #173256;
  --border: #1e385c;
  --border-focus: #2563eb;
  --primary: #1d6bf3;
  --primary-hover: #1557cf;
  --accent: #ffca21;
  --accent-soft: rgba(255, 202, 33, 0.15);
  --success: #10b981;
  --danger: #ef4444;
  --text: #f1f6fd;
  --text-dim: #94a9c9;
  --text-muted: #5e779c;
  --input-bg: #081628;
  --sidebar-w: 270px;
  --topbar-h: 70px;
  --radius: 14px;
}

@font-face {
  font-family: "Rabar 021";
  src: local("Rabar_021"), url("assets/Rabar_021.woff") format("woff");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: "DM Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background-color: var(--navy);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
}

/* Scrollbar */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: var(--navy); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #2f5280; }

/* Top Navigation Bar */
.admin-header {
  height: var(--topbar-h);
  background: rgba(13, 30, 52, 0.85);
  backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
}

.brand-section {
  display: flex;
  align-items: center;
  gap: 14px;
}

.admin-logo {
  width: 42px;
  height: 42px;
  border-radius: 10px;
  object-fit: cover;
  border: 1px solid rgba(255, 255, 255, 0.15);
}

.brand-title {
  font-family: "Manrope", sans-serif;
  font-weight: 800;
  font-size: 19px;
  letter-spacing: -0.02em;
  color: #fff;
  display: flex;
  align-items: center;
  gap: 8px;
}

.cms-badge {
  background: linear-gradient(135deg, var(--primary), #00c6ff);
  color: #fff;
  font-size: 10px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 3px 8px;
  border-radius: 6px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* Action Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  border-radius: 10px;
  font-weight: 600;
  font-size: 13.5px;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.2s ease;
  text-decoration: none;
  font-family: inherit;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
  box-shadow: 0 4px 14px rgba(29, 107, 243, 0.3);
}
.btn-primary:hover {
  background: var(--primary-hover);
  transform: translateY(-1px);
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.06);
  border-color: var(--border);
  color: var(--text);
}
.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.12);
  border-color: #3b6094;
}

.btn-accent {
  background: var(--accent);
  color: #1a1202;
  box-shadow: 0 4px 14px rgba(255, 202, 33, 0.25);
}
.btn-accent:hover {
  background: #f5bc0e;
  transform: translateY(-1px);
}

.btn-danger {
  background: rgba(239, 68, 68, 0.15);
  border-color: rgba(239, 68, 68, 0.4);
  color: #fca5a5;
}
.btn-danger:hover {
  background: var(--danger);
  color: #fff;
}

.btn-sm {
  padding: 5px 10px;
  font-size: 12px;
  border-radius: 7px;
}

/* Layout Container */
.admin-body {
  display: flex;
  flex: 1;
  position: relative;
}

/* Sidebar */
.admin-sidebar {
  width: var(--sidebar-w);
  background: var(--navy-panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  position: sticky;
  top: var(--topbar-h);
  height: calc(100vh - var(--topbar-h));
  overflow-y: auto;
}

.nav-group-title {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-muted);
  padding: 18px 20px 8px;
}

.sidebar-nav {
  list-style: none;
  padding: 0 10px 20px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-radius: 9px;
  color: var(--text-dim);
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: all 0.15s ease;
}

.nav-item:hover {
  color: #fff;
  background: rgba(255, 255, 255, 0.05);
}

.nav-item.active {
  color: #fff;
  background: rgba(29, 107, 243, 0.18);
  border-left: 3px solid var(--primary);
  padding-left: 11px;
}

.nav-item .icon {
  font-size: 16px;
  width: 20px;
  text-align: center;
}

.sidebar-footer {
  margin-top: auto;
  padding: 16px 20px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-muted);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

/* Main Content Area */
.admin-main {
  flex: 1;
  padding: 32px 40px;
  max-width: 1000px;
  margin: 0 auto;
  width: 100%;
}

.admin-main.preview-expanded {
  max-width: none;
  margin: 0;
  width: 50%;
}

.page-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 18px;
}

.page-title {
  font-family: "Manrope", sans-serif;
  font-size: 26px;
  font-weight: 800;
  color: #fff;
}

.page-subtitle {
  color: var(--text-dim);
  font-size: 14px;
  margin-top: 4px;
}

/* Section Cards */
.admin-card {
  background: var(--navy-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 24px;
  transition: border-color 0.2s;
}

.admin-card:focus-within {
  border-color: #2b5080;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
  padding-bottom: 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.card-title {
  font-family: "Manrope", sans-serif;
  font-size: 17px;
  font-weight: 700;
  color: #fff;
  display: flex;
  align-items: center;
  gap: 10px;
}

.card-desc {
  font-size: 13px;
  color: var(--text-dim);
}

/* Trilingual Language Switcher within Card */
.lang-tabs {
  display: flex;
  gap: 4px;
  background: var(--input-bg);
  padding: 4px;
  border-radius: 9px;
  border: 1px solid var(--border);
}

.lang-tab {
  background: none;
  border: 0;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 700;
  padding: 5px 12px;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.15s;
  font-family: inherit;
}

.lang-tab:hover {
  color: var(--text);
}

.lang-tab.active {
  background: var(--primary);
  color: #fff;
}

/* Form Controls */
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
}

.form-grid.full {
  grid-template-columns: 1fr;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 16px;
}

.form-group:last-child {
  margin-bottom: 0;
}

.form-label {
  font-size: 12.5px;
  font-weight: 700;
  color: var(--text-dim);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.field-badge {
  font-size: 10px;
  background: rgba(255, 255, 255, 0.08);
  padding: 2px 6px;
  border-radius: 4px;
  color: var(--text-muted);
}

.form-control {
  width: 100%;
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 10px 14px;
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.form-control:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(29, 107, 243, 0.2);
}

textarea.form-control {
  resize: vertical;
  min-height: 85px;
  line-height: 1.5;
}

/* Arabic & Kurdish RTL Form Controls */
.form-control.rtl-input {
  direction: rtl;
  text-align: right;
  font-family: "Rabar 021", Tahoma, Arial, sans-serif;
  font-size: 15px;
}

/* Image Upload & Preview Box */
.image-upload-wrapper {
  display: flex;
  align-items: center;
  gap: 16px;
  background: var(--input-bg);
  padding: 12px;
  border-radius: 10px;
  border: 1px dashed var(--border);
}

.image-preview-box {
  width: 64px;
  height: 64px;
  border-radius: 8px;
  background: #040d18;
  border: 1px solid var(--border);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.image-preview-box img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.image-upload-controls {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.file-input-hidden {
  display: none;
}

/* Split Live Preview Drawer */
.admin-preview-pane {
  width: 50%;
  background: #02070f;
  border-left: 1px solid var(--border);
  display: none;
  flex-direction: column;
  position: sticky;
  top: var(--topbar-h);
  height: calc(100vh - var(--topbar-h));
}

.admin-preview-pane.open {
  display: flex;
}

.preview-bar {
  height: 48px;
  background: var(--navy-panel);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
}

.device-switcher {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--navy);
  padding: 3px;
  border-radius: 7px;
  border: 1px solid var(--border);
}

.device-btn {
  background: none;
  border: 0;
  color: var(--text-muted);
  padding: 4px 8px;
  border-radius: 5px;
  font-size: 13px;
  cursor: pointer;
}

.device-btn.active {
  background: var(--primary);
  color: #fff;
}

.preview-frame-wrap {
  flex: 1;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  overflow: hidden;
  background: #09121d;
  padding: 12px;
}

.preview-iframe {
  width: 100%;
  height: 100%;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #fff;
  transition: width 0.3s ease;
}

.preview-iframe.tablet { width: 768px; }
.preview-iframe.mobile { width: 375px; }

/* Toast Notifications */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.toast {
  background: #152d4c;
  color: #fff;
  padding: 12px 20px;
  border-radius: 10px;
  border: 1px solid var(--border);
  box-shadow: 0 12px 35px rgba(0, 0, 0, 0.4);
  font-size: 14px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 10px;
  transform: translateY(20px);
  opacity: 0;
  transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.toast.show {
  transform: translateY(0);
  opacity: 1;
}

.toast.success { border-left: 4px solid var(--success); }
.toast.error { border-left: 4px solid var(--danger); }
.toast.info { border-left: 4px solid var(--primary); }

/* PIN Lock Screen Modal */
.lock-screen {
  position: fixed;
  inset: 0;
  background: rgba(7, 19, 36, 0.94);
  backdrop-filter: blur(20px);
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.lock-card {
  width: min(400px, 100%);
  background: var(--navy-panel);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 36px 30px;
  text-align: center;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.5);
}

.lock-card .brand-logo-big {
  width: 68px;
  height: 68px;
  border-radius: 16px;
  margin-bottom: 14px;
  border: 1px solid rgba(255, 255, 255, 0.15);
}

.lock-card h2 {
  font-family: "Manrope", sans-serif;
  font-size: 22px;
  margin-bottom: 6px;
  color: #fff;
}

.lock-card p {
  font-size: 13.5px;
  color: var(--text-dim);
  margin-bottom: 24px;
}

.pin-input {
  letter-spacing: 0.5em;
  font-size: 24px;
  text-align: center;
  font-weight: 700;
  padding: 12px;
  margin-bottom: 18px;
}

/* Export Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(8px);
  z-index: 5000;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-backdrop.open {
  display: flex;
}

.modal-dialog {
  background: var(--navy-panel);
  border: 1px solid var(--border);
  border-radius: 18px;
  max-width: 650px;
  width: 100%;
  padding: 28px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.6);
  max-height: 90vh;
  overflow-y: auto;
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.modal-title {
  font-family: "Manrope", sans-serif;
  font-size: 20px;
  color: #fff;
}

.modal-close {
  background: none;
  border: 0;
  color: var(--text-muted);
  font-size: 22px;
  cursor: pointer;
}

.code-snippet {
  background: #040b14;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px;
  font-family: monospace;
  font-size: 12px;
  color: #7dd3fc;
  max-height: 250px;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-all;
  margin: 14px 0;
}

/* Category & Feature Accordion Blocks */
.collapsible-item {
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: 12px;
  background: var(--input-bg);
  overflow: hidden;
}

.collapsible-header {
  padding: 14px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  background: rgba(255, 255, 255, 0.02);
  transition: background 0.15s;
}

.collapsible-header:hover {
  background: rgba(255, 255, 255, 0.05);
}

.collapsible-title {
  font-weight: 700;
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.collapsible-body {
  padding: 18px;
  border-top: 1px solid var(--border);
  display: none;
}

.collapsible-item.open .collapsible-body {
  display: block;
}

/* Responsive */
@media (max-width: 1080px) {
  .admin-main.preview-expanded {
    width: 100%;
  }
  .admin-preview-pane {
    position: fixed;
    top: var(--topbar-h);
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    z-index: 150;
  }
}

@media (max-width: 768px) {
  .admin-sidebar {
    position: fixed;
    left: -100%;
    transition: left 0.3s ease;
    z-index: 90;
  }
  .admin-sidebar.open {
    left: 0;
  }
  .admin-main {
    padding: 20px 16px;
  }
  .form-grid {
    grid-template-columns: 1fr;
  }
  .brand-title span {
    display: none;
  }
}

/* Server-backed authentication */
.auth-gate {
  position: fixed;
  inset: 0;
  z-index: 10001;
  display: none;
  place-items: center;
  align-content: center;
  gap: 16px;
  background: var(--navy);
  color: var(--text-dim);
  text-align: center;
}
.auth-gate strong { color: var(--text); font-family: "Manrope", sans-serif; font-size: 17px; letter-spacing: -.01em; }
.auth-gate p { font-size: 12px; margin-top: -8px; }
.auth-gate-spinner {
  width: 28px;
  height: 28px;
  border: 3px solid rgba(255,255,255,.13);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: auth-spin .75s linear infinite;
}
@keyframes auth-spin { to { transform: rotate(360deg); } }
body.auth-pending .auth-gate { display: grid; }
body.auth-pending .admin-header,
body.auth-pending .admin-body,
body.auth-locked .admin-header,
body.auth-locked .admin-body { visibility: hidden; pointer-events: none; user-select: none; }
.admin-user-badge {
  color: var(--text-dim);
  font-size: 12px;
  white-space: nowrap;
}
.login-field { text-align: left; margin-bottom: 12px; }
.login-error { min-height: 20px; margin: 10px 0; color: #fb7185; font-size: 12px; }
.turnstile-container { display: flex; justify-content: center; min-height: 18px; margin: 8px 0; }
.dev-verification { color: var(--text-muted); font-size: 11px; }
body.read-only .content-editable,
body.read-only #saveAllBtn { opacity: .55; pointer-events: none; }

.owner-grid { display: grid; grid-template-columns: minmax(280px, .8fr) minmax(360px, 1.2fr); gap: 24px; }
.field-help { display: block; color: var(--text-muted); font-size: 11px; margin-top: 6px; }
.user-list { display: grid; gap: 10px; }
.user-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px; background: var(--input-bg); border: 1px solid var(--border); border-radius: 11px; }
.user-main { display: flex; align-items: center; gap: 12px; min-width: 0; }
.user-avatar { width: 40px; height: 40px; border-radius: 11px; background: linear-gradient(135deg,var(--primary),#22a6f2); color: white; display: grid; place-items: center; font-weight: 800; flex: 0 0 auto; }
.user-main strong, .user-main small { display: block; }
.user-main small { color: var(--text-muted); margin-top: 2px; }
.role-pills { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 7px; }
.role-pill { display: inline-flex; padding: 3px 8px; border-radius: 999px; background: rgba(29,107,243,.15); border: 1px solid rgba(29,107,243,.3); color: #8fc1ff; font-size: 10px; font-weight: 800; text-transform: uppercase; }
.role-pill.owner { background: rgba(255,202,33,.12); border-color: rgba(255,202,33,.3); color: #fcd34d; }
.role-pill.off { background: rgba(239,68,68,.12); border-color: rgba(239,68,68,.3); color: #fca5a5; }
.audit-table-wrap { overflow-x: auto; }
.audit-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.audit-table th, .audit-table td { padding: 12px; border-bottom: 1px solid var(--border); text-align: left; white-space: nowrap; }
.audit-table th { color: var(--text-muted); font-size: 11px; text-transform: uppercase; letter-spacing: .05em; }
.account-active { display: flex; align-items: center; gap: 9px; color: var(--text-dim); margin: 8px 0 18px; }
.modal-actions { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 18px; }
.user-modal { max-width: 520px; }

@media (max-width: 900px) {
  .owner-grid { grid-template-columns: 1fr; }
  .user-row { align-items: flex-start; }
}
@media (max-width: 940px) {
  .admin-user-badge { display: none; }
}
