:root {
  color-scheme: light;
  --bg: #f7f5f1;
  --ink: #1f2328;
  --muted: #68707a;
  --panel: #ffffff;
  --line: #ded9cf;
  --accent: #0d7f73;
  --accent-dark: #075c54;
  --amber: #b86b14;
  --red: #b23b3b;
  --blue: #315f91;
  --shadow: 0 18px 48px rgba(33, 37, 41, 0.08);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.75), rgba(247, 245, 241, 0.9)),
    var(--bg);
  color: var(--ink);
  overflow-x: hidden;
}

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.shell {
  width: min(1440px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0 44px;
}

.topbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  padding: 8px 0 22px;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--accent-dark);
  font-size: 0.82rem;
  font-weight: 800;
  letter-spacing: 0;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 8px;
  font-size: clamp(2.2rem, 5vw, 4.4rem);
  line-height: 0.98;
  letter-spacing: 0;
}

.subtitle {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 1.08rem;
  overflow-wrap: anywhere;
}

.status-panel,
.config-bar,
.notice,
.panel {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.86);
  box-shadow: var(--shadow);
}

.status-panel {
  min-width: 220px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  border-radius: 8px;
}

.status-panel strong,
.status-panel span {
  display: block;
}

.status-panel span:last-child {
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.86rem;
}

.status-dot {
  width: 13px;
  height: 13px;
  border-radius: 999px;
  background: var(--amber);
  box-shadow: 0 0 0 5px rgba(184, 107, 20, 0.12);
}

.status-dot.ok {
  background: var(--accent);
  box-shadow: 0 0 0 5px rgba(13, 127, 115, 0.12);
}

.status-dot.error {
  background: var(--red);
  box-shadow: 0 0 0 5px rgba(178, 59, 59, 0.12);
}

.config-bar {
  display: grid;
  grid-template-columns: auto minmax(260px, 1fr) auto auto;
  align-items: center;
  gap: 10px;
  padding: 10px;
  border-radius: 8px;
  margin-bottom: 14px;
}

.config-bar > * {
  min-width: 0;
}

.config-bar label {
  padding-left: 6px;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 700;
}

input,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffdfa;
  color: var(--ink);
  outline: none;
}

input {
  min-height: 42px;
  padding: 0 12px;
}

textarea {
  resize: vertical;
  min-height: 132px;
  padding: 14px;
  line-height: 1.62;
}

input:focus,
textarea:focus {
  border-color: rgba(13, 127, 115, 0.75);
  box-shadow: 0 0 0 4px rgba(13, 127, 115, 0.12);
}

.notice {
  margin-bottom: 18px;
  padding: 12px 14px;
  border-radius: 8px;
  color: #5d4627;
  background: #fff6e8;
  box-shadow: none;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(360px, 0.95fr);
  gap: 16px;
  align-items: start;
}

.panel {
  border-radius: 8px;
  padding: 18px;
}

.transcript-panel,
.soap-panel {
  grid-row: span 2;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}

.panel-head > div:first-child {
  min-width: 0;
}

.step {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 24px;
  margin-bottom: 8px;
  border-radius: 999px;
  color: var(--accent-dark);
  background: rgba(13, 127, 115, 0.11);
  font-size: 0.78rem;
  font-weight: 800;
}

h2 {
  margin-bottom: 0;
  font-size: 1.2rem;
}

.panel-hint {
  margin: -4px 0 14px;
  color: var(--muted);
  font-size: 0.92rem;
  font-weight: 700;
  line-height: 1.5;
  overflow-wrap: anywhere;
}

h3 {
  margin-bottom: 10px;
  color: var(--muted);
  font-size: 0.9rem;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 40px;
  padding: 0 13px;
  border: 1px solid transparent;
  border-radius: 8px;
  font-weight: 800;
  white-space: nowrap;
  transition: transform 160ms ease, box-shadow 160ms ease, background 160ms ease;
}

.icon-button.long-label {
  min-height: 44px;
  max-width: 280px;
  padding-top: 7px;
  padding-bottom: 7px;
  white-space: normal;
}

.icon-button svg {
  flex: 0 0 auto;
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.icon-button span {
  min-width: 0;
  overflow-wrap: anywhere;
  line-height: 1.25;
}

.icon-button:hover {
  transform: translateY(-1px);
}

.icon-button:disabled {
  cursor: wait;
  opacity: 0.62;
  transform: none;
}

.icon-button.primary {
  color: #ffffff;
  background: var(--accent);
  box-shadow: 0 10px 24px rgba(13, 127, 115, 0.18);
}

.icon-button.primary:hover {
  background: var(--accent-dark);
}

.icon-button.secondary {
  color: var(--ink);
  background: #f4f1ea;
  border-color: var(--line);
}

.chip-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 10px;
  min-height: 168px;
}

.chip,
.category-card,
.option-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffdfa;
  text-align: left;
  transition: border-color 160ms ease, background 160ms ease, transform 160ms ease;
}

.chip {
  min-height: 104px;
  padding: 12px;
}

.chip:hover,
.category-card:hover,
.option-card:hover {
  border-color: rgba(13, 127, 115, 0.55);
  transform: translateY(-1px);
}

.chip.selected,
.category-card.selected,
.option-card.selected {
  border-color: var(--accent);
  background: rgba(13, 127, 115, 0.08);
}

.chip strong,
.category-card strong,
.option-card strong {
  display: block;
  margin-bottom: 6px;
}

.chip span,
.category-card span,
.option-card span {
  display: block;
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.45;
}

.split {
  display: grid;
  grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.1fr);
  gap: 14px;
}

.stack {
  display: grid;
  gap: 8px;
}

.category-card {
  padding: 12px;
}

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

.option-card {
  min-height: 78px;
  padding: 10px;
}

.selected-strip {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.selected-strip > span {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 800;
}

#selectedMeds {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 0 10px;
  border-radius: 999px;
  background: rgba(49, 95, 145, 0.12);
  color: #244d79;
  font-size: 0.88rem;
  font-weight: 800;
}

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

.soap-grid article {
  min-height: 150px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffdfa;
}

.soap-grid h3 {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  margin-bottom: 10px;
  border-radius: 999px;
  background: rgba(49, 95, 145, 0.12);
  color: #244d79;
}

.soap-grid p {
  margin-bottom: 0;
  color: #343a40;
  line-height: 1.62;
}

.risk-list {
  display: grid;
  gap: 9px;
  margin-top: 12px;
}

.risk-item {
  padding: 12px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #fffdfa;
}

.risk-item.high {
  border-color: rgba(178, 59, 59, 0.4);
  background: #fff0f0;
}

.risk-item.medium {
  border-color: rgba(184, 107, 20, 0.42);
  background: #fff8ed;
}

.risk-item.low {
  border-color: rgba(49, 95, 145, 0.28);
  background: #f2f7fc;
}

.risk-item strong {
  display: block;
  margin-bottom: 5px;
}

.risk-item p {
  margin-bottom: 5px;
  color: var(--muted);
  line-height: 1.5;
}

.risk-item em {
  color: var(--ink);
  font-style: normal;
  font-size: 0.92rem;
}

.empty {
  min-height: 116px;
  display: grid;
  place-items: center;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  text-align: center;
  padding: 18px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  z-index: 10;
  min-width: min(420px, calc(100vw - 32px));
  max-width: calc(100vw - 32px);
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #202428;
  color: #fff;
  box-shadow: var(--shadow);
  transform: translate(-50%, 90px);
  opacity: 0;
  pointer-events: none;
  transition: transform 180ms ease, opacity 180ms ease;
}

.toast.show {
  transform: translate(-50%, 0);
  opacity: 1;
}

@media (max-width: 980px) {
  .topbar {
    align-items: stretch;
    flex-direction: column;
  }

  .workspace,
  .split,
  .soap-grid {
    grid-template-columns: 1fr;
  }

  .transcript-panel,
  .soap-panel {
    grid-row: auto;
  }
}

@media (max-width: 720px) {
  .shell {
    width: calc(100vw - 48px);
    max-width: calc(100vw - 48px);
    margin-left: 24px;
    margin-right: 24px;
    padding-top: 18px;
  }

  h1 {
    font-size: clamp(1.95rem, 9vw, 2.35rem);
  }

  .notice {
    font-size: 0.94rem;
    line-height: 1.55;
    word-break: break-all;
  }

  .config-bar {
    grid-template-columns: 1fr;
  }

  .config-bar label {
    padding-left: 0;
  }

  .panel {
    padding: 14px;
  }

  .panel-head {
    align-items: stretch;
    flex-direction: column;
  }

  .actions {
    justify-content: stretch;
  }

  .icon-button {
    width: 100%;
    white-space: normal;
  }

  .icon-button.long-label {
    max-width: none;
  }

  .option-grid {
    grid-template-columns: 1fr;
  }
}
