/* ============================================================
   نظام تقارير العمليات — التصميم الكامل
   ============================================================ */

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

:root {
  --bg-main: #000000;
  --bg-card: #0a1512;
  --bg-input: #0d1a15;
  --border-card: #12332a;
  --border-input: #1a4438;
  --accent: #14a67e;
  --accent-dark: #0e7d5f;
  --accent-glow: rgba(20, 166, 126, 0.15);
  --text-main: #e8f5f0;
  --text-muted: #7a9c92;
  --text-dim: #4a6b62;
  --danger: #c02828;
  --danger-hover: #d63838;
}

html { direction: rtl; }

body {
  background: var(--bg-main);
  color: var(--text-main);
  font-family: "Tajawal", "Cairo", "Segoe UI", Tahoma, sans-serif;
  min-height: 100vh;
  padding: 30px 20px;
  background-image:
    radial-gradient(circle at 20% 10%, rgba(20, 166, 126, 0.04) 0%, transparent 40%),
    radial-gradient(circle at 80% 80%, rgba(20, 166, 126, 0.03) 0%, transparent 40%);
}

/* ---------- Header ---------- */
.top-header { text-align: center; margin-bottom: 30px; }
.top-logo {
  width: 70px; height: 70px; margin: 0 auto 15px;
  object-fit: contain; filter: drop-shadow(0 0 12px var(--accent-glow));
}
/* شعار الصفحة الرئيسية — عدّل width/height هنا للتحكم بالحجم */
.main-logo {
  display: block;
  width: 120px;         /* عرض الصورة */
  height: 120px;        /* ارتفاع الصورة */
  margin: 0 auto 20px;  /* المسافة من الأسفل */
  object-fit: contain;
  filter: drop-shadow(0 0 15px var(--accent-glow));
}
.anchor-icon {
  width: 60px; height: 60px; margin: 0 auto 15px;
  color: var(--accent); filter: drop-shadow(0 0 8px var(--accent-glow));
}
.top-header h1 { font-size: 26px; font-weight: 700; color: var(--text-main); letter-spacing: 0.5px; }
.top-header .subtitle { color: var(--text-muted); font-size: 14px; margin-top: 6px; }

/* ---------- Meta bar ---------- */
.meta-bar {
  max-width: 900px; margin: 0 auto 25px;
  background: var(--bg-card); border: 1px solid var(--border-card);
  border-radius: 12px; padding: 15px;
  display: flex; flex-wrap: wrap; gap: 12px;
  justify-content: center; align-items: center;
}
.meta-field { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.meta-field label { color: var(--text-muted); font-weight: 600; }
.meta-field input, .meta-field select {
  background: var(--bg-input); color: var(--text-main);
  border: 1px solid var(--border-input); border-radius: 6px;
  padding: 6px 10px; font-family: inherit; font-size: 13px;
}
.meta-field input:focus, .meta-field select:focus {
  outline: 1px solid var(--accent); border-color: var(--accent);
}

/* ---------- Shift Toggle ---------- */
.shift-toggle {
  display: flex; justify-content: center; gap: 0;
  margin: 25px auto 35px; max-width: 700px;
  background: var(--bg-card); border: 1px solid var(--border-card);
  border-radius: 12px; padding: 6px;
}
.shift-btn {
  flex: 1; padding: 12px 18px; background: transparent;
  color: var(--text-muted); border: none; border-radius: 8px;
  font-size: 14px; font-weight: 600; cursor: pointer;
  transition: all 0.2s; font-family: inherit; white-space: nowrap;
}
.shift-btn:hover { color: var(--text-main); }
.shift-btn.active {
  background: var(--accent); color: #fff;
  box-shadow: 0 2px 12px var(--accent-glow);
}

/* ---------- Grid of Section Cards ---------- */
.sections-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 18px; max-width: 1500px;
  margin: 0 auto 30px; justify-content: center;
}

.section-card {
  background: var(--bg-card); border: 1px solid var(--border-card);
  border-radius: 12px; padding: 16px;
  display: flex; flex-direction: column; gap: 10px;
  transition: border-color 0.2s;
}
.section-card:hover { border-color: var(--accent-dark); }

.section-header {
  display: flex; justify-content: space-between; align-items: center;
  padding-bottom: 10px; border-bottom: 1px solid var(--border-card);
  gap: 10px; flex-wrap: wrap;
}
.section-title {
  display: flex; align-items: center; gap: 8px;
  font-size: 15px; font-weight: 700; color: var(--accent);
  flex: 1; min-width: 0;
}
.section-title img, .section-title svg {
  width: 18px; height: 18px; object-fit: contain; opacity: 0.95;
  flex-shrink: 0;
}
.section-title-input {
  background: transparent; color: var(--accent);
  border: 1px dashed transparent; border-radius: 4px;
  padding: 3px 6px; font-size: 15px; font-weight: 700;
  font-family: inherit; flex: 1; min-width: 60px;
  text-align: right;
}
.section-title-input:hover, .section-title-input:focus {
  border-color: var(--border-input); outline: none;
  background: var(--bg-input);
}
.section-actions { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.add-unit-btn {
  background: transparent; color: var(--accent);
  border: 1px dashed var(--accent-dark); border-radius: 6px;
  padding: 4px 10px; font-size: 12px; font-weight: 600;
  cursor: pointer; font-family: inherit; transition: all 0.2s;
}
.add-unit-btn:hover { background: var(--accent-glow); border-style: solid; }

.mention-toggle {
  display: flex; align-items: center; gap: 5px;
  color: var(--text-muted); font-size: 11px;
  cursor: pointer; user-select: none;
  padding: 3px 8px; border: 1px solid var(--border-input);
  border-radius: 6px; background: var(--bg-input);
}
.mention-toggle input { cursor: pointer; accent-color: var(--accent); }
.mention-toggle:hover { color: var(--text-main); border-color: var(--accent-dark); }

/* عمود عمودي لمربعات الاختيار (كوبي ايدي + بدون كود) */
.section-checkboxes {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

/* زر خروج */
.exit-btn {
  background: transparent;
  color: #e0a94f;
  border: 1px solid #a56616;
  border-radius: 4px;
  padding: 2px 8px;
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.15s;
  height: 22px;
  flex-shrink: 0;
}
.exit-btn:hover {
  background: #a56616;
  color: #fff;
}

/* لوحة استيراد النص */
.text-import-container {
  max-width: 900px;
  margin: 20px auto;
  background: var(--bg-card);
  border: 1px solid var(--border-card);
  border-radius: 12px;
  padding: 15px 18px;
}
.text-import-checkbox {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  color: var(--text-main);
  font-weight: 700;
  font-size: 14px;
  user-select: none;
}
.text-import-checkbox input {
  accent-color: var(--accent);
  cursor: pointer;
  width: 16px;
  height: 16px;
}
.text-import-panel {
  margin-top: 15px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.text-import-hint {
  color: var(--text-muted);
  font-size: 12px;
  line-height: 1.7;
  padding: 8px 12px;
  background: var(--bg-input);
  border-radius: 6px;
}
.text-import-hint code {
  background: var(--bg-main);
  color: var(--accent);
  padding: 1px 6px;
  border-radius: 3px;
  font-size: 11px;
  font-family: "Consolas", monospace;
}
.text-import-input {
  background: var(--bg-input);
  color: var(--text-main);
  border: 1px solid var(--border-input);
  border-radius: 8px;
  padding: 10px;
  font-family: "Consolas", "Courier New", monospace;
  font-size: 13px;
  line-height: 1.7;
  resize: vertical;
  min-height: 200px;
  direction: rtl;
  width: 100%;
}
.text-import-input:focus { outline: 1px solid var(--accent); border-color: var(--accent); }
.text-import-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
}
.text-import-result {
  max-height: 250px;
  overflow-y: auto;
  border-top: 1px solid var(--border-card);
  padding-top: 10px;
}
.text-import-result:empty { display: none; }
.import-summary {
  display: flex;
  gap: 15px;
  justify-content: center;
  padding: 8px;
  font-size: 13px;
  font-weight: 700;
  margin-bottom: 10px;
}
.import-summary .ok { color: var(--accent); }
.import-summary .warn { color: #d68a28; }
.import-summary .fail { color: var(--danger); }
.import-log {
  list-style: none;
  padding: 0;
  margin: 0;
  font-size: 12px;
}
.import-log li {
  padding: 4px 8px;
  border-bottom: 1px solid var(--border-card);
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}
.import-log li:last-child { border-bottom: none; }
.import-log li.ok { color: var(--accent); }
.import-log li.warn { color: #d68a28; }
.import-log li.fail { color: var(--danger); }
.import-log code {
  background: var(--bg-main);
  color: var(--text-muted);
  padding: 2px 6px;
  border-radius: 3px;
  font-family: "Consolas", monospace;
  font-size: 11px;
  direction: rtl;
}

/* ---------- Unit Row ---------- */
.unit-row {
  display: flex; align-items: center; gap: 6px;
  background: var(--bg-input); border: 1px solid var(--border-input);
  border-radius: 8px; padding: 6px 8px; flex-wrap: wrap;
}
.unit-label {
  color: var(--text-main); font-size: 13px; font-weight: 500;
  flex: 1; min-width: 60px; text-align: right; padding: 0 4px;
}
.unit-label-input {
  background: transparent; color: var(--text-main);
  border: 1px dashed transparent; border-radius: 4px;
  padding: 2px 4px; font-size: 13px; font-family: inherit;
  font-weight: 500; flex: 1; min-width: 60px; text-align: right;
}
.unit-label-input:hover, .unit-label-input:focus {
  border-color: var(--border-input); outline: none; background: var(--bg-main);
}

.unit-controls { display: flex; gap: 5px; align-items: center; order: -1; }

.rank-select, .modifier-select {
  background: var(--bg-main); color: var(--text-main);
  border: 1px solid var(--border-input); border-radius: 5px;
  padding: 4px 6px; font-size: 12px; cursor: pointer;
  font-family: inherit; min-width: 40px;
}
.modifier-select { min-width: 55px; }
.rank-select:focus, .modifier-select:focus { outline: 1px solid var(--accent); }

.code-input {
  background: var(--bg-main); color: var(--text-main);
  border: 1px solid var(--border-input); border-radius: 5px;
  padding: 4px 6px; font-size: 12px; width: 60px;
  text-align: center; font-family: inherit;
}
.code-input:focus { outline: 1px solid var(--accent); border-color: var(--accent); }
.code-input::placeholder { color: var(--text-dim); }

.mention-input {
  background: var(--bg-main); color: var(--text-main);
  border: 1px solid var(--border-input); border-radius: 5px;
  padding: 4px 6px; font-size: 12px; width: 130px;
  font-family: inherit; direction: ltr; text-align: left;
}
.mention-input:focus { outline: 1px solid var(--accent); border-color: var(--accent); }
.mention-input::placeholder { color: var(--text-dim); font-size: 11px; }

.text-input-area {
  background: var(--bg-main); color: var(--text-main);
  border: 1px solid var(--border-input); border-radius: 5px;
  padding: 6px 8px; font-size: 13px; width: 100%;
  font-family: inherit; min-height: 60px; resize: vertical;
}

.delete-btn {
  background: var(--danger); color: #fff; border: none;
  border-radius: 4px; width: 22px; height: 22px;
  font-size: 12px; font-weight: 700; cursor: pointer;
  font-family: inherit; display: flex; align-items: center;
  justify-content: center; transition: background 0.15s; flex-shrink: 0;
}
.delete-btn:hover { background: var(--danger-hover); }

/* ---------- Final Report ---------- */
.report-final {
  max-width: 900px; margin: 40px auto 30px;
  background: var(--bg-card); border: 1px solid var(--border-card);
  border-radius: 12px; padding: 20px;
}
.report-final-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 15px;
}
.report-final-title { font-size: 18px; font-weight: 700; color: var(--accent); }
.report-final-actions { display: flex; gap: 10px; }
.copy-btn {
  background: var(--accent); color: #fff; border: none;
  border-radius: 6px; padding: 8px 20px; font-size: 13px;
  font-weight: 700; cursor: pointer; font-family: inherit;
  transition: background 0.15s;
}
.copy-btn:hover { background: var(--accent-dark); }
.copy-btn.copied { background: #2a7d5a; }
.copy-btn.danger {
  background: transparent; color: var(--danger);
  border: 1px solid var(--danger);
}
.copy-btn.danger:hover { background: var(--danger); color: #fff; }

.report-output {
  background: var(--bg-main); border: 1px solid var(--border-input);
  border-radius: 8px; padding: 18px; color: var(--text-main);
  font-family: "Consolas", "Courier New", monospace;
  font-size: 13px; line-height: 1.9; white-space: pre-wrap;
  max-height: 600px; overflow-y: auto;
  direction: rtl; text-align: right;
}
.report-output::-webkit-scrollbar { width: 8px; }
.report-output::-webkit-scrollbar-track { background: var(--bg-card); }
.report-output::-webkit-scrollbar-thumb { background: var(--border-input); border-radius: 4px; }

/* ---------- Home Page ---------- */
.main-menu {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 320px));
  gap: 25px; justify-content: center;
  max-width: 800px; margin: 50px auto;
}
.main-menu-card {
  background: var(--bg-card); border: 1px solid var(--border-card);
  border-radius: 16px; padding: 45px 25px; text-align: center;
  text-decoration: none; color: var(--text-main);
  transition: all 0.2s; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 18px;
}
.main-menu-card:hover {
  border-color: var(--accent); transform: translateY(-3px);
  box-shadow: 0 8px 25px var(--accent-glow);
}
.main-menu-card-icon { width: 65px; height: 65px; color: var(--accent); }
.main-menu-card-name { font-size: 20px; font-weight: 700; }
.main-menu-card-desc { font-size: 13px; color: var(--text-muted); margin-top: -8px; }

.home-container { max-width: 1400px; margin: 0 auto; }
.home-group-title {
  text-align: center; color: var(--text-muted); font-size: 15px;
  margin: 30px 0 20px; position: relative;
}
.home-group-title::before, .home-group-title::after {
  content: ""; position: absolute; top: 50%;
  width: 25%; height: 1px; background: var(--border-card);
}
.home-group-title::before { right: 15%; }
.home-group-title::after { left: 15%; }

.home-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 240px));
  gap: 20px; margin-bottom: 30px; justify-content: center;
}
.home-card {
  background: var(--bg-card); border: 1px solid var(--border-card);
  border-radius: 12px; padding: 25px 15px; text-align: center;
  text-decoration: none; color: var(--text-main);
  transition: all 0.2s; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 12px;
}
.home-card:hover {
  border-color: var(--accent); transform: translateY(-2px);
  box-shadow: 0 6px 20px var(--accent-glow);
}
.home-card-logo {
  width: 55px; height: 55px; object-fit: contain;
  filter: drop-shadow(0 0 8px var(--accent-glow));
}
.home-card-name { font-size: 15px; font-weight: 700; }

/* ---------- Back Button ---------- */
.back-link {
  display: inline-flex; align-items: center; gap: 6px;
  color: var(--text-muted); text-decoration: none;
  font-size: 13px; margin-bottom: 15px; padding: 6px 12px;
  border-radius: 6px; transition: all 0.2s;
}
.back-link:hover { color: var(--accent); background: var(--bg-card); }

/* ---------- Random Distribution Panel ---------- */
.dist-toggle-row {
  display: flex; justify-content: center; gap: 10px;
  margin: 20px auto; flex-wrap: wrap;
}
.dist-toggle-btn {
  background: var(--bg-card); color: var(--accent);
  border: 1px solid var(--accent-dark); border-radius: 8px;
  padding: 10px 20px; font-size: 13px; font-weight: 700;
  cursor: pointer; font-family: inherit; transition: all 0.15s;
}
.dist-toggle-btn:hover { background: var(--accent-glow); }
.dist-toggle-btn.primary {
  background: var(--accent); color: #fff;
}
.dist-toggle-btn.primary:hover { background: var(--accent-dark); }

.dist-panel {
  max-width: 700px; margin: 0 auto 30px;
  background: var(--bg-card); border: 1px solid var(--border-card);
  border-radius: 12px; padding: 20px; display: none;
}
.dist-panel.open { display: block; }
.dist-panel-title {
  color: var(--accent); font-size: 16px; font-weight: 700;
  margin-bottom: 12px; text-align: center;
}
.dist-panel-sub {
  color: var(--text-muted); font-size: 12px;
  margin-bottom: 15px; text-align: center;
}
.rank-pills {
  display: flex; justify-content: center; gap: 6px;
  flex-wrap: wrap; margin-bottom: 15px;
}
.rank-pill {
  background: var(--bg-input); color: var(--text-main);
  border: 1px solid var(--border-input); border-radius: 8px;
  padding: 8px 14px; font-size: 14px; font-weight: 700;
  cursor: pointer; font-family: inherit; min-width: 40px;
  transition: all 0.15s;
}
.rank-pill:hover { border-color: var(--accent-dark); color: var(--accent); }
.rank-pill.active {
  background: var(--accent); color: #fff;
  border-color: var(--accent); box-shadow: 0 0 10px var(--accent-glow);
}

.dist-input-row {
  display: flex; justify-content: center; gap: 8px;
  align-items: center; margin-bottom: 15px;
}
.dist-input-row label { color: var(--text-muted); font-size: 13px; }
.dist-code-input {
  background: var(--bg-input); color: var(--text-main);
  border: 1px solid var(--border-input); border-radius: 6px;
  padding: 8px 12px; font-size: 14px; width: 100px;
  text-align: center; font-family: inherit;
}
.dist-code-input:focus { outline: 1px solid var(--accent); border-color: var(--accent); }

.dist-list {
  background: var(--bg-input); border: 1px solid var(--border-input);
  border-radius: 8px; padding: 10px; min-height: 60px;
  max-height: 200px; overflow-y: auto; margin-bottom: 15px;
}
.dist-list-empty {
  color: var(--text-dim); font-size: 12px;
  text-align: center; padding: 10px;
}
.dist-list-item {
  display: flex; justify-content: space-between; align-items: center;
  background: var(--bg-main); border: 1px solid var(--border-card);
  border-radius: 6px; padding: 6px 10px; margin-bottom: 6px;
}
.dist-list-item:last-child { margin-bottom: 0; }
.dist-list-item-code {
  font-family: "Consolas", monospace; font-weight: 700; color: var(--text-main);
}
.dist-list-item .delete-btn { width: 20px; height: 20px; font-size: 10px; }

.dist-actions {
  display: flex; justify-content: center; gap: 10px; flex-wrap: wrap;
}

/* ---------- Templates Viewer ---------- */
.tpl-cat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 18px;
  max-width: 1200px;
  margin: 20px auto 30px;
  justify-content: center;
}

.tpl-cat-box {
  background: var(--bg-card);
  border: 1px solid var(--border-card);
  border-radius: 14px;
  padding: 28px 20px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}
.tpl-cat-box:hover {
  border-color: var(--accent);
  transform: translateY(-3px);
  box-shadow: 0 8px 24px var(--accent-glow);
}
.tpl-cat-icon { font-size: 40px; }
.tpl-cat-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-main);
  line-height: 1.5;
}
.tpl-cat-count {
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
  padding: 3px 12px;
  background: var(--accent-glow);
  border-radius: 20px;
}

.tpl-items-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 15px;
  max-width: 1200px;
  margin: 20px auto 30px;
}

.tpl-item-card {
  background: var(--bg-card);
  border: 1px solid var(--border-card);
  border-radius: 12px;
  padding: 18px 16px;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.tpl-item-card:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
}
.tpl-item-icon { font-size: 24px; }
.tpl-item-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--accent);
}
.tpl-item-preview {
  color: var(--text-muted);
  font-size: 11px;
  line-height: 1.6;
  max-height: 60px;
  overflow: hidden;
  direction: rtl;
}

.tpl-controls {
  max-width: 900px;
  margin: 15px auto;
  display: flex;
  justify-content: center;
}
.tpl-fill-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  color: var(--text-main);
  font-size: 14px;
  font-weight: 600;
  user-select: none;
  padding: 10px 18px;
  background: var(--bg-card);
  border: 1px solid var(--border-card);
  border-radius: 8px;
}
.tpl-fill-toggle input {
  accent-color: var(--accent);
  cursor: pointer;
  width: 16px;
  height: 16px;
}
.tpl-fill-toggle:hover { border-color: var(--accent); }

.tpl-output {
  background: var(--bg-main);
  border: 1px solid var(--border-input);
  border-radius: 8px;
  padding: 20px;
  color: var(--text-main);
  font-family: "Consolas", "Courier New", monospace;
  font-size: 13px;
  line-height: 2;
  white-space: pre-wrap;
  max-height: 700px;
  overflow-y: auto;
  direction: rtl;
  text-align: right;
}
.tpl-output.fill-mode {
  white-space: normal;
}
.tpl-output.fill-mode span {
  white-space: pre-wrap;
}
.tpl-field-input {
  background: var(--accent-glow);
  color: var(--text-main);
  border: 1px dashed var(--accent);
  border-radius: 4px;
  padding: 3px 8px;
  font-size: 13px;
  font-family: inherit;
  margin: 0 3px;
  text-align: center;
  direction: rtl;
  display: inline;
}
.tpl-field-input:focus {
  outline: 1px solid var(--accent);
  background: var(--bg-input);
  border-style: solid;
}
.tpl-field-input::placeholder {
  color: var(--text-dim);
  font-size: 11px;
}

.tpl-field-textarea {
  background: var(--accent-glow);
  color: var(--text-main);
  border: 1px dashed var(--accent);
  border-radius: 4px;
  padding: 6px 10px;
  font-size: 13px;
  font-family: inherit;
  line-height: 1.8;
  margin: 4px 0;
  min-width: 300px;
  min-height: 60px;
  resize: vertical;
  direction: rtl;
  display: block;
  width: 100%;
}
.tpl-field-textarea:focus {
  outline: 1px solid var(--accent);
  background: var(--bg-input);
  border-style: solid;
}
.tpl-field-textarea::placeholder {
  color: var(--text-dim);
  font-size: 11px;
}

.tpl-search-wrap {
  max-width: 900px;
  margin: 15px auto;
}
.tpl-search-input {
  width: 100%;
  background: var(--bg-input);
  color: var(--text-main);
  border: 1px solid var(--border-input);
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 14px;
  font-family: inherit;
  direction: rtl;
}
.tpl-search-input:focus {
  outline: 1px solid var(--accent);
  border-color: var(--accent);
}

.tpl-empty {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
  font-size: 14px;
}
.tpl-empty code {
  background: var(--bg-input);
  color: var(--accent);
  padding: 2px 8px;
  border-radius: 4px;
  font-family: "Consolas", monospace;
}

/* Legacy — احتفظ للتوافق */
.templates-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 260px));
  gap: 20px;
  max-width: 1200px;
  margin: 40px auto;
  justify-content: center;
}

/* ---------- Responsive ---------- */
@media (max-width: 640px) {
  body { padding: 20px 12px; }
  .top-header h1 { font-size: 20px; }
  .sections-grid { grid-template-columns: 1fr; }
  .home-grid { grid-template-columns: repeat(2, 1fr); }
  .main-menu { grid-template-columns: 1fr; }
  .shift-btn { padding: 10px 12px; font-size: 12px; }
  .meta-bar { flex-direction: column; align-items: stretch; }
  .meta-field { justify-content: space-between; }
}

/* ============================================================
   نظام Discord Auth
   ============================================================ */
.auth-status-bar {
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 900;
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg-card);
  border: 1px solid var(--border-card);
  border-radius: 30px;
  padding: 6px 12px 6px 6px;
  font-size: 12px;
  box-shadow: 0 2px 10px rgba(0,0,0,0.4);
}
.auth-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 1px solid var(--border-card);
}
.auth-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.auth-username {
  color: var(--text-main);
  font-weight: 700;
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 120px;
}
.auth-role {
  font-size: 10px;
  font-weight: 700;
  padding: 1px 8px;
  border-radius: 10px;
  display: inline-block;
  width: fit-content;
}
.auth-role-admin  { color: var(--accent); background: var(--accent-glow); }
.auth-role-viewer { color: #6ab7ff;         background: rgba(106,183,255,0.15); }
.auth-role-none   { color: var(--danger);   background: rgba(192,40,40,0.15); }

.auth-btn {
  background: transparent;
  color: var(--text-main);
  border: 1px solid var(--border-card);
  border-radius: 6px;
  padding: 6px 12px;
  cursor: pointer;
  font-family: inherit;
  font-size: 12px;
  font-weight: 700;
  transition: all 0.15s;
}
.auth-btn:hover { border-color: var(--accent); color: var(--accent); }
.auth-btn-login {
  background: #5865f2;
  color: #fff;
  border-color: #5865f2;
  padding: 8px 16px;
  font-size: 13px;
}
.auth-btn-login:hover { background: #4752c4; color: #fff; border-color: #4752c4; }
.auth-btn-logout { color: var(--danger); border-color: rgba(192,40,40,0.4); }
.auth-btn-logout:hover { background: var(--danger); color: #fff; }
.auth-btn-back {
  display: inline-block;
  text-decoration: none;
  color: var(--text-muted);
  margin-top: 15px;
}

.auth-loading {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.85);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  font-weight: 700;
  z-index: 10000;
}

.auth-blocked {
  max-width: 500px;
  margin: 80px auto;
  text-align: center;
  padding: 40px 30px;
  background: var(--bg-card);
  border: 1px solid var(--border-card);
  border-radius: 14px;
}
.auth-blocked-icon { font-size: 60px; margin-bottom: 15px; }
.auth-blocked h2   { color: var(--text-main); margin: 0 0 10px; }
.auth-blocked p    { color: var(--text-muted); margin: 8px 0; }
.auth-blocked strong { color: var(--accent); }
.auth-blocked .auth-btn { margin: 8px 5px; }

/* ============================================================
   محرر النماذج — أزرار Admin
   ============================================================ */
.tpl-admin-toolbar {
  max-width: 1200px;
  margin: 15px auto;
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
  padding: 12px;
  background: var(--bg-card);
  border: 1px dashed var(--accent);
  border-radius: 10px;
}
.tpl-admin-btn {
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--accent-dark);
  border-radius: 6px;
  padding: 8px 16px;
  cursor: pointer;
  font-family: inherit;
  font-size: 13px;
  font-weight: 700;
  transition: all 0.15s;
}
.tpl-admin-btn:hover { background: var(--accent); color: #fff; }
.tpl-admin-btn-danger { color: var(--danger); border-color: rgba(192,40,40,0.5); }
.tpl-admin-btn-danger:hover { background: var(--danger); color: #fff; }

/* أزرار التعديل الصغيرة على البطاقات */
.tpl-cat-actions, .tpl-item-actions {
  position: absolute;
  top: 8px;
  left: 8px;
  display: flex;
  gap: 4px;
  opacity: 0.6;
  transition: opacity 0.15s;
}
.tpl-cat-box:hover .tpl-cat-actions,
.tpl-item-card:hover .tpl-item-actions { opacity: 1; }
.tpl-cat-box, .tpl-item-card { position: relative; }
.tpl-mini-btn {
  background: rgba(0,0,0,0.5);
  color: var(--text-main);
  border: 1px solid var(--border-card);
  border-radius: 4px;
  width: 26px;
  height: 26px;
  cursor: pointer;
  font-size: 12px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
}
.tpl-mini-btn:hover { background: var(--accent); border-color: var(--accent); color: #fff; }
.tpl-mini-btn-danger:hover { background: var(--danger); border-color: var(--danger); }

/* بطاقات "إضافة قسم/نموذج جديد" */
.tpl-cat-add, .tpl-item-add {
  border-style: dashed !important;
  border-color: var(--accent-dark) !important;
  color: var(--accent);
  background: transparent !important;
}
.tpl-cat-add:hover, .tpl-item-add:hover {
  background: var(--accent-glow) !important;
  border-color: var(--accent) !important;
}

/* ============================================================
   نافذة تعديل النموذج (Modal)
   ============================================================ */
.tpl-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  padding: 20px;
}
.tpl-modal {
  background: var(--bg-card);
  border: 1px solid var(--border-card);
  border-radius: 12px;
  width: 100%;
  max-width: 800px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 60px rgba(0,0,0,0.6);
}
.tpl-modal-small { max-width: 450px; }
.tpl-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-card);
}
.tpl-modal-header h3 { margin: 0; color: var(--accent); font-size: 16px; }
.tpl-modal-close {
  background: transparent;
  color: var(--text-muted);
  border: none;
  font-size: 24px;
  cursor: pointer;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  transition: all 0.15s;
}
.tpl-modal-close:hover { background: var(--danger); color: #fff; }

.tpl-modal-body {
  padding: 20px;
  overflow-y: auto;
  flex: 1;
}
.tpl-modal-body label {
  display: block;
  color: var(--text-main);
  font-size: 13px;
  font-weight: 700;
  margin-bottom: 6px;
  margin-top: 12px;
}
.tpl-modal-body label:first-child { margin-top: 0; }
.tpl-modal-input {
  width: 100%;
  background: var(--bg-input);
  color: var(--text-main);
  border: 1px solid var(--border-input);
  border-radius: 6px;
  padding: 10px 14px;
  font-size: 14px;
  font-family: inherit;
  direction: rtl;
}
.tpl-modal-input:focus { outline: 1px solid var(--accent); border-color: var(--accent); }

.tpl-modal-textarea {
  width: 100%;
  background: var(--bg-input);
  color: var(--text-main);
  border: 1px solid var(--border-input);
  border-radius: 6px;
  padding: 12px;
  font-family: "Consolas", "Courier New", monospace;
  font-size: 13px;
  line-height: 1.8;
  min-height: 350px;
  resize: vertical;
  direction: rtl;
  text-align: right;
}
.tpl-modal-textarea:focus { outline: 1px solid var(--accent); border-color: var(--accent); }

.tpl-modal-hint {
  color: var(--text-muted);
  font-size: 11px;
  margin-top: 8px;
  padding: 8px 12px;
  background: var(--bg-main);
  border-radius: 4px;
}
.tpl-modal-hint code {
  background: var(--accent-glow);
  color: var(--accent);
  padding: 1px 6px;
  border-radius: 3px;
  font-family: "Consolas", monospace;
  margin: 0 3px;
}

.tpl-modal-footer {
  display: flex;
  gap: 10px;
  padding: 16px 20px;
  border-top: 1px solid var(--border-card);
  justify-content: flex-end;
}
.tpl-modal-btn {
  padding: 10px 20px;
  border-radius: 6px;
  cursor: pointer;
  font-family: inherit;
  font-size: 13px;
  font-weight: 700;
  border: 1px solid;
  transition: all 0.15s;
}
.tpl-modal-btn-save   { background: var(--accent); color: #fff; border-color: var(--accent); }
.tpl-modal-btn-save:hover { background: var(--accent-dark); border-color: var(--accent-dark); }
.tpl-modal-btn-cancel { background: transparent; color: var(--text-muted); border-color: var(--border-card); }
.tpl-modal-btn-cancel:hover { color: var(--text-main); border-color: var(--text-muted); }

/* ============================================================
   شاشة تسجيل الدخول الاحترافية
   ============================================================ */
.auth-welcome {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: linear-gradient(135deg, #1a1d24 0%, #0d1117 100%);
  z-index: 10;
}
.auth-welcome-card {
  max-width: 460px;
  width: 100%;
  background: var(--bg-card);
  border: 1px solid var(--border-card);
  border-radius: 20px;
  padding: 40px 32px;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0,0,0,0.6), 0 0 0 1px rgba(88,101,242,0.1);
  animation: authWelcomeFadeIn 0.4s ease-out;
}
@keyframes authWelcomeFadeIn {
  from { opacity: 0; transform: translateY(20px) scale(0.98); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
.auth-welcome-logo {
  width: 72px;
  height: 56px;
  margin: 0 auto 24px;
  color: #5865F2;
  filter: drop-shadow(0 4px 12px rgba(88,101,242,0.4));
}
.auth-welcome-logo svg { width: 100%; height: 100%; }

.auth-welcome-title {
  color: var(--text-main);
  font-size: 26px;
  margin: 0 0 12px;
  font-weight: 700;
}
.auth-welcome-desc {
  color: var(--text-muted);
  font-size: 14px;
  line-height: 1.8;
  margin: 0 0 28px;
}

.auth-welcome-user {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--bg-main);
  border: 1px solid var(--border-card);
  border-radius: 12px;
  padding: 14px 18px;
  margin: 0 auto 24px;
  width: fit-content;
  text-align: right;
}
.auth-welcome-user img {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 2px solid #5865F2;
}
.auth-welcome-username {
  color: var(--text-main);
  font-weight: 700;
  font-size: 15px;
}
.auth-welcome-userid {
  color: var(--text-muted);
  font-size: 12px;
}

.auth-welcome-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 14px 28px;
  border: none;
  border-radius: 10px;
  font-family: inherit;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s;
  text-decoration: none;
  min-width: 200px;
}
.auth-welcome-btn-discord {
  background: #5865F2;
  color: #fff;
  padding: 16px 32px;
  font-size: 16px;
  box-shadow: 0 4px 14px rgba(88,101,242,0.4);
}
.auth-welcome-btn-discord:hover {
  background: #4752c4;
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(88,101,242,0.5);
}
.auth-welcome-btn-discord:active { transform: translateY(0); }
.auth-welcome-btn-icon {
  width: 22px;
  height: 18px;
  color: currentColor;
  display: inline-block;
}
.auth-welcome-btn-icon svg { width: 100%; height: 100%; }

.auth-welcome-btn-primary {
  background: var(--accent);
  color: #fff;
}
.auth-welcome-btn-primary:hover { background: var(--accent-dark); }

.auth-welcome-btn-secondary {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border-card);
}
.auth-welcome-btn-secondary:hover {
  border-color: var(--text-main);
  color: var(--text-main);
}

.auth-welcome-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
}

.auth-welcome-hint {
  color: var(--text-dim);
  font-size: 11px;
  margin: 20px 0 0;
}

/* ============================================================
   أزرار إدراج الحقول في محرر النموذج
   ============================================================ */
.tpl-modal-large { max-width: 900px; }

.tpl-fields-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 12px;
  background: var(--bg-main);
  border: 1px solid var(--border-card);
  border-radius: 8px;
  margin-bottom: 12px;
  max-height: 200px;
  overflow-y: auto;
}
.tpl-field-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-card);
  color: var(--text-main);
  border: 1px solid var(--border-card);
  border-radius: 6px;
  padding: 6px 10px;
  cursor: pointer;
  font-family: inherit;
  font-size: 12px;
  transition: all 0.15s;
}
.tpl-field-btn:hover {
  background: var(--accent-glow);
  border-color: var(--accent);
  color: var(--accent);
  transform: translateY(-1px);
}
.tpl-field-btn:active { transform: translateY(0); }
.tpl-field-btn-icon {
  font-size: 14px;
  font-weight: 700;
  min-width: 16px;
  text-align: center;
}
.tpl-field-btn-label {
  font-size: 12px;
  font-weight: 600;
}
.tpl-field-btn-multi {
  background: rgba(106,183,255,0.1);
  border-color: rgba(106,183,255,0.4);
  color: #6ab7ff;
}
.tpl-field-btn-multi:hover {
  background: #6ab7ff;
  color: #fff;
  border-color: #6ab7ff;
}
.tpl-field-btn-custom {
  background: var(--accent-glow);
  border-color: var(--accent);
  color: var(--accent);
  border-style: dashed;
}
.tpl-field-btn-custom:hover {
  background: var(--accent);
  color: #fff;
  border-style: solid;
}