:root {
  --bg: #f5f6f8;
  --card: #ffffff;
  --border: #e3e6ea;
  --text: #1c2430;
  --muted: #6b7684;
  --primary: #2f5496;
  --primary-dark: #223e73;
  --danger: #c0392b;
  --easy: #2e9e5b;
  --medium: #d9a02b;
  --hard: #c0392b;
  --radius: 10px;
}
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 15px; line-height: 1.5;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
.container { max-width: 1080px; margin: 0 auto; padding: 24px 20px 80px; }

.topnav {
  background: var(--primary); color: #fff; display: flex; align-items: center; justify-content: space-between;
  padding: 12px 24px; position: sticky; top: 0; z-index: 20;
}
.topnav .brand { font-weight: 700; font-size: 16px; color: #fff; }
.topnav .brand:hover { text-decoration: none; opacity: .9; }
.navlinks { display: flex; align-items: center; gap: 18px; }
.navlinks a { color: #dce6f5; }
.navlinks a.active { color: #fff; font-weight: 600; text-decoration: underline; }
.btn-nav-cta { background: #fff; color: var(--primary) !important; padding: 6px 14px; border-radius: 20px; font-weight: 700; text-decoration: none !important; }
.btn-nav-cta:hover { background: #dce6f5; }
.btn-nav-cta.active { text-decoration: none !important; }
.navuser { color: #fff; font-size: 13px; opacity: .9; }
.role-badge { font-size: 10px; padding: 2px 6px; border-radius: 20px; background: rgba(255,255,255,.2); margin-left: 4px; }
.link-btn { background: none; border: none; color: #dce6f5; cursor: pointer; font-size: 14px; padding: 0; }
.link-btn:hover { text-decoration: underline; }

.page-head { display: flex; align-items: center; gap: 12px; margin: 10px 0 4px; flex-wrap: wrap; }
.page-head h1 { margin: 0; font-size: 24px; }
.breadcrumb { font-size: 13px; color: var(--muted); margin: 8px 0 12px; }
.ar { font-weight: 400; color: var(--muted); font-size: 0.85em; }

.card {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px 18px; margin: 14px 0;
}
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; margin-top: 12px; }
.cat-card, .sub-card { display: block; color: inherit; }
.cat-card:hover, .sub-card:hover { border-color: var(--primary); text-decoration: none; box-shadow: 0 2px 10px rgba(0,0,0,.05); }
.cat-card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.cat-card-head h3 { margin: 0; font-size: 16px; }
.cat-card-stats { display: flex; gap: 14px; font-size: 12px; color: var(--muted); margin-top: 8px; }
.small { font-size: 12.5px; }
.muted { color: var(--muted); }

.badge { font-size: 11px; padding: 3px 9px; border-radius: 20px; font-weight: 600; white-space: nowrap; }
.badge-draft { background: #eceff3; color: #5b6472; }
.badge-in-progress { background: #e4ecfb; color: var(--primary); }
.badge-ready-for-review { background: #fdf1d6; color: #8a6512; }
.badge-approved { background: #e2f5e9; color: #1e7a45; }
.badge-exported { background: #e8e2fb; color: #5333a8; }
.badge-rejected { background: #fbe3e2; color: #a3312a; }

.diff { font-size: 11px; padding: 2px 8px; border-radius: 20px; font-weight: 700; color: #fff; }
.diff-easy { background: var(--easy); }
.diff-medium { background: var(--medium); }
.diff-hard { background: var(--hard); }

.progress { height: 6px; background: #eef0f3; border-radius: 6px; overflow: hidden; margin-top: 10px; }
.progress-bar { height: 100%; background: var(--primary); }

.stat-row { display: flex; gap: 12px; margin: 14px 0; flex-wrap: wrap; }
.stat { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 20px; text-align: center; min-width: 110px; }
.stat b { display: block; font-size: 22px; }
.stat span { font-size: 12px; color: var(--muted); }
a.stat-link { text-decoration: none; color: inherit; display: block; border-color: var(--primary); }

.export-cat-row { display: flex; align-items: center; gap: 10px; padding: 8px 4px; border-bottom: 1px solid var(--border); }
.export-cat-row:last-of-type { border-bottom: none; }
.export-cat-row input[type="checkbox"] { width: auto; }

.action-row { display: flex; gap: 10px; align-items: center; margin: 14px 0; flex-wrap: wrap; }
.action-row .spacer { flex: 1; }
.sticky-actions { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 18px; }

.btn {
  border: 1px solid var(--border); background: #fff; color: var(--text); padding: 8px 16px;
  border-radius: 8px; cursor: pointer; font-size: 14px; font-weight: 600;
}
.btn:hover { border-color: var(--primary); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-dark); }
.btn-danger { color: var(--danger); border-color: #f1cfc9; }
.btn-danger:hover { background: #fdecea; }
.btn-small { padding: 4px 10px; font-size: 12.5px; }
.inline { display: inline-block; margin: 0; }

.inline-form { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.inline-form input[type=text], .inline-form select { padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; font-size: 14px; }
.inline-form input[type=text] { flex: 1; min-width: 160px; }

.stack { display: flex; flex-direction: column; gap: 14px; }
label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; font-weight: 600; color: #46505c; }
input, select, textarea {
  font-family: inherit; font-size: 14px; padding: 9px 11px; border: 1px solid var(--border);
  border-radius: 8px; background: #fff; color: var(--text);
}
textarea { resize: vertical; }
.field-row { display: flex; gap: 16px; margin-bottom: 10px; flex-wrap: wrap; }
.field-row label { flex: 1; min-width: 160px; }

.auth-wrap { display: flex; justify-content: center; padding-top: 60px; }
.auth-card { background: #fff; border: 1px solid var(--border); border-radius: 14px; padding: 32px; width: 380px; }
.auth-card h1 { font-size: 20px; margin: 0 0 6px; }

.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; font-size: 14px; }
.flash-ok { background: #e2f5e9; color: #1e7a45; }
.flash-error { background: #fdecea; color: #a33025; }
.flash-warn { background: #fff4e0; color: #92600a; }

.table { width: 100%; border-collapse: collapse; margin-top: 8px; }
.table th, .table td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--border); font-size: 13.5px; }
.table th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; }

.qlist { display: flex; flex-direction: column; gap: 6px; margin-top: 10px; }
.qrow { display: flex; align-items: center; gap: 12px; background: #fff; border: 1px solid var(--border); border-radius: 8px; padding: 10px 14px; color: inherit; }
.qrow:hover { border-color: var(--primary); text-decoration: none; }
.qtype { font-size: 11px; background: #eef1f6; padding: 3px 8px; border-radius: 6px; color: #46505c; min-width: 110px; text-align: center; }
.qtext { flex: 1; }

.media-empty { color: var(--muted); font-size: 13px; padding: 20px; text-align: center; border: 1px dashed var(--border); border-radius: 8px; }
.media-img { max-width: 100%; max-height: 280px; border-radius: 8px; display: block; }
.media-current { margin-bottom: 10px; }

.option-row { display: flex; gap: 12px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--border); }
.option-row:last-child { border-bottom: none; }
.option-correct { display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 11px; color: var(--muted); width: 60px; }
.option-fields { flex: 1; display: flex; gap: 8px; }
.option-fields input { flex: 1; }
.option-media { display: flex; flex-direction: column; align-items: center; gap: 6px; width: 110px; }
.option-media-preview img { width: 70px; height: 70px; object-fit: cover; border-radius: 6px; }

.gp-row { margin: 10px 0; padding: 8px; border: 1px dashed var(--border); border-radius: 8px; }
.gp-row-label { font-weight: 700; font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.gp-sources { display: flex; gap: 12px; flex-wrap: wrap; margin: 6px 0; }
.gp-source { width: 160px; border: 1px solid var(--border); border-radius: 8px; padding: 8px; display: flex; flex-direction: column; gap: 6px; }
.gp-source img { width: 100%; height: 90px; object-fit: cover; border-radius: 6px; }
.gp-source input, .gp-source select { font-size: 12px; padding: 5px 6px; }
.gp-result { margin-top: 14px; }
.gp-result img { max-width: 100%; border-radius: 8px; }

.gp-preview { display: flex; gap: 12px; flex-wrap: wrap; margin: 10px 0; }
.gp-preview-item { width: 130px; border: 1px solid var(--border); border-radius: 8px; padding: 8px; display: flex; flex-direction: column; gap: 6px; }
.gp-preview-item img { width: 100%; height: 80px; object-fit: cover; border-radius: 6px; }
.gp-preview-item .gp-preview-name { font-size: 11px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.gp-preview-item label { font-size: 12px; display: flex; align-items: center; gap: 4px; }
.gp-preview-item input[type="number"] { width: 52px; font-size: 12px; padding: 4px 5px; }
.gp-count-msg { font-size: 12px; margin: 4px 0; }
.gp-count-msg.gp-count-ok { color: var(--ok, #2a7d46); }
.gp-count-msg.gp-count-bad { color: var(--danger, #c0392b); }

.review-card { margin-bottom: 16px; }
.review-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.review-wrong-list { margin: 4px 0 0; padding-inline-start: 20px; color: var(--muted); font-size: 13px; }
@media (max-width: 640px) { .review-grid { grid-template-columns: 1fr; } }

.app-footer { text-align: center; color: var(--muted); font-size: 11px; padding: 20px 0 40px; }
.topnav-guest { justify-content: space-between; }

.comment-thread { display: flex; flex-direction: column; gap: 10px; margin-bottom: 12px; }
.comment-item { border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; background: #fafbfc; }
.comment-meta { margin-bottom: 4px; }
.comment-body { white-space: pre-wrap; font-size: 14px; }
.edit-log-list { list-style: none; margin: 8px 0 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.edit-log-item { border-inline-start: 3px solid var(--border); padding-inline-start: 10px; font-size: 13px; }
.edit-log-diff { margin-top: 2px; }
.edit-old { color: #a3312a; text-decoration: line-through; }
.edit-new { color: #1e7a45; font-weight: 600; }
.lang-switch { color: #dce6f5; font-size: 13px; border: 1px solid rgba(255,255,255,.35); border-radius: 20px; padding: 3px 12px; }
.lang-switch:hover { color: #fff; text-decoration: none; border-color: #fff; }

@media (max-width: 640px) {
  .topnav { flex-direction: column; gap: 8px; align-items: flex-start; }
  .navlinks { flex-wrap: wrap; }
}

/* ---- RTL (Arabic UI) ---- */
/* Flexbox row layouts (.topnav, .navlinks, .action-row, .inline-form, .field-row, option/gp rows,
   etc.) and default text alignment already mirror correctly under dir="rtl" for free, since the
   browser makes the flex row axis and block-level text-align direction-aware. Only a handful of
   hardcoded left/right values below need an explicit override. */
[dir="rtl"] .role-badge { margin-left: 0; margin-right: 4px; }
[dir="rtl"] .table th, [dir="rtl"] .table td { text-align: right; }
[dir="rtl"] .qtype { font-family: inherit; }
[dir="rtl"] .breadcrumb { direction: rtl; }
[dir="rtl"] .option-correct { text-align: center; }
