:root {
  --bg: #14151f;
  --surface: #1c1d2b;
  --surface-2: #262838;
  --text: #f2f3f8;
  --muted: #8b8fa8;
  --gate: #4fd17a;
  --wait: #f5cd47;
  --card-text: #15161f;
  --danger: #ff6b5e;
  --accent: #6c8cff;
  --radius: 10px;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  -webkit-tap-highlight-color: transparent;
}

[hidden] { display: none !important; }

h1 { margin: 0; font-size: 24px; font-weight: 700; }
h2 { margin: 0 0 16px; font-size: 19px; font-weight: 700; }

.screen { height: 100dvh; display: flex; flex-direction: column; }

/* ---------- формы ---------- */

.form-screen {
  max-width: 440px;
  margin: 0 auto;
  padding: 48px 20px 24px;
  overflow-y: auto;
}

.hint { margin: 8px 0 28px; color: var(--muted); }

form, .field { display: flex; flex-direction: column; gap: 10px; }

label { font-size: 14px; color: var(--muted); }

input {
  width: 100%;
  padding: 14px;
  border: 1px solid var(--surface-2);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 18px;
}
input:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }
#plate { text-transform: uppercase; }
#plate::placeholder { text-transform: none; }

.error { margin: 0; color: var(--danger); font-size: 14px; }

.btn {
  width: 100%;
  min-height: 52px;
  padding: 12px 16px;
  border: 0;
  border-radius: var(--radius);
  font: inherit;
  font-size: 17px;
  font-weight: 700;
  cursor: pointer;
}
.btn:disabled { opacity: .5; cursor: default; }
.btn-primary { background: var(--gate); color: var(--card-text); }
.btn-danger { background: var(--danger); color: var(--card-text); }
.btn-link {
  width: auto;
  min-height: 0;
  padding: 6px 0;
  background: none;
  color: var(--accent);
  font-size: 14px;
  font-weight: 500;
}
.form-screen > .btn-link { align-self: center; margin-top: 16px; padding: 10px; font-size: 16px; }

.plate-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 24px; }
.plate-list:empty { display: none; }

.plate-option {
  display: flex;
  align-items: baseline;
  gap: 6px;
  width: 100%;
  min-height: 56px;
  padding: 12px 16px;
  border: 1px solid var(--surface-2);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.plate-option:active { background: var(--surface-2); }

.plate-main { font-size: 20px; font-weight: 700; letter-spacing: .02em; }
.plate-region { font-size: 13px; font-weight: 600; }

/* ---------- доска ---------- */

.board-header { padding: 24px 16px 12px; }
.title-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }

.legend { display: flex; gap: 14px; margin-top: 12px; font-size: 13px; color: var(--text); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.dot { width: 10px; height: 10px; border-radius: 3px; }
.dot-gate { background: var(--gate); }
.dot-wait { background: var(--wait); }

.board {
  flex: 1;
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 4px 16px 16px;
  overflow: auto;
  scroll-padding: 0 16px;
}

.gate {
  flex: 0 0 148px;
  padding: 8px;
  border-radius: 12px;
  background: var(--surface);
}
.gate-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 6px;
  padding: 2px 4px 8px;
}
.gate-title { font-size: 15px; font-weight: 700; white-space: nowrap; }
.gate-count { font-size: 11px; color: var(--muted); white-space: nowrap; }

.gate-empty {
  padding: 18px 8px;
  border: 1px dashed var(--surface-2);
  border-radius: var(--radius);
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}

.card {
  padding: 10px 12px;
  border-radius: var(--radius);
  background: var(--wait);
  color: var(--card-text);
}
.card + .card { margin-top: 6px; }
.card.at-gate { background: var(--gate); }
.card.mine { box-shadow: 0 0 0 3px var(--text); }
.card .plate-main { font-size: 18px; }
.card-plate { display: flex; align-items: baseline; gap: 5px; white-space: nowrap; }
.card-name { margin-top: 4px; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- нижняя панель ---------- */

.action-bar {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px 16px calc(14px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--surface-2);
  background: var(--surface);
}
.me-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.me-info { font-size: 14px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.me-info b { color: var(--text); }
.status { margin: 0; font-size: 16px; font-weight: 600; }

/* ---------- выбор диапазона ---------- */

.sheet-backdrop {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgba(0, 0, 0, .6);
}
.sheet {
  width: 100%;
  max-width: 480px;
  max-height: 90dvh;
  overflow-y: auto;
  padding: 24px 16px calc(12px + env(safe-area-inset-bottom));
  border-radius: 18px 18px 0 0;
  background: var(--surface);
  text-align: center;
}
.range-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 8px; }
.range-option { background: var(--surface-2); color: var(--text); }
.range-option small { display: block; margin-top: 2px; font-size: 13px; font-weight: 400; color: var(--muted); }
.sheet .btn-link { padding: 12px; font-size: 16px; }

/* ---------- диспетчер ---------- */

.gate.closed { opacity: .55; }
.gate-toggle { display: block; width: 100%; margin-top: 6px; padding: 8px 0 2px; font-size: 13px; }
.card[data-user] { cursor: pointer; }
.sheet-label { margin: 18px 0 8px; font-size: 14px; color: var(--muted); }
.gate-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 8px; }
.gate-grid .btn { min-height: 56px; padding: 8px 4px; }
.gate-grid small { font-size: 11px; }
