/* Page styles owned by the admin-intake screens. Use tokens from tokens.css; prefer component classes (js/components/README.md). */

.ai-ltr .input, input.ai-ltr, .ai-ltr input { direction: ltr; text-align: right; }
.ai-cell-main { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.ai-cell-main__title { font-weight: var(--fw-semibold); color: var(--text); }
.ai-cell-main__sub { font-size: var(--fs-xs); color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 320px; }
.ai-dirty { display: inline-flex; align-items: center; gap: 4px; font-size: var(--fs-xs); color: var(--warning-text); }
.ai-clean { display: inline-flex; align-items: center; gap: 4px; font-size: var(--fs-xs); color: var(--success-text); }
.ai-savebar { margin-top: var(--space-5); padding-top: var(--space-4); border-top: 1px solid var(--border-subtle); }
.ai-savebar .ai-dirty { margin-inline-end: auto; }

/* ── clients list ──────────────────────────────────────────────────────────────────────── */
.ai-kpis { margin-bottom: var(--space-5); }
@media (max-width: 479.98px) {
  .ai-kpis.kpi-grid--4 { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-3); }
  .ai-kpis .kpi__icon { display: none; }
}
.ai-table-card > .card__body { overflow: hidden; border-radius: inherit; }
/* Work-around: components.css `.card > .card__body:first-child` out-ranks `.card--flush > .card__body` (20px gap on header-less flush cards). */
.card--flush.ai-table-card > .card__body:first-child,
.card--flush.ai-types__card > .card__body:first-child,
.card--flush.ai-editor-card > .card__body:first-child { padding-top: 0; }
.ai-table-card .datatable__frame { border: 0; border-radius: 0; box-shadow: none; border-top: 1px solid var(--border-subtle); }
.ai-toolbar { padding: var(--space-4) var(--space-5) var(--space-3); margin: 0; }
.ai-usage { display: flex; flex-direction: column; gap: 4px; min-width: 110px; }
/* "New office" modal: the four payment-status cards as a 2×2 grid (auto-fill gave 3 + an orphan). */
.ai-create .radio-group--cards .radio-group__options { grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (max-width: 479.98px) { .ai-create .radio-group--cards .radio-group__options { grid-template-columns: minmax(0, 1fr); } }
@media (max-width: 767.98px) {
  .ai-toolbar { padding: var(--space-3) var(--space-4); }
  .ai-toolbar .toolbar__search { max-width: none; flex-basis: 100%; }
  .ai-toolbar .toolbar__filters { width: 100%; overflow-x: auto; }
}

/* ── client detail ─────────────────────────────────────────────────────────────────────── */
.ai-stats { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-2); }
.ai-stats li { display: flex; align-items: center; justify-content: space-between; gap: var(--space-2); padding: 8px var(--space-3); border-radius: var(--radius-sm); background: var(--surface-2); font-size: var(--fs-sm); color: var(--text-muted); }
.ai-stats li strong { color: var(--text); font-size: var(--fs-md); }
.ai-stats li.tone-warning strong { color: var(--warning-text); }
.ai-stats li.tone-danger strong { color: var(--danger-text); }
.ai-stats li.tone-success strong { color: var(--success-text); }
.ai-stats li.tone-primary strong { color: var(--primary-text); }
.ai-month { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-2); margin-top: var(--space-3); padding-top: var(--space-3); border-top: 1px solid var(--border-subtle); }
.ai-month > div { display: flex; flex-direction: column; }
.ai-users { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.ai-users li { display: flex; align-items: flex-start; gap: var(--space-3); padding: 10px 0; border-top: 1px solid var(--border-subtle); }
.ai-users li:first-child { border-top: 0; padding-top: 0; }
.ai-users__main { display: flex; flex-direction: column; min-width: 0; }
.ai-users__name { font-weight: var(--fw-semibold); font-size: var(--fs-sm); }
.ai-users__sub { font-size: var(--fs-xs); color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ai-users__sub.ltr { text-align: right; }
.ai-key { display: flex; flex-direction: column; gap: 2px; padding: var(--space-3); border-radius: var(--radius-md); background: var(--surface-2); border: 1px solid var(--border-subtle); }
.ai-key code { font-family: var(--font-mono); font-size: var(--fs-sm); text-align: right; }

/* ── delivery types ────────────────────────────────────────────────────────────────────── */
.ai-types__card > .card__body { overflow: hidden; border-radius: inherit; }
.ai-types__scroll { overflow-x: auto; border-top: 1px solid var(--border-subtle); }
.ai-types__table { min-width: 880px; }
.ai-types__table td, .ai-types__table th[scope="row"] { vertical-align: top; padding-block: 12px; }
.ai-types__table tbody th[scope="row"] { text-align: start; font-weight: var(--fw-semibold); color: var(--text); white-space: normal; position: static; background: transparent; border-bottom: 1px solid var(--border-subtle); font-size: var(--fs-sm); padding-inline: var(--space-4); }
.ai-types__table tbody tr:last-child th { border-bottom: 0; }
.ai-types__table .field { margin: 0; }
.ai-type__name { display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap; padding-top: 6px; }
.ai-type__sub { display: block; margin-top: 2px; font-size: var(--fs-2xs); font-weight: var(--fw-regular); color: var(--text-subtle); }
.ai-type__tpl { display: inline-block; margin-top: 4px; font-size: var(--fs-2xs); font-family: var(--font-mono); color: var(--text-muted); text-decoration: none; }
.ai-type__tpl:hover { color: var(--primary-text); text-decoration: underline; }
.ai-type.is-inactive th[scope="row"] .ai-type__name > span:first-child { color: var(--text-muted); }
.ai-type td.align-center { text-align: center; padding-top: 18px; }
.ai-type td.align-center .switch, .ai-type td.align-center label { justify-content: center; }
.ai-type__state { display: block; min-height: 20px; margin-top: 4px; }
.ai-saved { display: inline-flex; align-items: center; gap: 4px; font-size: var(--fs-xs); white-space: nowrap; }
input.ai-num { width: 96px; }
.ai-types__table .select, .ai-types__table select { min-width: 150px; }
.ai-types__table td[data-label="תצהיר"] .select, .ai-types__table td[data-label="תצהיר"] select { min-width: 180px; }
.ai-type__name > span:first-child { white-space: nowrap; }
/* Fit the grid beside the sidebar at 1280: two-line headers for the long labels, tighter cell padding. */
@media (min-width: 768px) {
  .ai-types__table thead th { white-space: normal; vertical-align: bottom; line-height: 1.3; }
  .ai-types__table thead th:nth-child(3) { max-width: 96px; }
  .ai-types__table thead th:nth-child(6) { max-width: 72px; }
  .ai-types__table td { padding-inline: 10px; }
}
@media (max-width: 767.98px) {
  .ai-types__table { min-width: 0; }
  .ai-types__table thead { display: none; }
  .ai-types__table tbody tr { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: var(--space-3); padding: var(--space-4); border-bottom: 1px solid var(--border-subtle); }
  .ai-types__table tbody tr:last-child { border-bottom: 0; }
  .ai-types__table tbody th[scope="row"], .ai-types__table td { display: block; padding: 0 !important; border: 0 !important; }
  .ai-types__table tbody th[scope="row"] { grid-column: 1 / -1; }
  .ai-types__table td::before { content: attr(data-label); display: block; margin-bottom: 4px; font-size: var(--fs-2xs); color: var(--text-muted); }
  .ai-types__table td[data-label="אישור מסירה"], .ai-types__table td[data-label="תצהיר"] { grid-column: 1 / -1; }
  .ai-type td.align-center { text-align: start; }
  input.ai-num { width: 100%; }
  .ai-types__table .select, .ai-types__table select, .ai-types__table td[data-label="תצהיר"] .select, .ai-types__table td[data-label="תצהיר"] select { min-width: 0; width: 100%; }
  .ai-type__state { min-height: 0; }
  .ai-type__state:empty { display: none !important; }
}

/* ── templates ─────────────────────────────────────────────────────────────────────────── */
.ai-tpl-group + .ai-tpl-group { margin-top: var(--space-8); }
.ai-tpl-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(320px, 100%), 1fr)); gap: var(--space-4); }
.ai-tpl { display: flex; flex-direction: column; gap: var(--space-3); padding: var(--space-5); border-radius: var(--radius-card); background: var(--surface); border: 1px solid var(--border-subtle); box-shadow: var(--shadow-sm); transition: border-color var(--dur-2), box-shadow var(--dur-2); }
.ai-tpl:hover { border-color: var(--border-strong); box-shadow: var(--shadow-md); }
.ai-tpl.is-custom { border-inline-start: 3px solid var(--primary); }
.ai-tpl__head { display: flex; align-items: flex-start; gap: var(--space-3); }
.ai-tpl__icon { flex: none; display: grid; place-items: center; width: 40px; height: 40px; border-radius: 11px; background: var(--primary-soft); color: var(--primary-text); }
.ai-tpl__titles { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.ai-tpl__title { margin: 0; font-size: var(--fs-md); font-weight: var(--fw-semibold); line-height: var(--lh-snug); }
.ai-tpl__name { font-family: var(--font-mono); font-size: var(--fs-2xs); color: var(--text-muted); text-align: right; align-self: flex-start; max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
.ai-tpl__used { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; min-height: 24px; }
.ai-tpl__used-label { font-size: var(--fs-xs); color: var(--text-muted); }
.ai-tpl__type { font-size: var(--fs-xs); padding: 2px 8px; border-radius: var(--radius-pill); background: var(--surface-3); color: var(--text); }
.ai-tpl__actions { display: flex; flex-wrap: wrap; gap: var(--space-2); margin-top: auto; padding-top: var(--space-2); border-top: 1px solid var(--border-subtle); }

/* ── template editor ───────────────────────────────────────────────────────────────────── */
.ai-split { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: var(--space-5); align-items: start; }
.ai-split__code, .ai-split__preview { display: flex; flex-direction: column; gap: var(--space-4); min-width: 0; }
.ai-split__preview { position: sticky; top: calc(var(--topbar-h) + var(--space-4)); }
.ai-mobile-tabs { display: none; margin-bottom: var(--space-4); }
/* A template error shown above the code when the preview (which carries it on wide screens) is on the other tab. */
.ai-code-error { display: none; border-radius: var(--radius-md); }
@media (max-width: 1099.98px) {
  .ai-split { grid-template-columns: minmax(0, 1fr); }
  .ai-split__preview { position: static; }
  .ai-mobile-tabs { display: block; }
  .ai-split.show-code .ai-code-error { display: flex; }
  .ai-split.show-code .ai-split__preview { display: none; }
  .ai-split.show-preview .ai-split__code { display: none; }
}
.ai-editor-card > .card__body, .ai-preview-card > .card__body { overflow: hidden; border-radius: 0 0 var(--radius-card) var(--radius-card); }
.ai-editor { display: flex; flex-direction: column; }
.ai-editor__frame { display: flex; height: min(64vh, 720px); min-height: 360px; background: var(--surface-2); border-top: 1px solid var(--border-subtle); }
.ai-editor__gutter { flex: none; overflow: hidden; padding: 12px 0; min-width: 46px; text-align: right; background: var(--surface-3); border-right: 1px solid var(--border-subtle); color: var(--text-subtle); font-family: var(--font-mono); font-size: 12.5px; line-height: 20px; user-select: none; }
.ai-editor__gutter span { display: block; padding: 0 10px 0 8px; }
.ai-editor__gutter span.is-current { color: var(--text); background: var(--surface-sunken); }
.ai-editor__gutter span.is-error { color: var(--on-primary); background: var(--danger); font-weight: var(--fw-bold); }
.ai-editor__ta {
  flex: 1; min-width: 0; resize: none; border: 0; margin: 0; padding: 12px 14px; background: transparent; color: var(--text);
  font-family: var(--font-mono); font-size: 12.5px; line-height: 20px; tab-size: 2; white-space: pre; overflow: auto; direction: ltr; text-align: left;
}
.ai-editor__ta:focus { outline: none; box-shadow: inset 0 0 0 2px var(--primary-ring); }
.ai-editor__status { display: flex; flex-wrap: wrap; align-items: center; gap: 4px var(--space-4); padding: 6px var(--space-4); border-top: 1px solid var(--border-subtle); font-size: var(--fs-2xs); color: var(--text-muted); }
.ai-editor__keys { margin-inline-start: auto; }
.ai-editor__keys kbd { font-family: var(--font-mono); font-size: 10px; padding: 0 4px; border-radius: 4px; border: 1px solid var(--border); background: var(--surface); }
@media (max-width: 767.98px) { .ai-editor__keys { display: none; } .ai-editor__frame { height: 60vh; } }

.ai-palette { display: flex; flex-direction: column; gap: var(--space-3); }
.ai-palette__body { max-height: 320px; overflow-y: auto; display: flex; flex-direction: column; gap: var(--space-3); padding-inline-end: 4px; }
.ai-palette__gtitle { display: block; margin-bottom: 6px; font-size: var(--fs-2xs); font-weight: var(--fw-semibold); color: var(--text-subtle); letter-spacing: 0.02em; }
.ai-palette__chips { display: flex; flex-wrap: wrap; gap: 6px; }
.ai-ph {
  display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; font: inherit; font-size: var(--fs-xs); cursor: pointer;
  border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--surface); color: var(--text);
  transition: border-color var(--dur-2), background var(--dur-2);
}
.ai-ph:hover { border-color: var(--primary); background: var(--primary-soft); }
.ai-ph.is-block { border-style: dashed; }
.ai-ph__key { font-family: var(--font-mono); font-size: 10.5px; color: var(--text-muted); }
.ai-palette__hint { margin: 0; font-size: var(--fs-2xs); color: var(--text-muted); }
.ai-palette__hint code { font-family: var(--font-mono); padding: 0 3px; border-radius: 4px; background: var(--surface-3); }

.ai-preview__bar { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2) var(--space-3); padding: var(--space-3) var(--space-4); border-top: 1px solid var(--border-subtle); border-bottom: 1px solid var(--border-subtle); background: var(--surface-2); }
.ai-preview__bar .field { margin: 0; flex: 1 1 200px; }
.ai-preview__error { display: flex; align-items: flex-start; gap: var(--space-2); padding: var(--space-2) var(--space-4); background: var(--warning-soft); color: var(--warning-text); font-size: var(--fs-sm); }
.ai-linkbtn { margin-inline-start: auto; border: 0; background: none; padding: 0; font: inherit; font-weight: var(--fw-semibold); color: inherit; text-decoration: underline; cursor: pointer; white-space: nowrap; }
.ai-preview__stage { height: min(70vh, 860px); min-height: 420px; padding: var(--space-4); background: var(--surface-sunken); overflow: hidden; }
/* The sheet is laid out at A4 width (TemplateEdit sets width / padding / scale) and shrunk to fit the stage. */
.ai-paper { box-sizing: border-box; transform-origin: top right; border-radius: var(--radius-sm); background: var(--paper, #fff); box-shadow: var(--shadow-md); }
[dir="ltr"] .ai-paper { transform-origin: top left; }
.ai-preview__frame { display: block; width: 100%; height: 100%; border: 0; background: var(--paper, #fff); transition: opacity var(--dur-3); }
.ai-preview__stage.is-stale .ai-paper { opacity: 0.55; filter: grayscale(0.4); }
.ai-preview__stage.is-actual { overflow: auto; }
.ai-preview__empty { display: grid; place-items: center; height: 100%; color: var(--text-muted); font-size: var(--fs-sm); }
.ai-preview__note { margin: 0; padding: var(--space-2) var(--space-4); font-size: var(--fs-2xs); color: var(--text-muted); border-top: 1px solid var(--border-subtle); }

/* ── Visual (WYSIWYG) template editor ─────────────────────────────────────────────────────── */
.ai-ve { display: flex; flex-direction: column; border-top: 1px solid var(--border-subtle); }
.ai-ve__toolbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 4px; padding: 8px var(--space-3);
  background: var(--surface-2); border-bottom: 1px solid var(--border-subtle); position: sticky; top: 0; z-index: 1;
}
.ai-ve__btn {
  display: inline-grid; place-items: center; min-width: 30px; height: 30px; padding: 0 6px; border-radius: var(--radius-sm);
  border: 1px solid transparent; background: transparent; color: var(--text); font: inherit; font-size: 15px; cursor: pointer;
}
.ai-ve__btn:hover { background: var(--surface-sunken); border-color: var(--border-subtle); }
.ai-ve__btn:focus-visible { outline: 2px solid var(--primary-ring); outline-offset: 1px; }
.ai-ve__btn.is-on { background: var(--primary-soft); color: var(--primary-text); border-color: var(--primary-ring); }
.ai-ve__select {
  height: 30px; border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font: inherit; font-size: var(--fs-sm); padding: 0 6px; max-width: 140px;
}
.ai-ve__select--sm { max-width: 82px; }
.ai-ve__sep { width: 1px; height: 20px; background: var(--border-subtle); margin: 0 3px; }
.ai-ve__color { position: relative; display: inline-grid; place-items: center; width: 30px; height: 30px; border-radius: var(--radius-sm); cursor: pointer; font-weight: 700; }
.ai-ve__color:hover { background: var(--surface-sunken); }
.ai-ve__color input { position: absolute; inset: auto 4px 3px 4px; width: calc(100% - 8px); height: 5px; padding: 0; border: 0; opacity: .9; cursor: pointer; }
.ai-ve__color--bg span { color: #e0b400; }
.ai-ve__frame { display: block; width: 100%; height: min(70vh, 820px); min-height: 380px; border: 0; background: #E9EDF5; }
.ai-ve__legend { display: flex; flex-wrap: wrap; gap: 4px var(--space-4); padding: 6px var(--space-4); border-top: 1px solid var(--border-subtle); font-size: var(--fs-2xs); color: var(--text-muted); }
.ai-ve__chip { display: inline-block; border-radius: 4px; padding: 0 4px; background: #E8EEFF; border: 1px solid #A9BAF2; color: #1D3FA6; font-weight: 600; }
.ai-ve__chip--blk { background: #FFF6E0; border: 1px dashed #E0A93B; color: #8A5300; }
.ai-mode-tabs { padding: var(--space-2) var(--space-4) 0; }

/* ── Templates list (rows) ────────────────────────────────────────────────────────────────── */
.ai-tpl-list { list-style: none; margin: 0; padding: 0; }
.ai-tpl-row { display: grid; grid-template-columns: 44px minmax(0, 1fr) auto; gap: var(--space-4); align-items: center; padding: var(--space-4) var(--space-5); }
.ai-tpl-row + .ai-tpl-row { border-top: 1px solid var(--border-subtle); }
.ai-tpl-row:hover { background: var(--surface-2); }
.ai-tpl-row__icon { display: grid; place-items: center; width: 44px; height: 44px; border-radius: var(--radius-md); background: var(--primary-soft); color: var(--primary-text); }
.ai-tpl-row.is-custom .ai-tpl-row__icon { background: var(--success-soft); color: var(--success-text, var(--success)); }
.ai-tpl-row__title { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); font-weight: var(--fw-semibold); }
.ai-tpl-row__title a { color: inherit; text-decoration: none; }
.ai-tpl-row__title a:hover { color: var(--primary-text); text-decoration: underline; }
.ai-tpl-row__desc { color: var(--text-muted); font-size: var(--fs-sm); margin-top: 2px; }
.ai-tpl-row__meta { display: flex; flex-wrap: wrap; gap: 4px var(--space-3); margin-top: 6px; font-size: var(--fs-xs); color: var(--text-subtle); align-items: center; }
.ai-tpl-row__meta code { font-size: var(--fs-2xs); }
.ai-tpl-row__actions { display: flex; flex-wrap: wrap; gap: var(--space-2); justify-content: flex-end; }
@media (max-width: 760px) {
  .ai-tpl-row { grid-template-columns: 36px minmax(0, 1fr); }
  .ai-tpl-row__icon { width: 36px; height: 36px; }
  .ai-tpl-row__actions { grid-column: 1 / -1; justify-content: flex-start; }
}
.ai-logo { display: flex; align-items: center; gap: var(--space-5); flex-wrap: wrap; }
.ai-logo__box {
  display: grid; place-items: center; width: 180px; height: 84px; border-radius: var(--radius-md); background: #fff;
  border: 1px dashed var(--border); overflow: hidden;
}
.ai-logo__box img { max-width: 92%; max-height: 92%; object-fit: contain; }
.ai-logo__text { flex: 1; min-width: 220px; font-size: var(--fs-sm); color: var(--text-muted); }

/* ── Letter composer ──────────────────────────────────────────────────────────────────────── */
.ai-letter-fields { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: var(--space-3) var(--space-4); }
.ai-letter-fields .is-wide { grid-column: 1 / -1; }
@media (max-width: 760px) { .ai-letter-fields { grid-template-columns: minmax(0, 1fr); } }
