/* ================================================================
   ALBAR7AHPEDIA — Wikipedia Vector 2022 skin clone
   Font: Arial · RTL sidebar · Uniform text-scale · Mobile-first
   Type scale sourced from Wikipedia's actual skin.vector.styles
================================================================ */

@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+Arabic:wght@400;500;700&display=swap');

/* ── Design tokens ─────────────────────────────────────────── */
:root {
  /* Wikipedia exact palette */
  --bg-page:         #f8f9fa;
  --bg-content:      #ffffff;
  --bg-sidebar:      #f8f9fa;
  --border:          #a2a9b1;
  --link-blue:       #3366cc;
  --link-visited:    #6b4ba1;
  --link-red:        #cc3333;
  --text-main:       #202122;
  --text-muted:      #54595d;
  --accent-orange:   #f0a500;
  --tab-active-bg:   #ffffff;
  --tab-inactive-bg: #eaecf0;
  --tab-border:      #a2a9b1;
  --diff-add:        #d4f4bc;
  --diff-del:        #ffb3b3;
  --diff-add-strong: #a3d68a;
  --diff-del-strong: #e46060;

  /* Layout */
  --sidebar-width: 180px;
  --header-h:      56px;
  --content-pad:   20px;

  /*
   * TEXT SCALE — the ONLY place font-size is multiplied.
   * .mw-body-content uses calc(BASE * --text-scale).
   * All children use plain em so they scale together.
   * JS sets this property; default = 1.
   */
  --text-scale: 1;

  /* Font stacks */
  --font-ui:      Arial, 'Noto Sans Arabic', 'Helvetica Neue', Helvetica, sans-serif;
  --font-content: Arial, 'Noto Sans Arabic', 'Helvetica Neue', Helvetica, sans-serif;
  --font-arabic:  'Noto Sans Arabic', Arial, 'Helvetica Neue', sans-serif;
  --font-mono:    'Courier New', Courier, monospace;
}

/* ── Reset ─────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; overflow-x: hidden; }
body { overflow-x: hidden; }
img  { max-width: 100%; height: auto; display: block; }

/* ── Base body ─────────────────────────────────────────────── */
body {
  font-family: var(--font-arabic);
  font-size: 14px;           /* matches Wikipedia base */
  line-height: 1.6;
  background: var(--bg-page);
  color: var(--text-main);
  direction: rtl;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

a { color: var(--link-blue); text-decoration: none; }
a:hover { text-decoration: underline; }
a:visited { color: var(--link-visited); }
a.redlink { color: var(--link-red); }
a.external::after { content: ' ↗'; font-size: .78em; opacity: .6; }

/* ── Reading progress ──────────────────────────────────────── */
#reading-progress {
  position: fixed;
  top: 0; right: 0; left: 0;
  height: 3px;
  background: var(--link-blue);
  width: 0%;
  z-index: 9999;
  transition: width .1s linear;
}

/* ════════════════════════════════════════════════════════════
   HEADER
════════════════════════════════════════════════════════════ */
#mw-header {
  position: sticky;
  top: 0;
  z-index: 300;
  display: flex;
  align-items: center;
  gap: 10px;
  height: var(--header-h);
  padding: 0 14px;
  background: var(--bg-content);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 1px 3px rgba(0,0,0,.08);
  direction: rtl;
}

/* Hamburger */
#mw-burger {
  display: none;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  width: 40px;
  height: 40px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 6px;
  border-radius: 4px;
  flex-shrink: 0;
}
#mw-burger span {
  display: block;
  width: 22px;
  height: 2px;
  background: var(--text-main);
  border-radius: 2px;
  transition: transform .24s, opacity .24s;
}
#mw-burger[aria-expanded="true"] span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
#mw-burger[aria-expanded="true"] span:nth-child(2) { opacity: 0; }
#mw-burger[aria-expanded="true"] span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

/* Logo */
#mw-header-logo {
  display: flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  color: var(--text-main);
  flex-shrink: 0;
}
#mw-header-logo .globe-svg { width: 44px; height: 44px; flex-shrink: 0; }
.logo-text { display: flex; flex-direction: column; line-height: 1.15; }
.site-name-ar {
  font-family: var(--font-arabic);
  font-size: 17px;
  font-weight: 700;
  color: var(--text-main);
  white-space: nowrap;
}
.site-name-en {
  font-family: var(--font-ui);
  font-size: 10px;
  font-variant: small-caps;
  color: var(--text-muted);
  letter-spacing: .09em;
  white-space: nowrap;
}

/* Search */
#searchform {
  display: flex;
  flex: 1;
  max-width: 360px;
  margin: 0 auto;
  direction: rtl;
}
#searchform button {
  padding: 0 12px;
  border: 1px solid var(--border);
  border-left: none;
  border-radius: 0 3px 3px 0;   /* RTL: radius on left side */
  background: var(--bg-page);
  cursor: pointer;
  font-size: 15px;
  height: 36px;
  transition: background .12s;
}
#searchform button:hover { background: #e8eaed; }
#searchform input[type="search"] {
  flex: 1;
  height: 36px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-right: none;
  border-radius: 3px 0 0 3px;   /* RTL: radius on right side */
  font-family: var(--font-arabic);
  font-size: 14px;
  background: var(--bg-content);
  color: var(--text-main);
  outline: none;
  min-width: 0;
}
#searchform input[type="search"]:focus {
  border-color: var(--link-blue);
  box-shadow: 0 0 0 2px rgba(51,102,204,.18);
}

/* Text-size control pill */
#ts-controls {
  display: flex;
  align-items: stretch;
  flex-shrink: 0;
  border: 1px solid var(--border);
  border-radius: 3px;
  overflow: hidden;
  height: 32px;
}
.ts-btn {
  padding: 0 8px;
  background: var(--bg-page);
  border: none;
  border-right: 1px solid var(--border);
  cursor: pointer;
  font-family: Arial, sans-serif;   /* always Arial regardless of page font */
  color: var(--text-muted);
  line-height: 32px;
  transition: background .12s, color .12s;
  -webkit-tap-highlight-color: transparent;
}
.ts-btn:last-child { border-right: none; }
.ts-btn:hover   { background: #e8eaed; color: var(--text-main); }
.ts-btn.ts-active { background: var(--link-blue); color: #fff; }
.ts-small  { font-size: 11px; }
.ts-normal { font-size: 14px; }
.ts-large  { font-size: 17px; }
.ts-xlarge { font-size: 20px; }

/* User tools */
#user-tools {
  margin-right: auto;    /* RTL: push to left */
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: var(--font-ui);
  font-size: 13px;
  flex-shrink: 0;
  white-space: nowrap;
}
#user-tools a { color: var(--link-blue); }
.user-greeting { display: flex; align-items: center; gap: 6px; }
.badge-alert {
  display: inline-block;
  background: var(--accent-orange);
  color: #fff;
  border-radius: 10px;
  padding: 0 6px;
  font-size: 11px;
  font-weight: bold;
}

/* ════════════════════════════════════════════════════════════
   LAYOUT
════════════════════════════════════════════════════════════ */
#sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.46);
  z-index: 250;
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}
#sidebar-overlay.open { display: block; }

#mw-page-base {
  display: flex;
  direction: rtl;
  min-height: calc(100vh - var(--header-h) - 70px);
}

/* ════════════════════════════════════════════════════════════
   SIDEBAR  (right side in RTL)
════════════════════════════════════════════════════════════ */
#mw-panel {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  flex-shrink: 0;
  background: var(--bg-sidebar);
  border-left: 1px solid var(--border);
  padding: 14px 10px 32px;
  font-family: var(--font-ui);
  font-size: 13px;
  position: sticky;
  top: var(--header-h);
  align-self: flex-start;
  max-height: calc(100vh - var(--header-h));
  overflow-y: auto;
  overscroll-behavior: contain;
}
#mw-panel::-webkit-scrollbar { width: 4px; }
#mw-panel::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.portal { margin-bottom: 20px; }
.portal h3 {
  font-family: var(--font-ui);
  font-size: 11px;
  font-weight: bold;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .06em;
  margin-bottom: 7px;
  padding-bottom: 4px;
  border-bottom: 1px solid var(--border);
}
.portal ul { list-style: none; }
.portal ul li { padding: 3px 0; }
.portal ul li a {
  font-family: var(--font-ui);
  color: var(--link-blue);
  font-size: 13px;
  display: block;
}

/* Sidebar text-size widget */
.sidebar-ts {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr 1fr;
  gap: 3px;
  margin-top: 6px;
}
.sidebar-ts .ts-btn {
  border: 1px solid var(--border) !important;
  border-right: 1px solid var(--border) !important;
  border-radius: 2px;
  padding: 6px 2px;
  line-height: 1;
  height: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
}
.sidebar-ts .ts-btn small {
  font-family: var(--font-arabic);
  font-size: 9px;
}

/* ════════════════════════════════════════════════════════════
   CONTENT WRAPPER
════════════════════════════════════════════════════════════ */
#content-wrapper {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.admin-notice {
  background: #fef3c7;
  border-bottom: 1px solid var(--accent-orange);
  padding: 8px 20px;
  font-family: var(--font-arabic);
  font-size: 13px;
  color: #78350f;
}

/* ════════════════════════════════════════════════════════════
   ARTICLE TABS  (Wikipedia-exact styling)
════════════════════════════════════════════════════════════ */
#p-views {
  background: var(--bg-page);
  border-bottom: 1px solid var(--tab-border);
  padding: 0 var(--content-pad);
  padding-top: 6px;
  direction: rtl;
}
#p-views ul { list-style: none; display: flex; direction: rtl; }
#p-views ul li { margin-left: 2px; }
#p-views ul li a {
  display: block;
  padding: 7px 14px;
  background: var(--tab-inactive-bg);
  border: 1px solid var(--tab-border);
  border-bottom: none;
  border-radius: 3px 3px 0 0;
  font-family: var(--font-ui);
  font-size: 13px;
  color: var(--text-main);
  margin-bottom: -1px;
  position: relative;
  white-space: nowrap;
  transition: background .1s;
}
#p-views ul li.selected a {
  background: var(--tab-active-bg);
  border-bottom-color: #fff;
  z-index: 1;
}
#p-views ul li a:hover { background: #fff; text-decoration: none; }

/* ════════════════════════════════════════════════════════════
   MAIN CONTENT AREA
════════════════════════════════════════════════════════════ */
#mw-content {
  background: var(--bg-content);
  padding: var(--content-pad) 24px 36px;
  flex: 1;
}

/* ════════════════════════════════════════════════════════════
   ★ ARTICLE TYPOGRAPHY — the heart of the reading experience ★

   Architecture:
   1. #firstHeading — scales with --text-scale via calc()
   2. .mw-body-content — ONE font-size set here: base × --text-scale
   3. ALL children use plain em/% — they inherit and scale uniformly
   4. No child ever multiplies by --text-scale again (was the bug)

   Measurements from Wikipedia's actual skin.vector.styles:
   - body base:    0.875rem = 14px
   - h1:           1.8em
   - h2:           1.5em  (border-bottom)
   - h3:           1.2em
   - h4:           1em    (bold)
   - line-height:  1.625  (Wikipedia exact)
   - p margin:     0.4em 0 0.8em
════════════════════════════════════════════════════════════ */

/* Article title */
#firstHeading {
  font-family: var(--font-arabic);
  font-size: calc(1.8rem * var(--text-scale));
  font-weight: normal;
  line-height: 1.375;    /* Wikipedia h1/h2 line-height */
  border-bottom: 1px solid var(--border);
  padding-bottom: 5px;
  margin-bottom: 18px;
  color: var(--text-main);
}

/* ── Content container — the ONLY place --text-scale is applied ── */
.mw-body-content {
  font-family: var(--font-content);
  font-size: calc(0.9375rem * var(--text-scale));  /* 15px at scale=1 */
  line-height: 1.625;                               /* Wikipedia exact */
  color: var(--text-main);
  word-break: break-word;
}

/* Paragraphs */
.mw-body-content p {
  margin: 0.4em 0 0.8em;
  /* font-size: inherits from .mw-body-content — DO NOT override */
}

/* Headings — plain em, relative to .mw-body-content's font-size */
.mw-body-content h2 {
  font-family: var(--font-arabic);
  font-size: 1.5em;           /* Wikipedia: 150% */
  font-weight: normal;
  line-height: 1.375;
  border-bottom: 1px solid var(--border);
  padding-bottom: 3px;
  margin: 1.5em 0 0.5em;
}
.mw-body-content h3 {
  font-family: var(--font-arabic);
  font-size: 1.2em;           /* Wikipedia: 128% */
  font-weight: bold;
  line-height: 1.6;
  margin: 1.2em 0 0.4em;
}
.mw-body-content h4 {
  font-family: var(--font-arabic);
  font-size: 1em;             /* Wikipedia: 116% — we keep 1em for cleanliness */
  font-weight: bold;
  line-height: 1.6;
  margin: 1em 0 0.3em;
}
.mw-body-content h5, .mw-body-content h6 {
  font-size: 0.9em;
  font-weight: bold;
  margin: 0.8em 0 0.25em;
}

/* Lists */
.mw-body-content ul,
.mw-body-content ol {
  margin: 0.3em 0 0.9em;
  padding-right: 2em;
  padding-left: 0;
}
.mw-body-content li { margin: 0.3em 0; }

/* Inline */
.mw-body-content strong { font-weight: bold; }
.mw-body-content em     { font-style: italic; }
.mw-body-content hr     { border: none; border-top: 1px solid var(--border); margin: 1.2em 0; }
.mw-body-content code,
.mw-body-content pre   { font-family: var(--font-mono); font-size: 0.875em; }
.mw-body-content pre {
  background: var(--bg-page);
  border: 1px solid var(--border);
  padding: 10px 14px;
  overflow-x: auto;
  line-height: 1.4;
}
.mw-body-content blockquote {
  border-right: 4px solid var(--border);
  margin: 0.8em 0;
  padding: 6px 14px;
  color: var(--text-muted);
  font-size: 0.95em;
}

/* Tables */
.mw-body-content table.wikitable {
  border-collapse: collapse;
  margin: 1em 0;
  font-size: 0.875em;
  direction: rtl;
}
.mw-body-content table.wikitable th,
.mw-body-content table.wikitable td {
  border: 1px solid var(--border);
  padding: 5px 10px;
  text-align: right;
}
.mw-body-content table.wikitable th {
  background: #eaecf0;
  font-weight: bold;
}
.mw-body-content table.wikitable tr:nth-child(even) td {
  background: #f8f9fa;
}

/* ── Table of contents ─────────────────────────────────────── */
#toc {
  display: inline-block;
  background: var(--bg-page);
  border: 1px solid var(--border);
  padding: 12px 18px;
  margin: 0 24px 16px 0;
  float: right;
  min-width: 200px;
  max-width: 300px;
  font-family: var(--font-ui);
  font-size: 0.875em;   /* relative to .mw-body-content */
  direction: rtl;
}
#toc-title {
  font-weight: bold;
  text-align: center;
  margin-bottom: 8px;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  user-select: none;
  cursor: pointer;
}
.toc-toggle {
  font-weight: normal;
  font-size: 0.85em;
  color: var(--link-blue);
}
#toc-list {
  margin: 0;
  padding-right: 18px;
  padding-left: 0;
}
#toc li   { margin: 4px 0; }
#toc a    { color: var(--link-blue); font-size: 0.95em; }

/* ── Infobox ───────────────────────────────────────────────── */
table.infobox {
  float: left;
  clear: left;
  margin: 0 24px 16px 0;
  border: 1px solid var(--border);
  background: var(--bg-page);
  min-width: 220px;
  max-width: 320px;
  font-family: var(--font-ui);
  font-size: 0.85em;
  line-height: 1.6;
  border-collapse: collapse;
  direction: rtl;
}
table.infobox caption.infobox-title {
  background: #cee0f2;
  font-family: var(--font-arabic);
  font-size: 1.05em;
  font-weight: bold;
  text-align: center;
  padding: 6px 8px;
}
table.infobox td {
  padding: 4px 10px;
  border-top: 1px solid var(--border);
  vertical-align: top;
  text-align: right;
}
table.infobox td:first-child {
  font-weight: bold;
  color: var(--text-muted);
  white-space: nowrap;
  background: #f0f4fa;
}

/* ── Categories ────────────────────────────────────────────── */
#catlinks {
  background: var(--bg-page);
  border: 1px solid var(--border);
  padding: 8px 14px;
  margin-top: 24px;
  clear: both;
  font-family: var(--font-ui);
  font-size: 13px;
  direction: rtl;
}
.catlinks-label { font-weight: bold; color: var(--text-muted); margin-left: 6px; }
#catlinks a {
  display: inline-block;
  margin: 2px 4px;
  padding: 2px 10px;
  border: 1px solid var(--border);
  border-radius: 2px;
  background: var(--bg-content);
  color: var(--link-blue);
  font-size: 13px;
}
#catlinks a:hover { background: #e8eaed; text-decoration: none; }

/* ── Last edited ────────────────────────────────────────────── */
#mw-last-edited {
  font-family: var(--font-ui);
  font-size: 12px;
  color: var(--text-muted);
  padding: 8px 0 0;
  border-top: 1px solid var(--border);
  margin-top: 16px;
}

/* ════════════════════════════════════════════════════════════
   BUTTONS & FORMS  (Wikipedia-style gray border buttons)
════════════════════════════════════════════════════════════ */
.mw-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 6px 14px;
  min-height: 34px;
  border: 1px solid var(--border);
  background: var(--bg-page);
  color: var(--text-main);
  font-family: var(--font-ui);
  font-size: 13px;
  cursor: pointer;
  border-radius: 2px;
  text-decoration: none;
  line-height: 1.4;
  transition: background .1s, border-color .1s;
  -webkit-tap-highlight-color: transparent;
}
.mw-btn:hover { background: #e8eaed; border-color: #72777d; text-decoration: none; color: var(--text-main); }
.mw-btn:visited { color: var(--text-main); }

.mw-btn-primary { background: var(--link-blue); color: #fff !important; border-color: #2a4b8d; }
.mw-btn-primary:hover { background: #2a55b3; }

.mw-btn-danger  { background: #cc3333; color: #fff !important; border-color: #b32222; }
.mw-btn-danger:hover  { background: #b32222; }

.mw-btn-success { background: #14866d; color: #fff !important; border-color: #0d6658; }
.mw-btn-success:hover { background: #0d6658; }

.btn-group { display: flex; gap: 6px; flex-wrap: wrap; }

/* ── Login / Register forms ────────────────────────────────── */
.login-form {
  max-width: 480px;
  margin: 32px auto;
  background: var(--bg-content);
  border: 1px solid var(--border);
  padding: 28px 32px;
  direction: rtl;
}
.login-form h2 {
  font-family: var(--font-arabic);
  font-size: 1.4em;
  font-weight: normal;
  border-bottom: 1px solid var(--border);
  padding-bottom: 8px;
  margin-bottom: 20px;
}
.form-group { margin-bottom: 18px; }
.form-group label {
  display: block;
  margin-bottom: 5px;
  font-family: var(--font-ui);
  font-size: 13px;
  font-weight: bold;
}
.form-group input[type="text"],
.form-group input[type="email"],
.form-group input[type="password"] {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  font-family: var(--font-arabic);
  font-size: 14px;
  background: var(--bg-content);
  color: var(--text-main);
  border-radius: 2px;
  transition: border-color .15s, box-shadow .15s;
}
.form-group input:focus {
  outline: none;
  border-color: var(--link-blue);
  box-shadow: 0 0 0 2px rgba(51,102,204,.18);
}
.form-hint { font-family: var(--font-ui); font-size: 12px; color: var(--text-muted); margin-top: 4px; }

/* ── Edit form ─────────────────────────────────────────────── */
.edit-toolbar {
  margin-bottom: 6px;
  display: flex;
  gap: 3px;
  flex-wrap: wrap;
  direction: rtl;
}
.edit-toolbar button {
  padding: 4px 9px;
  min-height: 30px;
  border: 1px solid var(--border);
  background: var(--bg-page);
  cursor: pointer;
  font-family: var(--font-ui);
  font-size: 13px;
  border-radius: 2px;
}
.edit-toolbar button:hover { background: #e8eaed; }
.edit-textarea {
  width: 100%;
  min-height: 400px;
  font-family: var(--font-mono);
  font-size: 13px;
  padding: 10px;
  border: 1px solid var(--border);
  resize: vertical;
  background: var(--bg-content);
  color: var(--text-main);
  line-height: 1.55;
  direction: rtl;
}
.edit-summary-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 10px 0;
  direction: rtl;
}
.edit-summary-row label { font-family: var(--font-ui); font-size: 13px; white-space: nowrap; }
.edit-summary-input {
  flex: 1;
  padding: 7px 10px;
  border: 1px solid var(--border);
  font-family: var(--font-arabic);
  font-size: 13px;
  border-radius: 2px;
}
.edit-note { font-family: var(--font-ui); font-size: 12px; color: var(--text-muted); margin-bottom: 10px; }
.edit-actions { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }

/* ════════════════════════════════════════════════════════════
   TABLES  (history, admin)
════════════════════════════════════════════════════════════ */
.history-table,
.admin-table {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--font-ui);
  font-size: 13px;
  direction: rtl;
}
.history-table th, .history-table td,
.admin-table th,  .admin-table td {
  border: 1px solid var(--border);
  padding: 7px 10px;
  vertical-align: top;
  text-align: right;
}
.history-table th, .admin-table th {
  background: #eaecf0;
  font-weight: bold;
  white-space: nowrap;
}
.history-table tr:hover td,
.admin-table tr:hover td { background: #f0f4f8; }
.history-table .current-row td { background: #eaf3fb; }
.admin-table tr:nth-child(even) td { background: #f9fafb; }

/* ════════════════════════════════════════════════════════════
   SEARCH
════════════════════════════════════════════════════════════ */
.search-header {
  margin-bottom: 16px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 14px;
}
.search-results { margin-top: 8px; }
.search-result {
  padding: 14px 0;
  border-bottom: 1px solid #eaecf0;
}
.search-result:last-child { border-bottom: none; }
.search-result h3 { margin-bottom: 4px; }
.search-result h3 a {
  font-family: var(--font-arabic);
  font-size: 1.1em;
  color: var(--link-blue);
}
.search-result .result-url { font-family: var(--font-ui); font-size: 12px; color: #4c9a4c; margin-bottom: 4px; }
.search-result .excerpt {
  font-family: var(--font-arabic);
  font-size: 13px;
  color: var(--text-main);
  line-height: 1.55;
}
.search-result .excerpt mark { background: #fff176; padding: 0 2px; }
.search-no-results { font-family: var(--font-arabic); color: var(--text-muted); font-size: 14px; margin-top: 12px; }

/* ════════════════════════════════════════════════════════════
   BADGES & STATUS
════════════════════════════════════════════════════════════ */
.role-badge {
  display: inline-block;
  padding: 1px 7px;
  border-radius: 2px;
  font-family: var(--font-ui);
  font-size: 11px;
  font-weight: bold;
  text-transform: uppercase;
  letter-spacing: .04em;
}
.role-admin   { background: var(--accent-orange); color: #fff; }
.role-editor  { background: var(--link-blue); color: #fff; }
.role-visitor { background: #a2a9b1; color: #fff; }

.status-badge {
  display: inline-block;
  padding: 1px 7px;
  border-radius: 2px;
  font-family: var(--font-ui);
  font-size: 11px;
  font-weight: bold;
}
.status-pending  { background: #fff3cd; color: #856404; border: 1px solid #ffeeba; }
.status-approved { background: #d4edda; color: #155724; border: 1px solid #c3e6cb; }
.status-rejected { background: #f8d7da; color: #721c24; border: 1px solid #f5c6cb; }

.verified-badge { color: var(--accent-orange); }

/* ════════════════════════════════════════════════════════════
   MESSAGE BOXES
════════════════════════════════════════════════════════════ */
.mw-message-box {
  padding: 11px 16px;
  margin-bottom: 16px;
  border-radius: 2px;
  font-family: var(--font-arabic);
  font-size: 13px;
  border: 1px solid;
  line-height: 1.5;
}
.mw-message-box-success { background: #d4edda; border-color: #c3e6cb; color: #155724; }
.mw-message-box-error   { background: #f8d7da; border-color: #f5c6cb; color: #721c24; }
.mw-message-box-warning { background: #fff3cd; border-color: #ffeeba; color: #856404; }
.mw-message-box-info    { background: #d1ecf1; border-color: #bee5eb; color: #0c5460; }

/* ════════════════════════════════════════════════════════════
   USER CONTRIBUTIONS
════════════════════════════════════════════════════════════ */
.contribs-meta { font-family: var(--font-ui); font-size: 13px; color: var(--text-muted); margin-bottom: 20px; }
.contribs-list { list-style: none; }
.contribs-list li {
  display: flex;
  gap: 8px;
  align-items: baseline;
  flex-wrap: wrap;
  padding: 7px 0;
  border-bottom: 1px solid #eaecf0;
  font-family: var(--font-arabic);
  font-size: 13px;
}
.contribs-list li:last-child { border-bottom: none; }
.contribs-date    { font-family: var(--font-ui); font-size: 12px; color: var(--text-muted); white-space: nowrap; flex-shrink: 0; }
.contribs-summary { font-family: var(--font-ui); font-size: 12px; color: var(--text-muted); font-style: italic; }

/* ════════════════════════════════════════════════════════════
   HOMEPAGE
════════════════════════════════════════════════════════════ */

/* ── Welcome Banner ── */
#home-welcome {
  display: flex;
  align-items: center;
  gap: 20px;
  background: linear-gradient(135deg, #f8f9fa 0%, #eaf3fb 100%);
  border: 1px solid #a2a9b1;
  padding: 24px 28px;
  margin-bottom: 0;
}
#home-welcome-logo {
  font-size: 3.6rem;
  flex-shrink: 0;
  line-height: 1;
  filter: drop-shadow(0 2px 4px rgba(0,0,0,.15));
}
#home-welcome-title {
  font-size: 1.85rem;
  font-weight: bold;
  color: var(--text-primary);
  line-height: 1.2;
  margin-bottom: 4px;
}
#home-welcome-tagline {
  font-size: 0.92rem;
  color: var(--text-muted);
  margin-bottom: 8px;
}
#home-welcome-count {
  font-size: 0.88rem;
  color: var(--text-primary);
}
#home-welcome-count a { margin: 0 2px; }

/* ── Topic Grid ── */
#home-topics {
  display: flex;
  flex-wrap: wrap;
  gap: 0;
  border: 1px solid #a2a9b1;
  border-top: none;
  background: #fff;
  padding: 12px 16px;
  margin-bottom: 20px;
  justify-content: center;
}
.home-topic {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 6px 14px;
  text-decoration: none;
  color: var(--link-blue);
  font-size: 12px;
  border-radius: 3px;
  transition: background 0.12s;
  min-width: 64px;
  text-align: center;
}
.home-topic:hover { background: #eaf3fb; text-decoration: none; }
.topic-icon { font-size: 1.2rem; line-height: 1; }

/* ── Main 2-column ── */
#home-main {
  display: grid;
  grid-template-columns: 1fr 300px;
  gap: 20px;
  margin-bottom: 20px;
  align-items: start;
}

/* ── Featured Article ── */
#home-featured {
  background: var(--bg-content);
  border: 1px solid var(--border);
  padding: 16px 20px;
}
.home-section-hdr {
  font-size: 1rem;
  font-weight: bold;
  border-bottom: 1px solid var(--border);
  padding-bottom: 6px;
  margin-bottom: 14px;
  color: var(--text-primary);
}
.hdr-star { color: #f0a500; margin-left: 4px; }
.featured-img {
  float: left;
  margin: 0 0 12px 18px;
  max-width: 220px;
  max-height: 180px;
  width: auto;
  height: auto;
  border: 1px solid var(--border);
  padding: 3px;
  background: #fff;
}
.featured-title {
  font-size: 1.3em;
  font-weight: bold;
  margin-bottom: 10px;
  border: none;
  padding: 0;
}
.featured-title a { color: var(--text-primary); }
.featured-title a:hover { color: var(--link-blue); }
.featured-body {
  font-size: 14px;
  line-height: 1.7;
  color: var(--text-primary);
  margin-bottom: 12px;
}
.featured-footer {
  font-size: 13px;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
  padding-top: 8px;
  clear: both;
}
.featured-footer a { margin: 0 2px; }

/* ── Sidebar ── */
#home-sidebar {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* ── Shared section box ── */
.home-section {
  background: var(--bg-content);
  border: 1px solid var(--border);
  padding: 14px 16px;
  margin-bottom: 0;
}
.home-section .home-section-hdr { margin-top: 0; }
.home-art-list { list-style: none; margin: 0; padding: 0; }
.home-art-list li {
  padding: 5px 0;
  border-bottom: 1px solid #eaecf0;
  font-size: 14px;
}
.home-art-list li:last-child { border-bottom: none; }
.rc-date { font-size: 12px; color: var(--text-muted); }
.home-contribute p { font-size: 13px; margin: 6px 0 0; }

/* ── Recent edits full-width ── */
#home-recent-edits { margin-bottom: 0; }
.recent-change {
  padding: 6px 0;
  border-bottom: 1px solid #eaecf0;
  font-family: var(--font-arabic);
  font-size: 14px;
}
.recent-change:last-child { border-bottom: none; }
.rc-meta { font-family: var(--font-ui); color: var(--text-muted); font-size: 12px; }

/* ── Stats box ── */
.stats-box {
  background: var(--bg-page);
  border: 1px solid var(--border);
  padding: 14px 16px;
}
.stats-box h3 {
  font-family: var(--font-arabic);
  font-size: 0.95em;
  font-weight: bold;
  margin-bottom: 10px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 6px;
}
.stat-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 0;
  border-bottom: 1px solid #eaecf0;
  font-family: var(--font-ui);
  font-size: 13px;
}
.stat-item:last-child { border-bottom: none; }
.stat-value { font-weight: bold; color: var(--link-blue); font-size: 17px; }

/* ════════════════════════════════════════════════════════════
   TALK PAGE
════════════════════════════════════════════════════════════ */
.talk-message { padding: 12px 0; }
.talk-meta {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px;
}
.talk-meta strong a { color: var(--text-primary); }
.talk-subject { font-weight: bold; color: var(--text-primary); }
.talk-date { font-family: var(--font-ui); font-size: 12px; }
.talk-body {
  font-size: 14px;
  line-height: 1.7;
  padding-right: 12px;
  border-right: 3px solid var(--border);
}
.talk-hr { border: none; border-top: 1px solid var(--border); margin: 4px 0; }
.talk-del-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 11px;
  padding: 0 2px;
}
.talk-del-btn:hover { color: #c00; }
.talk-form-wrap {
  margin-top: 28px;
  padding-top: 20px;
  border-top: 2px solid var(--border);
}
.talk-form-title {
  font-size: 1.1em;
  font-weight: bold;
  margin-bottom: 14px;
  border: none;
  padding: 0;
}

/* ════════════════════════════════════════════════════════════
   ADMIN
════════════════════════════════════════════════════════════ */
.admin-section { margin-bottom: 32px; }
.admin-section h2 {
  font-family: var(--font-arabic);
  font-size: 1.3em;
  font-weight: normal;
  border-bottom: 1px solid var(--border);
  padding-bottom: 6px;
  margin-bottom: 14px;
}

/* ════════════════════════════════════════════════════════════
   MISC
════════════════════════════════════════════════════════════ */
.pending-notice {
  background: #fff3cd;
  border: 1px solid #ffc107;
  padding: 10px 16px;
  margin-bottom: 16px;
  font-family: var(--font-arabic);
  font-size: 13px;
  border-radius: 2px;
}

/* ── Footer ────────────────────────────────────────────────── */
#footer {
  background: var(--bg-page);
  border-top: 1px solid var(--border);
  padding: 16px 24px;
  font-family: var(--font-ui);
  font-size: 12px;
  color: var(--text-muted);
  text-align: center;
  direction: rtl;
  margin-bottom: 56px;  /* clear mobile bottom nav */
}
#footer div { margin-bottom: 4px; }
#footer a   { color: var(--link-blue); }

/* ── Scroll-to-top ─────────────────────────────────────────── */
#scroll-top-btn {
  position: fixed;
  bottom: 72px;
  left: 14px;
  width: 44px;
  height: 44px;
  background: var(--bg-content);
  border: 1px solid var(--border);
  border-radius: 50%;
  cursor: pointer;
  font-size: 18px;
  font-family: var(--font-ui);
  box-shadow: 0 2px 8px rgba(0,0,0,.15);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity .2s, transform .2s;
  z-index: 200;
  color: var(--text-main);
}
#scroll-top-btn.visible { opacity: 1; transform: translateY(0); }
#scroll-top-btn:hover { background: #e8eaed; }

/* ── Mobile bottom nav ─────────────────────────────────────── */
#mobile-bottom-nav {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 56px;
  background: var(--bg-content);
  border-top: 1px solid var(--border);
  z-index: 300;
  direction: rtl;
  box-shadow: 0 -2px 8px rgba(0,0,0,.08);
}
#mobile-bottom-nav a {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  height: 100%;
  color: var(--text-muted);
  font-family: var(--font-arabic);
  font-size: 10px;
  gap: 2px;
  text-decoration: none;
  padding: 4px 0;
  -webkit-tap-highlight-color: transparent;
  transition: color .12s;
}
#mobile-bottom-nav a:hover,
#mobile-bottom-nav a.active { color: var(--link-blue); text-decoration: none; }
#mobile-bottom-nav .nav-icon  { font-size: 21px; line-height: 1; }

/* ════════════════════════════════════════════════════════════
   ★ MOBILE RESPONSIVE ★
════════════════════════════════════════════════════════════ */
@media (max-width: 900px) {
  :root { --sidebar-width: 280px; }

  /* Show hamburger */
  #mw-burger { display: flex !important; }

  /* Hide desktop text-size pill (sidebar has it) */
  #ts-controls { display: none; }

  /* Sidebar becomes a fixed RIGHT-side drawer */
  #mw-panel {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    z-index: 260;
    min-width: 0;
    max-height: 100vh;
    padding-top: 60px;   /* room for close button */
    border-left: 1px solid var(--border);
    border-right: none;
    box-shadow: -4px 0 24px rgba(0,0,0,.18);
    transform: translateX(100%);
    transition: transform .28s cubic-bezier(.4,0,.2,1);
  }
  #mw-panel.open { transform: translateX(0); }

  /* Show mobile bottom nav */
  #mobile-bottom-nav { display: flex; }

  /* Block elements go full-width */
  table.infobox { float: none !important; margin: 0 0 16px !important; max-width: 100%; }
  #toc          { float: none !important; display: block; max-width: 100%; margin: 0 0 16px; }

  /* Homepage stacks */
  #home-welcome { flex-direction: column; text-align: center; padding: 18px 16px; gap: 12px; }
  #home-welcome-logo { font-size: 2.6rem; }
  #home-welcome-title { font-size: 1.4rem; }
  #home-topics { padding: 10px 8px; gap: 0; }
  .home-topic { padding: 6px 10px; min-width: 60px; font-size: 12px; }
  .topic-icon { font-size: 1.2rem; }
  #home-main { grid-template-columns: 1fr; }
  #home-sidebar { gap: 12px; }
  .featured-img { max-width: 140px; }
  .stats-box { position: static; }

  /* Content padding */
  #mw-content { padding: 14px 14px 28px; }
  #p-views    { padding: 0 12px; padding-top: 4px; }
  #p-views ul { overflow-x: auto; -webkit-overflow-scrolling: touch; flex-wrap: nowrap; }
  #p-views ul li a { padding: 6px 10px; font-size: 12px; white-space: nowrap; }

  /* Scrollable tables */
  .admin-table,
  .history-table { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; }

  /* Login form */
  .login-form { margin: 16px; padding: 18px; }
}

@media (max-width: 600px) {
  /* Slightly larger base on phones for comfort */
  .mw-body-content { font-size: calc(1rem * var(--text-scale)); }
  #firstHeading    { font-size: calc(1.5rem * var(--text-scale)); }

  /* ── Header: drop logo text, keep only globe ── */
  #mw-header { padding: 0 8px; gap: 6px; }
  .logo-text  { display: none; }             /* hide "البرحةبيديا" text */
  #mw-header-logo .globe-svg { width: 36px; height: 36px; }

  /* ── User tools: username only, hide nav links (they're in sidebar/bottom-nav) ── */
  #user-tools .role-badge { display: none; }
  #user-tools a[href*="admin"],
  #user-tools a[href*="logout"],
  #user-tools a[href*="login"],
  #user-tools a[href*="register"] { display: none; }
  #user-tools .user-greeting a {
    max-width: 70px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    display: inline-block;
    vertical-align: middle;
  }

  /* Prevent iOS auto-zoom on input focus */
  #searchform input[type="search"] { font-size: 16px; }

  .edit-textarea { min-height: 280px; }
  .edit-summary-row { flex-direction: column; align-items: stretch; }
  .btn-group { flex-direction: column; }
  .home-section-hdr { font-size: 0.95rem; }
}

/* ════════════════════════════════════════════════════════════
   COLLAPSIBLE SECTIONS  (mobile only — Wikipedia style)
   Collapse is JS-driven (inline style) — no CSS media query
   needed for show/hide, so no caching or specificity issues.
════════════════════════════════════════════════════════════ */

/* section-body: contain floats so they don't bleed outside */
.section-body { overflow: hidden; }

/* Toggle label — invisible until JS marks the h2 */
.section-toggle { display: none; }

/* Only style headings that JS has actually made collapsible */
@media (max-width: 900px) {
  .mw-body-content h2.collapsible-h2 {
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
  }
  .mw-body-content h2.collapsible-h2 .section-toggle {
    display: inline;
    margin-right: auto;   /* RTL: pushes to physical-left of heading */
    font-size: 0.8em;
    font-weight: normal;
    font-family: var(--font-ui);
    color: var(--link-blue);
    white-space: nowrap;
    flex-shrink: 0;
  }
}

/* ════════════════════════════════════════════════════════════
   WIKI IMAGE THUMBNAILS
════════════════════════════════════════════════════════════ */
.wiki-thumb {
  display: table;          /* shrink-wraps to image width */
  border: 1px solid #c8ccd1;
  background: #f8f9fa;
  padding: 4px;
  font-size: 0.85em;
  max-width: 100%;
  clear: right;            /* stack multiple thumbs */
}
.wiki-thumb img { display: block; max-width: 100%; height: auto; }
.wiki-thumb figcaption {
  display: table-caption;
  caption-side: bottom;
  text-align: center;
  padding: 4px 4px 2px;
  color: var(--text-muted);
  font-family: var(--font-ui);
  font-size: 0.85em;
  line-height: 1.3;
  background: #f8f9fa;
}
@media (max-width: 900px) {
  .wiki-thumb { float: none !important; margin: 0 auto 14px !important; display: block; max-width: 100% !important; }
  .wiki-thumb figcaption { display: block; }
}

/* ════════════════════════════════════════════════════════════
   IMAGE UPLOAD MODAL
════════════════════════════════════════════════════════════ */
#image-modal {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 9000;
  background: rgba(0,0,0,.55);
  align-items: center;
  justify-content: center;
  direction: rtl;
  padding: 16px;
}
#image-modal.open { display: flex; }

.img-modal-box {
  background: var(--bg-content);
  border-radius: 6px;
  width: 100%;
  max-width: 680px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 8px 40px rgba(0,0,0,.3);
  display: flex;
  flex-direction: column;
}
.img-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  font-family: var(--font-arabic);
  font-size: 16px;
  font-weight: bold;
  flex-shrink: 0;
}
.img-modal-close {
  background: none;
  border: none;
  font-size: 22px;
  cursor: pointer;
  color: var(--text-muted);
  line-height: 1;
  padding: 2px 6px;
  border-radius: 3px;
}
.img-modal-close:hover { background: #eee; color: var(--text-main); }
.img-modal-body { padding: 16px 18px; display: flex; flex-direction: column; gap: 16px; }

#img-dropzone {
  border: 2px dashed var(--border);
  border-radius: 6px;
  padding: 24px 16px;
  text-align: center;
  cursor: pointer;
  background: var(--bg-page);
  transition: border-color .15s, background .15s;
  font-family: var(--font-arabic);
  color: var(--text-muted);
  font-size: 14px;
}
#img-dropzone:hover, #img-dropzone.dragover {
  border-color: var(--link-blue);
  background: #f0f4ff;
  color: var(--link-blue);
}
#img-dropzone .drop-icon { font-size: 32px; display: block; margin-bottom: 6px; }
#img-preview { margin-top: 8px; display: flex; justify-content: center; }

#img-progress { display: none; background: #eaecf0; border-radius: 3px; height: 6px; overflow: hidden; }
.img-progress-bar { height: 100%; background: var(--link-blue); border-radius: 3px; transition: width .2s; width: 0; }

.img-gallery-label {
  font-family: var(--font-ui);
  font-size: 12px;
  font-weight: bold;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .05em;
  margin-bottom: 6px;
}
#img-gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(90px, 1fr));
  gap: 8px;
  max-height: 220px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 8px;
  background: var(--bg-page);
}
.img-card { border: 2px solid transparent; border-radius: 4px; cursor: pointer; overflow: hidden; background: var(--bg-content); transition: border-color .12s; display: flex; flex-direction: column; align-items: center; }
.img-card:hover   { border-color: var(--border); }
.img-card.selected { border-color: var(--link-blue); }
.img-card img { width: 100%; aspect-ratio: 1; object-fit: cover; display: block; }
.img-card span { font-family: var(--font-ui); font-size: 9px; color: var(--text-muted); padding: 2px 4px; word-break: break-all; text-align: center; direction: ltr; }
.img-loading, .img-empty { grid-column: 1 / -1; font-family: var(--font-arabic); font-size: 13px; color: var(--text-muted); text-align: center; padding: 20px; }

.img-caption-row { display: flex; align-items: center; gap: 8px; }
.img-caption-row label { font-family: var(--font-ui); font-size: 13px; white-space: nowrap; }
#img-caption { flex: 1; padding: 7px 10px; border: 1px solid var(--border); border-radius: 3px; font-family: var(--font-arabic); font-size: 13px; }

.img-modal-footer { display: flex; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--border); background: var(--bg-page); flex-shrink: 0; direction: rtl; }

/* ── Print ────────────────────────────────────────────────── */
@media print {
  #mw-header, #mw-panel, #p-views, #mobile-bottom-nav,
  #scroll-top-btn, #reading-progress, .admin-notice,
  .edit-actions, .btn-group { display: none !important; }
  body { background: #fff; direction: rtl; }
  #mw-content { padding: 0; }
  a[href]::after { content: ' (' attr(href) ')'; font-size: 10px; color: #666; }
}
