* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: system-ui, -apple-system, sans-serif;
  background: #f6f7f9;
  color: #222;
  line-height: 1.5;
  font-size: 16px;
}
header {
  display: flex; justify-content: space-between; align-items: center;
  background: #1f2a44; color: #fff; padding: 0.6em 1em;
  position: sticky; top: 0; z-index: 10;
}
header h1 { margin: 0; font-size: 1.1em; }
nav { display: flex; gap: 0.4em; }
nav button {
  background: transparent; color: #fff; border: 1px solid #4a567a;
  padding: 0.45em 0.9em; border-radius: 6px; font-size: 0.9em;
}
nav button.active { background: #4a567a; }
.phase { padding: 1em; max-width: 860px; margin: 0 auto; }
.phase.hidden { display: none; }
h2 { margin-top: 0.4em; }
.muted { color: #666; }
.err { color: #b00020; }

.btn-primary, button {
  background: #1f2a44; color: #fff; border: 0; border-radius: 8px;
  padding: 0.7em 1.1em; font-size: 1em; cursor: pointer;
}
.btn-primary { background: #2563eb; }
button[disabled] { opacity: 0.5; }
.row { display: flex; justify-content: space-between; align-items: center; gap: 0.5em; margin-top: 1em; flex-wrap: wrap; }

.file-pick { display: inline-block; }
.file-pick input { display: none; }

#mark-canvas-wrap { position: relative; touch-action: none; user-select: none; -webkit-user-select: none; }
#mark-canvas { width: 100%; max-height: 70vh; background: #ddd; display: block; touch-action: none; }
.info-pair { display: flex; gap: 0.5em; align-items: center; }
.info-pair code { background: #fff; padding: 0.2em 0.5em; border-radius: 4px; }

.callout { background: #fff7ed; border-left: 4px solid #f59e0b; padding: 0.6em 0.9em; border-radius: 6px; margin: 0.6em 0 0.8em; }
.callout p { margin: 0.25em 0; }

.preview-wrap { background: #fff; padding: 0.5em; border-radius: 8px; box-shadow: 0 1px 3px rgba(0,0,0,0.06); margin-top: 0.8em; }
.preview-wrap.hidden { display: none; }
.preview-wrap img { width: 100%; display: block; border-radius: 4px; }
.small { font-size: 0.85em; }

.canonical-wrap { background: #fff; padding: 0.4em; border-radius: 8px; box-shadow: 0 1px 3px rgba(0,0,0,0.06); }
.canonical-wrap img { width: 100%; display: block; }

.wells-grid { display: grid; grid-template-columns: repeat(8, 1fr); gap: 0.4em; margin: 0.8em 0; }
.well-cell { background: #fff; border-radius: 6px; padding: 0.3em; box-shadow: 0 1px 3px rgba(0,0,0,0.05); text-align: center; }
.well-cell img { width: 100%; height: 130px; object-fit: cover; border-radius: 4px; }
.well-cell .label { font-size: 0.75em; color: #555; margin: 0.2em 0 0; }
.well-cell .grade-pill {
  display: inline-block; padding: 0.3em 0.6em; margin-top: 0.3em;
  border: 2px solid #ccc; border-radius: 999px; font-weight: 600;
  cursor: pointer; min-width: 2.4em; background: #fff;
}
.well-cell.review .grade-pill { border-color: #d97706; background: #fef3c7; }
.well-cell.pos .grade-pill { border-color: #2563eb; background: #dbeafe; }
.well-cell.neg .grade-pill { border-color: #777; }
.well-cell.unknown .grade-pill { border-color: #b00020; background: #fee2e2; }
.well-cell.off-frame { opacity: 0.85; }
.well-cell.off-frame img { filter: grayscale(1); }
.off-frame-badge { color: #b45309; font-size: 0.7em; font-weight: 600; margin-top: 0.2em; }

.interp { background: #fff; border-radius: 8px; padding: 0.8em; margin-top: 0.6em; }
.interp h3 { margin: 0 0 0.4em; }
.interp-result.ok    { color: #065f46; font-weight: 600; }
.interp-result.warn  { color: #b45309; font-weight: 600; }
.issues { margin: 0.4em 0 0; padding-left: 1.2em; color: #b45309; }
.issues:empty { display: none; }

.patient-block { background: #fff; border-radius: 8px; padding: 0.8em; margin-top: 0.8em; display: grid; gap: 0.5em; }
.patient-block label { display: grid; gap: 0.2em; font-size: 0.92em; color: #333; }
.patient-block input, .patient-block textarea {
  font: inherit; padding: 0.5em; border: 1px solid #ccc; border-radius: 6px;
}

table#history-table { width: 100%; border-collapse: collapse; background: #fff; border-radius: 8px; overflow: hidden; box-shadow: 0 1px 3px rgba(0,0,0,0.06); }
#history-table th, #history-table td { padding: 0.5em 0.7em; text-align: left; border-bottom: 1px solid #eee; }
#history-table th { background: #f1f3f6; }

/* login */
body.login { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: #1f2a44; }
.login-card { background: #fff; padding: 2em; border-radius: 12px; box-shadow: 0 4px 18px rgba(0,0,0,0.18); width: 100%; max-width: 360px; }
.login-card h1 { margin: 0 0 0.2em; }
.login-card form { display: grid; gap: 0.8em; }
.login-card input { font: inherit; padding: 0.6em; border: 1px solid #ccc; border-radius: 6px; }

/* small screens */
@media (max-width: 720px) {
  .wells-grid { grid-template-columns: repeat(4, 1fr); }
  .well-cell img { height: 90px; }
}
