/* ── Reset & tokens ─────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:        #0d1117;
  --surface:   #161b22;
  --surface-2: #1c2128;
  --border:    #30363d;
  --border-2:  #21262d;
  --accent:    #58a6ff;
  --accent-dk: #1f6feb;
  --green:     #3fb950;
  --red:       #f85149;
  --text-1:    #e6edf3;
  --text-2:    #8b949e;
  --text-3:    #6e7681;
  --mono:      'JetBrains Mono', monospace;
  --sans:      'Inter', sans-serif;
  --display:   'Space Grotesk', sans-serif;
  --radius:    8px;
  --radius-lg: 12px;
}

html { scroll-behavior: smooth; }

body {
  background: var(--bg);
  color: var(--text-1);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.6;
  min-height: 100vh;
}

/* ── Header ──────────────────────────────────────────────────────── */
.site-header {
  border-bottom: 1px solid var(--border);
  background: rgba(22, 27, 34, 0.9);
  position: sticky;
  top: 0;
  z-index: 100;
  backdrop-filter: blur(12px);
}

.header-inner {
  max-width: 860px;
  margin: 0 auto;
  padding: 0.9rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

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

.header-title {
  font-family: var(--display);
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--text-1);
}

.header-sub {
  font-size: 0.76rem;
  font-weight: 500;
  color: var(--text-2);
  margin-top: 0.15rem;
  font-family: var(--mono);
}

/* ── Layout ──────────────────────────────────────────────────────── */
.main-content {
  max-width: 860px;
  margin: 0 auto;
  padding: 2rem 1.5rem 5rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

/* ── Card ────────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.75rem;
}

.card-title {
  font-family: var(--mono);
  font-size: 0.68rem;
  font-weight: 500;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-3);
  margin-bottom: 1.25rem;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.25rem;
}

/* ── Drop zone ───────────────────────────────────────────────────── */
.drop-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 2.75rem 1.5rem;
  text-align: center;
  cursor: pointer;
  background: var(--surface-2);
  margin-bottom: 1.75rem;
  transition: border-color 0.2s, background 0.2s;
  user-select: none;
}

.drop-zone:hover,
.drop-zone.drag-over {
  border-color: var(--accent);
  background: rgba(88, 166, 255, 0.04);
}

.drop-zone.has-file {
  border-style: solid;
  border-color: var(--green);
}

.drop-icon {
  font-size: 1.75rem;
  color: var(--text-3);
  margin-bottom: 0.6rem;
  transition: color 0.2s;
}

.drop-zone:hover .drop-icon,
.drop-zone.drag-over .drop-icon {
  color: var(--accent);
}

.drop-text {
  font-size: 0.95rem;
  font-weight: 500;
  color: var(--text-2);
}

.drop-sub {
  font-size: 0.8rem;
  color: var(--text-3);
  margin-top: 0.3rem;
}

.drop-link {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.drop-filename {
  margin-top: 0.85rem;
  font-family: var(--mono);
  font-size: 0.75rem;
  color: var(--green);
  min-height: 1em;
}

/* ── Sliders ─────────────────────────────────────────────────────── */
.slider-group {
  margin-bottom: 1.4rem;
}

.slider-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.55rem;
}

.slider-label {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-2);
}

.slider-val {
  font-family: var(--mono);
  font-size: 0.8rem;
  color: var(--accent);
  background: rgba(88, 166, 255, 0.1);
  border: 1px solid rgba(88, 166, 255, 0.2);
  padding: 0.1rem 0.55rem;
  border-radius: 4px;
  min-width: 3.5ch;
  text-align: center;
}

.slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 4px;
  border-radius: 2px;
  outline: none;
  cursor: pointer;
  background: var(--border);
}

.slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
  box-shadow: 0 0 0 3px rgba(88, 166, 255, 0.2);
}
.slider::-webkit-slider-thumb:hover {
  transform: scale(1.25);
  box-shadow: 0 0 0 5px rgba(88, 166, 255, 0.25);
}
.slider::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border: none;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
}

.slider-hint {
  font-size: 0.72rem;
  color: var(--text-3);
  margin-top: 0.4rem;
}

/* ── Advanced Settings ───────────────────────────────────────────── */
.advanced-settings {
  margin-bottom: 1.4rem;
}

.advanced-toggle {
  list-style: none;
  display: flex;
  align-items: center;
  gap: 0.45rem;
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--text-3);
  cursor: pointer;
  user-select: none;
  width: fit-content;
}

.advanced-toggle::-webkit-details-marker { display: none; }

.advanced-toggle::before {
  content: '▸';
  font-size: 0.65rem;
  transition: transform 0.2s;
  display: inline-block;
}

.advanced-settings[open] .advanced-toggle::before {
  transform: rotate(90deg);
}

.advanced-toggle:hover { color: var(--text-2); }

.advanced-body {
  margin-top: 1.1rem;
  padding-top: 1.1rem;
  border-top: 1px solid var(--border-2);
}

/* ── Progress ────────────────────────────────────────────────────── */
.progress-section {
  margin-bottom: 1rem;
}

.progress-status {
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--text-2);
  margin-bottom: 0.55rem;
  min-height: 1em;
}

.progress-bar-wrap {
  height: 3px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  width: 0%;
  transition: width 0.3s ease;
}

/* ── Buttons ─────────────────────────────────────────────────────── */
.form-btns {
  display: flex;
  gap: 0.75rem;
  align-items: stretch;
}

.btn-primary {
  flex: 1;
  padding: 0.875rem 1.5rem;
  background: var(--accent-dk);
  color: #fff;
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  font-family: var(--display);
  font-size: 0.95rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  transition: background 0.2s, box-shadow 0.2s;
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent);
  box-shadow: 0 0 20px rgba(88, 166, 255, 0.25);
}

.btn-primary:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-secondary {
  padding: 0.38rem 0.85rem;
  background: transparent;
  color: var(--text-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: var(--mono);
  font-size: 0.72rem;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
  white-space: nowrap;
}

.btn-secondary:hover:not(:disabled) {
  border-color: var(--text-2);
  color: var(--text-1);
}

.btn-secondary:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-cancel {
  padding: 0.875rem 1.25rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.btn-danger:hover {
  border-color: var(--red) !important;
  color: var(--red) !important;
}

/* ── Spinner ─────────────────────────────────────────────────────── */
.spinner {
  width: 15px;
  height: 15px;
  border: 2px solid rgba(255, 255, 255, 0.25);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.65s linear infinite;
  flex-shrink: 0;
}

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

/* ── Results grid ────────────────────────────────────────────────── */
.results-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

/* ── Result card ─────────────────────────────────────────────────── */
.result-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--surface-2);
  cursor: pointer;
  transition: transform 0.18s ease, box-shadow 0.18s ease;
}

.result-card:hover {
  transform: scale(1.015);
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
}

.result-card-img-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 4 / 3;
  overflow: hidden;
}

.result-card-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.result-card-dl {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  width: 28px;
  height: 28px;
  background: rgba(13, 17, 23, 0.82);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-2);
  font-size: 0.8rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.15s, color 0.15s, border-color 0.15s;
}

.result-card:hover .result-card-dl { opacity: 1; }

.result-card-dl:hover {
  color: var(--accent);
  border-color: var(--accent);
}

.result-card-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.55rem 0.85rem;
  gap: 0.5rem;
}

.result-card-name {
  font-family: var(--mono);
  font-size: 0.7rem;
  color: var(--text-2);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.result-card-badge {
  font-family: var(--display);
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--accent);
  background: rgba(88, 166, 255, 0.1);
  border: 1px solid rgba(88, 166, 255, 0.2);
  padding: 0.1rem 0.55rem;
  border-radius: 4px;
  white-space: nowrap;
  flex-shrink: 0;
}

/* ── Lightbox ────────────────────────────────────────────────────── */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.lightbox.open {
  opacity: 1;
  pointer-events: all;
}

.lightbox-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.9);
}

.lightbox-inner {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  max-width: 90vw;
  max-height: 90vh;
}

.lightbox-topbar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.55rem 0.85rem;
  background: rgba(22, 27, 34, 0.97);
  border: 1px solid var(--border);
  border-bottom: none;
  border-radius: var(--radius) var(--radius) 0 0;
}

.lightbox-filename {
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--text-2);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  min-width: 0;
}

.lightbox-badge {
  font-family: var(--mono);
  font-size: 0.68rem;
  color: var(--accent);
  background: rgba(88, 166, 255, 0.1);
  border: 1px solid rgba(88, 166, 255, 0.2);
  padding: 0.1rem 0.55rem;
  border-radius: 4px;
  white-space: nowrap;
  flex-shrink: 0;
}

.lightbox-close {
  background: transparent;
  border: none;
  color: var(--text-3);
  font-size: 0.9rem;
  cursor: pointer;
  padding: 0.1rem 0.25rem;
  line-height: 1;
  flex-shrink: 0;
  transition: color 0.15s;
}

.lightbox-close:hover { color: var(--text-1); }

.lightbox-body {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: visible;
}

.lightbox-img {
  display: block;
  max-width: 90vw;
  max-height: calc(90vh - 42px);
  object-fit: contain;
  border: 1px solid var(--border);
  border-top: none;
  border-radius: 0 0 var(--radius) var(--radius);
}

.lightbox-arrow {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  background: rgba(13, 17, 23, 0.78);
  border: 1px solid var(--border);
  color: var(--text-1);
  font-size: 1.6rem;
  line-height: 1;
  width: 2.4rem;
  height: 2.4rem;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, border-color 0.15s;
  z-index: 2;
}

.lightbox-arrow:hover {
  background: rgba(13, 17, 23, 0.97);
  border-color: var(--text-2);
}

.lightbox-prev { left:  -3.25rem; }
.lightbox-next { right: -3.25rem; }

/* ── Table section ───────────────────────────────────────────────── */
.table-actions {
  display: flex;
  gap: 0.5rem;
}

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

.table-empty {
  font-family: var(--mono);
  font-size: 0.78rem;
  color: var(--text-3);
  padding: 0.5rem 0;
}

/* Pandas-generated table */
#tableDiv table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

#tableDiv table thead th {
  font-family: var(--mono);
  font-size: 0.68rem;
  font-weight: 500;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--text-3);
  padding: 0.6rem 1rem;
  border-bottom: 1px solid var(--border);
  text-align: left;
}

/* Hide pandas row-index column */
#tableDiv table thead tr th:first-child,
#tableDiv table tbody tr th { display: none; }

#tableDiv table tbody td {
  padding: 0.6rem 1rem;
  color: var(--text-2);
  border-bottom: 1px solid var(--border-2);
}

#tableDiv table tbody tr:last-child td { border-bottom: none; }

#tableDiv table tbody tr:nth-child(odd) td {
  background: rgba(255, 255, 255, 0.018);
}

#tableDiv table tbody tr:hover td {
  background: rgba(88, 166, 255, 0.05);
  color: var(--text-1);
}

/* ── Responsive ──────────────────────────────────────────────────── */
@media (max-width: 600px) {
  .card { padding: 1.25rem; }
  .results-grid { grid-template-columns: 1fr; }
  .lightbox-prev { left:  0.5rem; }
  .lightbox-next { right: 0.5rem; }
}
