/* ==========================================================================
   AnyBox — Material Design 3 Expressive with Geist Font & Color Presets
   ========================================================================== */

:root {
  color-scheme: dark;

  /* Typography: Geist & Geist Mono */
  --md-ref-typeface: "Geist", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --md-ref-monospace: "Geist Mono", "JetBrains Mono", ui-monospace, Menlo, Consolas, monospace;

  /* Material Design 3 Dark Theme Base Surfaces */
  --md-sys-color-surface: #141318;
  --md-sys-color-surface-dim: #141318;
  --md-sys-color-surface-bright: #3b383e;
  --md-sys-color-surface-container-lowest: #0f0d13;
  --md-sys-color-surface-container-low: #1d1b20;
  --md-sys-color-surface-container: #211f26;
  --md-sys-color-surface-container-high: #2b2930;
  --md-sys-color-surface-container-highest: #36343b;

  --md-sys-color-on-surface: #e6e0e9;
  --md-sys-color-on-surface-variant: #cac4d0;
  --md-sys-color-outline: #938f99;
  --md-sys-color-outline-variant: #49454f;

  /* Default Preset: Purple / Lavender */
  --md-sys-color-primary: #d0bcff;
  --md-sys-color-on-primary: #381e72;
  --md-sys-color-primary-container: #4f378b;
  --md-sys-color-on-primary-container: #eaddff;

  --md-sys-color-secondary: #ccc2dc;
  --md-sys-color-on-secondary: #332d41;
  --md-sys-color-secondary-container: #4a4458;
  --md-sys-color-on-secondary-container: #e8def8;

  --md-sys-color-error: #f2b8b5;
  --md-sys-color-on-error: #601410;
  --md-sys-color-error-container: #8c1d18;
  --md-sys-color-on-error-container: #f9dedc;

  --md-color-success: #81c784;

  /* Shape tokens */
  --md-shape-corner-small: 8px;
  --md-shape-corner-medium: 12px;
  --md-shape-corner-large: 16px;
  --md-shape-corner-extra-large: 24px;
  --md-shape-corner-full: 9999px;

  /* State layers */
  --md-state-hover: rgba(255, 255, 255, 0.08);
  --md-state-pressed: rgba(255, 255, 255, 0.12);
}

/* ==========================================================================
   M3 Dynamic Color Presets (Monet Palettes)
   ========================================================================== */

[data-color-preset="blue"] {
  --md-sys-color-primary: #a8c7fa;
  --md-sys-color-on-primary: #062e6f;
  --md-sys-color-primary-container: #0842a0;
  --md-sys-color-on-primary-container: #d3e3fd;
  --md-sys-color-secondary-container: #3d4758;
  --md-sys-color-on-secondary-container: #d8e2f9;
}

[data-color-preset="green"] {
  --md-sys-color-primary: #9cd69b;
  --md-sys-color-on-primary: #00390f;
  --md-sys-color-primary-container: #1b5223;
  --md-sys-color-on-primary-container: #b8f3b6;
  --md-sys-color-secondary-container: #3e4a3c;
  --md-sys-color-on-secondary-container: #d9e6d7;
}

[data-color-preset="orange"] {
  --md-sys-color-primary: #ffb68c;
  --md-sys-color-on-primary: #522300;
  --md-sys-color-primary-container: #753400;
  --md-sys-color-on-primary-container: #ffdbc9;
  --md-sys-color-secondary-container: #51433b;
  --md-sys-color-on-secondary-container: #f2dfd6;
}

[data-color-preset="pink"] {
  --md-sys-color-primary: #ffb0cd;
  --md-sys-color-on-primary: #5e1136;
  --md-sys-color-primary-container: #7b294d;
  --md-sys-color-on-primary-container: #ffd9e4;
  --md-sys-color-secondary-container: #534349;
  --md-sys-color-on-secondary-container: #f7dee6;
}

[data-color-preset="cyan"] {
  --md-sys-color-primary: #80d5e2;
  --md-sys-color-on-primary: #00363d;
  --md-sys-color-primary-container: #004f58;
  --md-sys-color-on-primary-container: #9cebf8;
  --md-sys-color-secondary-container: #3b484b;
  --md-sys-color-on-secondary-container: #d6e5e8;
}

/* ==========================================================================
   Global Reset & Layout
   ========================================================================== */

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  min-height: 100%;
  background-color: var(--md-sys-color-surface);
  color: var(--md-sys-color-on-surface);
  font-family: var(--md-ref-typeface);
  -webkit-font-smoothing: antialiased;
}

body {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0 16px 36px 16px;
}

/* App Top Bar */
.app-top-bar {
  width: 100%;
  max-width: 768px;
  padding: 20px 0 24px 0;
}

.app-top-bar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 48px;
}

.app-title {
  font-size: 1.5rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--md-sys-color-on-surface);
}

.spacer {
  flex: 1;
}

.header-controls {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* Network Chip */
.network-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 14px;
  background-color: var(--md-sys-color-surface-container-high);
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--md-shape-corner-full);
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--md-sys-color-on-surface-variant);
}

.network-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: var(--md-sys-color-outline);
  transition: background-color 0.25s ease;
}

.network-dot.online {
  background-color: var(--md-color-success);
}

.network-dot.offline {
  background-color: var(--md-sys-color-error);
}

.network-latency {
  font-family: var(--md-ref-monospace);
  font-size: 0.75rem;
  opacity: 0.8;
}

/* Theming Popover & Anchor */
.theme-picker-anchor {
  position: relative;
}

.theme-popover {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  width: 220px;
  background-color: var(--md-sys-color-surface-container);
  border: 1px solid var(--md-sys-color-outline-variant);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
  border-radius: var(--md-shape-corner-large);
  padding: 14px;
  z-index: 100;
  animation: m3MenuIn 0.15s cubic-bezier(0, 0, 0.2, 1);
}

@keyframes m3MenuIn {
  from { opacity: 0; transform: translateY(-4px) scale(0.96); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.theme-popover-header {
  margin-bottom: 10px;
}

.theme-popover-title {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--md-sys-color-on-surface-variant);
}

.theme-swatches-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 8px;
}

.theme-swatch {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background-color: var(--swatch-color);
  border: 2px solid transparent;
  cursor: pointer;
  outline: none;
  transition: transform 0.15s ease, border-color 0.15s ease;
}

.theme-swatch:hover {
  transform: scale(1.15);
}

.theme-swatch.active {
  border-color: #ffffff;
  box-shadow: 0 0 0 2px var(--md-sys-color-surface);
}

/* Main Container */
.main-content {
  width: 100%;
  max-width: 768px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* Base M3 Card */
.m3-card {
  background-color: var(--md-sys-color-surface-container-low);
  border-radius: var(--md-shape-corner-extra-large);
  padding: 22px;
  position: relative;
  border: none;
  transition: background-color 0.25s ease;
}

/* Action Trigger Card */
.fetch-card-content {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.m3-title-large {
  font-size: 1.25rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--md-sys-color-on-surface);
}

.m3-body-medium {
  font-size: 0.875rem;
  font-weight: 400;
  letter-spacing: 0.15px;
  color: var(--md-sys-color-on-surface-variant);
  margin-top: 4px;
}

/* M3 Buttons */
.m3-filled-button,
.m3-filled-tonal-button,
.m3-outlined-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 40px;
  padding: 0 24px;
  border-radius: var(--md-shape-corner-full);
  font-family: var(--md-ref-typeface);
  font-size: 0.875rem;
  font-weight: 500;
  letter-spacing: 0.1px;
  cursor: pointer;
  border: none;
  text-decoration: none;
  white-space: nowrap;
  transition: background-color 0.2s, box-shadow 0.2s, transform 0.1s;
}

.m3-filled-button:active,
.m3-filled-tonal-button:active,
.m3-outlined-button:active {
  transform: scale(0.98);
}

.m3-filled-button {
  background-color: var(--md-sys-color-primary);
  color: var(--md-sys-color-on-primary);
}

.m3-filled-button:hover:not(:disabled) {
  box-shadow: 0 1px 3px 1px rgba(0, 0, 0, 0.15);
  background-color: color-mix(in srgb, var(--md-sys-color-primary) 90%, #ffffff);
}

.m3-btn-download {
  background-color: var(--md-sys-color-primary);
  color: var(--md-sys-color-on-primary);
}

.m3-filled-tonal-button {
  background-color: var(--md-sys-color-secondary-container);
  color: var(--md-sys-color-on-secondary-container);
}

.m3-filled-tonal-button:hover:not(:disabled) {
  background-color: color-mix(in srgb, var(--md-sys-color-secondary-container) 90%, #ffffff);
}

.m3-outlined-button {
  background-color: transparent;
  color: var(--md-sys-color-primary);
  border: 1px solid var(--md-sys-color-outline);
}

.m3-outlined-button:hover:not(:disabled) {
  background-color: var(--md-state-hover);
}

.m3-filled-button:disabled,
.m3-filled-tonal-button:disabled,
.m3-outlined-button:disabled {
  opacity: 0.38;
  cursor: not-allowed;
  transform: none;
}

.m3-icon-button {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  color: var(--md-sys-color-on-surface-variant);
  cursor: pointer;
  transition: background-color 0.2s, color 0.2s;
}

.m3-icon-button:hover {
  background-color: var(--md-state-hover);
  color: var(--md-sys-color-on-surface);
}

/* Results Section */
.results-section {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* Specter-Style Hero Grid */
.hero-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.kb-hero-card {
  background-color: color-mix(in srgb, var(--md-sys-color-primary-container) 45%, var(--md-sys-color-surface));
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 16px;
}

.kb-label {
  display: block;
  font-size: 0.6875rem;
  letter-spacing: 0.5px;
  font-weight: 500;
  text-transform: uppercase;
  color: var(--md-sys-color-on-surface-variant);
  margin-bottom: 4px;
}

.kb-name-row {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.kb-name {
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--md-sys-color-on-surface);
  word-break: break-all;
}

.kb-hero-footer {
  border-top: 1px solid var(--md-sys-color-outline-variant);
  padding-top: 12px;
}

.kb-status-row {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.kb-status-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.kb-status-text {
  font-size: 0.9375rem;
  font-weight: 500;
  color: var(--md-sys-color-on-surface);
}

.sp-hero-card {
  background-color: var(--md-sys-color-surface-container);
  display: flex;
  flex-direction: column;
  justify-content: space-around;
  gap: 12px;
}

.sp-entry {
  display: flex;
  flex-direction: column;
}

.sp-value {
  font-size: 0.9375rem;
  font-weight: 500;
  color: var(--md-sys-color-on-surface);
}

/* SHA-256 Card */
.hash-card {
  background-color: var(--md-sys-color-surface-container-low);
  padding: 16px 20px;
}

.hash-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.m3-assist-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 32px;
  padding: 0 12px;
  border-radius: var(--md-shape-corner-small);
  background-color: var(--md-sys-color-surface-container-high);
  border: 1px solid var(--md-sys-color-outline-variant);
  color: var(--md-sys-color-on-surface);
  font-family: var(--md-ref-typeface);
  font-size: 0.75rem;
  font-weight: 500;
  cursor: pointer;
  transition: background-color 0.2s;
}

.m3-assist-chip:hover {
  background-color: var(--md-sys-color-surface-container-highest);
}

.hash-code-block {
  font-family: var(--md-ref-monospace);
  font-size: 0.8125rem;
  color: var(--md-sys-color-on-surface-variant);
  background-color: var(--md-sys-color-surface-container-lowest);
  padding: 10px 14px;
  border-radius: var(--md-shape-corner-medium);
  word-break: break-all;
}

/* Action Buttons Row */
.action-buttons-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

/* Viewer Card */
.viewer-card {
  background-color: var(--md-sys-color-surface-container-lowest);
  padding: 0;
  overflow: hidden;
  border: 1px solid var(--md-sys-color-outline-variant);
}

.viewer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  background-color: var(--md-sys-color-surface-container-low);
  border-bottom: 1px solid var(--md-sys-color-outline-variant);
}

.m3-label-large {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--md-sys-color-on-surface);
}

.viewer-lines {
  font-family: var(--md-ref-monospace);
  font-size: 0.75rem;
  color: var(--md-sys-color-on-surface-variant);
}

.code-container {
  max-height: 400px;
  overflow-y: auto;
  padding: 16px 20px;
}

.code-container pre {
  font-family: var(--md-ref-monospace);
  font-size: 0.8125rem;
  line-height: 1.6;
  color: var(--md-sys-color-on-surface-variant);
  white-space: pre-wrap;
  word-break: break-all;
}

/* Guide Card */
.guide-card {
  background-color: var(--md-sys-color-surface-container-low);
}

.guide-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--md-sys-color-on-surface);
  margin-bottom: 14px;
}

.guide-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.guide-item {
  display: flex;
  align-items: flex-start;
  gap: 14px;
}

.guide-num {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background-color: var(--md-sys-color-primary-container);
  color: var(--md-sys-color-on-primary-container);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 600;
  flex-shrink: 0;
  margin-top: 2px;
}

.guide-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-size: 0.875rem;
  color: var(--md-sys-color-on-surface-variant);
}

.guide-heading {
  font-weight: 500;
  color: var(--md-sys-color-on-surface);
}

.guide-text code {
  font-family: var(--md-ref-monospace);
  font-size: 0.8em;
  background-color: var(--md-sys-color-surface-container-high);
  padding: 2px 6px;
  border-radius: 4px;
  color: var(--md-sys-color-on-surface);
}

/* Alert */
.m3-alert {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 16px;
  border-radius: var(--md-shape-corner-medium);
  background-color: var(--md-sys-color-error-container);
  color: var(--md-sys-color-on-error-container);
  margin-top: 14px;
}

.m3-alert-icon {
  flex-shrink: 0;
  margin-top: 2px;
}

.m3-alert-title {
  font-size: 0.875rem;
  font-weight: 600;
}

.m3-alert-message {
  font-size: 0.8125rem;
  margin-top: 2px;
}

/* Footer */
.app-footer {
  padding: 24px 0;
  text-align: center;
  font-size: 0.75rem;
  color: var(--md-sys-color-outline);
}

/* Toast Container (M3 Snackbar Style) */
.toast-container {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 1000;
  pointer-events: none;
}

.m3-snackbar {
  background-color: var(--md-sys-color-surface-container-highest);
  color: var(--md-sys-color-on-surface);
  border: 1px solid var(--md-sys-color-outline-variant);
  box-shadow: 0 4px 8px 3px rgba(0, 0, 0, 0.15);
  padding: 10px 18px;
  border-radius: var(--md-shape-corner-small);
  font-size: 0.875rem;
  font-weight: 400;
  pointer-events: auto;
  animation: m3SnackbarIn 0.2s cubic-bezier(0, 0, 0.2, 1);
}

@keyframes m3SnackbarIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.hidden {
  display: none !important;
}

.spinner {
  animation: m3Rotate 1s linear infinite;
}

@keyframes m3Rotate {
  100% { transform: rotate(360deg); }
}

/* ==========================================================================
   Source & Provider Picker Styles
   ========================================================================== */

.source-picker-container {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 20px;
  padding-top: 18px;
  border-top: 1px solid var(--md-sys-color-outline-variant);
}

.source-picker-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 6px;
}

.source-picker-label {
  font-size: 0.8125rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--md-sys-color-primary);
}

.source-picker-hint {
  font-size: 0.75rem;
  color: var(--md-sys-color-on-surface-variant);
}

.source-chips-group {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.source-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  border-radius: var(--md-shape-corner-full);
  border: 1px solid var(--md-sys-color-outline-variant);
  background: var(--md-sys-color-surface-container-low);
  color: var(--md-sys-color-on-surface);
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.2, 0, 0, 1);
  user-select: none;
}

.source-chip:hover {
  background: var(--md-sys-color-surface-container-high);
  border-color: var(--md-sys-color-outline);
}

.source-chip.active {
  background: var(--md-sys-color-primary-container);
  color: var(--md-sys-color-on-primary-container);
  border-color: var(--md-sys-color-primary);
  box-shadow: 0 0 12px rgba(208, 188, 255, 0.12);
}

.source-chip-icon {
  flex-shrink: 0;
}

.provider-select-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 4px;
  animation: m3FadeIn 0.25s ease-out;
}

.provider-select-row.hidden {
  display: none !important;
}

.provider-select-label-wrap {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.provider-field-label {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--md-sys-color-on-surface-variant);
}

.provider-badge-indicator {
  font-size: 0.6875rem;
  padding: 2px 8px;
  border-radius: var(--md-shape-corner-full);
  background: var(--md-sys-color-surface-container-highest);
  color: var(--md-sys-color-primary);
  font-weight: 600;
}

.m3-select-wrapper {
  position: relative;
  width: 100%;
}

.m3-select {
  width: 100%;
  appearance: none;
  -webkit-appearance: none;
  padding: 10px 38px 10px 14px;
  border-radius: var(--md-shape-corner-medium);
  border: 1px solid var(--md-sys-color-outline-variant);
  background: var(--md-sys-color-surface-container);
  color: var(--md-sys-color-on-surface);
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  outline: none;
  transition: border-color 0.2s, background-color 0.2s;
}

.m3-select:hover {
  border-color: var(--md-sys-color-outline);
  background: var(--md-sys-color-surface-container-high);
}

.m3-select:focus {
  border-color: var(--md-sys-color-primary);
  box-shadow: 0 0 0 1px var(--md-sys-color-primary);
}

.m3-select-arrow {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  pointer-events: none;
  color: var(--md-sys-color-outline);
}

/* Source & Status Badges on Result Card */
.kb-source-badge-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  flex-wrap: wrap;
}

.m3-source-tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 3px 8px;
  border-radius: var(--md-shape-corner-full);
  background: var(--md-sys-color-primary-container);
  color: var(--md-sys-color-on-primary-container);
}

.m3-status-tag {
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 3px 8px;
  border-radius: var(--md-shape-corner-full);
  background: var(--md-sys-color-surface-container-highest);
  color: var(--md-sys-color-on-surface-variant);
}

.m3-status-tag.strong {
  background: rgba(129, 199, 132, 0.16);
  color: #81c784;
  border: 1px solid rgba(129, 199, 132, 0.3);
}

.m3-status-tag.softban {
  background: rgba(255, 182, 140, 0.16);
  color: #ffb68c;
  border: 1px solid rgba(255, 182, 140, 0.3);
}

.m3-status-tag.revoked {
  background: rgba(242, 184, 181, 0.16);
  color: #f2b8b5;
  border: 1px solid rgba(242, 184, 181, 0.3);
}

.kb-provider-detail {
  font-size: 0.8125rem;
  color: var(--md-sys-color-on-surface-variant);
  margin-top: 4px;
  font-family: var(--md-ref-monospace);
}

@keyframes m3FadeIn {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (max-width: 600px) {
  .hero-grid {
    grid-template-columns: 1fr;
  }
  .fetch-card-content {
    flex-direction: column;
    align-items: stretch;
  }
  .action-buttons-row button {
    flex: 1 1 100%;
  }
  .source-chip {
    flex: 1 1 auto;
    justify-content: center;
  }
}

