/* ECG-Master Studio PWA — Dark ICU Monitor Theme + Mobile-First Responsive Grid */

@font-face {
  font-family: 'Cairo';
  src: url('../assets/fonts/Cairo-600.ttf') format('truetype');
  font-weight: 400 600;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'Cairo';
  src: url('../assets/fonts/Cairo-700.ttf') format('truetype');
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'Cairo';
  src: url('../assets/fonts/Cairo-800.ttf') format('truetype');
  font-weight: 800;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'Cairo';
  src: url('../assets/fonts/Cairo-900.ttf') format('truetype');
  font-weight: 900;
  font-style: normal;
  font-display: swap;
}

:root {
  --bg-app: #060A14;
  --bg-surface: #0B1220;
  --bg-card: #0F172A;
  --bg-soft: #162238;
  --border: #1E293B;
  --border-strong: #334155;
  --text: #F1F5F9;
  --text-sub: #CBD5E1;
  --text-muted: #94A3B8;
  --accent-teal: #10F2C6;
  --accent-cyan: #38BDF8;
  --accent-emerald: #34D399;
  --accent-blue: #0284C7;
  --accent-danger: #EF4444;
  --accent-caliper: #FBBF24;
  --font-ui: 'Cairo', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

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

html, body {
  height: 100%;
  background: var(--bg-app);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 14px;
  line-height: 1.5;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
}

body {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
}

button, input, select {
  font-family: inherit;
  color: inherit;
}

[hidden] {
  display: none !important;
}

/* Header */
.app-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 12px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  z-index: 20;
}

.brand-cluster {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.brand-logo {
  border-radius: 8px;
  border: 1px solid var(--border-strong);
  flex-shrink: 0;
}

.brand-text h1 {
  font-size: 0.95rem;
  font-weight: 800;
  letter-spacing: 0.01em;
  color: var(--text);
  line-height: 1.2;
}

.brand-text p {
  font-size: 0.72rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 220px;
}

.hud-vitals {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.vital-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-family: var(--font-mono);
  font-size: 0.78rem;
}

.vital-pill .vital-label {
  color: var(--text-muted);
  font-size: 0.68rem;
}

.vital-hr strong {
  color: var(--accent-teal);
  font-size: 0.92rem;
}

.beat-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #334155;
  transition: transform 0.08s ease;
}

.beat-dot.pulse {
  background: var(--accent-teal);
  box-shadow: 0 0 10px var(--accent-teal);
  transform: scale(1.35);
}

.active-case-pill {
  padding: 4px 10px;
  background: rgba(56, 189, 248, 0.12);
  border: 1px solid rgba(56, 189, 248, 0.35);
  border-radius: 8px;
  color: var(--accent-cyan);
  font-weight: 700;
  font-size: 0.78rem;
  max-width: 240px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.action-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  min-height: 44px;
  padding: 0 10px;
  border-radius: 8px;
  border: 1px solid var(--border-strong);
  background: var(--bg-card);
  color: var(--text);
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.action-btn:hover, .action-btn.active {
  border-color: var(--accent-cyan);
  background: rgba(56, 189, 248, 0.14);
}

.action-primary {
  background: var(--accent-blue);
  border-color: var(--accent-cyan);
  color: #FFFFFF;
}

.action-win {
  background: #0F2744;
  border-color: #2563EB;
  color: #BAE6FD;
}

/* Workspace Layout */
.workspace {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  padding: 8px;
  padding-bottom: calc(68px + var(--safe-bottom));
}

.pane {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.pane-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-card);
}

.pane-head h2 {
  font-size: 0.9rem;
  font-weight: 800;
  color: var(--text);
}

.count-badge {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(16, 242, 198, 0.12);
  color: var(--accent-teal);
  border: 1px solid rgba(16, 242, 198, 0.3);
}

/* Case Sidebar */
.search-box-wrap {
  padding: 8px 10px 4px;
}

.search-input {
  width: 100%;
  min-height: 44px;
  padding: 8px 12px;
  border-radius: 8px;
  border: 1px solid var(--border-strong);
  background: var(--bg-card);
  color: var(--text);
  font-size: 0.85rem;
}

.search-input:focus {
  outline: none;
  border-color: var(--accent-cyan);
}

.cat-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  padding: 6px 10px 8px;
  border-bottom: 1px solid var(--border);
}

.cat-pill {
  min-height: 36px;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  background: var(--bg-card);
  color: var(--text-sub);
  font-size: 0.75rem;
  font-weight: 700;
  cursor: pointer;
}

.cat-pill.active {
  background: rgba(56, 189, 248, 0.16);
  border-color: var(--accent-cyan);
  color: var(--accent-cyan);
}

.cases-list {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.case-item {
  width: 100%;
  flex-shrink: 0;
  text-align: start;
  padding: 10px 10px;
  min-height: 54px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  cursor: pointer;
  transition: border-color 0.12s ease, background 0.12s ease;
}

.case-item:hover {
  border-color: var(--border-strong);
}

.case-item.active {
  border-color: var(--accent-teal);
  background: rgba(16, 242, 198, 0.10);
}

.case-item-top {
  display: flex;
  align-items: center;
  gap: 6px;
}

.case-num {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--accent-cyan);
  flex-shrink: 0;
}

.case-name {
  font-size: 0.84rem;
  font-weight: 700;
  color: var(--text);
  flex: 1 1 auto;
}

.case-hr {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--accent-emerald);
  flex-shrink: 0;
  direction: ltr;
}

.case-item-sub {
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-top: 2px;
}

/* Center Monitor & Study/Quiz */
.center-pane {
  gap: 8px;
  padding: 8px;
  overflow-y: auto;
}

.monitor-card {
  display: flex;
  flex-direction: column;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  flex-shrink: 0;
}

.monitor-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-surface);
}

.tool-btn, .tool-select {
  min-height: 44px;
  padding: 0 10px;
  border-radius: 8px;
  border: 1px solid var(--border-strong);
  background: var(--bg-card);
  color: var(--text);
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
}

.tool-btn.active {
  border-color: var(--accent-caliper);
  color: var(--accent-caliper);
  background: rgba(251, 191, 36, 0.12);
}

.tool-primary {
  background: var(--accent-blue);
  border-color: var(--accent-cyan);
  color: #FFFFFF;
}

.ecg-viewport {
  position: relative;
  width: 100%;
  height: 340px;
  background: #080D18;
  overflow: hidden;
  touch-action: pan-y;
}

body.theme-paper .ecg-viewport {
  background: #FFF6F6;
}

body[data-mobile-tab="quiz"] .ecg-viewport {
  height: 240px;
}

#ecgCanvas {
  display: block;
  width: 100%;
  height: 100%;
}

/* Touch Caliper */
.caliper-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 10;
}

.caliper-region {
  position: absolute;
  background: rgba(251, 191, 36, 0.12);
  border: 1px dashed rgba(251, 191, 36, 0.45);
}

.caliper-bar-v {
  position: absolute;
  top: 22px;
  bottom: 0;
  width: 2px;
  background: var(--accent-caliper);
  pointer-events: auto;
  touch-action: none;
  cursor: ew-resize;
}

.caliper-bar-h {
  position: absolute;
  left: 0;
  right: 0;
  height: 2px;
  background: var(--accent-cyan);
  pointer-events: auto;
  touch-action: none;
  cursor: ns-resize;
}

.caliper-grip {
  position: absolute;
  min-width: 44px;
  min-height: 44px;
  padding: 4px 8px;
  border-radius: 8px;
  border: 1px solid #FFFFFF;
  background: #B45309;
  color: #FFFFFF;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 800;
  cursor: grab;
  touch-action: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.caliper-bar-v .caliper-grip {
  bottom: 6px;
  left: -21px;
}

.caliper-bar-h .caliper-grip {
  left: 8px;
  top: -21px;
  background: #0369A1;
}

.caliper-hud {
  position: absolute;
  top: 28px;
  right: 8px;
  max-width: 260px;
  background: rgba(8, 13, 24, 0.92);
  border: 1px solid var(--accent-caliper);
  border-radius: 8px;
  padding: 6px 8px;
  pointer-events: auto;
  font-size: 0.74rem;
}

.caliper-hud-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 4px;
}

.caliper-title {
  color: var(--accent-caliper);
  font-weight: 800;
}

.caliper-snap-btn {
  min-height: 28px;
  padding: 2px 8px;
  border-radius: 6px;
  border: 1px solid var(--accent-cyan);
  background: rgba(56, 189, 248, 0.14);
  color: var(--accent-cyan);
  font-size: 0.7rem;
  font-weight: 700;
  cursor: pointer;
}

.caliper-metrics {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  font-family: var(--font-mono);
  font-weight: 700;
  color: var(--text);
}

.caliper-hint {
  margin-top: 3px;
  color: var(--accent-teal);
  font-size: 0.72rem;
}

/* Sub-tabs & Study / Quiz Cards */
.subtab-bar {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.subtab-btn {
  min-height: 44px;
  padding: 6px 14px;
  border-radius: 8px;
  border: 1px solid var(--border-strong);
  background: var(--bg-card);
  color: var(--text-sub);
  font-size: 0.82rem;
  font-weight: 700;
  cursor: pointer;
}

.subtab-btn.active {
  background: rgba(16, 242, 198, 0.14);
  border-color: var(--accent-teal);
  color: var(--accent-teal);
}

.study-card, .quiz-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  flex: 1 1 auto;
}

.detail-title {
  font-size: 1rem;
  font-weight: 800;
  color: var(--accent-cyan);
}

.detail-meta {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.detail-block {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
}

.detail-block h4 {
  font-size: 0.82rem;
  font-weight: 800;
  color: var(--accent-teal);
  margin-bottom: 6px;
}

.detail-block p, .criteria-list li {
  font-size: 0.82rem;
  color: var(--text-sub);
  line-height: 1.6;
}

.criteria-list {
  padding-inline-start: 18px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.detail-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  margin: 8px 0;
}

.detail-mgmt {
  border-inline-start: 3px solid var(--accent-emerald);
}

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

.comp-chapter {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
}

.comp-chapter summary {
  font-weight: 800;
  font-size: 0.86rem;
  color: var(--accent-cyan);
  cursor: pointer;
  min-height: 36px;
  display: flex;
  align-items: center;
}

.comp-body {
  margin-top: 8px;
  font-size: 0.82rem;
  color: var(--text-sub);
  line-height: 1.65;
}

.comp-body ul, .comp-body ol {
  padding-inline-start: 20px;
  margin-top: 6px;
}

/* Quiz */
.quiz-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.score-badge {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(56, 189, 248, 0.14);
  color: var(--accent-cyan);
}

.quiz-modes {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.quiz-vignette {
  padding: 8px 10px;
  background: rgba(56, 189, 248, 0.08);
  border-inline-start: 3px solid var(--accent-cyan);
  border-radius: 6px;
  font-size: 0.84rem;
  color: var(--text);
}

.quiz-prompt {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--text);
}

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

.quiz-option {
  width: 100%;
  min-height: 46px;
  padding: 10px 12px;
  text-align: start;
  border-radius: 8px;
  border: 1px solid var(--border-strong);
  background: var(--bg-surface);
  color: var(--text);
  font-size: 0.84rem;
  font-weight: 600;
  cursor: pointer;
}

.quiz-option.selected {
  border-color: var(--accent-cyan);
  background: rgba(56, 189, 248, 0.16);
}

.quiz-option.correct {
  border-color: var(--accent-emerald);
  background: rgba(52, 211, 153, 0.18);
  color: #ECFDF5;
}

.quiz-option.wrong {
  border-color: var(--accent-danger);
  background: rgba(239, 68, 68, 0.18);
}

.quiz-numeric {
  display: flex;
  align-items: center;
  gap: 8px;
}

.unit-tag {
  font-family: var(--font-mono);
  color: var(--accent-cyan);
  font-weight: 700;
}

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

.quiz-feedback {
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 0.82rem;
  line-height: 1.6;
}

.quiz-feedback.ok {
  background: rgba(16, 185, 129, 0.14);
  border: 1px solid var(--accent-emerald);
}

.quiz-feedback.err {
  background: rgba(239, 68, 68, 0.14);
  border: 1px solid var(--accent-danger);
}

/* 3D Heart Panel */
.heart-pane {
  gap: 8px;
}

.heart-controls {
  display: flex;
  gap: 6px;
  padding: 0 10px;
}

.heart-controls .tool-btn {
  flex: 1 1 0;
}

.heart-viewport {
  position: relative;
  flex: 1 1 auto;
  min-height: 320px;
  margin: 0 10px;
  background: #080D18;
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
}

#heart3d {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

.heart-fallback {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 16px;
  text-align: center;
  background: radial-gradient(circle at center, #0F1C36 0%, #080D18 100%);
}

.heart-fallback-img {
  width: 180px;
  height: 180px;
  object-fit: contain;
  border-radius: 20px;
}

.heart-fallback p {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.conduction-strip {
  padding: 8px 10px 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.node-pills {
  display: flex;
  gap: 6px;
  justify-content: center;
}

.node-pill {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 700;
  padding: 4px 8px;
  border-radius: 6px;
  border: 1px solid var(--border-strong);
  background: var(--bg-card);
  color: var(--text-muted);
}

.node-pill.lit {
  border-color: var(--accent-teal);
  color: var(--accent-teal);
  background: rgba(16, 242, 198, 0.14);
}

.node-pill.blocked {
  border-color: var(--accent-danger);
  color: var(--accent-danger);
  background: rgba(239, 68, 68, 0.16);
}

.phase-readout {
  text-align: center;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--accent-cyan);
}

/* Mobile Bottom Tab Bar */
.mobile-tab-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  background: var(--bg-surface);
  border-top: 1px solid var(--border-strong);
  padding-bottom: var(--safe-bottom);
  z-index: 30;
}

.tab-btn {
  min-height: 54px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-size: 0.74rem;
  font-weight: 700;
  cursor: pointer;
}

.tab-btn.active {
  color: var(--accent-teal);
  background: rgba(16, 242, 198, 0.08);
}

.tab-icon {
  font-size: 1.05rem;
  line-height: 1;
}

/* Install Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(6, 10, 20, 0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 50;
}

.modal-card {
  width: 100%;
  max-width: 440px;
  background: var(--bg-card);
  border: 1px solid var(--border-strong);
  border-radius: 14px;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.modal-card h3 {
  font-size: 1rem;
  color: var(--accent-cyan);
}

.install-box {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 0.84rem;
  color: var(--text-sub);
}

.desktop-only {
  display: none;
}

.mobile-only {
  display: flex;
}

@media (max-width: 520px) {
  .brand-text p {
    display: none;
  }
  .hide-xs {
    display: none;
  }
  .active-case-pill {
    max-width: 150px;
  }
  .action-btn {
    padding: 0 8px;
    font-size: 0.72rem;
    min-width: 44px;
  }
}

/* Tablet & Desktop Split View (>= 900px) */
@media (min-width: 900px) {
  .desktop-only {
    display: flex;
  }
  .mobile-only, .mobile-tab-bar {
    display: none;
  }
  .workspace {
    grid-template-columns: 270px minmax(0, 1fr) 300px;
    padding-bottom: 10px;
  }
  .ecg-viewport {
    height: 390px;
  }
  .detail-grid {
    grid-template-columns: 1fr 1fr;
  }
}

@media (min-width: 1280px) {
  .workspace {
    grid-template-columns: 300px minmax(0, 1fr) 340px;
  }
  .ecg-viewport {
    height: 430px;
  }
}
