:root {
  --bg: #0a0a0a;
  --surface: #111111;
  --surface-2: #151515;
  --border: #222222;
  --border-soft: #1a1a1a;
  --text: #fafafa;
  --text-muted: #71717a;
  --accent: #a3e635;
  --accent-text: #a3e635;
  --accent-soft-bg: #052e16;
  --danger: #ef4444;
  --button-bg: #1a1a1a;
  --button-border: #333333;
  --warning-text: #eab308;
  --warning-soft-bg: #1c1a06;
  --danger-soft-bg: #1c0505;
  --muted-soft-bg: #1a1a1a;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #ffffff;
    --surface: #ffffff;
    --surface-2: #f7f7f7;
    --border: #e5e5e5;
    --border-soft: #ececec;
    --text: #0a0a0a;
    --text-muted: #71717a;
    --accent: #a3e635;
    --accent-text: #4d7c0f;
    --accent-soft-bg: #ecfccb;
    --danger: #dc2626;
    --button-bg: #f5f5f5;
    --button-border: #e5e5e5;
    --warning-text: #a16207;
    --warning-soft-bg: #fef9c3;
    --danger-soft-bg: #fee2e2;
    --muted-soft-bg: #f5f5f5;
  }
}

* {
  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;
}

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

h1,
h2,
h3,
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;
}

h3 {
  color: var(--text);
  font-size: 0.875rem;
  font-weight: 600;
  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 {
  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,
.btn-cancel:focus-visible,
.btn-primary:focus-visible,
#invite-form input:focus-visible,
#invite-form select:focus-visible,
.access-select:focus-visible,
.product-chip 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: 720px;
  padding: 2rem;
}

.loading-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;
}

.text-muted {
  color: var(--text-muted);
}

.products-section,
.payments-section,
.members-section,
.invite-form-section,
.invites-section {
  display: grid;
  gap: 0.5rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
}

.products-list,
.payments-list,
.members-list,
.invites-list {
  display: grid;
}

.product-item {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  padding: 0.875rem 0;
  border-bottom: 1px solid var(--border-soft);
}

.product-item:last-child,
.payment-item:last-child,
.member-item:last-child,
.invite-item:last-child {
  border-bottom: none;
}

.product-icon {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  border: 1px solid var(--button-border);
  border-radius: 6px;
  background: var(--button-bg);
  color: var(--accent-text);
  font-size: 0.875rem;
  font-weight: 600;
  line-height: 1;
}

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

.product-name {
  overflow-wrap: anywhere;
  color: var(--text);
  font-size: 0.875rem;
  font-weight: 500;
}

.product-expiry {
  margin-top: 2px;
  color: var(--text-muted);
  font-size: 0.75rem;
}

.status-badge {
  display: inline-block;
  margin-top: 4px;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.6875rem;
  font-weight: 500;
}

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

.status-pending {
  background: var(--warning-soft-bg);
  color: var(--warning-text);
}

.status-overdue {
  background: var(--danger-soft-bg);
  color: var(--danger);
}

.status-muted {
  background: var(--muted-soft-bg);
  color: var(--text-muted);
}

.btn-cancel {
  padding: 4px 8px;
  border: 1px solid var(--button-border);
  border-radius: 4px;
  background: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.75rem;
  white-space: nowrap;
  transition:
    border-color 150ms ease,
    color 150ms ease;
}

.btn-cancel:hover {
  border-color: var(--danger);
  color: var(--danger);
}

.btn-primary {
  padding: 0.5rem 1rem;
  border: 1px solid var(--accent);
  border-radius: 6px;
  background: var(--accent);
  color: #0a0a0a;
  cursor: pointer;
  font-weight: 500;
  line-height: 1.2;
  transition:
    filter 150ms ease,
    opacity 150ms ease;
}

.btn-primary:hover {
  filter: brightness(0.95);
}

.btn-primary:disabled {
  cursor: not-allowed;
  opacity: 0.7;
}

.member-item {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  padding: 0.875rem 0;
  border-bottom: 1px solid var(--border-soft);
}

.member-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;
}

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

.member-name {
  overflow-wrap: anywhere;
  color: var(--text);
  font-size: 0.875rem;
  font-weight: 500;
}

.member-email {
  margin-top: 2px;
  overflow-wrap: anywhere;
  color: var(--text-muted);
  font-size: 0.75rem;
}

.member-meta,
.member-products,
.member-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.375rem;
}

.member-meta {
  margin-top: 4px;
}

.member-products {
  margin-top: 0.5rem;
}

.member-actions {
  justify-content: flex-end;
  flex-shrink: 0;
}

.member-products-empty {
  color: var(--text-muted);
  font-size: 0.75rem;
}

.product-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 2px 8px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text);
  font-size: 0.75rem;
  line-height: 1.4;
}

.product-chip button {
  width: 16px;
  height: 16px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.75rem;
  line-height: 1;
}

.product-chip button:hover {
  color: var(--danger);
}

.access-select,
#invite-form input,
#invite-form select {
  min-height: 36px;
  border: 1px solid var(--button-border);
  border-radius: 6px;
  background: var(--button-bg);
  color: var(--text);
  font: inherit;
}

.access-select {
  max-width: 180px;
  padding: 4px 8px;
  color: var(--text-muted);
  font-size: 0.75rem;
}

.invite-accept-card {
  display: grid;
  gap: 0.75rem;
  margin-bottom: 1.5rem;
  padding: 1rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface-2);
}

.empty-state {
  padding: 2rem 0;
  color: var(--text-muted);
}

#invite-form {
  display: flex;
  gap: 0.5rem;
}

#invite-form input,
#invite-form select {
  min-width: 0;
  padding: 0.5rem 0.625rem;
}

#invite-form input {
  flex: 1;
}

#invite-form select {
  flex: 0 1 200px;
}

#invite-form input::placeholder {
  color: var(--text-muted);
}

.form-message,
.invite-accept-message {
  color: var(--text-muted);
  font-size: 0.8125rem;
}

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

.invite-item,
.payment-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  padding: 0.75rem 0;
  border-bottom: 1px solid var(--border-soft);
  font-size: 0.8125rem;
}

.invite-left {
  min-width: 0;
}

.invite-email {
  overflow-wrap: anywhere;
  color: var(--text);
  font-weight: 500;
}

.invite-product,
.invite-expiry {
  margin-top: 2px;
  color: var(--text-muted);
  font-size: 0.75rem;
}

.payment-left {
  min-width: 0;
  color: var(--text);
}

.payment-date {
  margin-top: 2px;
  color: var(--text-muted);
  font-size: 0.75rem;
}

.payment-right {
  flex-shrink: 0;
  text-align: right;
}

.payment-amount {
  color: var(--text);
  font-weight: 500;
}

.payment-method {
  margin-top: 2px;
  color: var(--text-muted);
  font-size: 0.75rem;
}

.payment-invoice {
  min-width: 90px;
  flex-shrink: 0;
  color: var(--text);
  font-size: 0.75rem;
  text-align: right;
}

.payment-invoice:empty {
  display: none;
}

.invoice-link {
  color: var(--accent-text);
  text-decoration: none;
}

.invoice-link:hover {
  text-decoration: underline;
}

.section-title {
  color: var(--text);
  font-size: 0.875rem;
  font-weight: 600;
}

.plans-link {
  color: var(--accent-text);
  text-decoration: none;
  white-space: nowrap;
}

.plans-link:hover {
  text-decoration: underline;
}

.catalog-section {
  margin-top: 2rem;
}

.catalog-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 1rem;
  margin-top: 1rem;
}

.catalog-card {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 1rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
}

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

.catalog-card p {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.8125rem;
}

.catalog-card .catalog-price {
  color: var(--text);
  font-weight: 600;
}

.catalog-cta {
  align-self: flex-start;
  margin-top: 0.5rem;
  text-decoration: none;
}

.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-nav a span {
    display: none;
  }

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

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

  .content {
    padding: 1rem;
  }

  .member-item,
  .invite-item {
    align-items: flex-start;
  }

  .member-actions {
    flex-direction: column;
    align-items: flex-end;
  }

  #invite-form {
    flex-direction: column;
  }

  #invite-form select,
  #invite-form button,
  .access-select {
    width: 100%;
    max-width: none;
  }
}
