/* ==========================================================================
   De Ticketshop — component styles
   --------------------------------------------------------------------------
   Rendered by the components in ui.js / charts.js, but usable directly too.

   Icon            .icon
   Button          .btn  + .btn-primary|secondary|ghost|danger|subtle  + .btn-sm|btn-lg
                   + .btn-block  .btn-icon (square)  .is-loading  .btn-spinner
   IconButton      .icon-btn (+ .icon-btn-sm)
   Field           .field  .field-label  .field-label-row  .field-req  .field-opt  .field-hint  .field-error
                   .field-row (2 cols → 1 on mobile)  .field-row-3
   Input           .input (wrapper) > input   .input-icon  .input-prefix  .input-suffix
                   .is-invalid  .is-disabled   .input-lg  .input-sm
   Textarea        .textarea
   Select          .select (wrapper) > select + .select-chevron
   Toggle          .toggle  .toggle-track  .toggle-thumb  .toggle-text
   Checkbox        .checkbox  .checkbox-box
   RadioCards      .radio-cards  .radio-card  .is-selected  .radio-card-icon  .radio-card-check
   MoneyInput      .input.money-input
   DateTimeInput   .datetime-input
   NumberStepper   .stepper  .stepper-btn  .stepper-value
   SearchInput     .input.search-input  .search-clear
   Segmented       .segmented  .segmented-item  .segmented-indicator  .is-active
   Card            .card  .card-header  .card-title  .card-subtitle  .card-actions  .card-body
                   .card-footer  .card-flush (no body padding)  .card-hover (interactive)
   Badge           .badge  .badge-neutral|success|warning|danger|info|brand  .badge-dot  .badge-lg
   Tabs            .tabs  .tab  .is-active  .tab-count   [data-compact] (icons hidden)  [data-fade=start|end|both]
   Overlay/Modal   .overlay  .modal-root  .modal  .modal-sm|md|lg|xl  .modal-header  .modal-title
                   .modal-description  .modal-body  .modal-footer  .modal-close   [data-state=open]
   Drawer          .drawer-root  .drawer  .drawer-header  .drawer-body  .drawer-footer
   Toast           .toast-stack(.[data-lifted])  .toast  .toast-icon  .toast-title  .toast-desc  .toast-close
                   --toast-offset: extra space below the stack (set it on body/:root for a bottom bar);
                   the stack also lifts itself above an open Modal/Drawer footer (see toast() in ui.js)
   Confirm         .confirm-icon
   Table           .table-wrap(.is-fit|.has-max-h)  .table  .table-compact  th/td  .is-clickable  .is-selected
                   .align-right|center  .hide-sm|md|lg (column hiding)  td.is-wrap (cells are nowrap by default)
                   .table-empty  .table-sort  .cell-primary (bold first line)  .cell-sub (muted second line)  .cell-clip
   EmptyState      .empty  .empty-icon  .empty-title  .empty-desc  .empty-actions  .empty-compact
   Stat            .stat  .stat-top  .stat-label  .stat-label-icon  .stat-main  .stat-value  .stat-foot
                   .stat-delta(.is-up|.is-down|.is-flat)  .stat-delta-label  .stat-hint  .stat-spark (hidden < 250px)
   Progress        .progress  .progress-track  .progress-bar  .progress-sm|lg  .progress-label
   Skeleton        .skeleton
   Spinner         .spinner
   CopyField       .copy-field  .copy-field-value  .copy-field-btn
   Dropdown        .dropdown  .menu  .menu-item  .menu-item-hint  .menu-label  .menu-divider  .is-danger  .is-active
                   (.menu is portalled; opened inside a Drawer/Modal it gets an inline z-index above that layer)
   Avatar          .avatar
   PageHeader      .page-header  .page-back  .page-title  .page-subtitle  .page-meta  .page-actions
   Pagination      .pagination  .pagination-pages  .page-btn  .is-current
   ImageUpload     .image-upload  .image-drop  .image-preview  .image-actions  .is-dragging
   QRCode          .qr
   Kbd             .kbd
   Tooltip         .tooltip-pop (singleton, positioned by JS)
   Alert           .alert  .alert-info|success|warning|danger|neutral  .alert-title
   DescriptionList .dl  .dl-row  .dl-label  .dl-value
   Charts          .chart  .chart-svg  .chart-tooltip  .chart-legend  .legend-item  .chart-empty
                   .donut  .donut-center  .sparkline  .bar-chart
   ========================================================================== */

/* Icon ------------------------------------------------------------------------ */
.icon { display: inline-block; vertical-align: middle; flex-shrink: 0; stroke: currentColor; fill: none; stroke-linecap: round; stroke-linejoin: round; }
.icon-spin { animation: dts-spin .8s linear infinite; }

/* Button ---------------------------------------------------------------------- */
.btn {
  --btn-h: var(--control-h);
  position: relative;
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  height: var(--btn-h); padding: 0 14px;
  font-size: var(--text-base); font-weight: 540; line-height: 1; letter-spacing: -0.006em;
  white-space: nowrap; text-decoration: none !important; user-select: none;
  border-radius: var(--radius); border: 1px solid transparent;
  transition: background-color var(--dur-fast) ease, border-color var(--dur-fast) ease,
              color var(--dur-fast) ease, box-shadow var(--dur-fast) ease, transform 80ms ease;
  cursor: pointer; flex-shrink: 0;
}
.btn:focus-visible { outline: none; box-shadow: var(--shadow-focus); }
.btn:active:not(:disabled):not(.is-disabled) { transform: translateY(.5px) scale(.99); }
.btn .icon { margin: 0 -2px; }

.btn-primary {
  background: var(--accent); color: var(--accent-contrast); border-color: var(--accent-hover);
  box-shadow: 0 1px 2px rgba(6, 60, 55, .18), inset 0 1px 0 rgba(255, 255, 255, .14);
}
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:active { background: var(--accent-active); }
.btn-primary:focus-visible { box-shadow: var(--shadow-focus), inset 0 1px 0 rgba(255,255,255,.14); }

.btn-secondary {
  background: var(--surface); color: var(--text); border-color: var(--border-strong);
  box-shadow: var(--shadow-xs);
}
.btn-secondary:hover { background: var(--surface-2); border-color: var(--ink-300); }
.btn-secondary:active { background: var(--surface-3); }
.theme-dark .btn-secondary:hover { border-color: #3A4658; }

.btn-ghost { background: transparent; color: var(--text-secondary); }
.btn-ghost:hover { background: var(--surface-3); color: var(--text); }
.btn-ghost:active { background: var(--ink-200); }
.theme-dark .btn-ghost:active { background: var(--border-strong); }

.btn-subtle { background: var(--accent-soft); color: var(--accent-text); }
.btn-subtle:hover { background: var(--accent-soft-hover); }

.btn-danger {
  background: var(--danger); color: #fff; border-color: var(--danger-hover);
  box-shadow: 0 1px 2px rgba(120, 20, 20, .16), inset 0 1px 0 rgba(255, 255, 255, .12);
}
.btn-danger:hover { background: var(--danger-hover); }
.btn-danger:focus-visible { box-shadow: var(--shadow-focus-danger), inset 0 1px 0 rgba(255,255,255,.12); }

.btn-sm { --btn-h: var(--control-h-sm); padding: 0 10px; font-size: var(--text-sm); gap: 6px; border-radius: 7px; }
.btn-lg { --btn-h: var(--control-h-lg); padding: 0 18px; font-size: var(--text-md); gap: 8px; border-radius: 10px; }
.btn-block { display: flex; width: 100%; }
.btn-icon { width: var(--btn-h); padding: 0; }

.btn:disabled, .btn.is-disabled { opacity: .5; cursor: not-allowed; box-shadow: none; pointer-events: none; }
.btn.is-loading { color: transparent !important; pointer-events: none; opacity: 1 !important; cursor: progress; }
.btn.is-loading > :not(.btn-spinner) { visibility: hidden; }
.btn-spinner { position: absolute; inset: 0; display: grid; place-items: center; }
.btn-primary .btn-spinner, .btn-danger .btn-spinner { color: var(--accent-contrast); }
.btn-danger .btn-spinner { color: #fff; }
.btn-secondary .btn-spinner, .btn-ghost .btn-spinner { color: var(--text-muted); }
.btn-subtle .btn-spinner { color: var(--accent-text); }

/* Icon button -------------------------------------------------------------- */
.icon-btn {
  display: inline-grid; place-items: center; width: 32px; height: 32px; border-radius: var(--radius);
  color: var(--text-muted); background: transparent; border: 1px solid transparent;
  transition: background-color var(--dur-fast) ease, color var(--dur-fast) ease, border-color var(--dur-fast) ease;
  flex-shrink: 0;
}
.icon-btn:hover { background: var(--surface-3); color: var(--text); }
.icon-btn:focus-visible { outline: none; box-shadow: var(--shadow-focus); }
.icon-btn:disabled { opacity: .45; }
.icon-btn-sm { width: 26px; height: 26px; border-radius: 6px; }
.icon-btn-lg { width: 40px; height: 40px; border-radius: 10px; }
.icon-btn.is-secondary { background: var(--surface); border-color: var(--border-strong); box-shadow: var(--shadow-xs); color: var(--text-secondary); }
.icon-btn.is-secondary:hover { background: var(--surface-2); }
.icon-btn.is-danger:hover { background: var(--danger-soft); color: var(--danger-text); }
.icon-btn.is-primary { background: var(--accent); color: var(--accent-contrast); }
.icon-btn.is-primary:hover { background: var(--accent-hover); }

/* Field ------------------------------------------------------------------------ */
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field-label {
  display: flex; align-items: baseline; gap: 6px;
  font-size: var(--text-sm); font-weight: 560; color: var(--text-secondary); line-height: 1.3;
}
.field-req { color: var(--danger); font-weight: 600; }
.field-opt { color: var(--text-subtle); font-weight: 450; font-size: var(--text-xs); }
.field-hint { font-size: 12.5px; color: var(--text-muted); line-height: 1.45; }
.field-label-row { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.field-label-row .field-label { flex: 1; min-width: 0; }
.field-error {
  display: flex; align-items: flex-start; gap: 6px;
  font-size: 12.5px; color: var(--danger-text); line-height: 1.4; font-weight: 500;
  animation: dts-rise-in var(--dur) var(--ease-out);
}
.field-error .icon { margin-top: 1px; }
.field-row { display: grid; gap: 16px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.field-row-3 { display: grid; gap: 16px; grid-template-columns: repeat(3, minmax(0, 1fr)); }
@media (max-width: 640px) { .field-row, .field-row-3 { grid-template-columns: minmax(0, 1fr); } }

/* Input ------------------------------------------------------------------------ */
.input {
  position: relative; display: flex; align-items: center; min-width: 0;
  height: var(--control-h);
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border-strong); border-radius: var(--radius);
  box-shadow: var(--shadow-xs);
  transition: border-color var(--dur-fast) ease, box-shadow var(--dur-fast) ease, background-color var(--dur-fast) ease;
}
.input:hover { border-color: var(--ink-300); }
.theme-dark .input:hover { border-color: #3A4658; }
.input:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-ring); }
.input > input, .input > .input-el {
  flex: 1 1 auto; min-width: 0; width: 100%; height: 100%;
  padding: 0 11px; border: 0; outline: 0; background: transparent;
  font-size: var(--text-base); color: inherit;
}
.input > input[type='number'] { font-variant-numeric: tabular-nums; }
.input > input::-webkit-outer-spin-button, .input > input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.input > input[type='number'] { -moz-appearance: textfield; appearance: textfield; }
.input > input[type='date'], .input > input[type='time'] { font-variant-numeric: tabular-nums; min-width: 0; }
.input > input[type='date']::-webkit-calendar-picker-indicator,
.input > input[type='time']::-webkit-calendar-picker-indicator { opacity: .55; cursor: pointer; }
.input-icon { display: grid; place-items: center; padding-left: 11px; color: var(--icon-subtle); pointer-events: none; }
.input-icon + input { padding-left: 8px; }
.input-prefix, .input-suffix {
  display: flex; align-items: center; align-self: stretch; padding: 0 11px;
  color: var(--text-muted); font-size: var(--text-sm); white-space: nowrap; user-select: none;
}
.input-prefix { padding-right: 0; }
.input-prefix + input { padding-left: 6px; }
.input-suffix { padding-left: 0; }
.input-prefix.is-boxed { background: var(--surface-2); border-right: 1px solid var(--border); padding-right: 11px; border-radius: var(--radius) 0 0 var(--radius); }
.input-prefix.is-boxed + input { padding-left: 10px; }
.input-suffix.is-boxed { background: var(--surface-2); border-left: 1px solid var(--border); padding-left: 11px; border-radius: 0 var(--radius) var(--radius) 0; }
.input-sm { height: var(--control-h-sm); }
.input-sm > input { font-size: var(--text-sm); padding: 0 9px; }
.input-lg { height: var(--control-h-lg); border-radius: 10px; }
.input-lg > input { font-size: var(--text-md); padding: 0 14px; }
.input.is-invalid { border-color: var(--danger); }
.input.is-invalid:focus-within { box-shadow: 0 0 0 3px var(--danger-ring); }
.input.is-disabled { background: var(--surface-2); color: var(--text-muted); box-shadow: none; cursor: not-allowed; }
.input.is-disabled > input { cursor: not-allowed; }
.input.is-readonly { background: var(--surface-2); }
.input .icon-btn { width: 28px; height: 28px; margin-right: 3px; }

/* Textarea ------------------------------------------------------------------ */
.textarea {
  display: block; width: 100%; min-height: 96px; padding: 9px 11px;
  font-size: var(--text-base); line-height: 1.55; color: var(--text);
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--radius);
  box-shadow: var(--shadow-xs); resize: vertical; outline: 0;
  transition: border-color var(--dur-fast) ease, box-shadow var(--dur-fast) ease;
}
.textarea:hover { border-color: var(--ink-300); }
.textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-ring); }
.textarea.is-invalid { border-color: var(--danger); }
.textarea.is-invalid:focus { box-shadow: 0 0 0 3px var(--danger-ring); }
.textarea:disabled { background: var(--surface-2); color: var(--text-muted); }

/* Select ------------------------------------------------------------------------ */
.select { position: relative; display: flex; align-items: center; min-width: 0; }
.select > select {
  appearance: none; -webkit-appearance: none; width: 100%; height: var(--control-h);
  padding: 0 34px 0 11px; font-size: var(--text-base); color: var(--text);
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--radius);
  box-shadow: var(--shadow-xs); cursor: pointer; outline: 0; text-overflow: ellipsis;
  transition: border-color var(--dur-fast) ease, box-shadow var(--dur-fast) ease;
}
.select > select:hover { border-color: var(--ink-300); }
.select > select:focus-visible { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-ring); }
.select > select:disabled { background: var(--surface-2); color: var(--text-muted); cursor: not-allowed; }
.select.is-invalid > select { border-color: var(--danger); }
.select-sm > select { height: var(--control-h-sm); font-size: var(--text-sm); padding-left: 9px; padding-right: 30px; }
.select-chevron { position: absolute; right: 10px; color: var(--icon-subtle); pointer-events: none; }
.select-sm .select-chevron { right: 8px; }

/* Toggle ------------------------------------------------------------------------ */
.toggle { display: inline-flex; align-items: flex-start; gap: 12px; cursor: pointer; user-select: none; min-width: 0; }
.toggle.is-disabled { cursor: not-allowed; opacity: .55; }
.toggle input { position: absolute; opacity: 0; width: 1px; height: 1px; pointer-events: none; }
.toggle-track {
  position: relative; flex-shrink: 0; width: 36px; height: 20px; margin-top: 1px;
  border-radius: 999px; background: var(--ink-300);
  transition: background-color var(--dur) var(--ease-out), box-shadow var(--dur-fast) ease;
  box-shadow: inset 0 1px 2px rgba(16,24,40,.12);
}
.theme-dark .toggle-track { background: #334052; }
.toggle-thumb {
  position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgba(16,24,40,.25), 0 1px 1px rgba(16,24,40,.08);
  transition: transform var(--dur) var(--ease-out);
}
.toggle input:checked + .toggle-track { background: var(--accent); }
.toggle input:checked + .toggle-track .toggle-thumb { transform: translateX(16px); }
.toggle input:focus-visible + .toggle-track { box-shadow: var(--shadow-focus); }
.toggle-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.toggle-label { font-weight: 540; color: var(--text); line-height: 1.4; }
.toggle-desc { font-size: var(--text-sm); color: var(--text-muted); line-height: 1.45; }
.toggle-sm .toggle-track { width: 30px; height: 17px; }
.toggle-sm .toggle-thumb { width: 13px; height: 13px; }
.toggle-sm input:checked + .toggle-track .toggle-thumb { transform: translateX(13px); }

/* Checkbox -------------------------------------------------------------------- */
.checkbox { display: inline-flex; align-items: flex-start; gap: 10px; cursor: pointer; user-select: none; min-width: 0; }
.checkbox.is-disabled { opacity: .55; cursor: not-allowed; }
.checkbox input { position: absolute; opacity: 0; width: 1px; height: 1px; pointer-events: none; }
.checkbox-box {
  flex-shrink: 0; display: grid; place-items: center; width: 17px; height: 17px; margin-top: 1.5px;
  border-radius: 5px; border: 1px solid var(--border-strong); background: var(--surface);
  box-shadow: var(--shadow-xs); color: transparent;
  transition: background-color var(--dur-fast) ease, border-color var(--dur-fast) ease, box-shadow var(--dur-fast) ease;
}
.checkbox:hover .checkbox-box { border-color: var(--ink-400); }
.checkbox input:checked + .checkbox-box, .checkbox input:indeterminate + .checkbox-box {
  background: var(--accent); border-color: var(--accent); color: var(--accent-contrast);
}
.checkbox input:focus-visible + .checkbox-box { box-shadow: var(--shadow-focus); }
.checkbox-label { line-height: 1.45; color: var(--text); }
.checkbox-desc { display: block; font-size: var(--text-sm); color: var(--text-muted); }

/* Radio cards ---------------------------------------------------------------- */
.radio-cards { display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.radio-cards.has-cols { grid-template-columns: repeat(var(--cols), minmax(0, 1fr)); }
@media (max-width: 640px) { .radio-cards.has-cols { grid-template-columns: minmax(0, 1fr); } }
.radio-card {
  position: relative; display: flex; align-items: flex-start; gap: 12px; padding: 14px 14px 14px 14px;
  text-align: left; background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xs); cursor: pointer; color: var(--text);
  transition: border-color var(--dur-fast) ease, box-shadow var(--dur-fast) ease, background-color var(--dur-fast) ease;
}
.radio-card:hover { border-color: var(--ink-300); background: var(--surface-2); }
.radio-card:focus-visible { outline: none; box-shadow: var(--shadow-focus); }
.radio-card.is-selected { border-color: var(--accent); background: var(--surface); box-shadow: 0 0 0 1px var(--accent), var(--shadow-sm); }
.radio-card.is-selected:focus-visible { box-shadow: 0 0 0 1px var(--accent), var(--shadow-focus); }
.radio-card.is-disabled { opacity: .5; cursor: not-allowed; }
.radio-card-icon {
  flex-shrink: 0; display: grid; place-items: center; width: 34px; height: 34px; border-radius: 9px;
  background: var(--surface-3); color: var(--text-muted);
  transition: background-color var(--dur-fast) ease, color var(--dur-fast) ease;
}
.radio-card.is-selected .radio-card-icon { background: var(--accent-soft); color: var(--accent-text); }
.radio-card-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; padding-right: 22px; }
.radio-card-label { font-weight: 580; line-height: 1.35; }
.radio-card-desc { font-size: var(--text-sm); color: var(--text-muted); line-height: 1.45; }
.radio-card-check {
  position: absolute; top: 12px; right: 12px; display: grid; place-items: center; width: 18px; height: 18px;
  border-radius: 50%; border: 1px solid var(--border-strong); background: var(--surface); color: transparent;
  transition: all var(--dur-fast) ease;
}
.radio-card.is-selected .radio-card-check { background: var(--accent); border-color: var(--accent); color: var(--accent-contrast); }

/* Money / datetime / stepper --------------------------------------------- */
.money-input > input { font-variant-numeric: tabular-nums; }
.datetime-input { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr); gap: 8px; }
.datetime-input .input > input { padding-right: 8px; }

.stepper {
  display: inline-flex; width: max-content; max-width: 100%; align-self: flex-start; align-items: stretch; height: var(--control-h);
  border: 1px solid var(--border-strong); border-radius: var(--radius); background: var(--surface);
  box-shadow: var(--shadow-xs); overflow: hidden;
}
.stepper:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-ring); }
.stepper-btn {
  display: grid; place-items: center; width: 34px; color: var(--text-secondary);
  transition: background-color var(--dur-fast) ease, color var(--dur-fast) ease;
}
.stepper-btn:hover:not(:disabled) { background: var(--surface-3); color: var(--text); }
.stepper-btn:disabled { color: var(--icon-subtle); opacity: .5; }
.stepper-value {
  width: 48px; border: 0; border-left: 1px solid var(--border); border-right: 1px solid var(--border);
  text-align: center; font-weight: 600; font-variant-numeric: tabular-nums; outline: 0; background: transparent;
  -moz-appearance: textfield; appearance: textfield;
}
.stepper-value::-webkit-outer-spin-button, .stepper-value::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.stepper-lg { height: 44px; border-radius: 10px; }
.stepper-lg .stepper-btn { width: 44px; }
.stepper-lg .stepper-value { width: 52px; font-size: var(--text-lg); }

.search-input { min-width: 220px; }
.search-input > input::-webkit-search-cancel-button, .search-input > input::-webkit-search-decoration { -webkit-appearance: none; appearance: none; }
.search-input .input-suffix .kbd { margin-right: -2px; }
@media (max-width: 640px) { .search-input { min-width: 0; } }
.search-clear { margin-right: 4px; }

/* Segmented control ------------------------------------------------------- */
.segmented {
  position: relative; display: inline-flex; align-items: center; padding: 3px; gap: 2px;
  background: var(--surface-3); border-radius: 9px; box-shadow: inset 0 0 0 1px rgba(15, 23, 42, .04);
  isolation: isolate; max-width: 100%; overflow-x: auto; scrollbar-width: none;
}
.segmented::-webkit-scrollbar { display: none; }
.segmented-item {
  position: relative; z-index: 1; display: inline-flex; align-items: center; gap: 6px; height: 28px; padding: 0 12px;
  font-size: var(--text-sm); font-weight: 540; color: var(--text-muted); border-radius: 7px; white-space: nowrap;
  transition: color var(--dur-fast) ease;
}
.segmented-item:hover { color: var(--text); }
.segmented-item.is-active { color: var(--text); }
.segmented-item:focus-visible { outline: none; box-shadow: var(--shadow-focus); }
.segmented-indicator {
  position: absolute; z-index: 0; top: 3px; bottom: 3px; left: 0; border-radius: 7px;
  background: var(--surface); box-shadow: 0 1px 2px rgba(16,24,40,.08), 0 0 0 1px rgba(16,24,40,.04);
  transition: transform var(--dur-slow) var(--ease-out), width var(--dur-slow) var(--ease-out);
}
.theme-dark .segmented { background: #0D121A; box-shadow: inset 0 0 0 1px var(--border); }
.theme-dark .segmented-indicator { background: #263042; box-shadow: 0 1px 2px rgba(0,0,0,.4), inset 0 1px 0 rgba(255,255,255,.05); }
.segmented-sm .segmented-item { height: 24px; padding: 0 9px; font-size: var(--text-xs); }
.segmented.is-block { display: flex; width: 100%; }
.segmented.is-block .segmented-item { flex: 1; justify-content: center; }

/* Card ---------------------------------------------------------------------------- */
.card {
  position: relative; min-width: 0;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xs);
}
.card-header {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 10px 12px; flex-wrap: wrap;
  padding: 16px 20px 0;
}
.card-header.has-border { padding-bottom: 14px; border-bottom: 1px solid var(--border-subtle); }
.card-heading { display: flex; flex-direction: column; gap: 2px; min-width: 0; flex: 1 1 180px; }
.card-title { font-size: var(--text-md); font-weight: 600; letter-spacing: var(--tracking-snug); line-height: 1.4; color: var(--text); }
.card-subtitle { font-size: var(--text-sm); color: var(--text-muted); line-height: 1.45; }
.card-actions { display: flex; align-items: center; gap: 8px; flex-shrink: 0; margin: -3px 0; flex-wrap: wrap; max-width: 100%; }
@media (max-width: 640px) { .card-actions .search-input { flex: 1 1 160px; } }
.card-body { padding: 16px 20px 20px; }
.card-header + .card-body { padding-top: 14px; }
.card-header.has-border + .card-body { padding-top: 18px; }
.card-flush > .card-body, .card-body.p-0 { padding: 0; }
.card-header + .card-flush-body, .card-flush-body { padding: 12px 0 0; }
.card-footer {
  display: flex; align-items: center; justify-content: flex-end; gap: 8px;
  padding: 12px 20px; border-top: 1px solid var(--border-subtle); background: var(--surface-2);
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}
.card-hover { transition: border-color var(--dur-fast) ease, box-shadow var(--dur) ease, transform var(--dur) var(--ease-out); cursor: pointer; }
.card-hover:hover { border-color: var(--border-strong); box-shadow: var(--shadow-md); }
.card-section + .card-section { border-top: 1px solid var(--border-subtle); }
@media (max-width: 640px) {
  .card-header { padding: 14px 16px 0; }
  .card-body { padding: 14px 16px 16px; }
  .card-footer { padding: 12px 16px; }
}

/* Badge ------------------------------------------------------------------------------ */
.badge {
  --badge-bg: var(--neutral-soft); --badge-fg: var(--neutral-text); --badge-ring: var(--neutral-ring);
  display: inline-flex; align-items: center; gap: 5px; height: 22px; padding: 0 8px;
  font-size: var(--text-xs); font-weight: 560; line-height: 1; white-space: nowrap; letter-spacing: 0;
  color: var(--badge-fg); background: var(--badge-bg); border-radius: 999px;
  box-shadow: inset 0 0 0 1px var(--badge-ring);
  font-variant-numeric: tabular-nums;
}
.badge .icon { margin-left: -2px; }
.badge-dot::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; margin-left: -1px; }
.badge-success { --badge-bg: var(--success-soft); --badge-fg: var(--success-text); --badge-ring: var(--success-ring); }
.badge-warning { --badge-bg: var(--warning-soft); --badge-fg: var(--warning-text); --badge-ring: var(--warning-ring); }
.badge-danger { --badge-bg: var(--danger-soft); --badge-fg: var(--danger-text); --badge-ring: var(--danger-ring); }
.badge-info { --badge-bg: var(--info-soft); --badge-fg: var(--info-text); --badge-ring: var(--info-ring); }
.badge-brand { --badge-bg: var(--accent-soft); --badge-fg: var(--accent-text); --badge-ring: rgba(34, 181, 166, .28); }
.badge-solid { --badge-bg: var(--ink-900); --badge-fg: #fff; --badge-ring: transparent; }
.badge-lg { height: 26px; padding: 0 10px; font-size: var(--text-sm); }
.badge-sm { height: 18px; padding: 0 6px; font-size: var(--text-2xs); }

/* Tabs ------------------------------------------------------------------------------ */
.tabs {
  /* Baseline as an inset shadow (not a border) so the 2px active underline sits inside the
     horizontally scrolling box instead of being clipped by it. */
  display: flex; align-items: flex-end; gap: 22px; box-shadow: inset 0 -1px 0 var(--border);
  overflow-x: auto; scrollbar-width: none; margin-bottom: 20px;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  position: relative; display: inline-flex; align-items: center; gap: 7px; height: 40px; padding: 0 1px;
  font-size: var(--text-base); font-weight: 530; color: var(--text-muted); white-space: nowrap;
  transition: color var(--dur-fast) ease; text-decoration: none !important;
}
.tab:hover { color: var(--text); }
.tab::after {
  content: ''; position: absolute; left: 0; right: 0; bottom: 0; height: 2px; border-radius: 2px 2px 0 0;
  background: var(--accent); transform: scaleX(0); opacity: 0;
  transition: transform var(--dur-slow) var(--ease-out), opacity var(--dur-fast) ease;
}
.tab.is-active { color: var(--text); }
.tab.is-active::after { transform: scaleX(1); opacity: 1; }
.tab:focus-visible { outline: none; }
.tab:focus-visible::before { content: ''; position: absolute; inset: 6px -6px; border-radius: 6px; box-shadow: var(--shadow-focus); }
.tab .icon { color: var(--icon-subtle); transition: color var(--dur-fast) ease; }
.tab.is-active .icon { color: var(--accent); }
/* Overflow cue, maintained by Tabs (ui.js): too narrow → icons drop out first (data-compact); still
   scrolling → the clipped side fades out (data-fade), so tabs beyond the edge never look absent.
   The fade width (40px) matches TAB_FADE_PX in ui.js. */
.tabs[data-compact] { gap: 18px; }
.tabs[data-compact] .tab > .icon { display: none; }
.tabs[data-fade='end'] {
  -webkit-mask-image: linear-gradient(90deg, #000 calc(100% - 40px), transparent);
  mask-image: linear-gradient(90deg, #000 calc(100% - 40px), transparent);
}
.tabs[data-fade='start'] {
  -webkit-mask-image: linear-gradient(90deg, transparent, #000 40px);
  mask-image: linear-gradient(90deg, transparent, #000 40px);
}
.tabs[data-fade='both'] {
  -webkit-mask-image: linear-gradient(90deg, transparent, #000 40px, #000 calc(100% - 40px), transparent);
  mask-image: linear-gradient(90deg, transparent, #000 40px, #000 calc(100% - 40px), transparent);
}
.tab-count {
  display: inline-grid; place-items: center; min-width: 20px; height: 18px; padding: 0 6px; border-radius: 999px;
  font-size: var(--text-2xs); font-weight: 600; background: var(--surface-3); color: var(--text-muted);
  font-variant-numeric: tabular-nums; transition: background-color var(--dur-fast) ease, color var(--dur-fast) ease;
}
.tab.is-active .tab-count { background: var(--accent-soft); color: var(--accent-text); }

/* Overlay, modal ---------------------------------------------------------------- */
.overlay {
  position: fixed; inset: 0; background: var(--overlay);
  backdrop-filter: blur(1px); -webkit-backdrop-filter: blur(1px);
  opacity: 0; transition: opacity var(--dur-slow) var(--ease-out);
}
[data-state='open'] > .overlay { opacity: 1; }

.modal-root {
  position: fixed; inset: 0; z-index: var(--z-modal);
  display: grid; place-items: center; padding: 24px 16px; overflow-y: auto;
}
.modal {
  position: relative; display: flex; flex-direction: column;
  width: 100%; max-width: 520px; max-height: calc(100dvh - 48px);
  background: var(--surface); border-radius: var(--radius-xl);
  box-shadow: var(--shadow-xl), 0 0 0 1px rgba(15, 23, 42, .06);
  opacity: 0; transform: translateY(8px) scale(.97);
  transition: opacity var(--dur-slow) var(--ease-out), transform var(--dur-slow) var(--ease-out);
}
.theme-dark .modal { box-shadow: var(--shadow-xl), 0 0 0 1px var(--border); }
.modal:focus { outline: none; }
[data-state='open'] > .modal { opacity: 1; transform: none; }
.modal-sm { max-width: 420px; }
.modal-md { max-width: 520px; }
.modal-lg { max-width: 720px; }
.modal-xl { max-width: 960px; }
.modal-header { display: flex; align-items: flex-start; gap: 12px; padding: 20px 24px 0; }
.modal-heading { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 4px; padding-right: 28px; }
.modal-title { font-size: var(--text-lg); font-weight: 620; letter-spacing: var(--tracking-snug); line-height: 1.35; }
.modal-description { color: var(--text-muted); font-size: var(--text-base); line-height: 1.5; }
.modal-close { position: absolute; top: 14px; right: 14px; }
.modal-body { padding: 16px 24px 20px; overflow-y: auto; min-height: 0; }
.modal-footer {
  display: flex; align-items: center; justify-content: flex-end; gap: 8px; flex-wrap: wrap;
  padding: 14px 24px; border-top: 1px solid var(--border-subtle); background: var(--surface-2);
  border-radius: 0 0 var(--radius-xl) var(--radius-xl);
}
.modal-footer .spacer { flex: 1; }
@media (max-width: 640px) {
  .modal-root { place-items: end center; padding: 0; }
  .modal {
    max-width: none !important; max-height: calc(100dvh - 24px); border-radius: 18px 18px 0 0;
    transform: translateY(40px); padding-bottom: var(--safe-bottom);
  }
  .modal-footer { border-radius: 0; }
  .modal-footer > .btn { flex: 1; }
  .modal-header { padding: 18px 18px 0; }
  .modal-body { padding: 14px 18px 18px; }
  .modal-footer { padding: 12px 18px; }
}

/* Drawer ------------------------------------------------------------------------- */
.drawer-root { position: fixed; inset: 0; z-index: var(--z-modal); }
.drawer {
  position: absolute; top: 0; right: 0; bottom: 0; display: flex; flex-direction: column;
  width: min(560px, 100vw); background: var(--surface);
  box-shadow: var(--shadow-xl), -1px 0 0 var(--border);
  transform: translateX(100%); transition: transform 260ms var(--ease-out);
}
.drawer:focus { outline: none; }
.drawer.is-left { right: auto; left: 0; transform: translateX(-100%); box-shadow: var(--shadow-xl), 1px 0 0 var(--border); }
[data-state='open'] > .drawer { transform: none; }
.drawer-header {
  display: flex; align-items: flex-start; gap: 12px; padding: 18px 20px 16px; padding-top: calc(18px + var(--safe-top));
  border-bottom: 1px solid var(--border-subtle);
}
.drawer-heading { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.drawer-title { font-size: var(--text-lg); font-weight: 620; letter-spacing: var(--tracking-snug); line-height: 1.35; }
.drawer-subtitle { color: var(--text-muted); font-size: var(--text-sm); }
.drawer-body { flex: 1; overflow-y: auto; padding: 20px; min-height: 0; overscroll-behavior: contain; }
.drawer-body.p-0 { padding: 0; }
.drawer-footer {
  display: flex; align-items: center; justify-content: flex-end; gap: 8px; flex-wrap: wrap;
  padding: 14px 20px; padding-bottom: calc(14px + var(--safe-bottom));
  border-top: 1px solid var(--border-subtle); background: var(--surface-2);
}
.drawer-footer .spacer { flex: 1; }

/* Toasts ---------------------------------------------------------------------------- */
.toast-stack {
  --toast-gap: 20px;
  position: fixed; z-index: var(--z-toast); right: 20px;
  bottom: calc(var(--toast-gap) + var(--toast-offset, 0px) + var(--safe-bottom));
  display: flex; flex-direction: column; gap: 8px; width: min(380px, calc(100vw - 32px));
  pointer-events: none; transition: bottom var(--dur-slow) var(--ease-out);
}
/* Lifted above the footer of an open Modal/Drawer (or a registered bar); --toast-lift is set by ui.js. */
.toast-stack[data-lifted] { bottom: max(var(--toast-lift, 0px), calc(var(--toast-gap) + var(--toast-offset, 0px) + var(--safe-bottom))); }
.toast {
  pointer-events: auto; position: relative; display: flex; align-items: flex-start; gap: 11px;
  padding: 12px 12px 12px 14px; background: var(--surface-raised); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg);
  animation: dts-toast-in 280ms var(--ease-out) both;
}
.toast.is-leaving { animation: dts-toast-out 200ms ease-in both; }
.toast-icon { margin-top: 1px; color: var(--text-muted); }
.toast-success .toast-icon { color: var(--success); }
.toast-danger .toast-icon { color: var(--danger); }
.toast-warning .toast-icon { color: var(--warning); }
.toast-info .toast-icon { color: var(--info); }
.toast-brand .toast-icon { color: var(--accent); }
.toast-content { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; padding-top: 0.5px; }
.toast-title { font-weight: 560; line-height: 1.4; }
.toast-desc { font-size: var(--text-sm); color: var(--text-muted); line-height: 1.45; }
.toast-action { margin-top: 6px; }
.toast-close { margin: -4px -4px 0 0; }
@keyframes dts-toast-in { from { opacity: 0; transform: translateY(12px) scale(.97); } to { opacity: 1; transform: none; } }
@keyframes dts-toast-out { from { opacity: 1; transform: none; } to { opacity: 0; transform: translateX(24px); } }
@media (max-width: 640px) {
  .toast-stack { --toast-gap: 16px; right: 16px; left: 16px; width: auto; }
}

/* Confirm ---------------------------------------------------------------------------- */
.confirm-body { display: flex; gap: 14px; align-items: flex-start; }
.confirm-icon {
  flex-shrink: 0; display: grid; place-items: center; width: 40px; height: 40px; border-radius: 12px;
  background: var(--accent-soft); color: var(--accent-text);
}
.confirm-icon.is-danger { background: var(--danger-soft); color: var(--danger-text); }
.confirm-icon.is-warning { background: var(--warning-soft); color: var(--warning-text); }
.confirm-text { display: flex; flex-direction: column; gap: 6px; padding-top: 1px; min-width: 0; }
.confirm-title { font-size: var(--text-lg); font-weight: 620; letter-spacing: var(--tracking-snug); line-height: 1.35; }
.confirm-message { color: var(--text-muted); line-height: 1.55; }

/* Table ---------------------------------------------------------------------------------- */
.table-wrap { position: relative; width: 100%; overflow-x: auto; overflow-y: hidden; }
.table-wrap.is-fit { overflow: visible; }
.table-wrap.has-max-h { overflow: auto; }
.table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: var(--text-sm); }
.table th {
  position: sticky; top: 0; z-index: 2;
  padding: 0 16px; height: 38px; text-align: left; white-space: nowrap;
  font-size: var(--text-xs); font-weight: 560; color: var(--text-muted); letter-spacing: .01em;
  background: var(--surface-2); border-bottom: 1px solid var(--border);
}
.table-wrap.is-fit .table th { top: var(--sticky-top); }
.table-wrap.has-max-h .table th { top: 0; }
.table th:first-child, .table td:first-child { padding-left: 20px; }
.table th:last-child, .table td:last-child { padding-right: 20px; }
.table td {
  padding: 11px 16px; height: 52px; vertical-align: middle; color: var(--text-secondary);
  border-bottom: 1px solid var(--border-subtle); background: var(--surface);
  transition: background-color 90ms ease; white-space: nowrap;
}
.table td.is-wrap { white-space: normal; }
.cell-clip { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.table tbody tr:last-child td { border-bottom: 0; }
.table .align-right { text-align: right; }
.table .align-center { text-align: center; }
.table td.align-right, .table td.num { font-variant-numeric: tabular-nums; }
.table tr.is-clickable { cursor: pointer; }
.table tr.is-clickable:hover td { background: var(--surface-2); }
/* Keyboard focus on a row: a solid 2px accent outline drawn inside the row (≥ 3:1), plus the soft tint. */
.table tr.is-clickable:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.table tr.is-clickable:focus-visible td { background: var(--accent-soft); }
.table tr.is-selected td { background: var(--accent-soft); }
.table-compact td { height: 44px; padding-top: 8px; padding-bottom: 8px; }
.table-compact th { height: 34px; }
.table-sort { display: inline-flex; align-items: center; gap: 4px; color: inherit; font: inherit; }
.table-sort:hover { color: var(--text); }
.table-sort .icon { opacity: .6; }
.table-sort.is-sorted { color: var(--text); }
.table-sort.is-sorted .icon { opacity: 1; }
.table-empty td { height: auto; padding: 0; background: var(--surface); }
.table-empty td:hover { background: var(--surface) !important; }
.table-skeleton td { height: 52px; }
.cell-primary { font-weight: 540; color: var(--text); line-height: 1.35; }
.cell-sub { font-size: var(--text-xs); color: var(--text-muted); line-height: 1.35; margin-top: 2px; }
.card > .table-wrap:first-child .table th:first-child,
.card-body.p-0 > .table-wrap:first-child .table th:first-child { border-top-left-radius: calc(var(--radius-lg) - 1px); }
.card > .table-wrap:first-child .table th:last-child,
.card-body.p-0 > .table-wrap:first-child .table th:last-child { border-top-right-radius: calc(var(--radius-lg) - 1px); }
.card > .table-wrap:last-child .table tbody tr:last-child td:first-child,
.card-body.p-0 > .table-wrap:last-child .table tbody tr:last-child td:first-child { border-bottom-left-radius: calc(var(--radius-lg) - 1px); }
.card > .table-wrap:last-child .table tbody tr:last-child td:last-child,
.card-body.p-0 > .table-wrap:last-child .table tbody tr:last-child td:last-child { border-bottom-right-radius: calc(var(--radius-lg) - 1px); }
.card-header + .table-wrap, .card-header + .card-body.p-0 { margin-top: 14px; border-top: 1px solid var(--border-subtle); }
@media (max-width: 640px) {
  .table th:first-child, .table td:first-child { padding-left: 16px; }
  .table th:last-child, .table td:last-child { padding-right: 16px; }
  .table th, .table td { padding-left: 12px; padding-right: 12px; }
  .table .hide-sm { display: none; }
}
@media (max-width: 900px) { .table .hide-md { display: none; } }
@media (max-width: 1200px) { .table .hide-lg { display: none; } }

/* Empty state ---------------------------------------------------------------------- */
.empty {
  display: flex; flex-direction: column; align-items: center; text-align: center;
  padding: 48px 24px; gap: 6px;
}
.empty-icon {
  position: relative; display: grid; place-items: center; width: 48px; height: 48px; margin-bottom: 10px;
  border-radius: 14px; color: var(--accent-text);
  background: linear-gradient(180deg, var(--surface) 0%, var(--surface-2) 100%);
  border: 1px solid var(--border); box-shadow: var(--shadow-sm), inset 0 -2px 0 rgba(16,24,40,.02);
}
.empty-icon::after {
  content: ''; position: absolute; inset: -1px; border-radius: 14px; padding: 1px;
  background: var(--brand-gradient); opacity: .45;
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor; mask-composite: exclude;
}
.empty-title { font-size: var(--text-md); font-weight: 600; color: var(--text); letter-spacing: var(--tracking-snug); }
.empty-desc { max-width: 380px; color: var(--text-muted); line-height: 1.55; }
.empty-actions { display: flex; gap: 8px; margin-top: 14px; flex-wrap: wrap; justify-content: center; }
.empty-compact { padding: 28px 16px; }
.empty-compact .empty-icon { width: 40px; height: 40px; border-radius: 12px; margin-bottom: 6px; }
.empty-compact .empty-icon::after { border-radius: 12px; }
.empty-compact .empty-title { font-size: var(--text-base); }
.empty-compact .empty-desc { font-size: var(--text-sm); }

/* Stat ------------------------------------------------------------------------------------ */
.stat {
  position: relative; display: flex; flex-direction: column; gap: 6px; min-width: 0; container-type: inline-size;
  padding: 16px 18px 16px; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-xs);
  overflow: hidden;
}
.stat-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.stat-label { display: flex; align-items: center; gap: 7px; font-size: var(--text-sm); font-weight: 520; color: var(--text-muted); min-width: 0; }
.stat-label-icon {
  display: grid; place-items: center; width: 24px; height: 24px; border-radius: 7px;
  background: var(--accent-soft); color: var(--accent-text); flex-shrink: 0;
}
.stat-value {
  font-size: 26px; font-weight: 650; letter-spacing: -0.025em; line-height: 1.15; color: var(--text);
  font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.stat-foot { display: flex; align-items: center; gap: 8px; min-height: 20px; flex-wrap: wrap; }
.stat-delta {
  display: inline-flex; align-items: center; gap: 2px; height: 20px; padding: 0 6px 0 4px; border-radius: 6px;
  font-size: var(--text-xs); font-weight: 600; font-variant-numeric: tabular-nums;
  background: var(--neutral-soft); color: var(--neutral-text);
}
.stat-delta.is-up { background: var(--success-soft); color: var(--success-text); }
.stat-delta.is-down { background: var(--danger-soft); color: var(--danger-text); }
.stat-delta-label, .stat-hint { font-size: var(--text-xs); color: var(--text-subtle); }
.stat-main { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; min-width: 0; }
.stat-main .stat-value { flex: 1 1 auto; min-width: 0; }
.stat-spark { width: 84px; height: 30px; flex-shrink: 0; margin-bottom: 2px; }
@container (max-width: 250px) { .stat-spark { display: none; } }

/* Progress --------------------------------------------------------------------------- */
.progress { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.progress-label { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; font-size: var(--text-sm); }
.progress-label-text { color: var(--text-secondary); font-weight: 520; }
.progress-label-value { color: var(--text-muted); font-variant-numeric: tabular-nums; font-size: var(--text-xs); }
.progress-track { position: relative; height: 6px; border-radius: 999px; background: var(--surface-3); overflow: hidden; }
.theme-dark .progress-track { background: #1F2836; }
.progress-bar {
  position: absolute; inset: 0 auto 0 0; border-radius: inherit; background: var(--brand-gradient);
  background-size: var(--progress-bg-size, 100%) 100%;
  transition: width 600ms var(--ease-out);
}
.progress-sm .progress-track { height: 4px; }
.progress-lg .progress-track { height: 10px; }
.progress-accent .progress-bar { background: var(--accent); }
.progress-success .progress-bar { background: var(--success); }
.progress-warning .progress-bar { background: var(--warning); }
.progress-danger .progress-bar { background: var(--danger); }
.progress-info .progress-bar { background: var(--info); }
.progress-neutral .progress-bar { background: var(--ink-400); }

/* Skeleton -------------------------------------------------------------------------- */
.skeleton {
  display: block; border-radius: 6px;
  background: linear-gradient(90deg, var(--surface-3) 0%, var(--surface-3) 35%, var(--ink-150) 50%, var(--surface-3) 65%, var(--surface-3) 100%);
  background-size: 200% 100%; animation: dts-shimmer 1.4s ease-in-out infinite;
}
.theme-dark .skeleton { background: linear-gradient(90deg, #171F2B 0%, #171F2B 35%, #202a38 50%, #171F2B 65%, #171F2B 100%); background-size: 200% 100%; }

/* Spinner ---------------------------------------------------------------------------- */
.spinner { display: inline-block; animation: dts-spin .75s linear infinite; color: currentColor; flex-shrink: 0; }
.spinner circle { fill: none; stroke: currentColor; }
.spinner .spinner-track { opacity: .18; }
.page-loader { display: grid; place-items: center; min-height: 40vh; color: var(--icon-subtle); }

/* Copy field ------------------------------------------------------------------------ */
.copy-field {
  display: flex; align-items: center; min-width: 0; height: var(--control-h);
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius);
  padding-left: 11px;
}
.copy-field-value { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-secondary); user-select: all; }
.copy-field-value.mono { font-family: var(--font-mono); font-size: 12.5px; letter-spacing: .01em; }
.copy-field-btn {
  display: inline-flex; align-items: center; gap: 6px; height: 100%; padding: 0 12px; flex-shrink: 0;
  border-left: 1px solid var(--border); color: var(--text-secondary); font-size: var(--text-sm); font-weight: 540;
  border-radius: 0 var(--radius) var(--radius) 0; transition: background-color var(--dur-fast) ease, color var(--dur-fast) ease;
}
.copy-field-btn:hover { background: var(--surface-3); color: var(--text); }
.copy-field-btn:focus-visible { outline: none; box-shadow: var(--shadow-focus); }
.copy-field-btn.is-copied { color: var(--success-text); }

/* Dropdown / menu ------------------------------------------------------------------- */
.dropdown { position: relative; display: inline-flex; }
.menu {
  position: fixed; z-index: var(--z-dropdown); min-width: 200px; max-width: 320px; padding: 5px;
  background: var(--surface-raised); border: 1px solid var(--border); border-radius: 10px;
  box-shadow: var(--shadow-lg); transform-origin: var(--menu-origin, top right);
  animation: dts-menu-in 160ms var(--ease-out);
  max-height: min(420px, calc(100vh - 24px)); overflow-y: auto;
}
.menu:focus { outline: none; }
@keyframes dts-menu-in { from { opacity: 0; transform: scale(.96) translateY(-4px); } to { opacity: 1; transform: none; } }
.menu-item {
  display: flex; align-items: center; gap: 9px; width: 100%; height: 34px; padding: 0 10px;
  border-radius: 6px; font-size: var(--text-sm); font-weight: 480; color: var(--text-secondary);
  text-align: left; text-decoration: none !important; white-space: nowrap; cursor: pointer;
}
.menu-item .icon { color: var(--icon-subtle); }
.menu-item:hover, .menu-item.is-active { background: var(--surface-3); color: var(--text); }
.menu-item:hover .icon, .menu-item.is-active .icon { color: var(--text-secondary); }
.menu-item.is-danger { color: var(--danger-text); }
.menu-item.is-danger .icon { color: var(--danger); }
.menu-item.is-danger:hover, .menu-item.is-danger.is-active { background: var(--danger-soft); }
.menu-item:disabled, .menu-item.is-disabled { opacity: .45; pointer-events: none; }
.menu-item-hint { margin-left: auto; color: var(--text-subtle); font-size: var(--text-xs); }
.menu-divider { height: 1px; margin: 5px -5px; background: var(--border-subtle); }
.menu-label { padding: 8px 10px 4px; font-size: var(--text-2xs); font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--text-subtle); }

/* Avatar ------------------------------------------------------------------------------- */
.avatar {
  --avatar-size: 32px;
  display: inline-grid; place-items: center; flex-shrink: 0;
  width: var(--avatar-size); height: var(--avatar-size); border-radius: 50%;
  font-size: calc(var(--avatar-size) * .38); font-weight: 620; letter-spacing: -0.01em; color: #fff;
  background: var(--avatar-bg, var(--brand-gradient)); user-select: none;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.18), 0 1px 2px rgba(16,24,40,.08);
  text-transform: uppercase; overflow: hidden;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }

/* Page header ------------------------------------------------------------------------- */
.page-header { display: flex; flex-direction: column; gap: 6px; margin-bottom: 24px; min-width: 0; }
.page-back {
  display: inline-flex; align-items: center; gap: 5px; align-self: flex-start; margin-bottom: 6px;
  font-size: var(--text-sm); font-weight: 520; color: var(--text-muted); text-decoration: none !important;
  padding: 3px 8px 3px 4px; margin-left: -4px; border-radius: 6px; transition: color var(--dur-fast) ease, background-color var(--dur-fast) ease;
}
.page-back:hover { color: var(--text); background: var(--surface-3); }
.page-header-main { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.page-heading { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.page-title { font-size: 24px; font-weight: 680; letter-spacing: -0.025em; line-height: 1.2; color: var(--text); overflow-wrap: anywhere; }
.page-subtitle { font-size: var(--text-base); color: var(--text-muted); line-height: 1.5; }
.page-meta { display: flex; align-items: center; flex-wrap: wrap; gap: 6px 14px; margin-top: 4px; color: var(--text-muted); font-size: var(--text-sm); }
.page-meta-item { display: inline-flex; align-items: center; gap: 6px; }
.page-meta-item .icon { color: var(--icon-subtle); }
.page-actions { display: flex; align-items: center; gap: 8px; flex-shrink: 0; flex-wrap: wrap; justify-content: flex-end; }
@media (max-width: 720px) {
  .page-header-main { flex-direction: column; align-items: stretch; gap: 14px; }
  .page-actions { justify-content: flex-start; }
  .page-title { font-size: 22px; }
}

/* Pagination ----------------------------------------------------------------------- */
.pagination { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; padding: 12px 20px; }
.pagination-info { font-size: var(--text-sm); color: var(--text-muted); font-variant-numeric: tabular-nums; }
.pagination-pages { display: flex; align-items: center; gap: 4px; }
.page-btn {
  display: inline-grid; place-items: center; min-width: 32px; height: 32px; padding: 0 8px; border-radius: 8px;
  font-size: var(--text-sm); font-weight: 540; color: var(--text-secondary); font-variant-numeric: tabular-nums;
  transition: background-color var(--dur-fast) ease, color var(--dur-fast) ease;
}
.page-btn:hover:not(:disabled) { background: var(--surface-3); color: var(--text); }
.page-btn:focus-visible { outline: none; box-shadow: var(--shadow-focus); }
.page-btn.is-current { background: var(--surface); color: var(--text); box-shadow: inset 0 0 0 1px var(--border-strong), var(--shadow-xs); }
.page-btn:disabled { opacity: .4; }
.page-gap { min-width: 20px; text-align: center; color: var(--text-subtle); }

/* Image upload --------------------------------------------------------------------- */
.image-upload { position: relative; width: 100%; }
.image-drop {
  position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px;
  width: 100%; aspect-ratio: var(--aspect, 16 / 9); padding: 20px; text-align: center; cursor: pointer;
  border: 1.5px dashed var(--border-strong); border-radius: var(--radius-lg); background: var(--surface-2);
  color: var(--text-muted); transition: border-color var(--dur-fast) ease, background-color var(--dur-fast) ease, box-shadow var(--dur-fast) ease;
  overflow: hidden;
}
.image-drop:hover { border-color: var(--accent); background: var(--accent-soft); }
.image-drop:focus-visible { outline: none; box-shadow: var(--shadow-focus); border-color: var(--accent); }
.image-upload.is-dragging .image-drop { border-color: var(--accent); background: var(--accent-soft); box-shadow: 0 0 0 4px var(--accent-ring); }
.image-drop-icon {
  display: grid; place-items: center; width: 40px; height: 40px; border-radius: 12px; background: var(--surface);
  border: 1px solid var(--border); box-shadow: var(--shadow-xs); color: var(--accent-text);
}
.image-drop-title { font-weight: 560; color: var(--text); }
.image-drop-title span { color: var(--accent-text); }
.image-drop-hint { font-size: var(--text-xs); color: var(--text-subtle); }
.image-preview {
  position: relative; width: 100%; aspect-ratio: var(--aspect, 16 / 9); border-radius: var(--radius-lg); overflow: hidden;
  background: var(--surface-3); border: 1px solid var(--border); box-shadow: var(--shadow-xs);
}
.image-preview img { width: 100%; height: 100%; object-fit: cover; }
.image-actions {
  position: absolute; right: 10px; bottom: 10px; display: flex; gap: 6px;
  opacity: 0; transform: translateY(4px); transition: opacity var(--dur) ease, transform var(--dur) var(--ease-out);
}
.image-preview:hover .image-actions, .image-preview:focus-within .image-actions { opacity: 1; transform: none; }
@media (hover: none) { .image-actions { opacity: 1; transform: none; } }
.image-actions .btn { background: rgba(255,255,255,.94); backdrop-filter: blur(6px); }
.image-busy {
  position: absolute; inset: 0; display: grid; place-items: center; background: rgba(255,255,255,.72);
  backdrop-filter: blur(2px); color: var(--accent); z-index: 2;
}
.theme-dark .image-busy { background: rgba(10,14,20,.7); }

/* QR --------------------------------------------------------------------------------- */
.qr {
  display: inline-block; padding: 8px; background: #fff; border-radius: var(--radius);
  border: 1px solid var(--border); box-shadow: var(--shadow-xs); line-height: 0;
}
.qr img { image-rendering: pixelated; }

/* Kbd --------------------------------------------------------------------------------- */
.kbd {
  display: inline-grid; place-items: center; min-width: 20px; height: 20px; padding: 0 5px;
  font-family: var(--font-sans); font-size: var(--text-2xs); font-weight: 600; color: var(--text-muted);
  background: var(--surface); border: 1px solid var(--border-strong); border-bottom-width: 2px; border-radius: 5px;
  line-height: 1;
}

/* Tooltip (singleton, positioned by ui.js) ----------------------------------------- */
.tooltip-pop {
  position: fixed; z-index: var(--z-tooltip); max-width: 260px; padding: 6px 9px;
  font-size: var(--text-xs); font-weight: 500; line-height: 1.4; color: #F8FAFC;
  background: #0F172A; border-radius: 7px; box-shadow: var(--shadow-md);
  pointer-events: none; opacity: 0; transform: translateY(2px);
  transition: opacity 120ms ease, transform 120ms var(--ease-out);
}
.tooltip-pop.is-visible { opacity: 1; transform: none; }
.tooltip-pop.is-below { transform: translateY(-2px); }
.tooltip-pop.is-below.is-visible { transform: none; }
.theme-dark .tooltip-pop { background: #EDF2F8; color: #0A0E14; }
.tooltip-trigger { display: inline-flex; align-items: center; }
.tooltip-trigger.is-help { color: var(--icon-subtle); cursor: help; }

/* Alert ------------------------------------------------------------------------------ */
.alert {
  --alert-bg: var(--info-soft); --alert-fg: var(--info-text); --alert-ring: var(--info-ring); --alert-icon: var(--info);
  display: flex; align-items: flex-start; gap: 10px; padding: 12px 14px; border-radius: var(--radius);
  background: var(--alert-bg); box-shadow: inset 0 0 0 1px var(--alert-ring); color: var(--text-secondary);
  font-size: var(--text-sm); line-height: 1.5;
}
.alert > .icon { color: var(--alert-icon); margin-top: 1px; }
.alert-content { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.alert-title { font-weight: 600; color: var(--alert-fg); }
.alert-success { --alert-bg: var(--success-soft); --alert-fg: var(--success-text); --alert-ring: var(--success-ring); --alert-icon: var(--success); }
.alert-warning { --alert-bg: var(--warning-soft); --alert-fg: var(--warning-text); --alert-ring: var(--warning-ring); --alert-icon: var(--warning); }
.alert-danger { --alert-bg: var(--danger-soft); --alert-fg: var(--danger-text); --alert-ring: var(--danger-ring); --alert-icon: var(--danger); }
.alert-neutral { --alert-bg: var(--surface-2); --alert-fg: var(--text); --alert-ring: var(--border); --alert-icon: var(--text-muted); }
.alert-brand { --alert-bg: var(--accent-soft); --alert-fg: var(--accent-text); --alert-ring: rgba(34,181,166,.25); --alert-icon: var(--accent); }
.alert-action { flex-shrink: 0; align-self: center; }

/* Description list ------------------------------------------------------------------ */
.dl { display: flex; flex-direction: column; }
.dl-row { display: grid; grid-template-columns: minmax(120px, 38%) minmax(0, 1fr); gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--border-subtle); font-size: var(--text-sm); }
.dl-row:last-child { border-bottom: 0; }
.dl-label { color: var(--text-muted); }
.dl-value { color: var(--text); font-weight: 480; min-width: 0; overflow-wrap: anywhere; }
.dl-value.num { font-variant-numeric: tabular-nums; }

/* Charts --------------------------------------------------------------------------- */
.chart { position: relative; width: 100%; min-width: 0; user-select: none; -webkit-user-select: none; }
.chart-svg { display: block; width: 100%; overflow: visible; touch-action: pan-y; }
.chart-svg text { font-family: var(--font-sans); font-size: 11px; fill: var(--chart-axis); font-variant-numeric: tabular-nums; }
.chart-grid line { stroke: var(--chart-grid); stroke-width: 1; shape-rendering: crispEdges; }
.chart-baseline { stroke: var(--border-strong); shape-rendering: crispEdges; }
.chart-line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart-line.is-drawn { stroke-dasharray: 1; stroke-dashoffset: 1; animation: dts-draw 900ms var(--ease-out) forwards; }
@keyframes dts-draw { to { stroke-dashoffset: 0; } }
.chart-area { animation: dts-fade-in 700ms 150ms var(--ease-out) both; }
.chart-cross { stroke: var(--ink-300); stroke-width: 1; stroke-dasharray: 3 3; shape-rendering: crispEdges; }
.theme-dark .chart-cross { stroke: #3A4658; }
.chart-dot { stroke: var(--surface); stroke-width: 2; }
.chart-tooltip {
  position: absolute; z-index: 5; top: 0; left: 0; min-width: 160px; max-width: 280px; padding: 9px 11px;
  background: var(--surface-raised); border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow-lg);
  pointer-events: none; font-size: var(--text-xs); transition: transform 90ms linear, opacity 120ms ease;
}
.chart-tooltip-title { font-weight: 600; color: var(--text); margin-bottom: 6px; font-size: var(--text-xs); }
.chart-tooltip-row { display: flex; align-items: center; gap: 8px; padding: 2px 0; color: var(--text-secondary); }
.chart-tooltip-row .swatch { width: 8px; height: 8px; border-radius: 3px; flex-shrink: 0; }
.chart-tooltip-row .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chart-tooltip-row .val { font-weight: 600; color: var(--text); font-variant-numeric: tabular-nums; }
.chart-tooltip-total { border-top: 1px solid var(--border-subtle); margin-top: 5px; padding-top: 5px; }
.chart-legend { display: flex; flex-wrap: wrap; gap: 4px 6px; margin-top: 12px; }
.legend-item {
  display: inline-flex; align-items: center; gap: 7px; height: 26px; padding: 0 9px 0 8px; border-radius: 7px;
  font-size: var(--text-xs); font-weight: 520; color: var(--text-secondary); transition: background-color var(--dur-fast) ease, opacity var(--dur-fast) ease;
}
.legend-item:hover { background: var(--surface-3); }
.legend-item .swatch { width: 10px; height: 10px; border-radius: 3px; }
.legend-item.is-off { opacity: .45; }
.legend-item.is-off .swatch { background: transparent !important; box-shadow: inset 0 0 0 1.5px var(--ink-400); }
.chart-empty {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  color: var(--text-muted); font-size: var(--text-sm); text-align: center;
}
.chart-empty .icon { color: var(--icon-subtle); }

.donut { position: relative; display: inline-grid; place-items: center; flex-shrink: 0; }
.donut svg { transform: rotate(-90deg); }
.donut-track { stroke: var(--surface-3); fill: none; }
.theme-dark .donut-track { stroke: #1F2836; }
.donut-arc { fill: none; stroke-linecap: round; transition: stroke-dashoffset 900ms var(--ease-out); }
.donut-center { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; gap: 1px; }
.donut-label { font-size: var(--donut-label-size, 20px); font-weight: 680; letter-spacing: -0.02em; color: var(--text); font-variant-numeric: tabular-nums; line-height: 1.1; }
.donut-sublabel { font-size: var(--text-xs); color: var(--text-muted); line-height: 1.3; }

.sparkline { display: block; width: 100%; overflow: visible; }
.sparkline path { vector-effect: non-scaling-stroke; }

.bar-chart .bar { transition: opacity var(--dur-fast) ease; }
.bar-chart .bar.is-dim { opacity: .45; }
