body.admin, body.login-page { font-family: var(--f-body); }
body.admin h1, body.admin h2, body.admin h3, body.admin h4, .login-card h1 { font-family: var(--f-display); }
/* ---------- Admin panel ---------- */
body.admin { display: flex; min-height: 100vh; }
.side { width: 250px; flex: none; background: var(--bg-2); border-inline-end: 1px solid var(--border); display: flex; flex-direction: column; padding: 1rem; position: sticky; top: 0; height: 100vh; }
.side .brand { padding: .4rem .5rem 1rem; }
.side nav { display: flex; flex-direction: column; gap: 3px; }
.side nav a { display: flex; align-items: center; gap: .6em; padding: .55em .8em; border-radius: 10px; color: var(--text-2); font-weight: 700; }
.side nav a:hover { background: var(--surface-2); color: var(--text); }
.side nav a.active { background: var(--brand-soft); color: var(--amber); border: 1px solid rgba(247,165,49,.25); }
.side-foot { margin-top: auto; display: flex; flex-direction: column; gap: .3em; padding-top: 1rem; border-top: 1px solid var(--border); }
.side-foot a, .linkish { display: flex; align-items: center; gap: .5em; padding: .45em .8em; color: var(--muted); background: none; border: 0; font: inherit; font-weight: 700; cursor: pointer; border-radius: 8px; }
.side-foot a:hover, .linkish:hover { color: var(--text); background: var(--surface-2); }
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.admin-top { display: flex; align-items: center; gap: 1rem; padding: .9rem 1.6rem; border-bottom: 1px solid var(--border); background: rgba(12,10,16,.7); backdrop-filter: blur(10px); position: sticky; top: 0; z-index: 10; }
.admin-top h1 { font-size: 1.3rem; margin: 0; flex: 1; }
.who { display: flex; align-items: center; gap: .5em; color: var(--text-2); font-weight: 600; font-size: .9rem; }
.content { padding: 1.6rem; max-width: 1100px; width: 100%; }
body.wide .content { max-width: 1400px; }
.flash { display: flex; align-items: center; gap: .5em; padding: .7em 1em; border-radius: 10px; margin-bottom: 1rem; font-weight: 700; background: var(--success-bg); color: var(--success); border: 1px solid rgba(61,220,132,.35); }
.flash-error { background: var(--danger-bg); color: var(--danger); border-color: rgba(255,77,94,.35); }

/* stats */
.stats { display: grid; grid-template-columns: repeat(5, 1fr); gap: .9rem; margin-bottom: 1.2rem; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem 1.1rem; display: flex; flex-direction: column; color: var(--text); }
.stat .ico { color: var(--coral); width: 22px; height: 22px; }
.stat b { font-size: 1.8rem; line-height: 1.2; margin-top: .3em; }
.stat span { color: var(--muted); font-size: .82rem; }
.stat:hover { border-color: var(--amber); }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; align-items: start; }
.card h3 { display: flex; align-items: center; gap: .4em; font-size: 1.05rem; margin: 0 0 .8em; }
.quick { display: flex; flex-wrap: wrap; gap: .5em; }
.plain { list-style: none; margin: 0; padding: 0; }
.plain li { display: flex; justify-content: space-between; gap: 1em; padding: .45em 0; border-top: 1px solid var(--border); font-size: .92rem; }
.plain li:first-child { border: 0; }
.plain small { color: var(--muted); white-space: nowrap; }
.toolbar { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.toolbar p { margin: 0; }

/* forms */
.form label { display: flex; flex-direction: column; gap: .3em; font-weight: 700; font-size: .9rem; margin-bottom: .9rem; color: var(--text-2); }
.form label small { font-weight: 500; }
.form input:not([type=checkbox]):not([type=file]), .form select, .form textarea {
  font: inherit; font-size: .97rem; background: var(--bg-2); border: 1px solid var(--border-2); color: var(--text); border-radius: 10px; padding: .55em .8em; width: 100%;
}
.form input:focus, .form select:focus, .form textarea:focus { outline: 0; border-color: var(--coral); box-shadow: 0 0 0 3px rgba(242,88,62,.15); }
.form textarea { resize: vertical; line-height: 1.7; }
.form .big-input { font-size: 1.25rem; font-weight: 800; }
.form label.check { flex-direction: row; align-items: center; gap: .5em; }
.form label.check input { width: 18px; height: 18px; accent-color: var(--coral); }
.row { display: flex; gap: .8rem; align-items: flex-end; flex-wrap: wrap; }
.row > label { margin-bottom: .9rem; }
.row .grow, .grow { flex: 1; min-width: 200px; }
.form-actions { display: flex; gap: .6em; flex-wrap: wrap; margin-top: .5rem; }
.form-actions.col { flex-direction: column; }
.form-actions.col .btn { justify-content: center; }
.editor-grid { display: grid; grid-template-columns: 1fr 320px; gap: 1rem; align-items: start; }
.side-form { position: sticky; top: 80px; }

/* markdown editor */
.md-editor { border: 1px solid var(--border-2); border-radius: 12px; overflow: hidden; background: var(--bg-2); }
.md-toolbar { display: flex; flex-wrap: wrap; gap: 3px; padding: .4em; background: var(--surface-2); border-bottom: 1px solid var(--border); }
.md-toolbar button, .md-toolbar .upl { font: inherit; font-size: .82rem; font-weight: 700; background: transparent; color: var(--text-2); border: 1px solid transparent; border-radius: 7px; padding: .3em .6em; cursor: pointer; display: inline-flex; align-items: center; gap: .3em; }
.md-toolbar button:hover, .md-toolbar .upl:hover { background: var(--surface-3); color: var(--text); border-color: var(--border-2); }
.md-toolbar .sep { width: 1px; background: var(--border-2); margin: 0 .3em; }
.md-toolbar .preview-btn { margin-inline-start: auto; }
.md-toolbar .preview-btn.on { background: var(--brand-soft); color: var(--amber); }
.md-panes { display: grid; grid-template-columns: 1fr; }
.md-panes.split { grid-template-columns: 1fr 1fr; }
.md-panes textarea { border: 0 !important; border-radius: 0 !important; font-family: ui-monospace, 'Cascadia Mono', Consolas, monospace !important; font-size: .95rem !important; min-height: 320px; background: var(--bg-2) !important; }
.md-panes.split textarea { border-inline-end: 1px solid var(--border) !important; }
.md-preview { padding: 1em 1.2em; overflow: auto; max-height: 70vh; background: var(--surface); }
.md-help { font-size: .78rem; color: var(--muted); padding: .4em .8em; border-top: 1px solid var(--border); }
.md-help code { background: var(--surface-3); padding: 0 .3em; border-radius: 4px; direction: ltr; unicode-bidi: embed; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; background: var(--muted); }
.dot-danger { background: var(--danger); } .dot-warning { background: var(--warning); } .dot-info { background: var(--info); } .dot-success { background: var(--success); } .dot-note { background: var(--note); }

/* lists (rules & wiki) */
.section-item { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: .8rem; }
.section-item summary { display: flex; align-items: center; gap: .8em; padding: .8rem 1rem; cursor: pointer; list-style: none; }
.section-item summary::-webkit-details-marker { display: none; }
.sec-title { flex: 1; display: flex; flex-direction: column; }
.sec-title small { color: var(--muted); font-size: .8rem; }
.section-item .actions { display: flex; gap: .4em; }
.drag { cursor: grab; color: var(--muted); font-size: 1.2rem; user-select: none; }
.rules-list { border-top: 1px solid var(--border); padding: .5rem .8rem; }
.rule-item { display: flex; align-items: center; gap: .7em; padding: .45em .6em; border-radius: 8px; border-inline-start: 3px solid transparent; }
.rule-item:hover { background: var(--surface-2); }
.rule-item .rule-t { flex: 1; color: var(--text); font-weight: 600; }
.rule-item.alert-danger { border-inline-start-color: var(--danger); } .rule-item.alert-warning { border-inline-start-color: var(--warning); } .rule-item.alert-info { border-inline-start-color: var(--info); } .rule-item.alert-success { border-inline-start-color: var(--success); }
.rule-item.unpub .rule-t, tr.unpub td { opacity: .55; }
.dragging { opacity: .4; }
.drop-before { box-shadow: 0 -2px 0 var(--amber); } .drop-after { box-shadow: 0 2px 0 var(--amber); }
.small { font-size: .85rem; padding: .3em .6em; }

/* tables */
.table-card { padding: .4rem 1rem; overflow-x: auto; }
.tbl { width: 100%; border-collapse: collapse; font-size: .92rem; }
.tbl th, .tbl td { padding: .6em .6em; border-bottom: 1px solid var(--border); text-align: start; vertical-align: middle; }
.tbl th { color: var(--muted); font-size: .8rem; }
.tbl tr:last-child td { border: 0; }
.tbl td.row { gap: .3em; align-items: center; }

/* announcements */
.ann { display: flex; align-items: center; gap: .6em; padding: .6em .8em; border-radius: 10px; margin-bottom: .5em; border: 1px solid; }
.ann span { flex: 1; font-weight: 600; }
.ann-info { background: var(--info-bg); border-color: rgba(79,179,255,.3); } .ann-warning { background: var(--warning-bg); border-color: rgba(255,181,61,.3); } .ann-danger { background: var(--danger-bg); border-color: rgba(255,77,94,.3); }
.ann.off { opacity: .5; }

/* uploads */
.uploads-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: .8rem; margin-top: 1rem; }
.upload-item { padding: .6rem; display: flex; flex-direction: column; gap: .4em; }
.upload-item img { width: 100%; height: 120px; object-fit: cover; border-radius: 8px; }
.upload-item .file-ico { height: 120px; display: flex; align-items: center; justify-content: center; background: var(--surface-2); border-radius: 8px; color: var(--muted); }
.upload-item input { font: inherit; font-size: .78rem; background: var(--bg-2); border: 1px solid var(--border); color: var(--text-2); border-radius: 6px; padding: .3em .5em; }
.upl input[type=file] { display: none; }

/* login */
.login-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 20px; }
.login-card { width: 100%; max-width: 400px; background: var(--surface); border: 1px solid var(--border); border-radius: 20px; padding: 2.2rem; display: flex; flex-direction: column; gap: .8rem; text-align: center; box-shadow: var(--shadow); }
.login-card img { margin: 0 auto; filter: drop-shadow(0 8px 20px rgba(242,88,62,.5)); }
.login-card h1 { font-size: 1.4rem; margin: 0; }
.login-card p { margin: 0 0 .5em; }
.login-card label { text-align: start; display: flex; flex-direction: column; gap: .3em; font-weight: 700; font-size: .9rem; color: var(--text-2); }
.login-card input { font: inherit; background: var(--bg-2); border: 1px solid var(--border-2); color: var(--text); border-radius: 10px; padding: .6em .8em; }
.login-card input:focus { outline: 0; border-color: var(--coral); }
.login-card .btn { justify-content: center; margin-top: .4em; }
.login-card .back { color: var(--muted); font-size: .85rem; display: inline-flex; gap: .3em; justify-content: center; align-items: center; }
.login-card .back .ico { transform: scaleX(-1); }

@media (max-width: 1000px) { .editor-grid, .two, .stats { grid-template-columns: 1fr 1fr; } .side-form { position: static; } }
@media (max-width: 760px) {
  body.admin { flex-direction: column; }
  .side { position: fixed; inset-inline-start: -260px; z-index: 40; transition: .2s; height: 100vh; }
  .side.open { inset-inline-start: 0; box-shadow: var(--shadow); }
  .admin-top .nav-toggle { display: inline-flex; }
  .editor-grid, .two, .stats { grid-template-columns: 1fr; }
  .md-panes.split { grid-template-columns: 1fr; }
  .content { padding: 1rem; }
}

/* ================= المحرر المرئي (بلوكات) ================= */
.bx { display: block; }
.bx-list { display: flex; flex-direction: column; gap: .8rem; }
.bx-empty { padding: 1.6rem; text-align: center; border: 1px dashed var(--line); border-radius: 12px; }
.bx-card { border: 1px solid var(--line); border-radius: 12px; background: var(--surface-2, rgba(255,255,255,.02)); overflow: hidden; }
.bx-card.dragging { opacity: .5; }
.bx-card.over { outline: 2px dashed var(--brand-2, #f2583e); outline-offset: 2px; }
.bx-head { display: flex; align-items: center; gap: .6em; padding: .55em .8em; background: rgba(255,255,255,.035); border-bottom: 1px solid var(--line); font-size: .95em; }
.bx-head b { font-weight: 800; }
.bx-grab { cursor: grab; opacity: .55; font-size: 1.1em; user-select: none; }
.bx-tools { margin-inline-start: auto; display: flex; gap: .25em; }
.bx-tools .btn { padding: .2em .55em; min-height: 32px; min-width: 32px; }
.bx-body { padding: .9em; display: flex; flex-direction: column; gap: .7em; }
.bx-f { display: flex; flex-direction: column; gap: .3em; font-size: .88em; font-weight: 700; color: var(--muted); }
.bx-f input, .bx-f textarea, .bx-f select { font-weight: 500; color: var(--text); }
.bx-f textarea { min-height: 5em; resize: vertical; }
.bx-row { display: flex; gap: .7em; flex-wrap: wrap; }
.bx-row > * { flex: 0 0 auto; }
.bx-row > .grow { flex: 1 1 12em; }
.bx-sub { border: 1px solid var(--line); border-radius: 10px; padding: .7em; display: flex; flex-direction: column; gap: .5em; }
.bx-sub-head { font-size: .85em; color: var(--muted); }

/* منطقة الصورة */
.bx-img-head { font-size: .88em; font-weight: 700; color: var(--muted); margin-bottom: .3em; }
.bx-drop { border: 1px dashed var(--line); border-radius: 10px; padding: .7em; display: flex; flex-direction: column; gap: .5em; transition: border-color .15s, background .15s; }
.bx-drop.over { border-color: var(--brand-2, #f2583e); background: rgba(242,88,62,.07); }
.bx-drop.busy { opacity: .6; pointer-events: none; }
.bx-prev { min-height: 92px; display: grid; place-items: center; background: rgba(0,0,0,.25); border-radius: 8px; overflow: hidden; }
.bx-prev img { max-height: 150px; max-width: 100%; object-fit: contain; }
.bx-img-row { display: flex; gap: .4em; align-items: center; }
.bx-url { flex: 1; min-width: 0; }

/* جدول الرتب داخل المحرر */
.bx-ranks { display: flex; flex-direction: column; gap: .5em; }
.bx-rank-row { display: flex; gap: .5em; align-items: flex-end; flex-wrap: wrap; border: 1px solid var(--line); border-radius: 10px; padding: .55em; }
.bx-rank-row > .bx-f { flex: 1 1 9em; min-width: 8em; }
.bx-rank-row > .grow { flex: 2 1 16em; }
.bx-rank-del { align-self: center; }
.bx-ins-pick { display: flex; gap: .35em; align-items: center; }
.bx-ins-pick select { min-width: 7em; }
.bx-ins-thumb img { width: 26px; height: 26px; object-fit: contain; }

.bx-add { display: flex; flex-wrap: wrap; gap: .4em; align-items: center; margin-top: .9rem; padding: .7em; border: 1px dashed var(--line); border-radius: 12px; }
.bx-add-label { font-weight: 800; font-size: .9em; display: inline-flex; align-items: center; gap: .35em; }
.bx-legacy { margin-top: 1rem; }
.bx-legacy > summary { cursor: pointer; color: var(--muted); font-size: .9em; padding: .4em 0; }

@media (max-width: 760px) {
  .bx-rank-row > .bx-f, .bx-rank-row > .grow { flex: 1 1 100%; }
  .bx-row > * { flex: 1 1 100%; }
}
.bx-hint { color: var(--muted); font-size: .85em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 22em; }
.bx-card.collapsed .bx-body { display: none; }
details.bx-img > summary { cursor: pointer; list-style: none; }
details.bx-img > summary::-webkit-details-marker { display: none; }
details.bx-img > summary::before { content: '+ '; opacity: .7; }
details.bx-img[open] > summary::before { content: '− '; }

/* مفتاح تشغيل/إيقاف */
.switch-row { display: flex; align-items: flex-start; gap: .8em; padding: .6em 0; cursor: pointer; }
.switch-row > span:last-child { display: flex; flex-direction: column; gap: .15em; }
.switch-row small { font-weight: 500; line-height: 1.6; }
.switch { position: relative; display: inline-block; width: 52px; height: 30px; flex: none; margin-top: .1em; }
.switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.switch .slider { position: absolute; inset: 0; background: #3a3442; border-radius: 999px; transition: background .18s; pointer-events: none; }
.switch .slider::before { content: ''; position: absolute; width: 22px; height: 22px; top: 4px; right: 4px; background: #fff; border-radius: 50%; transition: transform .18s; }
.switch input:checked + .slider { background: linear-gradient(135deg, #f7a531, #f2583e); }
.switch input:checked + .slider::before { transform: translateX(-22px); }
.switch input:focus-visible + .slider { outline: 2px solid var(--ring, #f7a531); outline-offset: 2px; }

textarea.big-input { font-family: var(--f-display); font-size: 1.15rem; font-weight: 700; line-height: 1.5; }
.form small code { font-family: var(--f-num); font-size: .85em; background: var(--surface-2); padding: .1em .35em; border-radius: 4px; }
