:root {
  color-scheme: dark;
  --md-bg: #0b0f16;
  --md-surface: #141b27;
  --md-surface-elevated: #1b2433;
  --md-border: rgba(148, 163, 184, 0.25);
  --md-soft-border: rgba(148, 163, 184, 0.12);
  --md-text: #e9edf5;
  --md-muted: #9aa6b8;
  --md-primary: #4f8cff;
  --md-danger: #ff6b6b;
}

html,
body {
  background-color: var(--md-bg);
  color: var(--md-text);
}

a {
  color: var(--md-primary);
  text-decoration: underline;
  text-decoration-color: rgba(79, 140, 255, 0.65);
  text-underline-offset: 0.2em;
  transition: color 0.2s ease, text-decoration-color 0.2s ease;
}

a:hover,
a:focus {
  color: #8cb2ff;
  text-decoration-color: currentColor;
}

a:focus-visible {
  outline: 2px solid rgba(140, 178, 255, 0.65);
  outline-offset: 2px;
}

.bg-body-tertiary {
  background-color: rgba(20, 27, 39, 0.92) !important;
  border: 1px solid var(--md-soft-border) !important;
}

.table-dark {
  --bs-table-bg: rgba(12, 16, 24, 0.85);
  --bs-table-border-color: rgba(148, 163, 184, 0.15);
}

.table-dark tbody tr:hover {
  background-color: rgba(30, 41, 59, 0.55);
}

.btn-outline-light {
  border-color: rgba(148, 163, 184, 0.45);
  color: var(--md-text);
}

.btn-outline-light:hover,
.btn-outline-light:focus {
  color: #0b0f16;
  background-color: rgba(229, 231, 235, 0.9);
  border-color: rgba(229, 231, 235, 0.9);
}

.qr-fab {
  position: fixed;
  right: 1.75rem;
  bottom: 1.75rem;
  width: 3.25rem;
  height: 3.25rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  z-index: 1050;
}

.qr-fab svg {
  pointer-events: none;
}

.receipt-upload__dropzone {
  border: 1px dashed var(--md-border);
  transition: border-color 0.2s ease, background-color 0.2s ease;
}

.receipt-upload__dropzone--active {
  border-color: var(--md-primary);
  background-color: rgba(79, 140, 255, 0.1);
}

.trace-entry {
  border: 1px solid var(--md-soft-border);
  border-radius: 0.75rem;
  background: var(--md-surface);
  margin-bottom: 0.75rem;
  overflow: hidden;
}

.trace-entry--nested {
  margin-left: 1rem;
}

.trace-entry summary {
  cursor: pointer;
  padding: 0.75rem 1rem;
  background: rgba(79, 140, 255, 0.08);
  font-weight: 600;
  list-style: none;
}

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

.trace-entry__title {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.trace-entry__title-main {
  font-size: 0.95rem;
}

.trace-entry__title-meta {
  font-size: 0.75rem;
  color: var(--md-muted);
}

.trace-entry__body {
  padding: 0.75rem 1rem 1rem;
  display: grid;
  gap: 0.5rem;
  background: rgba(15, 23, 42, 0.75);
}

.trace-leaf__key {
  font-weight: 600;
  font-size: 0.8rem;
  color: var(--md-muted);
}

.trace-leaf__value {
  font-family: "JetBrains Mono", "Fira Code", ui-monospace, SFMono-Regular, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-size: 0.8rem;
  padding: 0.35rem 0.5rem;
  border-radius: 0.5rem;
  background: rgba(12, 16, 24, 0.85);
  border: 1px solid rgba(148, 163, 184, 0.12);
  word-break: break-word;
}

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

.qr-item {
  transition: transform 0.2s ease;
}

.qr-item:hover {
  transform: translateY(-2px);
}

.qr-item__code {
  margin: 0.5rem 0;
  display: flex;
  justify-content: center;
}

.alert-secondary {
  background-color: rgba(23, 31, 45, 0.85);
  border-color: rgba(148, 163, 184, 0.18);
  color: var(--md-text);
}

.alert-success {
  background-color: rgba(34, 197, 94, 0.16);
  border-color: rgba(34, 197, 94, 0.35);
  color: #86efac;
}

.alert-danger {
  background-color: rgba(248, 113, 113, 0.16);
  border-color: rgba(248, 113, 113, 0.4);
  color: #fca5a5;
}

.badge.bg-dark-subtle {
  background-color: rgba(30, 41, 59, 0.75) !important;
}

summary::-webkit-details-marker,
summary::marker {
  display: none;
}

.trace-entry[open] > summary {
  background: rgba(79, 140, 255, 0.18);
}

.trace-entry summary::after {
  content: '▸';
  font-size: 0.75rem;
  margin-left: auto;
  transition: transform 0.2s ease;
}

.trace-entry[open] summary::after {
  transform: rotate(90deg);
}

.link-secondary:hover {
  color: var(--md-primary) !important;
}

.badge.text-bg-success {
  background-color: rgba(34, 197, 94, 0.25) !important;
  color: #bbf7d0 !important;
}

.badge.text-bg-danger {
  background-color: rgba(248, 113, 113, 0.25) !important;
  color: #fecaca !important;
}

@media (max-width: 576px) {
.qr-fab {
  right: 1rem;
  bottom: 1rem;
}
}

.trace-panel {
  grid-template-columns: 1fr;
}

.trace-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
}

.trace-toolbar__hint {
  margin: 0;
}

.trace-tree-wrapper {
  position: relative;
  width: 100%;
  min-height: 420px;
  border: 1px solid rgba(148, 163, 184, 0.2);
  border-radius: 1rem;
  background: rgba(15, 23, 42, 0.55);
  overflow: hidden;
}

.trace-tree-wrapper svg {
  width: 100%;
  height: 100%;
}

.trace-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 1.5rem;
  align-items: center;
}

.trace-legend__item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.8rem;
  color: rgba(226, 232, 240, 0.82);
}

.trace-legend__title {
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.72rem;
  color: rgba(148, 163, 184, 0.9);
}

.trace-legend__swatch {
  width: 0.9rem;
  height: 0.9rem;
  border-radius: 0.3rem;
  box-shadow: 0 0 0 1px rgba(15, 23, 42, 0.65);
}

.trace-detail {
  background: rgba(12, 18, 28, 0.82);
  border: 1px solid rgba(148, 163, 184, 0.25);
  border-radius: 0.9rem;
  padding: 1rem;
}

.trace-json {
  margin: 0;
  padding: 1rem;
  background: rgba(9, 13, 20, 0.85);
  border: 1px solid rgba(148, 163, 184, 0.18);
  border-radius: 0.75rem;
  color: rgba(226, 232, 240, 0.9);
  font-family: "JetBrains Mono", "Fira Code", ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-size: 0.78rem;
  max-height: 260px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
}

.trace-tree-node circle {
  transition: fill 0.15s ease, r 0.15s ease;
}

.trace-tree-node.is-active circle {
  r: 6.5;
  stroke-width: 2;
}

.trace-tree-label {
  fill: rgba(226, 232, 240, 0.9);
  font-size: 0.78rem;
  pointer-events: none;
}
