:root {
  --bg: #181818;
  --panel: #20201f;
  --panel-2: #242423;
  --text: #f4f1ea;
  --muted: #aaa69d;
  --line: #3a3936;
  --teal: #007f6d;
  --teal-bright: #009982;
  --teal-light: #bfe8dd;
  --blue-light: #cfe4ff;
  --sand: #f2dec1;
  --danger: #ff8b82;

  /* Change this value to customise the Optimize / simulation icon colour. */
  --simulate-icon-color: #a855f7;
  --simulate-icon-hover-color: #c084fc;
}

* { box-sizing: border-box; }

html { min-width: 320px; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button, input, select { font: inherit; }

.app-shell {
  width: min(1280px, calc(100% - 32px));
  margin: 0 auto;
  padding: 26px 0 40px;
}

.topbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 18px;
}

h1, h2, p { margin: 0; }

h1 {
  font-size: clamp(24px, 3vw, 38px);
  line-height: 1.05;
  letter-spacing: -0.04em;
}

.topbar p {
  margin-top: 7px;
  color: var(--muted);
  font-weight: 700;
}

.status {
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
  text-align: right;
}

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

/* Responsive control system */
.controls {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 185px), 1fr));
  gap: 16px;
  align-items: end;
  margin-bottom: 16px;
}

.primary-controls {
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 175px), 1fr));
}

.control {
  min-width: 0;
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-weight: 800;
}

.action-control { align-self: end; }

.label-row {
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.label-row strong { color: var(--text); }

input[type="range"] {
  width: 100%;
  min-width: 0;
  accent-color: var(--teal);
}

select,
button {
  height: 42px;
  max-width: 100%;
  border-radius: 9px;
  border: 1px solid var(--line);
  background: #222221;
  color: var(--text);
  font-weight: 800;
  padding: 0 14px;
}

.control select,
.controls button {
  width: 100%;
  min-width: 0;
}

select {
  overflow: hidden;
  text-overflow: ellipsis;
}

select:focus,
button:focus,
input:focus,
.help-icon:focus {
  outline: 2px solid #2a5ea8;
  outline-offset: 2px;
}

button {
  cursor: pointer;
  background: #272726;
  white-space: nowrap;
}

button:hover:not(:disabled) { border-color: #706b63; }

#optimizeButton {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.simulate-icon {
  color: white;
  background: var(--simulate-icon-color);
  border: 1px solid var(--simulate-icon-color);
  border-radius: 999px;
  padding: 4px 7px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  font-weight: 900;
}

#optimizeButton:hover .simulate-icon {
  background: var(--simulate-icon-hover-color);
  border-color: var(--simulate-icon-hover-color);
}

button:disabled {
  opacity: 0.5;
  cursor: wait;
}

.invisible-label {
  opacity: 0;
  pointer-events: none;
}

/* Help icons and hover descriptions */
.help-wrap {
  min-width: 0;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.help-icon {
  position: relative;
  z-index: 10;
  flex: 0 0 auto;
  width: 18px;
  height: 18px;
  display: inline-grid;
  place-items: center;
  border: 1px solid #4a4945;
  border-radius: 999px;
  background: #252524;
  color: var(--teal-light);
  font-size: 11px;
  line-height: 1;
  font-weight: 900;
  cursor: help;
  user-select: none;
}

.help-icon::after {
  content: attr(data-tooltip);
  position: absolute;
  left: 50%;
  top: calc(100% + 9px);
  width: min(290px, calc(100vw - 36px));
  transform: translateX(-50%) translateY(-3px);
  opacity: 0;
  pointer-events: none;
  background: #f4f1ea;
  color: #181818;
  border: 1px solid rgba(0,0,0,0.18);
  border-radius: 10px;
  box-shadow: 0 12px 28px rgba(0,0,0,0.36);
  padding: 10px 12px;
  font-size: 12px;
  font-weight: 750;
  line-height: 1.35;
  text-align: left;
  white-space: normal;
  transition: opacity 0.14s ease, transform 0.14s ease;
}

.help-icon::before {
  content: "";
  position: absolute;
  left: 50%;
  top: calc(100% + 4px);
  width: 10px;
  height: 10px;
  transform: translateX(-50%) rotate(45deg);
  background: #f4f1ea;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.14s ease;
}

.help-icon:hover::after,
.help-icon:hover::before,
.help-icon:focus::after,
.help-icon:focus::before {
  opacity: 1;
}

.help-icon:hover::after,
.help-icon:focus::after {
  transform: translateX(-50%) translateY(0);
}



/* Floating tooltips: rendered at <body> level so they are never clipped by
   cards, grid sections, selects, sliders or responsive containers. */
.help-icon::before,
.help-icon::after {
  display: none !important;
}

.floating-tooltip {
  position: fixed;
  z-index: 2147483647;
  width: max-content;
  max-width: min(280px, calc(100vw - 24px));
  background: #f4f1ea;
  color: #181818;
  border: 1px solid rgba(0,0,0,0.18);
  border-radius: 9px;
  box-shadow: 0 14px 34px rgba(0,0,0,0.46);
  padding: 8px 10px;
  font-size: 12px;
  font-weight: 750;
  line-height: 1.28;
  text-align: left;
  white-space: normal;
  pointer-events: none;
  opacity: 0;
  transform: translateY(-2px);
  transition: opacity 0.12s ease, transform 0.12s ease;
}

.floating-tooltip-text {
  display: block;
  max-height: calc(12px * 1.28 * 5);
  overflow: hidden;
}

.floating-tooltip.visible {
  opacity: 1;
  transform: translateY(0);
}

.floating-tooltip-arrow {
  position: absolute;
  left: var(--arrow-left, 50%);
  width: 10px;
  height: 10px;
  background: #f4f1ea;
  transform: translateX(-50%) rotate(45deg);
  border: inherit;
  z-index: -1;
}

.floating-tooltip[data-placement="bottom"] .floating-tooltip-arrow {
  top: -5px;
  border-right: 0;
  border-bottom: 0;
}

.floating-tooltip[data-placement="top"] .floating-tooltip-arrow {
  bottom: -5px;
  border-left: 0;
  border-top: 0;
}

/* Group builder */
.grouping-controls {
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 230px), 1fr));
  margin-top: -4px;
  margin-bottom: 18px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #1c1c1b;
}

.grouping-help {
  min-width: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
  align-self: center;
}

.grouping-help strong { color: var(--text); }

.muted-control { opacity: 0.46; }
.muted-control input { pointer-events: none; }

/* Metrics */
.metrics {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 175px), 1fr));
  gap: 16px;
  margin-bottom: 18px;
}

.metric-card {
  min-width: 0;
  background: var(--panel);
  border-radius: 10px;
  padding: 18px 20px;
}

.metric-label {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
  margin-bottom: 5px;
}

.metric-card strong {
  font-size: clamp(26px, 4vw, 38px);
  line-height: 1;
  letter-spacing: -0.04em;
}

/* Main workspace */
.workspace {
  display: grid;
  grid-template-columns: minmax(180px, 205px) minmax(0, 1fr);
  gap: 22px;
  align-items: start;
}

.seat-section {
  min-width: 0;
  position: sticky;
  top: 16px;
}

.seat-map-title {
  display: none;
  margin-bottom: 8px;
}

.seat-map {
  display: grid;
  gap: 4px;
}

.seat-header,
.seat-row {
  display: grid;
  grid-template-columns: repeat(3, 24px) 12px repeat(3, 24px) 22px;
  gap: 4px;
  align-items: center;
}

.seat-header {
  color: #d8d3cb;
  font-weight: 900;
  font-size: 12px;
  padding-left: 0;
}

.seat-header .blank,
.seat-row .aisle { width: 12px; }

.seat-row .row-number {
  color: #d8d3cb;
  font-size: 12px;
  font-weight: 800;
  text-align: right;
}

.seat {
  height: 18px;
  display: grid;
  place-items: center;
  border-radius: 2px;
  font-size: 9px;
  line-height: 1;
  font-weight: 900;
  color: #151515;
  user-select: none;
}

.seat.early-text { color: #f8f7f2; }

.seat.empty-seat {
  background: #252524;
  border: 1px dashed #393835;
  color: transparent;
}

.legend {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  margin-top: 18px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.legend-chip {
  width: 12px;
  height: 12px;
  border-radius: 3px;
  display: inline-block;
}

.legend-chip.early { background: var(--teal); }
.legend-chip.late { background: #e7e3db; }
.legend-chip.empty { background: #2c2c2a; border: 1px solid var(--line); }

.analysis-section {
  min-width: 0;
  display: grid;
  gap: 22px;
}

.chart-card,
.sequence-card,
.groups-card,
.explanation { background: transparent; }

.section-title-with-help,
.chart-card h2,
.sequence-card h2,
.groups-card h2 {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 16px;
  color: var(--muted);
  margin-bottom: 8px;
}

#scoreChart {
  width: 100%;
  height: 210px;
  display: block;
}

.sequence-card,
.groups-card {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 14px;
  min-width: 0;
}

.sequence-title {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 12px;
}

.sequence-title > div { min-width: 0; }

.seat-type-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.pill,
.token {
  display: inline-flex;
  align-items: center;
  border-radius: 4px;
  font-weight: 900;
}

.pill {
  padding: 5px 9px;
  font-size: 12px;
  color: #1b211f;
}

.window { background: #d7f6eb; }
.middle { background: var(--blue-light); }
.aisle { background: var(--sand); }

.sequence {
  max-height: 295px;
  overflow: auto;
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  padding-right: 4px;
}

.token {
  color: #151515;
  min-width: 38px;
  justify-content: center;
  padding: 5px 7px;
  font-size: 12px;
}

.small-note {
  color: var(--muted);
  font-size: 13px;
  margin-top: 3px;
}

.small-note strong { color: var(--text); }

.button-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.menu-tabs {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  border-bottom: 1px solid var(--line);
  padding-bottom: 10px;
  margin-bottom: 12px;
}

.tab-button {
  height: 34px;
  font-size: 13px;
  border-radius: 999px;
  background: #1f1f1e;
}

.tab-button.active {
  background: var(--teal);
  border-color: var(--teal);
  color: white;
}

.group-view { display: none; }
.group-view.active { display: block; }

.boarding-groups {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  max-height: 520px;
  overflow: auto;
  padding-right: 4px;
}

.group-card,
.group-card.wide {
  min-width: 0;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px;
}

.group-card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}

.group-card-head strong { font-size: 16px; }

.group-card-head small {
  color: var(--muted);
  font-weight: 800;
  text-align: right;
}

.group-card-head p {
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.group-card-head p b { color: var(--teal-light); }

.group-equals {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 5px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
}

.group-equals b {
  color: var(--text);
  margin-right: 4px;
}

.group-equals span,
.table-seat {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 38px;
  border-radius: 4px;
  padding: 4px 7px;
  color: #151515;
  font-size: 12px;
  font-weight: 900;
}

.table-toolbar {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 10px;
}

.table-toolbar label {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.table-toolbar select { height: 34px; }

.ticket-table-wrap {
  max-height: 440px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 10px;
}

.ticket-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.ticket-table th,
.ticket-table td {
  padding: 9px 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
}

.ticket-table th {
  position: sticky;
  top: 0;
  background: #20201f;
  color: var(--muted);
  z-index: 1;
}

.ticket-table td { color: var(--text); }

.ticket-preview-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 220px), 1fr));
  gap: 10px;
}

.boarding-pass {
  background: #f4f1ea;
  color: #181818;
  border-radius: 12px;
  padding: 14px;
  min-height: 112px;
  display: grid;
  gap: 12px;
  box-shadow: 0 8px 20px rgba(0,0,0,0.2);
}

.boarding-pass > span,
.boarding-pass small {
  color: #625d55;
  font-weight: 800;
  font-size: 12px;
}

.boarding-pass-main {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
}

.boarding-pass-main strong {
  font-size: 32px;
  letter-spacing: -0.06em;
}

.boarding-pass-main b {
  color: #007160;
  font-size: 16px;
}

.explanation {
  margin-top: 18px;
  color: var(--muted);
  line-height: 1.45;
  font-size: 14px;
}

.explanation strong { color: var(--text); }

@media (max-width: 1020px) {
  .workspace {
    grid-template-columns: 1fr;
  }

  .seat-section {
    position: static;
    overflow-x: auto;
    padding-bottom: 4px;
  }

  .seat-map-title { display: flex; }
}

@media (max-width: 760px) {
  .topbar {
    display: grid;
    align-items: start;
  }

  .status {
    text-align: left;
    white-space: normal;
  }

  .sequence-title,
  .button-row,
  .table-toolbar {
    display: grid;
    justify-content: stretch;
  }

  .button-row button,
  .sequence-title button {
    width: 100%;
  }

  .ticket-table { min-width: 620px; }
}

@media (max-width: 560px) {
  .app-shell { width: min(100% - 20px, 1280px); }

  .controls,
  .primary-controls,
  .grouping-controls,
  .metrics {
    grid-template-columns: 1fr;
  }

  .metric-card { padding: 16px; }

  .help-icon::after {
    width: min(260px, calc(100vw - 24px));
  }

  .group-card-head {
    display: grid;
  }

  .group-card-head small { text-align: left; }
}
