:root {
  --bg: #0d0d0d;
  --panel: #17181d;
  --panel-2: #202126;
  --panel-3: #292b31;
  --line: #3a3d45;
  --text: #f4f6fb;
  --muted: #a8adba;
  --danger: #e63946;
  --danger-2: #ff6b35;
  --green: #21c26b;
  --blue: #3399ff;
  --amber: #f4b740;
  --violet: #8a6cff;
  --shadow: 0 24px 70px rgba(0, 0, 0, .32);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--text);
  background:
    linear-gradient(140deg, rgba(230, 57, 70, .12), transparent 34%),
    linear-gradient(320deg, rgba(51, 153, 255, .10), transparent 30%),
    var(--bg);
  font-family: Arial, Tahoma, sans-serif;
  letter-spacing: 0;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled,
input:disabled,
select:disabled {
  cursor: not-allowed;
  opacity: .62;
}

a {
  color: inherit;
  text-decoration: none;
}

.auth-view {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.auth-layout {
  width: min(980px, 100%);
  display: grid;
  grid-template-columns: minmax(320px, 420px) minmax(340px, 1fr);
  gap: 18px;
  align-items: start;
}

.auth-panel {
  width: 100%;
  display: grid;
  gap: 16px;
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(23, 24, 29, .94);
  box-shadow: var(--shadow);
}

.member-login-panel {
  display: grid;
  gap: 14px;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(23, 24, 29, .94);
  box-shadow: var(--shadow);
}

.member-lookup-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: end;
}

.member-lookup-form label {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}

.member-lookup-result {
  display: grid;
  gap: 12px;
}

.member-summary-head,
.member-offer-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.member-summary-head h3,
.member-offers h3 {
  margin: 0;
}

.member-summary-head p,
.member-offer-row span {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.member-offers {
  display: grid;
  gap: 10px;
}

.member-offer-row {
  padding: 10px;
  background: #101116;
  border: 1px solid var(--line);
  border-radius: 6px;
}

.brand-logo {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  max-width: 270px;
  margin: 0 auto 2px;
}

.brand-logo img {
  display: block;
  width: 100%;
  max-height: 170px;
  object-fit: contain;
}

.brand-logo.small {
  width: 150px;
  max-width: 48vw;
  margin: 0;
  justify-content: flex-start;
}

.brand-logo.small img {
  max-height: 64px;
}

.auth-panel label,
.field label,
.form-grid label {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}

input,
select,
textarea {
  width: 100%;
  color: var(--text);
  background: #101116;
  border: 1px solid var(--line);
  border-radius: 6px;
  min-height: 40px;
  padding: 10px 12px;
  outline: 0;
}

textarea {
  min-height: 92px;
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--danger-2);
  box-shadow: 0 0 0 3px rgba(255, 107, 53, .16);
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 270px minmax(0, 1fr);
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 18px 14px;
  background: rgba(13, 13, 13, .92);
  border-left: 1px solid var(--line);
  backdrop-filter: blur(16px);
  z-index: 20;
}

.sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 48px;
  padding: 0 8px 14px;
}

.side-nav {
  display: grid;
  gap: 8px;
}

.side-nav button {
  display: flex;
  align-items: center;
  min-height: 44px;
  padding: 0 14px;
  color: var(--muted);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 6px;
  text-align: right;
}

.side-nav button.active,
.side-nav button:hover {
  color: var(--text);
  border-color: rgba(255, 107, 53, .32);
  background: linear-gradient(90deg, rgba(230, 57, 70, .22), rgba(255, 107, 53, .08));
}

.main-shell {
  min-width: 0;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 15;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 78px;
  padding: 14px 22px;
  border-bottom: 1px solid var(--line);
  background: rgba(15, 15, 16, .86);
  backdrop-filter: blur(16px);
}

.topbar h1 {
  margin: 0 0 4px;
  font-size: 22px;
}

.topbar p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.user-chip {
  display: grid;
  gap: 2px;
  min-width: 150px;
  padding: 8px 10px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 6px;
}

.user-chip small {
  color: var(--muted);
}

.content {
  padding: 22px;
}

.page {
  display: none;
}

.page.active {
  display: grid;
  gap: 18px;
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.toolbar.compact {
  align-items: end;
}

.toolbar-group {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.grid {
  display: grid;
  gap: 14px;
}

.grid.stats {
  grid-template-columns: repeat(4, minmax(180px, 1fr));
}

.grid.two {
  grid-template-columns: minmax(0, 1.1fr) minmax(320px, .9fr);
}

.grid.three {
  grid-template-columns: repeat(3, minmax(220px, 1fr));
}

.panel,
.stat-card,
.item-card {
  background: rgba(23, 24, 29, .92);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 12px 42px rgba(0, 0, 0, .18);
}

.panel {
  padding: 16px;
}

.panel-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.panel-title h2,
.panel-title h3 {
  margin: 0;
  font-size: 17px;
}

.panel-title small {
  color: var(--muted);
}

.stat-card {
  min-height: 116px;
  padding: 16px;
  display: grid;
  align-content: space-between;
  overflow: hidden;
}

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

.stat-card strong {
  font-size: 30px;
  line-height: 1.1;
}

.stat-card small {
  color: var(--muted);
}

.stat-card.red {
  border-color: rgba(230, 57, 70, .42);
}

.stat-card.green {
  border-color: rgba(33, 194, 107, .42);
}

.stat-card.blue {
  border-color: rgba(51, 153, 255, .42);
}

.stat-card.amber {
  border-color: rgba(244, 183, 64, .42);
}

.item-card {
  padding: 14px;
  display: grid;
  gap: 10px;
}

.item-card-head {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: start;
}

.item-card h3 {
  margin: 0 0 4px;
  font-size: 16px;
}

.item-card p {
  margin: 0;
  color: var(--muted);
  line-height: 1.6;
}

.btn,
.icon-btn {
  min-height: 38px;
  border-radius: 6px;
  border: 1px solid var(--line);
  color: var(--text);
  background: var(--panel-2);
  padding: 0 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  white-space: nowrap;
}

.icon-btn {
  width: 40px;
  padding: 0;
  font-size: 18px;
}

.btn.primary {
  background: linear-gradient(90deg, var(--danger), var(--danger-2));
  border-color: transparent;
  font-weight: 700;
}

.btn.ghost {
  background: transparent;
}

.btn.success {
  background: rgba(33, 194, 107, .16);
  border-color: rgba(33, 194, 107, .45);
}

.btn.danger,
.icon-btn.danger {
  background: rgba(230, 57, 70, .15);
  border-color: rgba(230, 57, 70, .42);
}

.btn.blue {
  background: rgba(51, 153, 255, .16);
  border-color: rgba(51, 153, 255, .42);
}

.btn.amber {
  background: rgba(244, 183, 64, .16);
  border-color: rgba(244, 183, 64, .42);
}

.segmented {
  display: inline-flex;
  background: #101116;
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
}

.segmented button {
  min-height: 38px;
  padding: 0 12px;
  color: var(--muted);
  background: transparent;
  border: 0;
  border-left: 1px solid var(--line);
}

.segmented button:last-child {
  border-left: 0;
}

.segmented button.active {
  color: var(--text);
  background: rgba(255, 107, 53, .18);
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(220px, 1fr));
  gap: 14px;
}

.form-grid .wide {
  grid-column: 1 / -1;
}

.calc-strip {
  display: grid;
  grid-template-columns: repeat(3, minmax(140px, 1fr));
  gap: 10px;
  padding: 12px;
  background: #101116;
  border: 1px solid var(--line);
  border-radius: 6px;
}

.calc-strip span {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
}

.calc-strip strong {
  color: var(--text);
  font-size: 16px;
}

.table-wrap {
  width: 100%;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

table {
  width: 100%;
  min-width: 820px;
  border-collapse: collapse;
  background: rgba(23, 24, 29, .76);
}

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

th {
  position: sticky;
  top: 0;
  z-index: 1;
  color: var(--muted);
  background: #121318;
  font-size: 12px;
}

tr:hover td {
  background: rgba(255, 255, 255, .025);
}

.actions {
  display: flex;
  align-items: center;
  gap: 7px;
  flex-wrap: wrap;
}

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 24px;
  min-width: 72px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  border: 1px solid transparent;
}

.badge.active {
  color: #d9ffe9;
  background: rgba(33, 194, 107, .16);
  border-color: rgba(33, 194, 107, .38);
}

.badge.expired {
  color: #ffd8dc;
  background: rgba(230, 57, 70, .16);
  border-color: rgba(230, 57, 70, .38);
}

.badge.frozen {
  color: #d8ebff;
  background: rgba(51, 153, 255, .16);
  border-color: rgba(51, 153, 255, .38);
}

.badge.warning {
  color: #fff1c7;
  background: rgba(244, 183, 64, .16);
  border-color: rgba(244, 183, 64, .38);
}

.badge.role {
  color: #e9e4ff;
  background: rgba(138, 108, 255, .16);
  border-color: rgba(138, 108, 255, .38);
}

.empty-state {
  display: grid;
  place-items: center;
  min-height: 180px;
  color: var(--muted);
  border: 1px dashed var(--line);
  border-radius: var(--radius);
}

.empty-state.compact {
  min-height: 86px;
}

.profile-layout {
  display: grid;
  grid-template-columns: 180px minmax(0, 1fr);
  gap: 16px;
}

.profile-photo {
  width: 100%;
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  overflow: hidden;
  border-radius: var(--radius);
  background: #101116;
  border: 1px solid var(--line);
  color: var(--muted);
}

.profile-photo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.qr-box {
  min-height: 170px;
  display: grid;
  place-items: center;
  padding: 12px;
  background: #fff;
  border-radius: var(--radius);
}

.qr-box canvas,
.qr-box img {
  max-width: 146px;
  max-height: 146px;
}

.detail-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(180px, 1fr));
  gap: 10px;
}

.detail-list.compact {
  grid-template-columns: repeat(2, minmax(140px, 1fr));
}

.detail-list div {
  padding: 10px;
  background: #101116;
  border: 1px solid var(--line);
  border-radius: 6px;
}

.detail-list small {
  display: block;
  color: var(--muted);
  margin-bottom: 5px;
}

.progress {
  height: 10px;
  overflow: hidden;
  background: #101116;
  border: 1px solid var(--line);
  border-radius: 999px;
}

.progress span {
  display: block;
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--green), var(--danger-2));
}

.modal-host {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(0, 0, 0, .68);
}

.modal {
  width: min(940px, 100%);
  max-height: min(90vh, 860px);
  overflow: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.modal.small {
  width: min(520px, 100%);
}

.modal-head,
.modal-foot {
  position: sticky;
  background: var(--panel);
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}

.modal-foot {
  bottom: 0;
  border-top: 1px solid var(--line);
  border-bottom: 0;
  justify-content: flex-start;
}

.modal-head {
  top: 0;
}

.modal-body {
  padding: 16px;
}

.scanner-host {
  position: fixed;
  inset: 0;
  z-index: 70;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(0, 0, 0, .78);
}

.scanner-panel {
  width: min(560px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}

#qrReader {
  min-height: 320px;
  overflow: hidden;
  border-radius: var(--radius);
  background: #101116;
}

.toast-host {
  position: fixed;
  left: 18px;
  bottom: 18px;
  z-index: 90;
  display: grid;
  gap: 10px;
  width: min(360px, calc(100vw - 36px));
}

.toast {
  padding: 12px 14px;
  border-radius: 6px;
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: 0 14px 42px rgba(0, 0, 0, .32);
}

.toast.success {
  border-color: rgba(33, 194, 107, .48);
}

.toast.error {
  border-color: rgba(230, 57, 70, .56);
}

.form-error {
  margin: 0;
  color: #ffb6bd;
  font-size: 13px;
}

.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 42px;
  padding: 10px;
  background: #101116;
  border: 1px solid var(--line);
  border-radius: 6px;
}

.switch-row input {
  width: 18px;
  min-height: 18px;
}

.permission-section {
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: rgba(16, 17, 22, .62);
}

.permission-section h3 {
  margin: 0;
  font-size: 15px;
}

.permission-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(180px, 1fr));
  gap: 10px;
}

.list-stack {
  display: grid;
  gap: 10px;
}

.money {
  direction: ltr;
  display: inline-block;
}

.mobile-only {
  display: none;
}

.portal-shell {
  min-height: 100vh;
}

.portal-head {
  min-height: 72px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 18px 22px;
  border-bottom: 1px solid var(--line);
  background: rgba(13, 13, 13, .88);
}

.portal-content {
  width: min(1120px, 100%);
  margin: 0 auto;
  padding: 22px;
  display: grid;
  gap: 18px;
}

.member-hero {
  display: grid;
  grid-template-columns: 130px minmax(0, 1fr);
  gap: 16px;
  align-items: center;
}

.alert {
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 6px;
}

.alert.danger {
  border-color: rgba(230, 57, 70, .45);
  background: rgba(230, 57, 70, .12);
}

.alert.amber {
  border-color: rgba(244, 183, 64, .45);
  background: rgba(244, 183, 64, .12);
}

@media (max-width: 1120px) {
  .grid.stats,
  .grid.three {
    grid-template-columns: repeat(2, minmax(180px, 1fr));
  }

  .grid.two {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 820px) {
  .auth-layout,
  .app-shell {
    grid-template-columns: 1fr;
  }

  .member-lookup-form {
    grid-template-columns: 1fr;
  }

  .permission-grid {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(310px, 86vw);
    transform: translateX(-105%);
    transition: transform .2s ease;
    border-right: 1px solid var(--line);
    border-left: 0;
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .mobile-only {
    display: inline-flex;
  }

  .topbar {
    align-items: flex-start;
    padding: 12px;
  }

  .topbar-actions {
    width: 100%;
    justify-content: flex-start;
    flex-wrap: wrap;
  }

  .content,
  .portal-content {
    padding: 14px;
  }

  .toolbar {
    align-items: stretch;
  }

  .toolbar-group,
  .toolbar > .btn,
  .toolbar input,
  .toolbar select {
    width: 100%;
  }

  .grid.stats,
  .grid.three,
  .form-grid,
  .detail-list,
  .calc-strip,
  .member-hero,
  .profile-layout {
    grid-template-columns: 1fr;
  }

  .brand-logo {
    max-width: 235px;
  }

  .brand-logo.small {
    width: 132px;
  }

  .auth-panel {
    padding: 20px;
  }

  .member-login-panel {
    padding: 18px;
  }

  table {
    min-width: 760px;
  }
}
