/* Clinical UI — component layer */

*,
*::before,
*::after {
  box-sizing: border-box;
}

/* The `hidden` attribute must win over any component's own display value.
   The UA stylesheet only gives [hidden] `display: none`, which loses to a class
   rule of equal specificity that comes later — so `.bx--inline-notification`'s
   `display: flex` was overriding it. The review screen's "Submit failed" banner
   is markup-hidden and only revealed by script, and it was therefore visible to
   every reviewer the instant the page loaded, announcing a failure that had not
   happened. Any element that hides itself this way had the same defect. */
[hidden] {
  display: none !important;
}

html {
  -webkit-text-size-adjust: 100%;
}

body.bx--body {
  margin: 0;
  line-height: 1.55;
  color: var(--ecg-text);
  background: var(--ecg-bg);
  font-size: var(--text-base);
  -webkit-font-smoothing: antialiased;
}

a {
  color: var(--ecg-primary);
  text-decoration: none;
  transition: color 0.18s ease;
}

a:hover {
  color: var(--ecg-primary-hover);
  text-decoration: underline;
}

code,
.ecg-mono,
[data-col="key"],
[data-col="subject"],
[data-col="uploaded_at"],
[data-col="pulse"] {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: 0.8125rem;
}

/* ——— Header: deep teal brand bar ——— */

.bx--header {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  gap: 1.5rem;
  min-height: var(--ecg-header-h);
  padding: 0 1.5rem;
  background: linear-gradient(115deg, var(--ecg-brand), var(--ecg-brand-2));
  color: var(--ecg-on-brand);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.04),
    0 10px 30px -22px rgba(0, 0, 0, 0.6);
}

.bx--header__name {
  display: inline-flex;
  align-items: center;
  gap: 0.625rem;
  color: #fff;
  font-weight: 600;
  font-size: var(--text-lg);
  letter-spacing: -0.01em;
  text-decoration: none;
  white-space: nowrap;
}

.bx--header__name:hover {
  color: #fff;
  text-decoration: none;
}

.bx--header__name--prefix {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  border-radius: 0.5rem;
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
  font-size: 0.6875rem;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.bx--header__name--text {
  color: inherit;
}

/* Session context chip: which organization you're acting in */
.ecg-org-chip {
  flex: none;
  padding: 0.2rem 0.65rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.1);
  color: rgba(255, 255, 255, 0.78);
  font-size: var(--text-xs);
  font-weight: 500;
  white-space: nowrap;
  max-width: 14rem;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Organization switcher: a native <details> dropdown so it needs no JS and is
   therefore safe under the portal's script-src 'self' CSP. */
.ecg-org-switch {
  position: relative;
  flex: none;
}
.ecg-org-chip--switch {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  cursor: pointer;
  list-style: none;
  max-width: 18rem;
}
.ecg-org-chip--switch::-webkit-details-marker {
  display: none;
}
.ecg-org-chip--switch:hover {
  background: rgba(255, 255, 255, 0.18);
}
.ecg-org-chip__role {
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-size: 0.62rem;
  padding: 0 0.28rem;
  border-radius: 3px;
  background: var(--ecg-primary);
  color: var(--ecg-on-primary, #fff);
}
.ecg-org-switch__caret {
  font-size: 0.7em;
  opacity: 0.8;
}
.ecg-org-switch[open] .ecg-org-switch__caret {
  transform: rotate(180deg);
}
.ecg-org-switch__menu {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  z-index: 500;
  min-width: 15rem;
  max-height: 60vh;
  overflow-y: auto;
  padding: 0.3rem;
  background: var(--ecg-surface);
  border: 1px solid var(--ecg-border);
  border-radius: var(--ecg-radius-sm);
  box-shadow: var(--ecg-shadow-md);
}
.ecg-org-switch__menu form {
  margin: 0;
}
.ecg-org-switch__item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  text-align: left;
  padding: 0.4rem 0.55rem;
  border: 0;
  border-radius: var(--ecg-radius-sm);
  background: transparent;
  color: var(--ecg-text);
  font-size: var(--text-sm);
  cursor: pointer;
}
.ecg-org-switch__item:hover {
  background: var(--ecg-row-hover);
}
.ecg-org-switch__item.is-current {
  font-weight: 600;
}
.ecg-org-switch__item.is-current::before {
  content: "\2713";
  color: var(--ecg-primary);
}
.ecg-org-switch__name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ecg-org-switch__badge {
  flex: none;
  font-size: 0.62rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 0.05rem 0.35rem;
  border-radius: 999px;
  background: var(--ecg-warn-bg);
  color: var(--ecg-warn-fg);
}

.bx--header__nav {
  flex: 1;
  min-width: 0;
}

.bx--header__menu-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.25rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.bx--header__global {
  margin-left: auto;
}

.bx--header__menu-item {
  display: inline-flex;
  align-items: center;
  min-height: 2.25rem;
  padding: 0.375rem 0.875rem;
  border-radius: var(--ecg-radius-sm);
  color: rgba(255, 255, 255, 0.74);
  font-size: var(--text-sm);
  font-weight: 500;
  text-decoration: none;
  transition: background 0.18s ease, color 0.18s ease;
}

.bx--header__menu-item:hover {
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
  text-decoration: none;
}

.bx--header__menu-item--current,
.bx--header__menu-item--current:hover {
  background: rgba(255, 255, 255, 0.16);
  color: #fff;
}

.bx--header .bx--btn--ghost {
  color: rgba(255, 255, 255, 0.82);
}

.bx--header .bx--btn--ghost:hover {
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
}

.bx--text-truncate--front {
  white-space: nowrap;
}

/* ——— Typography ——— */

.bx--type-productive-heading-04,
.ecg-page-header h1 {
  margin: 0;
  font-size: var(--text-3xl);
  font-weight: 600;
  line-height: 1.15;
  letter-spacing: -0.025em;
  color: var(--ecg-text);
  text-wrap: balance;
}

.bx--type-productive-heading-02,
.ecg-section-title {
  margin: 0;
  font-size: var(--text-xl);
  font-weight: 600;
  line-height: 1.3;
  letter-spacing: -0.012em;
  color: var(--ecg-text);
}

.bx--type-productive-heading-01 {
  margin: 0 0 0.75rem;
  font-size: var(--text-lg);
  font-weight: 600;
  line-height: 1.35;
  color: var(--ecg-text);
}

/* ——— Buttons ——— */

.bx--btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.375rem;
  min-height: 2.5rem;
  padding: 0 1.1rem;
  border: 1px solid transparent;
  border-radius: var(--ecg-radius-sm);
  font-family: inherit;
  font-size: var(--text-sm);
  font-weight: 600;
  line-height: 1;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.18s ease, border-color 0.18s ease,
    transform 0.12s ease, box-shadow 0.18s ease;
}

.bx--btn:hover {
  text-decoration: none;
}

.bx--btn:active:not(:disabled) {
  transform: translateY(1px);
}

.bx--btn:focus-visible {
  outline: 2px solid var(--ecg-primary);
  outline-offset: 2px;
}

.bx--btn--primary {
  background: var(--ecg-primary);
  color: var(--ecg-on-primary, #fff);
  box-shadow: var(--ecg-shadow-sm);
}

.bx--btn--primary:hover {
  background: var(--ecg-primary-hover);
  color: var(--ecg-on-primary, #fff);
}

.bx--btn--secondary {
  background: var(--ecg-surface);
  border-color: var(--ecg-border-strong);
  color: var(--ecg-text);
}

.bx--btn--secondary:hover {
  background: var(--ecg-surface-muted);
  color: var(--ecg-text);
}

/* The secondary action of a screen: white, outlined, equal in weight to the
   primary but not in colour — the mockups' «Экспорт» beside «Новый план».
   `--tertiary` was never defined, so every header's second action and every
   toolbar's «Поиск» fell back to bare `.bx--btn` (transparent border, no
   background) and read as a floating blue word. */
.bx--btn--tertiary {
  background: var(--ecg-surface);
  border-color: var(--ecg-border-strong);
  color: var(--ecg-text);
}

.bx--btn--tertiary:hover {
  background: var(--ecg-surface-muted);
  border-color: var(--ecg-text-muted);
  color: var(--ecg-text);
}

.bx--btn--ghost {
  background: transparent;
  color: var(--ecg-primary);
}

.bx--btn--ghost:hover {
  background: var(--ecg-primary-soft);
  color: var(--ecg-primary-hover);
}

.bx--btn--sm {
  min-height: 2rem;
  padding: 0 0.75rem;
  font-size: var(--text-xs);
}

.bx--btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/* ——— Forms ——— */

.bx--form-item {
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
}

.bx--label {
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--ecg-text-muted);
}

.bx--text-input,
.bx--select-input,
.bx--text-area {
  width: 100%;
  min-height: 2.5rem;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--ecg-border-strong);
  border-radius: var(--ecg-radius-sm);
  background: var(--ecg-surface);
  color: var(--ecg-text);
  font-family: inherit;
  font-size: var(--text-sm);
  transition: border-color 0.18s ease, box-shadow 0.18s ease;
}

.bx--text-input::placeholder,
.bx--text-area::placeholder {
  color: var(--ecg-text-muted);
}

.bx--text-input:hover,
.bx--select-input:hover,
.bx--text-area:hover {
  border-color: var(--ecg-primary);
}

.bx--text-input:focus,
.bx--select-input:focus,
.bx--text-area:focus {
  border-color: var(--ecg-primary);
  outline: none;
  box-shadow: 0 0 0 3px var(--ecg-focus-ring);
}

/* Multi-line: matches the inputs beside it (the class was previously undefined,
   so the support textarea fell back to raw browser styling). */
.bx--text-area {
  line-height: 1.5;
  resize: vertical;
}

.bx--select {
  position: relative;
}

/* Native <select> — reset the OS chevron for a token-consistent one so selects
   match the teal-bordered inputs in both themes. */
select.bx--select-input {
  appearance: none;
  -webkit-appearance: none;
  padding-right: 2rem;
  cursor: pointer;
  background-repeat: no-repeat;
  background-position: right 0.65rem center;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='7' viewBox='0 0 10 7'><path d='M1 1l4 4 4-4' fill='none' stroke='%235c706d' stroke-width='1.4' stroke-linecap='round' stroke-linejoin='round'/></svg>");
}

html[data-theme="dark"] select.bx--select-input {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='7' viewBox='0 0 10 7'><path d='M1 1l4 4 4-4' fill='none' stroke='%238ba39f' stroke-width='1.4' stroke-linecap='round' stroke-linejoin='round'/></svg>");
}

@media (prefers-color-scheme: dark) {
  html:not([data-theme="light"]) select.bx--select-input {
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='7' viewBox='0 0 10 7'><path d='M1 1l4 4 4-4' fill='none' stroke='%238ba39f' stroke-width='1.4' stroke-linecap='round' stroke-linejoin='round'/></svg>");
  }
}

/* ——— Navigation tiles (legitimate cards: they are link targets) ——— */

.bx--tile {
  background: var(--ecg-surface);
  border-radius: var(--ecg-radius);
  box-shadow: var(--ecg-shadow-sm);
  padding: 1.25rem;
}

.bx--tile--clickable {
  display: block;
  text-decoration: none;
  color: inherit;
  border-top: 3px solid transparent;
  transition: box-shadow 0.18s ease, transform 0.18s ease,
    border-color 0.18s ease;
}

.bx--tile--clickable:hover {
  border-top-color: var(--ecg-primary);
  box-shadow: var(--ecg-shadow-md);
  transform: translateY(-2px);
  text-decoration: none;
}

.bx--tile--clickable:focus-visible {
  outline: 2px solid var(--ecg-primary);
  outline-offset: 2px;
}

.bx--tile__title {
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--ecg-text-muted);
  margin: 0 0 0.5rem;
}

.bx--tile__count {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: var(--text-3xl);
  font-weight: 600;
  line-height: 1;
  color: var(--ecg-primary);
}

/* ——— Tables ——— */

.bx--data-table-container {
  overflow-x: auto;
  background: var(--ecg-surface);
  border: 1px solid var(--ecg-border);
  border-radius: var(--ecg-radius);
}

/* Inside the elevated panel the table sits flush */
.ecg-card--flush .bx--data-table-container {
  border: 0;
  border-radius: 0;
  background: transparent;
}

.bx--data-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: var(--text-sm);
}

.bx--data-table thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  padding: 0.75rem 1rem;
  background: var(--ecg-surface-muted);
  border-bottom: 1px solid var(--ecg-border);
  color: var(--ecg-text-muted);
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: 0.02em;
  text-align: left;
  white-space: nowrap;
}

.bx--data-table tbody td {
  padding: 0.8125rem 1rem;
  border-bottom: 1px solid var(--ecg-border);
  vertical-align: middle;
  color: var(--ecg-text);
}

.bx--data-table tbody tr:last-child td {
  border-bottom: none;
}

.bx--data-table tbody tr:hover td {
  background: var(--ecg-row-hover);
}

.bx--table-header-label {
  display: block;
}

/* Compact density for dense operational tables (auth events, uploads, status
   changes). The class was requested by 5 tables but had no CSS, so they all
   rendered at full row height. */
.bx--data-table--compact thead th {
  padding: 0.5rem 1rem;
}

.bx--data-table--compact tbody td {
  padding: 0.5rem 1rem;
}

/* ——— Status tags ——— */

.bx--tag {
  display: inline-flex;
  align-items: center;
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.bx--tag--green {
  background: var(--ecg-good-bg);
  color: var(--ecg-good-fg);
}

.bx--tag--gray {
  background: var(--ecg-warn-bg);
  color: var(--ecg-warn-fg);
}

.bx--tag--red {
  background: var(--ecg-bad-bg);
  color: var(--ecg-bad-fg);
}

.bx--tag--blue {
  background: var(--ecg-primary-soft);
  color: var(--ecg-primary-hover);
}

/* ——— Breadcrumb ——— */

.bx--breadcrumb {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.375rem;
  margin: 0;
  padding: 0;
  list-style: none;
  font-size: var(--text-sm);
}

.bx--breadcrumb-item {
  display: inline-flex;
  align-items: center;
  color: var(--ecg-text-muted);
}

.bx--breadcrumb-item:not(:last-child)::after {
  content: "/";
  margin-left: 0.375rem;
  color: var(--ecg-border-strong);
}

.bx--link {
  color: var(--ecg-primary);
  text-decoration: none;
}

.bx--link:hover {
  text-decoration: underline;
}

.bx--link:focus-visible {
  outline: 2px solid var(--ecg-primary);
  outline-offset: 2px;
  border-radius: 2px;
}

/* ——— Notifications ——— */

.bx--inline-notification {
  display: flex;
  flex-direction: column;
  padding: 0.875rem 1rem;
  border-radius: var(--ecg-radius-sm);
  border: 1px solid transparent;
  border-left-width: 3px;
  margin-bottom: 0.75rem;
}

.bx--inline-notification--error {
  background: var(--ecg-bad-bg);
  border-color: var(--ecg-bad-fg);
  color: var(--ecg-bad-fg);
}

.bx--inline-notification--warning {
  background: var(--ecg-warn-bg);
  border-color: var(--ecg-warn-fg);
  color: var(--ecg-warn-fg);
}

/* Success is the most common post-action feedback (save/upload) — it was
   previously undefined, so it rendered as a transparent, near-invisible box. */
.bx--inline-notification--success {
  background: var(--ecg-good-bg);
  border-color: var(--ecg-good-fg);
  color: var(--ecg-good-fg);
}

.bx--inline-notification--info {
  background: var(--ecg-primary-soft);
  border-color: var(--ecg-primary);
  color: var(--ecg-primary-hover);
}

.bx--inline-notification__subtitle {
  margin: 0;
  font-size: var(--text-sm);
}

/* ——— Pagination ——— */

.bx--pagination {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-top: 1.25rem;
  padding-top: 1rem;
  border-top: 1px solid var(--ecg-border);
}

.bx--pagination__text {
  font-size: var(--text-sm);
  color: var(--ecg-text-muted);
}

.bx--pagination__control-buttons {
  display: flex;
  gap: 0.5rem;
}

/* ——— Column picker dropdown ——— */

.bx--dropdown {
  position: relative;
}

.bx--dropdown summary {
  list-style: none;
  cursor: pointer;
}

.bx--dropdown summary::-webkit-details-marker {
  display: none;
}

.bx--dropdown #column-picker {
  position: absolute;
  right: 0;
  top: calc(100% + 0.375rem);
  z-index: 20;
  min-width: 12rem;
  padding: 0.5rem;
  background: var(--ecg-surface);
  border: 1px solid var(--ecg-border);
  border-radius: var(--ecg-radius-sm);
  box-shadow: var(--ecg-shadow-md);
  list-style: none;
  margin: 0;
}

@media (max-width: 768px) {
  .bx--header {
    flex-wrap: wrap;
    padding: 0.75rem 1rem;
    gap: 0.75rem;
  }

  .bx--header__nav {
    order: 3;
    flex-basis: 100%;
  }

  .bx--header__menu-bar {
    overflow-x: auto;
    flex-wrap: nowrap;
    padding-bottom: 0.25rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  .bx--btn,
  .bx--tile--clickable,
  a {
    transition: none;
  }
}

.ecg-skeleton-bar {
  display: block;
  inline-size: min(7rem, 72%);
  min-inline-size: 1rem;
  block-size: 0.7rem;
  border-radius: 0.2rem;
  background: var(--ecg-surface-muted);
  background: color-mix(in srgb, var(--ecg-text) 13%, var(--ecg-surface));
}

.ecg-skeleton-bar--check {
  inline-size: 1rem;
  block-size: 1rem;
}

.ecg-records-loading {
  padding: 1rem;
}

.ecg-records-loading__row {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  align-items: center;
  gap: 1rem;
  min-block-size: 2.5rem;
  border-block-end: 1px solid var(--ecg-border);
}

.ecg-records-loading__row:last-child {
  border-block-end: 0;
}

.ecg-waveform-loading {
  display: grid;
  place-content: center;
  min-block-size: 15rem;
  padding: 1rem;
  border: 1px solid var(--ecg-border);
  border-radius: var(--ecg-radius-sm);
  background: var(--ecg-surface);
  color: var(--ecg-text-muted);
  font-size: 0.875rem;
  text-align: center;
}

.ecg-waveform-loading--compact {
  min-block-size: 150px;
}

.ecg-waveform-loading .ecg-skeleton-bar {
  inline-size: 0.65rem;
  min-inline-size: 0;
  block-size: 0.65rem;
  border-radius: 50%;
  margin: 0 auto 0.6rem;
}

@media (prefers-reduced-motion: no-preference) {
  .ecg-skeleton-bar {
    animation: ecg-skeleton-pulse 1.8s ease-in-out 3;
  }
}

@keyframes ecg-skeleton-pulse {
  50% { opacity: 0.63; }
}
