:root {
  --bg: #0e141b;
  --panel: #18222c;
  --text: #e8eef4;
  --muted: #93a4b5;
  --tram: #ff7a1a;
  --paper: #f6f1e4;
  --ink: #1b1b1b;
  --rule: #2a2a2a;
  --lunch: #dcecc4;
  --change: #f4c7c2;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", system-ui, sans-serif;
}

.app {
  min-height: 100%;
}

.panel {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 16px 20px;
  background: var(--panel);
}

.top {
  position: sticky;
  top: 0;
  z-index: 20;
  flex-direction: column;
  align-items: stretch;
  gap: 10px;
}

.top-main {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  position: relative;
  z-index: 1;
}

.mini-cal {
  position: relative;
  z-index: 35;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  overflow: visible;
}

.cal-cell {
  position: relative;
  display: grid;
  grid-template-rows: 1fr auto;
  justify-items: center;
  align-items: center;
  min-height: 40px;
  padding: 3px 4px 2px;
  border-radius: 10px;
  border: 1px solid #3d5163;
  background: #243140;
  cursor: pointer;
  overflow: visible;
}

.cal-cell.today {
  z-index: 2;
  border-color: #7ea3bf;
}

.cal-cell.weekend {
  background: #203040;
}

.cal-cell.editing,
.cal-cell.asking {
  z-index: 6;
}

.cal-cell.editing {
  border-color: var(--tram);
}

.cal-exit,
.cal-input {
  grid-row: 1;
  grid-column: 1;
  width: 100%;
  min-height: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  font-weight: 800;
  line-height: 1;
  text-align: center;
}

.cal-input {
  background: transparent;
  border: 0;
  color: var(--text);
  padding: 0;
  font: inherit;
  font-size: 16px;
  font-weight: 800;
  outline: none;
}

.cal-exit.empty {
  color: #5d7080;
  font-weight: 700;
}

.cal-date {
  grid-row: 2;
  grid-column: 1;
  font-size: 10px;
  color: var(--muted);
  line-height: 1;
}

.cal-ask {
  position: absolute;
  inset: -2px;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: center;
  gap: 3px;
  padding: 4px;
  background: rgba(24, 34, 44, 0.96);
  border-radius: 10px;
}

.cal-ask[hidden],
.cal-suggest[hidden],
.cal-exit[hidden],
.cal-input[hidden] {
  display: none;
}

.cal-ask button {
  background: #36556b;
  color: var(--text);
  border: 1px solid #7ea3bf;
  border-radius: 7px;
  padding: 5px 6px;
  font: inherit;
  font-size: 11px;
  font-weight: 700;
  line-height: 1.1;
  cursor: pointer;
}

.cal-ask button[data-ask="delete"] {
  background: #5a3333;
  border-color: #c47a7a;
}

.cal-suggest {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(100% + 4px);
  z-index: 50;
  max-height: 180px;
  overflow-y: auto;
  background: #22303c;
  border: 1px solid #3d5163;
  border-radius: 10px;
  padding: 4px;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.35);
}

.cal-hint {
  display: block;
  width: 100%;
  text-align: left;
  background: transparent;
  color: var(--text);
  border: 0;
  border-radius: 8px;
  padding: 8px 10px;
  font: inherit;
  font-weight: 650;
  cursor: pointer;
}

.cal-hint:hover,
.cal-hint:focus {
  background: #2f4456;
}

.net-dot {
  position: absolute;
  left: 50%;
  top: 8px;
  width: 5px;
  height: 5px;
  margin-left: -2.5px;
  border-radius: 50%;
  background: #64748b;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.25);
  pointer-events: none;
}

.net-dot.from-net {
  background: #22c55e;
}

.net-dot.from-cache {
  background: #ef4444;
}

.picker {
  position: relative;
  z-index: 30;
}

.picker-tabs {
  display: flex;
  gap: 6px;
}

.picker-tabs button {
  background: #243140;
  color: var(--text);
  border: 1px solid #3d5163;
  border-radius: 10px;
  padding: 10px 14px;
  font: inherit;
  font-weight: 650;
  cursor: pointer;
}

.picker-tabs button.current {
  border-color: #7ea3bf;
  background: #2f4456;
}

.picker-tabs button[aria-expanded="true"] {
  background: #36556b;
}

.menu {
  display: none;
  position: fixed;
  left: 8px;
  right: auto;
  width: min(360px, calc(100vw - 16px));
  background: #22303c;
  border: 1px solid #3d5163;
  border-radius: 12px;
  padding: 8px;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.35);
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  z-index: 40;
}

.menu.open {
  display: block;
}

.menu-cols {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  align-items: start;
}

.menu-col {
  min-width: 0;
}

.menu-label {
  margin: 4px 8px 6px;
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.menu-item {
  display: block;
  width: 100%;
  text-align: left;
  background: transparent;
  color: var(--text);
  border: 0;
  border-radius: 8px;
  padding: 8px 10px;
  margin-bottom: 2px;
  font: inherit;
  font-weight: 650;
  cursor: pointer;
}

.menu-item.active,
.menu-item:hover {
  background: #2f4456;
}

.menu-empty {
  margin: 0 8px 8px;
  color: var(--muted);
  font-size: 13px;
}

.clock {
  margin: 0;
  font-variant-numeric: tabular-nums;
  font-size: 28px;
  font-weight: 700;
  text-align: right;
}

.status,
.next {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.clock-block {
  text-align: right;
}

.auth-bar {
  display: flex;
  justify-content: flex-end;
  gap: 6px;
  margin-bottom: 4px;
}

.auth-btn {
  background: #243140;
  color: var(--text);
  border: 1px solid #3d5163;
  border-radius: 8px;
  padding: 4px 10px;
  font: inherit;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}

.auth-btn[hidden] {
  display: none;
}

.chat-btn {
  position: relative;
  padding-right: 12px;
}

.chat-badge {
  position: absolute;
  top: -6px;
  right: -6px;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: 999px;
  background: #c44;
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  line-height: 16px;
  text-align: center;
}

.chat-badge[hidden] {
  display: none;
}

.chat-dialog {
  aspect-ratio: auto;
  width: min(420px, 100%);
  min-height: 360px;
  max-height: min(560px, calc(100vh - 64px));
}

.chat-feed {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 4px 2px 8px;
  margin-bottom: 8px;
  text-align: left;
  min-height: 180px;
}

.chat-msg-meta {
  display: flex;
  gap: 8px;
  align-items: baseline;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 2px;
}

.chat-msg-name {
  color: #9ec5e0;
  font-weight: 700;
}

.chat-msg-body {
  font-size: 14px;
  line-height: 1.35;
  word-break: break-word;
}

.chat-form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  margin-top: auto;
}

.chat-form input {
  width: 100%;
  background: #1c2833;
  border: 1px solid #3d5163;
  border-radius: 8px;
  color: var(--text);
  padding: 9px 10px;
  font: inherit;
}

.chat-form button {
  background: #36556b;
  color: var(--text);
  border: 1px solid #7ea3bf;
  border-radius: 8px;
  padding: 9px 12px;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
}

.auth-modal {
  position: fixed;
  inset: 0;
  z-index: 80;
  background: rgba(8, 12, 18, 0.55);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 48px 16px 16px;
}

.auth-modal[hidden] {
  display: none;
}

.auth-dialog {
  position: relative;
  width: min(320px, 100%);
  aspect-ratio: 1;
  max-height: min(320px, calc(100vh - 64px));
  background: #22303c;
  border: 1px solid #3d5163;
  border-radius: 14px;
  padding: 20px 18px 18px;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.45);
  display: flex;
  flex-direction: column;
}

.auth-dialog-search {
  aspect-ratio: auto;
  min-height: 280px;
  max-height: min(420px, calc(100vh - 64px));
}

.auth-dialog h2 {
  margin: 0 0 12px;
  font-size: 18px;
}

.auth-close {
  position: absolute;
  top: 8px;
  right: 10px;
  background: transparent;
  border: 0;
  color: var(--muted);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
}

.auth-form {
  display: grid;
  gap: 10px;
  flex: 1;
  align-content: start;
}

.auth-form label {
  display: grid;
  gap: 4px;
  font-size: 13px;
  color: var(--muted);
  text-align: left;
}

.auth-form input,
.auth-search-input {
  width: 100%;
  background: #1c2833;
  border: 1px solid #3d5163;
  border-radius: 8px;
  color: var(--text);
  padding: 9px 10px;
  font: inherit;
}

.auth-form button {
  margin-top: auto;
  background: #36556b;
  color: var(--text);
  border: 1px solid #7ea3bf;
  border-radius: 8px;
  padding: 10px 14px;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

.auth-error {
  color: #f0a0a0;
  font-size: 13px;
  margin: 0;
  text-align: left;
}

.auth-results {
  margin-top: 10px;
  overflow-y: auto;
  flex: 1;
  text-align: left;
}

.auth-hit {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 6px;
  border-bottom: 1px solid #2f4456;
  font-size: 14px;
}

.auth-hit span {
  color: var(--muted);
}

.auth-empty {
  margin: 8px 0;
  color: var(--muted);
  font-size: 13px;
}

.map-wrap {
  overflow: auto;
}

canvas {
  display: block;
  width: 100%;
  height: auto;
}

.controls {
  flex-wrap: wrap;
}

.toggle,
.slider {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 14px;
}

.slider {
  flex: 1;
  min-width: 220px;
}

.slider input {
  flex: 1;
}

.next {
  flex-basis: 100%;
  margin: 0;
}

.sheet-wrap {
  padding: 20px 12px 40px;
  padding-bottom: max(40px, env(safe-area-inset-bottom));
}

.sheet {
  max-width: 980px;
  margin: 0 auto;
  background: var(--paper);
  color: var(--ink);
  border: 1px solid #cfc6b3;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
  padding: 16px 18px 22px;
}

.sheet-head {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: start;
  gap: 12px;
  margin-bottom: 10px;
}

.sheet-depot,
.sheet-route {
  margin: 0;
  font-size: 14px;
}

.sheet-route {
  text-align: right;
}

.sheet-title {
  text-align: center;
}

.sheet-title p {
  margin: 0;
  font-weight: 700;
  line-height: 1.3;
}

.sheet-meta {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 12px;
  font-size: 14px;
}

.sheet-meta p {
  margin: 0;
}

.sheet-scroll {
  overflow-x: auto;
}

.sheet table {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
  font-size: 13px;
  text-align: center;
}

.sheet th,
.sheet td {
  border: 1px solid var(--rule);
  padding: 6px 4px;
  min-width: 72px;
}

.col-short {
  display: none;
}

.sheet th {
  font-size: 12px;
  font-weight: 700;
  background: #efe7d6;
}

.sheet td.empty {
  color: #888;
}

.sheet td.note {
  font-size: 11px;
  font-weight: 700;
  white-space: normal;
  line-height: 1.25;
}

.sheet .mark-lunch {
  background: var(--lunch);
}

.sheet .mark-change {
  background: var(--change);
  font-weight: 800;
}

.sheet td.now {
  outline: 3px solid var(--tram);
  outline-offset: -3px;
  background: #ffd2ad;
}

.handover td:first-child,
.banner td {
  text-align: left;
  padding-left: 8px;
}

@media (max-width: 720px) {
  .panel {
    padding: 12px 12px;
    gap: 10px;
  }

  .top {
    gap: 8px;
  }

  .top-main {
    gap: 10px;
  }

  .mini-cal {
    gap: 6px;
  }

  .cal-cell {
    min-height: 35px;
    padding: 2px 2px 2px;
    border-radius: 8px;
  }

  .cal-exit,
  .cal-input {
    font-size: 15px;
    min-height: 16px;
  }

  .cal-date {
    font-size: 10px;
  }

  .picker-tabs button {
    padding: 8px 10px;
    font-size: 14px;
  }

  .menu {
    left: 8px;
    right: 8px;
    width: auto;
  }

  .clock {
    font-size: 22px;
  }

  .sheet-wrap {
    padding: 12px 8px max(24px, env(safe-area-inset-bottom));
  }

  .sheet {
    padding: 10px 8px 14px;
    border-radius: 8px;
  }

  .sheet-head {
    grid-template-columns: 1fr 1fr;
    gap: 4px 8px;
    margin-bottom: 8px;
  }

  .sheet-title {
    grid-column: 1 / -1;
    text-align: left;
  }

  .sheet-title p {
    font-size: 13px;
  }

  .sheet-depot,
  .sheet-route {
    font-size: 12px;
  }

  .sheet-route {
    text-align: right;
  }

  .sheet-meta {
    grid-template-columns: 1fr 1fr;
    gap: 4px 10px;
    font-size: 12px;
    margin-bottom: 8px;
  }

  .sheet-scroll {
    overflow-x: visible;
  }

  .sheet table {
    table-layout: fixed;
    font-size: 11px;
  }

  .sheet th,
  .sheet td {
    min-width: 0;
    width: 12.5%;
    padding: 5px 1px;
    word-break: break-word;
  }

  .col-full {
    display: none;
  }

  .col-short {
    display: inline;
  }

  .sheet th {
    font-size: 10px;
    line-height: 1.15;
    font-weight: 700;
    padding: 6px 1px;
  }

  .sheet td.note {
    font-size: 10px;
    padding: 5px 4px;
  }

  .sheet td.time.split {
    line-height: 1.15;
  }

  .sheet td.time.split .t-a,
  .sheet td.time.split .t-b {
    display: block;
  }

  .sheet td.time.split .t-sep {
    display: none;
  }

  .sheet td.time.split .t-b {
    color: #444;
  }

  .handover td:first-child,
  .banner td {
    padding-left: 4px;
  }
}
