/* Shared UI for the builder and the admin panel (not used on rendered pages). */
:root {
  --bg: #f6f2ec;
  --panel: #fff;
  --ink: #1f2328;
  --muted: #6b6f76;
  --line: #e4ddd2;
  --accent: #0f766e;
  --accent-ink: #fff;
  --warn: #b45309;
  --err: #b91c1c;
  --ok: #15803d;
}
body.ui {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.45 system-ui, -apple-system, 'Segoe UI', sans-serif;
}
.ui * { box-sizing: border-box; }
.topbar h1 { font-size: 22px; margin: 0 0 4px; }
#editor h2 { font-size: 17px; margin: 0 0 12px; }
.topbar { padding: 20px 16px 8px; max-width: 1280px; margin: 0 auto; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.error { color: var(--err); font-weight: 600; }
.ok { color: var(--ok); }
.warn { color: var(--warn); font-weight: 600; }

.builder {
  display: grid;
  grid-template-columns: minmax(300px, 400px) 1fr;
  gap: 16px;
  padding: 8px 16px 32px;
  max-width: 1280px;
  margin: 0 auto;
  align-items: start;
}
@media (max-width: 800px) { .builder { grid-template-columns: 1fr; } }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 16px; min-width: 0; }
.settings { position: sticky; top: 12px; }
@media (max-width: 800px) { .settings { position: static; } }

.field { margin-bottom: 16px; }
.field > label, .flabel { display: block; font-weight: 600; margin-bottom: 6px; }
.ui input[type=text], .ui select, .ui textarea {
  width: 100%;
  padding: 8px 10px;
  font: inherit;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}
.ui textarea { resize: vertical; }
.radio, .check { display: flex; align-items: center; gap: 8px; padding: 3px 0; font-weight: 400; cursor: pointer; }
.checklist { max-height: 260px; overflow: auto; border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; }
.row-between { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin-bottom: 6px; }
.link { background: none; border: 0; padding: 0; color: var(--accent); cursor: pointer; font: inherit; font-size: 13px; }

.cover-options { display: flex; gap: 10px; flex-wrap: wrap; }
.cover-option {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  background: none; border: 2px solid transparent; border-radius: 10px; padding: 4px; cursor: pointer; color: inherit;
}
.cover-option.selected { border-color: var(--accent); }

.status { background: #faf7f2; border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; margin-bottom: 16px; }
.status p { margin: 0 0 6px; }
.status p:last-child { margin-bottom: 0; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0 8px; }
.chip { border: 1px solid var(--accent); color: var(--accent); background: #fff; border-radius: 999px; padding: 3px 10px; cursor: pointer; font: inherit; font-size: 13px; }

.actions { display: grid; gap: 8px; }
.btn {
  padding: 10px 14px; border-radius: 8px; border: 1px solid var(--accent);
  background: #fff; color: var(--accent); font: inherit; font-weight: 600; cursor: pointer;
}
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.danger { border-color: var(--err); color: var(--err); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.sm { padding: 5px 10px; font-size: 13px; }

.book-thumbs { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; justify-items: center; }

/* ---------- Admin ---------- */
.admin-bar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 10px 16px; background: #fff; border-bottom: 1px solid var(--line);
}
.admin-bar #save-state { margin-left: auto; }
.tabs { display: flex; gap: 4px; flex-wrap: wrap; }
.tabs button { background: none; border: 0; padding: 6px 12px; border-radius: 8px; font: inherit; cursor: pointer; color: var(--muted); }
.tabs button.active { background: var(--bg); color: var(--ink); font-weight: 600; }

.admin {
  display: grid;
  grid-template-columns: 240px minmax(320px, 1fr) minmax(320px, 360px);
  gap: 12px; padding: 12px 16px 32px; align-items: start;
}
@media (max-width: 1100px) { .admin { grid-template-columns: 220px 1fr; } .admin > :last-child { grid-column: 1 / -1; } }
@media (max-width: 700px) { .admin { grid-template-columns: 1fr; } }

.item-list { display: grid; gap: 4px; margin-bottom: 10px; max-height: 70vh; overflow: auto; }
.item {
  display: flex; gap: 8px; align-items: center; text-align: left;
  background: none; border: 1px solid transparent; border-radius: 8px; padding: 6px 8px; cursor: pointer; font: inherit; color: inherit;
}
.item:hover { background: var(--bg); }
.item.active { border-color: var(--accent); background: #f0faf8; }
.item-img { width: 40px; height: 40px; border-radius: 6px; object-fit: cover; flex: none; }
.item-text { display: grid; min-width: 0; }
.item-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.add-btn { width: 100%; }
.tools { display: flex; gap: 6px; }

.lang-box { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px 2px; margin: 0 0 14px; }
.lang-box legend { font-weight: 700; padding: 0 6px; }
.arabic-input { font-family: 'Noto Naskh Arabic', serif !important; font-size: 22px !important; line-height: 1.9 !important; }
label.field { display: block; }
.colors { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 0 12px; }
.ui input[type=color] { width: 100%; height: 34px; padding: 2px; border: 1px solid var(--line); border-radius: 8px; background: #fff; }

.zone-stage {
  position: relative; width: 100%; max-width: 480px; aspect-ratio: 1;
  background-size: 100% 100%; border-radius: 8px; margin: 6px 0 8px; touch-action: none;
}
.zone-box { position: absolute; border: 2px dashed #dc2626; background: rgba(220, 38, 38, .08); cursor: move; }
.handle { position: absolute; width: 14px; height: 14px; background: #dc2626; border: 2px solid #fff; border-radius: 50%; }
.handle.nw { left: -8px; top: -8px; cursor: nwse-resize; }
.handle.ne { right: -8px; top: -8px; cursor: nesw-resize; }
.handle.sw { left: -8px; bottom: -8px; cursor: nesw-resize; }
.handle.se { right: -8px; bottom: -8px; cursor: nwse-resize; }

.admin-preview { display: grid; gap: 14px; justify-items: center; }
.preview-item { margin: 0; display: grid; gap: 4px; justify-items: center; }

.font-options { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 6px; }
.font-option {
  min-height: 52px; padding: 4px 6px; border: 2px solid var(--line); border-radius: 10px;
  background: #fff; color: #6d28d9; cursor: pointer; line-height: 1.2;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.font-option.selected { border-color: var(--accent); background: #f0faf8; }

.lang-buttons { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.lang-btn {
  display: grid; gap: 2px; text-align: left; padding: 10px 12px; border-radius: 10px; cursor: pointer;
  background: #fff; border: 1px solid var(--line); font: inherit; color: inherit;
}
.lang-btn:hover { border-color: var(--accent); }
.lang-btn.done span { color: var(--ok); }
.lang-btn.missing span { color: var(--warn); font-weight: 600; }
.lang-dialog {
  width: min(640px, calc(100vw - 32px)); border: 0; border-radius: 14px; padding: 18px 20px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .25);
}
.lang-dialog::backdrop { background: rgba(20, 20, 20, .35); }
.lang-dialog h2 { font-size: 17px; margin: 0; }
.dialog-arabic {
  font-family: 'Noto Naskh Arabic', serif; font-weight: 700; font-size: 22px; line-height: 1.9;
  white-space: pre-line; text-align: center; background: var(--bg); border-radius: 10px; padding: 8px 12px; margin: 12px 0;
}

.offscreen { position: absolute; left: -10000px; top: 0; visibility: hidden; }
