:root {
  --royal: #0033a0;
  --royal-deep: #00257a;
  --white: #ffffff;
  --bg: #ffffff;
  --card: #ffffff;
  --text: #0033a0;
  --text-strong: #001f66;
  --muted: #2f4a8a;
  --line: #9db0d9;
  --wash: #e8eefc;
  --warn-bg: #0033a0;
  --warn: #ffffff;
  --ok: #ffffff;
  --offline: #b00020;
  --danger: #b00020;
  --tap: 56px;
  --radius: 14px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 18px;
  line-height: 1.35;
}

body {
  padding:
    env(safe-area-inset-top)
    env(safe-area-inset-right)
    env(safe-area-inset-bottom)
    env(safe-area-inset-left);
}

#app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--white);
}

button,
input,
a.btn {
  font: inherit;
}

button,
a.btn {
  min-height: var(--tap);
  border: 0;
  border-radius: var(--radius);
  padding: 0 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  text-decoration: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

button:disabled,
a.btn.disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

input {
  width: 100%;
  min-height: var(--tap);
  border-radius: var(--radius);
  border: 2px solid var(--royal);
  background: var(--white);
  color: var(--text-strong);
  padding: 0 16px;
}

input::placeholder {
  color: var(--muted);
  opacity: 0.7;
}

input:focus {
  outline: 3px solid var(--royal);
  outline-offset: 2px;
}

.sync {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  font-size: 15px;
  font-weight: 650;
  color: var(--white);
  background: var(--royal);
}

.sync .dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--white);
  display: inline-block;
}

.sync.offline {
  background: var(--offline);
}

.banner {
  margin: 12px 16px 0;
  padding: 14px 16px;
  background: var(--royal);
  color: var(--white);
  border-radius: var(--radius);
  font-weight: 750;
  font-size: 1.05rem;
}

.header {
  padding: 16px 16px 8px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.header h1 {
  margin: 0;
  font-size: 1.45rem;
  letter-spacing: 0.01em;
  color: var(--royal);
}

.header .sub {
  color: var(--muted);
  font-size: 16px;
  margin-top: 2px;
}

.ghost {
  background: transparent;
  color: var(--royal);
  min-width: var(--tap);
  padding: 0 10px;
  font-weight: 750;
}

.list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 12px 16px 24px;
}

.trip-card {
  display: block;
  background: var(--white);
  border-radius: var(--radius);
  padding: 18px 16px;
  min-height: 88px;
  color: var(--royal);
  text-decoration: none;
  border: 2px solid var(--royal);
}

.trip-card .num {
  font-size: 2.15rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  font-variant-numeric: tabular-nums;
  color: var(--royal);
}

.trip-card .meta {
  color: var(--muted);
  margin-top: 6px;
  font-size: 16px;
}

.trip-card .changed {
  color: var(--royal);
  font-weight: 750;
  margin-top: 8px;
}

.screen {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.login {
  padding: 24px 16px;
}

.login h1 {
  margin: 8px 0 4px;
  font-size: 2rem;
  color: var(--royal);
}

.login p.lead {
  color: var(--muted);
  margin: 0 0 24px;
}

.board {
  padding: 0 16px 24px;
}

.route-block {
  margin: 16px 0 24px;
}

.route-block h2 {
  margin: 0 0 4px;
  font-size: 1.25rem;
  color: var(--royal);
}

.stop-group {
  margin-top: 12px;
  border: 2px solid var(--royal);
  border-radius: var(--radius);
  padding: 12px 12px 4px;
  background: var(--white);
}

.stop-head h3 {
  margin: 4px 0;
  font-size: 1.35rem;
  color: var(--royal);
}

.stop-seq {
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.stop-group .trip-card {
  margin: 10px 0;
}

.users {
  margin: 8px 0 20px;
}

.users h2 {
  margin: 0 0 4px;
  font-size: 1.35rem;
  color: var(--royal);
}

.users h3 {
  margin: 16px 0 8px;
  font-size: 1rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

.user-group + .user-group {
  margin-top: 8px;
}

.user-card {
  width: 100%;
  display: block;
  text-align: left;
  background: var(--white);
  color: inherit;
  border: 2px solid var(--royal);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 10px;
  min-height: var(--tap);
}

.user-card:active {
  background: var(--wash);
}

.user-top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.user-name {
  font-weight: 800;
  font-size: 1.15rem;
  color: var(--royal);
}

.user-pin {
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.06em;
  color: var(--royal);
  white-space: nowrap;
}

.user-meta {
  color: var(--muted);
  margin-top: 4px;
  font-size: 15px;
}

.platform {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 12px 0 16px;
}

.pill {
  font-size: 13px;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--wash);
  color: var(--muted);
  border: 1px solid var(--line);
}

.pill.ok {
  color: var(--royal);
  border-color: var(--royal);
}

.pill.off {
  opacity: 0.7;
}

.hint hr {
  border: 0;
  border-top: 1px solid var(--line);
  margin: 14px 0;
}

.field {
  margin-bottom: 14px;
}

.field label {
  display: block;
  font-size: 15px;
  font-weight: 650;
  color: var(--royal);
  margin-bottom: 6px;
}

.primary {
  width: 100%;
  background: var(--royal);
  color: var(--white);
  font-weight: 750;
  margin-top: 8px;
}

.primary:active {
  background: var(--royal-deep);
}

.error {
  color: var(--danger);
  margin: 8px 0 0;
  min-height: 1.3em;
  font-weight: 650;
}

.hint {
  margin-top: 28px;
  padding: 16px;
  background: var(--white);
  border: 2px solid var(--line);
  border-radius: var(--radius);
  color: var(--muted);
  font-size: 15px;
}

.hint a {
  color: var(--royal);
  font-weight: 650;
}

.tabs {
  display: flex;
  gap: 8px;
  padding: 0 16px;
}

.tabs button {
  flex: 1;
  background: var(--white);
  color: var(--royal);
  border: 2px solid var(--royal);
  font-weight: 650;
}

.tabs button.active {
  background: var(--royal);
  color: var(--white);
  font-weight: 800;
}

.stop {
  background: var(--white);
  border: 2px solid var(--royal);
  border-radius: var(--radius);
  padding: 16px;
}

.stop.changed {
  box-shadow: inset 6px 0 0 var(--royal);
}

.stop h2 {
  margin: 0;
  font-size: 1.3rem;
  color: var(--royal);
}

.stop .addr {
  color: var(--muted);
  margin: 6px 0 14px;
}

.facts {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px 10px;
}

.facts dt {
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
  margin: 0;
}

.facts dd {
  margin: 2px 0 0;
  font-weight: 800;
  font-size: 1.1rem;
  color: var(--text-strong);
}

.row-actions {
  display: flex;
  gap: 10px;
  margin-top: 16px;
  align-items: stretch;
}

.window {
  flex: 1;
  background: var(--wash);
  border-radius: var(--radius);
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-height: var(--tap);
  color: var(--text-strong);
  font-weight: 750;
}

.window span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
}

.maps {
  background: var(--royal);
  color: var(--white);
  font-weight: 750;
  flex: 0 0 auto;
  min-width: 132px;
}

.notes {
  white-space: pre-wrap;
  background: var(--white);
  border-radius: var(--radius);
  padding: 8px 0 0;
  min-height: 80px;
  color: var(--text-strong);
  font-size: 1.05rem;
}

.changelog {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 0;
  padding: 0;
}

.changelog li {
  list-style: none;
  background: var(--white);
  border: 2px solid var(--royal);
  border-radius: var(--radius);
  padding: 14px 16px;
  color: var(--text-strong);
}

.changelog .meta {
  color: var(--muted);
  margin-top: 4px;
}

.status-block {
  padding: 8px 16px 24px;
}

.status-block h3 {
  margin: 8px 0;
  font-size: 14px;
  color: var(--muted);
  font-weight: 650;
}

.status-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.status-grid button {
  background: var(--white);
  color: var(--royal);
  border: 2px solid var(--royal);
  flex-direction: column;
  padding: 10px;
  font-weight: 750;
}

.status-grid button.current {
  background: var(--royal);
  color: var(--white);
}

.status-grid button.current small {
  color: var(--white);
}

.status-grid small {
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
}

.exception-panel {
  margin-top: 14px;
  padding: 16px;
  border: 2px solid var(--royal);
  border-radius: var(--radius);
  background: var(--white);
}

.exception-panel p {
  margin: 0 0 12px;
  font-weight: 700;
  color: var(--royal);
}

.reason-grid {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 14px;
}

.reason-grid label {
  min-height: var(--tap);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 12px;
  border: 2px solid var(--line);
  border-radius: var(--radius);
  font-weight: 650;
  color: var(--text-strong);
}

.reason-grid input {
  width: auto;
  min-height: 24px;
  accent-color: var(--royal);
}

.empty {
  color: var(--muted);
  padding: 24px 16px;
}

.driver-chat-card {
  margin: 0 16px 12px;
  border: 2px solid var(--royal);
  border-radius: var(--radius);
  background: var(--white);
  padding: 12px;
}

.driver-chat-toggle {
  width: 100%;
  min-height: 56px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  border: 0;
  background: transparent;
  color: var(--royal);
  padding: 4px 0;
  text-align: left;
}

.driver-chat-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.driver-chat-head h3 {
  margin: 0;
  color: var(--royal);
}

.driver-chat-card .desk-chat-form textarea {
  width: auto;
}

.notify-panel {
  margin: 0 16px 8px;
  padding: 14px 16px;
  border: 2px solid var(--royal);
  border-radius: var(--radius);
  background: var(--white);
}

.notify-panel h3 {
  margin: 0 0 8px;
  color: var(--royal);
  font-size: 1.05rem;
}

.notify-note {
  color: var(--muted);
  font-size: 15px;
  margin: 0 0 10px;
}

.notify-panel .primary,
.notify-panel .ghost {
  width: 100%;
  margin-top: 8px;
  border: 2px solid var(--royal);
}

.sms-log {
  margin-top: 12px;
  color: var(--text-strong);
  font-size: 14px;
}

.sms-log p {
  margin: 0 0 8px;
}

body.desk #app {
  max-width: 1100px;
}

.desk-jump {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.desk-jump h1 {
  margin: 0;
}

.desk-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  padding: 20px 16px 8px;
}

.desk-top-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.desk-login {
  margin: 8px 16px 32px;
  max-width: 420px;
  border: 2px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  display: grid;
  gap: 14px;
}

.desk-login .primary {
  width: 100%;
}

.desk-grid {
  display: grid;
  grid-template-columns: minmax(280px, 1fr) minmax(320px, 1.2fr);
  gap: 16px;
  padding: 8px 16px 16px;
}

.desk-compose,
.desk-roster,
.desk-log {
  border: 2px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  background: var(--white);
}

.desk-compose h2,
.desk-roster h2,
.desk-log h2 {
  margin: 0 0 12px;
  color: var(--royal);
}

.desk-templates,
.desk-quick,
.desk-channels {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.desk-templates .ghost,
.desk-quick .ghost {
  min-height: 40px;
  padding: 0 12px;
  border: 2px solid var(--royal);
  background: var(--white);
  color: var(--royal);
}

.desk-compose .field,
.desk-roster .field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 12px;
}

.desk-compose input,
.desk-compose textarea,
.desk-compose select,
.desk-roster input {
  width: 100%;
  border: 2px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  color: var(--text-strong);
}

.desk-channels label {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-strong);
  font-size: 15px;
}

.desk-count,
.desk-ok {
  margin: 0 0 12px;
  color: var(--text-strong);
  font-size: 15px;
}

.desk-ok {
  color: var(--royal-deep);
  font-weight: 650;
}

.desk-roster-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  margin-bottom: 10px;
}

.desk-roster-head h2 {
  margin: 0;
}

.desk-list {
  max-height: 58vh;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.desk-row {
  display: grid;
  grid-template-columns: 22px 1fr;
  gap: 10px;
  align-items: center;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 10px;
}

.desk-row input {
  width: auto;
}

.desk-open {
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-rows: auto auto;
  gap: 2px 10px;
  width: 100%;
  min-height: var(--tap);
  padding: 8px 4px;
  border: 0;
  background: transparent;
  text-align: left;
  justify-content: stretch;
}

.desk-open:hover,
.desk-open:focus-visible {
  background: var(--wash);
  border-radius: 8px;
}

.desk-name {
  font-weight: 700;
  color: var(--text-strong);
}

.desk-open .desk-name {
  grid-column: 1;
}

.desk-open .desk-meta {
  grid-column: 1;
}

.desk-meta {
  color: var(--muted);
  font-size: 14px;
}

.desk-flags {
  grid-column: 2;
  grid-row: 1 / span 2;
  display: flex;
  flex-direction: column;
  gap: 4px;
  align-items: flex-end;
}

.desk-modal {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 24px 16px;
}

.desk-modal-back {
  position: absolute;
  inset: 0;
  border: 0;
  border-radius: 0;
  background: rgb(0 31 102 / 45%);
  min-height: 0;
}

.desk-modal-card {
  position: relative;
  width: min(760px, 100%);
  max-height: calc(100dvh - 48px);
  overflow: auto;
  background: var(--white);
  border: 2px solid var(--royal);
  border-radius: var(--radius);
  padding: 16px;
}

.desk-modal-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
  margin-bottom: 12px;
}

.desk-modal-head h2 {
  margin: 0;
  color: var(--royal);
}

.desk-modal-actions {
  display: flex;
  gap: 8px;
}

.desk-loads {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.desk-stop {
  border: 2px solid var(--royal);
  border-radius: var(--radius);
  padding: 12px 12px 4px;
}

.desk-stop .trip-card {
  margin: 10px 0;
}

.desk-queue {
  margin: 0 16px 16px;
  border: 2px solid var(--royal);
  border-radius: var(--radius);
  padding: 16px;
}

.desk-queue h2 {
  margin: 0 0 10px;
  color: var(--royal);
}

.desk-queue-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 220px;
  overflow: auto;
}

.desk-queue-item {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  width: 100%;
  min-height: 48px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  background: var(--white);
  color: var(--text-strong);
  text-align: left;
}

.desk-queue-item.unread {
  border-color: var(--royal);
  background: var(--wash);
}

.desk-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.desk-tabs .ghost.on {
  background: var(--royal);
  color: var(--white);
}

.desk-chat {
  display: flex;
  flex-direction: column;
  min-height: 320px;
}

.desk-chat-log {
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 1;
  min-height: 220px;
  max-height: 46vh;
  overflow: auto;
  margin-bottom: 10px;
  padding: 4px 2px;
}

.desk-bubble {
  max-width: 85%;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--line);
}

.desk-bubble.in {
  align-self: flex-start;
  background: var(--wash);
}

.desk-bubble.out {
  align-self: flex-end;
  background: var(--white);
  border-color: var(--royal);
}

.desk-chat-form {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  position: sticky;
  bottom: 0;
  background: var(--white);
  padding-top: 8px;
}

.desk-chat-form textarea {
  flex: 1 1 auto;
  width: auto;
  min-width: 0;
  min-height: 48px;
  max-height: 140px;
  resize: none;
  border: 2px solid var(--royal);
  border-radius: 12px;
  padding: 10px 12px;
  color: var(--text-strong);
  font: inherit;
  line-height: 1.35;
  background: var(--white);
}

.desk-chat-form textarea:focus {
  outline: 3px solid var(--royal);
  outline-offset: 2px;
}

.desk-chat-form textarea:disabled {
  opacity: 0.45;
}

.desk-chat-send {
  flex: 0 0 auto;
  width: auto;
  min-width: 72px;
  min-height: 48px;
  margin: 0;
  padding: 0 16px;
  border: 0;
  border-radius: 12px;
  background: var(--royal);
  color: var(--white);
  font-weight: 700;
}

.desk-chat-send:disabled {
  opacity: 0.4;
}

.desk-map {
  width: 100%;
  height: 280px;
  border: 2px solid var(--line);
  border-radius: 10px;
}

.desk-log {
  margin: 0 16px 24px;
}

.desk-log ol {
  margin: 0;
  padding-left: 18px;
}

.desk-log li {
  margin-bottom: 10px;
}

.desk-log .desk-meta {
  display: block;
}

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