:root {
  --bg: #111318;
  --surface: #1a1d24;
  --surface2: #22262f;
  --border: #2e3340;
  --accent: #6c8fff;
  --accent-hover: #8aa4ff;
  --text: #e2e4eb;
  --text-muted: #7b8096;
  --success: #4caf7d;
  --warning: #f0b429;
  --error: #e05c5c;
  --radius: 8px;
}

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 14px;
  line-height: 1.5;
  min-height: 100vh;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }

/* Layout */
#app { display: flex; flex-direction: column; min-height: 100vh; }

header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  display: flex;
  align-items: center;
  gap: 16px;
  height: 52px;
  position: sticky;
  top: 0;
  z-index: 10;
}

.logo { font-size: 18px; font-weight: 700; color: var(--accent); flex-shrink: 0; }

nav { display: flex; gap: 4px; flex: 1; }

.tab-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 6px 14px;
  border-radius: var(--radius);
  font-size: 14px;
  transition: background 0.15s, color 0.15s;
}
.tab-btn:hover { background: var(--surface2); color: var(--text); }
.tab-btn.active { background: var(--surface2); color: var(--accent); }

.user-badge {
  font-size: 12px;
  color: var(--text-muted);
  flex-shrink: 0;
}
.user-badge strong { color: var(--text); }

.logout-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px 10px;
  border-radius: var(--radius);
  font-size: 12px;
  transition: border-color 0.15s, color 0.15s;
}
.logout-btn:hover { border-color: var(--error); color: var(--error); }

main { flex: 1; padding: 24px; max-width: 1200px; width: 100%; margin: 0 auto; }

/* Tab panels */
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* Search */
.search-bar {
  display: flex;
  gap: 8px;
  margin-bottom: 20px;
}

input[type="text"], select {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius);
  padding: 8px 12px;
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s;
}
input[type="text"]:focus, select:focus { border-color: var(--accent); }
input[type="text"] { flex: 1; }

button {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  padding: 8px 16px;
  font-size: 14px;
  cursor: pointer;
  transition: background 0.15s;
  white-space: nowrap;
}
button:hover { background: var(--accent-hover); }
button:disabled { opacity: 0.5; cursor: not-allowed; }

button.danger {
  background: transparent;
  border: 1px solid var(--error);
  color: var(--error);
}
button.danger:hover { background: var(--error); color: #fff; }

button.secondary {
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
}
button.secondary:hover { background: var(--border); }

/* Results grid */
.results-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 16px;
}

.result-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  transition: border-color 0.15s;
}
.result-card:hover { border-color: var(--accent); }

.result-poster {
  width: 100%;
  aspect-ratio: 2/3;
  object-fit: cover;
  background: var(--surface2);
  display: block;
}
.result-poster-placeholder {
  width: 100%;
  aspect-ratio: 2/3;
  background: var(--surface2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 36px;
  color: var(--text-muted);
}

.result-info { padding: 10px; }
.result-title { font-size: 13px; font-weight: 600; margin-bottom: 4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.result-meta { font-size: 11px; color: var(--text-muted); margin-bottom: 8px; }
.result-type-badge {
  display: inline-block;
  background: var(--surface2);
  border-radius: 4px;
  padding: 1px 6px;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-right: 4px;
}

/* Episode picker */
.episode-picker {
  background: var(--surface);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  padding: 12px;
  margin-top: 8px;
}
.episode-picker label { display: block; margin-bottom: 4px; font-size: 12px; color: var(--text-muted); }
.episode-picker select { width: 100%; margin-bottom: 8px; }
.episode-picker .picker-actions { display: flex; gap: 6px; }

/* Queue table */
.queue-section { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
th {
  background: var(--surface);
  color: var(--text-muted);
  font-weight: 600;
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
tr:hover td { background: var(--surface); }
tr:last-child td { border-bottom: none; }

.status-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.status-pending    { background: rgba(240,180,41,0.15); color: var(--warning); }
.status-downloading { background: rgba(108,143,255,0.15); color: var(--accent); }
.status-done       { background: rgba(76,175,125,0.15); color: var(--success); }
.status-error      { background: rgba(224,92,92,0.15); color: var(--error); }

.error-msg { font-size: 11px; color: var(--error); margin-top: 2px; }

/* Progress bar */
.progress-bar {
  height: 4px;
  background: var(--surface2);
  border-radius: 2px;
  margin-top: 6px;
  overflow: hidden;
}
.progress-bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  transition: width 0.4s ease;
}

/* Messages */
.message { padding: 12px 16px; border-radius: var(--radius); margin-bottom: 16px; }
.message.info    { background: rgba(108,143,255,0.12); border: 1px solid rgba(108,143,255,0.3); }
.message.error   { background: rgba(224,92,92,0.12);  border: 1px solid rgba(224,92,92,0.3); }
.message.success { background: rgba(76,175,125,0.12); border: 1px solid rgba(76,175,125,0.3); }

/* Loading spinner */
.spinner {
  display: inline-block;
  width: 16px; height: 16px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  vertical-align: middle;
}
@keyframes spin { to { transform: rotate(360deg); } }

.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-muted);
}
.empty-state .icon { font-size: 40px; margin-bottom: 12px; }

/* Queue header bar */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.section-header h2 { font-size: 16px; }

/* Dest path — truncated, styled via class so mobile can override */
.dest-path {
  font-size: 11px;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 300px;
}

/* Queue actions cell */
.col-actions { white-space: nowrap; display: flex; gap: 4px; }

/* ── Responsive ─────────────────────────────────────── */
@media (max-width: 640px) {
  /* Layout */
  main { padding: 12px; }
  header { padding: 0 12px; gap: 8px; }
  .user-badge { display: none; }

  /* Touch-friendly primary buttons */
  button { min-height: 40px; padding: 8px 16px; }

  /* Search bar: input + Search on row 1, selects on row 2 */
  .search-bar {
    display: grid;
    grid-template-columns: 1fr auto;
    grid-template-rows: auto auto;
    gap: 8px;
  }
  .search-bar input[type="text"] { grid-column: 1; grid-row: 1; }
  .search-bar #search-btn        { grid-column: 2; grid-row: 1; }
  .search-bar #search-type       { grid-column: 1; grid-row: 2; }
  .search-bar #search-provider   { grid-column: 2; grid-row: 2; }

  /* Results grid: 2 columns minimum */
  .results-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }

  /* Queue table → card list */
  .queue-section { overflow-x: unset; }
  table, tbody { display: block; }
  thead { display: none; }
  tr {
    display: block;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 10px 12px;
    margin-bottom: 8px;
  }
  tr:last-child td { border-bottom: none; }
  tr:hover td { background: transparent; }
  td {
    display: block;
    padding: 2px 0;
    border: none !important;
  }

  /* Type badge and S/E sit inline on one line */
  .col-type { display: inline-block; padding-right: 6px; }
  .col-se   { display: inline-block; color: var(--text-muted); font-size: 12px; }

  .col-status { margin-top: 4px; }

  /* Dest path: full width on mobile */
  .dest-path { max-width: 100%; }

  /* Requested-by: de-emphasised */
  .col-reqby { font-size: 11px; color: var(--text-muted); }

  /* Actions: right-aligned row at the bottom of the card */
  .col-actions {
    margin-top: 8px;
    justify-content: flex-end;
  }
}
