:root {
  --background: 0 0% 100%;
  --foreground: 240 10% 3.9%;
  --card: 0 0% 100%;
  --card-foreground: 240 10% 3.9%;
  --primary: 240 5.9% 10%;
  --primary-foreground: 0 0% 98%;
  --secondary: 240 4.8% 95.9%;
  --secondary-foreground: 240 6% 14%;
  --muted: 240 4.8% 95.9%;
  --muted-foreground: 240 5% 32%;
  --accent: 240 4.8% 95.9%;
  --accent-foreground: 240 5.9% 10%;
  --destructive: 0 72% 42%;
  --destructive-foreground: 0 0% 98%;
  --success: 142 71% 28%;
  --warning: 38 92% 32%;
  --border: 240 5.9% 86%;
  --input: 240 5.9% 86%;
  --ring: 240 5.9% 10%;
  --radius: 0.5rem;
}

@media (prefers-color-scheme: dark) {
  :root {
    --background: 240 10% 3.9%;
    --foreground: 0 0% 98%;
    --card: 240 10% 6%;
    --card-foreground: 0 0% 98%;
    --primary: 0 0% 98%;
    --primary-foreground: 240 5.9% 10%;
    --secondary: 240 3.7% 15.9%;
    --secondary-foreground: 0 0% 98%;
    --muted: 240 3.7% 15.9%;
    --muted-foreground: 240 5% 74%;
    --accent: 240 3.7% 15.9%;
    --accent-foreground: 0 0% 98%;
    --success: 142 70% 65%;
    --warning: 38 92% 65%;
    --border: 240 3.7% 18%;
    --input: 240 3.7% 18%;
    --ring: 240 4.9% 83.9%;
  }
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.55;
  color: hsl(var(--foreground));
  background: hsl(var(--background));
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-feature-settings: 'cv11', 'ss01', 'ss03';
  text-rendering: optimizeLegibility;
}

body { min-height: 100vh; }

.container {
  max-width: 1120px;
  margin: 0 auto;
  padding: 48px 24px;
}

/* ── header ────────────────────────────────────────────────── */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 32px;
  flex-wrap: wrap;
}

.page-header h1 {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-bottom: 6px;
  color: hsl(var(--foreground));
}

.page-header > div > p { font-size: 15px; }

.header-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.badges { display: flex; gap: 8px; flex-wrap: wrap; }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px;
  border-radius: 9999px;
  font-size: 12.5px;
  font-weight: 500;
  background: hsl(var(--background));
  color: hsl(var(--foreground));
  border: 1px solid hsl(var(--border));
  font-variant-numeric: tabular-nums;
}

.badge--secondary {
  background: hsl(var(--secondary));
  color: hsl(var(--secondary-foreground));
}

.badge__dot {
  width: 6px;
  height: 6px;
  border-radius: 9999px;
  background: hsl(var(--success));
  display: inline-block;
  box-shadow: 0 0 0 2px hsl(var(--success) / 0.15);
}

/* ── grid ──────────────────────────────────────────────────── */
.grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
  align-items: start;
}

@media (max-width: 900px) {
  .grid { grid-template-columns: 1fr; }
  .container { padding: 32px 16px; }
}

/* ── card ──────────────────────────────────────────────────── */
.card {
  background: hsl(var(--card));
  color: hsl(var(--card-foreground));
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius);
  box-shadow: 0 1px 2px hsl(0 0% 0% / 0.04);
}

.card-header { padding: 24px 24px 0; }

.card-title {
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.01em;
  margin-bottom: 4px;
}

.card-description {
  font-size: 14px;
  color: hsl(var(--muted-foreground));
}

.card-content { padding: 20px 24px 24px; }
.card-content + .card-content { padding-top: 20px; }

.card-footer {
  padding: 16px 24px;
  border-top: 1px solid hsl(var(--border));
  background: hsl(var(--muted) / 0.4);
  border-radius: 0 0 calc(var(--radius) - 1px) calc(var(--radius) - 1px);
}

.separator {
  height: 1px;
  background: hsl(var(--border));
  margin: 0;
}

/* ── buttons ───────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 18px;
  height: 38px;
  border-radius: calc(var(--radius) - 2px);
  font-size: 14px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  border: 1px solid transparent;
  white-space: nowrap;
  transition: background-color 0.15s ease, color 0.15s ease, border-color 0.15s ease, opacity 0.15s ease;
  outline: none;
}

.btn:focus-visible {
  box-shadow: 0 0 0 2px hsl(var(--background)), 0 0 0 4px hsl(var(--ring));
}

.btn--primary {
  background: hsl(var(--primary));
  color: hsl(var(--primary-foreground));
}
.btn--primary:hover { background: hsl(var(--primary) / 0.9); }

.btn--outline {
  background: hsl(var(--background));
  color: hsl(var(--foreground));
  border-color: hsl(var(--border));
}
.btn--outline:hover {
  background: hsl(var(--accent));
  color: hsl(var(--accent-foreground));
}

.btn--ghost {
  background: transparent;
  color: hsl(var(--foreground));
}
.btn--ghost:hover { background: hsl(var(--accent)); }

.btn[disabled], .btn--busy {
  opacity: 0.6;
  cursor: not-allowed;
  pointer-events: none;
}

.btn--full { width: 100%; }
.btn--justify-start { justify-content: flex-start; }

.btn--sm {
  height: 30px;
  padding: 0 12px;
  font-size: 13px;
  gap: 6px;
}

.btn--destructive-ghost {
  background: transparent;
  color: hsl(var(--destructive));
  border-color: hsl(var(--destructive) / 0.3);
}
.btn--destructive-ghost:hover {
  background: hsl(var(--destructive) / 0.08);
  border-color: hsl(var(--destructive) / 0.55);
  color: hsl(var(--destructive));
}

/* ── inputs ────────────────────────────────────────────────── */
.input {
  display: block;
  width: 100%;
  height: 38px;
  padding: 0 12px;
  background: hsl(var(--background));
  border: 1px solid hsl(var(--input));
  border-radius: calc(var(--radius) - 2px);
  font-size: 14.5px;
  font-family: inherit;
  color: hsl(var(--foreground));
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
  outline: none;
}

.input:focus-visible {
  border-color: hsl(var(--ring));
  box-shadow: 0 0 0 1px hsl(var(--ring));
}

.input::placeholder { color: hsl(var(--muted-foreground)); }

.input--sm {
  height: 34px;
  width: 76px;
  padding: 0 10px;
  font-size: 14px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.input[type="number"]::-webkit-outer-spin-button,
.input[type="number"]::-webkit-inner-spin-button {
  -webkit-appearance: none;
}
.input[type="number"] { -moz-appearance: textfield; }

/* ── label ─────────────────────────────────────────────────── */
.label {
  display: block;
  font-size: 13.5px;
  font-weight: 600;
  color: hsl(var(--foreground));
  margin-bottom: 6px;
  letter-spacing: -0.005em;
}

/* ── tabs ──────────────────────────────────────────────────── */
.tabs {
  display: inline-flex;
  gap: 2px;
  padding: 3px;
  background: hsl(var(--muted));
  border-radius: calc(var(--radius) - 2px);
  margin-bottom: 16px;
}

.tab {
  padding: 5px 16px;
  height: 30px;
  font-size: 13.5px;
  font-weight: 500;
  background: transparent;
  border: none;
  border-radius: calc(var(--radius) - 4px);
  color: hsl(var(--muted-foreground));
  cursor: pointer;
  font-family: inherit;
  transition: background 0.15s, color 0.15s, box-shadow 0.15s;
  outline: none;
}

.tab:hover { color: hsl(var(--foreground)); }

.tab--active {
  background: hsl(var(--background));
  color: hsl(var(--foreground));
  box-shadow: 0 1px 2px hsl(0 0% 0% / 0.08);
}

.tab:focus-visible {
  box-shadow: 0 0 0 2px hsl(var(--background)), 0 0 0 4px hsl(var(--ring));
}

/* ── fields ────────────────────────────────────────────────── */
.field { margin-bottom: 16px; }
.field[hidden] { display: none; }

.field-inline {
  display: flex;
  align-items: center;
  gap: 10px;
}
.field-inline .label { margin-bottom: 0; }

.controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 4px;
}

/* ── dropzone ──────────────────────────────────────────────── */
.dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 6px;
  padding: 36px 24px;
  border: 1px dashed hsl(var(--border));
  border-radius: calc(var(--radius) - 2px);
  background: hsl(var(--muted) / 0.4);
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.dropzone:hover {
  background: hsl(var(--muted) / 0.7);
  border-color: hsl(var(--ring) / 0.5);
}

.dropzone--active {
  background: hsl(var(--accent));
  border-color: hsl(var(--ring));
  border-style: solid;
}

.dropzone__icon {
  width: 28px;
  height: 28px;
  color: hsl(var(--muted-foreground));
  margin-bottom: 6px;
}

.dropzone__title {
  font-size: 15px;
  font-weight: 500;
  color: hsl(var(--foreground));
}

.dropzone__hint { font-size: 12.5px; }

/* ── ledger ────────────────────────────────────────────────── */
.ledger__head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 8px;
}

.ledger ul { list-style: none; }

.ledger__empty {
  padding: 6px 0;
}

.ledger li:not(.ledger__empty) {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 12px;
  padding: 9px 0;
  border-bottom: 1px solid hsl(var(--border));
  font-size: 13.5px;
  animation: slideIn 0.2s ease-out both;
}

.ledger li:last-child { border-bottom: none; }

.ledger__name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: hsl(var(--foreground));
}

.ledger__status {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11.5px;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: 9999px;
  border: 1px solid transparent;
  letter-spacing: 0.01em;
}

.ledger__status--pending {
  background: hsl(var(--muted));
  color: hsl(var(--muted-foreground));
  border-color: hsl(var(--border));
}
.ledger__status--pending::before {
  content: '';
  width: 7px;
  height: 7px;
  border: 1.5px solid currentColor;
  border-top-color: transparent;
  border-radius: 9999px;
  animation: spin 0.8s linear infinite;
}
.ledger__status--done {
  background: hsl(var(--success) / 0.1);
  color: hsl(var(--success));
  border-color: hsl(var(--success) / 0.2);
}
.ledger__status--done::before {
  content: '✓';
  font-size: 10px;
  font-weight: 700;
}
.ledger__status--error {
  background: hsl(var(--destructive) / 0.1);
  color: hsl(var(--destructive));
  border-color: hsl(var(--destructive) / 0.2);
}
.ledger__status--error::before {
  content: '×';
  font-size: 13px;
  font-weight: 700;
  line-height: 1;
}

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

/* ── results ───────────────────────────────────────────────── */
.results-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 12px;
}

.results-header h3 {
  font-size: 15px;
  font-weight: 600;
}

.empty {
  padding: 18px 0;
  text-align: center;
  font-size: 13.5px;
}

.result {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 14px;
  border: 1px solid hsl(var(--border));
  border-radius: calc(var(--radius) - 2px);
  background: hsl(var(--card));
  transition: background 0.15s, border-color 0.15s;
  animation: slideIn 0.25s ease-out both;
}

.result + .result { margin-top: 10px; }
.result:hover { background: hsl(var(--muted) / 0.3); }

.result__head {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 14px;
  align-items: center;
}

.result__rank {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: 9999px;
  background: hsl(var(--secondary));
  color: hsl(var(--secondary-foreground));
  font-size: 12px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  flex-shrink: 0;
}

.result__main { min-width: 0; }

.result__name {
  font-size: 14.5px;
  font-weight: 500;
  color: hsl(var(--foreground));
  margin-bottom: 3px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.result__meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0 8px;
  font-size: 12.5px;
  color: hsl(var(--muted-foreground));
}

.result__meta span:not(:last-child)::after {
  content: '·';
  margin-left: 8px;
  color: hsl(var(--border));
}

.result__distance {
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: hsl(var(--foreground));
  background: hsl(var(--secondary));
  padding: 5px 10px;
  border-radius: calc(var(--radius) - 4px);
  white-space: nowrap;
  letter-spacing: -0.01em;
}

/* ── result previews ───────────────────────────────────────── */
.result__preview {
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: calc(var(--radius) - 4px);
  background: hsl(var(--muted) / 0.6);
  border: 1px solid hsl(var(--border));
  overflow: hidden;
  max-width: 100%;
}

.result__preview--image {
  padding: 0;
  background: hsl(var(--muted));
  text-decoration: none;
  transition: opacity 0.15s ease;
}
.result__preview--image:hover { opacity: 0.9; }
.result__preview--image img {
  display: block;
  max-width: 100%;
  max-height: 280px;
  width: auto;
  height: auto;
  object-fit: contain;
}

.result__preview--video video {
  display: block;
  max-width: 100%;
  max-height: 320px;
  width: 100%;
  background: #000;
}

.result__preview--audio {
  padding: 14px 16px;
  justify-content: stretch;
}
.result__preview--audio audio {
  width: 100%;
}

.result__preview--pdf {
  flex-direction: column;
  align-items: stretch;
  position: relative;
  padding: 0;
  background: hsl(var(--muted));
}
.result__preview--pdf iframe {
  display: block;
  width: 100%;
  height: 360px;
  border: none;
  background: white;
}
.result__preview-open {
  display: block;
  padding: 8px 12px;
  font-size: 12.5px;
  font-weight: 500;
  text-align: right;
  color: hsl(var(--foreground));
  background: hsl(var(--card));
  border-top: 1px solid hsl(var(--border));
  text-decoration: none;
}
.result__preview-open:hover { background: hsl(var(--muted) / 0.6); }

.result__preview--generic {
  padding: 16px;
  font-size: 13px;
}
.result__preview--generic a {
  color: hsl(var(--foreground));
  font-weight: 500;
  text-decoration: none;
}
.result__preview--generic a:hover { text-decoration: underline; }

/* ── alert ─────────────────────────────────────────────────── */
.alert {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  padding: 12px 14px;
  border-radius: calc(var(--radius) - 2px);
  border: 1px solid hsl(var(--destructive) / 0.4);
  background: hsl(var(--destructive) / 0.08);
  color: hsl(var(--destructive));
  font-size: 13.5px;
  font-weight: 500;
}

/* ── footer ────────────────────────────────────────────────── */
.page-footer {
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 32px;
  padding-top: 20px;
  border-top: 1px solid hsl(var(--border));
}

/* ── utilities ─────────────────────────────────────────────── */
.muted { color: hsl(var(--muted-foreground)); }
.small { font-size: 12.5px; }

/* ── animations ────────────────────────────────────────────── */
@keyframes slideIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}
