:root {
  color-scheme: dark;
  --bg: #07111f;
  --bg-accent: #0e1a2c;
  --surface: rgba(17, 24, 39, 0.84);
  --surface-strong: rgba(15, 23, 42, 0.96);
  --surface-soft: rgba(30, 41, 59, 0.72);
  --border: rgba(148, 163, 184, 0.18);
  --border-strong: rgba(148, 163, 184, 0.28);
  --text: #e2e8f0;
  --text-soft: #94a3b8;
  --text-muted: #64748b;
  --primary: #60a5fa;
  --primary-strong: #3b82f6;
  --success: #22c55e;
  --warning: #f59e0b;
  --danger: #ef4444;
  --shadow: 0 16px 48px rgba(2, 6, 23, 0.35);
  --radius-xl: 18px;
  --radius-lg: 14px;
  --radius-md: 10px;
  --radius-sm: 8px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(circle at top right, rgba(96, 165, 250, 0.18), transparent 32%),
    radial-gradient(circle at left center, rgba(45, 212, 191, 0.14), transparent 28%),
    linear-gradient(180deg, #030712 0%, #07111f 100%);
  color: var(--text);
  font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 14px;
  line-height: 1.5;
}

body {
  padding: 20px;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  max-width: 1680px;
  margin: 0 auto;
  display: grid;
  gap: 16px;
}

.surface-card {
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  -webkit-backdrop-filter: blur(18px);
  backdrop-filter: blur(18px);
  border-radius: var(--radius-xl);
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 20px;
  padding: 18px 22px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--primary);
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 6px;
  font-size: clamp(1.4rem, 2.5vw, 2rem);
}

h2 {
  margin-bottom: 0;
  font-size: 1rem;
}

.topbar-subtitle,
.meta-label,
.panel-count,
.sidebar-note p,
.empty-state,
.table-caption,
.detail-hint,
.kv-value.muted,
.small-note {
  color: var(--text-soft);
}

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

.status-cluster {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.status-pill,
.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 24px;
  padding: 0 10px;
  border-radius: 999px;
  border: 1px solid transparent;
  font-size: 0.72rem;
  font-weight: 600;
}

.status-pill.neutral,
.badge.neutral {
  background: rgba(148, 163, 184, 0.12);
  border-color: rgba(148, 163, 184, 0.2);
  color: var(--text);
}

.status-pill.success,
.badge.success {
  background: rgba(34, 197, 94, 0.12);
  border-color: rgba(34, 197, 94, 0.28);
  color: #86efac;
}

.status-pill.warning,
.badge.warning {
  background: rgba(245, 158, 11, 0.12);
  border-color: rgba(245, 158, 11, 0.28);
  color: #fcd34d;
}

.status-pill.danger,
.badge.danger {
  background: rgba(239, 68, 68, 0.14);
  border-color: rgba(239, 68, 68, 0.3);
  color: #fca5a5;
}

.status-pill.info,
.badge.info {
  background: rgba(96, 165, 250, 0.14);
  border-color: rgba(96, 165, 250, 0.3);
  color: #93c5fd;
}

.primary-button,
.ghost-button {
  border-radius: 999px;
  padding: 10px 16px;
  border: 1px solid var(--border-strong);
  transition: transform 160ms ease, border-color 160ms ease, background 160ms ease;
  font-size: 0.88rem;
}

.primary-button {
  color: #eff6ff;
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-strong) 100%);
  border-color: rgba(96, 165, 250, 0.45);
}

.ghost-button {
  color: var(--text);
  background: rgba(148, 163, 184, 0.08);
}

.primary-button:hover,
.ghost-button:hover {
  transform: translateY(-1px);
  border-color: rgba(148, 163, 184, 0.42);
}

.meta-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
}

.meta-card {
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.meta-card.wide {
  min-width: 0;
}

.banner {
  padding: 16px 20px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-strong);
  font-weight: 500;
}

.banner.info {
  background: rgba(96, 165, 250, 0.14);
  border-color: rgba(96, 165, 250, 0.28);
}

.banner.warning {
  background: rgba(245, 158, 11, 0.12);
  border-color: rgba(245, 158, 11, 0.24);
}

.banner.danger {
  background: rgba(239, 68, 68, 0.14);
  border-color: rgba(239, 68, 68, 0.3);
}

.hidden {
  display: none;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
  margin-top: 4px;
}

.summary-card {
  padding: 14px 16px;
  display: grid;
  gap: 8px;
  min-height: 100px;
  border-top: 2px solid rgba(96, 165, 250, 0.25);
  transition: transform 180ms ease, box-shadow 180ms ease, border-color 180ms ease;
}

.summary-card:hover {
  transform: translateY(-2px);
  border-top-color: rgba(96, 165, 250, 0.5);
  box-shadow: 0 8px 24px rgba(2, 6, 23, 0.4);
}

.summary-card-header {
  display: flex;
  align-items: center;
  gap: 8px;
}

.summary-icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  color: var(--primary);
  opacity: 0.7;
}

.summary-value {
  font-size: clamp(1.2rem, 1.6vw, 1.5rem);
  font-weight: 700;
}

.summary-subtext {
  font-size: 0.78rem;
  color: var(--text-soft);
  line-height: 1.4;
}

.content-grid {
  display: grid;
  grid-template-columns: minmax(220px, 260px) minmax(0, 1fr) minmax(280px, 340px);
  gap: 14px;
  align-items: start;
  margin-top: 4px;
}

.filter-sidebar,
.detail-panel,
.panel-section {
  padding: 16px;
}

.filter-sidebar {
  position: sticky;
  top: 20px;
  display: grid;
  gap: 14px;
}

.filter-sidebar .filter-group:not(:first-of-type) {
  padding-top: 14px;
  border-top: 1px solid rgba(148, 163, 184, 0.08);
}

.filter-sidebar .checkbox-row {
  padding-top: 10px;
  border-top: 1px solid rgba(148, 163, 184, 0.08);
}

.sidebar-header,
.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 10px;
}

.filter-group {
  display: grid;
  gap: 5px;
}

.filter-group label,
.checkbox-row,
.detail-section-title,
.kv-label,
.table th {
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--text-soft);
}

.filter-group-inline {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

input,
select {
  width: 100%;
  padding: 8px 10px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: rgba(15, 23, 42, 0.8);
  color: var(--text);
  font-size: 0.9rem;
}

input:focus,
select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(96, 165, 250, 0.18), inset 0 0 0 1px rgba(96, 165, 250, 0.1);
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.checkbox-row input {
  width: 16px;
  height: 16px;
  margin: 0;
}

.sidebar-note {
  padding: 12px;
  border-radius: var(--radius-lg);
  background: rgba(15, 23, 42, 0.65);
  border: 1px solid var(--border);
  font-size: 0.8rem;
}

.sidebar-note h3 {
  font-size: 0.85rem;
  margin-bottom: 6px;
}

.content-column {
  display: grid;
  gap: 14px;
}

.table-wrapper {
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: rgba(2, 6, 23, 0.24);
}

.table {
  width: 100%;
  border-collapse: collapse;
  min-width: 780px;
  font-size: 0.88rem;
}

.table th,
.table td {
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid rgba(148, 163, 184, 0.08);
  vertical-align: top;
}

.table th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: rgba(15, 23, 42, 0.94);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
}

.table tbody tr {
  transition: background 160ms ease, transform 160ms ease;
}

.table tbody tr:hover {
  background: rgba(96, 165, 250, 0.09);
}

.table tbody tr.is-selected {
  background: rgba(96, 165, 250, 0.12);
  box-shadow: inset 3px 0 0 var(--primary);
}

.table tbody tr.clickable-row {
  cursor: pointer;
}

.table tbody tr.clickable-row:active {
  transform: scale(0.995);
}

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

.table td .secondary-text {
  display: block;
  margin-top: 2px;
  font-size: 0.78rem;
  color: var(--text-soft);
}

.amount-positive {
  color: #86efac;
  font-weight: 600;
}

.amount-negative {
  color: #fca5a5;
  font-weight: 600;
}

.amount-neutral {
  color: var(--text);
  font-weight: 600;
}

.empty-state {
  padding: 20px;
  text-align: center;
  font-size: 0.88rem;
}

.detail-panel {
  position: sticky;
  top: 20px;
}

.detail-content {
  display: grid;
  gap: 12px;
}

.empty-detail {
  min-height: 180px;
  display: grid;
  place-items: center;
  text-align: center;
  color: var(--text-soft);
  font-size: 0.88rem;
}

.detail-section {
  display: grid;
  gap: 10px;
  padding: 12px;
  border-radius: var(--radius-lg);
  background: rgba(15, 23, 42, 0.55);
  border: 1px solid rgba(148, 163, 184, 0.1);
}

.detail-section:first-child {
  border-left: 2px solid var(--primary);
}

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

.kv-item {
  display: grid;
  gap: 3px;
}

.kv-value {
  min-width: 0;
  overflow-wrap: anywhere;
  font-weight: 600;
  font-size: 0.88rem;
}

.kv-value-row {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.kv-value-row .kv-value {
  flex: 1;
  min-width: 0;
}

.copy-btn {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  padding: 0;
  border: none;
  border-radius: var(--radius-sm);
  background: rgba(96, 165, 250, 0.12);
  color: var(--primary);
  cursor: pointer;
  opacity: 0.6;
  transition: opacity 150ms ease, background 150ms ease, transform 150ms ease;
}

.copy-btn:hover {
  opacity: 1;
  background: rgba(96, 165, 250, 0.22);
}

.copy-btn:active {
  transform: scale(0.9);
}

.copy-btn.copied {
  background: rgba(34, 197, 94, 0.2);
  color: var(--success);
}

.copy-btn svg {
  width: 13px;
  height: 13px;
}

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

.list-item {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
  padding: 10px 12px;
  border-radius: var(--radius-md);
  background: rgba(2, 6, 23, 0.28);
  border: 1px solid rgba(148, 163, 184, 0.08);
}

.list-item-main {
  min-width: 0;
}

.list-item-main strong,
.list-item-main span {
  display: block;
}

.list-item-main span {
  margin-top: 2px;
  color: var(--text-soft);
  font-size: 0.78rem;
}

@media (max-width: 1440px) {
  .summary-grid {
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  }

  .content-grid {
    grid-template-columns: minmax(200px, 240px) minmax(0, 1fr);
  }

  .detail-panel {
    grid-column: 1 / -1;
    position: static;
  }
}

@media (max-width: 960px) {
  body {
    padding: 12px;
  }

  .topbar,
  .sidebar-header,
  .panel-header {
    flex-direction: column;
    align-items: stretch;
  }

  .meta-row,
  .summary-grid,
  .content-grid,
  .filter-group-inline,
  .kv-grid {
    grid-template-columns: 1fr;
  }

  .filter-sidebar {
    position: static;
  }

  .table {
    min-width: 640px;
  }
}

/* ─── Auth screen ─────────────────────────────────────────── */

.auth-screen {
  display: grid;
  place-items: center;
  min-height: 360px;
  padding: 36px 32px;
}

/* Hide auth-screen card entirely when all child panels are hidden */
.auth-screen:has(> #login-panel.hidden):has(> #not-admin-panel.hidden):has(> #verifying-panel.hidden) {
  display: none;
}

.auth-header {
  margin-bottom: 20px;
}

.auth-header h2 {
  margin-top: 6px;
  margin-bottom: 6px;
  font-size: 1.4rem;
}

.login-form {
  display: grid;
  gap: 14px;
  width: 100%;
  max-width: 380px;
  margin: 0 auto;
}

.form-group {
  display: grid;
  gap: 5px;
}

.form-group label {
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--text-soft);
}

#sign-in-button {
  margin-top: 4px;
  width: 100%;
  padding: 12px;
  font-size: 0.92rem;
  font-weight: 600;
}

#sign-in-button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

.auth-error {
  color: #fca5a5;
  font-size: 0.8rem;
  font-weight: 500;
  margin: 0;
  min-height: 1.2em;
}

.uid-box {
  margin: 16px 0;
  padding: 14px 16px;
  border-radius: var(--radius-md);
  background: rgba(15, 23, 42, 0.7);
  border: 1px solid var(--border-strong);
}

.uid-box-label {
  margin: 0 0 8px;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-soft);
  letter-spacing: 0.02em;
}

.uid-code {
  display: block;
  font-family: 'SFMono-Regular', 'Consolas', 'Liberation Mono', monospace;
  font-size: 0.85rem;
  color: var(--primary);
  word-break: break-all;
  -webkit-user-select: all;
  user-select: all;
}

.auth-note {
  font-size: 0.8rem;
  color: var(--text-soft);
  margin: 0 0 18px;
  line-height: 1.5;
}

.auth-note code {
  font-family: 'SFMono-Regular', 'Consolas', 'Liberation Mono', monospace;
  font-size: 0.78rem;
  color: var(--text);
  background: rgba(148, 163, 184, 0.12);
  padding: 2px 5px;
  border-radius: 4px;
}

#sign-out-not-admin-button {
  width: 100%;
  max-width: 280px;
}

/* Auth spinner for verifying state */
.auth-spinner {
  width: 32px;
  height: 32px;
  margin: 16px auto 0;
  border: 3px solid rgba(96, 165, 250, 0.2);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* Admin invite section */
.invite-section {
  padding: 20px 24px;
  margin-bottom: 0;
}

.invite-header {
  margin-bottom: 12px;
}

.invite-header .eyebrow {
  margin-bottom: 4px;
}

.invite-header h2 {
  font-size: 1rem;
  font-weight: 600;
}

.invite-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.invite-input-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.invite-input-row input {
  flex: 1;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.875rem;
  font-family: inherit;
  background: var(--bg);
  color: var(--text);
}

.invite-input-row input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(96, 165, 250, 0.15);
}

.invite-input-row .primary-button {
  white-space: nowrap;
}

.invite-status {
  font-size: 0.8125rem;
  margin: 0;
  padding: 6px 0;
}

.invite-status.success {
  color: var(--success);
}

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