/*
 * Components — one block per partial in components/.
 * Only tokens.css variables for color. Logical properties (inline-start = right in RTL).
 * Touch targets are at least --size-touch-min (44px) on touch layouts.
 */

/* ===== Button ========================================================= */

.btn {
  --btn-h: var(--size-control-medium);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-8);
  min-height: var(--btn-h);
  padding: 0 var(--space-16);
  border: var(--border-thin) solid transparent;
  border-radius: var(--radius-md);
  font-family: var(--font-family);
  font-size: 14px;
  line-height: 20px;
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
  transition: background-color var(--motion-fast) ease, border-color var(--motion-fast) ease, color var(--motion-fast) ease;
}

.btn--sm { --btn-h: var(--size-control-small); padding: 0 var(--space-12); font-size: 13px; line-height: 18px; }
.btn--md { --btn-h: var(--size-control-medium); }
.btn--lg { --btn-h: var(--size-control-large); padding: 0 var(--space-24); border-radius: var(--radius-md); }
.btn--block { display: flex; width: 100%; }

.btn--primary {
  background: var(--color-action-primary-default);
  color: var(--color-text-on-brand);
}
.btn--primary:hover { background: var(--color-action-primary-hover); }
.btn--primary:active { background: var(--color-action-primary-pressed); }

.btn--secondary {
  background: var(--color-action-secondary-default);
  border-color: var(--color-border-brand);
  color: var(--color-text-primary);
}
.btn--secondary:hover { background: var(--color-action-secondary-hover); }
.btn--secondary:active { background: var(--color-action-secondary-pressed); }

.btn--ghost {
  background: var(--color-action-ghost-default);
  color: var(--color-text-primary);
}
.btn--ghost:hover { background: var(--color-action-ghost-hover); }
.btn--ghost:active { background: var(--color-action-ghost-pressed); }

.btn--destructive {
  background: var(--color-action-destructive-default);
  color: var(--color-text-inverse);
}
.btn--destructive:hover { background: var(--color-action-destructive-hover); }
.btn--destructive:active { background: var(--color-action-destructive-pressed); }

.btn:disabled,
.btn[aria-disabled="true"] {
  cursor: not-allowed;
  background: var(--color-action-secondary-disabled);
  border-color: var(--color-border-disabled);
  color: var(--color-text-disabled);
}
.btn--primary:disabled { background: var(--color-action-primary-disabled); }
.btn--ghost:disabled { background: var(--color-action-ghost-disabled); border-color: transparent; }

.btn[aria-busy="true"] {
  pointer-events: none;
  opacity: 0.7;
}

/* Icon-only buttons (close, menu, bell). 44px hit area on touch layouts. */
.icon-btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--size-control-medium);
  height: var(--size-control-medium);
  padding: 0;
  border: 0;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--color-icon-primary);
  text-decoration: none;
}
.icon-btn:hover { background: var(--color-action-ghost-hover); }
.icon-btn--sm { width: var(--size-control-small); height: var(--size-control-small); }
.icon-btn--bordered {
  border: var(--border-thin) solid var(--color-border-subtle);
  border-radius: var(--radius-lg);
  background: var(--color-surface-base);
}

.link-btn {
  padding: 0;
  border: 0;
  background: none;
  color: var(--color-text-secondary);
  font-size: 13px;
  line-height: 18px;
  font-weight: 500;
  cursor: pointer;
}
.link-btn:hover { color: var(--color-text-primary); text-decoration: underline; }
.link-btn--strong { color: var(--color-text-primary); font-weight: 600; }

/* ===== Fields ========================================================= */

.field {
  display: flex;
  flex-direction: column;
  gap: var(--space-6);
  min-width: 0;
}

.field__label {
  color: var(--color-text-primary);
  font-size: 14px;
  line-height: 20px;
  font-weight: 500;
}

.field__helper {
  color: var(--color-text-tertiary);
  font-size: 12px;
  line-height: 16px;
  min-height: 16px;
}

.field__error {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  color: var(--color-text-danger);
  font-size: 12px;
  line-height: 16px;
}
.field__error:empty { display: none; }

/* When an error is shown, the helper makes room for it (F01/S1a, F04/S2a). */
.field:has(.field__error:not(:empty)) .field__helper { display: none; }

.control {
  position: relative;
  display: flex;
  align-items: center;
  min-height: var(--size-control-large);
  border: var(--border-thin) solid var(--color-border-default);
  border-radius: var(--radius-md);
  background: var(--color-surface-base);
  transition: border-color var(--motion-fast) ease, box-shadow var(--motion-fast) ease;
}
.control--md { min-height: var(--size-control-medium); }

.control:focus-within {
  border-color: var(--color-border-focus);
  box-shadow: 0 0 0 1px var(--color-focus-ring);
}

.field:has(.field__error:not(:empty)) .control,
.field--error .control,
.control:has([aria-invalid="true"]) {
  border-color: var(--color-border-danger);
}
.field:has(.field__error:not(:empty)) .control:focus-within,
.control:has([aria-invalid="true"]):focus-within {
  box-shadow: 0 0 0 1px var(--color-border-danger);
}

.control__input {
  flex: 1;
  width: 100%;
  min-width: 0;
  min-height: inherit;
  padding: 0 var(--space-16);
  border: 0;
  border-radius: inherit;
  background: transparent;
  color: var(--color-text-primary);
  font-size: 14px;
  line-height: 24px;
}
.control__input:focus-visible { outline: none; }
.control__input::placeholder { color: var(--color-text-tertiary); opacity: 1; }
.control__input[readonly] { color: var(--color-text-secondary); }
.control__input:disabled { color: var(--color-text-disabled); cursor: not-allowed; }
.control:has(.control__input:disabled) { background: var(--color-surface-subtle); border-color: var(--color-border-disabled); }

/* LTR values (mobile, codes) still align to the start of an RTL form. */
.control__input[dir="ltr"] { text-align: right; }

.control__icon {
  position: absolute;
  inset-inline-end: var(--space-12); /* design system: icons sit on the left (end in RTL) */
  color: var(--color-icon-secondary);
  pointer-events: none;
}
.control--icon .control__input { padding-inline-end: calc(var(--space-12) + var(--size-icon-md) + var(--space-8)); }

.control__icon--end {
  inset-inline-start: auto;
  inset-inline-end: var(--space-12);
}
.control--icon-end .control__input { padding-inline-end: calc(var(--space-12) + var(--size-icon-md) + var(--space-8)); }

.control__unit {
  flex: none;
  padding-inline: var(--space-12) var(--space-16);
  color: var(--color-text-tertiary);
  font-size: 13px;
  line-height: 20px;
}
.control--unit .control__input { padding-inline-end: 0; }

.control--select .control__input {
  appearance: none;
  padding-inline-end: calc(var(--space-12) + var(--size-icon-md) + var(--space-8));
  cursor: pointer;
}
.control__chevron {
  position: absolute;
  inset-inline-end: var(--space-12);
  color: var(--color-icon-secondary);
  pointer-events: none;
}
/* chevron-left turned to point down (overrides the RTL mirror). */
[dir="rtl"] .control .control__chevron,
.control .control__chevron { transform: rotate(-90deg); }

.control--textarea {
  flex-direction: column;
  align-items: stretch;
  border: 0;
  background: transparent;
  box-shadow: none !important;
}
.control--textarea .control__input {
  min-height: 96px;
  padding: var(--space-12) var(--space-16);
  border: var(--border-thin) solid var(--color-border-default);
  border-radius: var(--radius-md);
  background: var(--color-surface-base);
  resize: vertical;
}
.control--textarea .control__input:focus {
  border-color: var(--color-border-focus);
  box-shadow: 0 0 0 1px var(--color-focus-ring);
}
.control--textarea .control__input[aria-invalid="true"],
.field:has(.field__error:not(:empty)) .control--textarea .control__input {
  border-color: var(--color-border-danger);
}
.control__counter {
  align-self: flex-end;
  direction: ltr; /* reads «۴۲ / ۵۰۰» as in the frames */
  margin-top: var(--space-4);
  color: var(--color-text-tertiary);
  font-size: 12px;
  line-height: 16px;
}

/* ===== Upload ========================================================= */

.upload__tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-8);
  width: 130px;
  height: 130px;
  border: var(--border-thin) dashed var(--color-border-brand);
  border-radius: var(--radius-lg);
  background: var(--color-surface-base);
  color: var(--color-icon-secondary);
  cursor: pointer;
}
.upload__tile:hover { background: var(--color-surface-page); }
.upload:has(.visually-hidden:focus-visible) .upload__tile {
  outline: 2px solid var(--color-focus-ring);
  outline-offset: 2px;
}
.upload__cta {
  color: var(--color-text-secondary);
  font-size: 12px;
  line-height: 16px;
}
.upload__file {
  display: flex;
  align-items: center;
  gap: var(--space-8);
  max-width: 360px;
  padding: var(--space-8) var(--space-12);
  border: var(--border-thin) solid var(--color-border-subtle);
  border-radius: var(--radius-md);
  background: var(--color-surface-subtle);
}
.upload__file-icon { color: var(--color-icon-secondary); }
.upload__name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
}
.upload__size { color: var(--color-text-tertiary); font-size: 12px; }

/* ===== Switch / checkbox / option ===================================== */

.switch {
  display: inline-flex;
  align-items: flex-start;
  gap: var(--space-12);
  min-height: var(--size-touch-min);
  cursor: pointer;
}
.switch__input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch__track {
  position: relative;
  flex: none;
  width: 40px;
  height: 24px;
  margin-top: 2px;
  border-radius: var(--radius-full);
  background: var(--color-border-brand);
  transition: background-color var(--motion-fast) ease;
}
.switch__thumb {
  position: absolute;
  top: 2px;
  inset-inline-start: 2px;
  width: 20px;
  height: 20px;
  border-radius: var(--radius-full);
  background: var(--color-surface-base);
  transition: inset-inline-start var(--motion-fast) ease;
}
.switch__input:checked + .switch__track { background: var(--color-surface-success-strong); }
.switch__input:checked + .switch__track .switch__thumb { inset-inline-start: 18px; }
.switch__input:focus-visible + .switch__track { outline: 2px solid var(--color-focus-ring); outline-offset: 2px; }
.switch__input:disabled + .switch__track { opacity: 0.5; }
.switch__text { display: flex; flex-direction: column; }
.switch__label { font-size: 14px; line-height: 20px; font-weight: 500; }
.switch__desc { color: var(--color-text-tertiary); font-size: 12px; line-height: 16px; }

.checkbox-field__row {
  display: flex;
  align-items: flex-start;
  gap: var(--space-12);
  cursor: pointer;
}
.checkbox-field__input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.checkbox-field__box {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  margin-top: 2px;
  border: var(--border-strong) solid var(--color-border-default);
  border-radius: var(--radius-xs);
  color: transparent;
}
.checkbox-field__input:checked + .checkbox-field__box {
  border-color: var(--color-surface-inverse);
  background: var(--color-surface-inverse);
  color: var(--color-text-inverse);
}
.checkbox-field__input:focus-visible + .checkbox-field__box { outline: 2px solid var(--color-focus-ring); outline-offset: 2px; }
.checkbox-field__text { display: flex; flex-direction: column; gap: var(--space-2); }
.checkbox-field__label { font-size: 14px; line-height: 22px; font-weight: 500; }
.checkbox-field__desc { color: var(--color-text-secondary); font-size: 13px; line-height: 20px; }
.checkbox-field--error .checkbox-field__box { border-color: var(--color-border-danger); }

.option {
  position: relative;
  display: flex;
  align-items: center;
  gap: var(--space-12);
  padding: var(--space-16);
  border: var(--border-thin) solid var(--color-border-subtle);
  border-radius: var(--radius-lg);
  background: var(--color-surface-base);
  cursor: pointer;
}
.option__input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.option__chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  background: var(--color-surface-subtle);
  color: var(--color-icon-primary);
}
.option__text { flex: 1; display: flex; flex-direction: column; }
.option__title { font-size: 14px; line-height: 20px; font-weight: 600; }
.option__subtitle { color: var(--color-text-secondary); font-size: 13px; line-height: 20px; }
.option__mark {
  flex: none;
  width: 20px;
  height: 20px;
  border: var(--border-strong) solid var(--color-border-default);
  border-radius: var(--radius-full);
}
.option:has(.option__input:checked) { border-color: var(--color-surface-inverse); box-shadow: 0 0 0 1px var(--color-surface-inverse); }
.option:has(.option__input:checked) .option__mark { border: 6px solid var(--color-surface-inverse); }
.option:has(.option__input:focus-visible) { outline: 2px solid var(--color-focus-ring); outline-offset: 2px; }
.option.is-disabled { opacity: 0.5; cursor: not-allowed; }

/* ===== Segmented / rating ============================================= */

.segmented { margin: 0; padding: 0; border: 0; min-width: 0; }
.segmented__legend { margin-bottom: var(--space-8); font-size: 14px; line-height: 20px; font-weight: 500; }
.segmented__items {
  display: inline-flex;
  border: var(--border-thin) solid var(--color-border-subtle);
  border-radius: var(--radius-md);
  background: var(--color-surface-subtle);
  padding: var(--space-2);
}
.segmented__item { position: relative; }
.segmented__item input { position: absolute; opacity: 0; }
.segmented__item span {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: var(--size-touch-min);
  min-height: var(--size-control-small);
  padding: 0 var(--space-12);
  border-radius: var(--radius-sm);
  color: var(--color-text-secondary);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
}
.segmented__item input:checked + span { background: var(--color-surface-base); color: var(--color-text-primary); }
.segmented__item input:focus-visible + span { outline: 2px solid var(--color-focus-ring); }
.rating--error .segmented__items { border-color: var(--color-border-danger); }

/* ===== Tabs (Line) ==================================================== */

.tabs {
  display: flex;
  gap: var(--space-4);
  margin-bottom: var(--space-24);
  border-bottom: var(--border-thin) solid var(--color-border-subtle);
  overflow-x: auto;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }

.tabs__item {
  position: relative;
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: var(--space-4);
  min-height: var(--size-touch-min);
  padding: var(--space-8) var(--space-24);
  border: 0;
  background: none;
  color: var(--color-text-secondary);
  font-size: 13px;
  line-height: 18px;
  font-weight: 500;
  text-decoration: none;
  white-space: nowrap;
}
.tabs__item:hover { color: var(--color-text-primary); }

/* Active tab: neutral indicator (gold is reserved for the primary action). */
.tabs__item[aria-current="page"],
.tabs__item[aria-selected="true"] {
  color: var(--color-text-primary);
  font-weight: 600;
}
.tabs__item[aria-current="page"]::after,
.tabs__item[aria-selected="true"]::after {
  content: "";
  position: absolute;
  inset-inline: var(--space-8);
  bottom: -1px;
  height: 2px;
  border-radius: 2px;
  background: var(--color-text-primary);
}

/* ===== Alert / inline message / note ================================== */

.alert {
  display: flex;
  align-items: flex-start;
  gap: var(--space-12);
  padding: var(--space-16) var(--space-20);
  border: var(--border-thin) solid;
  border-radius: var(--radius-lg);
}
.alert__icon { margin-top: 2px; }
.alert__body { display: flex; flex-direction: column; gap: var(--space-2); }
.alert__title { font-size: 14px; line-height: 22px; font-weight: 600; }
.alert__message { color: var(--color-text-secondary); font-size: 13px; line-height: 22px; }

.alert--info { border-color: var(--color-border-info); background: var(--color-surface-info-subtle); }
.alert--info .alert__icon, .alert--info .alert__title { color: var(--color-text-info); }
.alert--warning { border-color: var(--color-border-warning); background: var(--color-surface-warning-subtle); }
.alert--warning .alert__icon { color: var(--color-icon-warning); }
.alert--warning .alert__title { color: var(--color-text-warning); }
.alert--danger { border-color: var(--color-border-danger); background: var(--color-surface-danger-subtle); }
.alert--danger .alert__icon { color: var(--color-icon-danger); }
.alert--danger .alert__title { color: var(--color-text-danger); }
.alert--success { border-color: var(--color-border-success); background: var(--color-surface-success-subtle); }
.alert--success .alert__icon { color: var(--color-icon-success); }
.alert--success .alert__title { color: var(--color-text-success); }

.inline-msg {
  display: flex;
  align-items: center;
  gap: var(--space-6);
  font-size: 12px;
  line-height: 18px;
}
.inline-msg--danger { color: var(--color-text-danger); }
.inline-msg--warning { color: var(--color-text-warning); }
.inline-msg--success { color: var(--color-text-success); }
.inline-msg--info { color: var(--color-text-info); }
.inline-msg--neutral { color: var(--color-text-secondary); }

.note {
  display: flex;
  align-items: flex-start;
  gap: var(--space-12);
  padding: var(--space-16);
  border-radius: var(--radius-lg);
  background: var(--color-surface-subtle);
  color: var(--color-text-secondary);
  font-size: 13px;
  line-height: 22px;
}
.note > .icon { color: var(--color-icon-secondary); margin-top: 1px; }
.note--stack { flex-direction: column; gap: var(--space-8); }
.note__title { color: var(--color-text-primary); font-size: 14px; line-height: 22px; font-weight: 600; }
.note__list { margin: 0; padding-inline-start: var(--space-20); }
.note__actions { display: flex; flex-wrap: wrap; gap: var(--space-8); margin-top: var(--space-4); }

/* ===== Toast ========================================================== */

.toast-region {
  position: fixed;
  z-index: 60;
  top: var(--space-16);
  left: 50%;
  display: flex;
  flex-direction: column;
  gap: var(--space-8);
  transform: translateX(-50%);
  width: min(420px, calc(100vw - var(--space-32)));
  pointer-events: none;
}
.toast {
  display: flex;
  align-items: center;
  gap: var(--space-12);
  padding: var(--space-12) var(--space-16);
  border: var(--border-thin) solid var(--color-border-subtle);
  border-radius: var(--radius-lg);
  background: var(--color-surface-raised);
  box-shadow: 0 8px 24px -8px var(--color-border-strong);
  font-size: 13px;
  line-height: 20px;
  pointer-events: auto;
}
.toast--success { background: var(--color-surface-success-subtle); border-color: var(--color-border-success); }
.toast--success .toast__icon { color: var(--color-icon-success); }
.toast--danger { background: var(--color-surface-danger-subtle); border-color: var(--color-border-danger); }
.toast--danger .toast__icon { color: var(--color-icon-danger); }

/* ===== Avatar / badge ================================================= */

.avatar {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-full);
  background: var(--color-surface-brand-default);
  color: var(--color-text-primary);
  font-weight: 600;
  white-space: nowrap;
}
.avatar--sm { width: var(--size-avatar-small); height: var(--size-avatar-small); font-size: 9px; }
.avatar--md { width: var(--size-avatar-medium); height: var(--size-avatar-medium); font-size: 11px; }
.avatar--lg { width: var(--size-avatar-large); height: var(--size-avatar-large); font-size: 13px; }

.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-6);
  min-height: 24px;
  padding: 0 var(--space-8);
  border-radius: var(--radius-full);
  font-size: 12px;
  line-height: 16px;
  font-weight: 500;
  white-space: nowrap;
}
.badge__dot {
  width: 6px;
  height: 6px;
  border-radius: var(--radius-full);
  background: currentColor;
}
.badge__check { width: 14px; height: 14px; }

.badge--neutral { background: var(--color-surface-subtle); color: var(--color-text-secondary); }
.badge--neutral .badge__dot { background: var(--color-icon-secondary); }
.badge--info { background: var(--color-surface-info-subtle); color: var(--color-text-info); }
.badge--info .badge__dot { background: var(--color-icon-info); }
.badge--warning { background: var(--color-surface-warning-subtle); color: var(--color-text-warning); }
.badge--warning .badge__dot { background: var(--color-icon-warning); }
.badge--success { background: var(--color-surface-success-subtle); color: var(--color-text-success); }
.badge--success .badge__dot { background: var(--color-icon-success); }
.badge--danger { background: var(--color-surface-danger-subtle); color: var(--color-text-danger); }
.badge--danger .badge__dot { background: var(--color-icon-danger); }

/* ===== Card, empty state, page head =================================== */

.card {
  padding: var(--space-24);
  border: var(--border-thin) solid var(--color-border-subtle);
  border-radius: var(--radius-xl);
  background: var(--color-surface-base);
}
.card--flush { padding: 0; overflow: hidden; }

.card__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-12);
  padding: var(--space-16) var(--space-24);
  border-bottom: var(--border-thin) solid var(--color-border-subtle);
}
.card__head--plain { padding: 0 0 var(--space-12); border-bottom: 0; }
.card__head .card__title { margin: 0; }
.card__head .badge { margin-inline-end: auto; }

.card__title {
  margin-bottom: var(--space-16);
  color: var(--color-text-primary);
  font-size: 18px;
  line-height: 28px;
  font-weight: 600;
}

.card__link {
  display: inline-flex;
  align-items: center;
  gap: var(--space-4);
  color: var(--color-text-primary);
  font-size: 13px;
  line-height: 18px;
  font-weight: 500;
  text-decoration: none;
}
.card__link:hover { text-decoration: underline; }

.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-8);
  padding: var(--space-48) var(--space-24);
  text-align: center;
}
.empty__icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 64px;
  height: 64px;
  margin-bottom: var(--space-8);
  border-radius: var(--radius-full);
  background: var(--color-surface-subtle);
  color: var(--color-icon-secondary);
}
.empty__title { font-size: 18px; line-height: 28px; font-weight: 600; }
.empty__desc { max-width: 380px; color: var(--color-text-secondary); font-size: 13px; line-height: 24px; }
.empty__action { margin-top: var(--space-24); }
.empty--compact { padding: var(--space-32) var(--space-24); }
.empty--compact .empty__icon { width: 48px; height: 48px; }
.empty--compact .empty__title { font-size: 16px; line-height: 24px; }

.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-16);
  margin-bottom: var(--space-24);
}
.page-head__title { font-size: 24px; line-height: 32px; font-weight: 600; }
.page-head__subtitle { margin-top: var(--space-4); color: var(--color-text-secondary); font-size: 13px; line-height: 20px; }
.page-head__actions { display: flex; gap: var(--space-8); flex: none; }

.section-title { font-size: 18px; line-height: 28px; font-weight: 600; }
.section-subtitle { color: var(--color-text-secondary); font-size: 13px; line-height: 20px; }

/* ===== Service card ==================================================== */

.service-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: var(--space-8);
  min-height: 184px;
  padding: var(--space-20) var(--space-20) var(--space-16);
  border: var(--border-thin) solid var(--color-border-subtle);
  border-radius: var(--radius-xl);
  background: var(--color-surface-base);
  color: var(--color-text-primary);
  text-decoration: none;
  transition: border-color var(--motion-fast) ease, box-shadow var(--motion-fast) ease;
}
a.service-card:hover { border-color: var(--color-border-brand); box-shadow: 0 4px 16px -8px var(--color-border-brand); }
.service-card.is-disabled { cursor: default; }
.service-card__chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  margin-bottom: var(--space-8);
  border-radius: var(--radius-lg);
  background: var(--color-surface-subtle);
  color: var(--color-icon-primary);
}
.service-card__title { font-size: 16px; line-height: 24px; font-weight: 600; }
.service-card__desc { color: var(--color-text-secondary); font-size: 13px; line-height: 22px; }
.service-card__action {
  display: inline-flex;
  align-items: center;
  gap: var(--space-4);
  margin-top: auto;
  padding-top: var(--space-8);
  font-size: 13px;
  line-height: 18px;
  font-weight: 600;
}
.service-card.is-disabled .service-card__action { color: var(--color-text-disabled); }

/* ===== Stat card ======================================================= */

.stat-card {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  padding: var(--space-20) var(--space-20);
  border: var(--border-thin) solid var(--color-border-subtle);
  border-radius: var(--radius-xl);
  background: var(--color-surface-base);
}
.stat-card__label { color: var(--color-text-secondary); font-size: 13px; line-height: 20px; }
.stat-card__value { font-size: 24px; line-height: 32px; font-weight: 700; }
.stat-card__hint { color: var(--color-text-tertiary); font-size: 12px; line-height: 16px; }

/* ===== Request row ===================================================== */

.row-list { padding: 0 var(--space-8); }
.request-row {
  display: flex;
  align-items: center;
  gap: var(--space-16);
  min-height: 72px;
  padding: var(--space-12) var(--space-16);
  border-bottom: var(--border-thin) solid var(--color-border-subtle);
  color: var(--color-text-primary);
  text-decoration: none;
}
.request-row:last-child { border-bottom: 0; }
.request-row:hover { background: var(--color-surface-page); }
.request-row__main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.request-row__title { font-size: 14px; line-height: 22px; font-weight: 500; }
.request-row__code { color: var(--color-text-tertiary); font-size: 12px; line-height: 16px; align-self: flex-start; }
.request-row__date { color: var(--color-text-secondary); font-size: 12px; line-height: 16px; white-space: nowrap; }
.request-row__chevron { color: var(--color-icon-secondary); }

/* ===== Key value ======================================================= */

.kv { margin: 0; }
.kv__row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-16);
  padding: var(--space-12) 0;
  border-bottom: var(--border-thin) solid var(--color-border-subtle);
}
.kv__row:last-child { border-bottom: 0; }
.kv__label { flex: none; min-width: 120px; color: var(--color-text-secondary); font-size: 13px; line-height: 20px; }
.kv__value { margin: 0; font-size: 14px; line-height: 22px; font-weight: 500; }
/* Row layout (F05/S2, F09/S2): label at the start (right), value at the end (left). */
.kv__value { text-align: end; }
.kv--stack .kv__row { flex-direction: column; gap: var(--space-2); }

/* ===== Table =========================================================== */

.table-wrap {
  border: var(--border-thin) solid var(--color-border-subtle);
  border-radius: var(--radius-xl);
  background: var(--color-surface-base);
  overflow: auto;
  max-height: none;
}
.table {
  width: 100%;
  font-size: 13px;
  line-height: 20px;
}
.table th {
  position: sticky;
  top: 0;
  z-index: 1;
  height: var(--layout-row-height-default);
  padding: 0 var(--space-16);
  background: var(--color-surface-subtle);
  color: var(--color-text-secondary);
  font-size: 13px;
  font-weight: 500;
  text-align: start;
  white-space: nowrap;
}
.table td {
  height: 56px;
  padding: var(--space-8) var(--space-16);
  border-top: var(--border-thin) solid var(--color-border-subtle);
  text-align: start;
  vertical-align: middle;
}
.table tbody tr.is-clickable { cursor: pointer; }
.table tbody tr:hover { background: var(--color-surface-page); }

.cell__empty { color: var(--color-text-tertiary); }
.cell__secondary { color: var(--color-text-secondary); white-space: nowrap; }
.cell__mono { color: var(--color-text-secondary); font-size: 13px; }
.cell__link { color: inherit; text-decoration: none; }
.cell__link:hover .cell__mono { color: var(--color-text-primary); text-decoration: underline; }
.cell__person { display: inline-flex; align-items: center; gap: var(--space-8); }
.cell__person-text { display: flex; flex-direction: column; }
.cell__person-name { font-weight: 500; white-space: nowrap; }
.cell__person-sub { color: var(--color-text-tertiary); font-size: 12px; line-height: 16px; }
.cell__action {
  display: inline-flex;
  align-items: center;
  gap: var(--space-4);
  color: var(--color-text-primary);
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
}
.cell__action:hover { text-decoration: underline; }

.table-footer { margin-top: var(--space-16); color: var(--color-text-tertiary); font-size: 12px; }

/* Under 768 px: every row becomes a card; each cell shows its column label. */
@media (max-width: 767px) {
  .table-wrap { border: 0; background: transparent; overflow: visible; }
  .table--cards,
  .table--cards tbody,
  .table--cards tr,
  .table--cards td { display: block; width: 100%; }
  .table--cards thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .table--cards tr {
    position: relative;
    display: grid;
    grid-template-columns: 1fr auto;
    gap: var(--space-8) var(--space-12);
    margin-bottom: var(--space-12);
    padding: var(--space-16);
    border: var(--border-thin) solid var(--color-border-subtle);
    border-radius: var(--radius-xl);
    background: var(--color-surface-base);
  }
  .table--cards td {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-12);
    height: auto;
    padding: 0;
    border: 0;
    grid-column: 1 / -1;
  }
  .table--cards td::before {
    content: attr(data-label);
    color: var(--color-text-tertiary);
    font-size: 12px;
  }
  .table--cards td.cell--primary { grid-column: 1; grid-row: 1; justify-content: flex-start; font-size: 14px; font-weight: 600; }
  .table--cards td.cell--primary::before,
  .table--cards td.cell--status::before,
  .table--cards td.cell--action::before { display: none; }
  .table--cards td.cell--status { grid-column: 2; grid-row: 1; justify-content: flex-end; }
  .table--cards td.cell--action { justify-content: flex-end; padding-top: var(--space-8); border-top: var(--border-thin) solid var(--color-border-subtle); }
  .table--cards td.cell--action .cell__action { min-height: var(--size-touch-min); }
  .table--cards tr.is-clickable .cell__link::after { content: ""; position: absolute; inset: 0; }
}

/* ===== Pagination ====================================================== */

.pagination { display: flex; gap: var(--space-4); margin-top: var(--space-16); }
.pagination__item {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: var(--size-control-medium);
  height: var(--size-control-medium);
  border: var(--border-thin) solid var(--color-border-subtle);
  border-radius: var(--radius-md);
  color: var(--color-text-primary);
  text-decoration: none;
}
.pagination__item[aria-current="page"] { background: var(--color-surface-inverse); border-color: var(--color-surface-inverse); color: var(--color-text-inverse); }

/* ===== OTP ============================================================= */

.otp {
  position: relative;
  width: 100%;
  max-width: 400px;
}
.otp__input {
  position: absolute;
  inset: 0;
  z-index: 1;
  width: 100%;
  height: 100%;
  border: 0;
  background: transparent;
  color: transparent;
  caret-color: transparent;
  font-size: 16px; /* no zoom on iOS */
  letter-spacing: 2em;
  opacity: 0.01;
}
.otp__input:focus-visible { outline: none; }
.otp__boxes {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: var(--space-12);
}
.otp__box {
  display: flex;
  align-items: center;
  justify-content: center;
  aspect-ratio: 1 / 1.05;
  max-height: 56px;
  border: var(--border-thin) solid var(--color-border-default);
  border-radius: var(--radius-md);
  background: var(--color-surface-base);
  font-size: 20px;
  line-height: 28px;
  font-weight: 600;
}
.otp--focus .otp__box.is-active {
  border-color: var(--color-border-focus);
  box-shadow: 0 0 0 1px var(--color-focus-ring);
}
.otp--error .otp__box {
  border-color: var(--color-border-danger);
  background: var(--color-surface-danger-subtle);
}

/* ===== Dialog: drawer & modal ========================================= */

.dialog {
  position: fixed;
  inset: 0;
  z-index: 50;
}
.dialog__backdrop {
  position: absolute;
  inset: 0;
  background: var(--color-surface-inverse);
  opacity: 0.4;
}
.dialog__panel {
  position: absolute;
  display: flex;
  flex-direction: column;
  background: var(--color-surface-overlay);
  box-shadow: 0 16px 48px -12px var(--color-border-strong);
}
.dialog__panel:focus-visible { outline: none; }

.dialog--drawer .dialog__panel {
  /* Details and forms open as a centred pop-up (no side panel). */
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: min(720px, calc(100vw - var(--space-32)));
  height: min(820px, calc(100vh - var(--space-48)));
  border-radius: var(--radius-xl);
  overflow: hidden;
}
@media (max-width: 640px) {
  .dialog--drawer .dialog__panel { width: 100vw; height: 100vh; border-radius: 0; }
}
.drawer-content,
.drawer-content > .review { display: flex; flex-direction: column; flex: 1; min-height: 0; }

.dialog--modal .dialog__panel {
  top: 50%;
  left: 50%;
  width: min(480px, calc(100vw - var(--space-32)));
  max-height: calc(100vh - var(--space-48));
  transform: translate(-50%, -50%);
  border-radius: var(--radius-xl);
}
.dialog--md .dialog__panel { width: min(640px, calc(100vw - var(--space-32))); }
.dialog--lg .dialog__panel { width: min(760px, calc(100vw - var(--space-32))); }
/* Long forms scroll inside the modal; the title and the buttons stay in view. */
.dialog--modal .dialog__body { flex: 1; min-height: 0; overflow-y: auto; }

.dialog__head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-16);
  padding: var(--space-20) var(--space-24);
}
.dialog--drawer .dialog__head { border-bottom: var(--border-thin) solid var(--color-border-subtle); }
.dialog__titles { min-width: 0; }
.dialog__title { font-size: 20px; line-height: 28px; font-weight: 600; }
.dialog__subtitle { margin-top: var(--space-2); color: var(--color-text-secondary); font-size: 13px; line-height: 20px; }
.dialog__body {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: var(--space-20);
  padding: var(--space-4) var(--space-24) var(--space-20);
  overflow-y: auto;
  color: var(--color-text-secondary);
  font-size: 14px;
  line-height: 24px;
}
.dialog--drawer .dialog__body { padding-top: var(--space-20); color: var(--color-text-primary); }
.dialog__foot {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-8);
  padding: var(--space-16) var(--space-24) var(--space-20);
}
.dialog--drawer .dialog__foot { border-top: var(--border-thin) solid var(--color-border-subtle); }
.dialog__foot--split { justify-content: space-between; }
.dialog__actions { display: flex; flex-wrap: wrap; gap: var(--space-8); }
.dialog--modal .dialog__actions { width: 100%; justify-content: space-between; }

.has-dialog,
.has-dialog body { overflow: hidden; }

/* ===== Back link / stepper / timeline / side info / success =========== */

.back-link {
  display: inline-flex;
  align-items: center;
  gap: var(--space-4);
  min-height: var(--size-touch-min);
  padding: 0;
  border: 0;
  background: none;
  color: var(--color-text-primary);
  font-size: 13px;
  line-height: 18px;
  font-weight: 500;
  text-decoration: none;
  cursor: pointer;
}
.back-link:hover span { text-decoration: underline; }

.stepper { display: flex; gap: var(--space-8); margin: 0 0 var(--space-24); padding: 0; list-style: none; }
.stepper__step { flex: 1; display: flex; align-items: center; gap: var(--space-8); color: var(--color-text-tertiary); font-size: 13px; }
.stepper__marker {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border: var(--border-thin) solid var(--color-border-subtle);
  border-radius: var(--radius-full);
}
.stepper__step--current { color: var(--color-text-primary); font-weight: 600; }
.stepper__step--current .stepper__marker { border-color: var(--color-surface-inverse); background: var(--color-surface-inverse); color: var(--color-text-inverse); }
.stepper__step--done .stepper__marker { border-color: var(--color-border-success); color: var(--color-icon-success); }

.timeline { margin: 0; padding: 0; list-style: none; }
.timeline__step {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: var(--space-8);
  padding: var(--space-12) 0;
  font-size: 13px;
  line-height: 20px;
}
.timeline__icon { color: var(--color-icon-success); }
.timeline__step--current .timeline__icon { color: var(--color-icon-secondary); }
.timeline__step--current .timeline__label { font-weight: 600; }
.timeline__time { color: var(--color-text-tertiary); font-size: 12px; white-space: nowrap; }

.side-info__title { margin-bottom: var(--space-12); font-size: 18px; line-height: 28px; font-weight: 600; }
.side-info__list { margin: 0; padding-inline-start: var(--space-16); color: var(--color-text-secondary); font-size: 13px; line-height: 24px; }
.side-info__list li + li { margin-top: var(--space-8); }

.success-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-16);
  width: 100%;
  max-width: 560px;
  padding: var(--space-40) var(--space-40);
  text-align: center;
}
.success-card__title { font-size: 24px; line-height: 32px; font-weight: 600; }
.success-card__code {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-4);
  width: 100%;
  padding: var(--space-16);
  border-radius: var(--radius-lg);
  background: var(--color-surface-subtle);
}
.success-card__code-label { color: var(--color-text-secondary); font-size: 12px; line-height: 16px; }
.success-card__code-value { font-size: 20px; line-height: 28px; font-weight: 600; }
.success-card__status { display: flex; align-items: center; gap: var(--space-8); color: var(--color-text-secondary); font-size: 13px; }
.success-card__text { max-width: 460px; color: var(--color-text-secondary); font-size: 13px; line-height: 24px; }
.success-card__actions { display: flex; flex-wrap: wrap; justify-content: center; gap: var(--space-12); margin-top: var(--space-8); }

/* ===== Logo ============================================================ */

.logo {
  display: inline-flex;
  align-items: center;
  gap: var(--space-8);
  color: var(--color-text-primary);
  text-decoration: none;
}
.logo--stack { flex-direction: column; align-items: flex-start; gap: var(--space-6); }
.logo__mark { width: auto; height: 34px; flex: none; }
.logo__word { fill: currentColor; }
.logo__caption { font-size: 12px; line-height: 16px; color: var(--color-text-secondary); }
.logo--inline .logo__caption { font-size: 16px; line-height: 24px; font-weight: 700; color: var(--color-text-primary); }

/* Jalali date picker (app.js "jalaliPicker"). */
.jdate-toggle { pointer-events: auto; background: none; border: 0; padding: 0; cursor: pointer; display: inline-flex; color: var(--color-icon-secondary); border-radius: 4px; }
.jdate-toggle:hover { color: var(--color-text-primary); }
.jdate-toggle:focus-visible { outline: 2px solid var(--color-border-focus); outline-offset: 2px; }
.jdate-pop { position: fixed; z-index: 1000; width: 280px; padding: 12px; background: var(--color-surface-overlay); border: 1px solid var(--color-border-subtle); border-radius: 12px; box-shadow: 0 12px 32px rgba(37, 38, 50, .16); direction: rtl; }
.jdate-pop__head { display: flex; align-items: center; justify-content: space-between; margin-block-end: 8px; }
.jdate-pop__title { display: inline-flex; gap: 6px; }
.jdate-pop__select { height: 32px; padding: 0 8px; border: 1px solid var(--color-border-subtle); border-radius: 8px; background: var(--color-surface-base); font: inherit; font-size: 13px; font-weight: 600; color: var(--color-text-primary); cursor: pointer; }
.jdate-pop__select:focus-visible { outline: 2px solid var(--color-focus-ring); outline-offset: 1px; }
.jdate-pop__nav { width: 32px; height: 32px; border: 0; background: none; border-radius: 8px; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; color: var(--color-text-secondary); }
.jdate-pop__nav:hover { background: var(--color-surface-subtle); }
.jdate-pop__grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; text-align: center; }
.jdate-pop__wd { font-size: 12px; color: var(--color-text-secondary); padding-block: 4px; }
.jdate-pop__day { height: 34px; border: 0; background: none; border-radius: 8px; cursor: pointer; font: inherit; font-size: 13px; color: var(--color-text-primary); }
.jdate-pop__day:hover { background: var(--color-surface-subtle); }
.jdate-pop__day:focus-visible { outline: 2px solid var(--color-border-focus); }
.jdate-pop__day--today { box-shadow: inset 0 0 0 1px var(--color-border-default); }
.jdate-pop__day--on { background: var(--color-action-primary-default); font-weight: 600; }
.jdate-pop__day--on:hover { background: var(--color-action-primary-hover); }
.jdate-pop__foot { display: flex; justify-content: space-between; margin-block-start: 8px; }
.jdate-pop__link { border: 0; background: none; cursor: pointer; font: inherit; font-size: 13px; color: var(--color-text-secondary); padding: 4px 8px; border-radius: 6px; }
.jdate-pop__link:hover { background: var(--color-surface-subtle); color: var(--color-text-primary); }

/* Page loading bar (app.js "pageLoading"). */
.page-loading { position: fixed; inset: 0 0 auto 0; height: 3px; z-index: 2000; pointer-events: none; overflow: hidden; }
.page-loading::before { content: ""; position: absolute; inset: 0; width: 40%; background: var(--color-action-primary-default); animation: page-loading 1.1s ease-in-out infinite; }
@keyframes page-loading { 0% { transform: translateX(160%); } 100% { transform: translateX(-260%); } }
@media (prefers-reduced-motion: reduce) { .page-loading::before { animation: none; width: 100%; opacity: .6; } }

.select-filter { width: 100%; height: 40px; margin-block-end: 8px; padding-inline: 12px; border: 1px solid var(--color-border-default); border-radius: var(--radius-md, 8px); background: var(--color-surface-base); font: inherit; }
.select-filter:focus { outline: 2px solid var(--color-focus-ring); outline-offset: 1px; }

input::-webkit-contacts-auto-fill-button, input::-webkit-credentials-auto-fill-button { visibility: hidden; display: none !important; pointer-events: none; }

/* Upload progress line and image preview. */
.progress-line[hidden] { display: none; }
.progress-line { height: 4px; width: 100%; min-width: 120px; margin-top: 6px; border-radius: 2px; background: var(--color-surface-subtle); overflow: hidden; }
.progress-line > span { display: block; height: 100%; background: var(--color-action-primary-default); transition: width .2s ease; }
.identity-doc__view { display: inline-flex; align-items: center; gap: 4px; margin-top: 6px; font-size: 13px; color: var(--color-text-primary); }
.identity-doc__thumb { width: 48px; height: 48px; object-fit: cover; border-radius: 8px; border: 1px solid var(--color-border-subtle); }
.lightbox { position: fixed; inset: 0; z-index: 3000; display: flex; align-items: center; justify-content: center; padding: 32px; background: rgba(15, 16, 22, .82); }
.lightbox img { max-width: 100%; max-height: 100%; border-radius: 8px; background: #fff; }
.lightbox__close { position: absolute; top: 16px; left: 16px; width: 40px; height: 40px; border: 0; border-radius: 50%; background: #fff; font-size: 24px; line-height: 1; cursor: pointer; }
