/* Management area styles — additive on top of chat/chat.css, which provides
   the oklch design tokens (:root/.dark) and shared components
   (.app-shell, .sidebar, .nav-link, .btn*, .icon-btn, .user-card). */

/* ── Layout ──────────────────────────────────────────────────────────── */
.manage-sidebar-wrap { flex-shrink: 0; }

.manage-panel {
  height: 100%;
  overflow-y: auto;
  /* Column so the footer sits at the bottom of short pages. */
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border);
  border-radius: 1.5rem;
  background: var(--card);
  box-shadow: var(--shadow-soft);
  padding: 1.5rem;
}

/* Center the page content instead of letting it hug the inline-start edge. */
.manage-content {
  width: 100%;
  max-width: 72rem;
  margin-inline: auto;
  margin-bottom: 2rem;
}

.manage-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.manage-header h1 { font-size: 1.375rem; font-weight: 800; }

/* ── Alerts (messages framework) ─────────────────────────────────────── */
.alert {
  padding: 0.625rem 1rem;
  border-radius: 0.75rem;
  font-size: 0.875rem;
  margin-bottom: 0.75rem;
}

.alert-success { background: rgba(46, 125, 91, 0.12); color: var(--success); }
.alert-warning { background: rgba(185, 138, 47, 0.18); color: var(--gold-foreground); }
.alert-error { background: rgba(192, 72, 58, 0.1); color: var(--destructive); }
.alert-info { background: rgba(20, 69, 58, 0.1); color: var(--primary); }

/* ── Dashboard ───────────────────────────────────────────────────────── */
/* Titled rows: materials stats / cards stats / chat activity. */
.dash-section + .dash-section { margin-top: 2rem; }

.dash-section-title {
  font-size: 1.0625rem;
  font-weight: 800;
  margin: 0 0 0.875rem;
  padding-inline-start: 0.75rem;
  border-inline-start: 3px solid var(--primary);
  color: var(--foreground);
}

.stat-grid {
  display: grid;
  /* auto-fit collapses empty tracks: tiles always fill the full row. */
  grid-template-columns: repeat(auto-fit, minmax(13rem, 1fr));
  gap: 1rem;
}

.stat-card {
  display: flex;
  align-items: center;
  gap: 0.875rem;
  padding: 1.125rem 1.25rem;
  border: 1px solid var(--border);
  border-radius: 1rem;
  background: var(--background);
  transition: border-color 0.15s, box-shadow 0.15s;
}

/* Only linked tiles advertise interactivity. */
a.stat-card:hover {
  border-color: rgba(20, 69, 58, 0.4);
  box-shadow: var(--shadow-elegant);
}

/* The icon carries the accent; the number stays in text ink. */
.stat-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2.75rem;
  height: 2.75rem;
  border-radius: 0.75rem;
  flex-shrink: 0;
  background: rgba(20, 69, 58, 0.1);
  color: var(--primary);
}

.stat-icon svg { width: 1.375rem; height: 1.375rem; }

.stat-body {
  display: flex;
  flex-direction: column;
  gap: 0.125rem;
  min-width: 0;
}

.stat-number {
  font-family: var(--font-display);
  font-size: 1.625rem;
  font-weight: 800;
  line-height: 1.2;
  color: var(--foreground);
  font-variant-numeric: tabular-nums;
}

.stat-label { font-size: 0.8125rem; color: var(--muted-foreground); }

/* Detail panels under the tiles. */
.panel-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(19rem, 1fr));
  gap: 1rem;
  margin-top: 1rem;
}

.panel {
  border: 1px solid var(--border);
  border-radius: 1rem;
  background: var(--background);
  padding: 1.25rem;
}

.panel h2,
.panel h3 {
  font-size: 0.9375rem;
  font-weight: 700;
  margin: 0 0 1rem;
  color: var(--foreground);
}

.panel-empty {
  font-size: 0.8125rem;
  color: var(--muted-foreground);
}

/* Single-hue magnitude bars: the bar shows proportion, the value is
   plain text beside it (never inside or colored like the bar). */
.bar-row {
  display: grid;
  grid-template-columns: minmax(6rem, 38%) 1fr auto;
  align-items: center;
  gap: 0.75rem;
  padding-block: 0.375rem;
  font-size: 0.8125rem;
}

.bar-name {
  color: var(--muted-foreground);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bar-track {
  height: 0.5rem;
  border-radius: 4px;
  background: var(--muted);
  overflow: hidden;
}

.bar-fill {
  display: block;
  height: 100%;
  min-width: 2px;
  border-radius: 4px;
  background: var(--primary);
}

.bar-value {
  font-weight: 600;
  color: var(--foreground);
  font-variant-numeric: tabular-nums;
  min-width: 2ch;
}

/* Latest-updated cards list. */
.recent-list { display: flex; flex-direction: column; }

.recent-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.625rem 0.25rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.8125rem;
  border-radius: 0.5rem;
  transition: background 0.15s;
}

.recent-item:last-child { border-bottom: none; }

.recent-item:hover { background: var(--muted); }

.recent-title {
  font-weight: 500;
  color: var(--foreground);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.recent-meta {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
  color: var(--muted-foreground);
}

/* ── List search bar ─────────────────────────────────────────────────── */
.list-search {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.list-search input[type='search'] {
  flex: 1;
  min-width: 0;
}

/* ── Data tables ─────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

.data-table th {
  text-align: right;
  padding: 0.625rem 0.75rem;
  color: var(--muted-foreground);
  font-weight: 500;
  font-size: 0.75rem;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.data-table td {
  padding: 0.625rem 0.75rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.data-table tbody tr:hover { background: var(--accent); }

.cell-title { font-weight: 500; }

/* Reply-list "when is it used" documentation column. */
.cell-description {
  color: var(--muted-foreground);
  font-size: 0.8125rem;
  max-width: 22rem;
}

.cell-actions {
  display: flex;
  gap: 0.375rem;
  justify-content: flex-end;
  white-space: nowrap;
}

.btn-danger { color: var(--destructive); }
.btn-danger:hover { background: rgba(192, 72, 58, 0.1); color: var(--destructive); }
.btn-danger-solid { background: var(--destructive); flex: 0 1 auto; }

.empty-state {
  text-align: center;
  color: var(--muted-foreground);
  padding: 3rem 1rem;
}

/* ── Pagination ──────────────────────────────────────────────────────── */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  margin-top: 1rem;
}

.pagination-info { font-size: 0.8125rem; color: var(--muted-foreground); }

/* ── Forms ───────────────────────────────────────────────────────────── */
/* Same design language as the public pages (dw-hero / enc-card): warm
   white card with a gold top accent, cream inputs, gold diamond markers. */
.manage-form {
  max-width: 52rem;
  margin-inline: auto;
}

.form-card {
  border: 1px solid var(--border);
  border-top: 3px solid var(--gold-border);
  border-radius: 1rem;
  background: var(--white);
  box-shadow: var(--shadow-soft);
  padding: 1.625rem 1.75rem 1.75rem;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.125rem 1.5rem;
}

@media (max-width: 640px) {
  .form-grid { grid-template-columns: 1fr; }
}

.form-grid .field { margin-bottom: 0; }

/* Long/technical fields take the full row. */
.form-grid > [data-field='title'],
.form-grid > [data-field='name'],
.form-grid > [data-field='description'],
.form-grid > [data-field='intro'],
.form-grid > [data-field='icon'],
.form-grid > [data-field='content_urls'],
.form-grid > [data-field='source_data'],
.form-grid > [data-field='card_property'],
.form-grid > [data-field='page_url'],
.form-grid > [data-field='visible_fields'] {
  grid-column: 1 / -1;
}

/* CheckboxSelectMultiple (visible fields per encyclopedia): Django 5
   renders nested <div>s — turn the options into selectable pills. */
[data-field='visible_fields'] > div {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.25rem;
}

/* Unwrap each option's <div> so the flex gap applies to the labels. */
[data-field='visible_fields'] > div > div { display: contents; }

[data-field='visible_fields'] div label {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  border: 1px solid var(--border);
  border-radius: 9999px;
  background: var(--card);
  padding: calc(0.375rem + 1px) 0.875rem calc(0.375rem - 1px);
  font-size: 0.8125rem;
  font-weight: 500;
  cursor: pointer;
  margin-bottom: 0;
  transition: border-color 0.15s, background 0.15s, color 0.15s;
}

[data-field='visible_fields'] div label:hover {
  border-color: rgba(20, 69, 58, 0.4);
  box-shadow: var(--shadow-soft);
}

[data-field='visible_fields'] div label:has(input:checked) {
  background: rgba(20, 69, 58, 0.1);
  border-color: rgba(20, 69, 58, 0.45);
  color: var(--primary);
  font-weight: 700;
}

[data-field='visible_fields'] div label:has(input:focus-visible) {
  outline: 2px solid var(--ring);
  outline-offset: 2px;
}

/* Custom-drawn checkbox: rounded square, checkmark pops in when checked. */
[data-field='visible_fields'] input[type='checkbox'] {
  appearance: none;
  width: 1.05rem;
  height: 1.05rem;
  margin: 0;
  border: 1.5px solid var(--border);
  border-radius: 0.3rem;
  background: var(--card);
  display: grid;
  place-content: center;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

[data-field='visible_fields'] input[type='checkbox']::before {
  content: '';
  width: 0.6rem;
  height: 0.6rem;
  transform: scale(0);
  transition: transform 0.12s ease-in-out;
  clip-path: polygon(14% 44%, 0 65%, 50% 100%, 100% 16%, 80% 0%, 43% 62%);
  background: var(--primary-foreground);
}

[data-field='visible_fields'] input[type='checkbox']:checked {
  background: var(--primary);
  border-color: var(--primary);
}

[data-field='visible_fields'] input[type='checkbox']:checked::before {
  transform: scale(1);
}

.field { margin-bottom: 0.875rem; }

.field label {
  display: block;
  font-size: 0.8125rem;
  font-weight: 700;
  color: var(--foreground);
  margin-bottom: 0.375rem;
}

/* Required fields carry the platform's gold diamond. */
.field label.required::after {
  content: '◆';
  color: var(--gold);
  font-size: 0.375rem;
  vertical-align: 0.375em;
  margin-inline-start: 0.3125rem;
}

.field input,
.field select,
.field textarea,
.list-search input,
.list-search select {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 0.625rem;
  background: var(--background);
  color: var(--foreground);
  /* +1px/-1px: recenters Tajawal glyphs, which sit above the middle. */
  padding: calc(0.5625rem + 1px) 0.875rem calc(0.5625rem - 1px);
  font-size: 0.875rem;
  transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
}

.field input:hover,
.field select:hover,
.field textarea:hover { border-color: var(--gold-border); }

.list-search input,
.list-search select { width: auto; }

.list-search input { flex: 1; }

.field input:focus,
.field select:focus,
.field textarea:focus,
.list-search input:focus,
.list-search select:focus {
  outline: none;
  border-color: var(--primary);
  background: var(--white);
  box-shadow: 0 0 0 3px rgba(20, 69, 58, 0.12);
}

.field textarea { line-height: 1.75; resize: vertical; }

/* Selects: custom chevron on the inline-end (left in RTL). */
.field select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%236f6a5c' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: left 0.75rem center;
  padding-inline-end: 0.875rem;
  padding-inline-start: 2.25rem;
  cursor: pointer;
}

.field-help {
  margin: 0.3125rem 0 0;
  font-size: 0.75rem;
  line-height: 1.7;
  color: var(--muted-foreground);
}

.field-error-text {
  margin: 0.3125rem 0 0;
  font-size: 0.75rem;
  color: var(--destructive);
}

.field-error-text::before {
  content: '!';
  display: inline-grid;
  place-content: center;
  width: 0.875rem;
  height: 0.875rem;
  margin-inline-end: 0.3125rem;
  border-radius: 50%;
  background: var(--destructive);
  color: var(--destructive-foreground);
  font-size: 0.625rem;
  font-weight: 800;
}

.field.field-error input,
.field.field-error select,
.field.field-error textarea { border-color: var(--destructive); }

/* ── Toggle switch (BooleanField) ── */
.field-switch { align-self: center; }

/* `.field label.switch`: must outrank `.field label { display: block }`
   or the flex row collapses and the track overlaps the text. */
.field label.switch,
.switch {
  display: flex;
  align-items: flex-start;
  gap: 0.875rem;
  cursor: pointer;
  margin-bottom: 0;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 0.75rem;
  background: var(--background);
  transition: border-color 0.15s, background 0.15s;
}

.switch:hover { border-color: var(--gold-border); }

.switch:has(input:checked) {
  border-color: rgba(20, 69, 58, 0.35);
  background: var(--accent);
}

.switch input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.switch-track {
  position: relative;
  flex-shrink: 0;
  width: 2.375rem;
  height: 1.375rem;
  border-radius: 999px;
  background: var(--border);
  transition: background 0.18s ease;
}

.switch-track::after {
  content: '';
  position: absolute;
  top: 0.1875rem;
  inset-inline-start: 0.1875rem;
  width: 1rem;
  height: 1rem;
  border-radius: 50%;
  background: var(--white);
  box-shadow: 0 1px 2px rgba(29, 42, 38, 0.25);
  transition: transform 0.18s ease;
}

.switch input:checked ~ .switch-track { background: var(--primary); }

/* RTL: the thumb travels left when on. */
.switch input:checked ~ .switch-track::after { transform: translateX(-1rem); }

[dir='ltr'] .switch input:checked ~ .switch-track::after { transform: translateX(1rem); }

.switch input:focus-visible ~ .switch-track {
  outline: 2px solid var(--ring);
  outline-offset: 2px;
}

.switch-text { display: flex; flex-direction: column; gap: 0.125rem; }

 /* +1px: Arabic glyphs sit high; nudges the text onto the optical middle. */
.switch-label { font-size: 0.875rem; font-weight: 700; transform: translateY(1px); }

.switch-text .field-help { margin: 0; }

/* ── Option picker (RadioSelect) / icon picker ── */
.option-picker {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(8.5rem, 1fr));
  gap: 0.5rem;
}

.option-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.4375rem;
  text-align: center;
  padding: 0.75rem 0.5rem 0.625rem;
  border: 1px solid var(--border);
  border-radius: 0.75rem;
  background: var(--background);
  font-size: 0.8125rem;
  font-weight: 500;
  cursor: pointer;
  margin-bottom: 0;
  transition: border-color 0.15s, background 0.15s, box-shadow 0.15s, color 0.15s;
}

.option-card:hover {
  border-color: var(--gold-border);
  box-shadow: var(--shadow-soft);
}

.option-card input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.option-card:has(input:checked) {
  border-color: rgba(20, 69, 58, 0.5);
  background: var(--accent);
  color: var(--primary);
  font-weight: 700;
  box-shadow: 0 0 0 1px rgba(20, 69, 58, 0.35);
}

.option-card:has(input:focus-visible) {
  outline: 2px solid var(--ring);
  outline-offset: 2px;
}

.option-glyph {
  display: grid;
  place-content: center;
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 0.625rem;
  background: var(--gold-soft);
  border: 1px solid var(--gold-border-soft);
  color: var(--gold-foreground);
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.option-glyph svg { width: 1.25rem; height: 1.25rem; }

.option-card:has(input:checked) .option-glyph {
  background: var(--primary);
  border-color: var(--primary);
  color: var(--primary-foreground);
}

.option-label { line-height: 1.4; }

.form-section-title {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 1rem;
  font-weight: 700;
  color: var(--primary);
  margin: 1.5rem 0 0.75rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

.form-section-title::before {
  content: '';
  flex-shrink: 0;
  width: 0.25rem;
  height: 1.125rem;
  border-radius: 999px;
  background: var(--primary);
}

.form-actions {
  display: flex;
  gap: 0.625rem;
  margin-top: 1.5rem;
}

.form-actions .btn { flex: 0 1 auto; padding-inline: 1.75rem; }

/* ── Inline formsets (card-style rows) ───────────────────────────────── */
.formset-rows {
  display: flex;
  flex-direction: column;
  gap: 0.875rem;
  margin-bottom: 0.875rem;
}

.formset-row {
  border: 1px solid var(--border);
  border-radius: 1rem;
  background: var(--white);
  padding: 0;
  margin: 0;
  overflow: hidden;
  transition: opacity 0.15s, border-color 0.15s;
}

/* Cream header with a gold diamond — same as the public enc-cards. */
.formset-row-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.5rem 0.875rem;
  background: var(--gold-soft);
  border-bottom: 1px solid var(--gold-border-soft);
}

.formset-row-title {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.8125rem;
  font-weight: 700;
  color: var(--foreground);
}

.formset-row-title::before {
  content: '◆';
  color: var(--gold);
  font-size: 0.4375rem;
  flex-shrink: 0;
}

.formset-row-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.375rem;
  height: 1.375rem;
  padding: 0 0.25rem;
  border-radius: 9999px;
  background: rgba(20, 69, 58, 0.1);
  color: var(--primary);
  font-size: 0.6875rem;
  font-weight: 700;
}

.formset-row-name {
  color: var(--primary);
  font-size: 0.8125rem;
  font-weight: 700;
}

.formset-delete {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--muted-foreground);
  cursor: pointer;
  border-radius: 0.5rem;
  padding: 0.25rem 0.5rem;
  transition: color 0.15s, background 0.15s;
}

.formset-delete:hover {
  color: var(--destructive);
  background: rgba(192, 72, 58, 0.1);
}

.formset-delete svg { width: 0.875rem; height: 0.875rem; }

.formset-delete input[type='checkbox'] {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

/* A row marked for deletion dims until the form is saved. */
.formset-row:has(.formset-delete input:checked) {
  opacity: 0.5;
  border-style: dashed;
  border-color: var(--destructive);
}

.formset-row:has(.formset-delete input:checked) .formset-delete {
  color: var(--destructive);
}

.formset-row-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem 1rem;
  padding: 0.875rem;
}

@media (max-width: 640px) {
  .formset-row-grid { grid-template-columns: 1fr; }
}

.formset-row-grid .field { margin-bottom: 0; }

/* Sentence text spans the full row; order stays narrow next to the field. */
.formset-row-grid > [data-field='text'] { grid-column: 1 / -1; }

/* JSON / LTR technical inputs read better in monospace. */
.field textarea[dir='ltr'],
.field input[dir='ltr'] {
  font-family: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
  font-size: 0.75rem;
}

.formset-add-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
}

.formset-add-btn svg { width: 1rem; height: 1rem; }

/* ── Small layout utilities (used by base.html header) ───────────────── */
.d-flex { display: flex; align-items: center; }
.gap-2 { gap: 0.5rem; }
.justify-content-between { justify-content: space-between; }

/* ── Delete confirmation ─────────────────────────────────────────────── */
.confirm-card {
  max-width: 36rem;
  margin-inline: auto;
  border: 1px solid var(--border);
  border-radius: 1rem;
  padding: 1.5rem;
  background: var(--background);
}

.confirm-card p { margin: 0 0 1rem; line-height: 1.7; }

/* ── Login page ──────────────────────────────────────────────────────── */
/* Body is a column: the login card fills the viewport, footer below. */
.login-body {
  height: auto;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.login-page {
  flex: 1 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background: var(--background);
}

.login-card {
  width: 100%;
  max-width: 24rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  border: 1px solid var(--border);
  border-radius: 1.5rem;
  background: var(--card);
  box-shadow: var(--shadow-elegant);
  padding: 2rem 1.75rem;
}

.login-card .logo-big {
  width: 4.5rem;
  height: 4.5rem;
  border-radius: 1rem;
  object-fit: contain;
  margin-bottom: 1rem;
}

.login-card h1 { font-size: 1.5rem; font-weight: 800; margin-bottom: 0.375rem; }

.login-sub {
  color: var(--muted-foreground);
  font-size: 0.875rem;
  margin: 0 0 1.25rem;
}

.login-card form { width: 100%; text-align: right; }

.login-card .alert { width: 100%; }

.login-btn { width: 100%; margin-top: 0.5rem; padding-block: 0.625rem; }

.login-back {
  margin-top: 1.25rem;
  font-size: 0.8125rem;
  color: var(--muted-foreground);
}

.login-back:hover { color: var(--primary); }

/* "ليس لديك حساب؟ إنشاء حساب" / "لديك حساب؟ تسجيل الدخول" */
.login-alt {
  margin: 1.25rem 0 0;
  font-size: 0.875rem;
  color: var(--muted-foreground);
}

.login-alt a {
  color: var(--primary);
  font-weight: 800;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.login-alt a:hover { color: var(--gold-foreground); }

.login-alt + .login-back { margin-top: 0.75rem; }

/* ── Register page: wider card, paired fields ─────────────────────────── */
.register-card { max-width: 34rem; }

.register-card .login-sub { margin-bottom: 1.5rem; }

.form-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0 0.875rem;
}

@media (max-width: 480px) {
  .form-row { grid-template-columns: 1fr; }
}

/* Native constraint bubbles are off (novalidate); errors render inline. */
.register-card .field-error-text { line-height: 1.6; }

/* Favourite language: the chat page's searchable combo (chat.css
   .chat-lang-combo + lang_picker.js), with the trigger sized and coloured
   like the other inputs of the form. The dropdown itself is untouched. */
.reg-lang-combo { width: 100%; }

.reg-lang-combo .lang-trigger {
  width: 100%;
  justify-content: space-between;
  border: 1px solid var(--border);
  border-radius: 0.625rem;
  background: var(--background);
  padding: calc(0.5625rem + 1px) 0.875rem calc(0.5625rem - 1px);
  font-size: 0.875rem;
  font-weight: 400;
  color: var(--foreground);
  transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
}

.reg-lang-combo .lang-trigger:hover { border-color: var(--gold-border); }

.reg-lang-combo .lang-trigger:focus-visible,
.reg-lang-combo .lang-trigger[aria-expanded='true'] {
  outline: none;
  border-color: var(--primary);
  background: var(--white);
  box-shadow: 0 0 0 3px rgba(20, 69, 58, 0.12);
}

.field-error .reg-lang-combo .lang-trigger { border-color: var(--destructive); }

/* Panel spans the field (the chat pins a fixed 250px panel to one edge)
   and stays above the paired password fields below it. */
.reg-lang-combo .lang-combo-list {
  inset-inline: 0;
  width: auto;
  z-index: 30;
}

/* ── Sidebar user card logout ────────────────────────────────────────── */
.logout-form { display: flex; }

/* ── Section-card board (بطاقات التبويبات) ─────────────────────────── */
.section-card-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
  align-items: stretch;
}

@media (max-width: 720px) {
  .section-card-grid { grid-template-columns: 1fr; }
}

.section-card {
  display: flex;
  flex-direction: column;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 0.875rem;
  padding: 1rem 1.125rem;
  box-shadow: 0 1px 2px rgba(29, 42, 38, 0.05);
}

.section-card-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem;
}

.section-card-title {
  margin: 0 0 0.375rem;
  font-size: 1.0625rem;
  font-weight: 800;
  color: var(--primary);
}

.section-card-order {
  flex-shrink: 0;
  font-size: 0.75rem;
  color: var(--muted-foreground);
  background: var(--muted);
  border-radius: 999px;
  padding: 0.0625rem 0.5rem;
}

.section-card-desc {
  margin: 0 0 0.75rem;
  font-size: 0.875rem;
  line-height: 1.75;
  color: var(--card-foreground);
  white-space: pre-line;
}

/* Attachments sit at the bottom of the card, right above the actions. */
.section-card-files {
  list-style: none;
  margin: auto 0 0.75rem;
  padding: 0.75rem 0 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.375rem;
}

.section-card-files a {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  max-width: 100%;
  padding: 0.25rem 0.625rem 0.1875rem;
  background: var(--gold-soft);
  border: 1px solid var(--gold-border);
  border-radius: 999px;
  color: var(--gold-foreground);
  font-size: 0.75rem;
  font-weight: 700;
  text-decoration: none;
}

.section-card-files a:hover { background: var(--gold); color: #fffdf8; }
.section-card-files svg { width: 13px; height: 13px; flex-shrink: 0; }

.section-card-files .file-name {
  max-width: 11rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.section-card-files .file-ext {
  text-transform: uppercase;
  font-size: 0.6563rem;
  opacity: 0.75;
}

.section-card-actions {
  display: flex;
  gap: 0.5rem;
  padding-top: 0.625rem;
  border-top: 1px dashed var(--border);
}

/* No attachments -> the actions row takes over pinning to the bottom. */
.section-card:not(:has(.section-card-files)) .section-card-actions {
  margin-top: auto;
}

/* ── Card modal ── */
.card-modal {
  width: min(42rem, calc(100vw - 2rem));
  border: none;
  border-top: 3px solid var(--gold-border);
  border-radius: 1rem;
  padding: 1.5rem 1.625rem;
  background: var(--white);
  color: var(--foreground);
  box-shadow: 0 20px 50px rgba(29, 42, 38, 0.25);
}

.card-modal::backdrop { background: rgba(29, 42, 38, 0.45); }

.card-modal h2 {
  display: flex;
  align-items: center;
  gap: 0.5625rem;
  margin: 0 0 1.25rem;
  font-size: 1.125rem;
  font-weight: 800;
  color: var(--primary);
}

.card-modal h2::before {
  content: '◆';
  color: var(--gold);
  font-size: 0.5rem;
  flex-shrink: 0;
}

.modal-attachments {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
}

.modal-attachments li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.625rem;
  padding: 0.375rem 0.625rem;
  background: var(--muted);
  border-radius: 0.5rem;
  font-size: 0.8125rem;
}

.modal-attachments li .file-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.modal-attachments li .btn { flex-shrink: 0; padding-block: 0.125rem; }

.modal-attachments li.attachment-removed .file-name {
  text-decoration: line-through;
  opacity: 0.55;
}

/* ── File inputs (attachments) ── */
.field input[type='file'] {
  border-style: dashed;
  border-color: var(--gold-border-soft);
  background: var(--gold-soft);
  cursor: pointer;
}

.field input[type='file']:hover { border-color: var(--gold-border); }

.field input[type='file']::file-selector-button {
  border: none;
  border-radius: 999px;
  background: var(--primary);
  color: var(--primary-foreground);
  font-family: inherit;
  font-size: 0.75rem;
  font-weight: 700;
  padding: calc(0.3125rem + 1px) 0.875rem calc(0.3125rem - 1px);
  margin-inline-end: 0.75rem;
  cursor: pointer;
  transition: background 0.15s;
}

.field input[type='file']::file-selector-button:hover {
  background: var(--primary-deep);
}

/* ── Mobile sidebar drawer (manage area) ─────────────────────────────── */
/* The manage sidebar keeps the hardcoded `open` class for desktop; on
   phones chat.css turns .sidebar-wrap into a fixed drawer where `open`
   means slid-in — so re-close it and use `mobile-open` (toggled by
   manage.js) as the actual mobile state. */
.manage-header-start {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  min-width: 0;
}

.manage-menu-btn { display: none; flex-shrink: 0; }

@media (max-width: 767px) {
  .manage-menu-btn { display: inline-flex; }

  .manage-sidebar-wrap.open { transform: translateX(100%); }

  .manage-sidebar-wrap.open.mobile-open {
    transform: translateX(0);
    box-shadow: -18px 0 44px rgba(29, 42, 38, 0.2);
  }

  .manage-panel { border-radius: 1rem; padding: 1rem; }

  .manage-header { flex-wrap: wrap; }
}

/* ── Encyclopedia sync (on-demand) ───────────────────────────────────── */
.sync-banner {
  display: flex;
  align-items: center;
  gap: 0.625rem;
}

.sync-spinner {
  flex-shrink: 0;
  width: 1rem;
  height: 1rem;
  border-radius: 50%;
  border: 2px solid rgba(20, 69, 58, 0.25);
  border-top-color: var(--primary);
  animation: sync-spin 0.8s linear infinite;
}

@keyframes sync-spin { to { transform: rotate(360deg); } }

.sync-badge {
  display: inline-flex;
  flex-direction: column;
  gap: 0.0625rem;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--muted-foreground);
}

.sync-badge small {
  font-size: 0.6875rem;
  font-weight: 400;
  color: var(--muted-foreground);
  direction: ltr;
  text-align: end;
}

.sync-success { color: var(--success); }
.sync-failed { color: var(--destructive); }
.sync-running { color: var(--primary); }

.sync-form { display: inline-flex; }

.sync-full-note {
  margin-top: 0.75rem;
  font-size: 0.75rem;
  color: var(--muted-foreground);
}

/* External link on a section card (manage board). */
.section-card-url {
  margin: 0 0 0.75rem;
  font-size: 0.8125rem;
}

.section-card-url a {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  color: var(--primary);
  font-weight: 700;
  text-decoration: none;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.section-card-url a:hover { text-decoration: underline; }
.section-card-url svg { width: 13px; height: 13px; flex-shrink: 0; }
