/* Podcast Intel — Admin Dashboard */

:root {
  --bg: #f5f6fa;
  --surface: #fff;
  --text: #1a1a2e;
  --text-secondary: #64748b;
  --border: #e2e8f0;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --danger: #ef4444;
  --danger-hover: #dc2626;
  --success: #22c55e;
  --sidebar-bg: #1e293b;
  --sidebar-text: #cbd5e1;
  --sidebar-active: #3b82f6;
  --badge-title: #3b82f6;
  --badge-summary: #22c55e;
  --badge-description: #22c55e;
  --badge-author: #f97316;
  --badge-tag: #8b5cf6;
  --badge-llm: #a855f7;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.06);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

/* ---- Layout ---- */
.app {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 220px;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 100;
}

.sidebar-brand {
  padding: 20px 16px;
  font-size: 15px;
  font-weight: 700;
  color: #fff;
  border-bottom: 1px solid rgba(255,255,255,.08);
  letter-spacing: -.3px;
}

.sidebar-brand small {
  display: block;
  font-size: 11px;
  font-weight: 400;
  color: var(--sidebar-text);
  margin-top: 2px;
}

.sidebar nav {
  flex: 1;
  padding: 12px 0;
}

.sidebar nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  color: var(--sidebar-text);
  text-decoration: none;
  font-size: 14px;
  transition: background .15s, color .15s;
}

.sidebar nav a:hover { background: rgba(255,255,255,.06); color: #fff; }
.sidebar nav a.active { background: var(--sidebar-active); color: #fff; font-weight: 500; }

.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid rgba(255,255,255,.08);
  font-size: 12px;
}

.sidebar-footer button {
  background: none;
  border: none;
  color: var(--sidebar-text);
  cursor: pointer;
  font-size: 12px;
  padding: 4px 0;
}
.sidebar-footer button:hover { color: #fff; }

.main {
  flex: 1;
  margin-left: 220px;
  padding: 24px 32px;
  min-width: 0;
}

.hamburger {
  display: none;
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 200;
  background: var(--sidebar-bg);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 20px;
  cursor: pointer;
  line-height: 1;
}

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

.page-header h1 {
  font-size: 22px;
  font-weight: 600;
}

/* ---- Cards ---- */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 28px;
}

.stat-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}

.stat-card .label {
  font-size: 12px;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: .5px;
  margin-bottom: 6px;
}

.stat-card .value {
  font-size: 28px;
  font-weight: 700;
  color: var(--text);
}

.stat-card .sub {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 4px;
}

/* ---- Card panel ---- */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 20px;
}

/* ---- Tables ---- */
.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

th {
  text-align: left;
  padding: 10px 12px;
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: var(--text-secondary);
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
}

td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

tr:nth-child(even) td { background: #f8fafc; }
tr:hover td { background: #f1f5f9; }

td.actions {
  white-space: nowrap;
}

.truncate {
  max-width: 280px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---- Buttons ---- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border: none;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background .15s, opacity .15s;
  text-decoration: none;
  line-height: 1.4;
}

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: var(--danger-hover); }
.btn-ghost { background: transparent; color: var(--text-secondary); border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--bg); }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ---- Forms ---- */
.toolbar {
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
  flex-wrap: wrap;
  align-items: center;
}

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

input[type="text"]:focus,
input[type="password"]:focus,
select:focus {
  border-color: var(--primary);
}

.inline-form {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.inline-form label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
}

/* ---- Badges ---- */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .3px;
  color: #fff;
}

.badge-title { background: var(--badge-title); }
.badge-summary, .badge-description { background: var(--badge-summary); }
.badge-author { background: var(--badge-author); }
.badge-tag { background: var(--badge-tag); }
.badge-llm { background: var(--badge-llm); }
.badge-cohost { background: transparent; color: var(--text-secondary); border: 1px solid var(--border); font-weight: 500; font-size: 10px; }

/* ---- Cross-podcast toggle ---- */
.btn-toggle { background: transparent; color: var(--text-secondary); border: 1px solid var(--border); }
.btn-toggle.active { background: var(--primary); color: #fff; border-color: var(--primary); }

/* ---- Pagination ---- */
.pagination {
  display: flex;
  gap: 4px;
  align-items: center;
  justify-content: center;
  margin-top: 16px;
  flex-wrap: wrap;
}

.pagination button {
  padding: 6px 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
  transition: background .15s;
}

.pagination button:hover:not(:disabled) { background: var(--bg); }
.pagination button:disabled { opacity: .4; cursor: default; }
.pagination button.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.pagination .info { font-size: 13px; color: var(--text-secondary); padding: 0 8px; }

/* ---- Login overlay ---- */
.login-overlay {
  position: fixed;
  inset: 0;
  background: rgba(30,41,59,.85);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.login-box {
  background: var(--surface);
  border-radius: 12px;
  padding: 40px;
  width: 380px;
  max-width: 90vw;
  box-shadow: 0 20px 60px rgba(0,0,0,.3);
}

.login-box h2 {
  margin-bottom: 8px;
  font-size: 20px;
}

.login-box p {
  color: var(--text-secondary);
  font-size: 14px;
  margin-bottom: 20px;
}

.login-box input {
  width: 100%;
  margin-bottom: 16px;
}

.login-box .btn { width: 100%; justify-content: center; }

.login-error {
  color: var(--danger);
  font-size: 13px;
  margin-bottom: 12px;
}

/* ---- Modal ---- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 900;
}

.modal {
  background: var(--surface);
  border-radius: 12px;
  padding: 28px;
  width: 420px;
  max-width: 90vw;
  box-shadow: 0 20px 60px rgba(0,0,0,.2);
}

.modal h3 { margin-bottom: 12px; }

.modal p {
  color: var(--text-secondary);
  font-size: 14px;
  margin-bottom: 20px;
}

.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

/* ---- Toast ---- */
.toast-container {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  padding: 12px 20px;
  border-radius: 8px;
  font-size: 14px;
  color: #fff;
  box-shadow: 0 4px 12px rgba(0,0,0,.15);
  animation: toast-in .3s ease;
  max-width: 360px;
}

.toast-success { background: var(--success); }
.toast-error { background: var(--danger); }
.toast-info { background: var(--primary); }

@keyframes toast-in {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* ---- Token display ---- */
.token-display {
  display: flex;
  align-items: center;
  gap: 6px;
}

.token-text {
  font-family: "SF Mono", Monaco, Consolas, monospace;
  font-size: 13px;
  background: #f1f5f9;
  padding: 2px 8px;
  border-radius: 4px;
}

.token-toggle {
  background: none;
  border: none;
  color: var(--primary);
  cursor: pointer;
  font-size: 12px;
  padding: 2px 4px;
}

/* ---- Detection method bar ---- */
.detection-bar {
  display: flex;
  border-radius: 6px;
  overflow: hidden;
  height: 24px;
  margin-top: 8px;
}

.detection-bar .segment {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: 600;
  color: #fff;
  padding: 0 6px;
  white-space: nowrap;
  min-width: 0;
}

/* ---- Loading ---- */
.loading {
  text-align: center;
  padding: 40px;
  color: var(--text-secondary);
  font-size: 14px;
}

.empty {
  text-align: center;
  padding: 40px;
  color: var(--text-secondary);
}

/* ---- Status badges ---- */
.badge-success { background: var(--success); }
.badge-error { background: var(--danger); }

/* ---- Bulk action bar ---- */
.bulk-bar {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--sidebar-bg);
  color: #fff;
  padding: 12px 24px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  gap: 16px;
  box-shadow: 0 8px 32px rgba(0,0,0,.25);
  z-index: 500;
  font-size: 14px;
}

.bulk-bar .bulk-count {
  font-weight: 600;
}

.bulk-bar .btn { font-size: 13px; }

/* ---- Analytics charts ---- */
.chart-container {
  display: flex;
  align-items: flex-end;
  gap: 4px;
  height: 120px;
  padding-top: 8px;
}

.chart-bar {
  flex: 1;
  min-width: 8px;
  max-width: 24px;
  background: var(--primary);
  border-radius: 3px 3px 0 0;
  transition: height .3s;
  position: relative;
}

.chart-bar:hover {
  opacity: .8;
}

.chart-labels {
  display: flex;
  gap: 4px;
  margin-top: 4px;
}

.chart-label {
  flex: 1;
  min-width: 8px;
  max-width: 24px;
  font-size: 9px;
  color: var(--text-secondary);
  text-align: center;
  overflow: hidden;
}

/* ---- Health indicator ---- */
.health-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 4px;
}

.health-dot.healthy { background: var(--success); }
.health-dot.unhealthy { background: var(--danger); }
.health-dot.unknown { background: var(--text-secondary); }

/* ---- Checkbox in table ---- */
th input[type="checkbox"],
td input[type="checkbox"] {
  cursor: pointer;
  width: 16px;
  height: 16px;
}

/* ---- Autocomplete ---- */
.autocomplete-wrap {
  position: relative;
  display: inline-block;
}

.autocomplete-list {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: var(--shadow);
  max-height: 200px;
  overflow-y: auto;
  z-index: 10;
}

.autocomplete-list div {
  padding: 8px 12px;
  cursor: pointer;
  font-size: 14px;
}

.autocomplete-list div:hover {
  background: var(--bg);
}

/* ---- Health strip ---- */
.health-strip {
  padding: 12px 20px;
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  margin-bottom: 20px;
  border-left: 4px solid var(--success);
  font-size: 14px;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 8px;
}

.health-strip.warning {
  border-left-color: #f59e0b;
  background: #fffbeb;
}

.health-strip.error {
  border-left-color: var(--danger);
  background: #fef2f2;
}

/* ---- Stat card deltas ---- */
.stat-card .delta {
  font-size: 12px;
  margin-top: 4px;
  font-weight: 500;
}

.stat-card .delta.up {
  color: var(--success);
}

.stat-card .delta.down {
  color: var(--danger);
}

.stat-card .delta.neutral {
  color: var(--text-secondary);
}

/* ---- Dashboard grid (two-column) ---- */
.dashboard-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-bottom: 20px;
}

/* ---- Card header ---- */
.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.card-header .label {
  font-size: 12px;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: .5px;
}

.card-header a {
  font-size: 12px;
  color: var(--primary);
  text-decoration: none;
}

.card-header a:hover {
  text-decoration: underline;
}

/* ---- Episode feed items ---- */
.episode-feed-item {
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}

.episode-feed-item:last-child {
  border-bottom: none;
}

.ep-title {
  font-size: 14px;
  font-weight: 500;
  margin-bottom: 2px;
  line-height: 1.3;
}

.ep-meta {
  font-size: 12px;
  color: var(--text-secondary);
}

.ep-meta .ep-guests {
  color: var(--text);
  font-weight: 500;
}

.ep-meta .ep-no-guests {
  color: var(--text-secondary);
  font-style: italic;
}

/* ---- User activity items ---- */
.user-activity-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}

.user-activity-item:last-child {
  border-bottom: none;
}

.user-activity-item .user-name {
  font-weight: 500;
}

.user-activity-item .user-subs {
  color: var(--text-secondary);
  font-size: 12px;
}

/* ---- Cadence labels ---- */
.cadence-label {
  font-weight: 500;
  font-size: 13px;
}

.cadence-since {
  font-size: 11px;
  color: var(--text-secondary);
}

/* ---- Sortable table headers ---- */
th.sortable {
  cursor: pointer;
  user-select: none;
  transition: color .15s;
}

th.sortable:hover {
  color: var(--text);
}

th.sortable .sort-arrow {
  font-size: 10px;
  margin-left: 4px;
  opacity: .3;
}

th.sorted {
  color: var(--text);
}

th.sorted .sort-arrow {
  opacity: 1;
}

/* ---- Episode links ---- */
a.episode-link {
  color: var(--text);
  text-decoration: none;
  font-weight: 500;
}

a.episode-link:hover {
  color: var(--primary);
  text-decoration: underline;
}

/* ---- Guest tags ---- */
.guest-tag {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 12px;
  font-weight: 500;
  background: #f1f5f9;
  color: var(--text);
  margin: 1px 2px;
  white-space: nowrap;
}

.no-guests {
  color: var(--text-secondary);
  font-style: italic;
  font-size: 13px;
}

/* ---- Podcast thumbnails ---- */
.podcast-thumb { width: 24px; height: 24px; border-radius: 4px; margin-right: 8px; vertical-align: middle; object-fit: cover; }
.podcast-title-link { color: var(--text); text-decoration: none; }
.podcast-title-link:hover { color: var(--primary); text-decoration: underline; }

/* ---- Episode summary ---- */
.ep-summary { font-size: 12px; color: var(--text-secondary); margin-top: 2px; max-width: 400px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---- Guest detail page ---- */
.guest-detail-header {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 24px;
}

.guest-detail-header .back-link {
  font-size: 13px;
  color: var(--text-secondary);
  text-decoration: none;
}

.guest-detail-header .back-link:hover {
  color: var(--primary);
}

.guest-link {
  color: var(--text);
  text-decoration: none;
}

.guest-link:hover {
  color: var(--primary);
  text-decoration: underline;
}

/* ---- Job type badges ---- */
.badge-job-type { background: #475569; }
.badge-warning { background: #f59e0b; }
.badge-info { background: var(--primary); }

/* ---- Job detail panel ---- */
.job-detail {
  border-top: 1px solid var(--border);
  padding-top: 12px;
  margin-top: 12px;
}

.job-error-row td {
  border-bottom: none !important;
  padding-top: 0 !important;
}

/* ---- Card header ---- */
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.card-header .label {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}

.card-header a {
  font-size: 13px;
  color: var(--primary);
  text-decoration: none;
}

.card-header a:hover {
  text-decoration: underline;
}

/* ---- Responsive ---- */
@media (max-width: 768px) {
  .hamburger { display: block; }

  .sidebar {
    transform: translateX(-100%);
    transition: transform .25s ease;
  }

  .sidebar.open { transform: translateX(0); }

  .main {
    margin-left: 0;
    padding: 60px 16px 24px;
  }

  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .dashboard-grid {
    grid-template-columns: 1fr;
  }

  .page-header { flex-direction: column; align-items: flex-start; }
}
