:root {
  color-scheme: light;
  --ink: #111827;
  --muted: #667085;
  --line: #d6dde7;
  --panel: #ffffff;
  --page: #eef2f7;
  --green: #087443;
  --green-soft: #e7f6ee;
  --red: #b42318;
  --red-soft: #fff1ef;
  --blue: #175cd3;
  --blue-soft: #e9f1ff;
  --amber: #a15c07;
  --amber-soft: #fff4d6;
  --soft: #f8fafc;
  --shadow: 0 14px 32px rgba(15, 23, 42, 0.08);
  --shadow-soft: 0 6px 16px rgba(15, 23, 42, 0.06);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(180deg, #dde7f3 0, var(--page) 240px),
    var(--page);
  color: var(--ink);
  font-family: Arial, Helvetica, sans-serif;
}

a {
  color: inherit;
}

button,
input,
select {
  font: inherit;
}

button,
.button-link {
  align-items: center;
  border: 0;
  border-radius: 7px;
  cursor: pointer;
  display: inline-flex;
  font-weight: 700;
  justify-content: center;
  min-height: 44px;
  padding: 0 16px;
  text-decoration: none;
  transition: transform 120ms ease, opacity 120ms ease, background 120ms ease;
}

button:active,
.button-link:active {
  transform: translateY(1px);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
  transform: none;
}

.app-shell {
  width: min(1220px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0 48px;
}

.app-header {
  align-items: center;
  background: rgba(255, 255, 255, 0.72);
  border: 1px solid rgba(214, 221, 231, 0.8);
  border-radius: 8px;
  box-shadow: var(--shadow-soft);
  backdrop-filter: blur(14px);
  display: flex;
  gap: 24px;
  justify-content: space-between;
  margin-bottom: 20px;
  min-height: 120px;
  padding: 24px;
}

.hero-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  margin: 15vh auto 0;
  max-width: 760px;
  padding: 32px;
}

.hero-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 24px;
}

.eyebrow {
  color: #194185;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  margin: 0 0 8px;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  font-size: clamp(28px, 4vw, 42px);
  line-height: 1.08;
  margin-bottom: 8px;
  max-width: 780px;
}

h2 {
  font-size: 20px;
  line-height: 1.2;
  margin-bottom: 6px;
}

.lead {
  color: var(--muted);
  font-size: 15px;
  line-height: 1.5;
  margin-bottom: 0;
  max-width: 720px;
}

.auth-panel {
  align-items: center;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow-soft);
  display: flex;
  gap: 18px;
  justify-content: space-between;
  margin-bottom: 16px;
  padding: 18px 20px;
}

.auth-panel p {
  color: var(--muted);
  margin-bottom: 0;
}

.auth-controls {
  align-items: end;
  display: grid;
  gap: 8px;
  grid-template-columns: minmax(180px, 240px) minmax(140px, 180px) auto auto auto;
}

.auth-controls button {
  background: #edf2f7;
  border: 1px solid #d8e0ea;
  color: #24313f;
}

.auth-controls #signInBtn {
  background: var(--blue);
  border-color: var(--blue);
  color: #fff;
}

body[data-page="admin"][data-admin="false"] .admin-content {
  display: none;
}

body[data-auth="signed-in"] #authPasswordInput,
body[data-auth="signed-in"] #authPhoneInput,
body[data-auth="signed-in"] #signInBtn,
body[data-auth="signed-in"] #registerBtn {
  display: none;
}

body[data-auth="signed-out"] #signOutBtn {
  display: none;
}

.gps-gate {
  align-items: center;
  background: #0f172a;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  box-shadow: var(--shadow);
  color: #fff;
  display: flex;
  gap: 18px;
  justify-content: space-between;
  margin-bottom: 18px;
  padding: 22px 24px;
}

.gps-gate.resolved {
  display: none;
}

.gps-gate .eyebrow,
.gps-gate p {
  color: #cbd5e1;
}

.gps-gate h2 {
  margin-bottom: 6px;
}

.workspace {
  display: grid;
  gap: 16px;
}

.user-grid {
  grid-template-columns: minmax(300px, 360px) 1fr;
}

.admin-grid {
  grid-template-columns: minmax(300px, 340px) 1fr 1fr;
}

.panel,
.history-section {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow-soft);
}

.panel {
  padding: 24px;
}

.panel-heading p,
.hint,
.message {
  color: var(--muted);
  line-height: 1.5;
}

.primary-action,
.button-link.primary {
  background: var(--blue);
  color: #fff;
  box-shadow: 0 8px 18px rgba(23, 92, 211, 0.22);
}

.button-link {
  background: #e9eef4;
  color: #22303c;
}

.divider {
  align-items: center;
  color: var(--muted);
  display: flex;
  font-size: 13px;
  gap: 10px;
  margin: 20px 0;
}

.divider::before,
.divider::after {
  background: var(--line);
  content: "";
  flex: 1;
  height: 1px;
}

.stack-form {
  display: grid;
  gap: 12px;
}

label {
  color: #334150;
  display: grid;
  font-size: 13px;
  font-weight: 700;
  gap: 6px;
}

input,
select {
  background: #fff;
  border: 1px solid #cbd5df;
  border-radius: 8px;
  color: var(--ink);
  min-height: 42px;
  padding: 9px 11px;
  width: 100%;
}

input:focus,
select:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(35, 100, 170, 0.16);
  outline: 0;
}

.stack-form button,
.history-actions button {
  background: #edf2f7;
  border: 1px solid #d8e0ea;
  color: #24313f;
}

.summary-list,
.current-session dl {
  display: grid;
  gap: 10px;
  margin: 20px 0 0;
}

.summary-list div,
.current-session dl div {
  align-items: center;
  background: var(--soft);
  border: 1px solid #e3e8ef;
  border-radius: 7px;
  display: flex;
  justify-content: space-between;
  padding: 11px 12px;
}

dt {
  color: var(--muted);
  font-size: 13px;
}

dd {
  font-weight: 800;
  margin: 0;
  text-align: right;
}

.check-panel {
  display: grid;
  gap: 16px;
}

.status-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.status-pill {
  background: var(--blue-soft);
  border: 1px solid #c9dbef;
  border-radius: 999px;
  color: #164879;
  display: inline-block;
  font-size: 14px;
  font-weight: 800;
  padding: 10px 14px;
}

.status-pill.allowed {
  background: var(--green-soft);
  border-color: #badfca;
  color: var(--green);
}

.status-pill.blocked {
  background: var(--red-soft);
  border-color: #f4c7c0;
  color: var(--red);
}

.status-pill.neutral {
  background: #eef2f6;
  border-color: #d8e0e8;
  color: #455363;
}

.distance-card {
  background:
    linear-gradient(180deg, #ffffff 0%, #f8fafc 100%);
  border: 1px solid var(--line);
  border-radius: 8px;
  min-height: 190px;
  padding: 26px;
}

.metric-label {
  color: var(--muted);
  font-weight: 700;
  margin-bottom: 14px;
}

.metric {
  font-size: clamp(48px, 8vw, 86px);
  font-weight: 900;
  line-height: 1;
}

.action-row {
  display: grid;
  gap: 12px;
  grid-template-columns: 1fr 1fr;
}

.check-button {
  color: #fff;
  font-size: 16px;
  min-height: 68px;
}

.check-button.in {
  background: var(--green);
}

.check-button.out {
  background: var(--red);
}

.message {
  background: #f8fafc;
  border-left: 4px solid var(--blue);
  margin: 0;
  padding: 12px 14px;
}

.current-session {
  border-top: 1px solid var(--line);
  padding-top: 18px;
}

.history-section {
  margin-top: 16px;
  padding: 24px;
}

.section-title {
  align-items: center;
  display: flex;
  gap: 18px;
  justify-content: space-between;
  margin-bottom: 16px;
}

.history-actions,
.filter-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
}

.filter-row {
  justify-content: flex-start;
  margin-bottom: 14px;
}

.filter-row label {
  width: min(320px, 100%);
}

.filter-row input[type="date"] {
  min-width: 170px;
}

.list {
  display: grid;
  gap: 8px;
  margin-top: 16px;
}

.list-item {
  align-items: center;
  background: var(--soft);
  border: 1px solid var(--line);
  border-radius: 8px;
  display: flex;
  gap: 10px;
  justify-content: space-between;
  padding: 10px 12px;
}

.list-item strong {
  display: block;
}

.list-item span {
  color: var(--muted);
  font-size: 13px;
}

.badge {
  border-radius: 999px;
  display: inline-block;
  font-size: 12px;
  font-weight: 800;
  padding: 5px 9px;
  white-space: nowrap;
}

.badge.ok {
  background: var(--green-soft);
  color: var(--green);
}

.badge.warn {
  background: var(--amber-soft);
  color: var(--amber);
}

.badge.bad {
  background: var(--red-soft);
  color: var(--red);
}

.table-action,
.ghost-button {
  background: #edf2f7;
  border: 1px solid #d8e0ea;
  color: #24313f;
  padding: 8px 12px;
}

.table-action {
  font-size: 13px;
  white-space: nowrap;
}

.edit-dialog {
  border: 0;
  border-radius: 8px;
  box-shadow: var(--shadow);
  max-width: min(560px, calc(100vw - 32px));
  padding: 0;
  width: 560px;
}

.edit-dialog::backdrop {
  background: rgba(15, 23, 42, 0.48);
}

.edit-form {
  background: var(--panel);
  padding: 24px;
}

.muted {
  color: var(--muted);
  margin-bottom: 0;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 18px;
}

.table-wrap {
  overflow-x: auto;
}

table {
  border-collapse: collapse;
  min-width: 880px;
  width: 100%;
}

body[data-page="admin"] .table-wrap table {
  min-width: 1120px;
}

th,
td {
  border-top: 1px solid var(--line);
  padding: 14px 12px;
  text-align: left;
  vertical-align: top;
}

body[data-page="admin"] th:last-child,
body[data-page="admin"] td:last-child {
  background: #fff;
  box-shadow: -10px 0 16px rgba(15, 23, 42, 0.08);
  position: sticky;
  right: 0;
  width: 96px;
  z-index: 1;
}

body[data-page="admin"] th:last-child {
  background: #f8fafc;
  z-index: 2;
}

body[data-page="admin"] th:nth-child(6),
body[data-page="admin"] td:nth-child(6) {
  min-width: 130px;
}

body[data-page="admin"] th:nth-child(7),
body[data-page="admin"] td:nth-child(7) {
  min-width: 150px;
}

th {
  background: #f8fafc;
  color: #475467;
  font-size: 13px;
  font-weight: 800;
}

td {
  color: #24313d;
}

tbody tr:hover td {
  background: #fbfdff;
}

.empty {
  color: var(--muted);
  text-align: center;
}

@media (max-width: 1040px) {
  .admin-grid,
  .user-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 820px) {
  .app-shell {
    width: min(100% - 20px, 640px);
    padding-top: 20px;
  }

  .app-header,
  .section-title,
  .gps-gate,
  .auth-panel {
    align-items: stretch;
    flex-direction: column;
  }

  .auth-controls {
    grid-template-columns: 1fr;
  }

}

@media (max-width: 520px) {
  .action-row {
    grid-template-columns: 1fr;
  }

  .panel,
  .history-section,
  .hero-panel {
    padding: 16px;
  }
}
