/* ============================================================
   Base — resets, body, buttons, toast, empty-states, scrollbars.
   ============================================================ */

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }

/* Screen-reader-only utility — visually hidden, exposed to AT.
   Used for the #a11y-live region (announces hire/fire/praise outcomes
   without painting them anywhere) and for hidden mood-breakdown text
   that aria-describedby points at on the staff mood row. */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}
body {
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--bg-deep);
  color: var(--text);
  font-size: var(--fs-md);
  line-height: var(--lh-base);
  overflow: hidden;
}

/* ---------- prefers-reduced-motion ---------- */
/* Quiet the infinite ambient loops (postit sway, machine breathe,
   tumbleweed, instrument scroll, etc.) and shorten all non-signal
   transitions for motion-sensitive users. Gameplay-signal animations
   (.signal-anim opt-out class) keep most of their identity — they're
   how the game communicates, not decoration. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
  /* Opt-outs: signal animations the game RELIES on to communicate.
     Day-flash, install seat-drop, test-pass burst, achievement banner,
     and level-up curtain all carry .signal-anim so they remain
     readable (shortened, but not killed). */
  .signal-anim,
  .signal-anim::before,
  .signal-anim::after {
    animation-duration: var(--reduced-signal-dur, 280ms) !important;
    transition-duration: var(--reduced-signal-dur, 280ms) !important;
  }
}

/* ---------- buttons ---------- */
button {
  font-family: inherit;
  font-size: var(--fs-md);
  cursor: pointer;
  border: none;
  border-radius: var(--r-sm);
  padding: var(--sp-2) var(--sp-3);
  transition: transform var(--dur-fast) var(--ease),
              background var(--dur-fast) var(--ease),
              box-shadow var(--dur-fast) var(--ease);
}
button:disabled { opacity: 0.4; cursor: not-allowed; }
/* Phase 2 P2.6 — tactile press depth on every button. Adds a small
   downward shift + scale + inner shadow so every click reads as a
   physical press. Replaces the bare 1px translate that was there. */
button:not(:disabled):active {
  transform: translateY(1px) scale(0.97);
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.25);
}
button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  box-shadow: var(--sh-focus);
}

/* Phase 2 P2.7 — deny-flash on failed actions. Toast helper adds
   this class to the source button for 280ms; a red border tint +
   inset shadow signals the action was rejected. Pairs with the
   .shake class for horizontal jitter. */
.deny-flash {
  animation: denyFlash 280ms ease-out;
}
@keyframes denyFlash {
  0%   { box-shadow: inset 0 0 0 0 rgba(232,80,58,0); }
  40%  { box-shadow: inset 0 0 0 2px rgba(232,80,58,0.65),
                     0 0 12px rgba(232,80,58,0.35); }
  100% { box-shadow: inset 0 0 0 0 rgba(232,80,58,0); }
}

/* Hover hint — a pulsing glow that links an inventory part to the machine
   slot it fits (and vice versa). Toggled by hover handlers in ui.js /
   repair.js; works on both the diagram part-card and the sidebar part-chip. */
@keyframes fitGlowPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(79, 195, 247, 0); }
  50%      { box-shadow: 0 0 0 4px rgba(79, 195, 247, 0.55); }
}
.fit-glow {
  animation: fitGlowPulse 1s ease-in-out infinite;
  position: relative;
  z-index: 5;
}

.btn-primary, button.primary {
  background: linear-gradient(180deg, var(--accent), var(--accent-2));
  color: var(--on-accent);
  font-weight: var(--fw-bold);
}
.btn-primary:hover:not(:disabled), button.primary:hover:not(:disabled) {
  background: linear-gradient(180deg, var(--accent-hover), var(--accent));
}
.btn-secondary {
  background: var(--bg-card);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-secondary:hover:not(:disabled) {
  background: var(--bg-card-hover);
  border-color: var(--border-strong);
}
.btn-danger {
  background: var(--bad);
  color: white;
  font-weight: var(--fw-bold);
}
.btn-danger:hover:not(:disabled) {
  background: var(--bad);
  filter: brightness(1.12);
}
.btn-danger.armed {
  background: #ff5252;
  animation: scrap-armed-pulse 0.8s ease-in-out infinite;
}
@keyframes scrap-armed-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255, 82, 82, 0.6); }
  50%      { box-shadow: 0 0 0 6px rgba(255, 82, 82, 0); }
}
.btn-small {
  padding: var(--sp-1) var(--sp-3);
  font-size: var(--fs-sm);
  background: var(--accent);
  color: var(--on-accent);
  font-weight: var(--fw-semi);
}
.btn-small:hover:not(:disabled) { background: var(--accent-hover); }

/* ---------- inputs ---------- */
input[type="number"], input[type="text"] {
  background: var(--bg-deep);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 5px var(--sp-2);
  font-family: inherit;
  font-size: var(--fs-sm);
}
input[type="number"]:focus, input[type="text"]:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

/* ---------- empty states ---------- */
.empty-state {
  color: var(--text-dim);
  font-style: italic;
  padding: var(--sp-3);
}
.empty-state.small { padding: var(--sp-1); font-size: var(--fs-sm); }
.empty-state.pad   { padding: 50px; text-align: center; }

.empty-state-cta {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--sp-3);
  padding: var(--sp-6) var(--sp-4);
  color: var(--text-dim);
  text-align: center;
}
.empty-state-cta .esc-icon {
  width: 56px; height: 56px;
  display: inline-flex; align-items: center; justify-content: center;
  background: rgba(79,195,247,0.10);
  color: var(--accent);
  border-radius: 50%;
  border: 1px solid rgba(79,195,247,0.25);
}
.empty-state-cta .esc-icon svg { width: 28px; height: 28px; }
.empty-state-cta .esc-msg { font-size: var(--fs-md); font-style: normal; }

.dim { color: var(--text-dim); }

/* ---------- toast ---------- */
.toast {
  position: fixed;
  bottom: var(--sp-5);
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: #2a3645;
  color: var(--text);
  padding: var(--sp-3) var(--sp-4);
  border-radius: var(--r-md);
  border-left: 3px solid var(--accent);
  box-shadow: var(--sh-3);
  opacity: 0;
  pointer-events: none;
  z-index: 100;
  transition: opacity var(--dur-mid) var(--ease),
              transform var(--dur-mid) var(--ease);
  font-size: var(--fs-sm);
  font-weight: var(--fw-semi);
  max-width: 400px;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.err  { border-left-color: var(--bad); }

/* Multi-line rich toast used by Inspect (per-slot diagnosis). */
.toast .toast-row { display: block; line-height: 1.35; }
.toast .toast-row + .toast-row { margin-top: 4px; }
.toast .toast-head { font-size: var(--fs-sm); }
.toast .toast-body { color: var(--text-dim); font-size: var(--fs-xs); }
.toast .toast-suggest { color: var(--accent); font-size: var(--fs-xs); font-style: italic; }
.toast .toast-bucket.broken  { color: var(--bad); font-weight: var(--fw-bold); }
.toast .toast-bucket.worn    { color: var(--bad); }
.toast .toast-bucket.aging   { color: var(--price-tag); }
.toast .toast-bucket.healthy { color: var(--good); }
.toast .toast-icon svg { width: 12px; height: 12px; vertical-align: -2px; }

/* ---------- day-rollover overlay (Phase 2 P2.4: garage-door wipe) ---
   The day transition is the most-repeated cinematic in the run, so it
   gets a workshop-themed sweep instead of a flat white wash. Two
   ribbed panels (top + bottom) slide in to meet at the chip, hold,
   then slide back out. The chip itself flips its number via rotateX
   to sell "the day actually advanced". */
.day-flash {
  position: fixed; inset: 0;
  z-index: 200;
  pointer-events: none;
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
}
/* Two sliding panels — uses ::before for top, ::after for bottom.
   The corrugated horizontal striping reads as a roll-up garage door. */
.day-flash::before,
.day-flash::after {
  content: "";
  position: absolute;
  left: 0; right: 0;
  height: 50%;
  background:
    linear-gradient(180deg, rgba(40,55,72,0.92) 0%, rgba(28,40,55,0.95) 100%),
    repeating-linear-gradient(0deg,
      rgba(255,255,255,0.05) 0 6px,
      rgba(0,0,0,0.12) 6px 8px);
  background-blend-mode: overlay, normal;
  box-shadow: inset 0 0 32px rgba(0,0,0,0.5);
  transition: transform 360ms var(--ease, cubic-bezier(.2,.7,.3,1));
}
.day-flash::before {
  top: 0;
  transform: translateY(-100%);
  border-bottom: 2px solid rgba(240, 198, 58, 0.4);
}
.day-flash::after {
  bottom: 0;
  transform: translateY(100%);
  border-top: 2px solid rgba(240, 198, 58, 0.4);
}
.day-flash.show::before { transform: translateY(0); }
.day-flash.show::after  { transform: translateY(0); }

/* "Fast day transitions" toggle: skip the garage-door panels entirely
   and just show the day chip for a brief moment. ~3.5× faster than
   the default sequence (220ms vs 800ms) for players who want to
   end-day rapidly. */
.day-flash.fast::before,
.day-flash.fast::after {
  display: none;
}
.day-flash.fast .df-chip {
  transition: transform 120ms var(--ease, ease), opacity 100ms ease;
}

.day-flash .df-chip {
  position: relative;
  z-index: 1;
  background: linear-gradient(180deg, var(--bg-panel), rgba(20,30,45,0.95));
  color: var(--text-strong);
  font-size: 28px;
  font-weight: var(--fw-bold);
  letter-spacing: 2px;
  padding: var(--sp-3) var(--sp-5);
  border-radius: var(--r-lg);
  box-shadow: 0 12px 32px rgba(0,0,0,0.5),
              0 0 24px rgba(240, 198, 58, 0.25);
  border: 1px solid rgba(240, 198, 58, 0.4);
  transform: rotateX(90deg) scale(0.85);
  opacity: 0;
  transition: transform 360ms var(--ease-bounce, cubic-bezier(.34,1.56,.64,1)),
              opacity 220ms ease;
  transform-style: preserve-3d;
  perspective: 600px;
}
.day-flash.show .df-chip { transform: rotateX(0deg) scale(1); opacity: 1; }

/* End-Day button press depression (Phase 2 P2.4 prelude). Class added
   for ~120ms when the button is clicked, before the day-flash fires. */
.end-day.endday-press {
  transform: translateY(2px) scale(0.97) !important;
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.35) !important;
}

/* ---------- scrollbars ---------- */
.main-view::-webkit-scrollbar,
.rightbar::-webkit-scrollbar,
.event-log::-webkit-scrollbar { width: 8px; }
.main-view::-webkit-scrollbar-track,
.rightbar::-webkit-scrollbar-track,
.event-log::-webkit-scrollbar-track { background: transparent; }
.main-view::-webkit-scrollbar-thumb,
.rightbar::-webkit-scrollbar-thumb,
.event-log::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: var(--r-sm);
}
.main-view::-webkit-scrollbar-thumb:hover,
.rightbar::-webkit-scrollbar-thumb:hover,
.event-log::-webkit-scrollbar-thumb:hover {
  background: var(--border-strong);
}

/* ---------- panel headers ---------- */
.panel-header { margin-bottom: var(--sp-4); }
.panel-header h2 {
  margin: 0;
  font-size: var(--fs-xl);
  font-weight: var(--fw-bold);
}
.panel-header .sub {
  color: var(--text-dim);
  margin-top: var(--sp-1);
  font-size: var(--fs-sm);
}

/* ---------- shared icon container ---------- */
.icon-svg {
  width: 16px;
  height: 16px;
  display: inline-block;
  flex-shrink: 0;
  vertical-align: middle;
}

/* ---------- layout shell ---------- */
.layout {
  display: grid;
  grid-template-columns: 220px 1fr 280px;
  height: calc(100vh - 56px);
}
.main-view {
  background: var(--bg-deep);
  padding: var(--sp-4);
  overflow-y: auto;
}

/* ---------- small screens ---------- */
@media (max-width: 1100px) {
  .layout { grid-template-columns: 200px 1fr 260px; }
}
@media (max-width: 900px) {
  /* Narrow viewport (mobile / split-screen): keep the leftnav + main but
     restack the inventory rail BELOW the main column instead of hiding
     it entirely. The previous `.rightbar { display: none }` was the only
     parts inventory / pending-orders surface — mobile players couldn't
     drag parts or see deliveries arriving (audit finding E18). Stacking
     below preserves the entire feature; the rail just becomes a scrollable
     section at the bottom of the page instead of a fixed sidebar. */
  .layout {
    grid-template-columns: 160px 1fr;
    grid-template-rows: auto auto;
    grid-template-areas:
      "leftnav main"
      "rightbar rightbar";
  }
  .leftnav  { grid-area: leftnav; }
  .main     { grid-area: main; }
  .rightbar {
    grid-area: rightbar;
    max-height: 50vh;   /* keeps the rail compact; user can scroll */
    overflow-y: auto;
  }
}

/* ---------- brand tag (small colored chip) ---------- */
.brand-tag {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: var(--fs-micro);
  font-weight: var(--fw-bold);
  letter-spacing: 0.5px;
  padding: 2px var(--sp-1);
  border-radius: 3px;
  border: 1px solid;
  color: #fff;
  text-shadow: 0 1px 1px rgba(0,0,0,0.25);
  min-width: 28px;
  height: 16px;
  white-space: nowrap;
  vertical-align: middle;
}

/* ---------- universal pill badge ---------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: var(--fs-micro);
  font-weight: var(--fw-bold);
  text-transform: uppercase;
  letter-spacing: 1px;
  padding: 3px var(--sp-2);
  border-radius: 999px;
  background: rgba(255,255,255,0.06);
  color: var(--text-dim);
  white-space: nowrap;
}
.badge svg { width: 11px; height: 11px; }
.badge.b-diagnose { background: rgba(255,170,58,0.18); color: var(--warn-soft); }
.badge.b-repair   { background: rgba(79,195,247,0.18); color: var(--accent); }
.badge.b-test     { background: rgba(196,123,255,0.18); color: var(--premium); }
.badge.b-ready    { background: rgba(76,175,80,0.18);  color: var(--good-soft); }
.badge.b-listed   { background: rgba(255,209,102,0.18); color: var(--money); }
.badge.b-good     { background: rgba(76,175,80,0.18);  color: var(--good-soft); }
.badge.b-warn     { background: rgba(255,170,58,0.18); color: var(--warn-soft); }
.badge.b-bad      { background: rgba(232,80,58,0.20);  color: var(--bad-soft); }
.badge.b-rented   { background: rgba(255,214,110,0.16); color: #ffd66e; }
