:root {
  color-scheme: light dark;
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #eef1f4;
  --text: #17202a;
  --muted: #55616e;
  --border: #d3d9e0;
  --accent: #0b6e63;
  --accent-hover: #095a51;
  --accent-contrast: #ffffff;
  --accent-soft: #e2f1ee;
  --danger: #b3261e;
  --danger-soft: #fbeae8;
  --warn-text: #6a4800;
  --warn-soft: #fff3d1;
  --shadow: 0 1px 2px rgb(16 24 40 / 6%), 0 1px 3px rgb(16 24 40 / 8%);
  --radius: 12px;
  --radius-small: 8px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #10151a;
    --surface: #192027;
    --surface-2: #232c35;
    --text: #e8edf2;
    --muted: #a5b0bc;
    --border: #36424e;
    --accent: #55c7b4;
    --accent-hover: #74d6c5;
    --accent-contrast: #05201c;
    --accent-soft: #15332f;
    --danger: #ff8f85;
    --danger-soft: #3b1e1c;
    --warn-text: #ffd98a;
    --warn-soft: #3a2f11;
    --shadow: none;
  }
}

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

[hidden] {
  display: none !important;
}

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 1rem;
  line-height: 1.5;
}

h1,
h2,
p,
ul,
ol {
  margin: 0;
}

h1 {
  font-size: 1.5rem;
  line-height: 1.25;
  font-weight: 650;
  letter-spacing: -0.01em;
  overflow-wrap: anywhere;
}

h2 {
  font-size: 1.0625rem;
  line-height: 1.3;
  font-weight: 650;
}

a {
  color: var(--accent);
}

:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

main:focus {
  outline: none;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

.muted {
  color: var(--muted);
}

.pre-line {
  white-space: pre-line;
  overflow-wrap: anywhere;
}

/* Header */

.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 max(1rem, env(safe-area-inset-right)) 0 max(1rem, env(safe-area-inset-left));
}

.app-header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem 1.5rem;
  flex-wrap: wrap;
  max-width: 60rem;
  margin: 0 auto;
  min-height: 3.5rem;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  color: var(--text);
  font-weight: 700;
  font-size: 1.0625rem;
  text-decoration: none;
  min-height: 2.75rem;
}

.brand img {
  border-radius: 7px;
}

.app-nav {
  display: flex;
  gap: 0.25rem;
}

.app-nav a {
  display: inline-flex;
  align-items: center;
  min-height: 2.75rem;
  padding: 0 0.75rem;
  border-radius: var(--radius-small);
  color: var(--muted);
  font-weight: 550;
  text-decoration: none;
}

.app-nav a:hover {
  background: var(--surface-2);
  color: var(--text);
}

.app-nav a[aria-current="page"] {
  background: var(--accent-soft);
  color: var(--accent);
}

/* Page layout */

.app-main {
  padding: 1.5rem max(1rem, env(safe-area-inset-right)) 5rem max(1rem, env(safe-area-inset-left));
}

.page {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  max-width: 60rem;
  margin: 0 auto;
}

.page-narrow {
  max-width: 38rem;
}

.page-auth {
  max-width: 26rem;
  padding-top: 6vh;
}

.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem 1rem;
  flex-wrap: wrap;
}

.meta {
  margin-top: 0.25rem;
  color: var(--muted);
  font-size: 0.9375rem;
}

.back-link {
  display: inline-flex;
  align-items: center;
  align-self: flex-start;
  gap: 0.15rem;
  min-height: 2rem;
  margin-bottom: -0.5rem;
  margin-left: -0.3rem;
  color: var(--muted);
  font-size: 0.9375rem;
  font-weight: 550;
  text-decoration: none;
}

.back-link:hover {
  color: var(--text);
}

.loading {
  padding: 3rem 0;
  color: var(--muted);
  text-align: center;
}

.noscript {
  max-width: 30rem;
  margin: 3rem auto;
  padding: 0 1rem;
  text-align: center;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.25rem;
}

.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
  padding: 3rem 1.25rem;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  color: var(--muted);
  text-align: center;
}

.empty h2 {
  color: var(--text);
}

.empty .btn {
  margin-top: 0.5rem;
}

/* Icons */

.icon {
  flex: none;
  width: 1.25rem;
  height: 1.25rem;
  fill: none;
  stroke: currentcolor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Buttons */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  min-height: 2.75rem;
  padding: 0.5rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-small);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  line-height: 1.2;
  text-decoration: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.btn:hover {
  background: var(--surface-2);
}

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

.btn-primary {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--accent-contrast);
}

.btn-primary:hover {
  border-color: var(--accent-hover);
  background: var(--accent-hover);
}

.btn-danger {
  border-color: var(--danger);
  background: var(--danger);
  color: var(--surface);
}

.btn-danger:hover {
  background: var(--danger);
  filter: brightness(0.92);
}

.btn-quiet {
  border-color: transparent;
  background: transparent;
  color: var(--muted);
}

.btn-quiet:hover {
  color: var(--text);
}

.btn-danger-text,
.btn-danger-text:hover {
  color: var(--danger);
}

.btn-icon {
  width: 2.75rem;
  padding: 0;
}

.btn-block {
  width: 100%;
}

.btn-large {
  min-height: 3.75rem;
  min-width: 9.5rem;
  padding: 0.75rem 1.5rem;
  border-radius: 999px;
  font-size: 1.0625rem;
}

.btn-large .icon {
  width: 1.5rem;
  height: 1.5rem;
}

.btn-chip {
  min-height: 2.5rem;
  padding: 0.35rem 0.9rem;
  border-radius: 999px;
  background: var(--surface-2);
  font-size: 0.9375rem;
  font-weight: 550;
}

.btn-chip:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
}

.actions-end {
  justify-content: flex-end;
}

.actions-center {
  justify-content: center;
}

/* Forms */

.form {
  display: flex;
  flex-direction: column;
  gap: 1.1rem;
}

fieldset {
  min-width: 0;
  margin: 0;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  min-width: 0;
}

label {
  font-size: 0.9375rem;
  font-weight: 600;
}

input[type="text"],
input[type="email"],
input[type="password"],
select,
textarea {
  width: 100%;
  min-height: 2.75rem;
  padding: 0.55rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-small);
  background: var(--surface);
  color: var(--text);
  font: inherit;
}

textarea {
  display: block;
  line-height: 1.5;
  resize: vertical;
}

input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  border-color: var(--accent);
  outline-offset: 0;
}

::placeholder {
  color: var(--muted);
  opacity: 0.85;
}

:disabled {
  cursor: not-allowed;
}

fieldset:disabled input,
fieldset:disabled select {
  background: var(--surface-2);
  color: var(--muted);
}

.hint {
  color: var(--muted);
  font-size: 0.875rem;
}

.hint:empty {
  display: none;
}

.form-error {
  color: var(--danger);
  font-weight: 550;
}

/* Notices and toasts */

.notice {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  border-radius: var(--radius-small);
  border: 1px solid transparent;
  overflow-wrap: anywhere;
}

.notice-error {
  background: var(--danger-soft);
  border-color: var(--danger);
  color: var(--text);
}

.notice-warn {
  background: var(--warn-soft);
  color: var(--warn-text);
}

.notice-success,
.notice-info {
  background: var(--accent-soft);
  border-color: var(--accent);
}

.notice .btn-icon {
  flex: none;
  margin: -0.4rem -0.5rem -0.4rem 0;
}

.toasts {
  position: fixed;
  left: 0;
  right: 0;
  bottom: max(1rem, env(safe-area-inset-bottom));
  z-index: 30;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  padding: 0 1rem;
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  max-width: 32rem;
  padding: 0.35rem 0.35rem 0.35rem 1rem;
  border-radius: var(--radius-small);
  background: var(--text);
  color: var(--bg);
  box-shadow: 0 6px 20px rgb(0 0 0 / 25%);
  pointer-events: auto;
}

.toast .btn {
  color: inherit;
}

.toast .btn:hover {
  background: transparent;
  opacity: 0.75;
}

.toast-error {
  background: var(--danger);
  color: var(--surface);
}

/* Lists */

.list {
  padding: 0;
  list-style: none;
  overflow: hidden;
}

.list li + li {
  border-top: 1px solid var(--border);
}

.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  min-height: 4rem;
  padding: 0.85rem 1.25rem;
  color: inherit;
  text-decoration: none;
}

.row:hover {
  background: var(--surface-2);
}

.row:focus-visible {
  outline-offset: -3px;
}

.row-main {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  min-width: 0;
}

.row-title {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 600;
  overflow-wrap: anywhere;
}

.row-meta {
  color: var(--muted);
  font-size: 0.875rem;
}

/* Search */

.search-filters {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.1rem;
}

.result {
  align-items: flex-start;
}

.result-text {
  display: -webkit-box;
  margin-top: 0.4rem;
  overflow: hidden;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 8;
  line-clamp: 8;
  white-space: pre-line;
  overflow-wrap: anywhere;
}

.badge {
  flex: none;
  padding: 0.2rem 0.65rem;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 0.8125rem;
  font-weight: 600;
  white-space: nowrap;
}

.badge-ready {
  background: var(--accent-soft);
  color: var(--accent);
}

.badge-failed {
  background: var(--danger-soft);
  color: var(--danger);
}

.badge-transcribing,
.badge-identifying,
.badge-generating,
.badge-uploaded {
  background: var(--warn-soft);
  color: var(--warn-text);
}

/* Auth */

.auth-brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  text-align: center;
}

.auth-brand img {
  border-radius: 11px;
}

.auth-switch {
  color: var(--muted);
  text-align: center;
}

/* Recorder */

.recorder {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 1.25rem;
  padding: 2rem 1.25rem;
  text-align: center;
}

.recorder .notice {
  text-align: left;
}

.timer {
  font-size: 3.5rem;
  font-weight: 300;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}

.recorder-state {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  color: var(--muted);
  font-weight: 600;
}

.dot {
  width: 0.7rem;
  height: 0.7rem;
  border-radius: 50%;
  background: var(--muted);
}

.dot-live {
  background: var(--danger);
  animation: pulse 1.6s ease-in-out infinite;
}

@keyframes pulse {
  50% {
    opacity: 0.35;
  }
}

.meter {
  width: 100%;
  max-width: 20rem;
  height: 0.6rem;
  margin: 0 auto;
  border-radius: 999px;
  background: var(--surface-2);
  overflow: hidden;
}

.meter-fill {
  --level: 0;

  height: 100%;
  border-radius: 999px;
  background: var(--accent);
  transform: scaleX(var(--level));
  transform-origin: left center;
  transition: transform 90ms linear;
}

progress {
  width: 100%;
  height: 0.6rem;
  border: 0;
  border-radius: 999px;
  background: var(--surface-2);
  accent-color: var(--accent);
  overflow: hidden;
  appearance: none;
}

progress::-webkit-progress-bar {
  background: var(--surface-2);
}

progress::-webkit-progress-value {
  background: var(--accent);
}

progress::-moz-progress-bar {
  background: var(--accent);
}

/* Encounter progress */

.progress-card {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  padding: 1.75rem 1.25rem;
}

.progress-title {
  font-size: 1.125rem;
  font-weight: 650;
}

.progress-bar {
  height: 0.4rem;
  border-radius: 999px;
  background: var(--surface-2);
  overflow: hidden;
}

.progress-bar-fill {
  width: 35%;
  height: 100%;
  border-radius: 999px;
  background: var(--accent);
  animation: slide 1.6s ease-in-out infinite;
}

@keyframes slide {
  0% {
    transform: translateX(-100%);
  }

  100% {
    transform: translateX(290%);
  }
}

.steps {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1.5rem;
  padding: 0;
  list-style: none;
}

.step {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  color: var(--muted);
  font-size: 0.9375rem;
}

.step-done {
  color: var(--accent);
}

.step-current {
  color: var(--text);
  font-weight: 600;
}

.step-dot {
  width: 0.6rem;
  height: 0.6rem;
  margin: 0 0.325rem;
  border: 2px solid currentcolor;
  border-radius: 50%;
}

.step-current .step-dot {
  background: currentcolor;
}

/* Note */

.toolbar .btn-danger-text {
  margin-left: auto;
}

.note {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.note-section {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  min-width: 0;
}

.note-section + .note-section {
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
}

.note-section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  min-height: 2.75rem;
  margin: -0.5rem 0;
}

.note-text {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  overflow-wrap: anywhere;
}

.note-text p {
  white-space: pre-line;
}

.note-text ul {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  padding-left: 1.4rem;
}

.note-text ul ul {
  margin-top: 0.25rem;
}

.feedback {
  border-color: var(--accent);
}

.transcript {
  padding: 0;
}

.transcript summary {
  display: flex;
  align-items: center;
  min-height: 3.25rem;
  padding: 0 1.25rem;
  border-radius: var(--radius);
  font-weight: 600;
  cursor: pointer;
}

.transcript summary::before {
  content: "";
  width: 0.5rem;
  height: 0.5rem;
  margin-right: 0.85rem;
  border-right: 2px solid currentcolor;
  border-bottom: 2px solid currentcolor;
  transform: rotate(-45deg);
}

.transcript[open] summary::before {
  transform: rotate(45deg);
}

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

.transcript-text {
  padding: 0 1.25rem 1.25rem;
  color: var(--muted);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.turns {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  padding: 0 1.25rem 1.25rem;
  color: var(--muted);
  overflow-wrap: anywhere;
}

.turn-speaker {
  margin-right: 0.5rem;
  color: var(--text);
  font-weight: 600;
}

.speakers {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin: 0 1.25rem 1.25rem;
  padding: 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-small);
  background: var(--surface-2);
}

.speakers-summary {
  margin-top: 0;
}

.speakers h3 {
  font-size: 0.9375rem;
}

.speaker-rows {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(11rem, 1fr));
  gap: 0.75rem;
}

/* Templates */

.examples {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.versions {
  padding: 0 1.25rem;
  list-style: none;
}

.version {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 0;
  border-top: 1px solid var(--border);
}

.version-main {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  min-width: 0;
  overflow-wrap: anywhere;
}

.section-editor-list {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  padding: 0;
  list-style: none;
}

.section-editor {
  display: flex;
  gap: 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.25rem;
}

.section-editor-fields {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 1rem;
  min-width: 0;
}

.section-editor-tools {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

/* Dialog */

.dialog {
  width: min(28rem, calc(100vw - 2rem));
  padding: 1.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 20px 50px rgb(0 0 0 / 30%);
}

.dialog[open] {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.dialog::backdrop {
  background: rgb(10 15 20 / 55%);
}

/* Small screens */

@media (max-width: 34rem) {
  .search-filters {
    grid-template-columns: 1fr;
  }

  .app-header-inner {
    justify-content: center;
    padding: 0.35rem 0;
  }

  .brand {
    display: none;
  }

  .app-nav {
    width: 100%;
  }

  .app-nav a {
    flex: 1;
    justify-content: center;
    padding: 0 0.25rem;
  }

  .app-main {
    padding-top: 1.25rem;
  }

  h1 {
    font-size: 1.375rem;
  }

  .timer {
    font-size: 3rem;
  }

  .recorder .btn-large {
    flex: 1 1 100%;
  }

  .section-editor {
    flex-direction: column;
  }

  .section-editor-tools {
    flex-direction: row;
  }

  .version {
    flex-direction: column;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
  }

  .progress-bar-fill {
    width: 100%;
    opacity: 0.5;
  }
}

/* Speech detection on the recording screen */

.listening {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.6rem;
}

.listening .meter {
  margin: 0;
}

.hearing {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  color: var(--muted);
  font-weight: 600;
}

.hearing-mark {
  box-sizing: border-box;
  width: 0.8rem;
  height: 0.8rem;
  border: 2px solid currentcolor;
  border-radius: 50%;
}

.hearing-active {
  color: var(--accent);
}

.hearing-active .hearing-mark {
  background: currentcolor;
}

.hearing-detail {
  color: var(--muted);
  font-size: 0.875rem;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}

.microphone-picker {
  width: 100%;
  max-width: 24rem;
  margin: 0 auto;
  text-align: left;
}

.recording-preview {
  width: 100%;
}
