:root {
  --ink: #1a2433;
  --muted: #5e6b7a;
  --bg: #f5f7fb;
  --card: #ffffff;
  --accent: #1f4f7a;
  --accent-soft: #e5eef6;
  --warn: #fff4ec;
  --warn-ink: #b8582a;
  --chip: #eef2f6;
  --border: #e1e7ef;
  --shadow: 0 14px 36px rgba(17, 26, 39, 0.08);
  --radius-lg: 22px;
  --radius-md: 16px;
  --radius-sm: 12px;
  font-synthesis-weight: none;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "IBM Plex Sans", "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--bg);
  min-height: 100vh;
}

.backdrop {
  position: fixed;
  inset: 0;
  background: radial-gradient(circle at 20% 0%, #ffffff 0%, rgba(255, 255, 255, 0.4) 45%, transparent 60%),
    linear-gradient(140deg, #f5f7fb 0%, #eef3f8 45%, #f8fafc 100%);
  z-index: -1;
}

.app {
  max-width: 860px;
  margin: 0 auto;
  padding: 24px 20px 40px;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

body.chat-open .app {
  max-width: 560px;
  padding: 0;
  min-height: 100vh;
}

.screen.hidden {
  display: none;
}

.top {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.eyebrow {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.2em;
  color: var(--muted);
}

h1 {
  font-family: "Space Grotesk", "IBM Plex Sans", sans-serif;
  font-size: 28px;
  margin: 0;
}

.sub {
  margin: 0;
  color: var(--muted);
}

.pill {
  align-self: flex-start;
  border: none;
  background: var(--accent-soft);
  color: var(--accent);
  padding: 8px 14px;
  border-radius: 999px;
  font-weight: 600;
}

.summary {
  display: grid;
  gap: 14px;
}

.stat {
  background: var(--card);
  border-radius: var(--radius-lg);
  padding: 16px 18px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  animation: rise 0.6s ease;
}

.stat.accent {
  background: var(--accent-soft);
  color: var(--ink);
  border: 1px solid rgba(31, 79, 122, 0.2);
}

.stat-title {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: inherit;
  opacity: 0.7;
}

.stat-value {
  font-size: 22px;
  font-weight: 600;
  margin-top: 6px;
}

.stat-note {
  font-size: 13px;
  opacity: 0.8;
  margin-top: 4px;
}

.actions {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
}

.action {
  border: none;
  background: var(--card);
  border-radius: var(--radius-md);
  padding: 14px 12px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-weight: 600;
  color: var(--ink);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.action small {
  font-size: 12px;
  color: var(--muted);
  font-weight: 500;
}

.action:active {
  transform: scale(0.98);
}

.block {
  background: rgba(255, 255, 255, 0.88);
  border-radius: var(--radius-lg);
  padding: 16px;
  backdrop-filter: blur(8px);
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.block-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.block-header h2 {
  margin: 0;
  font-size: 18px;
}

.ghost {
  border: none;
  background: transparent;
  color: var(--accent);
  font-weight: 600;
  padding: 6px 0;
}

.list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.card {
  background: var(--card);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border: 1px solid var(--border);
}

.card.warn {
  background: var(--warn);
  color: var(--warn-ink);
}

.card-title {
  font-weight: 600;
}

.card-sub {
  font-size: 12px;
  color: var(--muted);
  margin-top: 4px;
}

.card.warn .card-sub {
  color: var(--warn-ink);
}

.chip {
  border: none;
  background: var(--chip);
  color: var(--ink);
  padding: 6px 12px;
  border-radius: 999px;
  font-weight: 600;
  font-size: 12px;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.request-screen {
  min-height: calc(100vh - 64px);
  display: flex;
  flex-direction: column;
  border-radius: 22px;
  overflow: hidden;
  border: 1px solid #bfd1e2;
  background: #cfdcea;
  box-shadow: var(--shadow);
}

body.chat-open .request-screen {
  min-height: 100vh;
  border-radius: 0;
  border: none;
  box-shadow: none;
}

.chat-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-bottom: 1px solid #d9e4ef;
  background: #f5f9fd;
}

.chat-back-btn {
  border: none;
  background: transparent;
  color: #245a8a;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  font-size: 20px;
  font-weight: 700;
  line-height: 1;
}

.chat-peer {
  min-width: 0;
}

.chat-peer-title {
  font-size: 17px;
  font-weight: 700;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-peer-sub {
  font-size: 13px;
  color: #5a6d82;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
}

.chat-peer-meta {
  margin-top: 2px;
  font-size: 12px;
  color: #6e7f91;
}

.chat-body {
  flex: 1;
  overflow-y: auto;
  padding: 10px 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background:
    radial-gradient(circle at 20% 18%, rgba(255, 255, 255, 0.45), rgba(255, 255, 255, 0) 40%),
    radial-gradient(circle at 78% 70%, rgba(255, 255, 255, 0.35), rgba(255, 255, 255, 0) 42%),
    linear-gradient(180deg, #d8e6f2 0%, #c7d8e8 100%);
}

.chat-day-chip {
  align-self: center;
  background: rgba(255, 255, 255, 0.84);
  border: 1px solid rgba(137, 158, 180, 0.35);
  color: #5a7088;
  font-size: 12px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 999px;
}

.thread {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.message-row {
  display: flex;
}

.message-row.patient {
  justify-content: flex-start;
}

.message-row.doctor {
  justify-content: flex-end;
}

.message-bubble {
  max-width: min(82%, 430px);
  padding: 8px 12px 6px;
  border-radius: 16px;
  font-size: 15px;
  line-height: 1.35;
  border: 1px solid rgba(120, 142, 166, 0.2);
  box-shadow: 0 4px 12px rgba(28, 45, 66, 0.08);
}

.message-row.patient .message-bubble {
  background: #ffffff;
  border-top-left-radius: 8px;
}

.message-row.doctor .message-bubble {
  background: #e9ffd7;
  border-top-right-radius: 8px;
}

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

.message-meta {
  margin-top: 4px;
  font-size: 11px;
  color: #6e8195;
  text-align: right;
}

.message-bubble audio,
.message-bubble video {
  width: 100%;
}

.message-bubble video.video-circle {
  width: 180px;
  height: 180px;
  max-width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  border-radius: 50%;
}

.media-placeholder {
  margin-top: 6px;
  border: 1px dashed rgba(106, 127, 150, 0.45);
  color: #5d748d;
  border-radius: 10px;
  padding: 8px 10px;
  font-size: 12px;
}

.video-circle-placeholder {
  width: 180px;
  height: 180px;
  max-width: 100%;
  margin-top: 6px;
  border-radius: 50%;
  border: 1px dashed rgba(106, 127, 150, 0.45);
  background: rgba(238, 245, 252, 0.9);
  color: #4d6782;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 600;
}

.attachments {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.attachment {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 12px;
  border-radius: 12px;
  border: 1px solid rgba(123, 145, 169, 0.28);
  background: rgba(255, 255, 255, 0.78);
  font-size: 13px;
}

.attachment small {
  color: #5f748c;
  white-space: nowrap;
}

.chat-composer {
  border-top: 1px solid #d9e4ef;
  background: #f4f8fc;
  padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.chat-quick-row {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 2px;
}

.chat-quick-row .chip {
  flex: 0 0 auto;
  background: #e7eef5;
  border: 1px solid #d3deea;
  font-size: 12px;
}

.chat-input-row {
  display: grid;
  grid-template-columns: auto auto 1fr auto;
  gap: 8px;
  align-items: end;
}

.chat-tool-btn {
  border: 1px solid #d1dde9;
  background: #e8eff6;
  color: #28445f;
  border-radius: 999px;
  height: 36px;
  padding: 0 10px;
  font-size: 12px;
  font-weight: 600;
}

.chat-input-row textarea {
  width: 100%;
  min-height: 36px;
  max-height: 128px;
  border-radius: 18px;
  border: 1px solid #d1dde9;
  padding: 8px 12px;
  font-family: inherit;
  font-size: 15px;
  background: #fff;
  resize: none;
  line-height: 1.3;
}

.chat-send-btn {
  border: none;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: #2b5f8f;
  color: #fff;
  font-size: 16px;
  font-weight: 700;
}

.chat-send-btn:disabled {
  opacity: 0.45;
}

.footer {
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-size: 12px;
}

.muted {
  opacity: 0.7;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  background: #1f2a37;
  color: #fff;
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(-6px);
}

.overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgba(20, 20, 20, 0.35);
  backdrop-filter: blur(6px);
  z-index: 10;
  padding: 24px 16px;
}

.overlay.hidden {
  display: none;
}

.sheet {
  width: min(520px, 100%);
  background: var(--card);
  border-radius: 24px;
  box-shadow: var(--shadow);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  animation: rise 0.2s ease;
}

.sheet-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.sheet-title {
  font-weight: 700;
  font-size: 18px;
}

.sheet-sub {
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
}

.sheet-body {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.icon {
  border: none;
  background: var(--chip);
  border-radius: 50%;
  width: 32px;
  height: 32px;
  font-size: 18px;
  font-weight: 600;
  color: var(--ink);
}

.rec-status {
  font-weight: 600;
}

.rec-timer {
  font-family: "Space Grotesk", "IBM Plex Sans", sans-serif;
  font-size: 22px;
  color: var(--accent);
}

.rec-controls {
  display: flex;
  gap: 10px;
}

.primary,
.secondary {
  border: none;
  border-radius: 999px;
  padding: 10px 18px;
  font-weight: 600;
}

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

.secondary {
  background: var(--chip);
}

.primary:disabled,
.secondary:disabled {
  opacity: 0.5;
}

.rec-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.hidden {
  display: none;
}

.video-wrap {
  display: flex;
  justify-content: center;
}

.video-circle {
  width: 180px;
  height: 180px;
  border-radius: 50%;
  background: #0f172a;
  object-fit: cover;
}

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

@media (min-width: 720px) {
  .top {
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
  }

  .summary {
    grid-template-columns: repeat(3, 1fr);
  }
}
