:root {
  --bg: #0a0a0a;
  --surface: #111111;
  --surface-2: #151515;
  --border: #222222;
  --border-soft: #1a1a1a;
  --text: #fafafa;
  --text-muted: #71717a;
  --accent: #d97757;
  --accent-text: #f59e7a;
  --accent-soft-bg: #2a120b;
  --danger: #ef4444;
  --button-bg: #1a1a1a;
  --button-border: #333333;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #ffffff;
    --surface: #ffffff;
    --surface-2: #f7f7f7;
    --border: #e5e5e5;
    --border-soft: #ececec;
    --text: #0a0a0a;
    --text-muted: #71717a;
    --accent: #d97757;
    --accent-text: #a4492a;
    --accent-soft-bg: #fff1e8;
    --danger: #dc2626;
    --button-bg: #f5f5f5;
    --button-border: #e5e5e5;
  }
}

* {
  box-sizing: border-box;
}

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

body {
  min-height: 100vh;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, sans-serif;
  font-size: 0.875rem;
  font-weight: 400;
  letter-spacing: 0;
}

button {
  font: inherit;
}

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

a {
  color: var(--accent-text);
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  color: var(--text);
  font-size: 1.125rem;
  font-weight: 600;
  line-height: 1.4;
}

h2 {
  color: var(--text);
  font-size: 0.875rem;
  font-weight: 500;
  line-height: 1.4;
}

p {
  color: var(--text-muted);
  line-height: 1.6;
}

.shell {
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: 100vh;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  padding: 1.5rem 1rem;
  border-right: 1px solid var(--border);
  background: var(--surface-2);
}

.sidebar-logo {
  color: var(--text);
  font-size: 0.9375rem;
  font-weight: 600;
  line-height: 1.2;
}

.sidebar-logo span,
.brand span {
  color: var(--accent-text);
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  padding: 0.625rem 0.75rem;
  border-radius: 6px;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.875rem;
  transition:
    background 150ms ease,
    color 150ms ease;
}

.sidebar-nav a:hover {
  color: var(--text);
}

.sidebar-nav a.active {
  background: var(--accent-soft-bg);
  color: var(--accent-text);
}

.sidebar-nav a:focus-visible,
.logout-button:focus-visible,
.auth-button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.sidebar-nav a svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  margin-top: auto;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

.sidebar-user-info {
  min-width: 0;
  flex: 1;
}

.sidebar-user-info div:first-child {
  overflow: hidden;
  color: var(--text);
  font-size: 0.8125rem;
  font-weight: 500;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar-user-info div:last-child {
  overflow: hidden;
  color: var(--text-muted);
  font-size: 0.75rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.avatar {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  border: 1px solid var(--button-border);
  border-radius: 999px;
  background: var(--button-bg);
  color: var(--accent-text);
  font-size: 0.875rem;
  font-weight: 600;
  line-height: 1;
}

.logout-button {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  padding: 0;
  border: 1px solid var(--button-border);
  border-radius: 6px;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition:
    border-color 150ms ease,
    color 150ms ease;
}

.logout-button:hover {
  border-color: var(--danger);
  color: var(--danger);
}

.logout-button svg {
  width: 16px;
  height: 16px;
}

.content {
  width: 100%;
  max-width: 1180px;
  padding: 2rem;
}

.loading-state,
.callback-state {
  display: grid;
  justify-items: center;
  gap: 1rem;
  padding: 1.5rem 0;
  text-align: center;
}

.spinner {
  width: 24px;
  height: 24px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 999px;
  animation: spin 800ms linear infinite;
}

.signed-state {
  display: block;
}

.page-title {
  margin-bottom: 1.5rem;
  color: var(--text);
  font-size: 1.25rem;
  font-weight: 600;
  line-height: 1.3;
}

.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.page-header .page-title {
  margin-bottom: 0.25rem;
}

.admin-section {
  display: grid;
  gap: 0.5rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
}

.admin-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1.5rem;
  margin-bottom: 1.5rem;
}

.section-header,
.toolbar,
.pagination,
.subscription-header,
.product-summary,
.row-actions,
.card-actions,
.form-actions,
.dialog-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.toolbar {
  margin-bottom: 1rem;
}

.inline-status,
.inline-message {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--text-muted);
  font-size: 0.8125rem;
}

.inline-message {
  width: 100%;
  margin-bottom: 1rem;
  padding: 0.75rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface-2);
  color: var(--text);
}

.small-spinner {
  width: 16px;
  height: 16px;
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
}

.data-table th,
.data-table td {
  padding: 0.75rem;
  border-bottom: 1px solid var(--border-soft);
  text-align: left;
  vertical-align: top;
}

.data-table th {
  color: var(--text-muted);
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
}

.data-table tr:last-child td {
  border-bottom: none;
}

.clickable-row {
  cursor: pointer;
}

.clickable-row:hover {
  background: var(--surface-2);
}

.table-primary {
  color: var(--text);
  font-weight: 500;
}

.muted-text,
.data-table small,
.product-main small {
  color: var(--text-muted);
  font-size: 0.75rem;
}

.pill,
.chip {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0.25rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 500;
}

.pill-success {
  border-color: color-mix(in srgb, var(--accent) 40%, var(--border));
  background: var(--accent-soft-bg);
  color: var(--accent-text);
}

.pill-neutral {
  background: var(--surface-2);
  color: var(--text-muted);
}

.chips,
.subscription-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.empty-state {
  padding: 1rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text-muted);
}

.field {
  display: grid;
  gap: 0.375rem;
}

.field span,
fieldset legend,
.detail-list dt,
.compact-list dt {
  color: var(--text-muted);
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
}

.field input,
.field select,
.field textarea {
  width: 100%;
  min-height: 40px;
  padding: 0.625rem 0.75rem;
  border: 1px solid var(--button-border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
}

.compact-field {
  width: min(100%, 360px);
}

.primary-button,
.secondary-button,
.danger-button,
.danger-outline-button,
.text-button {
  min-height: 36px;
  padding: 0.5rem 0.75rem;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 600;
}

.primary-button {
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #0a0a0a;
}

.secondary-button {
  border: 1px solid var(--button-border);
  background: var(--button-bg);
  color: var(--text);
}

.danger-button {
  border: 1px solid var(--danger);
  background: var(--danger);
  color: #ffffff;
}

.danger-outline-button {
  border: 1px solid var(--danger);
  background: transparent;
  color: var(--danger);
}

.text-button {
  min-height: auto;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--accent-text);
}

.detail-list,
.compact-list {
  display: grid;
  gap: 0.75rem;
  margin: 0;
}

.detail-list div,
.compact-list div {
  display: grid;
  gap: 0.25rem;
}

.detail-list dd,
.compact-list dd {
  margin: 0;
  color: var(--text);
}

code {
  color: var(--text-muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.8125rem;
}

.subscription-list,
.event-list,
#products-list {
  display: grid;
  gap: 1rem;
}

.subscription-card,
.product-card,
.form-panel {
  display: grid;
  gap: 1rem;
  padding: 1rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
}

.subscription-card h3 {
  margin: 0 0 0.25rem;
  font-size: 1rem;
}

.nested-table {
  margin-top: 0.5rem;
}

.compact-table th,
.compact-table td {
  padding: 0.5rem;
}

.usage-chart {
  width: 100%;
  height: auto;
  margin: 0.5rem 0 1rem;
}

.usage-chart rect {
  fill: var(--accent);
}

.usage-chart line {
  stroke: var(--border);
}

.usage-chart text {
  fill: var(--text-muted);
  font-size: 11px;
}

.event-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.75rem 0;
  border-bottom: 1px solid var(--border-soft);
}

.event-row:last-child {
  border-bottom: none;
}

.event-row div {
  display: grid;
  gap: 0.25rem;
}

.event-row span {
  color: var(--text-muted);
  font-size: 0.75rem;
}

.product-main {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex: 1;
  min-height: 44px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  text-align: left;
}

.product-main span {
  display: grid;
  gap: 0.25rem;
}

.product-offers {
  display: grid;
  gap: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border-soft);
}

.form-panel {
  margin-bottom: 1.5rem;
}

.form-panel form {
  display: grid;
  gap: 1rem;
}

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

fieldset {
  display: grid;
  gap: 1rem;
  margin: 0;
  padding: 1rem;
  border: 1px solid var(--border);
  border-radius: 8px;
}

.confirm-dialog {
  width: min(100% - 2rem, 440px);
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
}

.confirm-dialog::backdrop {
  background: rgb(0 0 0 / 0.55);
}

.confirm-dialog form {
  display: grid;
  gap: 1rem;
}

.dialog-actions {
  justify-content: flex-end;
}

.toast {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  z-index: 10;
  max-width: min(360px, calc(100vw - 2rem));
  padding: 0.75rem 1rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text);
  box-shadow: 0 12px 32px rgb(0 0 0 / 0.2);
}

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

.auth-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
  background: var(--bg);
}

.boot-loading {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background: var(--bg);
}

.boot-error {
  min-height: 100vh;
  display: grid;
  place-items: center;
  gap: 1rem;
  padding: 1.5rem;
  background: var(--bg);
  text-align: center;
}

.boot-error h1 {
  font-size: 1.125rem;
}

.boot-error p {
  max-width: 30rem;
}

.auth-card {
  width: min(100%, 380px);
  display: grid;
  gap: 1.5rem;
  padding: 1.5rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
}

.brand {
  color: var(--text);
  font-size: 0.9375rem;
  font-weight: 600;
}

.auth-header {
  display: grid;
  gap: 0.375rem;
}

.auth-header p {
  color: var(--accent-text);
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
}

.auth-button {
  min-height: 42px;
  padding: 0.625rem 1rem;
  border: 1px solid var(--accent);
  border-radius: 6px;
  background: var(--accent);
  color: #0a0a0a;
  cursor: pointer;
  font-weight: 600;
  transition:
    filter 150ms ease,
    opacity 150ms ease;
}

.auth-button:hover {
  filter: brightness(0.95);
}

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

.hidden,
.route.hidden {
  display: none;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@media (max-width: 768px) {
  .shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    flex-direction: row;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }

  .sidebar-logo {
    display: none;
  }

  .sidebar-nav {
    flex: 1;
    flex-direction: row;
    overflow-x: auto;
  }

  .sidebar-nav a {
    flex-shrink: 0;
  }

  .sidebar-user {
    margin-top: 0;
    padding-top: 0;
    border-top: none;
  }

  .sidebar-user-info {
    display: none;
  }

  .content {
    padding: 1rem;
  }

  .page-header,
  .section-header,
  .product-summary,
  .subscription-header {
    align-items: stretch;
    flex-direction: column;
  }

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

  .row-actions,
  .card-actions,
  .dialog-actions {
    flex-wrap: wrap;
    justify-content: flex-start;
  }
}
