:root {
  --bg: #f4f7fb;
  --panel: #fff;
  --text: #1d2733;
  --muted: #6d7785;
  --line: #dce3ed;
  --primary: #1f6feb;
  --primary-dark: #1859bd;
  --danger: #d03333;
  --success: #0a7d45;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  overflow-x: hidden;
}

button,
input,
select {
  font: inherit;
}

button {
  border: 0;
  border-radius: 6px;
  background: var(--primary);
  color: #fff;
  cursor: pointer;
  font-weight: 700;
  line-height: 1.2;
  padding: 12px 16px;
  white-space: nowrap;
}

button:hover {
  background: var(--primary-dark);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

button.secondary {
  background: #344052;
}

button.danger {
  background: var(--danger);
}

button.fixed {
  background: var(--success);
}

button.release {
  background: #7a4f01;
}

button.icon-button {
  display: inline-grid;
  place-content: center;
  width: 38px;
  height: 38px;
  padding: 0;
  background: #eef4fc;
  color: var(--text);
  font-size: 24px;
  line-height: 1;
}

input,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 11px 12px;
  background: #fff;
  color: var(--text);
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
}

.auth-panel {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 380px;
  gap: 40px;
  align-items: center;
  width: min(980px, calc(100% - 32px));
  min-height: 100vh;
  margin: 0 auto;
}

.brand h1,
.topbar h1 {
  margin: 0;
  font-size: clamp(30px, 4vw, 42px);
  line-height: 1.15;
}

.brand p,
.section-head p,
.gate-panel p {
  color: var(--muted);
}

.brand p,
.gate-panel p {
  line-height: 1.55;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--primary);
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.form-card,
.gate-admin,
.activity,
.table-wrap,
.gate-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.form-card {
  display: grid;
  gap: 16px;
  padding: 24px;
  box-shadow: 0 16px 50px rgba(31, 44, 60, 0.08);
}

.dashboard {
  width: min(1120px, calc(100% - 32px));
  margin: 0 auto;
  padding: 24px 0 48px;
}

.topbar,
.gate-panel,
.section-head {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  align-items: flex-start;
}

.topbar {
  margin-bottom: 26px;
}

.gate-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.status-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(120px, 1fr));
  gap: 10px;
  max-width: 420px;
  margin-top: 16px;
}

.status-grid div {
  display: grid;
  gap: 4px;
  min-height: 72px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fbff;
  padding: 12px;
}

.status-grid span,
.status-grid small {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.status-grid strong {
  color: var(--text);
  font-size: 20px;
  overflow-wrap: anywhere;
}

.status-grid small {
  grid-column: 1 / -1;
}

.menu-shell {
  position: relative;
  flex: 0 0 auto;
}

.menu-toggle {
  display: inline-grid;
  place-content: center;
  gap: 5px;
  width: 46px;
  height: 46px;
  padding: 0;
  background: #e6edf7;
  color: var(--text);
}

.menu-toggle:hover {
  background: #d8e3f2;
}

.menu-toggle span {
  display: block;
  width: 22px;
  height: 2px;
  border-radius: 999px;
  background: currentColor;
}

.menu-popup {
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  z-index: 20;
  display: grid;
  gap: 6px;
  width: 220px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 16px 40px rgba(31, 44, 60, 0.18);
}

.menu-popup button {
  min-height: 42px;
  background: transparent;
  color: var(--text);
  text-align: left;
}

.menu-popup button:hover {
  background: #eef4fc;
}

.menu-popup button.active {
  background: var(--primary);
  color: #fff;
}

.page {
  display: grid;
  gap: 20px;
  min-width: 0;
}

.gate-panel {
  align-items: center;
  padding: 28px;
  min-width: 0;
}

.gate-panel h2 {
  margin: 0;
  font-size: clamp(40px, 6vw, 48px);
  line-height: 1.05;
  word-break: keep-all;
}

.gate-actions {
  align-items: end;
  min-width: min(100%, 520px);
}

.gate-select {
  min-width: 240px;
  flex: 1 1 240px;
}

.gate-admin,
.user-grid {
  display: grid;
  grid-template-columns: 160px minmax(160px, 1fr) auto;
  gap: 12px;
  align-items: end;
}

.gate-admin,
.activity,
.table-wrap {
  padding: 18px;
}

.gate-list,
.user-list {
  display: grid;
  gap: 10px;
}

.gate-card,
.user-card,
.admin-card {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: center;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.gate-card div,
.user-card div,
.admin-card div {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.gate-card .gate-edit,
.admin-card .admin-edit {
  flex: 1 1 260px;
  gap: 8px;
}

.gate-card .gate-edit label,
.admin-card .admin-edit label {
  max-width: 360px;
}

.gate-card-actions {
  display: flex;
  flex: 0 0 auto;
  gap: 8px;
}

.gate-card span,
.gate-card small,
.user-card span,
.user-card small,
.admin-card span,
.admin-card small {
  color: var(--muted);
}

.gate-card button,
.user-card button,
.admin-card button {
  flex: 0 0 auto;
}

.self-badge {
  flex: 0 0 auto;
  padding: 8px 10px;
  border-radius: 999px;
  background: #eef4fc;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(15, 23, 42, 0.42);
}

.modal-card {
  width: min(440px, 100%);
  grid-template-columns: 1fr;
  align-items: stretch;
  box-shadow: 0 24px 70px rgba(15, 23, 42, 0.24);
}

.modal-head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
}

.modal-head h2 {
  margin: 0;
}

.user-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr)) auto;
}

.form-card h2,
.section-head h2 {
  margin: 0;
}

.error-message,
.success-message {
  min-height: 20px;
  margin: 0;
  font-size: 14px;
  font-weight: 700;
}

.error-message {
  color: var(--danger);
}

.success-message {
  color: var(--success);
}

#gateLog {
  display: grid;
  gap: 8px;
  max-height: 260px;
  margin: 0;
  padding: 0 8px 0 20px;
  color: var(--muted);
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
}

#gateLog li {
  overflow-wrap: anywhere;
}

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

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

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

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

td button {
  padding: 8px 10px;
}

@media (max-width: 820px) {
  .auth-panel,
  .gate-panel,
  .section-head {
    display: grid;
  }

  #gateLog {
    max-height: 220px;
  }

  .auth-panel {
    grid-template-columns: 1fr;
    align-content: center;
    gap: 24px;
    padding: 32px 0;
    min-height: 100svh;
  }

  .brand h1,
  .topbar h1 {
    font-size: 34px;
  }

  .gate-actions {
    justify-content: start;
  }

  .dashboard {
    width: min(100% - 24px, 430px);
    padding-top: 16px;
  }

  .topbar {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 14px;
    margin-bottom: 18px;
  }

  .topbar > div:first-child {
    flex: 1 1 auto;
    min-width: 0;
  }

  .menu-shell {
    flex: 0 0 auto;
    margin-left: auto;
    align-self: flex-start;
  }

  .menu-toggle {
    width: 46px;
    min-width: 46px;
    min-height: 46px;
  }

  .gate-panel {
    align-items: stretch;
    padding: 22px;
  }

  .gate-actions {
    width: 100%;
    min-width: 0;
  }

  .gate-actions button,
  .gate-select {
    flex: 1 1 calc(50% - 8px);
  }

  .gate-admin,
  .user-grid {
    grid-template-columns: 1fr;
  }

  .gate-admin button,
  .user-grid button,
  .form-card button {
    width: 100%;
  }
}

@media (max-width: 520px) {
  body {
    background: #e8edf5;
  }

  button {
    width: 100%;
    min-height: 46px;
    padding: 12px 14px;
  }

  .auth-panel,
  .dashboard {
    width: min(100%, 430px);
    margin-right: auto;
    margin-left: auto;
  }

  .auth-panel {
    align-content: start;
    min-height: 100svh;
    padding: calc(env(safe-area-inset-top, 0px) + 28px) 18px 24px;
    background: linear-gradient(180deg, #eef5ff 0%, #fff 38%);
  }

  .brand {
    padding-top: 20px;
  }

  .brand p {
    margin-bottom: 0;
  }

  .form-card {
    border: 0;
    box-shadow: 0 18px 45px rgba(31, 44, 60, 0.12);
  }

  .dashboard {
    min-height: 100svh;
    padding: 0 0 calc(env(safe-area-inset-bottom, 0px) + 22px);
    background: #f7f9fc;
    box-shadow: 0 0 0 1px rgba(220, 227, 237, 0.7);
  }

  .topbar {
    position: sticky;
    top: 0;
    z-index: 15;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    width: calc(100% - 24px);
    min-height: 112px;
    margin: calc(env(safe-area-inset-top, 0px) + 8px) 12px 0;
    padding: 18px 18px 16px;
    border: 1px solid rgba(220, 227, 237, 0.85);
    border-radius: 22px;
    background: rgba(247, 251, 255, 0.96);
    box-shadow: 0 12px 30px rgba(31, 44, 60, 0.1);
    backdrop-filter: blur(14px);
  }

  .topbar > div:first-child {
    flex: 1 1 auto;
    min-width: 0;
  }

  .topbar h1 {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .form-card,
  .gate-admin,
  .activity,
  .table-wrap {
    padding: 14px;
  }

  .modal-backdrop {
    align-items: end;
    padding: 10px;
  }

  .modal-card {
    width: 100%;
    padding: 16px;
  }

  .gate-panel {
    margin: 12px 12px 0;
    padding: 20px;
    border: 0;
    border-radius: 20px;
    box-shadow: 0 14px 38px rgba(31, 44, 60, 0.1);
  }

  .brand h1,
  .topbar h1 {
    font-size: 28px;
  }

  .gate-panel h2 {
    font-size: 44px;
  }

  .eyebrow {
    margin-bottom: 5px;
    font-size: 11px;
    line-height: 1.4;
    overflow-wrap: anywhere;
  }

  .topbar .eyebrow {
    display: inline-block;
    max-width: 100%;
    padding: 1px 3px;
    background: rgba(29, 39, 51, 0.12);
    color: #2f3742;
    letter-spacing: 0.04em;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .page {
    gap: 14px;
    padding-bottom: 10px;
  }

  .page > .form-card,
  .page > .section-head,
  .page > .gate-admin,
  .page > .gate-list,
  .page > .user-grid,
  .page > .user-list,
  .page > .table-wrap {
    margin: 14px 12px 0;
  }

  .page > .form-card,
  .page > .gate-admin,
  .page > .gate-list,
  .page > .user-grid,
  .page > .user-list,
  .page > .table-wrap {
    border: 0;
    border-radius: 18px;
    background: var(--panel);
    box-shadow: 0 10px 28px rgba(31, 44, 60, 0.08);
  }

  .page > .gate-admin,
  .page > .user-grid {
    padding: 14px;
  }

  .page > .gate-list,
  .page > .user-list {
    padding: 10px;
  }

  .gate-card,
  .user-card,
  .admin-card {
    border: 0;
    padding: 12px;
  }

  .gate-card button,
  .user-card button,
  .admin-card button {
    width: auto;
    min-width: 72px;
    min-height: 42px;
    border-radius: 12px;
  }

  .page > .section-head {
    padding: 4px 4px 0;
  }

  .gate-panel p {
    margin-bottom: 0;
  }

  .gate-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    width: 100%;
    gap: 10px;
    margin-top: 10px;
  }

  .menu-shell {
    flex: 0 0 auto;
    justify-self: end;
    align-self: flex-start;
  }

  .menu-toggle {
    width: 56px;
    min-width: 56px;
    height: 56px;
    min-height: 56px;
    border-radius: 8px;
    background: #e8eef7;
  }

  .menu-toggle span {
    width: 25px;
    height: 2.5px;
  }

  .menu-popup {
    position: fixed;
    top: calc(env(safe-area-inset-top, 0px) + 126px);
    right: 12px;
    left: 12px;
    width: auto;
    border-radius: 16px;
    padding: 10px;
  }

  .gate-select {
    grid-column: 1 / -1;
    min-width: 0;
  }

  .gate-select select {
    min-height: 48px;
    border-radius: 12px;
  }

  .gate-actions button {
    min-height: 76px;
    border-radius: 18px;
    white-space: normal;
  }

  .section-head {
    gap: 12px;
  }

  .activity {
    margin: 0 12px;
    border: 0;
    border-radius: 18px;
    box-shadow: 0 10px 28px rgba(31, 44, 60, 0.08);
  }

  .section-head h2 {
    font-size: 18px;
  }

  .section-head button {
    min-height: 40px;
    border-radius: 12px;
  }

  #gateLog {
    max-height: 34svh;
    padding-right: 0;
  }

  th,
  td {
    padding: 10px 8px;
  }
}
