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

:root {
  /* reizdarmSOS CI green */
  --primary: #6cceb9;
  --primary-dark: #45b39b;
  --primary-soft: #e4f8f3;
  --secondary: #6c757d;
  --danger: #dc3545;
  --success: #45b39b;
  --warning: #ffc107;
  --light: #f8f9fa;
  --dark: #2c3a36;
  --border: #dee2e6;
  --text: #333;
  --error: #dc3545;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
    'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif;
  line-height: 1.5;
  color: var(--text);
  background: #f5f7fa;
}

/* === SCREENS === */

.screen {
  display: none;
}

.screen.visible {
  display: block;
}

/* === LOGIN SCREEN === */

#login-screen.visible {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #6cceb9 0%, #45b39b 100%);
}

.login-container {
  background: white;
  padding: 3rem;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  width: 100%;
  max-width: 400px;
}

.login-container h1 {
  font-size: 1.8rem;
  color: var(--primary);
  margin-bottom: 0.5rem;
}

.login-container .subtitle {
  font-size: 0.9rem;
  color: var(--secondary);
  margin-bottom: 2rem;
}

/* === NAVBAR === */

.navbar {
  background: white;
  border-bottom: 1px solid var(--border);
  padding: 1rem 2rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.navbar h1.nav-home { cursor: pointer; }

.navbar h1 {
  font-size: 1.3rem;
  color: var(--primary);
}

.nav-right {
  display: flex;
  align-items: center;
  gap: 1.5rem;
}

#user-display {
  color: var(--secondary);
  font-size: 0.9rem;
}

/* === MAIN APP CONTAINER === */

.container {
  max-width: 1000px;
  margin: 2rem auto;
  padding: 0 2rem;
}

.content-section {
  display: none;
  background: white;
  border-radius: 8px;
  padding: 2rem;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.content-section.visible {
  display: block;
}

.content-section h2 {
  font-size: 1.5rem;
  margin-bottom: 1.5rem;
  color: var(--dark);
}

/* === FORMS === */

.form-group {
  margin-bottom: 1.5rem;
}

.form-group label {
  display: block;
  font-weight: 600;
  margin-bottom: 0.5rem;
  color: var(--dark);
}

.form-group input[type='text'],
.form-group input[type='password'],
.form-group input[type='number'] {
  width: 100%;
  padding: 0.75rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 1rem;
  transition: border-color 0.2s;
}

.form-group input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(108, 206, 185, 0.3);
}

/* === BUTTONS === */

.btn {
  padding: 0.75rem 1.5rem;
  border: none;
  border-radius: 4px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-primary {
  background: var(--primary);
  color: white;
}

.btn-primary:hover {
  background: var(--primary-dark);
}

.btn-secondary {
  background: var(--secondary);
  color: white;
}

.btn-secondary:hover {
  background: #5a6268;
}

.btn-danger {
  background: var(--danger);
  color: white;
}

.btn-danger:hover {
  background: #c82333;
}

.btn-small {
  padding: 0.5rem 1rem;
  font-size: 0.9rem;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-outline {
  background: white;
  color: var(--primary-dark);
  border: 1px solid var(--primary);
}

.btn-outline:hover {
  background: var(--primary-soft);
}

.button-group {
  display: flex;
  gap: 1rem;
  margin-top: 2rem;
}

.button-group button {
  flex: 1;
}

/* === GRIDS === */

.entry-grid,
.review-grid,
.approval-grid {
  margin: 2rem 0;
  overflow-x: auto;
}

.grid-table {
  width: 100%;
  border-collapse: collapse;
  background: white;
}

.grid-table th,
.grid-table td {
  padding: 0.75rem;
  text-align: left;
  border: 1px solid var(--border);
}

.grid-table th {
  background: var(--light);
  font-weight: 600;
  color: var(--dark);
}

.grid-table tr:hover {
  background: #f9f9f9;
}

.grid-table input {
  width: 100%;
  padding: 0.4rem 0.3rem;
  border: 1px solid var(--border);
  border-radius: 3px;
  font-size: 1.15rem;
  font-weight: 600;
  text-align: center;
  color: var(--dark);
  font-variant-numeric: tabular-nums;
}

.grid-table input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(108, 206, 185, 0.3);
}

/* Tighter measurement cells so the larger numbers dominate the row. */
.entry-grid .grid-table td {
  padding: 0.5rem 0.4rem;
}

.corr-value {
  font-size: 0.9rem;
  color: var(--secondary);
}

/* Tube-number column (first column) emphasised in the entry grid. */
#entry-grid tbody td:first-child {
  color: var(--dark);
}
#entry-grid .tube-no { font-weight: 700; }

.corr-warning {
  color: var(--danger);
  font-weight: 600;
}

.grid-table input.input-invalid {
  border-color: var(--danger);
  background: #fff5f5;
  color: var(--danger);
}

.input-hint {
  font-size: 0.72rem;
  color: var(--danger);
  margin-top: 2px;
  line-height: 1.2;
  min-height: 0;
}

/* === MESSAGES === */

.error-message {
  color: var(--error);
  background: #f8d7da;
  padding: 1rem;
  border-radius: 4px;
  margin: 1rem 0;
  display: none;
}

.error-message.show {
  display: block;
}

.warnings {
  background: #fff3cd;
  border-left: 4px solid var(--warning);
  padding: 1rem;
  margin: 1rem 0;
  border-radius: 4px;
  display: none;
}

.warnings.show {
  display: block;
}

.warnings ul {
  margin-left: 1.5rem;
  list-style: disc;
}

.warnings li {
  margin-bottom: 0.5rem;
}

.intake-warning {
  font-weight: 600;
}

.autosave-status {
  font-size: 0.82rem;
  color: var(--secondary);
  min-height: 1.2em;
  margin: 0.25rem 0 0.5rem;
}

.autosave-status.saved { color: var(--success); }
.autosave-status.saving { color: var(--secondary); }
.autosave-status.failed { color: var(--danger); font-weight: 600; }

.danger-zone {
  margin-top: 1.5rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
  text-align: right;
}

/* Armed = first click registered, waiting for the confirming second click
   (see app.js delete-order-btn). Strong pulse so it reads as "this is now a
   different, more dangerous action" rather than a random restyle. */
#delete-order-btn.armed {
  background: #a71d2a;
  animation: delete-armed-pulse 0.8s ease-in-out infinite;
}

@keyframes delete-armed-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(167, 29, 42, 0.55); }
  50% { box-shadow: 0 0 0 6px rgba(167, 29, 42, 0); }
}

/* === ORDER HEADER === */

.order-header {
  background: var(--light);
  padding: 1rem;
  border-radius: 4px;
  margin-bottom: 1.5rem;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 1rem;
}

.order-header div {
  font-size: 0.95rem;
}

.order-header strong {
  color: var(--dark);
}

/* Entry + approval screens: the four items in one row */
#entry-screen .order-header,
#approval-screen .order-header {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

/* === CONFIRM TEXT === */

.confirm-text {
  background: #e7f3ff;
  border-left: 4px solid var(--primary);
  padding: 1rem;
  margin: 1.5rem 0;
  border-radius: 4px;
  color: var(--dark);
}

/* === EVAL RESULT === */

.eval-result {
  background: var(--light);
  padding: 1.5rem;
  border-radius: 4px;
  margin: 1.5rem 0;
  border-left: 4px solid var(--success);
}

.eval-result.show {
  display: block;
}

.eval-result h3 {
  color: var(--dark);
  margin-bottom: 0.5rem;
}

.eval-result p {
  color: var(--secondary);
  font-size: 0.95rem;
}

.eval-interp {
  color: var(--dark) !important;
  font-weight: 600;
  font-size: 1.05rem !important;
  margin-bottom: 0.75rem;
}

.eval-metrics {
  display: flex;
  flex-wrap: wrap;
  gap: 1.5rem;
  font-size: 0.95rem;
  color: var(--dark);
}

.eval-flags {
  margin-top: 0.75rem;
  color: #8a6d00;
  font-size: 0.9rem;
}

/* Clinical context / QC — intentionally NOT green, to read as context, not verdict. */
.clinical-context {
  display: none;
  background: #f4f6f8;
  border-left: 4px solid var(--secondary);
  padding: 1.25rem 1.5rem;
  border-radius: 4px;
  margin: 1rem 0 1.5rem;
}

.clinical-context.show {
  display: block;
}

.clinical-context h3 {
  color: var(--dark);
  font-size: 1rem;
  margin-bottom: 0.5rem;
}

.clinical-context ul {
  margin-left: 1.2rem;
  list-style: disc;
}

.clinical-context li {
  margin-bottom: 0.35rem;
  color: #444;
  font-size: 0.95rem;
}

/* === EVAL CRITERION === */

.eval-criterion {
  font-size: 0.82rem;
  color: var(--secondary);
  font-style: italic;
  margin-bottom: 0.75rem;
}

/* === SYMPTOM BLOCK === */

.symptom-block {
  background: #f9fbfc;
  border-left: 4px solid var(--border);
  padding: 1.25rem 1.5rem;
  border-radius: 4px;
  margin: 1rem 0 1.5rem;
}

.symptom-block h3 {
  color: var(--dark);
  font-size: 1rem;
  margin-bottom: 0.75rem;
}

.symptom-group {
  margin-bottom: 0.6rem;
}

.symptom-group-label {
  font-weight: 600;
  font-size: 0.78rem;
  color: var(--secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.3rem;
}

.symptom-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.symptom-chip {
  background: var(--primary-soft);
  color: var(--dark);
  border-radius: 12px;
  padding: 0.2rem 0.65rem;
  font-size: 0.85rem;
}

.symptom-chip.with-time {
  background: #e8f4ff;
}

.no-symptoms-text {
  font-size: 0.9rem;
  color: var(--secondary);
}

/* === LANGUAGE SWITCH === */

.lang-switch {
  display: inline-flex;
  gap: 2px;
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
}

.lang-btn {
  border: none;
  background: white;
  color: var(--secondary);
  font-size: 0.8rem;
  font-weight: 600;
  padding: 0.3rem 0.6rem;
  cursor: pointer;
  transition: all 0.15s;
}

.lang-btn:hover {
  background: var(--primary-soft);
}

.lang-btn.active {
  background: var(--primary);
  color: white;
}

#login-screen .lang-switch {
  position: absolute;
  top: 1rem;
  right: 1rem;
}

.login-container {
  position: relative;
}

/* === REVIEW LIST === */

.review-list-block {
  margin-top: 2.5rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
}

.review-list-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}

.review-list-head h3 {
  font-size: 1.15rem;
  color: var(--dark);
}

.worklist-tabs {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.tab-btn {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  padding: 0.5rem 0.25rem;
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--secondary);
  cursor: pointer;
}

.tab-btn:hover {
  color: var(--dark);
}

.tab-btn.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

/* Pushes the refresh button to the row's right edge, after the two tabs. */
.worklist-tabs #refresh-review-btn {
  margin-left: auto;
}

.worklist-panel[hidden] {
  display: none;
}

.review-list-empty {
  color: var(--secondary);
  font-size: 0.95rem;
  padding: 0.5rem 0;
}

.review-table td:last-child,
.review-table th:last-child {
  text-align: right;
  width: 1%;
  white-space: nowrap;
}

/* === RESPONSIVE === */

@media (max-width: 768px) {
  .navbar {
    flex-direction: column;
    gap: 1rem;
  }

  .container {
    padding: 0 1rem;
  }

  .content-section {
    padding: 1.5rem;
  }

  .button-group {
    flex-direction: column;
  }

  .order-header,
  #entry-screen .order-header,
  #approval-screen .order-header {
    grid-template-columns: 1fr;
  }

  .grid-table {
    font-size: 0.9rem;
  }

  .grid-table th,
  .grid-table td {
    padding: 0.5rem;
  }
}

/* === TOAST NOTIFICATION === */

#app-toast {
  position: fixed;
  bottom: 2rem;
  left: 50%;
  transform: translateX(-50%) translateY(120%);
  background: var(--dark);
  color: white;
  padding: 0.75rem 1.5rem;
  border-radius: 6px;
  font-size: 0.95rem;
  box-shadow: 0 4px 12px rgba(0,0,0,0.2);
  transition: transform 0.25s ease, opacity 0.25s ease;
  opacity: 0;
  z-index: 9999;
  max-width: 90vw;
  text-align: center;
  pointer-events: none;
}

#app-toast.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

#app-toast.toast-success { background: var(--success); }
#app-toast.toast-info    { background: var(--secondary); }

/* === LOADING STATE === */

.loading {
  opacity: 0.6;
  pointer-events: none;
}

.spinner {
  display: inline-block;
  width: 1rem;
  height: 1rem;
  border: 2px solid var(--light);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* === BEFUND PREVIEW (approval screen) === */
.befund-preview { margin: 1.5rem 0; }
.befund-preview-status { color: var(--gray, #6b7280); font-size: 0.95rem; margin-bottom: 0.5rem; }
.befund-preview-status:empty { display: none; }
.befund-preview-wrap {
  width: 100%;               /* same width as the box above; the A4 page is scaled to fit */
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: 0 1px 6px rgba(0, 0, 0, 0.08);
  background: #f5f7fa;
}
.befund-preview-frame {
  display: block;
  width: 794px;
  height: 1123px;
  border: 0;
  transform-origin: top left;
}

/* === ENTRY GUARDS: read-back of the tube just entered === */
/* Table left, read-back panel right (sticky, so it stays visible while the table scrolls). */
.entry-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.45fr) minmax(0, 1fr);
  gap: 1.2rem;
  align-items: start;
}
.entry-layout .entry-grid { margin: 1rem 0; }
.readback {
  position: sticky;
  top: 1rem;
  margin: 1rem 0;
  padding: 0.9rem 1.1rem;
  min-height: 11.5rem;
  background: var(--light);
  border: 1px dashed var(--border);
  border-radius: 6px;
}
.readback.active {
  background: #fff;
  border: 2px solid var(--primary);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.12);
}
.readback-placeholder { color: var(--secondary); font-size: 0.95rem; line-height: 1.5; }
.rb-title { font-weight: 700; color: var(--dark); margin-bottom: 0.5rem; }
.rb-values { display: flex; gap: 0.6rem; margin-bottom: 0.5rem; }
.rb-box {
  flex: 1 1 0;
  min-width: 0;
  text-align: center;
  padding: 0.4rem 0.3rem;
  border: 2px solid var(--border);
  border-radius: 6px;
  background: var(--light);
}
.rb-box.flagged { border-color: #e08a00; background: #fff6e5; }
.rb-gas { font-size: 0.9rem; color: var(--secondary); font-weight: 600; }
.rb-val { font-size: 2.3rem; font-weight: 800; line-height: 1.1; color: var(--dark); font-variant-numeric: tabular-nums; }
.rb-unit { font-size: 0.85rem; color: var(--secondary); }
.rb-note { color: #8a5a00; font-weight: 600; margin-bottom: 0.4rem; }
.rb-warn { margin: 0 0 0.5rem 1.1rem; padding: 0; color: #8a5a00; font-weight: 600; font-size: 0.9rem; }
.rb-controls { display: flex; gap: 0.8rem; flex-wrap: wrap; margin-bottom: 0.5rem; }
.rb-control { display: flex; flex-direction: column; font-size: 0.85rem; font-weight: 600; color: var(--dark); }
.rb-control input {
  margin-top: 0.25rem; padding: 0.4rem; font-size: 1.4rem; font-weight: 700; width: 8rem;
  border: 2px solid #e08a00; border-radius: 4px; text-align: center;
}
.rb-error { color: var(--danger); font-weight: 600; min-height: 1.2rem; font-size: 0.9rem; }
.rb-actions { display: flex; gap: 0.6rem; flex-wrap: wrap; }

@media (max-width: 900px) {
  .entry-layout { grid-template-columns: 1fr; }
  .readback { position: static; }
}

/* confirmed tubes in the entry grid */
#entry-grid tr.tube-confirmed td { background: #f1fbf6; }
.tube-check { color: #1e8e5a; font-weight: 800; margin-left: 0.35rem; }
.tube-min { font-weight: 400; color: var(--secondary); font-size: 0.85rem; white-space: nowrap; }  /* "(120 min)" never wraps; the column widens instead */

/* review chart */
.review-chart { margin: 1rem 0; }
.review-chart h3 { font-size: 1rem; color: var(--dark); margin-bottom: 0.3rem; }
.review-chart svg { width: 100%; max-width: 640px; height: auto; display: block; }

/* "TEST" badge next to the logo (shown when APP_ENV=test) */
.nav-left { display: flex; align-items: center; gap: 0.6rem; }
.env-badge { background: #d9534f; color: #fff; font-size: 0.7rem; font-weight: 700; letter-spacing: 0.08em; padding: 0.15rem 0.5rem; border-radius: 4px; }
