:root {
  color-scheme: light dark;
  --color-bg: #f4f6fb;
  --color-surface: #ffffff;
  --color-surface-muted: #f1f5f9;
  --color-border: #d2dbe8;
  --color-text: #0f172a;
  --color-text-muted: #475569;
  --color-primary: #2563eb;
  --color-primary-strong: #1d4ed8;
  --color-success: #15803d;
  --color-error: #dc2626;
  --shadow-card: 0 10px 40px -24px rgba(15, 23, 42, 0.45);
}

html[data-theme="dark"] {
  --color-bg: #0f172a;
  --color-surface: #1e293b;
  --color-surface-muted: #16213a;
  --color-border: #334155;
  --color-text: #e2e8f0;
  --color-text-muted: #94a3b8;
  --color-primary: #60a5fa;
  --color-primary-strong: #3b82f6;
  --shadow-card: 0 10px 40px -24px rgba(15, 23, 42, 0.9);
}

* {
  box-sizing: border-box;
}

html, body {
  height: 100%;
}

body {
  margin: 0;
  font-family: 'Segoe UI', Roboto, sans-serif;
  background: var(--color-bg);
  color: var(--color-text);
  -webkit-font-smoothing: antialiased;
}

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

a:hover {
  text-decoration: underline;
}

.app-shell {
  display: flex;
  min-height: 100vh;
  flex-direction: column;
}

.app-layout {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 280px;
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  padding: 1.75rem 1.5rem 1.5rem;
  position: sticky;
  top: 0;
  height: 100vh;
}

.sidebar-header {
  display: flex;
  align-items: center;
  gap: 0.85rem;
}

.sidebar-logo {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: var(--color-surface-muted);
  display: grid;
  place-items: center;
  overflow: hidden;
}

.sidebar-logo-image {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.sidebar-logo-fallback {
  background: linear-gradient(135deg, rgba(37, 99, 235, 0.18), rgba(37, 99, 235, 0.05));
  color: var(--color-primary);
  font-weight: 700;
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
  letter-spacing: 0.08em;
  border-radius: 12px;
}

.sidebar-meta {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.sidebar-title {
  font-weight: 600;
  font-size: 1rem;
}

.side-nav {
  flex: 1 1 auto;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.nav-collection {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 1.75rem;
}

.nav-section {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.nav-section-label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--color-text-muted);
  padding-left: 0.55rem;
  transition: color 0.18s ease;
}

.nav-section-label.active {
  color: var(--color-primary);
}

.nav-subitems {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.55rem 0.75rem;
  border-radius: 0.9rem;
  color: var(--color-text-muted);
  transition: background 0.18s ease, color 0.18s ease, box-shadow 0.18s ease;
  font-weight: 500;
}

.nav-item:hover {
  background: rgba(37, 99, 235, 0.08);
  color: var(--color-primary);
}

.nav-item.active {
  background: rgba(37, 99, 235, 0.14);
  color: var(--color-primary);
  box-shadow: inset 0 0 0 1px rgba(37, 99, 235, 0.2);
}

.nav-item.disabled {
  cursor: not-allowed;
  opacity: 0.6;
  color: var(--color-text-muted);
}

.nav-subitem {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.45rem 0.75rem 0.45rem 0.65rem;
  border-radius: 0.8rem;
  color: var(--color-text-muted);
  transition: background 0.18s ease, color 0.18s ease, box-shadow 0.18s ease;
}

.nav-subitem:hover {
  background: rgba(37, 99, 235, 0.08);
  color: var(--color-primary);
}

.nav-subitem.active {
  background: rgba(37, 99, 235, 0.12);
  color: var(--color-primary);
  box-shadow: inset 0 0 0 1px rgba(37, 99, 235, 0.18);
}

.nav-icon {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: var(--color-surface-muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--color-text-muted);
  transition: background 0.18s ease, color 0.18s ease;
}

.nav-item.active .nav-icon {
  background: rgba(37, 99, 235, 0.18);
  color: var(--color-primary);
}

.nav-item:hover .nav-icon {
  color: var(--color-primary);
}

.nav-icon svg {
  width: 18px;
  height: 18px;
}

.nav-text {
  flex: 1 1 auto;
}

.nav-indicator {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: var(--color-border);
  transition: background 0.18s ease, transform 0.18s ease;
}

.nav-subitem.active .nav-indicator,
.nav-subitem:hover .nav-indicator {
  background: var(--color-primary);
  transform: scale(1.1);
}

.sidebar-footer {
  margin-top: 1rem;
  padding: 1.25rem 1rem;
  background: var(--color-surface-muted);
  border-radius: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.sidebar-avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: linear-gradient(135deg, rgba(37, 99, 235, 0.35), rgba(37, 99, 235, 0.15));
  color: white;
  font-weight: 600;
  display: grid;
  place-items: center;
  letter-spacing: 0.05em;
}

.sidebar-user-meta {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.sidebar-user-name {
  font-weight: 600;
}

.sidebar-user-role {
  font-size: 0.78rem;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.sidebar-logout-form {
  display: flex;
  justify-content: flex-end;
}

.main-area {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  background: var(--color-bg);
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.5rem 2.5rem 0;
}

.header-actions,
.header-account {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.content {
  flex: 1 1 auto;
  width: min(1200px, 100%);
  padding: 2rem 2.5rem 3rem;
}

.footer {
  padding: 1.25rem 2.5rem 1.75rem;
  text-align: center;
  font-size: 0.875rem;
  color: var(--color-text-muted);
}

@media (max-width: 900px) {
  .app-layout {
    flex-direction: column;
  }

  .sidebar {
    position: relative;
    width: 100%;
    height: auto;
    gap: 1.25rem;
  }

  .side-nav {
    flex-direction: column;
    gap: 1.25rem;
  }

  .nav-collection {
    gap: 1.25rem;
  }

  .nav-section {
    width: 100%;
  }

  .nav-subitems {
    flex-direction: row;
    flex-wrap: wrap;
    gap: 0.5rem;
  }

  .nav-item {
    flex: 1 1 calc(50% - 0.5rem);
  }

  .nav-subitem {
    flex: 1 1 calc(50% - 0.5rem);
  }

  .sidebar-footer {
    flex-direction: column;
    align-items: stretch;
  }

  .sidebar-logout-form {
    justify-content: flex-start;
  }

  .content {
    padding: 1.5rem 1.25rem 2.5rem;
  }

  .app-header {
    padding: 1.25rem 1.25rem 0;
  }

  .footer {
    padding: 1rem 1.25rem 1.5rem;
  }
}

@media (max-width: 540px) {
  .nav-item,
  .nav-subitem {
    flex: 1 1 100%;
  }
}

.icon-button {
  background: none;
  border: 1px solid var(--color-border);
  border-radius: 999px;
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: background 0.2s ease;
}

.icon-button:hover {
  background: var(--color-surface-muted);
}

.icon {
  width: 1.125rem;
  height: 1.125rem;
}

.icon-sun::before {
  content: "☀";
  font-size: 1rem;
}

html[data-theme="dark"] .icon-sun::before {
  content: "☾";
}

.user-pill {
  background: var(--color-surface-muted);
  padding: 0.35rem 0.75rem;
  border-radius: 999px;
  font-size: 0.875rem;
  color: var(--color-text-muted);
}

.inline-form {
  margin: 0;
}

.page-header {
  margin-bottom: 1.5rem;
}

.page-title {
  margin: 0;
  font-size: 1.75rem;
  font-weight: 600;
}

.page-subtitle {
  margin-top: 0.25rem;
  color: var(--color-text-muted);
}

.card {
  background: var(--color-surface);
  border-radius: 1rem;
  padding: 1.75rem;
  box-shadow: var(--shadow-card);
  border: 1px solid rgba(15, 23, 42, 0.05);
}

.card ul {
  margin: 0;
  padding-left: 1.25rem;
  color: var(--color-text-muted);
}

.card ul li {
  margin-bottom: 0.35rem;
}

.card-with-divider {
  border-left: 4px solid var(--color-primary);
}

.card-title {
  font-size: 1.125rem;
  font-weight: 600;
  margin-bottom: 1rem;
}

.dashboard-section {
  margin-bottom: 2.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.dashboard-section-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
}

.dashboard-section-title {
  font-size: 1.2rem;
  font-weight: 600;
  margin: 0;
}

.dashboard-section-subtitle {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--color-text-muted);
}

.dashboard-grid {
  display: grid;
  gap: 1.5rem;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
}

.membership-grid {
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
}

.metric-card {
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.metric-card.highlight {
  background: linear-gradient(135deg, rgba(37, 99, 235, 0.12), rgba(37, 99, 235, 0.02));
}

.metric-title {
  font-size: 0.9rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--color-text-muted);
  margin: 0;
}

.metric-value {
  font-size: 2rem;
  font-weight: 600;
  margin: 0;
  color: var(--color-text);
}

.metric-footnote {
  font-size: 0.85rem;
  color: var(--color-text-muted);
  margin: 0;
}

.metric-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.metric-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  font-size: 0.95rem;
}

.metric-list-value {
  font-weight: 600;
}

.metric-empty {
  margin: 0;
  font-size: 0.9rem;
  color: var(--color-text-muted);
}

.grid {
  display: grid;
  gap: 1rem;
}

.gap-4 {
  gap: 1rem;
}

.space-y-4 > * + * {
  margin-top: 1rem;
}

.form-field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.form-field-with-count .form-label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.form-field-with-count .results-count {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--color-text);
  white-space: nowrap;
}

.user-password-input {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.field-hint {
  font-size: 0.75rem;
  color: var(--color-text-muted);
}

.form-label {
  font-size: 0.85rem;
  color: var(--color-text-muted);
}

.form-input {
  border-radius: 0.65rem;
  border: 1px solid var(--color-border);
  padding: 0.65rem 0.85rem;
  font-size: 0.95rem;
  background: var(--color-surface);
  color: inherit;
}

.form-input:focus {
  outline: 2px solid rgba(37, 99, 235, 0.4);
  border-color: var(--color-primary);
}

.form-input-sm {
  padding: 0.45rem 0.6rem;
  font-size: 0.85rem;
}

select.form-input option {
  background: var(--color-surface);
  color: var(--color-text);
}

.form-actions {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  flex-wrap: wrap;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  font-weight: 600;
  border-radius: 999px;
  border: none;
  cursor: pointer;
  padding: 0.65rem 1.3rem;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.btn:hover {
  transform: translateY(-1px);
}

.btn:focus-visible {
  outline: 2px solid rgba(37, 99, 235, 0.5);
  outline-offset: 2px;
}

.btn-sm {
  padding: 0.4rem 0.9rem;
  font-size: 0.85rem;
}

.btn-primary {
  background: linear-gradient(135deg, var(--color-primary), var(--color-primary-strong));
  color: white;
  box-shadow: 0 14px 28px -18px rgba(37, 99, 235, 0.8);
}

.btn-secondary {
  background: rgba(37, 99, 235, 0.14);
  color: var(--color-primary);
}

.btn-tertiary {
  background: var(--color-surface-muted);
  color: var(--color-text-muted);
}

.btn-danger {
  background: linear-gradient(135deg, #dc2626, #b91c1c);
  color: white;
  box-shadow: 0 14px 28px -18px rgba(220, 38, 38, 0.8);
}

.btn-secondary:hover,
.btn-tertiary:hover {
  filter: brightness(1.05);
}

.btn-primary:hover {
  box-shadow: 0 18px 35px -16px rgba(37, 99, 235, 0.9);
}

.w-full {
  width: 100%;
}

.table {
  width: 100%;
  border-collapse: collapse;
  border-radius: 0.75rem;
  overflow: hidden;
}

.table th,
.table td {
  text-align: left;
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--color-border);
}

.table thead th {
  background: var(--color-surface-muted);
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.table tbody tr:hover {
  background: rgba(37, 99, 235, 0.06);
}

.table-actions {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  justify-content: flex-end;
}

.text-right {
  text-align: right;
}

.text-center {
  text-align: center;
}

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

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

.text-sm {
  font-size: 0.875rem;
}

.text-xs {
  font-size: 0.75rem;
}

.text-2xl {
  font-size: 1.5rem;
}

.font-semibold {
  font-weight: 600;
}

.mb-4 {
  margin-bottom: 1rem;
}

.mb-6 {
  margin-bottom: 1.5rem;
}

.mt-2 {
  margin-top: 0.5rem;
}

.mt-4 {
  margin-top: 1rem;
}

.receipt-card {
  border: 1px solid var(--color-border);
  padding: 1rem 1.25rem;
}

.receipt-card summary {
  list-style: none;
}

.receipt-card[open] > summary::after {
  content: "";
}

.receipt-summary {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1rem;
  align-items: center;
  cursor: pointer;
}

.receipt-summary::-webkit-details-marker {
  display: none;
}

.receipt-number {
  font-weight: 600;
  font-size: 1.1rem;
}

.receipt-meta,
.receipt-meta-group {
  color: var(--color-text-muted);
  font-size: 0.9rem;
}

.receipt-total {
  text-align: right;
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--color-primary);
}

.receipt-body {
  margin-top: 1rem;
}

.member-card {
  border: 1px solid var(--color-border);
  padding: 1.25rem 1.5rem;
}

.member-card summary {
  list-style: none;
}

.member-card summary::-webkit-details-marker {
  display: none;
}

.member-card[open] > summary::after {
  content: "";
}

.member-card-summary {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  cursor: pointer;
}

.member-name {
  font-weight: 600;
  font-size: 1.05rem;
}

.member-status {
  font-size: 0.8rem;
  font-weight: 600;
  padding: 0.25rem 0.7rem;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.member-status-active {
  background: rgba(21, 128, 61, 0.18);
  color: var(--color-success);
}

.member-status-inactive {
  background: rgba(148, 163, 184, 0.2);
  color: var(--color-text-muted);
}

.member-card-body {
  margin-top: 1.25rem;
}

.member-detail-grid {
  display: grid;
  gap: 1rem;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}

.member-detail-table-wrapper {
  margin-top: 1.5rem;
  overflow-x: auto;
}

.member-detail-table {
  min-width: 520px;
}

.member-detail-empty {
  margin-top: 1.5rem;
  color: var(--color-text-muted);
  font-style: italic;
}

.member-detail-grid dt {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-text-muted);
  margin-bottom: 0.2rem;
}

.member-detail-grid dd {
  margin: 0;
  font-size: 0.95rem;
  color: var(--color-text);
}

.line-items th,
.line-items td {
  font-size: 0.9rem;
}

.pagination {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 1.25rem;
  margin-top: 2rem;
}

.pagination-status {
  font-size: 0.9rem;
  color: var(--color-text-muted);
}

.empty-state {
  text-align: center;
  padding: 4rem 1rem;
  border: 2px dashed var(--color-border);
  border-radius: 1rem;
  background: rgba(148, 163, 184, 0.08);
}

.empty-state h2 {
  margin-top: 0;
}

.alert {
  padding: 0.85rem 1rem;
  border-radius: 0.75rem;
  font-size: 0.9rem;
}

.alert-success {
  background: rgba(21, 128, 61, 0.12);
  color: var(--color-success);
}

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

.items-center {
  align-items: center;
}

.gap-2 {
  gap: 0.5rem;
}

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

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

.card .table {
  margin: 0;
}

.auth-shell {
  display: grid;
  place-items: center;
  min-height: 100vh;
  background: radial-gradient(circle at top, rgba(37, 99, 235, 0.18), transparent 55%), var(--color-bg);
}

.auth-content {
  width: min(420px, 90vw);
}

.auth-card {
  background: var(--color-surface);
  border-radius: 1.5rem;
  padding: 2.5rem;
  box-shadow: var(--shadow-card);
  border: 1px solid rgba(37, 99, 235, 0.12);
}

.text-error li {
  list-style: none;
}

/* Responsive utilities */
.md\:grid-cols-2 {
  grid-template-columns: repeat(1, minmax(0, 1fr));
}

.lg\:grid-cols-3 {
  grid-template-columns: repeat(1, minmax(0, 1fr));
}

.xl\:grid-cols-6 {
  grid-template-columns: repeat(1, minmax(0, 1fr));
}

.lg\:col-span-1,
.lg\:col-span-2,
.xl\:col-span-1,
.xl\:col-span-2,
.xl\:col-span-6 {
  grid-column: span 1 / span 1;
}

@media (min-width: 768px) {
  .md\:grid-cols-2 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (min-width: 1024px) {
  .lg\:grid-cols-3 {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .lg\:col-span-1 {
    grid-column: span 1 / span 1;
  }

  .lg\:col-span-2 {
    grid-column: span 2 / span 2;
  }
}

@media (min-width: 1280px) {
  .xl\:grid-cols-6 {
    grid-template-columns: repeat(6, minmax(0, 1fr));
  }

  .xl\:col-span-1 {
    grid-column: span 1 / span 1;
  }

  .xl\:col-span-2 {
    grid-column: span 2 / span 2;
  }

  .xl\:col-span-6 {
    grid-column: span 6 / span 6;
  }
}