/* ============================================================
   JABES AI - Clinical Teal Theme (design tokens + base styles)
   ============================================================ */

:root {
  --color-bg: #f7f8fa;
  --color-surface: #ffffff;
  --color-border: #e3e7ec;
  --color-border-strong: #d3d9e0;

  --color-text: #1c2126;
  --color-text-strong: #10151a;
  --color-text-muted: #62707d;
  --color-text-subtle: #98a6b3;

  --color-primary: #0f766e;
  --color-primary-dark: #0b5d56;
  --color-primary-light: #14b8a6;
  --color-primary-soft: #e6f7f5;

  --color-danger: #dc2626;
  --color-danger-dark: #b91c1c;
  --color-danger-soft: #fce8e8;
  --color-success: #16a34a;

  --sidebar-start: #0b1220;
  --sidebar-end: #123832;

  --radius-sm: 0.375rem;
  --radius-md: 0.625rem;
  --radius-lg: 0.875rem;

  --shadow-card: 0 1px 0.1875rem rgba(16,24,40,0.06), 0 1px 2px rgba(16,24,40,0.05);
  --shadow-elevated: 0 0.75rem 2rem rgba(16,24,40,0.14);
}

* { box-sizing: border-box; }

/* Screen size. Everything in the app is sized in rem, so the whole interface
   scales with the root font size. 16px at 1600px wide (what the layout was
   drawn for); above that in proportion to the width (about 18px at 1920,
   23px at 2560, 32px at 3840, where it stops); below it a little smaller
   (about 15px at 1366, 14px from 1100 down), which is room for the cards.
   The window is measured in CSS px, so OS display scaling and browser zoom
   are already counted.
   Only pages built on base.html have #app-wrapper. /label sets its own size
   (label-ui.js), and the pages with their own stylesheets keep 16px. */
html:has(#app-wrapper) {
  font-size: clamp(14px, calc(16px - (1600px - 100vw) * 0.0045), 16px);
}
@media (min-width: 1600px) {
  html:has(#app-wrapper) {
    font-size: clamp(16px, calc(16px + (100vw - 1600px) * 0.00714), 32px);
  }
}

body {
  margin: 0;
  padding: 0;
  font-family: 'Segoe UI', 'Noto Sans KR', Arial, sans-serif;
  background: var(--color-bg);
  color: var(--color-text);
  font-size: 0.9375rem;
  overflow-x: hidden;
}

/* ============================================================
   Layout: Sidebar + Main
   ============================================================ */
#app-wrapper {
  display: flex;
  min-height: 100vh;
  transition: padding-left 0.3s;
}

/* ============================================================
   Sidebar
   ============================================================ */
#sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: 17.5rem;
  height: 100vh;
  background: linear-gradient(180deg, var(--sidebar-start) 0%, var(--sidebar-end) 100%);
  color: #fff;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  z-index: 100;
  transition: width 0.3s;
  overflow: hidden;
}

#sidebar.collapsed {
  width: 4.75rem;
}

#sidebar.collapsed .sidebar-brand,
#sidebar.collapsed .sidebar-user-label,
#sidebar.collapsed .sidebar-item span,
#sidebar.collapsed .sidebar-bottom-text,
#sidebar.collapsed .sidebar-stethoscope {
  display: none;
}

.sidebar-top {
  flex: 1;
  overflow-y: auto;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  padding: 1.375rem 1.375rem 0.625rem;
}

.sidebar-brand {
  font-family: 'Georgia', serif;
  font-style: italic;
  font-size: 1.9rem;
  font-weight: bold;
  letter-spacing: 0.125rem;
}

.sidebar-toggle {
  margin-left: auto;
  background: none;
  border: none;
  color: #fff;
  font-size: 1.125rem;
  cursor: pointer;
  padding: 0.25rem 0.5rem;
  opacity: 0.7;
}
.sidebar-toggle:hover { opacity: 1; }

.sidebar-user-label {
  padding: 0.375rem 1.625rem 1.375rem;
  font-size: 0.875rem;
  font-weight: 600;
  color: #aab;
  letter-spacing: 0.0625rem;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
}

.sidebar-item {
  display: flex;
  align-items: center;
  padding: 0.875rem 1.625rem;
  color: #c8c8e0;
  text-decoration: none;
  font-size: 0.9375rem;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
  border-left: 0.1875rem solid transparent;
}

.sidebar-item i {
  width: 1.625rem;
  text-align: center;
  margin-right: 0.875rem;
  font-size: 1.0625rem;
  flex-shrink: 0;
}

.sidebar-item:hover {
  background: rgba(255,255,255,0.08);
  color: #fff;
}

/* small "opens elsewhere" marker for items that leave the app shell */
.sidebar-item-ext {
  width: auto !important;
  margin: 0 0 0 0.375rem !important;
  font-size: 0.625rem !important;
  opacity: 0.6;
  vertical-align: middle;
}

.sidebar-item.active {
  background: rgba(20,184,166,0.18);
  color: #fff;
  border-left-color: var(--color-primary-light);
  font-weight: 600;
}

.sidebar-bottom {
  padding: 1rem 1.125rem 1.25rem;
  text-align: center;
}

.sidebar-stethoscope {
  width: 80%;
  max-width: 10.625rem;
  aspect-ratio: 1 / 1;
  object-fit: contain;
  background: #fff;
  border-radius: 0.5rem;
  margin-bottom: 0.625rem;
  opacity: 0.85;
}

.sidebar-bottom-text {
  font-size: 0.8125rem;
  color: #aab;
  font-style: italic;
}

/* ============================================================
   Top Bar
   ============================================================ */
#topbar {
  position: fixed;
  top: 0;
  left: 17.5rem;
  right: 0;
  height: 3.75rem;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.75rem;
  z-index: 90;
  transition: left 0.3s;
}

.sidebar-collapsed #topbar {
  left: 4.75rem;
}

.topbar-left { display: flex; align-items: center; }

.sidebar-toggle-mobile {
  display: none;
  background: none;
  border: none;
  font-size: 1.25rem;
  color: #333;
  cursor: pointer;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 0.875rem;
}

#topbarUserInfo {
  font-size: 0.9375rem !important;
  color: #555;
}

.topbar-avatar {
  cursor: pointer;
}
.topbar-avatar i {
  font-size: 2rem !important;
  color: var(--color-primary);
}

/* ============================================================
   Main Content
   ============================================================ */
#main-content {
  margin-left: 17.5rem;
  margin-top: 3.75rem;
  padding: 1.5rem 1.75rem;
  flex: 1;
  min-width: 0;   /* a flex item stays as wide as its widest child unless told it may shrink: on a phone the page was 551px wide in a 390px window */
  transition: margin-left 0.3s;
  min-height: calc(100vh - 3.75rem);
}

.sidebar-collapsed #main-content {
  margin-left: 4.75rem;
}

/* ============================================================
   Patient Search Bar
   ============================================================ */
.patient-search-bar {
  display: flex;
  align-items: center;
  margin-bottom: 1.125rem;
}

.patient-search-input-wrap {
  display: flex;
  align-items: center;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 1.25rem;
  padding: 0 0.375rem;
  min-width: 20rem;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.patient-search-input-wrap:focus-within {
  border-color: var(--color-primary-light);
  box-shadow: 0 0 0 0.1875rem var(--color-primary-soft);
}

.patient-search-input-wrap input {
  flex: 1;
  border: none;
  outline: none;
  padding: 0.5625rem 1rem;
  font-size: 0.9375rem;
  background: transparent;
  color: var(--color-text);
}

/* ============================================================
   Recording Section: Step 1 + Step 2
   ============================================================ */
.recording-row {
  display: flex;
  gap: 1.125rem;
  margin-bottom: 1.125rem;
}

.card-step {
  background: var(--color-surface);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-card);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.card-step-left { flex: 5; }
.card-step-right { flex: 5; }

.card-step-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.875rem 1.125rem;
  border-bottom: 1px solid var(--color-border);
}

.card-step-header h6 {
  margin: 0;
  font-size: 1rem;
  color: var(--color-text);
}

.card-step-body {
  padding: 0.875rem 1.125rem 1.125rem;
  flex: 1;
}

/* Mode Radio Group */
.mode-radio-group {
  display: inline-flex;
  align-items: center;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: 62.4375rem;
  padding: 0.25rem;
  gap: 2px;
  margin: 0.25rem auto 0.625rem;
  justify-content: center;
  box-shadow: inset 0 1px 2px rgba(16,24,40,0.04);
}

.recording-row .mode-radio-group {
  display: flex;
  width: fit-content;
  margin-left: auto;
  margin-right: auto;
}

.mode-radio {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.5625rem 1.375rem;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--color-text-muted);
  cursor: pointer;
  border-radius: 62.4375rem;
  transition: color 0.2s, background 0.2s, box-shadow 0.2s, transform 0.15s;
  white-space: nowrap;
  user-select: none;
}

.mode-radio input[type="radio"] {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.mode-radio i {
  margin-right: 0.375rem;
  font-size: 0.8125rem;
  opacity: 0.8;
}

.mode-radio:hover { color: var(--color-primary); }

.mode-radio:has(input[type="radio"]:checked) {
  background: linear-gradient(135deg, var(--color-primary) 0%, var(--color-primary-light) 100%);
  color: #fff;
  box-shadow: 0 0.25rem 0.75rem rgba(15, 118, 110, 0.35);
  transform: translateY(-1px);
}

.mode-radio:has(input[type="radio"]:checked) i { opacity: 1; }

.recording_body {
  background: var(--color-bg);
  border-radius: 0.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  /* Locks the box to the anatomy images' own ratio (453x280, both chest and
     back) so object-fit:contain never letterboxes — without this, the
     position markers (positioned by % of this box) drift off the actual
     visible image at container widths whose ratio isn't ~1.618:1, which is
     most of them. See recording.html for the marker markup. */
  aspect-ratio: 453 / 280;
}

.btn-record-top {
  background: var(--color-primary);
  color: #fff;
  border: none;
  border-radius: 0.375rem;
  padding: 0.375rem 1rem;
  font-size: 0.8125rem;
  cursor: pointer;
}
.btn-record-top:hover { background: var(--color-primary-dark); color: #fff; }

#waveform {
  background: #eef1f4;
  border-radius: 0.5rem;
}

.recording-actions {
  display: flex;
  justify-content: center;
  gap: 0.875rem;
  margin-top: 1.125rem;
}

.btn-action {
  border-radius: 1.5rem;
  padding: 0.6875rem 2.25rem;
  font-size: 0.9375rem;
  font-weight: 700;
  border: none;
  cursor: pointer;
  letter-spacing: 0.0312rem;
  white-space: nowrap;
}

.btn-record { background: var(--color-danger); color: #fff; }
.btn-record:hover { background: var(--color-danger-dark); color: #fff; }

.btn-upload {
  background: var(--color-surface);
  color: var(--color-primary);
  border: 1.5px solid var(--color-primary);
}
.btn-upload:hover { background: var(--color-primary-soft); color: var(--color-primary-dark); }

/* ============================================================
   Recording Visualization Panels (Step 2 — dual mode-selectable views)
   ============================================================ */
.viz-panel {
  position: relative;
  margin-bottom: 0.375rem;
}
.viz-mode-select {
  position: absolute;
  top: 0.375rem;
  right: 0.375rem;
  z-index: 2;
  font-size: 0.6875rem;
  font-weight: 600;
  padding: 0.1875rem 0.5rem;
  border-radius: 0.375rem;
  border: 1px solid rgba(255,255,255,0.25);
  background: rgba(16,21,26,0.55);
  color: #fff;
  cursor: pointer;
}
.viz-mode-select:focus { outline: 2px solid var(--color-primary-light); }
.viz-canvas {
  display: block;
  width: 100%;
  height: 8rem;
  background: #eef1f4;
  border-radius: 0.5rem;
}

/* ============================================================
   Results Table (shared across pages)
   ============================================================ */
.results-section {
  background: var(--color-surface);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-card);
  padding: 1.125rem;
}

.results-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.875rem;
}

.results-total {
  font-size: 1rem;
  color: var(--color-text);
}

.results-table-wrap {
  overflow-x: auto;
  max-height: 32.5rem;
  overflow-y: auto;
}

.results-table {
  width: 100%;
  font-size: 0.875rem;
  text-align: center;
  border-collapse: collapse;
}

.results-table thead th {
  background: var(--color-bg);
  color: var(--color-text-muted);
  font-weight: 600;
  padding: 0.6875rem 0.625rem;
  border-bottom: 2px solid var(--color-border);
  position: sticky;
  top: 0;
  z-index: 1;
}

.results-table tbody td {
  padding: 0.6875rem 0.625rem;
  border-bottom: 1px solid var(--color-border);
  color: var(--color-text);
  vertical-align: middle;
}

.results-table tbody tr:hover { background: var(--color-primary-soft); }

.results-table .btn-sm {
  font-size: 0.8125rem;
  padding: 0.25rem 0.75rem;
  border-radius: 0.25rem;
}

.status-done {
  display: inline-block;
  background: var(--color-primary-soft);
  color: var(--color-primary-dark);
  border-radius: 0.875rem;
  padding: 0.25rem 0.875rem;
  font-size: 0.8125rem;
  font-weight: 600;
}

.assign-list-wrap {
  max-height: 20rem;
  overflow-y: auto;
  border: 1px solid var(--color-border);
  border-radius: 0.375rem;
}
.assign-list-wrap table { margin: 0; }
.assign-list-wrap tbody tr { cursor: pointer; }
.assign-list-wrap tbody tr:hover { background: var(--color-primary-soft); }

/* ============================================================
   Recording Warning Banner
   ============================================================ */
.recording-warning {
  display: none;
  position: fixed;
  bottom: 2.25rem;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(220, 38, 38, 0.95);
  color: #fff;
  padding: 0.875rem 1.75rem;
  border-radius: 62.4375rem;
  font-size: 0.9375rem;
  font-weight: 600;
  box-shadow: 0 0.375rem 1.5rem rgba(220, 38, 38, 0.4);
  z-index: 1100;
  align-items: center;
  gap: 0.75rem;
  white-space: nowrap;
  animation: recording-blink 1s ease-in-out infinite;
}
.recording-warning.active { display: inline-flex; }
.recording-warning-dot {
  font-size: 0.75rem;
  color: #fff;
}
.recording-warning-timer {
  background: #fff;
  color: var(--color-danger);
  border-radius: 62.4375rem;
  padding: 2px 0.75rem;
  font-weight: 700;
  min-width: 2rem;
  text-align: center;
}
@keyframes recording-blink {
  0%, 100% { opacity: 1; box-shadow: 0 0.375rem 1.5rem rgba(220, 38, 38, 0.4); }
  50%      { opacity: 0.55; box-shadow: 0 0.375rem 0.75rem rgba(220, 38, 38, 0.2); }
}

/* ============================================================
   Audio Quality Toast (non-blocking, auto-dismissing)
   ============================================================ */
.audio-toast {
  position: fixed;
  top: 5.25rem;
  right: 1.5rem;
  display: flex;
  align-items: center;
  gap: 0.625rem;
  background: #b45309;
  color: #fff;
  padding: 0.8125rem 1.375rem;
  border-radius: 0.75rem;
  font-size: 0.875rem;
  font-weight: 600;
  box-shadow: var(--shadow-elevated);
  z-index: 1150;
  max-width: 21.25rem;
  opacity: 0;
  transform: translateX(1rem);
  pointer-events: none;
  transition: opacity 0.3s ease, transform 0.3s ease;
}
.audio-toast.show {
  opacity: 1;
  transform: translateX(0);
}
.audio-toast-icon {
  font-size: 1rem;
  flex-shrink: 0;
}

body.recording-locked #sidebar .sidebar-item {
  pointer-events: none;
  opacity: 0.55;
}

/* ============================================================
   Position Markers (light theme)
   ============================================================ */
.position-marker {
  transform: translate(-50%, -50%);
  transform-origin: center center;
}
.play_point {
  cursor: pointer;
  opacity: 0.85;
  transition: opacity 0.2s, transform 0.2s;
}
.play_point:hover {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1.1);
}

/* ============================================================
   Scrollbar
   ============================================================ */
::-webkit-scrollbar { width: 0.5rem; height: 0.5rem; }
::-webkit-scrollbar-track { background: var(--color-bg); }
::-webkit-scrollbar-thumb { background: var(--color-border-strong); border-radius: 0.25rem; }
::-webkit-scrollbar-thumb:hover { background: var(--color-text-subtle); }

/* ============================================================
   Icon Hover (global)
   ============================================================ */
.hovable-icon { color: var(--color-text-muted); }
.hovable-icon:hover { color: var(--color-text-strong); }

/* ============================================================
   Bootstrap Button Theming (global — retint default blue to brand teal)
   ============================================================ */
.btn-primary {
  background-color: var(--color-primary);
  border-color: var(--color-primary);
}
.btn-primary:hover,
.btn-primary:focus,
.btn-primary:active {
  background-color: var(--color-primary-dark) !important;
  border-color: var(--color-primary-dark) !important;
}
.btn-outline-primary {
  color: var(--color-primary);
  border-color: var(--color-primary);
}
.btn-outline-primary:hover {
  background-color: var(--color-primary);
  border-color: var(--color-primary);
}
.btn-outline-secondary {
  color: var(--color-text-muted);
  border-color: var(--color-border-strong);
}
.btn-outline-secondary:hover {
  background-color: var(--color-bg);
  border-color: var(--color-text-subtle);
  color: var(--color-text);
}
.btn:focus, .btn.focus,
.form-control:focus, .form-select:focus {
  box-shadow: 0 0 0 0.1875rem var(--color-primary-soft);
}

/* ============================================================
   Responsive
   ============================================================ */
/* The side-by-side cards and the full sidebar need about 1100px; below that
   the sidebar is icons only (the menu button opens it again), and below 900px
   the two steps stack. */
@media (max-width: 1500px) {
  .btn-action { padding-inline: 1.25rem; letter-spacing: 0; }
}

@media (max-width: 1100px) {
  #sidebar { width: 4.75rem; }
  #sidebar .sidebar-brand,
  #sidebar .sidebar-user-label,
  #sidebar .sidebar-item span,
  #sidebar .sidebar-bottom-text,
  #sidebar .sidebar-stethoscope { display: none; }
  #topbar { left: 4.75rem; }
  #main-content { margin-left: 4.75rem; }
  .sidebar-toggle-mobile { display: block; }
}

@media (max-width: 900px) {
  .recording-row { flex-direction: column; }
}

@media (max-width: 600px) {
  #main-content { padding: 1rem 0.75rem; }
  .recording-row .mode-radio-group { width: 100%; }
  .mode-radio { flex: 1; padding-inline: 0.5rem; font-size: 0.8125rem; white-space: nowrap; }
}

@media (max-width: 768px) {
  .recording-row { flex-direction: column; }
  #sidebar { width: 0; }
  #sidebar.show { width: 17.5rem; }
  #topbar { left: 0; }
  #main-content { margin-left: 0; }
}

/* What the browser says it does to the microphone (MicProcessing, app.js): the normal state is quiet, only "On" is loud. */
.mic-proc-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.3125rem;
  padding: 2px 0.625rem;
  border-radius: 62.4375rem;
  background: var(--color-primary-soft);
  color: var(--color-primary-dark);
  font-size: 0.75rem;
  font-weight: 600;
  white-space: nowrap;
  cursor: help;
}
.mic-proc-chip[hidden] { display: none; }
.mic-proc-chip.is-on { background: #fef3c7; color: #92400e; }
