/* Layout uses logical properties (inline-start/end, text-align: start) so the
   same rules read correctly in RTL Arabic and LTR English. A hard-coded
   text-align: right reads wrong in the English UI. */
:root {
  --bg: #f4f6f9; --panel: #fff; --ink: #1d2733; --muted: #66727f; --line: #d9dee5;
  --accent: #1f5fa8; --accent-ink: #fff; --danger: #c62828; --warn: #b26a00; --ok: #2e7d32;
  --radius: 8px; --shadow: 0 1px 3px rgba(0,0,0,.08);
  font-family: AccArabic, AccSans, system-ui, sans-serif;
}
html[lang="en"] { font-family: AccSans, AccArabic, system-ui, sans-serif; }
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font-size: 15px; line-height: 1.5; }
a { color: var(--accent); }
h1 { font-size: 1.35rem; margin: 0 0 .75rem; }
h2 { font-size: 1.1rem; margin: 1.25rem 0 .5rem; }
h3 { font-size: 1rem; margin: 1rem 0 .4rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.mono { font-family: AccMono, monospace; }
[hidden] { display: none !important; }

.topbar { display: flex; align-items: center; gap: 1rem; padding: .5rem 1rem; background: #17324f; color: #fff; position: sticky; top: 0; z-index: 20; flex-wrap: wrap; }
.topbar a, .topbar .muted { color: #dbe6f3; }
.brand { display: flex; align-items: center; gap: .5rem; font-weight: 700; text-decoration: none; color: #fff !important; }
#nav { display: flex; gap: .25rem; flex-wrap: wrap; }
#nav a { text-decoration: none; padding: .3rem .6rem; border-radius: 6px; }
#nav a.active, #nav a:hover { background: rgba(255,255,255,.14); color: #fff; }
.topbar-end { margin-inline-start: auto; display: flex; gap: .5rem; align-items: center; }

main { padding: 1rem; max-width: 1400px; margin: 0 auto; }
main:focus { outline: none; }
.loading { padding: 2rem; text-align: center; color: var(--muted); }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; box-shadow: var(--shadow); margin-bottom: 1rem; }
.row { display: flex; gap: 1rem; flex-wrap: wrap; align-items: flex-start; }
.row > .grow { flex: 1 1 320px; min-width: 0; }
.toolbar { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; margin-bottom: .75rem; }
.toolbar .spacer { flex: 1; }

.btn { display: inline-flex; align-items: center; gap: .35rem; border: 1px solid var(--line); background: #fff; color: var(--ink); padding: .45rem .9rem; border-radius: 6px; cursor: pointer; font: inherit; text-decoration: none; }
.btn:hover { border-color: #aab4c0; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.danger { color: var(--danger); border-color: #e7b3b3; }
.btn.ghost { background: transparent; color: inherit; border-color: rgba(255,255,255,.35); }
.btn.small { padding: .2rem .55rem; font-size: .85rem; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.active { background: #e3edf8; border-color: var(--accent); }

label.field { display: flex; flex-direction: column; gap: .2rem; margin-bottom: .6rem; font-size: .9rem; }
label.field > span { color: var(--muted); }
label.field.req > span::after { content: " *"; color: var(--danger); }
label.check { display: flex; gap: .4rem; align-items: center; margin-bottom: .5rem; font-size: .9rem; }
input, select, textarea { font: inherit; padding: .4rem .55rem; border: 1px solid var(--line); border-radius: 6px; background: #fff; color: var(--ink); min-width: 0; }
input[type=number] { width: 7rem; }
input:focus, select:focus, textarea:focus { outline: 2px solid #9cc2ec; border-color: var(--accent); }
input[readonly] { background: #f2f4f7; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 .75rem; }
.grid3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0 .6rem; }

table.data { width: 100%; border-collapse: collapse; background: #fff; }
table.data th, table.data td { padding: .45rem .6rem; border-bottom: 1px solid var(--line); text-align: start; vertical-align: top; }
table.data th { background: #eef2f6; font-weight: 600; font-size: .88rem; position: sticky; top: 0; }
table.data tr:hover td { background: #f8fafc; }
/* Badges are inline elements inside cells; cells themselves keep table-cell
   display (inline-block on a td pulls it out of the column model). */
.badge { display: inline-block; padding: .05rem .5rem; border-radius: 99px; font-size: .78rem; background: #e8edf3; }
.badge.ok { background: #e3f3e5; color: var(--ok); }
.badge.warn { background: #fff1dc; color: var(--warn); }
.badge.err { background: #fde5e5; color: var(--danger); }
.table-wrap { overflow: auto; max-height: 70vh; border: 1px solid var(--line); border-radius: var(--radius); }

.preview { background: repeating-conic-gradient(#eef1f5 0% 25%, #fff 0% 50%) 50% / 16px 16px; border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; display: flex; justify-content: center; align-items: center; min-height: 160px; }
.preview svg { box-shadow: 0 2px 8px rgba(0,0,0,.18); background: #fff; max-width: 100%; height: auto; }
.issues { list-style: none; padding: 0; margin: .5rem 0; }
.issues li { padding: .35rem .6rem; border-radius: 6px; margin-bottom: .3rem; font-size: .88rem; }
.issues li.error { background: #fde5e5; color: #8e1b1b; }
.issues li.warning { background: #fff4e0; color: #7a4a00; }

.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 1rem; }
.card { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: .75rem; display: flex; flex-direction: column; gap: .5rem; }
.card .thumb svg { width: 100%; height: auto; box-shadow: 0 1px 4px rgba(0,0,0,.15); }
.card .title { font-weight: 600; }

#toasts { position: fixed; bottom: 1rem; inset-inline-end: 1rem; display: flex; flex-direction: column; gap: .5rem; z-index: 100; max-width: min(460px, 90vw); }
.toast { background: #17324f; color: #fff; padding: .7rem 1rem; border-radius: 8px; box-shadow: 0 4px 12px rgba(0,0,0,.2); white-space: pre-line; }
.toast.error { background: var(--danger); }
.toast.ok { background: var(--ok); }

.modal-back { position: fixed; inset: 0; background: rgba(10,20,30,.45); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 1rem; }
.modal { background: #fff; border-radius: 10px; padding: 1.25rem; width: min(560px, 100%); max-height: 90vh; overflow: auto; box-shadow: 0 10px 30px rgba(0,0,0,.3); }
.modal.wide { width: min(900px, 100%); }
.modal h2 { margin-top: 0; }
.modal .actions { display: flex; gap: .5rem; justify-content: flex-end; margin-top: 1rem; flex-wrap: wrap; }

.login { max-width: 360px; margin: 10vh auto; }

/* Designer */
.designer { display: grid; grid-template-columns: 170px minmax(0, 1fr) 330px; gap: .75rem; align-items: start; }
@media (max-width: 1100px) { .designer { grid-template-columns: 1fr; } }
.palette { display: flex; flex-direction: column; gap: .35rem; }
.palette .btn { justify-content: flex-start; }
.stage-wrap { background: #dfe4ea; border-radius: var(--radius); padding: 24px; overflow: auto; min-height: 420px; position: relative; }
.stage { position: relative; margin: 0 auto; background: #fff; box-shadow: 0 2px 10px rgba(0,0,0,.2); }
.stage > svg { position: absolute; inset: 0; width: 100%; height: 100%; }
.stage .grid { position: absolute; inset: 0; pointer-events: none; }
.stage .hit { position: absolute; cursor: move; outline: 1px dashed transparent; }
.stage .hit:hover { outline-color: rgba(31,95,168,.5); }
.stage .hit.sel { outline: 2px solid var(--accent); background: rgba(31,95,168,.06); }
.stage .hit .h { position: absolute; width: 10px; height: 10px; background: #fff; border: 2px solid var(--accent); inset-inline-end: -6px; bottom: -6px; cursor: nwse-resize; }
[dir=rtl] .stage .hit .h { cursor: nesw-resize; }
.stage .hit .bind { position: absolute; top: -18px; inset-inline-start: 0; font-size: 11px; background: var(--accent); color: #fff; padding: 0 4px; border-radius: 3px; white-space: nowrap; pointer-events: none; }
.stage .hit .bind.bad { background: var(--danger); }
.props h3 { margin-top: .25rem; }
.props .grid2 label.field, .props .grid3 label.field { margin-bottom: .4rem; }
.props input[type=number] { width: 100%; }
.tabs { display: flex; gap: .25rem; margin-bottom: .6rem; flex-wrap: wrap; }
.tabs .btn { padding: .25rem .6rem; font-size: .85rem; }
.fields-table input { width: 100%; }
.fields-table td { padding: .25rem; }
.kbd { font-family: AccMono, monospace; background: #eef2f6; padding: 0 .3rem; border-radius: 4px; font-size: .85em; }
.notice { background: #eef5fd; border: 1px solid #c7dcf3; border-radius: var(--radius); padding: .6rem .8rem; font-size: .9rem; margin-bottom: .75rem; }
.notice.warn { background: #fff6e6; border-color: #f0d49e; }
