*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: var(--fs-m);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
:lang(fa) body, html[lang="fa"] body { line-height: 1.75; }
h1, h2, h3, p, dl, dd, ol, ul { margin: 0; padding: 0; }
ol, ul { list-style: none; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
svg { display: block; }
a { color: var(--accent); }

:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

.ltr { direction: ltr; unicode-bidi: isolate; display: inline-block; }
.num { font-variant-numeric: tabular-nums; }
.visually-hidden {
  position: absolute !important; width: 1px; height: 1px; margin: -1px; padding: 0;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ---------- app frame ---------- */
.app { min-height: 100dvh; display: flex; flex-direction: column; }

.header {
  position: sticky; top: 0; z-index: 30;
  background: var(--header-bg); color: var(--header-ink);
  height: var(--header-h);
}
/* the one decorative device: a dashed lane line under the header */
.header::after {
  content: ""; position: absolute; inset-inline: 0; bottom: 0; height: 2px;
  background: repeating-linear-gradient(90deg, rgba(255,255,255,.5) 0 22px, transparent 22px 40px);
}
.header__inner {
  height: 100%; width: min(1560px, 100%); margin-inline: auto;
  padding-inline: clamp(12px, 2.4vw, 32px);
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
}
.brand { display: flex; align-items: center; gap: 12px; color: inherit; text-decoration: none; min-width: 0; border-radius: var(--r-m); }
.brand:focus-visible { outline-color: #fff; }
.brand { min-width: 36px; }        /* the logo keeps its place however crowded the header is */
.brand__mark { flex: none; width: 36px; height: 36px; display: grid; place-items: center; border-radius: 9px; background: #fff;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, .25), 0 1px 3px rgba(0, 0, 0, .3); }
.brand__mark img { display: block; width: 28px; height: 28px; object-fit: contain; }
.brand__text { display: flex; flex-direction: column; min-width: 0; line-height: 1.25; }
.brand__text strong { font-size: var(--fs-m); font-weight: 650; letter-spacing: -.005em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand__text span { font-size: var(--fs-xs); color: var(--header-ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.header__actions { display: flex; align-items: center; gap: 10px; flex: none; }

.lang { display: inline-flex; background: rgba(255,255,255,.08); border-radius: var(--r-m); padding: 3px; }
.lang__opt {
  border: 0; background: transparent; color: var(--header-ink-2); height: 30px; min-width: 44px; padding-inline: 10px;
  border-radius: 6px; font-size: var(--fs-s); font-weight: 550;
}
.lang__opt[aria-pressed="true"] { background: var(--header-ink); color: #1a2126; }
.lang__opt:focus-visible { outline-color: #fff; }

.layout {
  width: min(1560px, 100%); margin-inline: auto; flex: 1;
  padding: 20px clamp(12px, 2.4vw, 32px) 64px;
  display: grid; grid-template-columns: minmax(0, 1fr); gap: 20px; align-items: start;
}
.content { display: grid; gap: 16px; min-width: 0; }

@media (min-width: 1120px) {
  .layout { grid-template-columns: minmax(0, 1fr) var(--rail-w); }
}

/* ---------- controls ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 38px; padding-inline: 14px; border-radius: var(--r-m);
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink);
  font-size: var(--fs-s); font-weight: 550; white-space: nowrap;
  transition: background-color .12s, border-color .12s;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn--primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn--primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.header .btn--primary:focus-visible { outline-color: #fff; }
.btn--quiet { border-color: transparent; background: transparent; color: var(--ink-2); }
.btn--quiet:hover { background: var(--surface-3); color: var(--ink); }
.btn--danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn--danger:hover { filter: brightness(1.08); background: var(--danger); }
.btn svg { width: 18px; height: 18px; flex: none; }

.icon-btn {
  display: inline-grid; place-items: center; width: 36px; height: 36px; padding: 0;
  border: 1px solid transparent; background: transparent; color: var(--ink-2); border-radius: var(--r-m);
}
.icon-btn:hover { background: var(--surface-3); color: var(--ink); }
.icon-btn svg { width: 19px; height: 19px; }
.header .icon-btn { color: var(--header-ink); }
.header .icon-btn:hover { background: rgba(255,255,255,.1); color: #fff; }
.header .icon-btn:focus-visible { outline-color: #fff; }

.input {
  width: 100%; height: 40px; padding-inline: 12px; border-radius: var(--r-m);
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink);
}
textarea.input { height: auto; min-height: 84px; padding-block: 9px; resize: vertical; line-height: 1.6; }
.input::placeholder { color: var(--ink-3); }
.input:hover { border-color: var(--ink-3); }
.input:focus-visible { outline: 2px solid var(--focus); outline-offset: 0; border-color: var(--focus); }
select.input { appearance: none; padding-inline-end: 34px; background-repeat: no-repeat; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}

/* the header folds its buttons to icons (their titles stay as tooltips) as the window narrows, so it never spills
   sideways: first the secondary ones, then all of them; the title shortens with an ellipsis last */
@media (max-width: 1360px) {
  .header .hdr-sec span { display: none; }
  .header .hdr-sec { padding-inline: 0; width: 38px; }
}
@media (max-width: 960px) {
  .brand__text span { display: none; }
  .header .btn span { display: none; }
  .header .btn { padding-inline: 0; width: 38px; }
  .header__actions { gap: 6px; }
  .header__inner { gap: 10px; }
  .brand { flex: 1 1 0; }
  .brand__text strong { overflow: hidden; text-overflow: ellipsis; }
}

@media (max-width: 640px) {
  :root { --header-h: 56px; }
  .brand__text span { display: none; }
  .brand__text strong { white-space: nowrap; font-size: var(--fs-m); }
  .header .btn span { display: none; }
  .header .btn { padding-inline: 0; width: 38px; }
  .header__actions { gap: 4px; flex: none; }
  .header__inner { gap: 8px; }
  .brand { flex: 1 1 0; gap: 8px; }
  .brand__text strong { overflow: hidden; text-overflow: ellipsis; }
  .lang__opt { min-width: 34px; padding-inline: 7px; height: 28px; font-size: var(--fs-xs); }
  .header .icon-btn { width: 34px; }
  .header .btn { width: 34px; height: 34px; }
}

/* the hidden attribute must always win over component display rules */
[hidden] { display: none !important; }
