:root {
  --med-ink: #142257;
  --med-blue: #1b5ff5;
  --med-sky: #59a5ff;
  --surface: rgba(255, 255, 255, 0.86);
  --surface-solid: #ffffff;
  --border: rgba(188, 220, 255, 0.7);
  --text: #1a2b45;
  --muted: #527ca3;
  --input-bg: #ffffff;
  --footer-bg: rgba(255, 255, 255, 0.72);
  --shadow: 0 14px 40px -16px rgba(20, 34, 87, 0.28);
  --card-hover-shadow: 0 20px 44px -18px rgba(20, 34, 87, 0.38);
}

html.dark {
  color-scheme: dark;
  --med-ink: #e8f1ff;
  --med-blue: #4d8dff;
  --med-sky: #7eb6ff;
  --surface: rgba(18, 28, 52, 0.88);
  --surface-solid: #162033;
  --border: rgba(89, 165, 255, 0.22);
  --text: #e8f1ff;
  --muted: #9bb4d0;
  --input-bg: #121c32;
  --footer-bg: rgba(12, 18, 34, 0.85);
  --shadow: 0 14px 40px -16px rgba(0, 0, 0, 0.55);
  --card-hover-shadow: 0 22px 48px -18px rgba(0, 0, 0, 0.65);
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  min-height: 100%;
  min-height: 100dvh;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  font-family: "Sora", "Segoe UI", sans-serif;
  color: var(--text);
  overflow-x: clip;
  background:
    radial-gradient(1200px 600px at 10% -10%, rgba(89, 165, 255, 0.28), transparent 55%),
    radial-gradient(900px 500px at 100% 0%, rgba(27, 95, 245, 0.18), transparent 50%),
    linear-gradient(180deg, #eef7ff 0%, #f4f7fb 40%, #e8eef6 100%);
  background-attachment: fixed;
  transition: background 0.35s ease, color 0.25s ease;
}

@media (max-width: 1024px) {
  body {
    background-attachment: scroll; /* better mobile scroll performance */
  }
}

html.dark body {
  background:
    radial-gradient(1000px 520px at 8% -8%, rgba(51, 129, 255, 0.22), transparent 55%),
    radial-gradient(800px 480px at 100% 0%, rgba(20, 73, 225, 0.18), transparent 50%),
    linear-gradient(180deg, #0b1222 0%, #101a30 45%, #0d1526 100%);
}

.mesh-grid {
  background-image:
    linear-gradient(rgba(25, 54, 143, 0.04) 1px, transparent 1px),
    linear-gradient(90deg, rgba(25, 54, 143, 0.04) 1px, transparent 1px);
  background-size: 28px 28px;
}

html.dark .mesh-grid {
  background-image:
    linear-gradient(rgba(142, 198, 255, 0.05) 1px, transparent 1px),
    linear-gradient(90deg, rgba(142, 198, 255, 0.05) 1px, transparent 1px);
}

.glass {
  background: var(--surface);
  backdrop-filter: blur(14px);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: linear-gradient(145deg, #4d8dff, #1b5ff5 55%, #1449e1);
  box-shadow: 0 8px 20px rgba(27, 95, 245, 0.4);
  display: grid;
  place-items: center;
  color: white;
  font-family: "Sora", "Segoe UI", sans-serif;
  font-weight: 800;
  letter-spacing: -0.03em;
}

/* Cards */
.anim-card {
  transition: transform 0.28s cubic-bezier(0.22, 1, 0.36, 1), box-shadow 0.28s ease, border-color 0.28s ease;
  will-change: transform;
}

.anim-card:hover {
  transform: translateY(-4px);
  box-shadow: var(--card-hover-shadow);
  border-color: rgba(89, 165, 255, 0.55);
}

.anim-card:active {
  transform: translateY(-1px);
}

.stagger > * {
  animation: fade-up 0.45s cubic-bezier(0.22, 1, 0.36, 1) both;
}

.stagger > *:nth-child(1) { animation-delay: 0.02s; }
.stagger > *:nth-child(2) { animation-delay: 0.07s; }
.stagger > *:nth-child(3) { animation-delay: 0.12s; }
.stagger > *:nth-child(4) { animation-delay: 0.17s; }
.stagger > *:nth-child(5) { animation-delay: 0.22s; }
.stagger > *:nth-child(6) { animation-delay: 0.27s; }

.role-card {
  transition: transform 0.28s cubic-bezier(0.22, 1, 0.36, 1), box-shadow 0.28s ease, border-color 0.28s ease;
}

.role-card:hover {
  transform: translateY(-4px);
  box-shadow: var(--card-hover-shadow);
  border-color: rgba(89, 165, 255, 0.55);
}

.role-card:active {
  transform: translateY(-1px);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  border-radius: 0.75rem;
  font-weight: 700;
  font-size: 0.875rem;
  line-height: 1.25rem;
  padding: 0.625rem 1rem;
  min-height: 2.5rem;
  border: 1px solid transparent;
  transition: transform 0.15s ease, box-shadow 0.2s ease, background 0.2s ease, border-color 0.2s ease, filter 0.2s ease;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.btn:active {
  transform: translateY(1px) scale(0.98);
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
}

.btn-primary {
  color: #fff;
  background: linear-gradient(135deg, #3b82f6 0%, #1b5ff5 48%, #1449e1 100%);
  box-shadow: 0 10px 22px -10px rgba(27, 95, 245, 0.7);
}

.btn-primary:hover {
  filter: brightness(1.06);
  box-shadow: 0 14px 28px -10px rgba(27, 95, 245, 0.8);
}

.btn-secondary {
  color: var(--text);
  background: var(--surface-solid);
  border-color: var(--border);
  box-shadow: 0 4px 12px -8px rgba(20, 34, 87, 0.25);
}

.btn-secondary:hover {
  border-color: rgba(89, 165, 255, 0.65);
  background: rgba(89, 165, 255, 0.08);
}

.btn-success {
  color: #fff;
  background: linear-gradient(135deg, #14b8a6 0%, #0d9488 50%, #0f766e 100%);
  box-shadow: 0 10px 22px -10px rgba(13, 148, 136, 0.7);
}

.btn-success:hover {
  filter: brightness(1.06);
}

.btn-danger {
  color: #fff;
  background: linear-gradient(135deg, #f43f5e 0%, #e11d48 55%, #be123c 100%);
  box-shadow: 0 10px 22px -10px rgba(225, 29, 72, 0.65);
}

.btn-danger:hover {
  filter: brightness(1.05);
}

.btn-warning {
  color: #fff;
  background: linear-gradient(135deg, #fbbf24 0%, #f59e0b 50%, #d97706 100%);
  box-shadow: 0 10px 22px -10px rgba(217, 119, 6, 0.55);
}

.btn-ghost {
  color: var(--muted);
  background: transparent;
  border-color: var(--border);
}

.btn-ghost:hover {
  color: var(--text);
  background: rgba(89, 165, 255, 0.08);
}

.btn-record {
  color: #fff;
  background: linear-gradient(135deg, #fb7185 0%, #e11d48 50%, #be123c 100%);
  box-shadow: 0 12px 24px -10px rgba(225, 29, 72, 0.7);
}

.btn-record:hover {
  filter: brightness(1.06);
}

.btn-icon {
  width: 2.5rem;
  height: 2.5rem;
  padding: 0;
  border-radius: 0.8rem;
}

.nav-pill {
  transition: background 0.18s ease, color 0.18s ease, transform 0.15s ease;
}

.nav-pill:hover {
  background: rgba(27, 95, 245, 0.1);
}

.nav-pill.active {
  background: linear-gradient(135deg, #3b82f6, #1b5ff5);
  color: white;
  box-shadow: 0 8px 18px rgba(27, 95, 245, 0.35);
}

html.dark .nav-pill:not(.active) {
  color: #c5d7ee;
}

/* Form controls */
.field {
  width: 100%;
  margin-top: 0.25rem;
  padding: 0.65rem 0.85rem;
  border-radius: 0.75rem;
  border: 1px solid var(--border);
  background: var(--input-bg);
  color: var(--text);
  font-size: 0.925rem;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.field:focus {
  outline: none;
  border-color: #59a5ff;
  box-shadow: 0 0 0 4px rgba(51, 129, 255, 0.18);
}

.field-label {
  display: block;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.case-accession-field {
  font-family: "Sora", "Segoe UI", monospace;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  font-variant-numeric: tabular-nums;
}

/* Modern SA date picker */
.sa-dp {
  position: relative;
  display: block;
  min-width: 15.5rem;
}

.sa-dp .field-label {
  margin-bottom: 0.35rem;
}

.sa-dp-trigger {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.7rem 0.85rem;
  border-radius: 0.9rem;
  border: 1px solid var(--border);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.92), rgba(238, 247, 255, 0.88));
  color: var(--text);
  box-shadow: 0 8px 22px -16px rgba(20, 34, 87, 0.45);
  cursor: pointer;
  transition: border-color 0.18s ease, box-shadow 0.18s ease, transform 0.18s ease;
  text-align: left;
}

html.dark .sa-dp-trigger {
  background: linear-gradient(180deg, rgba(30, 42, 68, 0.95), rgba(18, 28, 52, 0.92));
}

.sa-dp-trigger:hover {
  border-color: rgba(89, 165, 255, 0.7);
  transform: translateY(-1px);
  box-shadow: 0 12px 28px -16px rgba(27, 95, 245, 0.45);
}

.sa-dp.is-open .sa-dp-trigger {
  border-color: #59a5ff;
  box-shadow: 0 0 0 4px rgba(51, 129, 255, 0.16);
}

.sa-dp-icon {
  width: 2.15rem;
  height: 2.15rem;
  border-radius: 0.7rem;
  display: grid;
  place-items: center;
  color: #fff;
  background: linear-gradient(145deg, #4d8dff, #1b5ff5);
  flex-shrink: 0;
  box-shadow: 0 8px 16px -10px rgba(27, 95, 245, 0.8);
}

.sa-dp-text {
  min-width: 0;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}

.sa-dp-label {
  font-weight: 700;
  font-size: 0.95rem;
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sa-dp-hint {
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--muted);
}

.sa-dp-caret {
  width: 0.45rem;
  height: 0.45rem;
  border-right: 2px solid var(--muted);
  border-bottom: 2px solid var(--muted);
  transform: rotate(45deg);
  margin-top: -0.2rem;
  transition: transform 0.18s ease;
}

.sa-dp.is-open .sa-dp-caret {
  transform: rotate(225deg);
  margin-top: 0.15rem;
}

.sa-dp-popover {
  position: absolute;
  top: calc(100% + 0.45rem);
  right: 0;
  z-index: 60;
  width: 19.5rem;
  padding: 0.85rem;
  border-radius: 1.1rem;
  border: 1px solid var(--border);
  background: var(--surface-solid);
  box-shadow: 0 22px 48px -20px rgba(20, 34, 87, 0.45);
  animation: sa-dp-in 0.18s ease;
}

@keyframes sa-dp-in {
  from { opacity: 0; transform: translateY(-6px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.sa-dp-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.7rem;
}

.sa-dp-month {
  font-weight: 800;
  font-size: 0.95rem;
  color: var(--text);
  letter-spacing: -0.01em;
}

.sa-dp-nav {
  width: 2rem;
  height: 2rem;
  border: 0;
  border-radius: 0.65rem;
  background: rgba(51, 129, 255, 0.1);
  color: var(--med-blue);
  font-size: 1.25rem;
  line-height: 1;
  cursor: pointer;
  transition: background 0.15s ease;
}

.sa-dp-nav:hover {
  background: rgba(51, 129, 255, 0.2);
}

.sa-dp-weekdays {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 0.2rem;
  margin-bottom: 0.35rem;
}

.sa-dp-weekdays span {
  text-align: center;
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 0.2rem 0;
}

.sa-dp-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 0.25rem;
}

.sa-dp-day {
  aspect-ratio: 1;
  border: 0;
  border-radius: 0.7rem;
  background: transparent;
  color: var(--text);
  font-size: 0.85rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  transition: background 0.12s ease, color 0.12s ease, transform 0.12s ease;
}

.sa-dp-day.is-empty {
  cursor: default;
  pointer-events: none;
}

.sa-dp-day:not(.is-empty):hover {
  background: rgba(51, 129, 255, 0.12);
  transform: translateY(-1px);
}

.sa-dp-day.is-today {
  box-shadow: inset 0 0 0 1.5px rgba(27, 95, 245, 0.55);
  font-weight: 800;
}

.sa-dp-day.is-selected {
  background: linear-gradient(145deg, #4d8dff, #1b5ff5);
  color: #fff;
  font-weight: 800;
  box-shadow: 0 8px 16px -10px rgba(27, 95, 245, 0.85);
}

.sa-dp-day.is-selected.is-today {
  box-shadow: 0 8px 16px -10px rgba(27, 95, 245, 0.85);
}

.sa-dp-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-top: 0.75rem;
  padding-top: 0.65rem;
  border-top: 1px solid var(--border);
}

.sa-dp-tz {
  font-size: 0.68rem;
  font-weight: 700;
  color: var(--muted);
  letter-spacing: 0.02em;
}

.sa-dp-today {
  border: 0;
  border-radius: 999px;
  padding: 0.35rem 0.8rem;
  font-size: 0.75rem;
  font-weight: 800;
  cursor: pointer;
  color: #fff;
  background: linear-gradient(145deg, #4d8dff, #1b5ff5);
}

.sa-dp-today:hover {
  filter: brightness(1.05);
}

@media (max-width: 640px) {
  .sa-dp-popover {
    left: 0;
    right: auto;
    width: min(19.5rem, calc(100vw - 2rem));
  }
}

.app-footer {
  margin-top: auto;
  border-top: 1px solid var(--border);
  background: var(--footer-bg);
  backdrop-filter: blur(12px);
}

.app-footer-inner {
  max-width: 80rem;
  margin: 0 auto;
  padding: 1.25rem 1.25rem 1.5rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.app-footer-brand {
  display: flex;
  align-items: center;
  gap: 0.65rem;
}

.app-footer-brand .mini-mark {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: linear-gradient(145deg, #4d8dff, #1449e1);
  color: #fff;
  display: grid;
  place-items: center;
  font-family: "Sora", "Segoe UI", sans-serif;
  font-size: 0.7rem;
  font-weight: 800;
}

.app-footer-credit {
  font-size: 0.85rem;
  color: var(--muted);
}

.app-footer-credit strong {
  color: var(--text);
  font-weight: 700;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  display: inline-block;
}

.waveform {
  display: flex;
  align-items: flex-end;
  gap: 3px;
  height: 36px;
}

.waveform span {
  width: 4px;
  border-radius: 999px;
  background: linear-gradient(180deg, #59a5ff, #1b5ff5);
  animation: pulse-bar 1s ease-in-out infinite;
}

.waveform span:nth-child(1) { height: 30%; animation-delay: 0s; }
.waveform span:nth-child(2) { height: 60%; animation-delay: 0.1s; }
.waveform span:nth-child(3) { height: 90%; animation-delay: 0.2s; }
.waveform span:nth-child(4) { height: 50%; animation-delay: 0.3s; }
.waveform span:nth-child(5) { height: 75%; animation-delay: 0.15s; }
.waveform span:nth-child(6) { height: 40%; animation-delay: 0.25s; }
.waveform span:nth-child(7) { height: 85%; animation-delay: 0.05s; }
.waveform span:nth-child(8) { height: 55%; animation-delay: 0.2s; }

@keyframes pulse-bar {
  0%, 100% { transform: scaleY(0.55); opacity: 0.7; }
  50% { transform: scaleY(1); opacity: 1; }
}

.rec-pulse {
  animation: rec-glow 1.2s ease-in-out infinite;
}

@keyframes rec-glow {
  0%, 100% { box-shadow: 0 0 0 0 rgba(220, 38, 38, 0.45); }
  50% { box-shadow: 0 0 0 12px rgba(220, 38, 38, 0); }
}

.fade-in {
  animation: fade-up 0.35s ease both;
}

@keyframes fade-up {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.toast {
  pointer-events: auto;
  min-width: min(240px, calc(100vw - 2rem));
  max-width: min(360px, calc(100vw - 2rem));
  padding: 0.85rem 1rem;
  border-radius: 12px;
  background: #19368f;
  color: white;
  box-shadow: 0 12px 30px rgba(20, 34, 87, 0.3);
  animation: fade-up 0.25s ease both;
}

.toast.error {
  background: #9f1239;
}

.toast.success {
  background: #0f766e;
}

.audio-slider {
  -webkit-appearance: none;
  appearance: none;
  height: 6px;
  border-radius: 999px;
  background: rgba(163, 188, 212, 0.55);
  outline: none;
}

html.dark .audio-slider {
  background: rgba(89, 165, 255, 0.25);
}

.audio-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #1b5ff5;
  cursor: pointer;
  box-shadow: 0 0 0 4px rgba(27, 95, 245, 0.15);
}

.modal-backdrop {
  background: rgba(20, 34, 87, 0.45);
  backdrop-filter: blur(4px);
}

html.dark .modal-backdrop {
  background: rgba(5, 10, 22, 0.7);
}

.auth-shell {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.auth-panel {
  width: 100%;
  max-width: 440px;
}

/* App shell / responsive header */
.app-shell {
  padding-left: env(safe-area-inset-left, 0);
  padding-right: env(safe-area-inset-right, 0);
}

.app-header {
  padding-top: env(safe-area-inset-top, 0);
}

.app-header-bar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0.75rem 1rem;
  align-items: center;
}

.app-header-brand {
  justify-self: start;
  grid-column: 1;
  grid-row: 1;
}

.app-header-actions {
  justify-self: end;
  grid-column: 2;
  grid-row: 1;
}

.app-header-nav {
  grid-column: 1 / -1;
  grid-row: 2;
  min-width: 0;
  display: flex;
  justify-content: center;
}

.app-header-nav-track {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.25rem;
  padding: 0.25rem;
  border-radius: 0.9rem;
  background: rgba(232, 238, 246, 0.8);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  overscroll-behavior-x: contain;
  max-width: 100%;
}

.app-header-nav-track::-webkit-scrollbar {
  display: none;
}

html.dark .app-header-nav-track {
  background: rgba(18, 28, 52, 0.85);
}

@media (min-width: 960px) {
  .app-header-bar {
    grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
    gap: 1rem;
  }

  .app-header-brand {
    grid-column: 1;
    grid-row: 1;
    justify-self: start;
  }

  .app-header-nav {
    grid-column: 2;
    grid-row: 1;
    justify-self: center;
    max-width: 100%;
  }

  .app-header-actions {
    grid-column: 3;
    grid-row: 1;
    justify-self: end;
  }
}

.page-actions .btn {
  flex: 1 1 auto;
}

@media (min-width: 640px) {
  .page-actions .btn {
    flex: 0 1 auto;
  }
}

.theme-toggle {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 0.8rem;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  min-width: 2.5rem;
  min-height: 2.5rem;
  width: 2.5rem;
  height: 2.5rem;
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: transform 0.15s ease, border-color 0.2s ease, background 0.2s ease;
}

.theme-toggle:hover {
  border-color: rgba(89, 165, 255, 0.7);
  transform: translateY(-1px);
}

/* Dark-mode helpers for common Tailwind text/bg used in markup */
html.dark .text-med-950,
html.dark .text-med-900 {
  color: #e8f1ff !important;
}

html.dark .text-steel-700,
html.dark .text-steel-600 {
  color: #b7c9de !important;
}

html.dark .text-steel-500 {
  color: #8fa6c0 !important;
}

html.dark .bg-white,
html.dark .bg-white\/70 {
  background-color: rgba(18, 28, 52, 0.92) !important;
}

html.dark .bg-steel-50,
html.dark .bg-steel-100,
html.dark .bg-steel-100\/80 {
  background-color: rgba(30, 45, 74, 0.85) !important;
}

html.dark .border-steel-200,
html.dark .border-med-100,
html.dark .border-med-50 {
  border-color: rgba(89, 165, 255, 0.2) !important;
}

html.dark .divide-med-50 > :not([hidden]) ~ :not([hidden]) {
  border-color: rgba(89, 165, 255, 0.12);
}

html.dark .hover\:bg-med-50\/70:hover,
html.dark .hover\:bg-steel-50:hover {
  background-color: rgba(51, 129, 255, 0.12) !important;
}

html.dark .bg-med-50,
html.dark .bg-med-50\/50,
html.dark .bg-med-50\/70 {
  background-color: rgba(51, 129, 255, 0.12) !important;
}

html.dark header.sticky {
  background: rgba(12, 18, 34, 0.82) !important;
  border-color: rgba(89, 165, 255, 0.15) !important;
}

html.dark .modal-backdrop .bg-white {
  background-color: #162033 !important;
}

.scrollbar-thin::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

.scrollbar-thin::-webkit-scrollbar-thumb {
  background: #a3bcd4;
  border-radius: 999px;
}

html.dark .scrollbar-thin::-webkit-scrollbar-thumb {
  background: #3f6388;
}

.scrollbar-thin::-webkit-scrollbar-track {
  background: transparent;
}

/* Template browser */
.tpl-chip-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--border);
  background: rgba(244, 247, 251, 0.55);
}

html.dark .tpl-chip-bar {
  background: rgba(12, 18, 34, 0.45);
}

.tpl-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  border: 1px solid var(--border);
  background: var(--surface-solid);
  color: var(--text);
  border-radius: 999px;
  padding: 0.35rem 0.7rem;
  font-size: 0.75rem;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease, transform 0.15s ease;
}

.tpl-chip em {
  font-style: normal;
  font-size: 0.68rem;
  opacity: 0.65;
  background: rgba(51, 129, 255, 0.1);
  border-radius: 999px;
  padding: 0.05rem 0.4rem;
}

.tpl-chip:hover {
  border-color: rgba(89, 165, 255, 0.65);
  transform: translateY(-1px);
}

.tpl-chip.is-active {
  color: #fff;
  border-color: transparent;
  background: linear-gradient(135deg, #3b82f6, #1b5ff5);
  box-shadow: 0 8px 16px -10px rgba(27, 95, 245, 0.7);
}

.tpl-chip.is-active em {
  background: rgba(255, 255, 255, 0.22);
  opacity: 1;
}

.tpl-sidebar {
  display: flex;
  flex-direction: column;
  border-bottom: 1px solid var(--border);
  background:
    linear-gradient(180deg, rgba(238, 247, 255, 0.65), rgba(244, 247, 251, 0.35));
  min-height: min(360px, 55vh);
  max-height: min(420px, 60vh);
}

html.dark .tpl-sidebar {
  background: linear-gradient(180deg, rgba(18, 28, 52, 0.95), rgba(12, 18, 34, 0.7));
  border-color: rgba(89, 165, 255, 0.15);
}

@media (min-width: 1024px) {
  .tpl-sidebar {
    border-bottom: 0;
    border-right: 1px solid var(--border);
    max-height: 680px;
    min-height: 560px;
  }
}

.tpl-sidebar-head {
  position: sticky;
  top: 0;
  z-index: 2;
  padding: 0.85rem 0.85rem 0.65rem;
  border-bottom: 1px solid var(--border);
  background: inherit;
  backdrop-filter: blur(8px);
}

.tpl-search-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.tpl-search-icon {
  position: absolute;
  left: 0.75rem;
  color: var(--muted);
  display: grid;
  place-items: center;
  pointer-events: none;
}

.tpl-search-wrap input {
  width: 100%;
  border: 1px solid var(--border);
  background: var(--input-bg);
  color: var(--text);
  border-radius: 0.85rem;
  padding: 0.7rem 2.2rem 0.7rem 2.35rem;
  font-size: 0.875rem;
  font-weight: 500;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.tpl-search-wrap input::placeholder {
  color: var(--muted);
  opacity: 0.85;
}

.tpl-search-wrap input:focus {
  border-color: #59a5ff;
  box-shadow: 0 0 0 4px rgba(51, 129, 255, 0.16);
}

.tpl-search-clear {
  position: absolute;
  right: 0.45rem;
  width: 1.6rem;
  height: 1.6rem;
  border: 0;
  border-radius: 999px;
  background: rgba(82, 124, 163, 0.15);
  color: var(--muted);
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
}

.tpl-search-clear:hover {
  background: rgba(27, 95, 245, 0.15);
  color: var(--text);
}

.tpl-sidebar-meta {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  margin-top: 0.55rem;
  padding: 0 0.15rem;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--muted);
}

.tpl-list {
  flex: 1;
  overflow-y: auto;
  padding: 0.4rem 0.45rem 0.75rem;
}

.tpl-group-header {
  position: sticky;
  top: 0;
  z-index: 1;
  margin: 0.45rem 0.35rem 0.3rem;
  padding: 0.35rem 0.5rem;
  font-size: 0.65rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #1b5ff5;
  background: rgba(238, 247, 255, 0.92);
  border-radius: 0.45rem;
  backdrop-filter: blur(6px);
}

html.dark .tpl-group-header {
  color: #8ec6ff;
  background: rgba(20, 34, 70, 0.92);
}

.tpl-list-item {
  width: 100%;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 0.65rem;
  text-align: left;
  border: 1px solid transparent;
  background: transparent;
  border-radius: 0.85rem;
  padding: 0.65rem 0.6rem;
  margin-bottom: 0.2rem;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.15s ease, box-shadow 0.15s ease;
}

.tpl-list-item:hover {
  background: rgba(255, 255, 255, 0.72);
  border-color: rgba(89, 165, 255, 0.28);
  transform: translateX(2px);
}

html.dark .tpl-list-item:hover {
  background: rgba(30, 45, 74, 0.75);
}

.tpl-list-item.is-active {
  background: linear-gradient(135deg, rgba(59, 130, 246, 0.16), rgba(27, 95, 245, 0.08));
  border-color: rgba(27, 95, 245, 0.35);
  box-shadow: 0 8px 18px -14px rgba(27, 95, 245, 0.55);
}

html.dark .tpl-list-item.is-active {
  background: linear-gradient(135deg, rgba(77, 141, 255, 0.24), rgba(27, 95, 245, 0.1));
  border-color: rgba(89, 165, 255, 0.4);
}

.tpl-list-index {
  width: 1.7rem;
  height: 1.7rem;
  border-radius: 0.5rem;
  display: grid;
  place-items: center;
  font-size: 0.68rem;
  font-weight: 800;
  color: var(--muted);
  background: rgba(82, 124, 163, 0.12);
}

.tpl-list-item.is-active .tpl-list-index {
  color: #fff;
  background: linear-gradient(135deg, #3b82f6, #1b5ff5);
}

.tpl-list-main {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.tpl-list-name {
  font-size: 0.86rem;
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tpl-list-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  font-size: 0.68rem;
  color: var(--muted);
  font-weight: 600;
}

.tpl-list-label {
  max-width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  opacity: 0.9;
}

.tpl-list-chevron {
  color: var(--muted);
  font-size: 1.1rem;
  font-weight: 700;
  opacity: 0.45;
  transition: transform 0.15s ease, opacity 0.15s ease, color 0.15s ease;
}

.tpl-list-item:hover .tpl-list-chevron,
.tpl-list-item.is-active .tpl-list-chevron {
  opacity: 1;
  color: #1b5ff5;
  transform: translateX(2px);
}

.tpl-empty {
  text-align: center;
  padding: 2.5rem 1rem;
  color: var(--muted);
}

.tpl-empty-icon {
  width: 2.5rem;
  height: 2.5rem;
  margin: 0 auto 0.65rem;
  border-radius: 999px;
  display: grid;
  place-items: center;
  font-size: 1.1rem;
  background: rgba(51, 129, 255, 0.1);
  color: #1b5ff5;
}

.tpl-empty p {
  margin: 0;
  font-weight: 700;
  color: var(--text);
}

.tpl-empty span {
  display: block;
  margin-top: 0.25rem;
  font-size: 0.8rem;
}

.tpl-detail {
  background: var(--surface);
}

.tpl-block {
  border: 1px solid var(--border);
  border-radius: 1rem;
  background: var(--input-bg);
  padding: 0.9rem 1rem;
}

.tpl-block-accent {
  background: rgba(51, 129, 255, 0.06);
  border-color: rgba(51, 129, 255, 0.28);
}

html.dark .tpl-block-accent {
  background: rgba(77, 141, 255, 0.1);
}

.tpl-block-label {
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 0.45rem;
}

.tpl-block-body {
  color: var(--text);
  margin: 0;
}

/* Admin stats */
.stats-panel {
  display: flex;
  flex-direction: column;
  min-height: 100%;
}

.stats-panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.15rem 1.25rem 0.85rem;
  border-bottom: 1px solid var(--border);
}

.stats-panel-head-sky {
  background: linear-gradient(180deg, rgba(14, 165, 233, 0.1), transparent);
}

.stats-panel-head-med {
  background: linear-gradient(180deg, rgba(27, 95, 245, 0.1), transparent);
}

.stats-panel-total {
  text-align: right;
  flex-shrink: 0;
}

.stats-panel-total-value {
  font-family: "Sora", "Segoe UI", sans-serif;
  font-size: 2rem;
  font-weight: 800;
  line-height: 1;
  letter-spacing: -0.03em;
  color: var(--med-blue);
}

.stats-panel-head-sky .stats-panel-total-value {
  color: #0284c7;
}

.stats-panel-total-label {
  margin-top: 0.2rem;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.stats-panel-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  padding: 0.75rem 1.25rem;
  border-bottom: 1px solid var(--border);
  background: rgba(244, 247, 251, 0.65);
}

html.dark .stats-panel-summary {
  background: rgba(12, 18, 34, 0.35);
}

.stats-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.28rem 0.65rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--muted);
  background: var(--surface-solid);
  border: 1px solid var(--border);
}

.stats-chip span {
  font-weight: 800;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.stats-chip-urgent {
  background: rgba(251, 191, 36, 0.14);
  border-color: rgba(245, 158, 11, 0.3);
  color: #b45309;
}

html.dark .stats-chip-urgent {
  color: #fbbf24;
}

.stats-chip-urgent span {
  color: inherit;
}

.stats-chip-done {
  background: rgba(16, 185, 129, 0.12);
  border-color: rgba(16, 185, 129, 0.28);
  color: #047857;
}

html.dark .stats-chip-done {
  color: #6ee7b7;
}

.stats-chip-done span {
  color: inherit;
}

.stats-panel-empty {
  padding: 2rem 1.25rem;
  text-align: center;
  font-size: 0.9rem;
  color: var(--muted);
}

.stats-staff-list {
  display: flex;
  flex-direction: column;
  padding: 0.4rem 0;
}

.stats-staff-row {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  padding: 0.85rem 1.25rem;
  border-bottom: 1px solid var(--border);
}

.stats-staff-row:last-child {
  border-bottom: 0;
}

.stats-staff-row:hover {
  background: rgba(51, 129, 255, 0.05);
}

.stats-staff-avatar {
  width: 2.4rem;
  height: 2.4rem;
  border-radius: 0.8rem;
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 0.95rem;
  flex-shrink: 0;
  color: #fff;
}

.stats-staff-avatar-sky {
  background: linear-gradient(145deg, #38bdf8, #0284c7);
}

.stats-staff-avatar-med {
  background: linear-gradient(145deg, #4d8dff, #1b5ff5);
}

.stats-staff-main {
  min-width: 0;
  flex: 1;
}

.stats-staff-name {
  font-weight: 700;
  color: var(--text);
  font-size: 0.98rem;
  line-height: 1.25;
}

.stats-staff-meta {
  margin-top: 0.2rem;
  font-size: 0.75rem;
  color: var(--muted);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.25rem 0.35rem;
}

.stats-dot {
  opacity: 0.55;
}

.stats-staff-count {
  text-align: right;
  flex-shrink: 0;
  min-width: 3.5rem;
}

.stats-staff-count-value {
  font-family: "Sora", "Segoe UI", sans-serif;
  font-size: 1.55rem;
  font-weight: 800;
  line-height: 1;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
}

.stats-staff-count-label {
  margin-top: 0.15rem;
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--muted);
}

.stats-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

.stats-table th,
.stats-table td {
  text-align: left;
  padding: 0.65rem 0.75rem;
  border-bottom: 1px solid var(--border);
}

.stats-table th {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  font-weight: 800;
}

.hourly-chart {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(28px, 1fr));
  gap: 0.35rem;
  align-items: end;
  min-height: 140px;
  padding: 0.5rem 0.25rem 0;
}

.hourly-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.3rem;
  min-width: 0;
}

.hourly-bar-wrap {
  width: 100%;
  height: 110px;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgba(82, 124, 163, 0.08);
  border-radius: 0.45rem 0.45rem 0.2rem 0.2rem;
}

.hourly-bar {
  width: 70%;
  min-height: 0;
  border-radius: 0.35rem 0.35rem 0.15rem 0.15rem;
  background: linear-gradient(180deg, #5aa2ff, #1b5ff5);
  transition: height 0.25s ease;
}

.hourly-label {
  font-size: 0.62rem;
  font-weight: 700;
  color: var(--muted);
}

.queue-urgent {
  background: linear-gradient(90deg, rgba(225, 29, 72, 0.08), transparent 55%);
  box-shadow: inset 3px 0 0 #e11d48;
}

html.dark .queue-urgent {
  background: linear-gradient(90deg, rgba(225, 29, 72, 0.18), transparent 55%);
}

/* Voice pedal (typist foot-pedal replacement) */
.voice-pedal {
  border: 1px solid var(--border);
  border-radius: 1rem;
  background: rgba(255, 255, 255, 0.72);
  padding: 0.85rem;
}

html.dark .voice-pedal {
  background: rgba(12, 18, 34, 0.55);
}

.voice-pedal.is-listening {
  box-shadow: 0 0 0 3px rgba(27, 95, 245, 0.15);
}

.voice-pedal.is-error {
  box-shadow: 0 0 0 3px rgba(225, 29, 72, 0.2);
}

.voice-pedal.is-error .voice-pedal-badge {
  background: rgba(225, 29, 72, 0.15);
  color: #e11d48;
}

.voice-pedal.is-mic-busy {
  box-shadow: 0 0 0 3px rgba(225, 29, 72, 0.18);
}

.voice-pedal.is-mic-busy .voice-pedal-badge {
  background: rgba(225, 29, 72, 0.15);
  color: #e11d48;
}

.voice-pedal.is-dictation .voice-pedal-pad-main {
  background: linear-gradient(180deg, rgba(244, 63, 94, 0.14), rgba(225, 29, 72, 0.06));
  border-color: rgba(225, 29, 72, 0.3);
}

.voice-pedal-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.voice-pedal-title {
  font-weight: 800;
  color: var(--text);
  font-size: 0.95rem;
}

.voice-pedal-sub {
  margin: 0.15rem 0 0;
  font-size: 0.75rem;
  color: var(--muted);
}

.voice-pedal-badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 0.25rem 0.65rem;
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  background: rgba(82, 124, 163, 0.15);
  color: var(--muted);
}

.voice-pedal.is-listening .voice-pedal-badge {
  background: rgba(27, 95, 245, 0.15);
  color: #1b5ff5;
}

.voice-pedal.is-hold-rewind .voice-pedal-badge,
.voice-pedal.is-hold-forward .voice-pedal-badge {
  background: rgba(217, 119, 6, 0.18);
  color: #d97706;
}

.voice-pedal-deck {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.5rem;
}

.voice-pedal-pad {
  border: 1px solid var(--border);
  border-radius: 0.85rem;
  padding: 0.65rem 0.45rem;
  text-align: center;
  background: var(--input-bg);
  transition: border-color 0.15s ease, background 0.15s ease, transform 0.15s ease;
}

.voice-pedal-pad strong {
  display: block;
  font-size: 0.82rem;
  color: var(--text);
  margin: 0.15rem 0;
}

.voice-pedal-pad small {
  display: block;
  font-size: 0.65rem;
  color: var(--muted);
}

.voice-pedal-pad-label {
  display: block;
  font-size: 0.62rem;
  font-weight: 800;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--muted);
}

.voice-pedal-pad-main {
  background: linear-gradient(180deg, rgba(59, 130, 246, 0.12), rgba(27, 95, 245, 0.05));
  border-color: rgba(27, 95, 245, 0.28);
}

.voice-pedal-pad.is-active {
  transform: translateY(-1px);
  border-color: #1b5ff5;
  box-shadow: 0 8px 18px -12px rgba(27, 95, 245, 0.65);
  background: linear-gradient(180deg, rgba(59, 130, 246, 0.22), rgba(27, 95, 245, 0.1));
}

.voice-pedal.is-hold-rewind [data-pedal="rewind"],
.voice-pedal.is-hold-forward [data-pedal="forward"] {
  border-color: #d97706;
  background: linear-gradient(180deg, rgba(251, 191, 36, 0.25), rgba(217, 119, 6, 0.08));
}

.voice-pedal-footer {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.65rem;
  margin-top: 0.75rem;
}

.voice-pedal-heard {
  margin: 0;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--muted);
  flex: 1;
  min-width: 160px;
}

.voice-pedal-tip {
  margin: 0.55rem 0 0;
  font-size: 0.7rem;
  color: var(--muted);
}

@media (max-width: 640px) {
  .voice-pedal-deck {
    grid-template-columns: 1fr;
  }

  .voice-pedal-pad {
    min-height: 4.25rem;
  }
}

.case-search-wrap {
  position: relative;
}

.case-search-wrap .field {
  padding-right: 2.2rem;
}

.case-search-clear {
  position: absolute;
  right: 0.45rem;
  top: 50%;
  transform: translateY(-50%);
  width: 1.6rem;
  height: 1.6rem;
  border: 0;
  border-radius: 999px;
  background: rgba(82, 124, 163, 0.15);
  color: var(--muted);
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
}

.case-search-clear:hover {
  background: rgba(27, 95, 245, 0.15);
  color: var(--text);
}

/* Typist waiting queue */
.wait-case {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.85rem 1.25rem;
  padding: 1rem 1.1rem;
  border-radius: 1rem;
  border: 1px solid var(--border);
  background: var(--surface);
  box-shadow: var(--shadow);
  transition: transform 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
  cursor: pointer;
}

.wait-case:hover {
  transform: translateY(-2px);
  border-color: rgba(89, 165, 255, 0.55);
  box-shadow: var(--card-hover-shadow);
}

.wait-case-active {
  border-color: rgba(27, 95, 245, 0.55);
  box-shadow: 0 0 0 3px rgba(51, 129, 255, 0.18);
}

.wait-time-block {
  flex-shrink: 0;
  text-align: right;
  min-width: 5.5rem;
  padding: 0.45rem 0.7rem;
  border-radius: 0.75rem;
  background: rgba(251, 191, 36, 0.14);
  border: 1px solid rgba(245, 158, 11, 0.28);
}

.wait-time-label {
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #b45309;
}

.wait-time-value {
  font-size: 1.15rem;
  font-weight: 800;
  color: #92400e;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}

html.dark .wait-time-block {
  background: rgba(245, 158, 11, 0.12);
  border-color: rgba(251, 191, 36, 0.25);
}

html.dark .wait-time-label {
  color: #fbbf24;
}

html.dark .wait-time-value {
  color: #fde68a;
}

/* Cross-device responsive polish */
@media (max-width: 640px) {
  .field,
  input.field,
  select.field,
  textarea.field,
  .sa-dp-trigger {
    font-size: 16px !important; /* prevents iOS zoom on focus */
  }

  .app-footer-inner {
    padding: 1rem 1rem calc(1rem + env(safe-area-inset-bottom, 0px));
    flex-direction: column;
    align-items: flex-start;
  }

  .sa-dp {
    width: 100%;
    min-width: 0;
  }

  .sa-dp-popover {
    left: 0;
    right: 0;
    width: 100%;
  }

  .stats-staff-row {
    gap: 0.65rem;
    padding: 0.8rem 1rem;
  }

  .stats-staff-meta {
    font-size: 0.7rem;
  }

  .hourly-chart {
    grid-template-columns: repeat(auto-fit, minmax(22px, 1fr));
    min-height: 120px;
  }

  .wait-case {
    padding: 0.9rem 1rem;
  }

  .wait-time-block {
    min-width: 4.75rem;
  }

  #toast-root {
    left: 0.75rem;
    right: 0.75rem;
    bottom: calc(0.75rem + env(safe-area-inset-bottom, 0px));
    align-items: stretch;
  }

  .toast {
    max-width: none;
    min-width: 0;
    width: 100%;
  }
}

@media (max-width: 380px) {
  .brand-mark {
    width: 36px;
    height: 36px;
    border-radius: 10px;
  }

  .stats-panel-total-value {
    font-size: 1.6rem;
  }

  .stats-staff-count-value {
    font-size: 1.3rem;
  }
}

/* Touch devices: reduce hover lift that feels sticky */
@media (hover: none) {
  .anim-card:hover,
  .role-card:hover,
  .wait-case:hover,
  .sa-dp-trigger:hover {
    transform: none;
  }

  .btn:hover {
    filter: none;
  }
}

/* Large tablets / landscape phones */
@media (min-width: 641px) and (max-width: 1023px) {
  .tpl-sidebar {
    min-height: 380px;
    max-height: 480px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .waveform span,
  .rec-pulse,
  .fade-in,
  .role-card,
  .anim-card,
  .stagger > *,
  .btn,
  .sa-dp-popover {
    animation: none !important;
    transition: none !important;
  }
}
