:root {
  --ui-font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", sans-serif;
  --ui-radius-xs: 8px;
  --ui-radius-sm: 8px;
  --ui-radius-md: 8px;
  --ui-radius-lg: 8px;
  --ui-space-1: 4px;
  --ui-space-2: 8px;
  --ui-space-3: 12px;
  --ui-space-4: 16px;
  --ui-space-5: 20px;
  --ui-space-6: 24px;
  --ui-gutter: 16px;
  --ui-gutter-compact: 8px;
  --ui-page-gutter: var(--ui-gutter-compact);
  --ui-card-radius: var(--ui-radius-xs);
  --ui-card-pad: var(--ui-space-3);
  --ui-title-size: 22px;
  --ui-hero-size: 34px;
  --app-radius: var(--ui-radius-xs);
  --ui-control-h: 44px;
  --ui-select-pad-end: 26px;
  --ui-select-caret-inset: 10px;
  --ui-border: color-mix(in srgb, var(--tg-theme-hint-color, #8e8e93) 22%, transparent);
  --ui-border-strong: color-mix(in srgb, var(--tg-theme-hint-color, #8e8e93) 38%, transparent);
  --ui-surface: color-mix(in srgb, var(--tg-theme-bg-color, #fff) 96%, var(--tg-theme-text-color, #111) 4%);
  --ui-surface-raised: color-mix(in srgb, var(--tg-theme-bg-color, #fff) 99%, var(--tg-theme-text-color, #111) 1%);
  --ui-surface-muted: color-mix(in srgb, var(--tg-theme-secondary-bg-color, #f2f2f7) 82%, transparent);
  --ui-accent-soft: color-mix(in srgb, var(--tg-theme-button-color, #3390ec) 13%, transparent);
  --ui-danger: #d43b43;
  --ui-danger-soft: color-mix(in srgb, var(--ui-danger) 12%, transparent);
  --ui-shadow: 0 1px 2px rgb(0 0 0 / 5%), 0 10px 30px rgb(0 0 0 / 5%);
  --ui-focus: 0 0 0 3px color-mix(in srgb, var(--tg-theme-button-color, #3390ec) 24%, transparent);
}

* {
  box-sizing: border-box;
}

body {
  font-family: var(--ui-font);
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}

button,
input,
select,
textarea {
  font: inherit;
}

button,
[role="button"],
a,
input,
select,
textarea {
  -webkit-tap-highlight-color: transparent;
}

:where(button, [role="button"], a, input, select, textarea):focus-visible {
  outline: none;
  box-shadow: var(--ui-focus);
}

.ui-surface {
  border: 1px solid var(--ui-border);
  border-radius: var(--ui-radius-md);
  background: var(--ui-surface-raised);
  box-shadow: var(--ui-shadow);
}

.ui-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--ui-space-2);
}

.ui-action {
  min-height: var(--ui-control-h);
  border: 1px solid transparent;
  border-radius: var(--ui-radius-sm);
  padding: 0 var(--ui-space-4);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--ui-space-2);
  font-weight: 650;
  line-height: 1.15;
  cursor: pointer;
  transition: transform 120ms ease, filter 120ms ease, background-color 120ms ease;
}

.ui-action:active:not(:disabled) {
  transform: scale(.98);
}

.ui-action:disabled,
.ui-action[aria-disabled="true"] {
  opacity: .48;
  cursor: default;
}

.ui-action.is-primary {
  color: var(--tg-theme-button-text-color, #fff);
  background: var(--tg-theme-button-color, #3390ec);
}

.ui-action.is-secondary {
  color: var(--tg-theme-text-color, #111);
  background: var(--ui-surface-muted);
  border-color: var(--ui-border);
}

.ui-action.is-quiet {
  color: var(--ui-accent-ink, #185fa8);
  background: transparent;
}

.ui-action.is-danger {
  color: var(--ui-danger);
  background: var(--ui-danger-soft);
  border-color: color-mix(in srgb, var(--ui-danger) 18%, transparent);
}

.ui-action[aria-busy="true"] {
  color: transparent;
  position: relative;
}

.ui-action[aria-busy="true"]::after {
  content: "";
  width: 16px;
  height: 16px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  color: var(--tg-theme-button-text-color, #fff);
  position: absolute;
  animation: ui-spin .7s linear infinite;
}

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

.tab {
  min-height: 48px;
}

/* Dashboard already shows period/KPI on the cards. The header #status chip
   only echoed «За период · Всё время» and could not be changed. */
body.pro[data-view="dash"] #hdr #status {
  display: none;
}

.ph-icon {
  display: block;
  width: 1em;
  height: 1em;
  flex: 0 0 auto;
  fill: currentColor;
}

.tab .ti {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 1.15em;
  width: 1.15em;
  height: 1.15em;
  min-width: 1.15em;
  font-family: var(--ui-font);
  font-size: 18px;
  font-weight: 400;
  line-height: 1;
}

.hdr-btn-glyph,
.ms-ico,
.sw-item-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.ms-ico {
  width: 26px;
  height: 26px;
}

.tab .ti .ph-icon,
.hdr-btn-glyph .ph-icon,
.ms-ico .ph-icon {
  width: 100%;
  height: 100%;
}

.workspace-nav-icon .ph-icon,
.docs-nav-icon .ph-icon,
.doc-topic-icon .ph-icon,
.sw-item-icon .ph-icon,
#lite-back > span:first-child .ph-icon,
.attn-ico .ph-icon,
.ui-action-icon .ph-icon,
.plus-glyph .ph-icon,
.search-glyph .ph-icon,
.workspace-empty-icon .ph-icon,
.rf-kind-icon .ph-icon,
.act .ph-icon,
.tn-switch-hint .ph-icon,
.context-switch-button .ph-icon,
.new-btn-ico .ph-icon,
.lh-tile .ico .ph-icon,
.reg-bar-actions .ph-icon,
.reg-fs .ph-icon,
.reg-chip .ph-icon,
.reg-chip .ui-action-icon .ph-icon,
.reg-fpick-name .ph-icon {
  width: 1em;
  height: 1em;
}

.stage-emoji .ph-icon {
  width: 46px;
  height: 46px;
}

.stage-emoji-sm .ph-icon {
  width: 40px;
  height: 40px;
}

.hdr-btn,
.hdr-search,
.help-q {
  min-width: 44px;
  min-height: 44px;
  border-radius: var(--ui-radius-sm);
}

.help-q {
  font-weight: 750;
}

/* Keep header ❓ in the DOM (test_help_buttons) but hide it when the frame
 already has an inline/modal ❓ — otherwise two identical buttons stack. */
body.modal-open #hdr .help-q,
body.more-open #hdr .help-q,
body.choice-open #hdr .help-q,
body[data-view="deals"] #hdr .help-q,
body[data-view="refs"] #hdr .help-q,
body[data-view="docs"] #hdr .help-q,
body[data-view="catalog"] #hdr .help-q,
body[data-view="settings"] #hdr .help-q,
body[data-view="suppliers"] #hdr .help-q,
body[data-view="platform"] #hdr .help-q {
  display: none;
}

.more-sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 55;
  background: rgb(0 0 0 / 16%);
  backdrop-filter: blur(2px);
}

#more-sheet .ms-item,
#choice-sheet .ms-item {
  min-height: 52px;
  display: flex;
  align-items: center;
  gap: var(--ui-space-3);
  text-align: start;
}

#choice-back { z-index: 105; }
#choice-sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: calc(86px + env(safe-area-inset-bottom));
  z-index: 110;
  max-height: calc(100dvh - 98px - env(safe-area-inset-bottom, 0px));
  overflow-x: hidden;
  overflow-y: auto;
  background: var(--tg-theme-bg-color, #fff);
  border-radius: 8px 8px 0 0;
  box-shadow: 0 -4px 20px rgba(0, 0, 0, .18);
  padding: 8px 10px 24px;
}
.choice-sheet-title,
.choice-sheet-h {
  padding: 8px 10px 6px;
  color: var(--tg-theme-hint-color, #8e8e93);
  font-size: 20px;
  font-weight: 750;
  line-height: 1.2;
}
.choice-sheet-h {
  padding: 14px 10px 6px;
}
.choice-sheet-sec:first-child .choice-sheet-h {
  padding-top: 8px;
}
.choice-sheet-sec + .choice-sheet-sec {
  margin-top: 4px;
  border-top: 1px solid rgba(127, 127, 127, .16);
  padding-top: 4px;
}
#choice-sheet .ms-item.is-current {
  font-weight: 650;
  color: var(--tg-theme-link-color, #3390ec);
}
#choice-sheet.has-apply {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding-bottom: 8px;
}
#choice-sheet .choice-sheet-body {
  min-height: 0;
  overflow: auto;
}
#choice-sheet .ms-item.is-check {
  justify-content: space-between;
  min-height: 44px;
  font-weight: 500;
  color: inherit;
}
#choice-sheet .ms-item.is-check.is-current {
  font-weight: 550;
  color: inherit;
}
#choice-sheet .ms-check {
  flex: 0 0 22px;
  width: 22px;
  height: 22px;
  box-sizing: border-box;
  border: 1.5px solid rgba(127, 127, 127, .45);
  border-radius: 8px;
}
#choice-sheet .ms-item.is-check.is-current .ms-check {
  border-color: var(--tg-theme-link-color, #3390ec);
  background: var(--tg-theme-link-color, #3390ec);
}
#choice-sheet .ms-item.is-check.is-current .ms-check::after {
  content: "✓";
  display: block;
  color: #fff;
  font-size: 13px;
  line-height: 19px;
  text-align: center;
}
#choice-sheet .choice-sheet-apply {
  flex: 0 0 auto;
  padding: 8px 10px 4px;
}
#choice-sheet .choice-apply {
  width: 100%;
  min-height: 44px;
}
.led-shs-pick { margin: 0; padding: 0; border: 0; width: 100%; }
.led-sheet-pick,
.deal-status-pick,
.deal-view-pick {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 44px;
  gap: 8px;
}
.deal-status-pick,
.deal-view-pick,
.reg-cols-pick,
.reg-filters-pick {
  flex-direction: column;
  align-items: stretch;
  justify-content: center;
  min-height: 40px;
  gap: 1px;
  padding: 3px 10px;
}
.reg-phone-row {
  display: flex;
  align-items: stretch;
  gap: 8px;
  min-width: 0;
}
.reg-phone-row .reg-cols-pick,
.reg-phone-row .reg-filters-pick {
  flex: 1 1 0;
  min-width: 0;
  overflow: hidden;
}
.deal-pick-cap {
  font-size: 11px;
  font-weight: 650;
  line-height: 1.2;
  color: var(--tg-theme-hint-color, #8e8e93);
}
.deal-pick-value {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  min-width: 0;
}
.led-sheet-pick,
.deal-status-pick { width: 100%; }
.deal-status-phone,
.deal-view-phone {
  display: flex;
  align-items: stretch;
  gap: 8px;
  width: 100%;
  min-width: 0;
}
.deal-view-phone .deal-view-pick {
  flex: 1 1 auto;
  min-width: 0;
  width: auto;
}
.deal-view-phone .help-q {
  flex: 0 0 40px;
  width: 40px;
  min-width: 40px;
  height: 40px;
}
.led-pick-label {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.led-pick-caret { flex: 0 0 auto; opacity: .65; font-size: 12px; }

@media (hover: hover) {
  .ui-action:hover:not(:disabled),
  .tab:hover,
  .hdr-btn:hover,
  .hdr-search:hover {
    filter: brightness(.98);
  }
}

body.dense {
  --ui-control-h: 36px;
}

@media (max-width: 899px) {
  .ui-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .ui-actions > .ui-action:only-child,
  .ui-actions > .ui-action.is-primary:last-child:nth-child(odd) {
    grid-column: 1 / -1;
  }
}

@media (max-width: 420px) {
  .ui-actions {
    grid-template-columns: 1fr;
  }

  .ui-actions > .ui-action {
    width: 100%;
    grid-column: auto;
  }
}

@media (prefers-reduced-motion: reduce) {
 *,
 *::before,
 *::after {
    scroll-behavior: auto !important;
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}
