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

:root {
  --bg: #fafafa;
  --surface: #ffffff;
  --border: #e5e7eb;
  --border-light: #f0f0f0;
  --text: #111827;
  --text-secondary: #6b7280;
  --text-muted: #9ca3af;
  --accent: #111827;
  --accent-hover: #374151;
  --green: #059669;
  --green-bg: #ecfdf5;
  --green-text: #065f46;
  --yellow-bg: #fffbeb;
  --yellow-text: #92400e;
  --red-bg: #fef2f2;
  --red-text: #991b1b;
  --idle-bg: #f3f4f6;
  --idle-text: #9ca3af;
  --radius: 6px;
  --radius-lg: 10px;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.04);
  --shadow: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --transition: 150ms ease;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Inter', 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ── Layout ── */
.container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 2rem 2.5rem;
}

/* ── Header ── */
.header {
  display: flex;
  align-items: baseline;
  gap: 1rem;
  margin-bottom: 0.5rem;
}
.header h1 {
  font-size: 1.5rem;
  font-weight: 600;
  letter-spacing: -0.025em;
  color: var(--text);
}
.header .version {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 400;
}
.header-spacer { flex: 1; }
.user-bar {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-size: 0.8rem;
  color: var(--text-secondary);
}
.user-bar img {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 1px solid var(--border);
}
.user-bar .user-name { font-weight: 500; color: var(--text); }
.user-bar a {
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.75rem;
}
.user-bar a:hover { color: var(--text); }

#qdrant-status {
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-bottom: 1.75rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
#qdrant-status .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
}
.dot-ok { background: var(--green); }
.dot-err { background: var(--red-text); }
.dot-loading { background: var(--text-muted); animation: pulse 1.2s ease-in-out infinite; }

@keyframes pulse {
  0%, 100% { opacity: 0.4; }
  50% { opacity: 1; }
}

/* ── Table ── */
.table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}

thead th {
  text-align: left;
  padding: 0.65rem 0.75rem;
  font-size: 0.7rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  background: var(--surface);
  position: sticky;
  top: 0;
  z-index: 2;
}

tbody td {
  padding: 0.6rem 0.75rem;
  border-bottom: 1px solid var(--border-light);
  vertical-align: top;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #f9fafb; }

.audience-name {
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
}
.audience-count {
  font-variant-numeric: tabular-nums;
  color: var(--text-secondary);
}

/* ── Tags ── */
.tag {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.15rem 0.55rem;
  border-radius: 9999px;
  font-size: 0.7rem;
  font-weight: 500;
  white-space: nowrap;
  transition: background var(--transition);
}
.t-idle { background: var(--idle-bg); color: var(--idle-text); }
.t-work { background: var(--yellow-bg); color: var(--yellow-text); }
.t-done { background: var(--green-bg); color: var(--green-text); }
.t-err  { background: var(--red-bg); color: var(--red-text); }

/* ── Spinner ── */
.spinner {
  display: inline-block;
  width: 12px;
  height: 12px;
  border: 2px solid var(--border);
  border-top-color: var(--yellow-text);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  vertical-align: middle;
  flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Buttons ── */
button, .btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.35rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font-size: 0.75rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
}
button:hover { background: #f3f4f6; border-color: #d1d5db; }
button:active { transform: scale(0.97); }
button:disabled { opacity: 0.4; cursor: not-allowed; }

.btn-primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }

.btn-green {
  background: var(--green);
  color: #fff;
  border-color: var(--green);
  text-decoration: none;
}
.btn-green:hover { background: #047857; border-color: #047857; }

.btn-sm {
  padding: 0.2rem 0.55rem;
  font-size: 0.7rem;
}

/* ── Inputs ── */
input[type=number] {
  width: 90px;
  padding: 0.3rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.8rem;
  font-family: inherit;
  color: var(--text);
  background: var(--surface);
  transition: border-color var(--transition);
}
input[type=number]:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(17,24,39,0.08);
}

select[multiple] {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2px;
  font-size: 0.72rem;
  background: var(--surface);
  color: var(--text);
}

select[multiple]:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(17,24,39,0.08);
}

select[multiple] option {
  padding: 1px 4px;
}

select[multiple] option:checked {
  background: var(--accent);
  color: #fff;
}

/* ── Stage cell layout ── */
.stage-cell {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  min-width: 110px;
}
.stage-cell .tag + button,
.stage-cell .tag + .btn-sm { margin-top: 0.15rem; }

/* ── Plot thumbnail ── */
.plot-thumb {
  margin-top: 0.35rem;
}
.plot-thumb img {
  max-width: 220px;
  border-radius: var(--radius);
  cursor: pointer;
  border: 1px solid var(--border);
  transition: box-shadow var(--transition), transform var(--transition);
}
.plot-thumb img:hover {
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
  transform: scale(1.02);
}

/* ── Modal ── */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.8);
  backdrop-filter: blur(4px);
  z-index: 100;
  justify-content: center;
  align-items: center;
  cursor: pointer;
}
.modal-overlay.open { display: flex; }
.modal-overlay img {
  max-width: 94vw;
  max-height: 94vh;
  border-radius: var(--radius-lg);
  box-shadow: 0 25px 50px rgba(0,0,0,0.3);
}

/* ── Empty state ── */
.empty-state {
  padding: 3rem 2rem;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.9rem;
}

/* ── Responsive ── */
@media (max-width: 1024px) {
  .container { padding: 1rem; }
  input[type=number] { width: 75px; }
  .plot-thumb img { max-width: 160px; }
}

@media (max-width: 640px) {
  .container { padding: 0.75rem; }
  .header h1 { font-size: 1.2rem; }
  table { font-size: 0.75rem; }
  thead th { font-size: 0.65rem; padding: 0.5rem; }
  tbody td { padding: 0.4rem 0.5rem; }
}
