/* Templates gallery and editor (shares tokens with styles.css) */
.nav-links a[aria-current="page"] { color: var(--ink); text-decoration: underline; text-underline-offset: 6px; text-decoration-color: var(--pencil); text-decoration-thickness: 2px; }
.btn-sm { min-height: 36px; padding: 0 14px; font-size: .9rem; }

.t-hero { padding: clamp(36px, 6vw, 70px) 0 26px; }
.t-hero h1 { font-size: clamp(2rem, 1.3rem + 2.6vw, 3.2rem); font-weight: 700; line-height: 1.08; max-width: 20ch; }
html[lang="ar"] .t-hero h1 { line-height: 1.35; }
.t-search { position: relative; margin-top: 26px; max-width: 640px; }
.t-search svg { position: absolute; inset-inline-start: 16px; top: 50%; translate: 0 -50%; width: 20px; color: var(--muted); }
.t-search input { width: 100%; height: 54px; padding-inline: 48px 110px; font: 400 1.05rem var(--sans); color: var(--ink);
  border: 1px solid var(--line); border-radius: 12px; background: var(--paper); box-shadow: var(--shadow-sheet); }
.t-search input:focus { outline: 2px solid var(--pencil); border-color: transparent; }
.t-count { position: absolute; inset-inline-end: 16px; top: 50%; translate: 0 -50%; color: var(--muted); font-size: .9rem; }

.gallery { padding: 10px 0 80px; }
.gallery-in { display: grid; grid-template-columns: 230px 1fr; gap: 32px; align-items: start; }
.cats { position: sticky; top: 84px; display: grid; gap: 2px; }
.cat { display: flex; justify-content: space-between; gap: 8px; text-align: start; font: 500 .95rem var(--sans); color: var(--muted);
  background: none; border: 0; border-radius: 8px; padding: 9px 12px; cursor: pointer; }
.cat:hover { background: var(--paper); color: var(--ink); }
.cat[aria-pressed="true"] { background: var(--paper); color: var(--ink); font-weight: 600; box-shadow: inset 3px 0 0 var(--pencil); }
html[dir="rtl"] .cat[aria-pressed="true"] { box-shadow: inset -3px 0 0 var(--pencil); }
.cat .n { color: var(--muted); font-size: .82rem; font-weight: 400; }
@media (max-width: 860px) {
  .gallery-in { grid-template-columns: 1fr; }
  .cats { position: static; display: flex; overflow-x: auto; gap: 6px; padding-bottom: 6px; }
  .cat { white-space: nowrap; border: 1px solid var(--line); background: var(--paper); }
  .cat[aria-pressed="true"] { box-shadow: none; background: var(--ink); color: var(--paper); }
  .cat .n { display: none; }
}

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(178px, 1fr)); gap: 18px; }
.card { display: grid; gap: 8px; text-align: start; background: none; border: 0; padding: 0; cursor: pointer; font: inherit; color: inherit; }
.card .thumb { position: relative; aspect-ratio: 210 / 297; background: var(--paper); border-radius: 4px; overflow: hidden;
  box-shadow: var(--shadow-sheet); border: 1px solid var(--line); transition: transform .15s, box-shadow .15s; }
.card .thumb.land { aspect-ratio: 210 / 297; display: grid; place-items: center; background: var(--desk-2); }
.card .thumb.land img { height: auto; object-fit: contain; box-shadow: 0 2px 8px rgba(23,33,46,.18); }
.card .thumb img { width: 100%; height: 100%; object-fit: cover; object-position: top; display: block; }
.card:hover .thumb, .card:focus-visible .thumb { transform: translateY(-3px); box-shadow: 0 16px 34px -14px rgba(23,33,46,.35); }
.card .cname { font-weight: 600; font-size: .95rem; line-height: 1.3; }
.card .cmeta { color: var(--muted); font-size: .82rem; display: flex; gap: 8px; flex-wrap: wrap; }
.badge { font-size: .74rem; padding: 2px 7px; border-radius: 5px; background: var(--pencil-wash); color: var(--pencil-ink); }
.badge.ar { background: var(--ok-bg); color: var(--ok); }

/* editor */
body.ed-open { overflow: hidden; }
.editor { position: fixed; inset: 0; z-index: 40; background: var(--desk); display: grid; grid-template-rows: auto 1fr; }
.ed-bar { display: flex; align-items: center; gap: 16px; padding: 12px clamp(16px, 3vw, 32px); background: var(--paper); border-bottom: 1px solid var(--line); }
.ed-bar h2 { font-size: 1.25rem; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ed-lang { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: .9rem; }
.ed-lang select { height: 38px; border: 1px solid var(--line); border-radius: 8px; background: var(--paper); color: var(--ink); font: 500 .95rem var(--sans); padding: 0 8px; }
.ed-body { overflow: auto; display: grid; grid-template-columns: minmax(240px, 360px) 1fr; gap: clamp(18px, 3vw, 40px); padding: clamp(16px, 3vw, 32px); align-items: start; }
.ed-side { position: sticky; top: 0; display: grid; gap: 16px; }
.ed-preview { background: var(--paper); border-radius: 4px; box-shadow: var(--shadow-sheet); border: 1px solid var(--line); overflow: hidden; }
.ed-preview img { width: 100%; display: block; }
.ed-variants h3 { font-size: 1rem; margin-bottom: 8px; }
.variant-row { display: flex; gap: 10px; flex-wrap: wrap; }
.variant { width: 72px; border: 2px solid transparent; border-radius: 5px; padding: 0; background: var(--paper); cursor: pointer; overflow: hidden; }
.variant img { width: 100%; display: block; }
.variant[aria-checked="true"] { border-color: var(--pencil); }
.ed-main { background: var(--paper); border: 1px solid var(--line); border-radius: 14px; padding: clamp(18px, 3vw, 30px); box-shadow: var(--shadow-sheet); min-width: 0; }
@media (max-width: 860px) { .ed-body { grid-template-columns: 1fr; } .ed-side { position: static; } .ed-preview { max-width: 260px; } .ed-lang span { display: none; } }

.field textarea { width: 100%; padding: 10px 12px; font: 400 1rem/1.5 var(--sans); color: var(--ink); border: 1px solid var(--line);
  border-radius: var(--r-ctl); background: var(--paper); resize: vertical; }
.field textarea:focus, .field select:focus { outline: 2px solid var(--pencil); border-color: transparent; }
.field select { height: 42px; border: 1px solid var(--line); border-radius: var(--r-ctl); background: var(--paper); color: var(--ink); font: 400 1rem var(--sans); padding: 0 8px; }
.ai-file { display: flex; align-items: center; gap: 10px; margin: 12px 0 18px; flex-wrap: wrap; }
.ai-file .btn { cursor: pointer; }
.ai-fname { color: var(--ok); font-weight: 600; }
.modes { border: 0; padding: 0; margin: 0 0 20px; display: grid; gap: 8px; }
.modes legend { font-weight: 600; margin-bottom: 8px; }
.modes label { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; cursor: pointer; }
.modes label:has(input:checked) { border-color: var(--pencil); background: var(--pencil-wash); }
.modes input { margin-top: 4px; accent-color: var(--pencil); }
.modes span { display: grid; }
.modes small { color: var(--muted); }
.ai-off { margin: 0 0 8px; padding: 12px 14px; background: var(--warn-bg); color: var(--warn); border-radius: 10px; }
.ai-done { margin: 0; flex: 1; padding: 10px 12px; background: var(--ok-bg); color: var(--ok); border-radius: 8px; }

.form-tools { display: flex; gap: 8px; align-items: center; margin-bottom: 14px; flex-wrap: wrap; justify-content: flex-end; }
#docForm { display: grid; gap: 14px; }
#docForm .f-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 16px; }
#docForm .f-wide { grid-column: 1 / -1; }
@media (max-width: 640px) { #docForm .f-grid { grid-template-columns: 1fr; } }
.f-group { border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px 14px; margin: 0; }
.f-group > legend { font-weight: 600; padding: 0 6px; }
.f-rows { display: grid; gap: 10px; }
.f-row { position: relative; border: 1px dashed var(--line); border-radius: 10px; padding: 12px 14px; background: var(--desk); }
.f-row .row-n { font-weight: 600; color: var(--muted); font-size: .85rem; margin-bottom: 6px; display: flex; justify-content: space-between; }
.row-x { font: 500 .85rem var(--sans); color: var(--mark); background: none; border: 0; cursor: pointer; text-decoration: underline; }
.add-row { justify-self: start; font: 600 .92rem var(--sans); color: var(--pencil-ink); background: none; border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px; cursor: pointer; }
.add-row:hover { border-color: var(--pencil); }
.field input[type="number"], .field input[type="date"] { height: 42px; padding: 0 12px; font: 400 1rem var(--sans); color: var(--ink); border: 1px solid var(--line); border-radius: var(--r-ctl); background: var(--paper); }
.field small.help { color: var(--muted); font-size: .8rem; }

.ed-go { display: flex; flex-wrap: wrap; gap: 16px; align-items: center; justify-content: flex-end; margin-top: 22px; padding-top: 18px; border-top: 1px solid var(--line); }
.t-result { margin-top: 16px; display: flex; gap: 14px; align-items: center; padding: 16px; border-radius: 12px; background: var(--ok-bg); }
.t-result svg { width: 40px; flex: none; }
.t-result .result-actions { margin-top: 8px; }
.t-result:focus { outline: none; }
