:root {
  --font-main: "Montserrat", ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --bg-0: #f7fbff;
  --bg-1: #eef6ff;
  --bg-2: #f8f5ff;
  --glass: rgba(255, 255, 255, 0.72);
  --glass-strong: rgba(255, 255, 255, 0.86);
  --glass-soft: rgba(255, 255, 255, 0.48);
  --line: rgba(255, 255, 255, 0.62);
  --line-dark: rgba(16, 24, 40, 0.08);
  --text: #172033;
  --muted: #6c7486;
  --primary: #3478f6;
  --primary-2: #7c5cff;
  --cyan: #38c9e8;
  --success: #1f9d70;
  --warning: #c98a19;
  --danger: #df4b5f;
  --radius-xl: 32px;
  --radius-lg: 24px;
  --radius-md: 18px;
  --radius-sm: 14px;
  --shadow-soft: 0 24px 70px rgba(32, 57, 102, 0.12);
  --shadow-card: 0 18px 45px rgba(32, 57, 102, 0.10), inset 0 1px 0 rgba(255, 255, 255, 0.78);
  --shadow-button: 0 12px 24px rgba(52, 120, 246, 0.26);
  color: var(--text);
  font-family: var(--font-main);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  overflow-x: hidden;
  background:
    radial-gradient(circle at 8% 10%, rgba(116, 199, 255, 0.42), transparent 34%),
    radial-gradient(circle at 86% 4%, rgba(160, 132, 255, 0.32), transparent 31%),
    linear-gradient(145deg, var(--bg-0), var(--bg-1) 46%, var(--bg-2));
  color: var(--text);
  font-family: var(--font-main);
}

body::before {
  position: fixed;
  inset: 0;
  z-index: -1;
  background-image: linear-gradient(rgba(255, 255, 255, 0.28) 1px, transparent 1px), linear-gradient(90deg, rgba(255, 255, 255, 0.28) 1px, transparent 1px);
  background-size: 54px 54px;
  content: "";
  mask-image: linear-gradient(to bottom, #000, transparent 82%);
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  display: grid;
  width: 100%;
  min-height: 100vh;
  grid-template-columns: 292px minmax(0, 1fr);
  gap: 24px;
  padding: 24px;
}

.auth-gate {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 24px;
}

.auth-card {
  width: min(720px, 100%);
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius-xl);
  background: var(--glass);
  box-shadow: var(--shadow-soft), inset 0 1px 0 rgba(255, 255, 255, 0.78);
  padding: clamp(22px, 4vw, 34px);
  backdrop-filter: blur(28px) saturate(160%);
  -webkit-backdrop-filter: blur(28px) saturate(160%);
}

.auth-brand {
  padding-bottom: 18px;
}

.auth-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 8px 0 18px;
  border: 1px solid var(--line-dark);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.42);
  padding: 6px;
}

.auth-tab {
  min-width: 0;
  min-height: 44px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
  overflow-wrap: anywhere;
}

.auth-tab.active {
  background: rgba(255, 255, 255, 0.78);
  color: #215ecf;
  box-shadow: 0 10px 24px rgba(32, 57, 102, 0.10);
}

.auth-form {
  display: none;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.auth-form.active {
  display: grid;
}

.auth-form .button {
  grid-column: 1 / -1;
}

.sidebar,
.panel,
.metric,
.notice,
.topbar {
  border: 1px solid var(--line);
  background: var(--glass);
  box-shadow: var(--shadow-card);
  backdrop-filter: blur(28px) saturate(160%);
  -webkit-backdrop-filter: blur(28px) saturate(160%);
}

.sidebar {
  position: sticky;
  top: 24px;
  height: calc(100vh - 48px);
  overflow: auto;
  border-radius: var(--radius-xl);
  padding: 22px;
}

.brand {
  display: grid;
  grid-template-columns: 56px minmax(0, 1fr);
  gap: 14px;
  align-items: center;
  padding-bottom: 22px;
}

.brand-mark {
  display: grid;
  width: 56px;
  height: 56px;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.7);
  border-radius: 20px;
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  box-shadow: var(--shadow-button);
  color: white;
  font-size: 22px;
  font-weight: 800;
  line-height: 1;
  text-align: center;
}

.brand-name {
  color: var(--text);
  font-size: 18px;
  font-weight: 800;
  letter-spacing: -0.03em;
}

.brand-subtitle {
  margin-top: 3px;
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.nav {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}

.nav-item {
  width: 100%;
  min-height: 46px;
  border: 1px solid transparent;
  border-radius: 18px;
  background: transparent;
  color: var(--muted);
  padding: 11px 14px;
  text-align: left;
  font-size: 14px;
  font-weight: 700;
  transition: 180ms ease;
}

.nav-item:hover {
  border-color: var(--line);
  background: rgba(255, 255, 255, 0.48);
  color: var(--text);
  transform: translateY(-1px);
}

.nav-item.active {
  border-color: rgba(52, 120, 246, 0.18);
  background: linear-gradient(135deg, rgba(52, 120, 246, 0.16), rgba(124, 92, 255, 0.12));
  color: #1f56c5;
}

.main {
  min-width: 0;
}

.topbar {
  display: grid;
  grid-template-columns: minmax(280px, 1fr) minmax(420px, 720px);
  gap: 24px;
  align-items: center;
  border-radius: var(--radius-xl);
  margin-bottom: 24px;
  padding: 28px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  color: var(--text);
  font-size: clamp(28px, 4vw, 44px);
  font-weight: 800;
  letter-spacing: -0.055em;
  line-height: 1.02;
}

h2 {
  color: var(--text);
  font-size: 20px;
  font-weight: 800;
  letter-spacing: -0.035em;
}

p {
  margin-top: 9px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
  line-height: 1.6;
}

.connection,
.filters {
  display: grid;
  grid-template-columns: minmax(160px, 1fr) minmax(160px, 1fr) auto;
  gap: 10px;
}

.filters {
  grid-template-columns: repeat(4, minmax(120px, 1fr));
  width: min(760px, 100%);
}

label {
  display: grid;
  min-width: 0;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

input,
select,
textarea {
  width: 100%;
  min-height: 46px;
  border: 1px solid var(--line-dark);
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.58);
  color: var(--text);
  padding: 11px 14px;
  outline: none;
  font-size: 14px;
  font-weight: 600;
  transition: 170ms ease;
}

textarea {
  min-height: 108px;
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  border-color: rgba(52, 120, 246, 0.6);
  background: rgba(255, 255, 255, 0.86);
  box-shadow: 0 0 0 4px rgba(52, 120, 246, 0.12);
}

.button {
  min-width: 0;
  min-height: 46px;
  border: 1px solid rgba(52, 120, 246, 0.28);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.58);
  color: #215ecf;
  padding: 11px 18px;
  font-size: 14px;
  font-weight: 800;
  white-space: nowrap;
  transition: 180ms ease;
}

.button:hover {
  background: rgba(255, 255, 255, 0.82);
  transform: translateY(-1px);
}

.button.primary {
  border-color: transparent;
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  box-shadow: var(--shadow-button);
  color: white;
}

.button.primary:hover {
  filter: saturate(1.08);
}

.button.ghost {
  border-color: transparent;
  background: transparent;
}

.button.danger {
  border-color: rgba(223, 75, 95, 0.22);
  background: rgba(255, 255, 255, 0.54);
  color: var(--danger);
}

.notice {
  margin-bottom: 24px;
  border-radius: var(--radius-lg);
  padding: 14px 18px;
  color: #215ecf;
  font-size: 13px;
  font-weight: 700;
}

.notice.error {
  color: var(--danger);
}

.hidden {
  display: none !important;
}

.view {
  display: none;
}

.view.active {
  display: grid;
  gap: 24px;
}

.metrics-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
}

.metric {
  min-height: 150px;
  border-radius: var(--radius-xl);
  padding: 24px;
}

.metric-label {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.metric strong {
  display: block;
  margin-top: 16px;
  color: var(--text);
  font-size: 42px;
  font-weight: 800;
  letter-spacing: -0.06em;
}

.layout-two {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 24px;
  align-items: stretch;
}

.layout-two > .panel:only-child {
  grid-column: 1 / -1;
}

.panel {
  min-width: 0;
  border-radius: var(--radius-xl);
  padding: 24px;
}

.panel-head {
  display: flex;
  min-width: 0;
  min-height: 46px;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 18px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.span-2 {
  grid-column: 1 / -1;
}

.stack,
.occupancy-list,
.bars {
  display: grid;
  gap: 12px;
}

.inline-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 110px auto;
  gap: 10px;
  margin-top: 16px;
}

.method-group {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  border: 1px solid var(--line-dark);
  border-radius: var(--radius-lg);
  background: rgba(255, 255, 255, 0.42);
  padding: 14px;
}

.method-group label {
  display: flex;
  align-items: center;
  gap: 8px;
}

.method-group input {
  width: 16px;
  min-height: 16px;
}

.hint-box,
.checkbox-card {
  border: 1px solid var(--line-dark);
  border-radius: var(--radius-lg);
  background: rgba(255, 255, 255, 0.42);
  color: var(--muted);
  padding: 14px;
  font-size: 12px;
  font-weight: 700;
  line-height: 1.55;
}

.checkbox-card {
  display: flex;
  align-items: center;
  gap: 10px;
}

.checkbox-card input {
  width: 16px;
  min-height: 16px;
}

.quick-grants {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 10px;
}

.checklist {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 10px;
}

.check-item {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 10px;
  border: 1px solid var(--line-dark);
  border-radius: var(--radius-lg);
  background: rgba(255, 255, 255, 0.46);
  padding: 13px 14px;
  color: var(--text);
  font-size: 13px;
  font-weight: 800;
  transition: transform 0.18s ease, border-color 0.18s ease, background 0.18s ease;
}

.check-item:hover {
  transform: translateY(-1px);
  border-color: rgba(52, 120, 246, 0.22);
  background: rgba(255, 255, 255, 0.68);
}

.check-item input {
  width: 17px;
  min-height: 17px;
  flex: 0 0 auto;
}

.check-item span {
  display: grid;
  min-width: 0;
  gap: 3px;
}

.check-item small {
  overflow: hidden;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--line-dark);
  border-radius: var(--radius-lg);
  background: rgba(255, 255, 255, 0.34);
}

.table-wrap.compact {
  max-height: 420px;
}

#dashboard .layout-two .panel {
  display: flex;
  flex-direction: column;
}

#dashboard .table-wrap.compact,
#dashboard .occupancy-list {
  flex: 1;
  max-height: none;
}

table {
  width: 100%;
  min-width: 860px;
  border-collapse: collapse;
}

th,
td {
  border-bottom: 1px solid rgba(16, 24, 40, 0.06);
  padding: 15px 16px;
  text-align: left;
  vertical-align: middle;
}

th {
  background: rgba(255, 255, 255, 0.42);
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

td {
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
}

tr:last-child td {
  border-bottom: 0;
}

.muted {
  color: var(--muted);
}

.badge {
  display: inline-flex;
  margin: 2px;
  min-height: 28px;
  align-items: center;
  border: 1px solid rgba(16, 24, 40, 0.06);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.52);
  color: var(--muted);
  padding: 5px 10px;
  font-size: 11px;
  font-weight: 800;
}

.badge.green {
  background: rgba(31, 157, 112, 0.12);
  color: var(--success);
}

.badge.red {
  background: rgba(223, 75, 95, 0.12);
  color: var(--danger);
}

.badge.yellow {
  background: rgba(201, 138, 25, 0.12);
  color: var(--warning);
}

.badge.blue {
  background: rgba(52, 120, 246, 0.12);
  color: #215ecf;
}

.row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.row-actions .button {
  min-height: 34px;
  padding: 7px 12px;
  font-size: 12px;
}

.row-actions .icon-button {
  width: 38px;
  min-height: 38px;
  justify-content: center;
  padding: 0;
  font-size: 16px;
}

.search {
  max-width: 300px;
}

.occupancy-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  border: 1px solid var(--line-dark);
  border-radius: var(--radius-lg);
  background: rgba(255, 255, 255, 0.42);
  padding: 16px;
}

.occupancy-name {
  font-weight: 800;
}

.occupancy-people {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.bar-row {
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr) 56px;
  gap: 12px;
  align-items: center;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.bar-track {
  height: 10px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.52);
}

.bar-fill {
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--primary), var(--cyan));
}

.code-output {
  margin-top: 14px;
  min-height: 118px;
  font-family: "SF Mono", "Cascadia Code", Consolas, monospace;
  font-size: 12px;
}

.token-cell {
  display: inline-block;
  max-width: 280px;
  overflow: auto;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.58);
  padding: 7px 9px;
  color: #215ecf;
  font-family: "SF Mono", "Cascadia Code", Consolas, monospace;
  font-size: 11px;
  white-space: nowrap;
}

.details {
  display: grid;
  gap: 12px;
  margin: 0 0 18px;
}

.details div {
  display: grid;
  grid-template-columns: 110px minmax(0, 1fr);
  gap: 12px;
  border-bottom: 1px solid rgba(16, 24, 40, 0.06);
  padding-bottom: 12px;
}

.details dt {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.details dd {
  margin: 0;
  overflow-wrap: anywhere;
  font-size: 13px;
  font-weight: 700;
}

@media (max-width: 1280px) {
  .topbar {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 1160px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
  }

  .nav {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .layout-two,
  .metrics-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 720px) {
  .app-shell {
    padding: 14px;
  }

  .connection,
  .filters,
  .form-grid,
  .auth-form,
  .inline-form,
  .quick-grants,
  .nav {
    grid-template-columns: 1fr;
  }

  .panel-head {
    align-items: stretch;
    flex-direction: column;
  }

  .button {
    white-space: normal;
  }

  .bar-row {
    grid-template-columns: 1fr;
  }
}
