:root {
  --bg: #f4f7fb;
  --card: #ffffff;
  --ink: #162033;
  --muted: #64748b;
  --line: #dbe3ee;
  --brand: #173b69;
  --brand2: #215a96;
  --ok: #18794e;
  --warn: #9a6700;
  --bad: #b42318;
}
* { box-sizing: border-box; }
body { margin:0; font-family: Arial, Helvetica, sans-serif; color:var(--ink); background:var(--bg); }
a { color:var(--brand2); text-decoration:none; }
a:hover { text-decoration:underline; }
.topbar { background:var(--brand); color:#fff; padding:14px 20px; }
.topbar .wrap { display:flex; align-items:center; justify-content:space-between; gap:18px; }
.brand { font-weight:700; letter-spacing:.2px; }
.nav { display:flex; gap:14px; align-items:center; flex-wrap:wrap; }
.nav a, .nav button { color:#fff; background:none; border:0; padding:0; font:inherit; cursor:pointer; }
.wrap { max-width:1020px; margin:0 auto; padding:0 18px; }
main.wrap { padding-top:26px; padding-bottom:50px; }
.card { background:var(--card); border:1px solid var(--line); border-radius:12px; padding:22px; margin:0 0 20px; box-shadow:0 4px 14px rgba(20,40,70,.04); }
.card.narrow { max-width:520px; margin:40px auto; }
h1 { margin:0 0 18px; font-size:26px; }
h2 { margin:0 0 14px; font-size:20px; }
.grid { display:grid; grid-template-columns:repeat(2,minmax(0,1fr)); gap:16px; }
.grid-4 { display:grid; grid-template-columns:repeat(4,minmax(0,1fr)); gap:12px; }
label { display:block; font-weight:700; font-size:14px; margin-bottom:6px; }
input, select { width:100%; padding:11px 12px; border:1px solid #b9c6d7; border-radius:8px; font-size:16px; background:#fff; }
button, .button { display:inline-block; border:0; border-radius:8px; background:var(--brand2); color:#fff; padding:11px 16px; font-size:15px; font-weight:700; cursor:pointer; text-decoration:none; }
.button.secondary, button.secondary { background:#e9eef6; color:var(--ink); }
.button.danger, button.danger { background:var(--bad); }
.actions { display:flex; gap:10px; align-items:center; flex-wrap:wrap; margin-top:18px; }
.muted { color:var(--muted); }
.notice { border-radius:9px; padding:12px 14px; margin-bottom:16px; border:1px solid; }
.notice.ok { background:#effaf5; border-color:#9fd7bf; color:#125a3c; }
.notice.error { background:#fff1f0; border-color:#f1aaa5; color:#8f1d15; }
.notice.info { background:#eff6ff; border-color:#aac8ef; color:#173b69; }
.kpi { background:#fff; border:1px solid var(--line); border-radius:10px; padding:16px; }
.kpi strong { display:block; font-size:24px; margin-top:4px; }
table { width:100%; border-collapse:collapse; }
th, td { border-bottom:1px solid var(--line); padding:11px 8px; text-align:left; vertical-align:top; }
th { font-size:13px; color:var(--muted); }
.badge { display:inline-block; padding:4px 8px; border-radius:999px; font-size:12px; font-weight:700; background:#eef2f7; }
.badge.active { background:#e6f7ef; color:var(--ok); }
.badge.scheduled { background:#e9f2ff; color:#245b97; }
.badge.expired { background:#f2f4f7; color:#667085; }
.badge.failed { background:#fff0ee; color:var(--bad); }
.code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size:20px; letter-spacing:2px; font-weight:700; }
.summary-row { display:flex; justify-content:space-between; gap:18px; padding:10px 0; border-bottom:1px solid var(--line); }
.summary-row:last-child { border-bottom:0; }
.inline-form { display:inline; }
.small { font-size:13px; }
@media (max-width:760px) {
  .grid, .grid-4 { grid-template-columns:1fr; }
  .topbar .wrap { align-items:flex-start; flex-direction:column; }
  table { font-size:14px; }
  th:nth-child(4), td:nth-child(4) { display:none; }
}


/* ===== Mobile-first iLOQ enhancements ===== */

/* Better touch targets everywhere */
button,
.button,
input,
select {
  min-height: 48px;
}

button,
.button {
  touch-action: manipulation;
}

/* Unit R / S large touch selector */
.unit-picker-wrap {
  grid-column: 1 / -1;
}

.unit-picker {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-top: 8px;
}

.unit-picker label {
  margin: 0;
  cursor: pointer;
}

.unit-picker input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
  width: 1px;
  height: 1px;
}

.unit-picker span {
  display: flex;
  min-height: 58px;
  align-items: center;
  justify-content: center;
  border: 2px solid #b9c6d7;
  border-radius: 10px;
  background: #fff;
  color: var(--ink);
  font-size: 17px;
  font-weight: 700;
  transition: border-color .15s ease, background .15s ease, color .15s ease;
}

.unit-picker input:checked + span {
  border-color: var(--brand2);
  background: var(--brand2);
  color: #fff;
}

.unit-picker input:focus-visible + span {
  outline: 3px solid rgba(33,90,150,.25);
  outline-offset: 2px;
}

/* Generated PIN should be impossible to miss */
.door-code-row {
  align-items: center;
}

.code {
  font-size: 34px;
  letter-spacing: 5px;
  line-height: 1.15;
}

.activation-notice {
  line-height: 1.45;
}

/* Tablet / phone */
@media (max-width: 760px) {

  body {
    font-size: 16px;
  }

  .wrap {
    padding-left: 14px;
    padding-right: 14px;
  }

  main.wrap {
    padding-top: 16px;
    padding-bottom: max(40px, env(safe-area-inset-bottom));
  }

  .card {
    padding: 17px;
    margin-bottom: 14px;
    border-radius: 14px;
  }

  .card.narrow {
    margin: 18px auto;
  }

  h1 {
    font-size: 24px;
    line-height: 1.2;
    margin-bottom: 15px;
  }

  h2 {
    font-size: 19px;
  }

  /*
   * Keep header compact.
   * Navigation stays one line and can scroll sideways on small phones.
   */
  .topbar {
    padding: 11px 0;
  }

  .topbar .wrap {
    flex-direction: column;
    align-items: stretch;
    gap: 9px;
  }

  .brand {
    font-size: 17px;
  }

  .nav {
    width: 100%;
    flex-wrap: nowrap;
    gap: 18px;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 3px 0 5px;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }

  .nav::-webkit-scrollbar {
    display: none;
  }

  .nav a,
  .nav button,
  .nav span {
    flex: 0 0 auto;
    white-space: nowrap;
  }

  /* User name is not essential on a small screen */
  .nav > span {
    display: none;
  }

  /*
   * Main forms stack cleanly.
   * KPI cards remain 2 x 2 instead of becoming four long rows.
   */
  .grid {
    grid-template-columns: 1fr;
    gap: 14px;
  }

  .grid-4 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 9px;
  }

  .kpi {
    padding: 13px;
  }

  .kpi strong {
    font-size: 26px;
  }

  label {
    font-size: 15px;
  }

  input,
  select {
    min-height: 52px;
    padding: 12px;
    border-radius: 10px;
    font-size: 16px;
  }

  button,
  .button {
    min-height: 50px;
    padding: 13px 17px;
    border-radius: 10px;
    font-size: 16px;
  }

  /*
   * Content-page actions become large, easy touch targets.
   */
  .actions {
    align-items: stretch;
    gap: 9px;
  }

  .actions > h1 {
    flex-basis: 100%;
    width: 100%;
  }

  .actions > .button,
  .actions > button {
    flex: 1 1 180px;
    text-align: center;
  }

  /*
   * Confirmation / reservation details read vertically.
   */
  .summary-row {
    flex-direction: column;
    gap: 5px;
    padding: 11px 0;
  }

  .summary-row > strong {
    color: var(--muted);
    font-size: 13px;
  }

  .door-code-row {
    gap: 8px;
  }

  .door-code-row .code {
    color: var(--brand);
    font-size: 40px;
    letter-spacing: 6px;
  }

  /*
   * Reservation tables become phone-friendly cards.
   * This applies only to Recent Access / History, not the Users table.
   */
  .reservation-table,
  .reservation-table tbody {
    display: block;
    width: 100%;
  }

  .reservation-table thead {
    display: none;
  }

  .reservation-table tr {
    position: relative;
    display: block;
    margin-bottom: 12px;
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: #fff;
  }

  .reservation-table td {
    display: block;
    border: 0;
    padding: 3px 0;
  }

  .reservation-table td:nth-child(1) {
    padding-right: 90px;
    font-size: 16px;
    font-weight: 700;
  }

  .reservation-table td:nth-child(2) {
    margin-top: 6px;
    font-weight: 700;
  }

  .reservation-table td:nth-child(3) {
    margin-top: 4px;
    line-height: 1.4;
  }

  .reservation-table td:nth-child(4) {
    display: none;
  }

  .reservation-table td:nth-child(5) {
    position: absolute;
    top: 13px;
    right: 13px;
    padding: 0;
  }

  .reservation-table .badge {
    font-size: 12px;
    padding: 5px 9px;
  }
}

/* Very small phones */
@media (max-width: 390px) {

  .wrap {
    padding-left: 11px;
    padding-right: 11px;
  }

  .card {
    padding: 15px;
  }

  .unit-picker {
    gap: 8px;
  }

  .unit-picker span {
    min-height: 54px;
  }

  .door-code-row .code {
    font-size: 36px;
    letter-spacing: 5px;
  }
}


/* ===== iPhone final mobile refinements ===== */

@media (max-width: 760px) {

  /*
   * Leave enough scroll room for Safari's floating bottom toolbar
   * so the final history/reservation card can scroll completely
   * above the browser controls.
   */
  main.wrap {
    padding-bottom: calc(120px + env(safe-area-inset-bottom));
  }

  /*
   * Make an unselected unit choice visually obvious.
   */
  .unit-picker span {
    background: #fff;
  }
}


/* ===== Reservation cancellation controls ===== */

.badge.cancelled {
  background: #fff4e5;
  color: #8a4b08;
}

.cancel-form {
  margin-top: 7px;
}

.cancel-link {
  display: block;
  min-height: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: none;
  color: var(--bad);
  font-size: 13px;
  font-weight: 700;
  line-height: 1.3;
  text-decoration: underline;
  cursor: pointer;
}

.cancel-link:hover {
  background: none;
  color: #8f1d15;
}

@media (max-width: 760px) {

  .reservation-table td:nth-child(5) {
    text-align: right;
  }

  .reservation-table .cancel-form {
    margin-top: 7px;
  }

  .reservation-table .cancel-link {
    margin-left: auto;
  }
}


/* ===== Reservation status and cancellation controls ===== */

.badge.access_removed {
  background: #eef2f7;
  color: #475467;
}

.badge.cancelled {
  background: #fff4e5;
  color: #8a4b08;
}

.cancel-form {
  margin-top: 7px;
}

.cancel-link {
  display: block;
  min-height: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: none;
  color: var(--bad);
  font-size: 13px;
  font-weight: 700;
  line-height: 1.3;
  text-decoration: underline;
  cursor: pointer;
}

.cancel-link:hover {
  background: none;
  color: #8f1d15;
}

@media (max-width: 760px) {

  .reservation-table td:nth-child(5) {
    text-align: right;
  }

  .reservation-table .cancel-link {
    margin-left: auto;
  }
}
