:root {
  --brand-navy: #1a2744;
  --brand-red: #e31837;
  --brand-white: #ffffff;
  --brand-gray: #f5f5f5;
  --text-dark: #222222;
  --text-muted: #777777;
  --tile-height: 160px;
  --tap-min: 56px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--brand-gray);
  color: var(--text-dark);
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  height: 100vh;
  height: 100dvh;
}

/* App layout wrapper */
body {
  display: flex;
  flex-direction: column;
}

/* Login */
.login-body {
  background: var(--brand-navy);
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 24px;
}
.login-container {
  width: 100%;
  max-width: 420px;
}
.login-brand {
  text-align: center;
  margin-bottom: 32px;
}
.login-logo {
  font-size: 64px;
  font-weight: 900;
  color: var(--brand-white);
  letter-spacing: 2px;
}
.login-subtitle {
  font-size: 18px;
  color: rgba(255,255,255,0.7);
  margin-top: 4px;
}
.login-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.login-error {
  background: var(--brand-red);
  color: #fff;
  padding: 12px 16px;
  border-radius: 8px;
  font-size: 15px;
  text-align: center;
}
.login-label {
  color: rgba(255,255,255,0.85);
  font-size: 15px;
  font-weight: 600;
}
.login-input {
  height: var(--tap-min);
  padding: 0 16px;
  font-size: 18px;
  border: none;
  border-radius: 8px;
  background: rgba(255,255,255,0.1);
  color: #fff;
  outline: none;
}
.login-input::placeholder { color: rgba(255,255,255,0.4); }
.login-button {
  height: var(--tap-min);
  font-size: 18px;
  font-weight: 700;
  border: none;
  border-radius: 8px;
  background: var(--brand-red);
  color: #fff;
  cursor: pointer;
  margin-top: 8px;
}

/* Header */
.app-header {
  background: var(--brand-navy);
  color: #fff;
  padding: 16px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-shrink: 0;
  z-index: 10;
}
.app-header h1 {
  font-size: 20px;
  font-weight: 700;
}
.header-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}
.user-name {
  font-size: 15px;
  opacity: 0.9;
}
.btn-logout {
  background: var(--brand-red);
  color: #fff;
  text-decoration: none;
  padding: 8px 16px;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 600;
  min-height: 36px;
  display: inline-flex;
  align-items: center;
}
.back-arrow {
  color: #fff;
  text-decoration: none;
  font-size: 24px;
  margin-right: 8px;
  min-width: 44px;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* Sub-header */
.sub-header {
  padding: 12px 20px;
  font-size: 16px;
  font-weight: 600;
  color: var(--text-muted);
  background: #fff;
  border-bottom: 1px solid #e0e0e0;
  flex-shrink: 0;
}

/* Home tiles */
.home-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  padding: 20px;
  max-width: 900px;
  margin: 0 auto;
}
.tile {
  background: #fff;
  border-radius: 16px;
  padding: 20px;
  min-height: var(--tile-height);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
  text-decoration: none;
  position: relative;
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
  transition: transform 0.1s ease, box-shadow 0.1s ease;
}
.tile-active { cursor: pointer; }
.tile-disabled {
  opacity: 0.45;
  pointer-events: none;
  background: #eee;
}
.tile-wide {
  grid-column: 1 / -1;
  background: var(--brand-navy);
  color: #fff;
}
.tile-code {
  font-size: 32px;
  font-weight: 900;
  line-height: 1;
}
.tile-name {
  font-size: 15px;
  margin-top: 6px;
  color: var(--text-muted);
}
.tile-wide .tile-name { color: rgba(255,255,255,0.75); }
.tile-meta {
  font-size: 14px;
  margin-top: 10px;
  color: var(--text-muted);
  font-weight: 600;
}
.tile-wide .tile-meta { color: rgba(255,255,255,0.7); }
.badge {
  position: absolute;
  top: 12px;
  right: 12px;
  font-size: 11px;
  font-weight: 700;
  padding: 4px 8px;
  border-radius: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.badge-prototype {
  background: var(--brand-red);
  color: #fff;
}
.badge-soon {
  background: #999;
  color: #fff;
}

/* Bench grid */
.bench-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 12px;
  padding: 20px;
  max-width: 900px;
  margin: 0 auto;
}
.bench-tile {
  background: #fff;
  border-radius: 12px;
  padding: 14px 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.05);
  cursor: pointer;
  transition: transform 0.1s ease;
}
.bench-number {
  font-size: 28px;
  font-weight: 800;
  line-height: 1;
}
.bench-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  margin: 8px 0;
  background: #ccc;
}
.bench-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  color: var(--text-muted);
  text-align: center;
}

/* State colours */
.bench-tile[data-state="INTAKE"] .bench-dot { background: #2196f3; }
.bench-tile[data-state="AWAITING_MANUAL_INPUTS"] .bench-dot { background: #ff9800; }
.bench-tile[data-state="AWAITING_ROOT_CAUSE"] .bench-dot { background: #9c27b0; }
.bench-tile[data-state="AWAITING_SOLUTIONS_ENTRY"] .bench-dot { background: #ffc107; }
.bench-tile[data-state="RECOMMENDATIONS_SENT"] .bench-dot { background: #009688; }
.bench-tile[data-state="CALLBACKS"] .bench-dot { background: #607d8b; }
.bench-tile[data-state="WORK_IN_PROGRESS"] .bench-dot { background: #4caf50; }
.bench-tile[data-state="AWAITING_CLEANUP"] .bench-dot { background: #8bc34a; }
.bench-tile[data-state="CLOSED"] .bench-dot { background: #388e3c; }
.bench-tile[data-state="EMPTY"] .bench-dot { background: #e0e0e0; }

/* Legend */
.legend {
  max-width: 900px;
  margin: 0 auto 40px;
  padding: 0 20px;
}
.legend h3 {
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  margin-bottom: 12px;
}
.legend-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 8px;
}
.legend-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-dark);
}
.legend-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* Queue empty state */
.queue-main {
  max-width: 900px;
  margin: 0 auto;
  padding: 40px 20px;
}
.empty-state {
  text-align: center;
  padding: 60px 20px;
}
.empty-icon {
  font-size: 64px;
  opacity: 0.25;
  margin-bottom: 16px;
}
.empty-text {
  font-size: 18px;
  color: var(--text-muted);
}

/* ---- Drawer ---- */
.drawer-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 50;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}
.drawer-overlay.open {
  opacity: 1;
  pointer-events: auto;
}
.drawer-panel {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 380px;
  max-width: 100%;
  background: #fff;
  z-index: 51;
  transform: translateX(100%);
  transition: transform 0.25s ease;
  display: flex;
  flex-direction: column;
  box-shadow: -4px 0 24px rgba(0,0,0,0.15);
}
.drawer-panel.open {
  transform: translateX(0);
}
.drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid #e0e0e0;
  background: var(--brand-navy);
  color: #fff;
}
.drawer-header h2 {
  font-size: 18px;
  font-weight: 700;
}
.drawer-close {
  background: none;
  border: none;
  color: #fff;
  font-size: 28px;
  cursor: pointer;
  min-width: 44px;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.drawer-body {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
}
.drawer-section {
  margin-bottom: 20px;
}
.drawer-section label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.4px;
  margin-bottom: 6px;
}
.drawer-section .value {
  font-size: 16px;
  color: var(--text-dark);
  word-break: break-word;
}
.state-badge {
  display: inline-block;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 6px 12px;
  border-radius: 20px;
  color: #fff;
}
.state-badge.INTAKE { background: #2196f3; }
.state-badge.AWAITING_MANUAL_INPUTS { background: #ff9800; }
.state-badge.AWAITING_ROOT_CAUSE { background: #9c27b0; }
.state-badge.AWAITING_SOLUTIONS_ENTRY { background: #ffc107; }
.state-badge.RECOMMENDATIONS_SENT { background: #009688; }
.state-badge.CALLBACKS { background: #607d8b; }
.state-badge.WORK_IN_PROGRESS { background: #4caf50; }
.state-badge.AWAITING_CLEANUP { background: #8bc34a; }
.state-badge.CLOSED { background: #388e3c; }

.drawer-actions {
  padding: 16px 20px;
  border-top: 1px solid #e0e0e0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  padding: 0 20px;
  font-size: 16px;
  font-weight: 700;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  text-decoration: none;
}
.btn-primary { background: var(--brand-navy); color: #fff; }
.btn-secondary { background: #e0e0e0; color: var(--text-dark); }
.btn-success { background: #4caf50; color: #fff; }
.btn-danger { background: var(--brand-red); color: #fff; }

/* Forms inside drawer */
.form-group {
  margin-bottom: 14px;
}
.form-group label {
  display: block;
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 6px;
}
.form-input, .form-textarea {
  width: 100%;
  min-height: 48px;
  padding: 10px 14px;
  font-size: 16px;
  border: 1px solid #ccc;
  border-radius: 10px;
  outline: none;
}
.form-input:focus, .form-textarea:focus { border-color: var(--brand-navy); }
.form-textarea { min-height: 90px; resize: vertical; }

/* PSU form */
.psu-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}
.psu-row label {
  flex: 1;
  font-size: 15px;
  font-weight: 600;
}
.psu-row input {
  width: 110px;
  min-height: 44px;
  padding: 8px 12px;
  font-size: 16px;
  border: 2px solid #ccc;
  border-radius: 8px;
  text-align: right;
}
.psu-row input.psu-pass { border-color: #4caf50; background: #e8f5e9; }
.psu-row input.psu-fail { border-color: var(--brand-red); background: #ffebee; }
.psu-threshold {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* Recommendations list */
.rec-list {
  max-width: 900px;
  margin: 0 auto;
  padding: 20px;
}
.rec-card {
  background: #fff;
  border-radius: 12px;
  padding: 16px 18px;
  margin-bottom: 12px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.05);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  transition: transform 0.1s ease;
}
.rec-card:active { transform: scale(0.98); }
.rec-info { flex: 1; }
.rec-title {
  font-size: 16px;
  font-weight: 700;
  margin-bottom: 4px;
}
.rec-meta {
  font-size: 14px;
  color: var(--text-muted);
}
.rec-detail-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 60;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}
.rec-detail-overlay.open {
  opacity: 1;
  pointer-events: auto;
}
.rec-detail-panel {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 420px;
  max-width: 100%;
  background: #fff;
  z-index: 61;
  transform: translateX(100%);
  transition: transform 0.25s ease;
  display: flex;
  flex-direction: column;
  box-shadow: -4px 0 24px rgba(0,0,0,0.15);
}
.rec-detail-panel.open {
  transform: translateX(0);
}
.rec-detail-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid #e0e0e0;
  background: var(--brand-navy);
  color: #fff;
}
.rec-detail-header h2 { font-size: 18px; font-weight: 700; }
.rec-detail-body {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
}
pre.json-block {
  background: #f5f5f5;
  padding: 14px;
  border-radius: 10px;
  font-size: 13px;
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-word;
}

/* Responsive */
@media (max-width: 600px) {
  .home-grid { grid-template-columns: 1fr; }
  .bench-grid { grid-template-columns: repeat(3, 1fr); }
}
@media (min-width: 768px) and (max-width: 1200px) {
  body { font-size: 16px; }
  .bench-grid { grid-template-columns: repeat(5, 1fr); }
}
@media (max-width: 480px) {
  .drawer-panel { width: 100%; }
  .rec-detail-panel { width: 100%; }
}

/* --------------------------------------------------------------------------
   LSC Bench Map — additions / overrides
   -------------------------------------------------------------------------- */

/* Bench map container */
.bench-map {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  flex: 1;
  min-height: 0;
  padding: 16px;
  max-width: 1100px;
  margin: 0 auto;
  width: 100%;
}

/* Each physical row */
.bench-row {
  display: grid;
  gap: 10px;
}

/* Top row: 13 benches */
#top-row {
  grid-template-columns: repeat(auto-fit, minmax(64px, 1fr));
}

/* Bottom row: 7 benches */
#bottom-row {
  grid-template-columns: repeat(auto-fit, minmax(64px, 1fr));
}

/* Bench tile (override base) */
.bench-tile {
  background: #fff;
  border-radius: 12px;
  padding: 10px 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 72px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.05);
  cursor: pointer;
  transition: transform 0.1s ease, box-shadow 0.15s ease;
  position: relative;
  border: 2px solid transparent;
}

.bench-tile:active {
  transform: scale(0.96);
}

.bench-number {
  font-size: 22px;
  font-weight: 800;
  line-height: 1;
}

.bench-special {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--brand-red);
  margin-top: 2px;
}

.bench-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  margin: 6px 0;
  background: #ccc;
}

.bench-label {
  font-size: 9px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  color: var(--text-muted);
  text-align: center;
  line-height: 1.2;
}

/* State colours via CSS classes (used by JS for border tint) */
.bench-tile.state-idle                     { border-color: #9e9e9e; }
.bench-tile.state-intake-running           { border-color: #2196f3; }
.bench-tile.state-intake-complete          { border-color: #90caf9; }
.bench-tile.state-findings-ready           { border-color: #ffc107; }
.bench-tile.state-recommendations-ready    { border-color: #ff9800; }
.bench-tile.state-resolved                 { border-color: #4caf50; }

/* Pulsing animation for intake_running */
@keyframes pulse-blue {
  0%   { box-shadow: 0 0 0 0 rgba(33, 150, 243, 0.45); }
  70%  { box-shadow: 0 0 0 10px rgba(33, 150, 243, 0); }
  100% { box-shadow: 0 0 0 0 rgba(33, 150, 243, 0); }
}

.bench-tile[data-state="intake_running"],
.bench-tile[data-state="INTAKE"] {
  animation: pulse-blue 2s infinite;
}
/* Pulsing animation for intake_failed (error/stuck) */
@keyframes pulse-red {
  0%, 100% { box-shadow: 0 0 0 0 rgba(244,67,54,0.6); border-color: #f44336; }
  50%       { box-shadow: 0 0 0 8px rgba(244,67,54,0); border-color: #b71c1c; }
}
.bench-tile.state-intake-failed {
  border-color: #f44336;
  animation: pulse-red 1.4s infinite;
}


/* Drawer header tweaks */
.drawer-title-wrap {
  flex: 1;
}
.drawer-title-wrap h2 {
  font-size: 18px;
  font-weight: 700;
  margin: 0;
}
.drawer-subtitle {
  font-size: 12px;
  opacity: 0.75;
  margin-top: 2px;
}

/* Legend inside bench-map (compact strip) */
.bench-map .legend {
  margin: 12px auto 0;
  padding: 0;
  max-width: 100%;
}
.bench-map .legend h3 {
  display: none;
}
.bench-map .legend-grid {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px 16px;
}
.bench-map .legend-item {
  font-size: 12px;
}
.bench-map .legend-dot {
  width: 10px;
  height: 10px;
}

/* SI tag input in idle drawer */
.si-tag-input {
  width: 100%;
  height: 48px;
  padding: 0 14px;
  font-size: 18px;
  border: 2px solid #ccc;
  border-radius: 10px;
  outline: none;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
.si-tag-input:focus {
  border-color: var(--brand-navy);
}
.si-tag-input.shake {
  animation: shake-input 0.4s ease;
  border-color: var(--brand-red);
  box-shadow: 0 0 0 3px rgba(227, 24, 55, 0.15);
}

@keyframes shake-input {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-6px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(4px); }
}

/* Responsive: tablet portrait and below */
@media (max-width: 768px) {
  #top-row {
    grid-template-columns: repeat(auto-fill, minmax(60px, 1fr));
  }
  #bottom-row {
    grid-template-columns: repeat(auto-fill, minmax(72px, 1fr));
  }
  .bench-tile {
    min-height: 64px;
    padding: 8px 2px;
  }
  .bench-number {
    font-size: 18px;
  }
  .bench-label {
    font-size: 8px;
  }
}

@media (max-width: 480px) {
  .bench-map {
    padding: 10px;
  }
  .bench-tile {
    min-height: 56px;
  }
  .bench-number {
    font-size: 16px;
  }
  .bench-dot {
    width: 10px;
    height: 10px;
    margin: 4px 0;
  }
}

/* ── Intake progress section ─────────────────────────────────────────────── */
.intake-progress-section {
  margin: 12px 0 8px;
  border-top: 1px solid #e0e0e0;
  padding-top: 10px;
}

.progress-title {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #555;
  margin-bottom: 8px;
}

.progress-list {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 200px;
  overflow-y: auto;
}

.progress-item {
  font-size: 12px;
  font-family: monospace;
  color: #333;
  padding: 3px 0;
  border-bottom: 1px solid #f0f0f0;
  line-height: 1.4;
}

.progress-waiting {
  font-size: 12px;
  color: #888;
  font-style: italic;
  padding: 4px 0;
}

.progress-stale {
  margin-top: 8px;
  font-size: 12px;
  color: #e65100;
  background: #fff3e0;
  border-radius: 4px;
  padding: 6px 8px;
}
/* ── Prescan Diagnostics section ─────────────────────────────────────────── */
.diag-section {
  margin-top: 16px;
  border-top: 2px solid #1a2744;
  padding-top: 12px;
}

.diag-heading {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #1a2744;
  margin-bottom: 10px;
}

.diag-card {
  background: #f8f9fb;
  border: 1px solid #e0e3ea;
  border-radius: 8px;
  padding: 10px 12px;
  margin-bottom: 8px;
}

.diag-card-warn {
  background: #fff8f0;
  border-color: #ffcc80;
}

.diag-card-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #555;
  margin-bottom: 8px;
}

.diag-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  font-size: 13px;
  padding: 3px 0;
  border-bottom: 1px solid #eee;
  flex-wrap: wrap;
}

.diag-row:last-child {
  border-bottom: none;
}

.diag-label {
  color: #666;
  flex: 0 0 110px;
  font-size: 12px;
}

.diag-value {
  color: #222;
  flex: 1;
  word-break: break-word;
}

.diag-hard-stop {
  color: #c62828;
  font-weight: 700;
  font-size: 13px;
}

.diag-chip {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 600;
}

.diag-ok {
  background: #e8f5e9;
  color: #2e7d32;
  border: 1px solid #a5d6a7;
}

.diag-warn {
  background: #fff8e1;
  color: #e65100;
  border: 1px solid #ffcc80;
}

.diag-info {
  background: #e3f2fd;
  color: #1565c0;
  border: 1px solid #90caf9;
}
/* Storage drive block */
.diag-drive-block { border-bottom: 1px solid #e0e0e0; padding-bottom: 10px; margin-bottom: 10px; }
.diag-drive-block:last-child { border-bottom: none; margin-bottom: 0; }
.diag-warn-text { color: #e53935; font-weight: 600; }
