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

:root {
  --bg: #f1f4f8;
  --col-bg: #ffffff;
  --border: #d6dde6;
  --text: #1c2733;
  --muted: #6b7a8c;
  --waiting: #2f80ed;
  --departed: #27ae60;
  --pool: #95a5b8;
  --warn: #e67e22;
  --danger: #e74c3c;
  --sub: #9b59b6;
}

html, body { height: 100%; }

body {
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

/* ---------- Top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  background: #223449;
  color: #fff;
  flex-wrap: wrap;
}
.title-group { display: flex; align-items: baseline; gap: 14px; flex-wrap: wrap; }
.topbar h1 { font-size: 1.25rem; }
.board-date { color: #b8c6d8; font-size: 1rem; }

.conn { display: inline-flex; align-items: center; gap: 6px; font-size: 0.85rem; color: #b8c6d8; }
.conn-dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--danger);
}
.conn.connected .conn-dot { background: #2ecc71; }

.topbar-actions { display: flex; gap: 10px; }

/* ---------- Buttons ---------- */
.btn {
  font-size: 1rem;
  padding: 10px 16px;
  min-height: 44px;
  border: none;
  border-radius: 8px;
  background: #3d5a7d;
  color: #fff;
  cursor: pointer;
  touch-action: manipulation;
}
.btn:hover { filter: brightness(1.1); }
.btn-warn { background: var(--warn); }
.btn-primary { background: var(--waiting); }
.btn-sub { background: var(--sub); }
.btn-ghost { background: transparent; border: 1px solid var(--border); color: inherit; }
.btn-small { min-height: 36px; padding: 6px 12px; font-size: 0.9rem; }
.btn-danger { background: var(--danger); }

/* ---------- Stale banner ---------- */
.stale-banner {
  background: #fdf0d5;
  color: #7a5200;
  border-bottom: 1px solid #ecd9a8;
  padding: 10px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.stale-banner .btn-ghost { color: #7a5200; border-color: #ecd9a8; }

/* ---------- Board ---------- */
.board {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 1.15fr 1.15fr 1.15fr 1.15fr 1fr;
  gap: 10px;
  padding: 10px;
  overflow: hidden;
  min-height: 0;
}

.column {
  background: var(--col-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}
.column h2 {
  font-size: 0.95rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 10px 12px 4px;
  color: var(--muted);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.count { font-size: 0.85rem; font-weight: normal; }
.lane-hint {
  font-size: 0.7rem;
  color: var(--muted);
  padding: 0 12px 4px;
}
.col-lane h2 { color: var(--waiting); }
.col-departed h2 { color: var(--departed); }

.bus-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 60px;
}
/* Visible drop target when a lane is empty */
.bus-list:empty {
  border: 2px dashed var(--border);
  border-radius: 8px;
  margin: 8px;
  padding: 0;
}

/* ---------- Bus blocks ---------- */
.bus {
  background: #fff;
  border: 1px solid var(--border);
  border-left: 6px solid var(--pool);
  border-radius: 8px;
  padding: 10px 12px;
  cursor: grab;
  user-select: none;
  box-shadow: 0 1px 2px rgba(0,0,0,0.06);
  touch-action: none;
}
.bus:active { cursor: grabbing; }
.bus-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.bus-number {
  font-size: 1.6rem;
  font-weight: 700;
  line-height: 1.1;
}
.sub-badge {
  font-size: 0.7rem;
  font-weight: 700;
  color: #fff;
  background: var(--sub);
  border-radius: 4px;
  padding: 2px 6px;
  letter-spacing: 0.05em;
}
.pos-badge {
  font-size: 0.8rem;
  color: var(--muted);
  white-space: nowrap;
}

.bus.in-lane { border-left-color: var(--waiting); }
.bus.is-departed {
  border-left-color: var(--departed);
  opacity: 0.75;
}

.bus-action {
  margin-top: 8px;
  width: 100%;
  min-height: 44px;
  font-size: 0.95rem;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  touch-action: manipulation;
}
.bus-action.depart { background: var(--departed); color: #fff; }
.bus-action.undo { background: #edf1f5; color: var(--text); }
.bus-action:hover { filter: brightness(1.05); }

/* SortableJS states */
.bus.sortable-ghost { opacity: 0.35; }
.bus.sortable-chosen { box-shadow: 0 4px 12px rgba(0,0,0,0.18); }

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(20, 30, 42, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 16px;
}
.modal {
  background: #fff;
  border-radius: 12px;
  width: min(560px, 100%);
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  padding: 18px;
  gap: 12px;
}
.modal-head { display: flex; justify-content: space-between; align-items: center; }
.modal-head h2 { font-size: 1.2rem; }

.roster-add {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.roster-add #add-number { grid-column: span 2; }
.roster-add input {
  font-size: 1rem;
  padding: 10px;
  min-height: 44px;
  border: 1px solid var(--border);
  border-radius: 8px;
}
.roster-add button { grid-column: span 1; }
.roster-add .btn-primary { grid-column: 1; }
.roster-add .btn-sub { grid-column: 2; }

.roster-warning { color: var(--warn); font-size: 0.9rem; }

.roster-list {
  list-style: none;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.roster-list li {
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
}
.roster-list .r-number { font-weight: 700; font-size: 1.1rem; flex: 1; }
.roster-list .sub-badge { flex-shrink: 0; }

/* ---------- Disconnected overlay ---------- */
.disconnected-overlay {
  position: fixed;
  inset: 0;
  background: rgba(20, 30, 42, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.disconnected-card {
  background: #fff;
  border-radius: 12px;
  padding: 28px 36px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}
.spinner {
  width: 32px; height: 32px;
  border: 4px solid var(--border);
  border-top-color: var(--waiting);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.hidden { display: none !important; }

/* ---------- Narrow screens: stack columns ---------- */
@media (max-width: 900px) {
  body { overflow: auto; height: auto; }
  .board {
    grid-template-columns: 1fr 1fr;
    overflow: visible;
  }
  .column { min-height: 160px; }
  .bus-list { overflow-y: visible; }
}
