/* Components. Every visual building block used by public/js/ui/*. */

/* ---------- icons ---------- */
.icon { width: 20px; height: 20px; flex: none; display: inline-block; vertical-align: middle; }
.icon-sm { width: 16px; height: 16px; }
.icon-lg { width: 24px; height: 24px; }
.icon-xl { width: 32px; height: 32px; }
.icon-flip { transform: scaleX(-1); }

/* ---------- buttons ---------- */
.btn {
  --btn-bg: var(--surface);
  --btn-fg: var(--text);
  --btn-bd: var(--border-strong);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-3);
  height: var(--control-h);
  padding: 0 var(--sp-5);
  border-radius: var(--r-sm);
  border: 1px solid var(--btn-bd);
  background: var(--btn-bg);
  color: var(--btn-fg);
  font-size: 14px;
  font-weight: 550;
  line-height: 1;
  white-space: nowrap;
  user-select: none;
  box-shadow: var(--shadow-sm);
  transition: background-color var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease);
  text-decoration: none;
}
.btn:hover { text-decoration: none; --btn-bg: var(--surface-2); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled, .btn.is-loading { opacity: .55; pointer-events: none; }
.btn.is-loading .icon { animation: spin .8s linear infinite; }
.btn .icon { width: 18px; height: 18px; }

.btn-primary {
  --btn-bg: var(--primary);
  --btn-fg: var(--on-primary);
  --btn-bd: var(--primary);
}
.btn-primary:hover { --btn-bg: var(--primary-hover); --btn-bd: var(--primary-hover); }

.btn-secondary { --btn-bg: var(--surface); }

.btn-ghost {
  --btn-bg: transparent;
  --btn-bd: transparent;
  box-shadow: none;
}
.btn-ghost:hover { --btn-bg: var(--surface-2); }

.btn-danger {
  --btn-bg: var(--danger);
  --btn-fg: #FFFFFF;
  --btn-bd: var(--danger);
}
.btn-danger:hover { --btn-bg: #D92D20; --btn-bd: #D92D20; }
.btn-danger-ghost { --btn-fg: var(--danger-text); --btn-bd: transparent; --btn-bg: transparent; box-shadow: none; }
.btn-danger-ghost:hover { --btn-bg: var(--danger-soft); }

.btn-link {
  --btn-bg: transparent;
  --btn-bd: transparent;
  --btn-fg: var(--primary-text);
  box-shadow: none;
  height: auto;
  padding: 0;
  font-weight: 500;
}
.btn-link:hover { --btn-bg: transparent; text-decoration: underline; }

.btn-sm { height: 32px; padding: 0 var(--sp-4); font-size: 13px; }
.btn-sm .icon { width: 16px; height: 16px; }
.btn-lg { height: 44px; padding: 0 var(--sp-6); font-size: 15px; }
.btn-block { width: 100%; }

.btn-icon { width: var(--control-h); padding: 0; }
.btn-icon.btn-sm { width: 32px; }
.btn-icon.btn-ghost { color: var(--text-2); }
.btn-icon.btn-ghost:hover { color: var(--text); }

.btn-group { display: inline-flex; gap: var(--sp-2); align-items: center; flex-wrap: wrap; }

@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- form controls ---------- */
.field { display: flex; flex-direction: column; gap: var(--sp-2); min-width: 0; }
.field-label { font-size: 13px; line-height: 20px; font-weight: 550; color: var(--text); display: inline-flex; gap: var(--sp-1); align-items: baseline; }
.field-label .req { color: var(--danger-text); }
.field-label .opt { color: var(--text-3); font-weight: 400; font-size: 12px; }
.field-hint { font-size: 12px; line-height: 16px; color: var(--text-2); }
.field-error { font-size: 12px; line-height: 16px; color: var(--danger-text); display: none; }
.field.is-invalid .field-error { display: block; }
.field.is-invalid .input, .field.is-invalid .select, .field.is-invalid .textarea { border-color: var(--danger); }
.field.is-invalid .input:focus, .field.is-invalid .select:focus, .field.is-invalid .textarea:focus { box-shadow: 0 0 0 3px rgba(240, 68, 56, .2); }

.input, .select, .textarea {
  width: 100%;
  min-width: 0;
  height: var(--control-h);
  padding: 0 var(--sp-4);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-sm);
  color: var(--text);
  font-size: 14px;
  line-height: 20px;
  box-shadow: var(--shadow-sm);
  transition: border-color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
}
.input::placeholder, .textarea::placeholder { color: var(--text-3); }
.input:hover:not(:disabled), .select:hover:not(:disabled), .textarea:hover:not(:disabled) { border-color: var(--text-3); }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--primary); box-shadow: var(--focus); }
.input:disabled, .select:disabled, .textarea:disabled { background: var(--surface-2); color: var(--text-3); }
.input[dir="ltr"], .ltr-input { direction: ltr; text-align: start; }
.input.mono { font-family: var(--mono); }
.input-num { font-variant-numeric: tabular-nums; direction: ltr; text-align: start; }
.textarea { height: auto; min-height: 96px; padding: var(--sp-3) var(--sp-4); resize: vertical; line-height: 22px; }
/* chevron colour per theme: a data URI cannot read var(), so each theme keeps its own
   copy of the stroke colour (the text-2 token of that theme) in --select-chevron */
:root {
  --select-chevron: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8' width='12' height='8'%3E%3Cpath d='M1 1.5l5 5 5-5' fill='none' stroke='%234A5568' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --select-chevron: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8' width='12' height='8'%3E%3Cpath d='M1 1.5l5 5 5-5' fill='none' stroke='%23A9B4C6' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  }
}
:root[data-theme="dark"] {
  --select-chevron: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8' width='12' height='8'%3E%3Cpath d='M1 1.5l5 5 5-5' fill='none' stroke='%23A9B4C6' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
}
.select {
  appearance: none;
  padding-inline-end: 36px;
  background-image: var(--select-chevron);
  background-position: right 13px center;
  background-size: 12px 8px;
  background-repeat: no-repeat;
}
/* inline end is the left side in RTL */
[dir="rtl"] .select { background-position: left 13px center; }
.input-group { position: relative; display: flex; align-items: center; }
.input-group .input { padding-inline-end: 40px; }
.input-group > .input-adorn { position: absolute; inset-inline-end: 4px; height: 32px; width: 32px; display: grid; place-items: center; color: var(--text-2); border-radius: var(--r-sm); }
.input-group > .input-adorn:hover { background: var(--surface-2); color: var(--text); }
.input-group > .input-adorn-start { inset-inline-end: auto; inset-inline-start: 4px; }
.input-group .input.has-start { padding-inline-start: 40px; padding-inline-end: var(--sp-4); }

.input-search { position: relative; }
.input-search .icon { position: absolute; inset-inline-end: 12px; top: 50%; transform: translateY(-50%); color: var(--text-3); pointer-events: none; }
.input-search .input { padding-inline-end: 38px; }

.form-section { display: flex; flex-direction: column; gap: var(--sp-5); }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--sp-5) var(--sp-6); }
.form-grid .span-2 { grid-column: 1 / -1; }
@media (max-width: 720px) { .form-grid { grid-template-columns: minmax(0, 1fr); } }

.error-summary {
  display: flex; gap: var(--sp-3);
  background: var(--danger-soft);
  color: var(--danger-text);
  border-radius: var(--r-md);
  padding: var(--sp-4) var(--sp-5);
  font-size: 13px;
  line-height: 20px;
}
.error-summary ul { margin: 0; padding-inline-start: 0; display: flex; flex-direction: column; gap: 2px; }
.error-summary button { color: inherit; text-decoration: underline; text-align: start; }

/* switch */
.switch { display: inline-flex; align-items: center; gap: var(--sp-3); cursor: pointer; font-size: 14px; user-select: none; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; pointer-events: none; }
.switch-track {
  position: relative; width: 36px; height: 20px; border-radius: var(--r-pill);
  background: var(--border-strong); transition: background-color var(--dur-fast) var(--ease); flex: none;
}
.switch-track::after {
  content: ""; position: absolute; top: 2px; inset-inline-start: 2px; width: 16px; height: 16px; border-radius: 50%;
  background: #FFFFFF; box-shadow: var(--shadow-sm); transition: transform var(--dur-fast) var(--ease);
}
[dir="rtl"] .switch-track::after { transform: none; }
.switch input:checked + .switch-track { background: var(--primary); }
.switch input:checked + .switch-track::after { transform: translateX(-16px); }
[dir="rtl"] .switch input:checked + .switch-track::after { transform: translateX(-16px); }
.switch input:focus-visible + .switch-track { box-shadow: var(--focus); }
.switch input:disabled + .switch-track { opacity: .5; }

/* checkbox and radio */
.check { display: inline-flex; align-items: flex-start; gap: var(--sp-3); cursor: pointer; font-size: 14px; line-height: 20px; user-select: none; }
.check input { appearance: none; margin: 1px 0 0; width: 18px; height: 18px; flex: none; border: 1px solid var(--border-strong); border-radius: 5px; background: var(--surface); display: grid; place-content: center; cursor: pointer; transition: background-color var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease); }
.check input[type="radio"] { border-radius: 50%; }
.check input:checked { background: var(--primary); border-color: var(--primary); }
.check input[type="checkbox"]:checked::after {
  content: ""; width: 9px; height: 5px; border: 2px solid #FFF; border-top: 0; border-inline-end: 0; transform: rotate(-45deg) translate(1px, -1px);
}
.check input[type="radio"]:checked::after { content: ""; width: 8px; height: 8px; border-radius: 50%; background: #FFF; }
.check input:focus-visible { box-shadow: var(--focus); outline: none; }
.check.is-disabled { opacity: .55; cursor: not-allowed; }
.check .check-desc { display: block; color: var(--text-2); font-size: 12px; line-height: 16px; }

/* radio cards */
.radio-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: var(--sp-3); }
.radio-card { position: relative; display: flex; flex-direction: column; gap: var(--sp-2); padding: var(--sp-4); border: 1px solid var(--border-strong); border-radius: var(--r-md); background: var(--surface); cursor: pointer; transition: border-color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease); }
.radio-card:hover { border-color: var(--text-3); }
.radio-card input { position: absolute; opacity: 0; pointer-events: none; }
.radio-card:has(input:checked) { border-color: var(--primary); box-shadow: 0 0 0 1px var(--primary) inset; background: var(--primary-soft); }
.radio-card:has(input:focus-visible) { box-shadow: var(--focus); }
.radio-card-title { font-weight: 600; font-size: 14px; display: flex; align-items: center; gap: var(--sp-2); }
.radio-card-desc { font-size: 12px; line-height: 18px; color: var(--text-2); }

/* OTP digit boxes */
.otp { display: flex; gap: var(--sp-3); direction: ltr; justify-content: center; }
.otp-box {
  width: 48px; height: 56px; text-align: center; font-size: 22px; font-weight: 650; font-variant-numeric: tabular-nums;
  border: 1px solid var(--border-strong); border-radius: var(--r-md); background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm);
}
.otp-box:focus { outline: none; border-color: var(--primary); box-shadow: var(--focus); }
.otp-box.is-filled { border-color: var(--text-3); }
@media (max-width: 380px) { .otp { gap: 6px; } .otp-box { width: 42px; height: 50px; } }

/* ---------- cards and panels ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-sm);
  min-width: 0;
}
.card-pad { padding: var(--sp-6); }
.card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--sp-4); padding: var(--sp-5) var(--sp-6); border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.card-head-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.card-head-text p { font-size: 13px; color: var(--text-2); line-height: 20px; }
.card-body { padding: var(--sp-6); }
.card-body-flush { padding: 0; }
.card-foot { display: flex; justify-content: flex-end; gap: var(--sp-3); padding: var(--sp-4) var(--sp-6); border-top: 1px solid var(--border); background: var(--surface-2); border-radius: 0 0 var(--r-md) var(--r-md); flex-wrap: wrap; }
.card-link { color: inherit; display: block; }
a.card-link:hover { text-decoration: none; border-color: var(--border-strong); }

.kv { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: var(--sp-3) var(--sp-6); margin: 0; font-size: 13px; }
.kv dt { color: var(--text-2); }
.kv dd { margin: 0; color: var(--text); min-width: 0; overflow-wrap: anywhere; }

.list { display: flex; flex-direction: column; }
.list-item { display: flex; align-items: center; gap: var(--sp-4); padding: var(--sp-4) var(--sp-6); border-top: 1px solid var(--border); min-width: 0; }
.list-item:first-child { border-top: 0; }
.list-item-main { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.list-item-title { font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-item-sub { font-size: 12px; color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.progress { height: 8px; border-radius: var(--r-pill); background: var(--surface-2); overflow: hidden; position: relative; }
.progress-bar { height: 100%; width: 0; border-radius: inherit; background: var(--primary); transition: width var(--dur) var(--ease); }
.progress-bar.is-success { background: var(--success); }
.progress-bar.is-warning { background: var(--warning); }
.progress-bar.is-danger { background: var(--danger); }
.progress-bar.is-info { background: var(--info); }
.progress-sm { height: 4px; }

/* alerts / banners */
.alert { display: flex; gap: var(--sp-4); align-items: flex-start; padding: var(--sp-4) var(--sp-5); border-radius: var(--r-md); border: 1px solid transparent; font-size: 13px; line-height: 20px; }
.alert > .icon { margin-top: 1px; }
.alert-body { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.alert-title { font-weight: 600; font-size: 14px; }
.alert-info { background: var(--info-soft); color: var(--info-text); }
.alert-success { background: var(--success-soft); color: var(--success-text); }
.alert-warning { background: var(--warning-soft); color: var(--warning-text); }
.alert-danger { background: var(--danger-soft); color: var(--danger-text); }
.alert-neutral { background: var(--surface-2); color: var(--text-2); border-color: var(--border); }
.alert .btn { margin-inline-start: auto; }

/* ---------- badges, pills, avatars ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 6px; height: 22px; padding: 0 var(--sp-3);
  border-radius: var(--r-pill); font-size: 12px; font-weight: 550; line-height: 1; white-space: nowrap;
  background: var(--surface-2); color: var(--text-2);
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .85; }
.badge.no-dot::before { display: none; }
.badge-primary { background: var(--primary-soft); color: var(--primary-text); }
.badge-success { background: var(--success-soft); color: var(--success-text); }
.badge-warning { background: var(--warning-soft); color: var(--warning-text); }
.badge-danger { background: var(--danger-soft); color: var(--danger-text); }
.badge-info { background: var(--info-soft); color: var(--info-text); }
.badge-neutral { background: var(--surface-2); color: var(--text-2); }
.badge-count { height: 20px; min-width: 20px; padding: 0 6px; justify-content: center; font-size: 11px; background: var(--surface-2); color: var(--text-2); }
.badge-count::before { display: none; }
.badge-count.is-accent { background: var(--primary); color: var(--on-primary); }
.badge-outline { background: transparent; border: 1px solid var(--border-strong); }
.badge-mono { font-family: var(--mono); direction: ltr; font-size: 11px; }

.avatar {
  width: 32px; height: 32px; border-radius: 50%; flex: none;
  display: inline-grid; place-items: center; font-size: 12px; font-weight: 650;
  background: var(--primary-soft); color: var(--primary-text);
}
.avatar-lg { width: 44px; height: 44px; font-size: 15px; }
.avatar-sm { width: 24px; height: 24px; font-size: 10px; }

/* ---------- tables ---------- */
.table-wrap { width: 100%; overflow-x: auto; }
.table { width: 100%; font-size: 13px; }
.table th, .table td { padding: 0 var(--sp-5); height: var(--row-h); border-bottom: 1px solid var(--border); text-align: start; vertical-align: middle; }
.table th { background: var(--surface-2); font-size: 12px; line-height: 16px; font-weight: 550; color: var(--text-2); white-space: nowrap; position: sticky; top: 0; z-index: 1; }
.table th:first-child, .table td:first-child { padding-inline-start: var(--sp-6); }
.table th:last-child, .table td:last-child { padding-inline-end: var(--sp-6); }
.table td { color: var(--text); }
.table tbody tr { transition: background-color var(--dur-fast) var(--ease); }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr.is-clickable { cursor: pointer; }
.table tbody tr.is-clickable:hover, .table tbody tr.is-clickable:focus-visible { background: var(--surface-hover); }
.table tbody tr.is-clickable:focus-visible { outline: 2px solid var(--primary); outline-offset: -2px; }
.table td.num, .table th.num { font-variant-numeric: tabular-nums; }
.table th.is-numeric, .table td.is-numeric { text-align: end; }
.table th.is-sortable { cursor: pointer; user-select: none; }
.table th.is-sortable:hover { color: var(--text); }
.table .sort-ind { display: inline-block; width: 12px; color: var(--text-3); }
.table th[aria-sort] .sort-ind { color: var(--primary-text); }
.table .cell-sub { display: block; font-size: 12px; color: var(--text-2); }
.table .cell-actions { width: 48px; text-align: end; }
.table-sticky-head { max-height: 70vh; overflow: auto; }
.table .is-hidden-col { display: none; }
.table-cards { display: none; }
.table-skeleton td { padding-block: 0; }

/* responsive: below 720px each row becomes a card */
@media (max-width: 720px) {
  .dt-table { display: none; }
  .table-cards { display: flex; flex-direction: column; }
  .dt-card {
    display: flex; flex-direction: column; gap: var(--sp-3);
    padding: var(--sp-4) var(--sp-5);
    border-bottom: 1px solid var(--border);
    background: var(--surface);
  }
  .dt-card:last-child { border-bottom: 0; }
  .dt-card.is-clickable:active { background: var(--surface-hover); }
  .dt-card-head { display: flex; align-items: center; gap: var(--sp-3); min-width: 0; }
  .dt-card-title { font-weight: 600; flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .dt-card-fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--sp-3) var(--sp-4); font-size: 13px; }
  .dt-card-field { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
  .dt-card-field dt { font-size: 12px; color: var(--text-2); }
  .dt-card-field dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
  .dt-card .dt-card-actions { display: flex; justify-content: flex-end; }
}

/* toolbar, pager, filter chips */
.dt-toolbar { display: flex; align-items: center; gap: var(--sp-3); flex-wrap: wrap; padding: var(--sp-4) var(--sp-6); border-bottom: 1px solid var(--border); }
.dt-toolbar .input-search { flex: 1 1 220px; max-width: 360px; }
.dt-toolbar:not(:has(> :not(:empty))) { display: none; }
.dt-toolbar .toolbar-end { margin-inline-start: auto; display: flex; gap: var(--sp-2); align-items: center; }
.dt-footer { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-4); padding: var(--sp-3) var(--sp-6); border-top: 1px solid var(--border); flex-wrap: wrap; font-size: 13px; color: var(--text-2); }
.pager { display: inline-flex; align-items: center; gap: var(--sp-2); }
.pager .btn-icon { width: 32px; height: 32px; }
.pager-info { padding: 0 var(--sp-2); font-variant-numeric: tabular-nums; }

.chips { display: flex; gap: var(--sp-2); flex-wrap: wrap; align-items: center; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; height: 30px; padding: 0 var(--sp-3);
  border-radius: var(--r-pill); border: 1px solid var(--border-strong); background: var(--surface);
  font-size: 13px; color: var(--text-2); transition: background-color var(--dur-fast) var(--ease);
}
.chip:hover { background: var(--surface-2); color: var(--text); }
.chip[aria-pressed="true"] { background: var(--primary-soft); border-color: transparent; color: var(--primary-text); font-weight: 550; }
.chip .chip-x { width: 16px; height: 16px; display: grid; place-items: center; border-radius: 50%; }
.chip .chip-x:hover { background: var(--border-strong); }

/* ---------- tabs ---------- */
.tabs { display: flex; gap: var(--sp-6); border-bottom: 1px solid var(--border); overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab {
  position: relative; display: inline-flex; align-items: center; gap: var(--sp-2); height: 40px;
  color: var(--text-2); font-weight: 550; font-size: 14px; white-space: nowrap; border-radius: 0;
}
.tab:hover { color: var(--text); }
.tab[aria-selected="true"] { color: var(--primary-text); }
.tab[aria-selected="true"]::after { content: ""; position: absolute; inset-inline: 0; bottom: -1px; height: 2px; background: var(--primary); border-radius: 2px; }
.tab:focus-visible { outline-offset: -2px; }

.segmented { display: inline-flex; padding: 3px; background: var(--surface-2); border-radius: var(--r-sm); gap: 2px; }
.segmented button { height: 28px; padding: 0 var(--sp-3); border-radius: 4px; font-size: 13px; color: var(--text-2); font-weight: 550; display: inline-flex; align-items: center; gap: 6px; }
.segmented button[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }

/* ---------- dialog, drawer, toast ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 50; background: var(--overlay);
  display: flex; align-items: center; justify-content: center; padding: var(--sp-5);
  animation: fade-in var(--dur) var(--ease);
}
.dialog {
  width: min(520px, 100%); max-height: calc(100vh - 2 * var(--sp-5));
  display: flex; flex-direction: column;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--r-lg); box-shadow: var(--shadow-lg);
  animation: dialog-in var(--dur) var(--ease);
  outline: none;
}
.dialog.is-wide { width: min(760px, 100%); }
.dialog.is-danger .dialog-icon { background: var(--danger-soft); color: var(--danger-text); }
.dialog-head { display: flex; align-items: flex-start; gap: var(--sp-4); padding: var(--sp-6) var(--sp-6) var(--sp-4); }
.dialog-head-text { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: var(--sp-1); }
.dialog-title { font-size: 17px; line-height: 26px; font-weight: 650; }
.dialog-desc { font-size: 13px; line-height: 20px; color: var(--text-2); }
.dialog-icon { width: 40px; height: 40px; border-radius: var(--r-md); display: grid; place-items: center; background: var(--primary-soft); color: var(--primary-text); flex: none; }
.dialog-body { padding: var(--sp-2) var(--sp-6) var(--sp-6); overflow-y: auto; min-height: 0; display: flex; flex-direction: column; gap: var(--sp-5); }
.dialog-foot { display: flex; justify-content: flex-end; align-items: center; gap: var(--sp-3); padding: var(--sp-4) var(--sp-6); border-top: 1px solid var(--border); flex-wrap: wrap; }
.dialog-foot .grow { margin-inline-end: auto; }

.drawer-overlay { justify-content: flex-start; padding: 0; animation: fade-in var(--dur) var(--ease); }
.drawer {
  width: min(480px, 100vw); height: 100%;
  display: flex; flex-direction: column;
  background: var(--surface); color: var(--text);
  border-inline-start: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  animation: drawer-in var(--dur) var(--ease);
  outline: none;
}
.drawer.is-wide { width: min(720px, 100vw); }
.drawer-head { display: flex; align-items: center; gap: var(--sp-3); padding: var(--sp-5) var(--sp-6); border-bottom: 1px solid var(--border); }
.drawer-head .dialog-title { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.drawer-body { flex: 1 1 auto; overflow-y: auto; padding: var(--sp-6); display: flex; flex-direction: column; gap: var(--sp-6); min-height: 0; }
.drawer-foot { display: flex; align-items: center; gap: var(--sp-3); padding: var(--sp-4) var(--sp-6); border-top: 1px solid var(--border); background: var(--surface); flex-wrap: wrap; }
.drawer-foot .grow { margin-inline-end: auto; }

@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes dialog-in { from { opacity: 0; transform: translateY(8px) scale(.98); } to { opacity: 1; transform: none; } }
@keyframes drawer-in { from { opacity: 0; transform: translateX(-24px); } to { opacity: 1; transform: none; } }
@keyframes toast-in { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }

@media (max-width: 720px) {
  .overlay { align-items: flex-end; padding: 0; }
  .dialog { width: 100%; max-height: 92vh; border-radius: var(--r-lg) var(--r-lg) 0 0; border-bottom: 0; }
  .drawer-overlay { align-items: stretch; }
  .drawer { width: 100vw; }
}

.toasts { position: fixed; inset-block-start: var(--sp-5); inset-inline-end: var(--sp-5); z-index: 80; display: flex; flex-direction: column; gap: var(--sp-3); width: min(380px, calc(100vw - 2 * var(--sp-5))); pointer-events: none; }
.toast {
  pointer-events: auto; display: flex; gap: var(--sp-3); align-items: flex-start;
  padding: var(--sp-4); background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-md); box-shadow: var(--shadow-lg);
  animation: toast-in var(--dur) var(--ease);
}
.toast-icon { width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; flex: none; }
.toast-success .toast-icon { background: var(--success-soft); color: var(--success-text); }
.toast-error .toast-icon { background: var(--danger-soft); color: var(--danger-text); }
.toast-warning .toast-icon { background: var(--warning-soft); color: var(--warning-text); }
.toast-info .toast-icon { background: var(--info-soft); color: var(--info-text); }
.toast-body { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: 2px; font-size: 13px; line-height: 20px; }
.toast-title { font-weight: 600; font-size: 14px; }
.toast-text { color: var(--text-2); overflow-wrap: anywhere; }
.toast-close { width: 24px; height: 24px; display: grid; place-items: center; color: var(--text-3); border-radius: var(--r-sm); flex: none; }
.toast-close:hover { color: var(--text); background: var(--surface-2); }
.toast.is-leaving { opacity: 0; transform: translateY(-6px); transition: opacity var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease); }

/* ---------- menu / popover ---------- */
.menu {
  position: fixed; z-index: 60; min-width: 200px; max-width: min(300px, calc(100vw - 24px));
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-md); box-shadow: var(--shadow-lg);
  padding: var(--sp-2); display: flex; flex-direction: column; gap: 1px;
  animation: toast-in var(--dur-fast) var(--ease); outline: none;
}
.menu-label { padding: var(--sp-2) var(--sp-3) var(--sp-1); font-size: 12px; color: var(--text-2); }
.menu-item {
  display: flex; align-items: center; gap: var(--sp-3); width: 100%; min-height: 34px; padding: 0 var(--sp-3);
  border-radius: var(--r-sm); font-size: 13px; color: var(--text); text-align: start; text-decoration: none;
}
.menu-item .icon { color: var(--text-2); }
.menu-item:hover, .menu-item.is-active { background: var(--surface-2); text-decoration: none; }
.menu-item.is-danger { color: var(--danger-text); }
.menu-item.is-danger .icon { color: var(--danger-text); }
.menu-item[disabled] { opacity: .5; pointer-events: none; }
.menu-item-end { margin-inline-start: auto; color: var(--text-3); font-size: 12px; }
.menu-sep { height: 1px; background: var(--border); margin: var(--sp-2) 0; }
.menu-check { margin-inline-start: auto; color: var(--primary-text); }

/* ---------- command palette ---------- */
.palette-overlay { align-items: flex-start; padding-top: 12vh; }
.palette {
  width: min(600px, 100%); max-height: 70vh; display: flex; flex-direction: column; overflow: hidden;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); box-shadow: var(--shadow-lg);
  animation: dialog-in var(--dur) var(--ease); outline: none;
}
.palette-input-wrap { display: flex; align-items: center; gap: var(--sp-3); padding: 0 var(--sp-5); border-bottom: 1px solid var(--border); }
.palette-input { flex: 1 1 auto; height: 52px; border: 0; background: transparent; font-size: 15px; color: var(--text); outline: none; min-width: 0; }
.palette-input::placeholder { color: var(--text-3); }
.palette-list { overflow-y: auto; padding: var(--sp-2); display: flex; flex-direction: column; gap: 1px; min-height: 0; }
.palette-group { padding: var(--sp-3) var(--sp-3) var(--sp-1); font-size: 12px; color: var(--text-2); }
.palette-item { display: flex; align-items: center; gap: var(--sp-3); min-height: 40px; padding: 0 var(--sp-3); border-radius: var(--r-sm); cursor: pointer; font-size: 14px; color: var(--text); }
.palette-item .icon { color: var(--text-2); }
.palette-item.is-active { background: var(--primary-soft); color: var(--primary-text); }
.palette-item.is-active .icon { color: var(--primary-text); }
.palette-item-sub { margin-inline-start: auto; font-size: 12px; color: var(--text-3); }
.palette-foot { display: flex; gap: var(--sp-4); padding: var(--sp-3) var(--sp-5); border-top: 1px solid var(--border); font-size: 12px; color: var(--text-2); background: var(--surface-2); flex-wrap: wrap; }
.palette-empty { padding: var(--sp-8) var(--sp-5); text-align: center; color: var(--text-2); font-size: 13px; }

kbd.kbd, .kbd {
  display: inline-flex; align-items: center; justify-content: center; min-width: 20px; height: 20px; padding: 0 5px;
  border: 1px solid var(--border-strong); border-bottom-width: 2px; border-radius: 5px; background: var(--surface);
  font-size: 11px; color: var(--text-2); font-family: var(--mono); line-height: 1; direction: ltr;
}

/* ---------- stat card and sparkline ---------- */
.stat { display: flex; flex-direction: column; gap: var(--sp-3); padding: var(--sp-5) var(--sp-6); min-width: 0; }
.stat-top { display: flex; align-items: center; gap: var(--sp-3); color: var(--text-2); font-size: 13px; }
.stat-icon { width: 32px; height: 32px; border-radius: var(--r-sm); display: grid; place-items: center; background: var(--primary-soft); color: var(--primary-text); flex: none; }
.stat-icon.is-success { background: var(--success-soft); color: var(--success-text); }
.stat-icon.is-warning { background: var(--warning-soft); color: var(--warning-text); }
.stat-icon.is-danger { background: var(--danger-soft); color: var(--danger-text); }
.stat-icon.is-info { background: var(--info-soft); color: var(--info-text); }
.stat-main { display: flex; align-items: flex-end; justify-content: space-between; gap: var(--sp-3); }
.stat-value { font-size: 28px; line-height: 36px; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: 0; }
.stat-delta { font-size: 12px; font-weight: 550; display: inline-flex; align-items: center; gap: 2px; }
.stat-delta.is-up { color: var(--success-text); }
.stat-delta.is-down { color: var(--danger-text); }
.stat-hint { font-size: 12px; color: var(--text-2); }
.stat-spark { width: 96px; height: 36px; color: var(--primary); flex: none; }
.stat-spark.is-success { color: var(--success); }
.stat-spark.is-danger { color: var(--danger); }
.stat-spark path.area { fill: currentColor; opacity: .12; stroke: none; }
.stat-spark path.line { fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linejoin: round; stroke-linecap: round; }
a.stat-link { color: inherit; display: block; border-radius: var(--r-md); transition: box-shadow var(--dur-fast) var(--ease); }
a.stat-link:hover { text-decoration: none; box-shadow: var(--shadow-md); }

/* ---------- timeline and stepper ---------- */
.timeline { display: flex; flex-direction: column; }
.timeline-item { position: relative; display: grid; grid-template-columns: 28px minmax(0, 1fr); gap: var(--sp-4); padding-bottom: var(--sp-5); }
.timeline-item:last-child { padding-bottom: 0; }
.timeline-item:not(:last-child)::before { content: ""; position: absolute; inset-inline-start: 13px; top: 30px; bottom: 0; width: 1px; background: var(--border); }
.timeline-dot { width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; background: var(--surface-2); color: var(--text-2); border: 1px solid var(--border); }
.timeline-dot.is-primary { background: var(--primary-soft); color: var(--primary-text); border-color: transparent; }
.timeline-dot.is-success { background: var(--success-soft); color: var(--success-text); border-color: transparent; }
.timeline-dot.is-warning { background: var(--warning-soft); color: var(--warning-text); border-color: transparent; }
.timeline-dot.is-danger { background: var(--danger-soft); color: var(--danger-text); border-color: transparent; }
.timeline-dot .icon { width: 14px; height: 14px; }
.timeline-body { min-width: 0; display: flex; flex-direction: column; gap: 2px; padding-top: 2px; }
.timeline-title { font-size: 13px; font-weight: 550; overflow-wrap: anywhere; }
.timeline-text { font-size: 12px; color: var(--text-2); overflow-wrap: anywhere; }
.timeline-time { font-size: 12px; color: var(--text-3); }

.stepper { display: flex; align-items: center; gap: var(--sp-3); list-style: none; padding: 0; margin: 0; overflow-x: auto; }
.step { display: flex; align-items: center; gap: var(--sp-3); font-size: 13px; color: var(--text-2); white-space: nowrap; flex: none; }
.step-num { width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; font-size: 12px; font-weight: 650; background: var(--surface-2); color: var(--text-2); border: 1px solid var(--border-strong); }
.step.is-done .step-num { background: var(--success-soft); color: var(--success-text); border-color: transparent; }
.step.is-done .step-num .icon { width: 14px; height: 14px; }
.step.is-current { color: var(--text); font-weight: 600; }
.step.is-current .step-num { background: var(--primary); color: var(--on-primary); border-color: var(--primary); }
.step-line { flex: 1 1 24px; min-width: 24px; height: 2px; background: var(--border); border-radius: 2px; }
.step-line.is-done { background: var(--success); }
@media (max-width: 600px) {
  .step:not(.is-current) .step-label { display: none; }
  .step-line { min-width: 12px; }
}

/* ---------- empty state and skeleton ---------- */
.empty { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: var(--sp-3); padding: var(--sp-10) var(--sp-6); text-align: center; color: var(--text-2); }
.empty-icon { width: 56px; height: 56px; border-radius: var(--r-lg); display: grid; place-items: center; background: var(--surface-2); color: var(--text-2); border: 1px solid var(--border); margin-bottom: var(--sp-2); }
.empty-title { font-size: 15px; font-weight: 650; color: var(--text); }
.empty-text { font-size: 13px; line-height: 20px; max-width: 360px; }
.empty-action { margin-top: var(--sp-2); }
.empty-compact { padding: var(--sp-6); }
.empty-compact .empty-icon { width: 40px; height: 40px; }

.skeleton-line, .skeleton-block, .skeleton-circle {
  display: block; border-radius: var(--r-sm); background: var(--surface-2); position: relative; overflow: hidden;
}
.skeleton-line { height: 12px; width: 100%; }
.skeleton-block { height: 120px; width: 100%; border-radius: var(--r-md); }
.skeleton-circle { width: 32px; height: 32px; border-radius: 50%; flex: none; }
.skeleton-line::after, .skeleton-block::after, .skeleton-circle::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(90deg, transparent, color-mix(in srgb, var(--surface) 70%, transparent), transparent);
  transform: translateX(-100%); animation: shimmer 1.4s var(--ease) infinite;
}
@keyframes shimmer { to { transform: translateX(100%); } }
.skeleton-rows { display: flex; flex-direction: column; gap: var(--sp-4); padding: var(--sp-5) var(--sp-6); }
.skeleton-row { display: flex; align-items: center; gap: var(--sp-4); }
.skeleton-row .skeleton-line { flex: 1 1 auto; }

/* ---------- page header ---------- */
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--sp-4) var(--sp-6); flex-wrap: wrap; }
.page-head-text { min-width: 0; flex: 1 1 320px; display: flex; flex-direction: column; gap: var(--sp-1); }
.page-desc { font-size: 13px; line-height: 20px; color: var(--text-2); max-width: 720px; }
.page-actions { display: flex; gap: var(--sp-3); align-items: center; flex-wrap: wrap; }
.page-section-head { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); flex-wrap: wrap; }
.page-section-head h2 { font-size: 15px; font-weight: 650; }

/* ---------- copy field ---------- */
.copy-field { display: flex; align-items: stretch; gap: 0; width: 100%; min-width: 0; border: 1px solid var(--border-strong); border-radius: var(--r-sm); background: var(--surface-2); overflow: hidden; }
.copy-field-value { flex: 1 1 auto; min-width: 0; padding: 0 var(--sp-4); display: flex; align-items: center; font-family: var(--mono); font-size: 13px; direction: ltr; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; height: var(--control-h); user-select: all; }
.copy-field-value.is-text { font-family: var(--font); direction: rtl; }
.copy-field-btn { display: inline-flex; align-items: center; gap: var(--sp-2); padding: 0 var(--sp-4); border-inline-start: 1px solid var(--border-strong); font-size: 13px; color: var(--text-2); background: var(--surface); flex: none; }
.copy-field-btn:hover { color: var(--text); background: var(--surface-2); }
.copy-field-btn.is-copied { color: var(--success-text); }

/* ---------- file drop ---------- */
.file-drop {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: var(--sp-2);
  padding: var(--sp-8) var(--sp-6); text-align: center; border: 1.5px dashed var(--border-strong); border-radius: var(--r-md);
  background: var(--surface-2); color: var(--text-2); cursor: pointer; transition: border-color var(--dur-fast) var(--ease), background-color var(--dur-fast) var(--ease);
}
.file-drop:hover, .file-drop.is-over { border-color: var(--primary); background: var(--primary-soft); color: var(--text); }
.file-drop:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.file-drop input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.file-drop-title { font-weight: 600; color: var(--text); font-size: 14px; }
.file-drop-meta { font-size: 12px; }
.file-drop.has-file { border-style: solid; padding: var(--sp-4) var(--sp-5); text-align: start; flex-direction: column; align-items: stretch; background: var(--surface); }
.file-drop-file { display: flex; align-items: center; gap: var(--sp-3); }
.file-drop-file .file-drop-icon { width: 36px; height: 36px; border-radius: var(--r-sm); display: grid; place-items: center; background: var(--primary-soft); color: var(--primary-text); flex: none; }
.file-drop-file-text { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; }
.file-drop-file-text b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 550; }
.file-drop-file .progress { margin-top: var(--sp-3); }
.file-drop.is-disabled { opacity: .6; pointer-events: none; }
.file-drop-wrap { position: relative; }

/* ---------- auth-only pieces ---------- */
.brand-mark {
  width: 32px; height: 32px; border-radius: 9px; display: grid; place-items: center; flex: none;
  background: var(--brand-gradient); color: #FFFFFF; font-weight: 700; font-size: 16px; box-shadow: var(--shadow-sm);
}
.brand-mark.is-lg { width: 44px; height: 44px; border-radius: 12px; font-size: 22px; }
.brand-name { font-weight: 700; font-size: 15px; line-height: 20px; }
.brand-sub { font-size: 12px; color: var(--text-2); line-height: 16px; }

/* ---------- misc ---------- */
.divider { height: 1px; background: var(--border); border: 0; margin: 0; }
.divider-v { width: 1px; align-self: stretch; background: var(--border); }
.tag-list { display: flex; flex-wrap: wrap; gap: var(--sp-2); }
.pill-count { font-variant-numeric: tabular-nums; }
.meter { display: flex; flex-direction: column; gap: var(--sp-2); }
.meter-head { display: flex; justify-content: space-between; font-size: 12px; color: var(--text-2); }
.dot-status { width: 8px; height: 8px; border-radius: 50%; display: inline-block; background: var(--text-3); }
.dot-status.is-success { background: var(--success); }
.dot-status.is-danger { background: var(--danger); }
.dot-status.is-warning { background: var(--warning); }
.dot-status.is-primary { background: var(--primary); }
.loading-line { display: flex; align-items: center; gap: var(--sp-3); color: var(--text-2); font-size: 13px; padding: var(--sp-6); }
.loading-line .icon { animation: spin .8s linear infinite; }

/* jalali date input: year, month, day */
.jalali-date { display: grid; grid-template-columns: 1.1fr 1.5fr 1fr; gap: var(--sp-3); min-width: 0; }
.jalali-date .input-num { text-align: center; }
html.is-locked { overflow: hidden; }
.input-adorn-wrap { position: absolute; inset-inline-end: 4px; top: 50%; transform: translateY(-50%); display: flex; }
.input-adorn-wrap.input-adorn-start { inset-inline-end: auto; inset-inline-start: 4px; }
.input-group .input-adorn { position: absolute; top: 50%; transform: translateY(-50%); inset-inline-end: 4px; height: 32px; width: 32px; display: grid; place-items: center; color: var(--text-2); border-radius: var(--r-sm); }
.input-group .input-adorn:hover { background: var(--surface-2); color: var(--text); }
.input-group .input-adorn-wrap .btn { height: 32px; }
.input-group .input-adorn-wrap .btn-icon { width: 32px; }

/* ---------- additions used by the reference views and helpers ---------- */
.progress-bar { width: var(--pct, 0%); }
.progress-bar.is-danger { background: var(--danger); }
.stat-text { display: flex; flex-direction: column; gap: var(--sp-2); min-width: 0; }
.skeleton-line.is-short, .skeleton-line.short { width: 60%; }
.skeleton-line.is-title { height: 22px; width: 260px; max-width: 70%; }
.dt-table .table th { width: var(--col-w, auto); }
.chip-group { display: inline-flex; align-items: center; gap: var(--sp-2); flex-wrap: wrap; }
.chip-group + .chip-group { margin-inline-start: var(--sp-3); padding-inline-start: var(--sp-3); border-inline-start: 1px solid var(--border); }
.chip-group-label { color: var(--text-3); margin-inline-end: var(--sp-1); }
.dt-filters { display: flex; flex-wrap: wrap; gap: var(--sp-2) 0; }
.dt-filters[hidden] { display: none; }
.otp-wrap { display: flex; flex-direction: column; gap: var(--sp-4); }
.ltr-field .input, .ltr-field input { direction: ltr; text-align: start; }
.hidden-kpi { display: none; }
.list-item-main a, a.list-item-main { color: inherit; }
a.list-item-main:hover { text-decoration: none; }
.list-item:has(a.list-item-main):hover { background: var(--surface-hover); }
.list-item-main[href] { flex: 1 1 auto; }
.list-item .badge { flex: none; }
.text-end { text-align: end; }
.async-slot { min-width: 0; }
.plan-card { padding: var(--sp-6); display: flex; flex-direction: column; gap: var(--sp-5); background: linear-gradient(180deg, var(--surface) 0%, var(--surface) 60%); }
.plan-card-main { display: flex; justify-content: space-between; align-items: flex-start; gap: var(--sp-5); flex-wrap: wrap; }
.plan-name { font-size: 22px; line-height: 30px; font-weight: 700; }
.plan-card-side { display: flex; align-items: center; }
.plan-days { display: flex; flex-direction: column; align-items: center; min-width: 96px; padding: var(--sp-3) var(--sp-5); border-radius: var(--r-md); background: var(--surface-2); border: 1px solid var(--border); }
.plan-days-value { font-size: 28px; line-height: 36px; font-weight: 700; font-variant-numeric: tabular-nums; }
.plan-card-foot { display: flex; flex-direction: column; gap: var(--sp-3); }
.stat-main .stat-text .stat-delta { margin-top: 0; }
.stat-value { white-space: nowrap; }

/* ltr inputs inside an RTL group: the adornment sits on the left, so the padding must too */
.input-group .input[dir="ltr"] { padding-inline-start: 40px; padding-inline-end: var(--sp-4); }
.input-group > .input-adorn { inset-inline-end: 4px; }
