:root {
  --ink: #1f1a16;
  --muted: #6f655c;
  --brand: #241103;
  --brand-2: #3a2412;
  --gold: #c4a577;
  --paper: #f6f4f1;
  --card: #ffffff;
  --soft: #faf9f7;
  --line: #e4ded6;
  --ok: #1f7a4d;
  --ok-bg: #e7f4ec;
  --bad: #a03030;
  --bad-bg: #fbeaea;
  --draft: #8a5a12;
  --draft-bg: #f8f0e1;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(36, 17, 3, 0.05), 0 6px 20px rgba(36, 17, 3, 0.04);
  --font: "IBM Plex Sans Arabic", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.6;
}
h1, h2 { font-weight: 600; letter-spacing: 0; }
h1 { font-size: 1.7rem; line-height: 1.3; margin: 0; }
h2 { font-size: 1.05rem; margin: 0; }
a { color: inherit; }
code { font-size: 0.85em; background: var(--soft); border: 1px solid var(--line); border-radius: 6px; padding: 0 5px; }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; opacity: 0.45; }
:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
[hidden] { display: none !important; }

/* ---------- shell ---------- */
.mark {
  display: inline-grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: var(--gold);
  color: var(--brand);
  font-weight: 600;
  font-size: 1.1rem;
  flex: none;
}
.shell { display: grid; grid-template-columns: 248px minmax(0, 1fr); min-height: 100vh; align-items: start; }
.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  overflow: auto;
  background: var(--brand);
  color: #efe7dc;
  padding: 22px 14px;
  display: flex;
  flex-direction: column;
  gap: 22px;
}
.brand { display: flex; gap: 10px; align-items: center; text-decoration: none; padding-inline: 6px; }
.brand b { display: block; font-size: 1.15rem; line-height: 1.2; color: #fff; }
.brand small { color: #b9a994; font-size: 0.8rem; }
.sidebar nav { display: flex; flex-direction: column; gap: 2px; }
.nav-label { margin: 14px 10px 4px; color: #9c8b76; font-size: 0.75rem; font-weight: 600; }
.sidebar nav a {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  text-decoration: none;
  padding: 8px 10px;
  border-radius: 8px;
  color: #dcd0c0;
}
.sidebar nav a:hover { background: rgba(255, 255, 255, 0.06); color: #fff; }
.sidebar nav a[aria-current="page"] { background: rgba(196, 165, 119, 0.18); color: #fff; }
.dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.dot.is-draft { background: var(--gold); }
.dot.is-off { background: #8a7d70; }
.logout { margin-top: auto; }
.logout button {
  width: 100%;
  background: transparent;
  color: #cbbda9;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 8px;
  padding: 8px 10px;
}
.logout button:hover { color: #fff; border-color: rgba(255, 255, 255, 0.3); }

.canvas { width: min(980px, 100%); min-width: 0; margin-inline: auto; padding: 32px 32px 80px; }
.canvas.is-wide { width: min(1680px, 100%); }
.top { display: flex; justify-content: space-between; gap: 24px; align-items: flex-end; margin-bottom: 20px; }
.eyebrow { margin: 0 0 6px; color: var(--muted); font-size: 0.88rem; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.eyebrow a { color: var(--brand); }
.lede { margin: 6px 0 0; max-width: 68ch; color: var(--muted); }

/* ---------- buttons, pills, banners ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 38px;
  border-radius: 9px;
  padding: 7px 14px;
  border: 1px solid transparent;
  text-decoration: none;
  white-space: nowrap;
  font-weight: 500;
}
.btn.primary { background: var(--brand); color: #fff; }
.btn.primary:hover:not(:disabled) { background: var(--brand-2); }
.btn.ghost { background: var(--card); border-color: var(--line); }
.btn.ghost:hover:not(:disabled) { border-color: #cbbfb1; }
.btn.small { min-height: 32px; padding: 4px 10px; font-size: 0.88rem; }

.pip {
  font-style: normal;
  font-size: 0.78rem;
  font-weight: 500;
  border-radius: 999px;
  padding: 1px 9px;
  background: #eeeae5;
  color: var(--muted);
}
.pip.is-on { background: var(--ok-bg); color: var(--ok); }
.pip.is-off { background: #eeeae5; color: var(--muted); }
.pip.is-draft { background: var(--draft-bg); color: var(--draft); }

.banner {
  background: var(--card);
  border: 1px solid var(--line);
  border-inline-start: 3px solid var(--gold);
  border-radius: 10px;
  padding: 10px 14px;
  margin: 0 0 16px;
}
.banner.is-ok { border-inline-start-color: var(--ok); }
.banner.is-bad { border-inline-start-color: var(--bad); color: var(--bad); }

.card, .install, .script-list li, .history li, .section {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

/* ---------- inputs ---------- */
input, textarea, select {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 10px;
  background: #fff;
}
input:hover, textarea:hover, select:hover { border-color: #d3c9bd; }
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--gold); box-shadow: 0 0 0 3px rgba(196, 165, 119, 0.22); }
textarea { resize: vertical; line-height: 1.55; }
[dir="ltr"] { text-align: left; }
label { display: grid; gap: 6px; font-size: 0.9rem; }

/* ---------- dashboard ---------- */
.stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin-bottom: 18px; }
.stats div { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 18px; }
.stats b { display: block; font-size: 1.8rem; font-weight: 600; line-height: 1.2; }
.stats b small { font-size: 1rem; color: var(--muted); font-weight: 500; }
.stats span { color: var(--muted); font-size: 0.88rem; }
.script-list, .history { list-style: none; padding: 0; margin: 0 0 22px; display: flex; flex-direction: column; gap: 10px; }
.script-list li, .history li { display: flex; justify-content: space-between; gap: 16px; padding: 16px 18px; align-items: center; }
.script-main { display: grid; gap: 4px; min-width: 0; }
.script-main a { text-decoration: none; font-size: 1.05rem; }
.script-main a:hover { color: var(--brand-2); text-decoration: underline; }
.script-main > span { color: var(--muted); }
.meta { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 2px; }
.meta small { color: var(--muted); }
.script-actions { display: flex; gap: 8px; flex: none; }
.install { padding: 18px; display: grid; gap: 12px; }
.install p { margin: 4px 0 0; color: var(--muted); }
.install textarea { direction: ltr; text-align: left; font-family: ui-monospace, SFMono-Regular, monospace; font-size: 12.5px; background: var(--soft); }
.install .btn { justify-self: start; }
.history span, .history small { display: block; color: var(--muted); }
.account { padding: 18px; max-width: 460px; }
.account form { display: grid; gap: 12px; }
.account .hint { margin: 0; color: var(--muted); font-size: 0.85rem; }
.account .btn { justify-self: start; }

/* ---------- editor toolbar ---------- */
.toolbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin: 0 -8px 16px;
  padding: 10px 8px;
  background: rgba(246, 244, 241, 0.92);
  backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--line);
}
.toolbar .note { width: min(260px, 100%); }
.toolbar-end { margin-inline-start: auto; display: flex; gap: 8px; align-items: center; }
.status { font-size: 0.88rem; color: var(--muted); }
.status.is-ok { color: var(--ok); }
.status.is-bad { color: var(--bad); }
.status.is-draft { color: var(--draft); }
.menu { position: relative; }
.menu > summary { list-style: none; cursor: pointer; }
.menu > summary::-webkit-details-marker { display: none; }
.menu-list {
  position: absolute;
  inset-inline-end: 0;
  top: calc(100% + 6px);
  min-width: 240px;
  display: grid;
  padding: 6px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 12px 32px rgba(36, 17, 3, 0.14);
  z-index: 10;
}
.menu-list a, .menu-list button, .menu-list label {
  display: block;
  text-align: start;
  text-decoration: none;
  background: none;
  border: 0;
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 0.92rem;
  cursor: pointer;
}
.menu-list a:hover, .menu-list button:hover, .menu-list label:hover { background: var(--soft); }
.menu-list .is-danger { color: var(--bad); }

/* ---------- editor workspace ---------- */
.workspace { display: grid; gap: 20px; grid-template-columns: minmax(0, 1fr); align-items: start; }
.workspace.has-preview { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
.form-col { min-width: 0; max-width: 980px; }
.search { margin-bottom: 14px; background: var(--card); }
.empty { color: var(--muted); }

.section { margin: 0 0 14px; overflow: hidden; }
.section > summary { list-style: none; cursor: pointer; padding: 14px 18px; }
.section > summary::-webkit-details-marker { display: none; }
.section > summary h2 { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.section > summary h2::after, .item > summary::before {
  content: "";
  width: 7px;
  height: 7px;
  border-inline-end: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(45deg);
  flex: none;
  opacity: 0.6;
}
.section[open] > summary h2::after { transform: rotate(-135deg); }
.section > summary .hint { margin: 4px 0 0; color: var(--muted); font-size: 0.88rem; max-width: 80ch; }
.section-body { padding: 4px 18px 18px; display: grid; gap: 16px; border-top: 1px solid var(--line); padding-top: 16px; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px 16px; }
.field { display: grid; gap: 6px; align-content: start; min-width: 0; }
.field-head { display: grid; gap: 1px; }
.field-label { font-weight: 500; font-size: 0.9rem; }
.field-hint { color: var(--muted); font-size: 0.8rem; font-weight: 400; }

.pair { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.lang { position: relative; display: block; }
.lang-tag {
  position: absolute;
  top: 9px;
  inset-inline-end: 8px;
  font-size: 0.68rem;
  font-weight: 600;
  color: #a69888;
  pointer-events: none;
}
.lang input, .lang textarea { padding-inline-end: 30px; }
.lang input[dir="ltr"], .lang textarea[dir="ltr"] { padding-inline-end: 10px; padding-right: 30px; }
.lang:has([dir="ltr"]) .lang-tag { inset-inline-end: auto; right: 8px; }

.color-input { display: flex; gap: 6px; align-items: center; }
.color-input input[type="color"] { flex: none; width: 38px; height: 38px; padding: 3px; cursor: pointer; }
.color-input.is-bad input[type="text"] { border-color: var(--bad); }
.with-thumb { display: flex; gap: 8px; align-items: center; }
.thumb {
  flex: none;
  width: 38px;
  height: 38px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--soft) center / cover no-repeat;
}
.thumb.is-empty { background-image: linear-gradient(135deg, transparent 47%, var(--line) 47%, var(--line) 53%, transparent 53%); }
input[role="switch"] {
  appearance: none;
  -webkit-appearance: none;
  position: relative;
  width: 42px;
  min-height: 0;
  height: 24px;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: #cfc6bb;
  cursor: pointer;
}
input[role="switch"]::before {
  content: "";
  position: absolute;
  top: 3px;
  inset-inline-start: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.15s ease;
}
input[role="switch"]:checked { background: var(--ok); }
[dir="rtl"] input[role="switch"]:checked::before { transform: translateX(-18px); }

.group { border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px 14px; margin: 0; display: grid; gap: 12px; min-width: 0; }
.group > legend { padding: 0 6px; font-weight: 600; font-size: 0.92rem; }

/* lists */
.list { display: grid; gap: 8px; min-width: 0; }
.list-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px; }
.list-head .field-hint { flex-basis: 100%; }
.count { color: var(--muted); font-size: 0.78rem; background: #eeeae5; border-radius: 999px; padding: 0 8px; }
.list-body { display: grid; gap: 8px; }
.add-btn {
  justify-self: start;
  border: 1px dashed #cbbfb1;
  background: transparent;
  color: var(--brand);
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 0.88rem;
}
.add-btn:hover { background: var(--soft); border-color: var(--gold); }
.icon-btn {
  width: 30px;
  height: 30px;
  display: inline-grid;
  place-items: center;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-size: 1rem;
  line-height: 1;
}
.icon-btn:hover:not(:disabled) { background: #efebe6; color: var(--ink); }
.icon-btn.is-danger:hover:not(:disabled) { background: var(--bad-bg); color: var(--bad); }
.item-actions { display: inline-flex; gap: 2px; align-items: center; }

.lines { grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.line { display: flex; gap: 4px; align-items: center; }
.line > :first-child { flex: 1; min-width: 0; }

.rows .row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: end;
  padding: 10px;
  background: var(--soft);
  border: 1px solid var(--line);
  border-radius: 10px;
}
.rows .cell { flex: 1 1 160px; min-width: 0; display: grid; gap: 4px; }
.rows .cell:has(.pair) { flex: 2 1 320px; }
.cell-label { font-size: 0.75rem; color: var(--muted); font-weight: 500; }
.row-actions { display: flex; gap: 2px; padding-bottom: 4px; }

.cards { gap: 8px; }
.item { border: 1px solid var(--line); border-radius: 10px; background: var(--soft); min-width: 0; }
.item[open] { background: #fff; }
.item > summary {
  list-style: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
}
.item > summary::-webkit-details-marker { display: none; }
.item[open] > summary::before { transform: rotate(-135deg); }
.item[open] > summary { border-bottom: 1px solid var(--line); }
.item-index {
  flex: none;
  width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
  border-radius: 6px;
  background: #eeeae5;
  font-size: 0.78rem;
  color: var(--muted);
}
.item-title { font-weight: 500; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-meta { color: var(--muted); font-size: 0.8rem; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; direction: ltr; flex: 1; text-align: end; }
.item-body { padding: 14px; display: grid; gap: 16px; }

/* customiser copy table */
.copy-table { display: grid; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.copy-row { display: grid; grid-template-columns: 170px minmax(0, 1fr) minmax(0, 1fr); gap: 8px; align-items: center; padding: 6px 10px; border-top: 1px solid var(--line); }
.copy-row:first-child { border-top: 0; }
.copy-row.is-head { background: var(--soft); font-size: 0.78rem; font-weight: 600; color: var(--muted); padding-block: 8px; }
.copy-key { font-size: 0.85rem; color: var(--muted); }

/* preview */
.preview-col {
  position: sticky;
  top: 70px;
  display: grid;
  gap: 8px;
  min-width: 0;
  height: calc(100vh - 90px);
  grid-template-rows: auto auto minmax(0, 1fr);
}
.preview-bar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.preview-note { margin: 0; color: var(--muted); font-size: 0.8rem; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: var(--card); }
.seg button { border: 0; background: transparent; padding: 5px 12px; font-size: 0.86rem; color: var(--muted); }
.seg button + button { border-inline-start: 1px solid var(--line); }
.seg button[aria-pressed="true"] { background: var(--brand); color: #fff; }
.preview-stage {
  position: relative;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  box-shadow: var(--shadow);
}
.preview-stage.is-mobile { background: #ebe6e0; }
.preview-stage iframe { display: block; border: 0; background: #fff; transform-origin: top right; }
[dir="ltr"] .preview-stage iframe { transform-origin: top left; }

/* login */
.login-body { min-height: 100vh; display: grid; place-items: center; padding: 32px 16px; }
.login-card {
  width: min(400px, 100%);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 28px 24px 24px;
}
.login-card h1 { margin-top: 14px; font-size: 1.5rem; }
.login-card > p { margin: 6px 0 18px; color: var(--muted); }
.login-card form { display: grid; gap: 14px; }
.login-card .btn { width: 100%; margin-top: 4px; }

@media (max-width: 1200px) {
  .workspace.has-preview { grid-template-columns: minmax(0, 1fr); }
  .workspace.has-preview .preview-col { order: -1; position: static; height: 520px; }
}

@media (max-width: 860px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .sidebar { position: static; height: auto; padding: 14px 16px; gap: 12px; }
  .sidebar nav { flex-direction: row; overflow-x: auto; gap: 4px; }
  .sidebar nav a { white-space: nowrap; }
  .nav-label, .logout { display: none; }
  .canvas { padding: 20px 16px 72px; }
  .top { display: grid; gap: 12px; }
  .toolbar .note { width: 100%; order: 10; }
  .toolbar-end { margin-inline-start: 0; }
  .script-list li, .history li { display: grid; }
  .script-actions { flex-wrap: wrap; }
  .pair { grid-template-columns: 1fr; }
  .copy-row { grid-template-columns: 1fr; }
  .copy-row.is-head { display: none; }
  .stats { grid-template-columns: 1fr 1fr; }
}
@media (prefers-reduced-motion: reduce) {
  input[role="switch"]::before { transition: none; }
}
