:root {
  --bg-main: #ffb901;
  --text-main: #013668;
  --danger-main: #ed1b24;
  --danger-hover: #d0141f;
  --control-height: 38px;
  --panel-bg: #ffb901;
  --line: #013668;
  --muted: #24527c;
  --soft: #ffb901;
  --soft-2: #ffb901;
  --white: #ffffff;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text-main);
  font-family: Calibri, "Segoe UI", Arial, sans-serif;
  background: #000000;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(280px, 340px) 1fr;
  gap: 12px;
  padding: 12px;
  max-width: 1860px;
  margin: 0 auto;
}

.panel {
  background: var(--panel-bg);
  border: 0;
  border-radius: 14px;
  padding: 12px;
  box-shadow: 0 10px 24px rgba(1, 54, 104, 0.16);
}

.controls {
  display: flex;
  flex-direction: column;
  gap: 8px;
  height: fit-content;
  position: sticky;
  top: 8px;
  overflow: hidden;
}

.brand {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-main);
  margin: -12px -12px 8px;
  padding: 10px 12px;
  border-bottom: 0;
  border-top-left-radius: 12px;
  border-top-right-radius: 12px;
}

.app-logo {
  height: 52px;
  width: auto;
  object-fit: contain;
}

h1,
h2,
h3 {
  margin: 0;
  color: var(--danger-main);
}

h1 {
  font-size: 1.26rem;
}

h3 {
  font-size: 1rem;
}

.subtitle {
  color: var(--text-main);
  margin: 0 0 8px;
  font-size: 0.95rem;
}

label {
  font-size: 0.78rem;
  color: var(--text-main);
  display: block;
  margin-bottom: 5px;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  font-weight: 600;
}

input,
select,
button,
textarea {
  font-family: inherit;
  border-radius: 10px;
  border: 1.5px solid var(--line);
  background: var(--white);
  color: var(--text-main);
  padding: 8px 9px;
  font-size: 0.84rem;
}

input,
select,
textarea {
  min-height: var(--control-height);
}

button {
  cursor: pointer;
  font-weight: 700;
  background: var(--danger-main);
  color: var(--white);
  border-color: var(--danger-main);
  min-height: var(--control-height);
  padding: 7px 10px;
  font-size: 0.8rem;
  line-height: 1.1;
  text-align: center;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.15s ease, background 0.15s ease, border-color 0.15s ease;
}

button:hover:enabled {
  transform: translateY(-1px);
  background: var(--danger-hover);
  border-color: var(--danger-hover);
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-primary,
.btn-accent {
  background: var(--danger-main);
  color: var(--white);
  border-color: var(--danger-main);
}

.control-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.playback-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
}

.control-row > div,
.playback-row > *,
.toolbox-row > * {
  min-width: 0;
}

.controls button,
.controls input,
.controls select {
  width: 100%;
}

.playback-row button,
.playback-row select,
.toolbox-row button {
  width: 100%;
  min-width: 0;
}

.timeline-wrap {
  display: grid;
  grid-template-columns: 1fr;
  gap: 6px;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--danger-main);
  padding: 0;
  background: transparent;
  border: 0;
}

.toolbox {
  border: 0;
  border-radius: 10px;
  background: var(--soft-2);
  padding: 8px;
  display: grid;
  gap: 6px;
}

.toolbox-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.toolbox select,
.toolbox > button {
  width: 100%;
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 2px 0;
  text-transform: none;
  letter-spacing: 0;
  font-size: 0.9rem;
  color: var(--text-main);
}

.checkbox-row input[type="checkbox"] {
  width: 16px;
  height: 16px;
  margin: 0;
}

.status {
  font-size: 0.92rem;
  color: var(--text-main);
  min-height: 22px;
}

.status.error {
  color: var(--danger-main);
  font-weight: 700;
}

.summary {
  border: 0;
  border-radius: 10px;
  padding: 10px;
  background: var(--soft-2);
  font-size: 0.9rem;
  color: var(--text-main);
  line-height: 1.45;
  min-height: 78px;
}

.board {
  display: grid;
  grid-template-rows: auto auto 1fr;
  gap: 8px;
  min-height: 0;
}

.board-head {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: baseline;
  flex-wrap: wrap;
}

.board-head h2 {
  font-size: 1.15rem;
}

.board-meta {
  color: var(--text-main);
  font-size: 0.9rem;
  font-weight: 600;
}

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  overflow-x: auto;
  padding-bottom: 4px;
  scrollbar-width: thin;
}

.tab-btn {
  background: #fff2c8;
  color: var(--text-main);
  border: 1.5px solid var(--line);
  font-weight: 700;
  padding: 7px 11px;
  font-size: 0.8rem;
  flex: 0 0 auto;
  min-width: max-content;
}

.tab-btn:hover:enabled {
  background: #ffe08a;
  border-color: var(--line);
}

.tab-btn.active {
  background: var(--danger-main);
  color: var(--white);
  border-color: var(--danger-main);
}

.tab-panel {
  display: none;
  gap: 10px;
}

.tab-panel.active {
  display: grid;
}

.flow-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(280px, 340px);
  gap: 10px;
  align-items: start;
}

.flow-main {
  display: grid;
  gap: 8px;
  min-width: 0;
}

.map-toolbar {
  display: flex;
  justify-content: flex-end;
}

.map-toolbar button {
  width: auto;
  min-height: 34px;
  padding: 6px 12px;
}

.flow-log {
  display: grid;
  gap: 8px;
}

.flow-side {
  background: var(--soft-2);
  border-radius: 12px;
  padding: 8px;
  display: grid;
  gap: 8px;
  align-content: start;
}

#factoryWrap {
  position: relative;
  overflow: auto;
  border-radius: 12px;
  border: 0;
  background: var(--soft);
}

.fullscreen-stage {
  position: fixed;
  inset: 0;
  z-index: 9000;
  display: none;
  grid-template-rows: auto 1fr auto;
  gap: 8px;
  padding: 10px;
  background: #000000;
}

.fullscreen-stage.active {
  display: grid;
}

.fullscreen-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  background: var(--bg-main);
  border-radius: 10px;
  padding: 8px 10px;
}

.fullscreen-head-left {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.fullscreen-title {
  font-size: 0.96rem;
  font-weight: 700;
  color: var(--danger-main);
}

.fullscreen-controls {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
  max-width: 420px;
}

.fullscreen-controls button,
.fullscreen-controls select {
  width: 100%;
  min-width: 0;
  min-height: 34px;
}

.fullscreen-head button {
  width: auto;
  min-height: 34px;
  padding: 6px 12px;
}

.fullscreen-map-mount {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
  overflow: auto;
  border-radius: 10px;
  background: #000000;
}

.fullscreen-map-mount #mapCanvas {
  max-width: 100%;
  max-height: 100%;
  min-height: 0;
}

.fullscreen-timeline-wrap {
  background: var(--bg-main);
  border-radius: 10px;
  padding: 8px 10px;
  display: grid;
  gap: 6px;
}

#mapCanvas {
  position: relative;
  width: 100%;
  height: 520px;
  min-width: 0;
  overflow: hidden;
}

#mapImage {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  opacity: 0.88;
}

#mapImage.negative {
  filter: invert(1) hue-rotate(180deg) saturate(0.9) contrast(1.05);
}

.map-placeholder {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  text-align: center;
  padding: 20px;
  font-size: 1rem;
  color: var(--text-main);
  background: rgba(255, 185, 1, 0.86);
}

#pathLayer {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.path-line {
  fill: none;
  stroke-width: 8;
  opacity: 0.98;
  stroke-linecap: round;
  stroke-linejoin: round;
  filter: drop-shadow(0 0 3px #39ff14) drop-shadow(0 0 8px #39ff14);
}

#stationLayer {
  position: absolute;
  inset: 0;
}

.station-node {
  position: absolute;
  transform: translate(-50%, -50%);
  width: clamp(112px, 10.8vw, 168px);
  min-width: 0;
  max-width: none;
  border: 1.5px solid var(--line);
  background: var(--bg-main);
  border-radius: 10px;
  padding: clamp(4px, 0.5vw, 7px);
  display: grid;
  gap: clamp(2px, 0.3vw, 4px);
  box-shadow: 0 8px 20px rgba(1, 54, 104, 0.2);
  user-select: none;
  transition: border-color 0.2s ease, transform 0.2s ease;
}

.station-node .line-tag {
  font-size: clamp(0.52rem, 0.56vw, 0.62rem);
  color: var(--danger-main);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 700;
}

.station-node .station-name {
  font-size: clamp(0.74rem, 0.78vw, 0.82rem);
  font-weight: 700;
  line-height: 1.15;
  word-break: break-word;
  color: var(--text-main);
}

.station-node .station-count {
  color: var(--text-main);
  font-size: clamp(0.64rem, 0.72vw, 0.72rem);
}

.station-node.flash {
  border-color: var(--danger-main);
  animation: flash 0.45s ease;
}

.station-node.editable {
  cursor: grab;
}

.station-node.dragging {
  cursor: grabbing;
  border-color: var(--danger-main);
  box-shadow: 0 0 0 2px rgba(237, 27, 36, 0.45), 0 10px 30px rgba(1, 54, 104, 0.25);
}

@keyframes flash {
  0% {
    box-shadow: 0 0 0 rgba(237, 27, 36, 0.4);
  }
  50% {
    box-shadow: 0 0 24px rgba(237, 27, 36, 0.4);
  }
  100% {
    box-shadow: 0 0 0 rgba(237, 27, 36, 0);
  }
}

#tokenLayer {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.token {
  position: absolute;
  min-width: 24px;
  height: 24px;
  padding: 0 5px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  font-size: 0.56rem;
  font-weight: 700;
  color: var(--text-main);
  border: 1px solid var(--line);
  box-shadow: 0 6px 14px rgba(1, 54, 104, 0.2);
  transform: translate(-100px, -100px);
  transition: transform 0.45s cubic-bezier(0.2, 0.8, 0.2, 1);
  will-change: transform;
}

.current-event,
.events,
.storage-panel,
.order-panel,
.insight-card {
  border: 0;
  border-radius: 10px;
  background: var(--soft-2);
}

.current-event {
  padding: 10px;
  color: var(--text-main);
  font-size: 0.9rem;
  min-height: 48px;
}

.events {
  margin-top: 8px;
  overflow: auto;
  max-height: 190px;
}

.event-item {
  padding: 8px 10px;
  border-bottom: 1px solid rgba(1, 54, 104, 0.25);
  font-size: 0.82rem;
  color: var(--text-main);
  line-height: 1.35;
  font-variant-numeric: tabular-nums;
}

.event-item.clickable-order {
  cursor: pointer;
}

.event-item.clickable-order:hover {
  background: #ffe4a3;
}

.event-item:last-child {
  border-bottom: 0;
}

.storage-panel,
.order-panel,
.insight-card {
  margin-top: 8px;
  padding: 8px;
}

.flow-side .storage-panel,
.flow-side .order-panel {
  margin-top: 0;
}

.storage-panel h3,
.order-panel h3 {
  margin: 0 0 8px;
}

.storage-list,
.order-details {
  font-size: 0.84rem;
  line-height: 1.45;
  color: var(--text-main);
}

.order-complete-summary {
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px solid rgba(1, 54, 104, 0.25);
  font-size: 0.82rem;
  line-height: 1.4;
  color: var(--text-main);
}

.storage-list {
  display: grid;
  gap: 8px;
  max-height: 620px;
  overflow-y: auto;
  padding-right: 4px;
}

.storage-item {
  border: 0;
  border-radius: 8px;
  padding: 8px;
  background: var(--bg-main);
  line-height: 1.35;
}

.storage-item strong {
  color: var(--danger-main);
}

.storage-item.clickable-order {
  cursor: pointer;
}

.storage-item.clickable-order:hover {
  background: #ffe4a3;
}

.order-delay-text {
  color: var(--danger-main);
  font-weight: 700;
}

.order-on-time-text {
  color: #0c8f41;
  font-weight: 700;
}

.insights-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.ranking-list,
.distribution-grid,
.utilization-box,
.gantt-view,
.recommendations-list {
  font-size: 0.85rem;
  color: var(--text-main);
  min-height: 48px;
}

.trend-plot {
  width: 100%;
  height: 220px;
  border: 0;
  border-radius: 8px;
  background: var(--bg-main);
}

.scenario-control {
  margin-bottom: 10px;
}

.scenario-value {
  margin-top: 4px;
  font-weight: 700;
}

.kpi-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.kpi-table th,
.kpi-table td {
  border: 1px solid var(--line);
  padding: 6px 8px;
  text-align: left;
}

.kpi-table thead th {
  background: var(--danger-main);
  color: var(--white);
}

.app-footer {
  text-align: center;
  color: var(--text-main);
  font-size: 0.82rem;
  letter-spacing: 0.03em;
  padding: 10px 16px 16px;
  font-weight: 600;
}

.board-head-right {
  display: grid;
  justify-items: end;
  gap: 6px;
}

.session-meta {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.session-user {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--text-main);
}

.session-meta form {
  margin: 0;
}

.logout-btn {
  min-height: 30px;
  padding: 5px 10px;
  border-radius: 999px;
  font-size: 0.75rem;
  width: auto;
}

.auth-body {
  background: #000000;
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: 16px;
}

.auth-shell {
  width: min(420px, 100%);
}

.auth-card {
  background: var(--bg-main);
  border-radius: 14px;
  box-shadow: 0 10px 24px rgba(1, 54, 104, 0.22);
  padding: 14px;
}

.auth-brand {
  margin-bottom: 8px;
}

.auth-form {
  display: grid;
  gap: 8px;
}

.loading-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(255, 185, 1, 0.28);
}

body.page-loading .loading-overlay {
  display: flex;
}

body.page-loading .app-shell,
body.page-loading .app-footer {
  filter: blur(4px);
  pointer-events: none;
  user-select: none;
}

.loading-card {
  min-width: 220px;
  border: 2px solid var(--line);
  border-radius: 12px;
  background: var(--bg-main);
  color: var(--text-main);
  padding: 16px 18px;
  display: grid;
  justify-items: center;
  gap: 10px;
  box-shadow: 0 14px 30px rgba(1, 54, 104, 0.22);
}

.spinner {
  width: 34px;
  height: 34px;
  border: 4px solid rgba(1, 54, 104, 0.28);
  border-top-color: var(--danger-main);
  border-radius: 50%;
  animation: spinner-rotate 0.9s linear infinite;
}

.loading-text {
  font-size: 0.92rem;
  font-weight: 700;
}

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

@media (max-width: 1120px) {
  .app-shell {
    grid-template-columns: 1fr;
    padding: 10px;
    gap: 10px;
  }

  .controls {
    position: static;
  }

  #mapCanvas {
    min-width: 0;
  }

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

  .flow-layout {
    grid-template-columns: 1fr;
  }

  .station-node {
    width: clamp(100px, 16vw, 146px);
  }

  .fullscreen-head {
    flex-wrap: wrap;
  }

  .fullscreen-controls {
    max-width: none;
  }
}

@media (max-width: 820px) {
  .panel {
    padding: 10px;
  }

  .board-head {
    align-items: flex-start;
    flex-direction: column;
  }

  .board-head-right {
    width: 100%;
    justify-items: start;
  }

  .session-meta {
    justify-content: flex-start;
  }

  .control-row,
  .playback-row,
  .toolbox-row {
    grid-template-columns: 1fr;
  }

  .tabs {
    display: flex;
    flex-wrap: nowrap;
    overflow-x: auto;
  }

  .tab-btn {
    width: auto;
    min-width: max-content;
  }

  .station-node {
    width: clamp(88px, 21vw, 124px);
    padding: 4px 5px;
    border-radius: 8px;
  }

  #mapCanvas {
    height: 360px;
  }
}

@media (max-width: 560px) {
  .app-shell {
    padding: 6px;
    gap: 6px;
  }

  .panel {
    border-radius: 10px;
    padding: 8px;
  }

  .app-logo {
    height: 42px;
  }

  h1 {
    font-size: 1.05rem;
  }

  .subtitle {
    font-size: 0.87rem;
  }

  label {
    font-size: 0.74rem;
  }

  button,
  input,
  select,
  textarea {
    font-size: 0.8rem;
  }

  #mapCanvas {
    height: 280px;
  }

  .auth-body {
    padding: 8px;
  }
}
