:root {
  color-scheme: light;
  --bg: #f4f7f8;
  --surface: #ffffff;
  --surface-soft: #eef5f2;
  --surface-raised: #fbfdfc;
  --surface-muted: #f4f6f5;
  --control-bg: #ffffff;
  --hover-bg: #e2ede9;
  --border: #d9e3e1;
  --text: #182422;
  --muted: #61706d;
  --accent: #167a68;
  --accent-strong: #0f5f51;
  --amber: #b86e14;
  --blue: #326f9f;
  --danger: #b43434;
  --danger-strong: #9b2525;
  --danger-soft: #fdeaea;
  --warning: #b86e14;
  --warning-strong: #9a5a00;
  --warning-soft: #fff4df;
  --success-soft: #e8f5f0;
  --low-soft: #e8f1f8;
  --unknown-soft: #edf0ef;
  --row-high: #fff7f7;
  --row-low: #f6fbff;
  --row-normal: #fbfefd;
  --chart-grid: rgba(97, 112, 109, 0.16);
  --shadow: 0 10px 28px rgba(26, 45, 43, 0.06), 0 2px 8px rgba(26, 45, 43, 0.04);
  --accent-glow: 0 0 14px rgba(22, 122, 104, 0.25);
  
  /* Smooth transitions */
  --transition-fast: 0.15s ease;
  --transition-normal: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  --transition-slow: 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #111715;
    --surface: #18211f;
    --surface-soft: #22302c;
    --surface-raised: #151d1a;
    --surface-muted: #202926;
    --control-bg: #121a18;
    --hover-bg: #253530;
    --border: #31413d;
    --text: #eef6f3;
    --muted: #a2b3ae;
    --accent: #47bca3;
    --accent-strong: #7edbc7;
    --amber: #e4a75c;
    --blue: #78acd7;
    --danger: #ef7d7d;
    --danger-strong: #ffb3b3;
    --danger-soft: rgba(239, 125, 125, 0.14);
    --warning: #e4a75c;
    --warning-strong: #ffd28f;
    --warning-soft: rgba(228, 167, 92, 0.16);
    --success-soft: rgba(71, 188, 163, 0.14);
    --low-soft: rgba(120, 172, 215, 0.15);
    --unknown-soft: rgba(162, 179, 174, 0.14);
    --row-high: rgba(239, 125, 125, 0.09);
    --row-low: rgba(120, 172, 215, 0.1);
    --row-normal: rgba(71, 188, 163, 0.08);
    --chart-grid: rgba(162, 179, 174, 0.18);
    --shadow: 0 16px 42px rgba(0, 0, 0, 0.28), 0 2px 10px rgba(0, 0, 0, 0.22);
    --accent-glow: 0 0 18px rgba(71, 188, 163, 0.28);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111715;
  --surface: #18211f;
  --surface-soft: #22302c;
  --surface-raised: #151d1a;
  --surface-muted: #202926;
  --control-bg: #121a18;
  --hover-bg: #253530;
  --border: #31413d;
  --text: #eef6f3;
  --muted: #a2b3ae;
  --accent: #47bca3;
  --accent-strong: #7edbc7;
  --amber: #e4a75c;
  --blue: #78acd7;
  --danger: #ef7d7d;
  --danger-strong: #ffb3b3;
  --danger-soft: rgba(239, 125, 125, 0.14);
  --warning: #e4a75c;
  --warning-strong: #ffd28f;
  --warning-soft: rgba(228, 167, 92, 0.16);
  --success-soft: rgba(71, 188, 163, 0.14);
  --low-soft: rgba(120, 172, 215, 0.15);
  --unknown-soft: rgba(162, 179, 174, 0.14);
  --row-high: rgba(239, 125, 125, 0.09);
  --row-low: rgba(120, 172, 215, 0.1);
  --row-normal: rgba(71, 188, 163, 0.08);
  --chart-grid: rgba(162, 179, 174, 0.18);
  --shadow: 0 16px 42px rgba(0, 0, 0, 0.28), 0 2px 10px rgba(0, 0, 0, 0.22);
  --accent-glow: 0 0 18px rgba(71, 188, 163, 0.28);
}

* {
  box-sizing: border-box;
  scrollbar-color: var(--border) transparent;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

.telegram-webapp body {
  background: var(--tg-bg, var(--bg));
  color: var(--tg-text, var(--text));
}

.app-mode-patient #new-patient {
  display: none;
}

.app-mode-patient #patient-select {
  pointer-events: none;
}

.developer-only {
  display: none !important;
}

.app-mode-developer .developer-only {
  display: inline-flex !important;
}

.auth-pending .topbar,
.auth-pending .tab-nav,
.auth-pending .tab-panel,
.auth-pending #dev-toggle {
  display: none !important;
}

.auth-pending .workspace {
  min-height: 100vh;
}

.auth-required {
  background: var(--bg);
}

.auth-required .workspace {
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: 24px;
}

.auth-required .topbar,
.auth-required .topbar-patient,
.auth-required .topbar-actions,
.auth-required .tab-nav,
.auth-required .tab-panel,
.auth-required #dev-toggle {
  display: none !important;
}

.auth-panel {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 16px;
  width: min(420px, 100%);
  padding: 34px 28px;
  margin: 0;
  text-align: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.auth-logo {
  width: 92px;
  height: 92px;
  object-fit: contain;
}

.auth-panel h2 {
  margin: 0;
  font-size: 22px;
}

.auth-panel p {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.telegram-login-widget {
  display: none;
}

.telegram-login-fallback {
  width: 100%;
  max-width: 260px;
  height: 46px;
  border: 0;
  border-radius: 8px;
  padding: 0 18px;
  background: var(--accent);
  color: #ffffff;
  font-weight: 700;
  cursor: pointer;
}

.telegram-login-fallback:hover {
  background: var(--accent-strong);
}

.developer-logout {
  position: fixed;
  top: 18px;
  right: 18px;
  z-index: 35;
  align-items: center;
  gap: 8px;
  min-height: 38px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--accent-strong);
  font-weight: 700;
  box-shadow: var(--shadow);
  cursor: pointer;
}

.developer-logout:hover {
  border-color: rgba(22, 122, 104, 0.35);
  background: var(--surface-soft);
}

.developer-logout i {
  width: 18px;
  height: 18px;
}

button,
input,
select {
  font: inherit;
}

input::placeholder,
textarea::placeholder {
  color: var(--muted);
  opacity: 1;
}

input::file-selector-button {
  min-height: 30px;
  margin-right: 8px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--surface-soft);
  color: var(--text);
  font: inherit;
  cursor: pointer;
}

.app-shell {
  min-height: 100vh;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 22px;
  border-right: 1px solid var(--border);
  background: var(--surface-raised);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 48px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  flex: 0 0 42px;
  border-radius: 10px;
  background: transparent;
  color: transparent;
  font-weight: 800;
}

.brand-logo-mark {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.brand h1,
.topbar h2,
.section-head h3 {
  margin: 0;
  line-height: 1.1;
}

.brand h1 {
  font-size: 22px;
}

.brand p,
.topbar p,
.section-head p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 13px;
}

#status-line[data-tone="warn"] {
  color: var(--amber);
}

#status-line[data-tone="error"] {
  color: var(--danger);
}

.panel,
.patient-summary,
.dashboard-section,
.record-section,
.chart-section,
.review-section,
.deviation-section,
.parameter-card,
.summary-pane,
.table-pane {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  transition: box-shadow var(--transition-normal), border-color var(--transition-normal);
}

.panel:hover,
.patient-summary:hover,
.dashboard-section:hover,
.record-section:hover,
.chart-section:hover,
.deviation-section:hover,
.parameter-card:hover {
  box-shadow: 0 14px 36px rgba(26, 45, 43, 0.1), 0 4px 12px rgba(26, 45, 43, 0.04);
  border-color: rgba(22, 122, 104, 0.25);
}

.panel {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 16px;
}

.panel-title,
.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.panel-title {
  justify-content: flex-start;
  color: var(--accent-strong);
  font-weight: 700;
}

.panel-title svg,
button svg {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
}

.patient-select-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 38px;
  gap: 8px;
  align-items: end;
}

.patient-select-row label {
  min-width: 0;
}

.patient-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(112px, 0.72fr);
  gap: 10px;
}

.upload-dashboard-card {
  gap: 16px;
  padding: 18px;
}

.upload-form-grid {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) minmax(260px, max-content);
  gap: 12px;
  align-items: end;
}

.upload-dashboard-card .upload-submit {
  align-self: end;
}

.upload-options {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
}

.checkbox-option {
  display: inline-flex;
  grid-template-columns: none;
  align-items: center;
  gap: 8px;
  width: fit-content;
  color: var(--text);
  font-size: 13px;
  font-weight: 700;
}

.checkbox-option input {
  width: 16px;
  min-height: 16px;
  margin: 0;
  accent-color: var(--accent);
}

.upload-progress {
  display: grid;
  gap: 7px;
}

.upload-progress-track {
  position: relative;
  height: 9px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--border);
}

.upload-progress-track span {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent), var(--blue));
  transition: width 0.35s ease;
}

.upload-progress.is-active .upload-progress-track span {
  background-image:
    repeating-linear-gradient(
      45deg,
      rgba(255, 255, 255, 0.25) 0,
      rgba(255, 255, 255, 0.25) 8px,
      rgba(255, 255, 255, 0) 8px,
      rgba(255, 255, 255, 0) 16px
    ),
    linear-gradient(90deg, var(--accent), var(--blue));
  background-size: 28px 28px, 100% 100%;
  animation: upload-progress-stripes 1s linear infinite;
}

.upload-progress-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  color: var(--muted);
  font-size: 12px;
}

#upload-progress-label {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#upload-progress-percent {
  flex: 0 0 auto;
  color: var(--accent-strong);
  font-weight: 800;
}

@keyframes upload-progress-stripes {
  from {
    background-position: 0 0, 0 0;
  }
  to {
    background-position: 28px 0, 0 0;
  }
}

.upload-audit {
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  border-radius: 8px;
  background: var(--surface-raised);
}

.upload-audit[data-status="warning"] {
  border-left-color: var(--warning);
}

.upload-audit[data-status="error"] {
  border-left-color: var(--danger);
}

.upload-audit-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.upload-audit-head > div:first-child {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.upload-audit-head strong {
  color: var(--text);
  font-size: 14px;
}

.upload-audit-head span {
  color: var(--muted);
  font-size: 12px;
}

.upload-audit-metrics {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px;
}

.upload-audit-pill {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--success-soft);
  color: var(--accent-strong);
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.upload-audit-pill.tone-warning {
  background: var(--warning-soft);
  color: var(--warning-strong);
}

.upload-audit-pill.tone-error {
  background: var(--danger-soft);
  color: var(--danger);
}

.upload-audit-list {
  display: grid;
  gap: 8px;
}

.upload-audit-item {
  display: grid;
  gap: 3px;
  padding: 9px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--control-bg);
}

.upload-audit-item.severity-warning {
  border-color: var(--warning);
}

.upload-audit-item.severity-error {
  border-color: var(--danger);
}

.upload-audit-item strong {
  color: var(--text);
  font-size: 13px;
}

.upload-audit-item span,
.upload-audit-item small,
.upload-audit-more {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.upload-audit-more {
  font-weight: 700;
}

input,
select {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--control-bg);
  color: var(--text);
  padding: 8px 10px;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

select {
  overflow: hidden;
  padding-right: 34px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

input:focus,
select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(22, 122, 104, 0.15);
}

.checkbox-option input[type="checkbox"] {
  width: 16px;
  min-height: 16px;
  padding: 0;
  border-radius: 4px;
}

.check-row {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
}

.check-row input {
  width: 16px;
  min-height: 16px;
}

button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 38px;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 700;
  transition: background-color var(--transition-fast), transform var(--transition-fast), box-shadow var(--transition-fast);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.62;
}

button:active:not(:disabled) {
  transform: scale(0.97);
}

.primary-action {
  background: var(--accent);
  color: #fff;
}

.primary-action:hover:not(:disabled) {
  background: var(--accent-strong);
  box-shadow: var(--accent-glow);
}

.upload-submit {
  width: 100%;
  min-height: 42px;
  padding: 8px 12px;
  justify-content: center;
  gap: 8px;
  border-radius: 8px;
}

.upload-submit span {
  min-width: 0;
  overflow-wrap: anywhere;
  line-height: 1.2;
  text-align: center;
  white-space: normal;
}

.upload-submit svg {
  width: 17px;
  height: 17px;
}

.secondary-action {
  background: var(--surface-soft);
  color: var(--accent-strong);
  border: 1px solid transparent;
  transition: background-color var(--transition-fast), border-color var(--transition-fast), transform var(--transition-fast);
}

.secondary-action:hover:not(:disabled) {
  background: var(--hover-bg);
  border-color: rgba(22, 122, 104, 0.2);
}

.icon-action {
  width: 36px;
  min-height: 36px;
  padding: 0;
  background: var(--surface-soft);
  color: var(--accent-strong);
  border: 1px solid transparent;
  transition: background-color var(--transition-fast), border-color var(--transition-fast), transform var(--transition-fast);
}

.icon-action:hover:not(:disabled) {
  background: var(--hover-bg);
  border-color: rgba(22, 122, 104, 0.2);
}

.danger-action {
  background: var(--danger);
  color: #fff;
}

.danger-action.subtle {
  background: var(--danger-soft);
  color: var(--danger-strong);
}

.workspace {
  display: flex;
  flex-direction: column;
  gap: 18px;
  min-width: 0;
  padding: 24px;
}

.topbar {
  display: grid;
  grid-template-columns: auto minmax(320px, 1fr) auto;
  grid-template-areas:
    "brand title refresh"
    "patient patient metrics";
  align-items: center;
  gap: 12px 18px;
}

.topbar-main {
  display: contents;
}

.topbar .brand {
  grid-area: brand;
  position: relative;
  min-width: 64px;
  min-height: 64px;
  gap: 0;
}

.topbar .brand-mark {
  width: 64px;
  height: 64px;
  flex-basis: 64px;
}

.topbar .brand > div:not(.brand-mark) {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}

.topbar-title {
  grid-area: title;
  min-width: 0;
  max-width: 720px;
}

.topbar-patient,
.topbar-patient .patient-select-row label {
  min-width: 0;
}

.topbar-patient {
  grid-area: patient;
  max-width: 720px;
}

.topbar-patient .patient-select-row {
  grid-template-columns: minmax(280px, 520px) 36px;
  align-items: center;
  justify-content: start;
}

.topbar-patient .patient-select-row label {
  gap: 0;
}

.topbar-patient .patient-select-row label > span {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}

.topbar-actions {
  display: contents;
}

.topbar-refresh {
  grid-area: refresh;
  flex: 0 0 auto;
  justify-self: end;
  padding: 0 14px;
  white-space: nowrap;
}

.topbar h2 {
  font-size: 28px;
}

.metric-strip {
  display: flex;
  grid-area: metrics;
  justify-self: end;
  gap: 8px;
}

.metric-strip div {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 38px;
  min-width: 112px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
}

.metric-strip span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.15;
}

.metric-strip strong {
  display: block;
  margin-top: 0;
  font-size: 17px;
}

.tab-nav {
  position: sticky;
  top: 0;
  z-index: 12;
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 2px;
  border-bottom: 1px solid var(--border);
  padding: 8px 0 0 2px;
  background: var(--bg);
  box-shadow: 0 10px 18px rgba(26, 45, 43, 0.04);
}

.tab-menu-toggle {
  display: none;
}

.tab-menu-items {
  display: contents;
}

.tab-button {
  min-height: 40px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-bottom: 0;
  border-radius: 8px 8px 0 0;
  background: var(--surface-soft);
  color: var(--muted);
  font-size: 13px;
  box-shadow: none;
}

.tab-button.active {
  position: relative;
  z-index: 1;
  border-color: var(--border);
  background: var(--surface);
  color: var(--accent-strong);
  transform: translateY(1px);
}

.tab-button:not(.active):hover {
  background: var(--surface-soft);
  color: var(--accent-strong);
}

.tab-panel {
  display: flex;
  flex-direction: column;
  gap: 18px;
  min-width: 0;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr);
  gap: 18px;
}

.patient-summary,
.dashboard-section,
.record-section {
  min-width: 0;
  padding: 18px;
}

.patient-summary-head {
  min-width: 0;
}

.patient-title-row {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.patient-title-row h3 {
  min-width: 0;
  overflow-wrap: anywhere;
}

.patient-edit-action {
  flex: 0 0 auto;
}

.patient-name-editor {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) max-content 36px;
  gap: 8px;
  align-items: center;
  margin-top: 10px;
  max-width: 620px;
}

.patient-name-editor .secondary-action {
  min-width: 120px;
  padding: 0 12px;
}

.patient-name-editor input {
  min-width: 0;
}

.dashboard-section.wide {
  grid-column: 1 / -1;
}

.patient-focus {
  display: grid;
  grid-template-columns: 112px minmax(0, 1fr);
  gap: 16px;
  align-items: start;
  margin: 14px 0;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-raised);
}

.patient-focus h4 {
  margin: 0 0 10px;
  font-size: 14px;
}

.patient-figure {
  position: relative;
  width: 112px;
  height: 112px;
  justify-self: center;
  align-self: start;
  margin-top: 18px;
  --avatar-stroke: var(--accent);
}

.patient-figure::before {
  display: none;
}

.patient-figure .patient-icon {
  position: absolute;
  inset: 0;
  z-index: 1;
  width: 100%;
  height: 100%;
  border-radius: 8px;
  object-fit: contain;
}

.patient-age-badge {
  position: absolute;
  right: -4px;
  bottom: -4px;
  z-index: 2;
  min-width: 32px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--avatar-stroke);
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  line-height: 1.5;
  text-align: center;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.18);
}

.patient-age-badge:empty {
  display: none;
}

.patient-figure.avatar-female {
  --avatar-stroke: #cb4f9b;
}

.patient-figure.avatar-male {
  --avatar-stroke: #0c7dc4;
}

.focus-list {
  display: grid;
  gap: 8px;
}

.focus-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 18px;
  gap: 10px;
  width: 100%;
  min-height: 52px;
  padding: 9px 10px;
  border: 1px solid var(--border);
  border-left: 4px solid var(--muted);
  border-radius: 8px;
  background: var(--control-bg);
  color: var(--text);
  text-align: left;
  transition: transform var(--transition-fast), background-color var(--transition-fast), box-shadow var(--transition-fast), border-color var(--transition-fast);
}

.focus-item:hover {
  transform: translateY(-2px);
  background: var(--surface);
  border-color: rgba(22, 122, 104, 0.25);
  box-shadow: 0 6px 16px rgba(26, 45, 43, 0.05);
}

.focus-item strong,
.focus-item em {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.focus-item em {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
  font-style: normal;
}

.focus-item.priority-critical,
.focus-item.priority-high {
  border-left-color: var(--danger);
}

.focus-item.priority-medium,
.focus-item.priority-important,
.focus-item.priority-watch {
  border-left-color: var(--amber);
}

.focus-item.priority-low,
.focus-item.priority-normal {
  border-left-color: var(--accent);
}

.summary-list {
  display: grid;
  gap: 8px;
}

.summary-item {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) max-content;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 64px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--control-bg);
  color: var(--text);
  text-align: left;
  transition: transform var(--transition-fast), background-color var(--transition-fast), box-shadow var(--transition-fast), border-color var(--transition-fast);
}

.summary-item:hover {
  transform: translateY(-2px);
  background: var(--surface);
  border-color: rgba(22, 122, 104, 0.25);
  box-shadow: 0 6px 16px rgba(26, 45, 43, 0.05);
}

.summary-icon {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: var(--success-soft);
  color: var(--accent);
}

.summary-icon svg {
  width: 17px;
  height: 17px;
}

.summary-copy {
  min-width: 0;
}

.summary-copy strong,
.summary-count {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.summary-copy em {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
  font-style: normal;
  line-height: 1.35;
  white-space: normal;
}

.summary-count {
  color: var(--blue);
  font-weight: 800;
}

.summary-side {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  justify-self: end;
}

.summary-chevron {
  width: 16px;
  height: 16px;
  color: var(--muted);
  transition: transform var(--transition-fast);
}

.summary-item.is-expanded {
  align-items: start;
}

.summary-item.is-expanded .summary-chevron {
  transform: rotate(180deg);
}

.summary-details {
  grid-column: 2 / -1;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding-top: 2px;
}

.summary-details span {
  max-width: 100%;
  padding: 4px 8px;
  border-radius: 999px;
  background: var(--surface-soft);
  color: var(--text);
  font-size: 12px;
  line-height: 1.35;
}

.summary-item.is-stale,
.summary-item.is-empty {
  background: var(--surface-muted);
  color: var(--muted);
}

.summary-item.is-stale .summary-icon,
.summary-item.is-empty .summary-icon {
  background: var(--unknown-soft);
  color: var(--muted);
}

.summary-item.is-stale .summary-count,
.summary-item.is-empty .summary-count,
.summary-item.is-stale .summary-copy em,
.summary-item.is-empty .summary-copy em,
.summary-item.is-stale .summary-chevron,
.summary-item.is-empty .summary-chevron {
  color: var(--muted);
}

.summary-item.is-stale .summary-details span,
.summary-item.is-empty .summary-details span {
  background: var(--unknown-soft);
  color: var(--muted);
}

.chart-controls {
  display: grid;
  grid-template-columns: minmax(150px, 0.9fr) minmax(170px, 1fr) max-content;
  gap: 8px;
  align-items: center;
  min-width: min(100%, 560px);
}

.chart-controls .secondary-action {
  min-width: 112px;
  padding: 0 12px;
}

.compare-selection {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  min-height: 30px;
  margin: 2px 0 12px;
}

.compare-selection:empty {
  display: none;
}

.compare-chip,
.compare-clear {
  min-height: 28px;
  padding: 3px 9px;
  border: 1px solid var(--border);
  background: var(--control-bg);
  color: var(--accent-strong);
  font-size: 12px;
  font-weight: 800;
}

.compare-chip svg {
  width: 14px;
  height: 14px;
}

.compare-clear {
  background: var(--surface-soft);
  color: var(--muted);
}

.record-layout {
  display: grid;
  grid-template-columns: minmax(280px, 360px) minmax(0, 1fr);
  gap: 18px;
}

.record-layout.record-layout-collapsed {
  grid-template-columns: 1fr;
}

.record-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

@keyframes slideDownFade {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.record-form {
  display: grid;
  align-content: start;
  gap: 12px;
}

.record-form:not(.hidden) {
  animation: slideDownFade var(--transition-slow);
}

.audio-consultation-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 0.9fr);
  gap: 18px;
  align-items: start;
}

.audio-consultation-source,
.audio-consultation-fields {
  display: grid;
  gap: 12px;
  min-width: 0;
}

.audio-consultation-grid {
  display: grid;
  grid-template-columns: minmax(180px, 220px) minmax(0, 1fr);
  gap: 12px;
}

.audio-consultation-section textarea {
  min-height: 112px;
}

#audio-consultation-transcript {
  min-height: 220px;
}

.audio-consultation-footer {
  display: flex;
  justify-content: flex-end;
  margin-top: 14px;
}

textarea {
  width: 100%;
  min-height: 120px;
  resize: vertical;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--control-bg);
  color: var(--text);
  padding: 8px 10px;
  font: inherit;
  line-height: 1.4;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(22, 122, 104, 0.15);
}

.record-list {
  display: grid;
  align-content: start;
  gap: 10px;
  min-width: 0;
}

.record-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 36px;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  border-radius: 8px;
  background: var(--control-bg);
  transition: transform var(--transition-fast), background-color var(--transition-fast), box-shadow var(--transition-fast), border-color var(--transition-fast);
}

.record-item:hover {
  transform: translateY(-2px);
  background: var(--surface);
  border-color: rgba(22, 122, 104, 0.25);
  box-shadow: 0 6px 16px rgba(26, 45, 43, 0.05);
}

.record-item.priority-critical,
.record-item.priority-high {
  border-left-color: var(--danger);
}

.record-item.priority-medium,
.record-item.priority-important,
.record-item.priority-watch {
  border-left-color: var(--amber);
}

.record-item.priority-low,
.record-item.priority-normal,
.record-item.is-active {
  border-left-color: var(--accent);
}

.record-item h4,
.record-item p {
  margin: 0;
}

.record-date {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.record-item h4 {
  font-size: 15px;
}

.record-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.record-chip {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  padding: 2px 7px;
  border-radius: 999px;
  background: var(--unknown-soft);
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.record-item p {
  margin-top: 6px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
  white-space: pre-wrap;
}

.chart-section,
.review-section,
.deviation-section,
.parameter-card {
  padding: 18px;
}

.hidden {
  display: none !important;
}

.review-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.review-section.is-attention {
  border-color: rgba(22, 122, 104, 0.45);
  box-shadow: 0 16px 34px rgba(22, 122, 104, 0.14);
}

.editor-wrap {
  max-height: 360px;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
}

.editor-table {
  min-width: 1180px;
}

.editor-table input[type="text"],
.editor-table input[type="number"],
.editor-table input[type="date"] {
  min-height: 32px;
  padding: 6px 8px;
  font-size: 12px;
}

.editor-table input[type="checkbox"] {
  width: 16px;
  min-height: 16px;
}

.review-row.status-high td {
  background: var(--row-high);
}

.review-row.status-low td {
  background: var(--row-low);
}

.review-row.status-normal td {
  background: var(--row-normal);
}

.deviation-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 460px), 1fr));
  gap: 12px;
}

.deviation-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) max-content;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 64px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-left-width: 4px;
  border-radius: 8px;
  background: var(--control-bg);
  color: var(--text);
  text-align: left;
  transition: transform var(--transition-fast), background-color var(--transition-fast), box-shadow var(--transition-fast), border-color var(--transition-fast);
}

.deviation-card:hover {
  transform: translateY(-2px);
  background: var(--surface);
  border-color: rgba(22, 122, 104, 0.25);
  box-shadow: 0 6px 16px rgba(26, 45, 43, 0.05);
}

.deviation-card.status-high {
  border-left-color: var(--danger);
}

.deviation-card.status-low {
  border-left-color: var(--blue);
}

.deviation-card > span:first-child {
  min-width: 0;
}

.deviation-card strong,
.deviation-card em {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.deviation-card em {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
  font-style: normal;
}

.deviation-value {
  display: grid;
  justify-items: end;
  gap: 5px;
  min-width: 120px;
  color: var(--blue);
  font-weight: 800;
  white-space: nowrap;
}

.empty-state {
  padding: 14px;
  border: 1px dashed var(--border);
  border-radius: 8px;
  color: var(--muted);
  background: var(--control-bg);
}

.parameter-card-body {
  display: grid;
  gap: 14px;
}

.detail-stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.detail-stat {
  min-width: 0;
  padding: 12px;
  border: 1px solid var(--border);
  border-left: 4px solid var(--muted);
  border-radius: 8px;
  background: var(--surface-raised);
}

.detail-stat.status-normal {
  border-left-color: var(--accent);
}

.detail-stat.status-high {
  border-left-color: var(--danger);
}

.detail-stat.status-low {
  border-left-color: var(--blue);
}

.detail-stat span,
.detail-stat em {
  display: block;
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  font-style: normal;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.detail-stat strong {
  display: block;
  overflow: hidden;
  margin: 6px 0 4px;
  color: var(--text);
  font-size: 18px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.detail-stat em {
  display: flex;
  align-items: center;
  gap: 6px;
}

.tag-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.tag,
.muted-text {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--surface-soft);
  color: var(--accent-strong);
  font-size: 12px;
  font-weight: 700;
}

.muted-text {
  color: var(--muted);
  background: var(--unknown-soft);
}

.detail-table-wrap {
  max-height: 260px;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
}

.chart-wrap {
  position: relative;
  height: 320px;
  margin-top: 14px;
}

.data-grid {
  display: grid;
  grid-template-columns: 360px minmax(0, 1fr);
  gap: 18px;
  min-width: 0;
}

.summary-pane,
.table-pane {
  min-width: 0;
  padding: 16px;
}

.compact {
  margin-bottom: 12px;
}

.parameter-list {
  display: grid;
  gap: 8px;
  max-height: 420px;
  overflow: auto;
}

.parameter-item {
  width: 100%;
  justify-content: space-between;
  align-items: center;
  min-height: 50px;
  padding: 9px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--control-bg);
  color: var(--text);
  text-align: left;
  transition: transform var(--transition-fast), background-color var(--transition-fast), box-shadow var(--transition-fast), border-color var(--transition-fast);
}

.parameter-item:hover {
  transform: translateY(-1px);
  border-color: rgba(22, 122, 104, 0.25);
  box-shadow: 0 4px 12px rgba(26, 45, 43, 0.04);
}

.parameter-item.active {
  border-color: var(--accent);
  background: var(--surface-soft);
  box-shadow: var(--accent-glow);
}

.parameter-item.is-compared {
  box-shadow: inset 0 0 0 2px rgba(22, 122, 104, 0.18);
}

.parameter-item.status-high {
  border-left: 4px solid var(--danger);
}

.parameter-item.status-low {
  border-left: 4px solid var(--blue);
}

.parameter-item.status-normal {
  border-left: 4px solid var(--accent);
}

.parameter-item.status-unknown {
  border-left: 4px solid var(--muted);
}

.parameter-item.status-fact {
  border-left: 4px solid var(--muted);
}

.parameter-main {
  min-width: 0;
}

.parameter-main strong,
.parameter-main span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.parameter-main span {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.parameter-value {
  color: var(--blue);
  font-weight: 800;
  white-space: nowrap;
}

.parameter-side {
  display: grid;
  justify-items: end;
  gap: 5px;
  flex: 0 0 auto;
  max-width: 128px;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 20px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 800;
  line-height: 1.2;
  white-space: nowrap;
}

.status-badge.status-normal {
  background: var(--success-soft);
  color: var(--accent-strong);
}

.status-badge.status-high {
  background: var(--danger-soft);
  color: var(--danger-strong);
}

.status-badge.status-low {
  background: var(--low-soft);
  color: var(--blue);
}

.status-badge.status-unknown {
  background: var(--unknown-soft);
  color: var(--muted);
}

.status-badge.status-fact {
  background: var(--unknown-soft);
  color: var(--muted);
}

.table-wrap {
  max-height: 420px;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

th,
td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--surface-soft);
  color: var(--muted);
  font-size: 12px;
}

td strong {
  color: var(--accent-strong);
}

.result-row.status-high td {
  background: var(--row-high);
}

.result-row.status-low td {
  background: var(--row-low);
}

.result-row.status-normal td {
  background: var(--row-normal);
}

.result-row.status-high td:first-child {
  border-left: 4px solid var(--danger);
}

.result-row.status-low td:first-child {
  border-left: 4px solid var(--blue);
}

.result-row.status-normal td:first-child {
  border-left: 4px solid var(--accent);
}

.ref-cell {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

pre {
  min-height: 160px;
  max-height: 320px;
  overflow: auto;
  margin: 0;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #101615;
  color: #d9fff3;
  font-size: 12px;
  line-height: 1.5;
}

.dev-toggle {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 20;
  width: 48px;
  min-height: 48px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  box-shadow: 0 14px 34px rgba(16, 49, 45, 0.22);
}

.dev-panel {
  position: fixed;
  right: 22px;
  bottom: 84px;
  z-index: 20;
  display: flex;
  flex-direction: column;
  gap: 14px;
  width: min(560px, calc(100vw - 32px));
  max-height: min(760px, calc(100vh - 112px));
  padding: 16px;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 18px 46px rgba(16, 49, 45, 0.2);
}

.dev-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.dev-head h3 {
  margin: 0;
  font-size: 17px;
  line-height: 1.2;
}

.dev-head p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.dev-usage {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.dev-usage:empty {
  display: none;
}

.dev-usage-card {
  display: grid;
  gap: 5px;
  min-width: 0;
  min-height: 108px;
  padding: 12px;
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  border-radius: 8px;
  background: var(--surface-raised);
}

.dev-usage-card.tone-strong {
  border-left-color: var(--blue);
}

.dev-usage-card span,
.dev-usage-card em {
  display: block;
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  font-style: normal;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dev-usage-card strong {
  display: block;
  overflow: hidden;
  color: var(--text);
  font-size: 26px;
  line-height: 1.05;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dev-actions,
.dev-danger-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.dev-actions button,
.dev-danger-actions button {
  justify-content: flex-start;
  min-width: 0;
  padding: 0 10px;
}

.dev-actions span,
.dev-danger-actions span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dev-danger {
  display: grid;
  gap: 10px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.dev-log-output {
  min-height: 180px;
  max-height: 300px;
  font-size: 11px;
}

@media (max-width: 1320px) {
  .topbar {
    grid-template-columns: auto minmax(0, 1fr) auto;
    grid-template-areas:
      "brand title refresh"
      "patient patient patient"
      "metrics metrics metrics";
  }

  .metric-strip {
    justify-self: start;
    flex-wrap: wrap;
  }
}

@media (max-width: 980px) {
  .dashboard-grid,
  .upload-form-grid,
  .record-layout,
  .audio-consultation-layout,
  .audio-consultation-grid,
  .data-grid {
    grid-template-columns: 1fr;
  }

  .topbar {
    grid-template-columns: 1fr;
    grid-template-areas:
      "brand"
      "title"
      "patient"
      "refresh"
      "metrics";
    align-items: stretch;
    gap: 12px;
  }

  .topbar .brand,
  .topbar-title {
    min-width: 0;
  }

  .topbar-patient {
    min-width: 0;
    max-width: none;
  }

  .topbar-patient .patient-select-row {
    grid-template-columns: minmax(0, 1fr) 36px;
  }

  .topbar-refresh {
    justify-self: stretch;
    width: 100%;
  }

  .metric-strip {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    justify-self: stretch;
  }

  .metric-strip div {
    min-width: 0;
  }

  .chart-controls {
    grid-template-columns: 1fr;
    width: 100%;
  }

}

@media (max-width: 820px) {
  .tab-nav {
    display: grid;
    align-items: stretch;
    gap: 8px;
    padding: 8px 0;
    border-bottom: 0;
  }

  .tab-menu-toggle {
    display: grid;
    grid-template-columns: 18px minmax(0, 1fr) 18px;
    width: 100%;
    min-height: 44px;
    padding: 0 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
    color: var(--accent-strong);
    box-shadow: var(--shadow);
  }

  .tab-menu-toggle span {
    min-width: 0;
    overflow: hidden;
    text-align: left;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .tab-menu-toggle svg:last-child {
    transition: transform var(--transition-fast);
  }

  .tab-nav.is-open .tab-menu-toggle svg:last-child {
    transform: rotate(180deg);
  }

  .tab-menu-items {
    display: none;
    grid-template-columns: 1fr;
    gap: 6px;
    max-height: min(58vh, 360px);
    overflow: auto;
    padding: 8px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
    box-shadow: var(--shadow);
  }

  .tab-nav.is-open .tab-menu-items {
    display: grid;
  }

  .tab-button {
    width: 100%;
    min-height: 42px;
    justify-content: flex-start;
    border: 1px solid transparent;
    border-radius: 8px;
    background: transparent;
  }

  .tab-button.active {
    border-color: rgba(22, 122, 104, 0.18);
    background: var(--surface-soft);
    transform: none;
  }
}

@media (max-width: 640px) {
  .workspace {
    padding: 16px;
  }

  .metric-strip {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .detail-stats,
  .upload-form-grid,
  .patient-grid,
  .patient-name-editor,
  .patient-focus {
    grid-template-columns: 1fr;
  }

  .patient-name-editor .secondary-action,
  .patient-name-editor .icon-action {
    width: 100%;
  }

  .tab-button {
    width: 100%;
    justify-content: flex-start;
  }

  .tab-nav {
    display: grid;
    align-items: stretch;
    gap: 8px;
    padding: 8px 0;
    border-bottom: 0;
  }

  .tab-menu-toggle {
    display: grid;
    grid-template-columns: 18px minmax(0, 1fr) 18px;
    width: 100%;
    min-height: 42px;
    padding: 0 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
    color: var(--accent-strong);
    box-shadow: var(--shadow);
  }

  .tab-menu-toggle span {
    min-width: 0;
    overflow: hidden;
    text-align: left;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .tab-menu-toggle svg:last-child {
    transition: transform var(--transition-fast);
  }

  .tab-nav.is-open .tab-menu-toggle svg:last-child {
    transform: rotate(180deg);
  }

  .tab-menu-items {
    display: none;
    grid-template-columns: 1fr;
    gap: 6px;
    padding: 8px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
    box-shadow: var(--shadow);
  }

  .tab-nav.is-open .tab-menu-items {
    display: grid;
  }

  .tab-button {
    min-height: 42px;
    border: 1px solid transparent;
    border-radius: 8px;
    background: transparent;
  }

  .tab-button.active {
    border-color: rgba(22, 122, 104, 0.18);
    background: var(--surface-soft);
    transform: none;
  }

  .chart-wrap {
    height: 260px;
  }

  .dev-panel {
    right: 16px;
    bottom: 78px;
  }

  .dev-actions,
  .dev-danger-actions,
  .dev-usage {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  body {
    overflow-x: hidden;
  }

  .workspace {
    gap: 14px;
  }

  .topbar {
    grid-template-columns: 52px minmax(0, 1fr);
    grid-template-areas:
      "brand title"
      "patient patient"
      "refresh refresh"
      "metrics metrics";
    gap: 10px 12px;
  }

  .topbar .brand {
    min-width: 52px;
    min-height: 52px;
  }

  .topbar .brand-mark {
    width: 52px;
    height: 52px;
    flex-basis: 52px;
  }

  .topbar-title {
    align-self: center;
  }

  .topbar h2 {
    font-size: 23px;
    line-height: 1.08;
    overflow-wrap: anywhere;
  }

  .topbar p,
  .section-head p {
    font-size: 12px;
    line-height: 1.35;
  }

  .metric-strip {
    gap: 6px;
  }

  .metric-strip div {
    display: grid;
    align-content: center;
    gap: 4px;
    min-height: 54px;
    padding: 8px 7px;
  }

  .metric-strip span {
    font-size: 11px;
  }

  .metric-strip strong {
    font-size: 18px;
  }

  .panel,
  .patient-summary,
  .dashboard-section,
  .record-section,
  .chart-section,
  .review-section,
  .deviation-section,
  .parameter-card,
  .summary-pane,
  .table-pane {
    padding: 14px;
    border-radius: 10px;
  }

  .section-head {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }

  .parameter-card .section-head {
    flex-direction: row;
    align-items: flex-start;
  }

  .section-head > div,
  .patient-summary-head {
    min-width: 0;
  }

  .record-actions,
  .review-actions,
  .audio-consultation-footer {
    display: grid;
    grid-template-columns: 1fr;
    width: 100%;
  }

  .record-actions button,
  .review-actions button,
  .audio-consultation-footer button {
    width: 100%;
    justify-content: center;
  }

  .upload-dashboard-card {
    padding: 14px;
  }

  .upload-submit,
  .topbar-refresh,
  .telegram-login-fallback {
    min-height: 46px;
  }

  input,
  select,
  textarea {
    font-size: 16px;
  }

  .patient-focus {
    grid-template-columns: 84px minmax(0, 1fr);
    gap: 12px;
    padding: 12px;
  }

  .patient-figure {
    width: 84px;
    height: 84px;
    margin-top: 0;
  }

  .focus-item strong,
  .focus-item em,
  .summary-copy strong,
  .summary-copy em,
  .parameter-main strong,
  .parameter-main span,
  .deviation-card strong,
  .deviation-card em,
  .record-item h4,
  .record-item p {
    white-space: normal;
  }

  .summary-item {
    grid-template-columns: 34px minmax(0, 1fr) auto;
    align-items: start;
  }

  .summary-side {
    align-self: center;
  }

  .deviation-card {
    grid-template-columns: 1fr;
    align-items: start;
  }

  .deviation-value {
    justify-items: start;
    min-width: 0;
    white-space: normal;
  }

  .record-item {
    grid-template-columns: minmax(0, 1fr) 36px;
  }

  .parameter-item {
    align-items: flex-start;
    gap: 10px;
  }

  .parameter-side {
    max-width: 112px;
  }

  .table-wrap,
  .detail-table-wrap,
  .editor-wrap {
    max-width: 100%;
    overflow: auto;
  }

  .table-wrap table:not(.pivot-table),
  .detail-table-wrap table,
  .editor-table {
    min-width: 680px;
  }

  .detail-stats {
    gap: 8px;
  }

  .detail-stat strong {
    white-space: normal;
  }

  .auth-panel {
    width: min(360px, 100%);
    padding: 28px 20px;
  }

  .auth-logo {
    width: 82px;
    height: 82px;
  }
}

@media (max-width: 420px) {
  .workspace {
    padding: 10px;
  }

  .topbar {
    grid-template-columns: 46px minmax(0, 1fr);
    gap: 9px 10px;
  }

  .topbar .brand {
    min-width: 46px;
    min-height: 46px;
  }

  .topbar .brand-mark {
    width: 46px;
    height: 46px;
    flex-basis: 46px;
  }

  .topbar h2 {
    font-size: 21px;
  }

  .metric-strip div {
    min-height: 50px;
    padding: 7px 5px;
  }

  .metric-strip span {
    font-size: 10px;
  }

  .patient-focus {
    grid-template-columns: 74px minmax(0, 1fr);
    gap: 10px;
    padding: 10px;
  }

  .patient-figure {
    width: 74px;
    height: 74px;
  }

  .patient-age-badge {
    min-width: 28px;
    padding: 1px 7px;
    font-size: 11px;
  }

  .summary-item {
    grid-template-columns: 32px minmax(0, 1fr);
  }

  .summary-side {
    grid-column: 2;
    justify-self: start;
  }

  .record-item,
  .deviation-card {
    padding: 10px;
  }

  .dev-panel {
    right: 10px;
    left: 10px;
    width: auto;
    bottom: 72px;
  }

  .dev-toggle {
    right: 14px;
    bottom: 14px;
  }
}

/* Labs Pivot Table */
.labs-pivot-section {
  margin-bottom: 24px;
}

.labs-pivot-section .table-wrap {
  max-height: 460px;
  overflow: auto;
  overscroll-behavior-x: contain;
}

.pivot-table {
  --pivot-table-width: 980px;
  --pivot-date-count: 1;
  --pivot-name-col-width: 300px;
  --pivot-date-col-width: 96px;
  --pivot-ref-col-width: 300px;
  --pivot-unit-col-width: 96px;
  width: max(100%, var(--pivot-table-width));
  min-width: var(--pivot-table-width);
  table-layout: fixed;
  font-size: 15px; /* Kрупнее шрифт для таблицы */
  border-spacing: 0;
  border-collapse: collapse;
}

.pivot-table th {
  font-size: 13px;
  padding: 14px 16px;
  background: var(--surface-soft);
  color: var(--muted);
  font-weight: 600;
  border-bottom: 2px solid var(--border);
}

.pivot-table td {
  text-align: center;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}

.pivot-table .pivot-name-head,
.pivot-table .pivot-name-cell {
  text-align: left;
  font-weight: 500;
  width: var(--pivot-name-col-width);
  min-width: var(--pivot-name-col-width);
  max-width: var(--pivot-name-col-width);
}

.pivot-table .pivot-name-head,
.pivot-table .pivot-row .pivot-name-cell {
  position: sticky;
  left: 0;
  z-index: 2;
  background: var(--surface);
  box-shadow: 1px 0 0 var(--border);
}

.pivot-table .pivot-name-head {
  z-index: 4;
  background: var(--surface-soft);
}

.pivot-table .pivot-date-head,
.pivot-table .pivot-date-cell {
  width: var(--pivot-date-col-width);
  min-width: var(--pivot-date-col-width);
  max-width: var(--pivot-date-col-width);
}

.pivot-table .pivot-date-head {
  padding: 10px 8px;
  line-height: 1.25;
  white-space: normal;
}

.pivot-table .pivot-date-cell {
  padding: 12px 8px;
  white-space: nowrap;
}

.pivot-table .pivot-ref-head,
.pivot-table td.pivot-ref-cell {
  width: var(--pivot-ref-col-width);
  min-width: var(--pivot-ref-col-width);
  max-width: var(--pivot-ref-col-width);
}

.pivot-table .pivot-unit-head,
.pivot-table td.pivot-unit-cell {
  width: var(--pivot-unit-col-width);
  min-width: var(--pivot-unit-col-width);
  max-width: var(--pivot-unit-col-width);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Элементы аккордеона групп */
.pivot-group-header {
  cursor: pointer;
  background-color: var(--surface-soft) !important;
  user-select: none;
  transition: background-color var(--transition-fast);
}

.pivot-group-header:hover td {
  background-color: var(--border) !important;
}

.pivot-group-header td {
  text-align: left !important;
  padding: 12px 16px !important;
  color: var(--accent-strong) !important;
  font-size: 14px !important;
  font-weight: 600 !important;
  border-bottom: 2px solid var(--border) !important;
}

.pivot-group-header-content {
  display: flex;
  align-items: center;
  gap: 10px;
}

.pivot-group-toggle-icon {
  display: inline-block;
  transition: transform var(--transition-normal);
  font-size: 11px;
  color: var(--accent);
}

.pivot-group-header.expanded .pivot-group-toggle-icon {
  transform: rotate(90deg);
}

.pivot-group-count {
  font-size: 12px;
  color: var(--muted);
  font-weight: normal;
  margin-left: 4px;
}

/* Hover-эффекты на обычные строки */
.pivot-table tr.pivot-row:hover td {
  background-color: var(--surface-soft);
}

.pivot-table td.status-high {
  background-color: var(--row-high) !important;
  color: var(--danger) !important;
  font-weight: 600;
}

.pivot-table td.status-low {
  background-color: var(--row-low) !important;
  color: var(--blue) !important;
  font-weight: 600;
}

.pivot-table td.status-normal {
  color: var(--text);
}

.pivot-table .pivot-ref-cell {
  overflow: hidden;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pivot-row.hidden {
  display: none !important;
}
