:root {
  --ink: #172033;
  --indigo: #243056;
  --indigo-2: #1b2544;
  --stitch: #c4a574;
  --paper: #eef1f4;
  --card: #ffffff;
  --line: #d5dbe3;
  --muted: #5c6778;
  --ok: #1f7a4d;
  --bad: #8d2f2f;
  --draft: #8a5a12;
  --shadow: 0 18px 40px rgba(23, 32, 51, 0.08);
  --display: "Readex Pro", "IBM Plex Sans Arabic", sans-serif;
  --body: "IBM Plex Sans Arabic", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--paper);
  color: var(--ink);
  font-family: var(--body);
  font-size: 16px;
  line-height: 1.6;
}
h1, h2, .brand b { font-family: var(--display); font-weight: 600; letter-spacing: 0; }
h1 { font-size: 2rem; line-height: 1.25; margin: 0; }
h2 { font-size: 1.15rem; margin: 0 0 6px; }
a { color: inherit; }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--indigo); outline-offset: 3px; }

.mark { display: inline-flex; gap: 6px; align-items: center; }
.mark i {
  width: 16px; height: 16px; border-radius: 999px; display: block;
  box-shadow: 0 0 0 1px rgba(23, 32, 51, 0.25), inset 0 0 0 2px #fff;
}
.mark i:nth-child(1) { background: #f4f1ea; }
.mark i:nth-child(2) { background: #1c2740; }
.mark i:nth-child(3) { background: var(--stitch); }

.shell { display: grid; grid-template-columns: 272px minmax(0, 1fr); min-height: 100vh; align-items: start; }
.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  overflow: auto;
  background: var(--indigo);
  color: #f4f6f8;
  padding: 28px 18px;
  display: flex;
  flex-direction: column;
  gap: 22px;
}
.brand { display: flex; gap: 12px; align-items: center; text-decoration: none; }
.brand b { display: block; font-size: 1.35rem; line-height: 1; }
.brand small { color: #c5ceda; }
.sidebar nav { display: flex; flex-direction: column; gap: 4px; }
.sidebar nav a {
  text-decoration: none;
  padding: 8px 10px;
  border-radius: 10px;
  color: #d5deea;
}
.sidebar nav a[aria-current="page"], .sidebar nav a:hover { background: rgba(255,255,255,.08); color: white; }
.logout { margin-top: auto; }
.logout button {
  width: 100%;
  background: transparent;
  color: #d5deea;
  border: 1px solid rgba(255,255,255,.18);
  border-radius: 10px;
  padding: 8px 10px;
}

.canvas { width: min(1040px, 100%); margin-inline: auto; padding: 36px 32px 80px; }
.top { display: flex; justify-content: space-between; gap: 24px; align-items: flex-end; margin-bottom: 22px; }
.eyebrow { margin: 0 0 6px; color: var(--muted); font-size: 0.92rem; }
.eyebrow a { color: var(--indigo); }
.lede { margin: 8px 0 0; max-width: 62ch; color: var(--muted); }
.live { margin: 0; text-align: center; }
.live b { display: block; font-family: var(--display); font-size: 2.4rem; line-height: 1; }
.live span { color: var(--muted); font-size: 0.9rem; }

.banner {
  background: #fff;
  border: 1px solid var(--line);
  border-inline-start: 3px solid var(--stitch);
  border-radius: 12px;
  padding: 12px 14px;
  margin: 0 0 18px;
}
.banner.is-ok { border-inline-start-color: var(--ok); }
.banner.is-bad { border-inline-start-color: var(--bad); color: var(--bad); }

.install, .account, .copy-fields, .group, .field, .history li, .script-list li {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
}
.install { padding: 18px; margin-bottom: 22px; }
.install textarea, .install.slim textarea, textarea, input, select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  background: #fbfcfd;
}
textarea { resize: vertical; }
.install textarea { direction: ltr; text-align: left; font-family: ui-monospace, monospace; font-size: 12.5px; }

.primary, .ghost {
  border-radius: 999px;
  padding: 9px 16px;
  border: 1px solid transparent;
}
.primary { background: var(--indigo); color: white; }
.ghost { background: white; border-color: var(--line); }

.script-list, .history { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 12px; }
.script-list li, .history li {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 18px;
  align-items: center;
}
.script-list a { text-decoration: none; display: flex; flex-direction: column; gap: 4px; }
.script-list a span, .history span, .history small { color: var(--muted); }
.meta { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.pip {
  font-style: normal;
  font-size: 0.82rem;
  border-radius: 999px;
  padding: 2px 8px;
  background: #eef1f4;
}
.pip.is-on { background: #e5f5ec; color: var(--ok); }
.pip.is-draft { background: #f8f1e4; color: var(--draft); }
.account { margin-top: 28px; padding: 8px 16px 16px; }
.account form, .copy-fields { display: grid; gap: 12px; }
label { display: grid; gap: 6px; font-size: 0.92rem; }
label > span { color: var(--muted); font-size: 0.8rem; }
.account form { max-width: 420px; margin-top: 10px; }

.toolbar, .editor-tools { display: flex; flex-wrap: wrap; gap: 8px; align-items: end; margin-bottom: 16px; }
.toolbar .note { min-width: min(280px, 100%); }
[data-status] { color: var(--muted); font-size: 0.92rem; }
.install.slim { margin-top: 22px; padding: 12px 16px; }

.section {
  margin: 0 0 18px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 0;
  overflow: hidden;
}
.section > summary,
.group > summary,
.field[data-item] > details > summary {
  list-style: none;
  cursor: pointer;
}
.section > summary::-webkit-details-marker,
.group > summary::-webkit-details-marker,
.field[data-item] > details > summary::-webkit-details-marker { display: none; }
.section > summary { padding: 16px 18px; }
.section > summary h2 {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 0;
}
.section > summary h2::after,
.group > summary b::before,
.field[data-item] > details > summary b::before {
  content: "";
  width: 8px;
  height: 8px;
  border-inline-end: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(45deg);
  flex: none;
}
.section[open] > summary h2::after,
.group[open] > summary b::before,
.field[data-item] > details[open] > summary b::before {
  transform: rotate(-135deg);
}
.section > summary .hint { margin: 4px 0 0; }
.section > .kids,
.copy-fields.section > :not(summary) { padding: 0 18px; }
.section > .kids { padding-bottom: 8px; }
.group { padding: 0; }
.group > summary {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
}
.group > summary b { display: inline-flex; align-items: center; gap: 8px; margin-inline-end: auto; }
.group > summary .swatch-row { margin: 0; min-height: 0; }
.group > summary .item-actions { margin-inline-start: auto; }
.group-body { padding: 0 16px 16px; }
.field[data-item] > details > summary.item-head { margin: 0; padding: 12px 14px; }
.field[data-item] > details > summary b { display: inline-flex; align-items: center; gap: 8px; }
.field[data-item] > details > .kids { padding: 0 14px 14px; }
.copy-fields.section { padding: 0 0 8px; }
.section .hint, .field-hint { margin: 0 0 12px; color: var(--muted); font-size: 0.9rem; }
.field-hint { margin: 2px 0 0; font-size: 0.82rem; font-weight: 400; }
.stack { display: grid; gap: 12px; }
.field { padding: 14px; }
.field header, .item-head { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; margin-bottom: 8px; }
.field header b, .item-head b { font-weight: 600; }
.field[data-kind="bilingual"],
.field[data-kind="locale-map"] {
  background: transparent;
  border: 0;
  box-shadow: none;
  border-radius: 0;
  padding: 12px 0;
}
.field[data-kind="bilingual"] { border-bottom: 1px solid var(--line); }
.field[data-kind="locale-map"] > .kids { gap: 0; }
.section .field {
  background: transparent;
  border: 0;
  box-shadow: none;
  padding: 4px 0 14px;
}
.section .field[data-item] {
  background: #fbfcfd;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px;
}
.pair { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.pair > label > span, .lang > span {
  display: block;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 600;
  margin-bottom: 4px;
}
.ltr { direction: ltr; text-align: left; }
.checks { display: flex; align-items: center; gap: 8px; }
.checks input { width: auto; }
.item-actions { display: flex; gap: 6px; }
.item-actions button, .add { border: 0; background: transparent; color: var(--indigo); padding: 4px 6px; }
.matrix { overflow: auto; margin-bottom: 8px; }
.matrix table { border-collapse: collapse; width: 100%; min-width: 720px; }
.matrix th, .matrix td { border-bottom: 1px solid var(--line); padding: 8px; text-align: center; font-weight: 500; vertical-align: bottom; }
.matrix th.band { text-align: right; white-space: nowrap; }
.matrix .cell { display: grid; gap: 6px; min-width: 84px; }
.matrix .cell span { color: var(--muted); font-size: 0.72rem; font-weight: 600; }
.matrix input { width: 100%; text-align: center; padding: 6px 8px; }

.group { padding: 16px; margin-bottom: 16px; }
.swatch-row { display: flex; gap: 10px; align-items: center; min-height: 42px; margin: 8px 0 14px; }
.swatch-row button {
  width: 34px; height: 34px; border-radius: 999px; padding: 0;
  border: 1px solid rgba(0,0,0,.14);
  box-shadow: inset 0 0 0 2px #fff;
  background-size: cover;
  background-position: center;
}
.swatch-row button[aria-current="true"] { box-shadow: 0 0 0 2px var(--ink), inset 0 0 0 2px #fff; }
.color-grid { display: grid; gap: 12px; }
.color-card { border: 1px solid var(--line); border-radius: 14px; padding: 12px; display: grid; gap: 10px; }
.color-line { display: grid; grid-template-columns: minmax(140px, 180px) 1fr 1fr minmax(140px, 180px); gap: 10px; align-items: end; }
.hex { display: flex; gap: 8px; align-items: center; }
.hex input[type="color"] { width: 42px; height: 42px; padding: 0; border: 0; background: transparent; }
.add-group { margin-bottom: 22px; }
.copy-fields { padding: 16px; }
.warn { color: var(--draft); margin: 0; font-size: 0.92rem; }
.extra summary { cursor: pointer; color: var(--indigo); }
.extra .pair { margin-top: 10px; }

.login-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 32px 16px;
  background:
    radial-gradient(ellipse at 100% 0%, rgba(196, 165, 116, 0.22), transparent 46%),
    var(--paper);
}
.login-card {
  width: min(420px, 100%);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 20px;
  box-shadow: var(--shadow);
  padding: 28px 24px 24px;
}
.login-card h1 { margin-top: 16px; }
.login-card > p { margin: 8px 0 18px; color: var(--muted); }
.login-card form { display: grid; gap: 14px; }
.login-card .primary { width: 100%; margin-top: 4px; }

@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; overflow: visible; }
  .sidebar nav { flex-direction: row; flex-wrap: nowrap; overflow: auto; }
  .sidebar nav a { white-space: nowrap; }
  .logout { display: none; }
  .canvas { padding: 20px 16px 88px; }
  .toolbar {
    position: sticky;
    bottom: 0;
    z-index: 3;
    background: var(--paper);
    padding: 10px 0;
  }
  .script-list li, .history li, .color-line, .pair { display: grid; grid-template-columns: 1fr; }
  .top { display: block; }
}
@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto; }
}
