/* The conversation is the primary profile surface; the record is a quiet reference. */
:root[data-design="inside"] .sidebar .nav-item[data-route="/profile"] { --nav-ico: var(--ico-profile); }

#profileView .profile-home {
  --profile-ink: #1d342d;
  --profile-muted: #61736a;
  --profile-line: #dce5dc;
  --profile-soft: #f5f8f3;
  --profile-accent: #2b7454;
  width: min(100%, 1440px);
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(320px, 1fr);
  grid-template-rows: auto auto;
  align-items: start;
  gap: 18px 24px;
  color: var(--profile-ink);
  font-size: 18px;
  line-height: 1.5;
  overflow-wrap: anywhere;
}
#profileView .profile-home > * { min-width: 0; }
#profileView .profile-home [hidden] { display: none !important; }

#profileView .profile-home-header { grid-column: 1 / -1; padding: 0 0 3px; }
#profileView .profile-home-eyebrow {
  margin: 0 0 5px;
  color: var(--profile-accent);
  font-size: 14px;
  font-weight: 650;
  letter-spacing: .08em;
  text-transform: uppercase;
}
#profileView .profile-home-header h1 {
  max-width: 26ch;
  margin: 0;
  color: var(--profile-ink);
  font-family: var(--font-display, inherit);
  font-size: clamp(33px, 3vw, 42px);
  font-weight: 650;
  letter-spacing: -.035em;
  line-height: 1.13;
}
#profileView .profile-home-subtitle { margin: 7px 0 0; color: var(--profile-muted); font-size: 16px; }

#profileView .profile-home-conversation {
  grid-column: 1;
  grid-row: 2;
  display: grid;
  grid-template-rows: auto minmax(170px, 1fr) auto auto auto;
  min-width: 0;
  min-height: 620px;
  height: clamp(620px, 75dvh, 820px);
  border: 1px solid var(--profile-line);
  border-radius: 22px;
  background: #fff;
  box-shadow: 0 10px 32px #183d2c0a;
  overflow: hidden;
}
#profileView .profile-home-conversation.has-active-question { height: auto; grid-template-rows: auto minmax(100px, 270px) auto auto auto; }
#profileView .profile-home-conversation.has-active-question .profile-home-messages { min-height: 100px; max-height: min(28dvh, 270px); }
#profileView .profile-home-conversation-head {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  padding: 24px 28px 19px;
  border-bottom: 1px solid var(--profile-line);
}
#profileView .profile-home-conversation-head > div { min-width: 0; }
#profileView .profile-home-conversation-kicker {
  margin: 0 0 3px;
  color: var(--profile-accent);
  font-size: 13px;
  font-weight: 650;
  letter-spacing: .04em;
}
#profileView .profile-home-conversation-head h2 {
  margin: 0;
  color: var(--profile-ink);
  font-family: var(--font-display, inherit);
  font-size: clamp(25px, 2.2vw, 30px);
  font-weight: 650;
  letter-spacing: -.025em;
  line-height: 1.2;
}
#profileView .profile-home-conversation-head p:last-child {
  max-width: 54ch;
  margin: 8px 0 0;
  color: var(--profile-muted);
  font-size: 15px;
  line-height: 1.45;
}
#profileView .profile-home-count {
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: center;
  min-width: 32px;
  height: 32px;
  padding: 0 8px;
  border-radius: 999px;
  background: #e3efe5;
  color: #275d3c;
  font-size: 14px;
  font-weight: 700;
}

#profileView .profile-home-conversation .profile-home-messages {
  min-width: 0;
  min-height: 170px;
  overflow-x: hidden;
  overflow-y: auto;
  padding: 24px 28px;
  background: #fff;
  scrollbar-gutter: stable;
  scrollbar-color: #b9c9bb transparent;
}
#profileView .profile-home-conversation .profile-home-messages:empty::before {
  content: "История разговора появится здесь.";
  display: block;
  max-width: 45ch;
  margin: 12px auto;
  color: var(--profile-muted);
  font-size: 16px;
  text-align: center;
}
#profileView .profile-home-conversation:has(.profile-home-messages :is(.profile-chat-welcome, .chat-empty)) {
  height: auto;
  min-height: 0;
  grid-template-rows: auto auto auto auto auto;
}
#profileView .profile-home-conversation .profile-home-messages:has(:is(.profile-chat-welcome, .chat-empty)) {
  min-height: 0;
  max-height: none;
  padding-block: 13px;
}
#profileView .profile-home-messages .profile-chat-welcome {
  max-width: 52ch;
  margin: 0 auto;
  padding: 13px 0;
  text-align: center;
}
#profileView .profile-home-messages .profile-chat-welcome > span {
  color: var(--profile-accent);
  font-size: 20px;
  line-height: 1;
}
#profileView .profile-home-messages .profile-chat-welcome h3 {
  margin: 7px 0 4px;
  color: var(--profile-ink);
  font-size: 19px;
  font-weight: 650;
  line-height: 1.3;
}
#profileView .profile-home-messages .profile-chat-welcome p,
#profileView .profile-home-messages .chat-empty p { margin: 0; color: var(--profile-muted); font-size: 15px; line-height: 1.5; }
#profileView .profile-home-messages .chat-empty { min-height: 0; padding: 10px 0; }
#profileView .profile-home-messages .chat-empty > strong { font-size: 19px; }
#profileView .profile-home-messages .profile-chat-loading {
  max-width: 48ch;
  margin: 0 auto;
  padding: 16px 0;
  color: var(--profile-muted);
  font-size: 15px;
  line-height: 1.5;
  text-align: center;
}
#profileView .profile-home-messages .profile-chat-loading p { margin: 0 0 14px; }
#profileView .profile-home-messages .profile-chat-loading button { min-height: 44px; }

#profileView .profile-home-attention,
#profileView .profile-home-chat-composer {
  min-width: 0;
  padding: 16px 24px 12px;
  border-top: 1px solid var(--profile-line);
  background: #fbfcf9;
}
#profileView .profile-home-attention { max-height: min(420px, 46dvh); overflow-y: auto; }
#profileView .profile-home-attention > p[role="status"] { margin: 0; color: var(--profile-muted); font-size: 15px; }
#profileView .profile-home-attention .profile-home-section-head { margin-bottom: 5px; }
#profileView .profile-home-attention .profile-home-section-head h2 { font-size: 18px; }
#profileView .profile-home-attention-intro { margin: 0 0 12px; color: var(--profile-muted); font-size: 14px; }
#profileView .profile-home-attention .attention-list { display: grid; gap: 10px; }
#profileView .profile-home-attention .attention-card {
  min-width: 0;
  margin: 0;
  padding: 16px 18px;
  border: 1px solid var(--profile-line);
  border-radius: 15px;
  background: #fff;
  box-shadow: none;
}
#profileView .profile-home-attention .attention-card h3 { margin: 2px 0 6px; font-size: 18px; line-height: 1.3; }
#profileView .profile-home-attention .attention-kind { color: var(--profile-accent); font-size: 12px; }
#profileView .profile-home-attention :is(.attention-prompt, .attention-card-document p) { font-size: 18px; font-weight: 600; line-height: 1.4; }
#profileView .profile-home-conversation .profile-home-attention .attention-card:not(.attention-card-document) > .attention-prompt {
  color: var(--profile-ink);
  font-family: var(--font-text, inherit);
  font-size: 18px;
  font-weight: 600;
  line-height: 1.4;
}
#profileView .profile-home-attention .attention-card-document { align-items: flex-start; flex-direction: column; gap: 12px; }
#profileView .profile-home-attention .attention-card form { grid-template-columns: minmax(0, 1fr) auto; }
#profileView .profile-home-attention .attention-card :is(button, textarea) { min-height: 44px; }
#profileView .profile-home-conversation .profile-home-attention .attention-card form .secondary-button {
  border: 1px solid var(--profile-accent);
  background: var(--profile-accent);
  color: #fff;
  box-shadow: none;
  font-weight: 600;
}
#profileView .profile-home-conversation .profile-home-attention .attention-card form .secondary-button:hover:not(:disabled) {
  border-color: #205a41;
  background: #205a41;
  color: #fff;
  box-shadow: none;
}
#profileView .profile-home-conversation .profile-home-attention .attention-card form .secondary-button:disabled {
  border-color: #cad7cc;
  background: #cad7cc;
  color: #435849;
  box-shadow: none;
}
#profileView .profile-home-attention .attention-empty { padding: 13px 15px; background: #f0f6ee; }

#profileView .profile-home-chat-composer .scoped-composer-wrap {
  padding: 0;
  border: 0;
  background: transparent;
}
#profileView .profile-home-chat-composer .scoped-composer { max-width: none; }
#profileView .profile-home-chat-toggle {
  justify-self: start;
  min-height: 44px;
  margin: 0 24px 12px;
  padding-inline: 12px;
  color: var(--profile-accent);
  font-size: 15px;
  font-weight: 600;
}
#profileView .profile-home-chat-status {
  min-height: 0;
  margin: 0;
  padding: 0 24px;
  color: var(--profile-muted);
  font-size: 14px;
}
#profileView .profile-home-chat-status:not(:empty) { padding-bottom: 14px; }

#profileView .profile-home-reference {
  grid-column: 2;
  grid-row: 2;
  min-width: 0;
  border: 1px solid var(--profile-line);
  border-radius: 20px;
  background: #fff;
  box-shadow: 0 8px 25px #183d2c07;
}
#profileView .profile-home-reference-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 21px 22px 16px;
}
#profileView .profile-home-reference-head h2 {
  margin: 0;
  color: var(--profile-ink);
  font-family: var(--font-display, inherit);
  font-size: 22px;
  font-weight: 650;
  letter-spacing: -.02em;
  line-height: 1.2;
}
#profileView .profile-home-reference-head button,
#profileView .profile-home-section-head button { flex: 0 0 auto; min-height: 44px; font-size: 14px; }
#profileView .profile-home-reference-head button svg { width: 16px; height: 16px; margin-right: 6px; vertical-align: -3px; }
#profileView .profile-home-passport,
#profileView .profile-home-summary { min-width: 0; padding: 17px 22px 20px; border-top: 1px solid var(--profile-line); }
#profileView .profile-home-section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 9px;
  margin-bottom: 12px;
}
#profileView .profile-home-section-head :is(h2, h3) {
  margin: 0;
  color: var(--profile-ink);
  font-family: var(--font-display, inherit);
  font-size: 19px;
  font-weight: 650;
  line-height: 1.25;
}
#profileView .profile-home-metrics { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0; margin: 0; }
#profileView .profile-home-metrics > div { min-width: 0; padding: 2px 10px; border-left: 1px solid var(--profile-line); }
#profileView .profile-home-metrics > div:first-child { padding-left: 0; border-left: 0; }
#profileView .profile-home-metrics dt { margin: 0 0 2px; color: var(--profile-muted); font-size: 13px; }
#profileView .profile-home-metrics dd { margin: 0; color: var(--profile-ink); font-size: 21px; font-weight: 650; line-height: 1.2; }
#profileView .profile-home-metrics dd > span:not(.profile-home-unknown) { color: var(--profile-muted); font-size: 13px; font-weight: 400; }
#profileView .profile-home-metrics dd .profile-home-unknown { color: var(--profile-muted); font-size: 13px; font-weight: 400; line-height: 1.3; }
#profileView .profile-home-metrics > div > small { display: block; margin-top: 4px; color: var(--profile-muted); font-size: 11px; line-height: 1.3; }
#profileView .profile-home-metrics a,
#profileView .profile-home-summary-link { color: var(--profile-accent); text-underline-offset: 3px; }
#profileView .profile-home-measured { margin: 10px 0 0; color: var(--profile-muted); font-size: 13px; }
#profileView .profile-home-passport .profile-editor { margin-top: 16px; padding: 17px; border-color: var(--profile-line); border-radius: 13px; background: var(--profile-soft); }
#profileView .profile-home-passport .profile-editor-fields { grid-template-columns: minmax(0, 1fr); gap: 12px; }
#profileView .profile-home-summary-date { color: var(--profile-muted); font-size: 13px; }
#profileView .profile-home-summary-text { margin: 0; color: #354b3d; font-size: 16px; line-height: 1.6; white-space: pre-wrap; }
#profileView .profile-home-muted { color: var(--profile-muted); }
#profileView .profile-home-summary-link { display: inline-flex; align-items: center; gap: 6px; margin-top: 10px; font-size: 14px; font-weight: 600; }
#profileView .profile-home-summary-link svg { width: 15px; height: 15px; }
#profileView .profile-home-summary .epicrisis-status { margin: 14px 0 0; padding: 14px; border-color: var(--profile-line); border-radius: 12px; background: var(--profile-soft); }
#profileView .profile-home-summary .epicrisis-status p { font-size: 14px; }
#profileView .profile-home-summary .epicrisis-status button { min-height: 44px; }
#profileView .profile-home-reference .profile-home-summary [data-epicrisis-generate] {
  border: 1px solid var(--profile-line);
  background: #fff;
  color: var(--profile-accent);
  box-shadow: none;
}

#profileView .profile-medical-story {
  grid-column: 1 / -1;
  grid-row: 3;
  min-width: 0;
  border: 1px solid var(--profile-line);
  border-radius: 18px;
  background: #fff;
}
#profileView .profile-medical-story > summary {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 70px;
  padding: 15px 22px;
  list-style: none;
  cursor: pointer;
}
#profileView .profile-medical-story > summary::-webkit-details-marker { display: none; }
#profileView .profile-medical-story > summary > span { min-width: 0; }
#profileView .profile-home-story-title { display: block; color: var(--profile-ink); font-size: 17px; font-weight: 650; line-height: 1.3; }
#profileView .profile-medical-story > summary span span { display: block; color: var(--profile-muted); font-size: 13px; line-height: 1.35; }
#profileView .profile-medical-story > summary svg { flex: 0 0 18px; width: 18px; height: 18px; margin-left: auto; color: var(--profile-accent); }
#profileView .profile-medical-story[open] > summary svg { transform: rotate(180deg); }
#profileView .profile-medical-story > summary:hover { background: var(--profile-soft); }
#profileView .profile-clinical-document.epicrisis-document { max-width: 1100px; margin: 0 auto; padding: 0 22px 28px; border: 0; border-radius: 0; box-shadow: none; }
#profileView .profile-clinical-document .epicrisis-section { border-color: var(--profile-line); }
#profileView .profile-clinical-document .epicrisis-text { font-size: 16px; line-height: 1.6; }
#profileView .profile-clinical-document .epicrisis-table-scroll { max-width: 100%; }

#profileView .profile-home :is(button, a, summary, input, select, textarea):focus-visible { outline: 3px solid #6ab58b; outline-offset: 3px; }

@media (max-width: 980px) {
  #profileView .profile-home { grid-template-columns: minmax(0, 1fr); gap: 14px; }
  #profileView .profile-home-header { grid-column: 1; }
  #profileView .profile-home-conversation { grid-column: 1; grid-row: 2; }
  #profileView .profile-home-reference { grid-column: 1; grid-row: 3; }
  #profileView .profile-medical-story { grid-column: 1; grid-row: 4; }
}

@media (max-width: 650px) {
  #profileView .profile-home { font-size: 16px; }
  #profileView .profile-home-header h1 { font-size: clamp(29px, 8vw, 38px); }
  #profileView .profile-home-conversation {
    height: auto;
    min-height: 0;
    grid-template-rows: auto minmax(210px, auto) auto auto auto;
    border-radius: 17px;
  }
  #profileView .profile-home-conversation-head { flex-direction: column; gap: 8px; padding: 19px 18px 15px; }
  #profileView .profile-home-conversation-kicker { display: none; }
  #profileView .profile-home-conversation-head .profile-home-count { align-self: start; height: 26px; }
  #profileView .profile-home-conversation-head h2 { font-size: 24px; }
  #profileView .profile-home-conversation-head p:last-child { font-size: 14px; }
  #profileView .profile-home-conversation .profile-home-messages { min-height: 210px; max-height: min(42dvh, 360px); padding: 18px 15px; }
  #profileView .profile-home-conversation .profile-home-messages:has(:is(.profile-chat-welcome, .chat-empty)) { min-height: 0; max-height: none; padding-block: 10px; }
  #profileView .profile-home-attention,
  #profileView .profile-home-chat-composer { padding: 14px 14px 10px; }
  #profileView .profile-home-attention { max-height: none; overflow: visible; }
  #profileView .profile-home-conversation.has-active-question { grid-template-rows: auto minmax(80px, 130px) auto auto auto; }
  #profileView .profile-home-conversation.has-active-question .profile-home-messages { min-height: 80px; max-height: 130px; }
  #profileView .profile-home-attention .attention-card { padding: 14px; }
  #profileView .profile-home-attention .attention-card form { grid-template-columns: minmax(0, 1fr); }
  #profileView .profile-home-attention .attention-card form button { justify-self: start; }
  #profileView .profile-home-chat-toggle { margin: 0 14px 10px; }
  #profileView .profile-home-chat-status { padding-inline: 14px; }
  #profileView .profile-home-reference { border-radius: 17px; }
  #profileView .profile-home-reference-head,
  #profileView .profile-home-passport,
  #profileView .profile-home-summary { padding-inline: 17px; }
  #profileView .profile-clinical-document.epicrisis-document { padding-inline: 17px; }
}

@media (max-width: 390px) {
  #profileView .profile-home-metrics > div { padding-inline: 6px; }
  #profileView .profile-home-metrics > div:first-child { padding-left: 0; }
  #profileView .profile-home-reference-head h2 { font-size: 19px; }
}
