:root {
  --bg: #08132a;
  --bg2: #0d1b36;
  --card: #142a52;
  --card2: #1b3768;
  --line: rgba(212, 175, 95, .22);
  --gold: #d4af5f;
  --gold2: #f0d48f;
  --text: #f3efe2;
  --muted: #b4bfd3;
  --danger: #e2876f;
  --input: #0a1630;
  --radius: 14px;
  --font: "IBM Plex Sans Arabic", system-ui, -apple-system, "Segoe UI", Tahoma, sans-serif;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); font-family: var(--font); }
body {
  min-height: 100vh;
  background:
    radial-gradient(1200px 600px at 100% -10%, rgba(212,175,95,.10), transparent 60%),
    radial-gradient(900px 500px at -10% 110%, rgba(27,55,104,.6), transparent 60%),
    var(--bg);
  background-attachment: fixed;
}
button { font-family: inherit; cursor: pointer; }
[hidden] { display: none !important; }

/* ---------- الشريط العلوي ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 10px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: linear-gradient(180deg, rgba(8,19,42,.98), rgba(8,19,42,.92));
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(8px);
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; flex: 1; }
.brand-logo { width: 46px; height: 46px; flex: none; }
.brand-name { font-weight: 700; font-size: 18px; color: var(--gold2); white-space: nowrap; }
.brand-sub { font-size: 12.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-text { min-width: 0; }
.icon-btn { background: none; border: 0; color: var(--gold2); padding: 6px; border-radius: 10px; display: grid; place-items: center; }
.icon-btn:hover { background: rgba(255,255,255,.06); }
.top-actions { display: flex; gap: 8px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border-radius: 11px; padding: 9px 14px; font-size: 14.5px; font-weight: 600;
  border: 1px solid transparent; transition: transform .06s, filter .15s;
}
.btn:active { transform: scale(.97); }
.btn.gold { background: linear-gradient(180deg, var(--gold2), var(--gold)); color: #1f1606; }
.btn.ghost { background: rgba(255,255,255,.04); color: var(--gold2); border-color: var(--line); }
.btn.wide { width: 100%; padding: 13px; font-size: 16px; }
.btn.small { padding: 6px 10px; font-size: 13px; }
.btn:disabled { opacity: .5; }

/* ---------- الرئيسية ---------- */
.view { max-width: 1280px; margin: 0 auto; padding: 16px; }
.home-section { margin-bottom: 26px; }
.sec-title { font-size: 16px; color: var(--gold2); margin: 6px 2px 12px; font-weight: 600; display: flex; gap: 8px; align-items: center; }
.count { font-size: 12px; color: var(--muted); background: rgba(255,255,255,.06); border-radius: 20px; padding: 1px 9px; }
.tpl-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.tpl-card {
  display: flex; gap: 14px; align-items: stretch; text-align: right;
  background: linear-gradient(160deg, var(--card2), var(--card));
  border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; color: var(--text);
}
.tpl-card:hover { border-color: rgba(212,175,95,.5); }
.tpl-thumb { width: 74px; height: 96px; flex: none; border-radius: 6px; background: #fff; object-fit: cover; object-position: top; box-shadow: 0 2px 8px rgba(0,0,0,.35); }
.tpl-info { display: flex; flex-direction: column; justify-content: center; gap: 6px; min-width: 0; }
.tpl-name { font-weight: 700; font-size: 16px; }
.tpl-desc { font-size: 13px; color: var(--muted); line-height: 1.55; }
.tpl-go { font-size: 13px; color: var(--gold2); font-weight: 600; }

.doc-list { display: flex; flex-direction: column; gap: 8px; }
.doc-item {
  display: flex; align-items: center; gap: 10px; padding: 11px 12px;
  background: rgba(255,255,255,.035); border: 1px solid var(--line); border-radius: 12px;
}
.doc-open { flex: 1; min-width: 0; background: none; border: 0; color: var(--text); text-align: right; padding: 0; }
.doc-title { font-weight: 600; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.doc-meta { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.doc-del { background: none; border: 0; color: var(--danger); padding: 6px; border-radius: 8px; }
.empty { color: var(--muted); font-size: 14px; padding: 14px; text-align: center; border: 1px dashed var(--line); border-radius: 12px; }
.foot { text-align: center; color: var(--muted); font-size: 12px; padding: 20px 0 calc(10px + env(safe-area-inset-bottom)); opacity: .8; }

/* ---------- التعبئة ---------- */
.fill-layout { display: grid; grid-template-columns: minmax(360px, 520px) 1fr; gap: 18px; align-items: start; }
.tabs { display: none; }
.form-pane { min-width: 0; }
.preview-pane { position: sticky; top: 84px; max-height: calc(100vh - 100px); overflow: auto; border-radius: var(--radius); background: rgba(0,0,0,.18); border: 1px solid var(--line); padding: 12px; }
.preview-bar { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 8px; position: sticky; top: 0; z-index: 2; }
.preview-status { font-size: 12.5px; color: var(--muted); }
.zoom { display: inline-flex; align-items: center; gap: 4px; background: var(--input); border: 1px solid var(--line); border-radius: 10px; padding: 3px; flex: none; }
.zoom button { width: 34px; height: 30px; border: 0; border-radius: 8px; background: rgba(255,255,255,.06); color: var(--gold2); font-size: 19px; line-height: 1; }
.zoom span { min-width: 46px; text-align: center; font-size: 13px; color: var(--text); direction: ltr; }
.pages { direction: ltr; display: flex; flex-direction: column; gap: 12px; align-items: center; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.pages.zoomed { align-items: flex-start; }
/* اتجاه الرسم داخل المعاينة يساري دائماً حتى لا تنزاح رموز الفورم مثل ( ✓ ) */
.pages canvas { direction: ltr; }
.pages canvas { flex: none; width: 100%; max-width: 820px; background: #fff; border-radius: 4px; box-shadow: 0 4px 18px rgba(0,0,0,.4); }

.settings-card, .section {
  background: linear-gradient(160deg, rgba(27,55,104,.75), rgba(20,42,82,.75));
  border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 12px;
}
.settings-card { padding: 10px 12px; display: flex; flex-direction: column; gap: 10px; }
.set-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.set-label { font-size: 13.5px; color: var(--muted); min-width: 64px; }
.ink-chips { display: flex; gap: 8px; flex-wrap: wrap; }
.ink-chip { width: 30px; height: 30px; border-radius: 50%; border: 2px solid rgba(255,255,255,.25); padding: 0; position: relative; }
.ink-chip.active { border-color: var(--gold2); box-shadow: 0 0 0 3px rgba(240,212,143,.25); }
.ink-chip.active::after { content: ""; position: absolute; inset: 9px; border-radius: 50%; background: rgba(255,255,255,.85); }

.seg { display: inline-flex; background: var(--input); border: 1px solid var(--line); border-radius: 10px; padding: 3px; gap: 3px; flex-wrap: wrap; }
.seg button { background: none; border: 0; color: var(--muted); padding: 6px 11px; border-radius: 8px; font-size: 13.5px; }
.seg button.active { background: var(--gold); color: #1f1606; font-weight: 600; }

.section > summary {
  list-style: none; display: flex; align-items: center; justify-content: space-between;
  padding: 12px 14px; font-weight: 700; color: var(--gold2); font-size: 15.5px; cursor: pointer; user-select: none;
}
.section > summary::-webkit-details-marker { display: none; }
.section > summary .chev { transition: transform .2s; opacity: .8; }
.section[open] > summary .chev { transform: rotate(180deg); }
.sec-body { padding: 2px 14px 14px; display: grid; grid-template-columns: 1fr 1fr; gap: 10px 10px; }
.sec-note { grid-column: 1 / -1; font-size: 12.5px; color: var(--muted); margin-top: -2px; }

.fld { grid-column: 1 / -1; display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.fld.half { grid-column: auto; }
.fld > label, .fld-label { font-size: 13px; color: var(--muted); }
.fld-label .auto { color: var(--gold); font-size: 11.5px; margin-inline-start: 6px; }
.inp, .fld select {
  width: 100%; background: var(--input); color: var(--text); border: 1px solid rgba(255,255,255,.12);
  border-radius: 10px; padding: 10px 11px; font-size: 16px; font-family: inherit; outline: none; min-width: 0;
}
.inp:focus { border-color: var(--gold); box-shadow: 0 0 0 3px rgba(212,175,95,.18); }
.inp::placeholder { color: rgba(180,191,211,.55); }
.inp.ltr { direction: ltr; text-align: left; }
.inp.digits { direction: ltr; text-align: center; letter-spacing: 3px; font-variant-numeric: tabular-nums; }

.chk { grid-column: 1 / -1; display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 10px; background: rgba(0,0,0,.12); cursor: pointer; user-select: none; }
.chk.indent { margin-inline-start: 22px; background: rgba(0,0,0,.07); }
.chk input { display: none; }
.chk .box { width: 22px; height: 22px; border-radius: 6px; border: 2px solid rgba(255,255,255,.35); display: grid; place-items: center; flex: none; }
.chk input:checked + .box { background: var(--gold); border-color: var(--gold); }
.chk input:checked + .box::after { content: ""; width: 6px; height: 11px; border: solid #1f1606; border-width: 0 2.5px 2.5px 0; transform: rotate(45deg) translate(-1px,-1px); }
.chk span.t { font-size: 15px; }
.fld.indent { margin-inline-start: 22px; }

.date-row { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.date-row .inp { width: 64px; text-align: center; padding: 10px 4px; direction: ltr; }
.date-row .inp.y { width: 82px; }
.date-row .sep { color: var(--muted); }
.date-row .seg button { padding: 6px 9px; }
.mini { background: rgba(255,255,255,.05); color: var(--gold2); border: 1px solid var(--line); border-radius: 8px; padding: 6px 9px; font-size: 12.5px; }

.table-rows { grid-column: 1 / -1; display: flex; flex-direction: column; gap: 10px; }
.row-card { border: 1px solid var(--line); border-radius: 12px; padding: 10px; background: rgba(0,0,0,.12); display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.row-head { grid-column: 1 / -1; display: flex; justify-content: space-between; align-items: center; font-size: 13.5px; color: var(--gold2); font-weight: 600; }
.row-del { background: none; border: 0; color: var(--danger); font-size: 13px; }
.add-row { grid-column: 1 / -1; }

.form-end { display: flex; flex-direction: column; gap: 10px; margin: 18px 0 30px; }

.toast {
  position: fixed; left: 50%; bottom: calc(22px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: #1d1608; color: var(--gold2); border: 1px solid var(--gold); border-radius: 12px; padding: 10px 16px;
  font-size: 14px; z-index: 50; box-shadow: 0 8px 24px rgba(0,0,0,.45); max-width: calc(100vw - 32px);
}

/* ---------- الجوال ---------- */
@media (max-width: 900px) {
  .view { padding: 12px 16px; }
  .fill-layout { grid-template-columns: 1fr; }
  .tabs {
    display: flex; position: sticky; top: var(--hdr, 64px); z-index: 10; gap: 4px; margin: -12px -16px 12px;
    background: rgba(8,19,42,.97); border-bottom: 1px solid var(--line); padding: 8px 16px; backdrop-filter: blur(8px);
  }
  .tab { flex: 1; background: var(--input); border: 1px solid var(--line); color: var(--muted); padding: 9px; border-radius: 10px; font-size: 15px; font-weight: 600; }
  .tab.active { background: var(--gold); border-color: var(--gold); color: #1f1606; }
  .fill-layout[data-tab="form"] .preview-pane { display: none; }
  .fill-layout[data-tab="preview"] .form-pane { display: none; }
  .preview-pane { position: static; max-height: none; padding: 8px; }
  .top-actions .btn span { display: none; }
  .top-actions .btn { padding: 9px 11px; }
  .brand-logo { width: 40px; height: 40px; }
  .brand-name { font-size: 16.5px; }
}
@media (max-width: 420px) {
  .sec-body, .row-card { grid-template-columns: 1fr; }
  .fld.half { grid-column: 1 / -1; }
}

.about { text-align: center; margin: 4px 0 0; padding: 18px 16px; border: 1px solid var(--line); border-radius: var(--radius);
  background: linear-gradient(160deg, rgba(27,55,104,.55), rgba(20,42,82,.55)); }
.about img { width: 64px; height: 64px; }
.about .a-name { font-weight: 700; color: var(--gold2); font-size: 16px; margin-top: 6px; }
.about .a-line { font-size: 14px; color: var(--text); margin-top: 6px; }
.about .a-line a { color: var(--gold2); text-decoration: none; direction: ltr; unicode-bidi: isolate; }
.about .a-copy { font-size: 12.5px; color: var(--muted); margin-top: 10px; }

.switch-row { grid-column: 1 / -1; display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 12px; border-radius: 12px; background: rgba(0,0,0,.16); border: 1px solid var(--line); cursor: pointer; user-select: none; }
.switch-row .t { font-size: 15.5px; font-weight: 600; }
.switch-row input { display: none; }
.switch-row .sw { width: 50px; height: 30px; border-radius: 30px; background: rgba(255,255,255,.18); position: relative; flex: none; transition: background .2s; }
.switch-row .sw::after { content: ""; position: absolute; top: 3px; right: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; transition: transform .2s; box-shadow: 0 1px 3px rgba(0,0,0,.4); }
.switch-row input:checked + .sw { background: var(--gold); }
.switch-row input:checked + .sw::after { transform: translateX(-20px); }

.lang-switch { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; user-select: none; }
.lang-switch input { display: none; }
.lang-switch .ls { font-size: 14px; color: var(--muted); }
.lang-switch[data-v="ar"] .ls-ar, .lang-switch[data-v="en"] .ls-en { color: var(--gold2); font-weight: 700; }
.lang-switch .sw { width: 50px; height: 30px; border-radius: 30px; background: var(--gold); position: relative; flex: none; }
.lang-switch .sw::after { content: ""; position: absolute; top: 3px; right: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; transition: transform .2s; box-shadow: 0 1px 3px rgba(0,0,0,.4); }
.lang-switch input:checked + .sw::after { transform: translateX(-20px); }

.photo-row { display: flex; gap: 14px; align-items: flex-start; }
.photo-thumb { width: 96px; height: 128px; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); background: #fff; flex: none; }
.photo-thumb.empty { display: grid; place-items: center; background: var(--input); color: var(--muted); font-size: 12px; text-align: center; padding: 6px; }
.photo-actions { display: flex; flex-direction: column; gap: 8px; min-width: 0; flex: 1; }
.btn.danger { color: var(--danger); border-color: rgba(226,135,111,.4); }

.en-word { font-family: "IBM Plex Sans Arabic", system-ui, sans-serif; font-weight: 700; letter-spacing: .08em; direction: ltr; unicode-bidi: isolate; }

textarea.inp { resize: vertical; min-height: 90px; line-height: 1.6; }
