:root {
  --bg: #f8f6f2;
  --bg-accent: #dad7cb;
  --surface: rgba(255, 255, 255, 0.96);
  --surface-strong: #ffffff;
  --border: rgba(46, 45, 41, 0.2);
  --text: #2e2d29;
  --muted: #5f574f;
  --accent: #8c1515;
  --blue: #006cb8;
  --gold: #b26f16;
  --danger: #b1040e;
  --good: #007c92;
  --shadow: 0 8px 12px -6px rgba(46, 45, 41, 0.22);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--text);
  background: var(--bg-accent);
}

.app-shell {
  width: min(1540px, calc(100% - 40px));
  margin: 0 auto;
  padding: 12px 0;
}

.workspace {
  display: grid;
  grid-template-columns: 375px 1fr;
  gap: 10px;
  align-items: stretch;
  height: calc(100vh - 24px);
}

.status-panel {
  display: grid;
  gap: 8px;
  align-content: start;
  max-height: 100%;
  overflow: auto;
}

.status-card,
.metrics-card {
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 0;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.logo-monitor-button {
  display: block;
  width: min(174px, 100%);
  margin: 0 0 6px;
  padding: 3px;
  border: 2px solid transparent;
  background: transparent;
  cursor: pointer;
  text-align: left;
}

.logo-monitor-button.monitor-connected {
  border-color: var(--accent);
}

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

.stanford-logo {
  display: block;
  width: min(174px, 100%);
  height: auto;
  margin-bottom: 0;
}

.monitor-status {
  display: none;
}

.monitor-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(2, 6, 23, 0.82);
}

.monitor-overlay[hidden] {
  display: none;
}

.monitor-overlay-panel {
  display: grid;
  gap: 12px;
  justify-items: center;
  max-width: 94vw;
  max-height: 92vh;
}

.monitor-overlay-title {
  margin: 0;
  color: #ffffff;
  font-size: 1rem;
  font-weight: 800;
}

.monitor-roi-canvas {
  max-width: 90vw;
  max-height: 78vh;
  border: 2px dashed #ffffff;
  background: #020617;
  cursor: crosshair;
}

.monitor-overlay-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.monitor-video {
  display: none;
}

.status-label,
.metric-label {
  display: block;
  margin-bottom: 4px;
  font-size: 0.7rem;
  font-weight: 750;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.app-title {
  font-size: 1.35rem;
  line-height: 1.1;
  letter-spacing: 0;
  text-transform: none;
  color: var(--accent);
}

.status-card strong {
  font-size: 0.92rem;
  color: var(--text);
}

.status-note,
.status-disclaimer {
  margin: 6px 0 0;
  font-size: 0.84rem;
  line-height: 1.32;
  color: var(--muted);
}

.status-note a {
  color: var(--accent);
  font-weight: 800;
}

.author-line {
  margin-top: 12px;
  font-size: 0.72rem;
}

.author-line a {
  font-weight: inherit;
}

.status-disclaimer {
  padding-top: 6px;
  border-top: 1px solid var(--border);
  color: var(--danger);
}

.compact-title {
  display: block;
  line-height: 1.32;
}

.compact-note {
  font-size: 0.84rem;
}

.stats-header-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 6px;
}

.stats-accession {
  margin: 0;
  font-size: 0.9rem;
  font-weight: 750;
  color: var(--accent);
  text-align: right;
}

#stats-panel {
  display: grid;
  gap: 8px;
}

.analysis-table {
  display: grid;
  gap: 0;
  margin-top: 0;
  border-top: 1px solid var(--border);
}

.analysis-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: baseline;
  padding: 7px 0;
  border-bottom: 1px solid var(--border);
}

.analysis-row:last-child {
  border-bottom: 0;
}

.report-button {
  width: auto;
  margin-top: 14px;
  padding: 8px 10px;
  border: 1px solid var(--accent);
  border-radius: 0;
  background: var(--accent);
  color: #ffffff;
  font-size: 0.86rem;
  font-weight: 800;
  cursor: pointer;
  justify-self: start;
}

.report-button:disabled,
.nav-button:disabled {
  opacity: 0.45;
  cursor: default;
}

.report-button:active,
.nav-button:active {
  transform: translateY(1px);
}

.report-section {
  margin-top: 14px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}

.report-preview {
  margin-top: 6px;
  padding: 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  font-size: 0.84rem;
  line-height: 1.38;
  color: var(--muted);
}

.stats-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 12px;
}

.study-nav {
  display: flex;
  align-items: center;
  gap: 6px;
}

.nav-button {
  width: auto;
  padding: 8px 9px;
  border: 1px solid var(--border);
  border-radius: 0;
  background: var(--surface-strong);
  color: var(--text);
  font-size: 0.78rem;
  font-weight: 800;
  cursor: pointer;
}

.study-count {
  min-width: 44px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  text-align: center;
}

.stats-file {
  margin: 0;
  font-size: 0.9rem;
  font-weight: 750;
  color: var(--accent);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.save-warning {
  margin: 8px 0 0;
  color: var(--gold);
  font-size: 0.78rem;
  line-height: 1.3;
  font-weight: 700;
}

.sidebar-table {
  margin-top: 12px;
}

.results-section {
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 0;
  background: var(--surface);
  box-shadow: var(--shadow);
  min-height: 0;
  display: flex;
  flex-direction: column;
  outline: none;
  cursor: pointer;
  transition: border-color 0.2s ease, background 0.2s ease;
}

.results-section:hover,
.results-section.active {
  border-color: var(--accent);
  background: #fffefe;
}

.results-section.has-image-output {
  padding: 0;
  border: 0;
  background: transparent;
  box-shadow: none;
}

.results-section.has-image-output:hover,
.results-section.has-image-output.active {
  background: transparent;
}

.results-grid {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
}

.results-grid.empty-results {
  place-items: center;
}

.empty-state {
  border-radius: 0;
  background: var(--bg);
  border: 1px solid var(--border);
  overflow: hidden;
}

.empty-panel {
  width: min(260px, 82%);
  display: grid;
  gap: 8px;
  justify-items: center;
}

.drop-disclaimer {
  width: 100%;
  margin: 0;
  color: var(--danger);
  font-size: 0.86rem;
  line-height: 1.28;
  text-align: center;
}

.result-card {
  min-height: 0;
  display: grid;
  overflow: hidden;
}

.empty-state {
  display: grid;
  place-items: center;
  width: 100%;
  min-height: 70px;
  padding: 14px 18px;
  color: var(--muted);
  border: 2px dashed rgba(140, 21, 21, 0.35);
}

.empty-state p {
  margin: 0;
  font-size: 1rem;
  font-weight: 800;
  letter-spacing: 0;
  text-align: center;
}

.empty-state .drop-kicker {
  margin-bottom: 8px;
  color: var(--accent);
  font-size: 0.86rem;
  font-weight: 800;
}

.empty-state.analyzing {
  gap: 8px;
}

.hourglass-emoji {
  display: inline-block;
  margin-left: 6px;
  animation: blink-hourglass 0.9s ease-in-out infinite;
}

@keyframes blink-hourglass {
  0%, 100% {
    opacity: 1;
  }
  50% {
    opacity: 0.25;
  }
}

.canvas-wrap {
  width: 100%;
  height: 100%;
  min-height: 0;
  background: #020617;
  display: flex;
  align-items: center;
  justify-content: center;
}

.annotated-canvas {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.result-body {
  padding: 16px;
}

.result-name {
  margin: 0 0 12px;
  font-size: 0.9rem;
  font-weight: 750;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.measurement-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 14px;
}

.metric-value {
  font-size: 0.9rem;
  font-weight: 800;
  text-align: right;
}

.metric-value.good {
  color: var(--good);
}

.metric-value.warning {
  color: var(--gold);
}

.metric-value.neutral {
  color: var(--blue);
}

.landmark-table {
  display: grid;
  gap: 8px;
}

.landmark-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  padding: 8px 0;
  border-top: 1px solid var(--border);
  font-size: 0.8rem;
}

.landmark-row span:first-child {
  color: var(--muted);
  font-weight: 650;
}

.landmark-row strong {
  font-weight: 750;
  text-align: right;
}

.error-text {
  color: var(--danger);
  font-weight: 750;
}

@media (max-width: 1020px) {
  body {
    overflow: auto;
  }

  .workspace {
    height: auto;
  }

  .workspace {
    grid-template-columns: 1fr;
  }

  .status-panel {
    grid-template-columns: repeat(2, 1fr);
    max-height: none;
  }

  .results-section {
    min-height: 72vh;
  }
}

@media (max-width: 760px) {
  .app-shell {
    width: min(100% - 24px, 1540px);
  }

  .status-panel,
  .measurement-grid {
    grid-template-columns: 1fr;
  }

  .results-section {
    padding: 16px;
  }

  .results-section.has-image-output {
    padding: 0;
  }

  .results-grid {
    grid-template-columns: 1fr;
  }
}
