/* Assay Workflow Dashboard - Styles */

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

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

/* ── Layout ─────────────────────────────────────────── */

.layout {
  display: flex;
  height: calc(100vh - 32px);
}

.sidebar {
  width: 220px;
  min-width: 220px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  transition: width 0.2s ease, min-width 0.2s ease;
}

/* Collapsed (icon-only) sidebar — desktop fold mode */
.sidebar.collapsed {
  width: 56px;
  min-width: 56px;
}
.sidebar.collapsed .sidebar-section,
.sidebar.collapsed .nav-label,
.sidebar.collapsed .logo-full {
  display: none;
}
.sidebar.collapsed .logo-mark {
  display: inline;
}
.sidebar.collapsed .nav-link {
  justify-content: center;
  padding: 10px 0;
}
.sidebar.collapsed .sidebar-header {
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 12px 0;
}
/* Toggle icon swaps between < and > based on collapsed state */
.icon-expand   { display: none; }
.sidebar.collapsed .icon-collapse { display: none; }
.sidebar.collapsed .icon-expand   { display: inline; }
/* Theme icons swap based on data-theme on <html> */
.icon-moon { display: none; }
[data-theme="light"] .icon-sun  { display: none; }
[data-theme="light"] .icon-moon { display: inline; }

.main-content {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  background: var(--bg);
}

/* ── Sidebar ────────────────────────────────────────── */

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px;
  border-bottom: 1px solid var(--border);
}

.logo {
  font-size: 18px;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: -0.5px;
}

/* The single-letter mark shown when the sidebar is collapsed */
.logo-mark {
  display: none;
  font-size: 20px;
  font-weight: 700;
  color: var(--accent);
}

/* Small icon button used in the sidebar header (e.g. collapse toggle) */
.header-icon-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text-muted);
  cursor: pointer;
  padding: 1px 4px;
  font-size: 12px;
  line-height: 1;
  font-family: inherit;
  flex: 0 0 auto;
}

.header-icon-btn:hover {
  color: var(--text);
  border-color: var(--text-muted);
}

/* Button styled as a nav-link (for the Theme toggle in the footer) */
.nav-link-button {
  width: 100%;
  background: none;
  border: none;
  font-family: inherit;
  text-align: left;
  cursor: pointer;
}

/* Icon-only nav-link variant — centers the single icon in the row */
.nav-link-icon {
  justify-content: center;
}

.sidebar-section {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}

.sidebar-label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.namespace-select {
  width: 100%;
  padding: 6px 8px;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
}

.namespace-select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 22%, transparent);
}

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

.nav-link {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 13px;
  font-weight: 500;
  border-left: 3px solid transparent;
}

.nav-link:hover {
  color: var(--text);
  background: var(--surface-hover);
}

.nav-link.active {
  color: var(--text);
  background: var(--surface-hover);
  border-left-color: var(--accent);
}

.nav-icon {
  font-size: 14px;
  width: 18px;
  text-align: center;
}

.sidebar-footer {
  border-top: 1px solid var(--border);
  padding: 8px 0;
  display: flex;
  align-items: stretch;
}

/* API Docs nav-link grows to fill the footer; theme toggle stays compact */
.nav-link-grow { flex: 1; }
.sidebar-footer .nav-link-icon { flex: 0 0 44px; }

/* When collapsed, stack the footer vertically (API Docs + theme icon) */
.sidebar.collapsed .sidebar-footer { flex-direction: column; }
.sidebar.collapsed .sidebar-footer .nav-link-icon { flex: 0 0 auto; }

/* ── Status Bar ─────────────────────────────────────── */

.status-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 32px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 24px;
  font-size: 12px;
  color: var(--text-muted);
  z-index: 100;
}

.status-item {
  display: flex;
  align-items: center;
  gap: 6px;
}

.status-version {
  margin-left: auto;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--yellow);
}

.status-dot.connected { background: var(--green); }
.status-dot.disconnected { background: var(--red); }

/* ── Data Tables ────────────────────────────────────── */

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.data-table th {
  text-align: left;
  padding: 8px 12px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.3px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  position: sticky;
  top: 0;
}

.data-table td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.data-table tr:hover td {
  background: var(--surface-hover);
}

.data-table .clickable {
  color: var(--accent);
  cursor: pointer;
  text-decoration: none;
}

.data-table .clickable:hover {
  text-decoration: underline;
}

.data-table .mono {
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  font-size: 12px;
}

/* ── Status Badges ──────────────────────────────────── */

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.badge-pending   { background: rgba(139,148,158,0.15); color: var(--text-muted); }
.badge-running   { background: color-mix(in srgb, var(--accent) 15%, transparent); color: var(--accent); }
.badge-completed { background: rgba(63,185,80,0.15); color: var(--green); }
.badge-failed    { background: rgba(248,81,73,0.15); color: var(--red); }
.badge-waiting   { background: rgba(210,153,34,0.15); color: var(--yellow); }
.badge-cancelled { background: rgba(219,109,40,0.15); color: var(--orange); }

/* ── Worker Status Dots ─────────────────────────────── */

.worker-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

.worker-dot.healthy  { background: var(--green); }
.worker-dot.warning  { background: var(--yellow); }
.worker-dot.stale    { background: var(--red); }

/* ── Detail Panel ───────────────────────────────────── */

.detail-panel {
  position: fixed;
  top: 0;
  right: -620px;
  width: 600px;
  height: calc(100vh - 32px);
  background: var(--surface);
  border-left: 1px solid var(--border);
  box-shadow: -4px 0 24px var(--shadow);
  overflow-y: auto;
  z-index: 50;
  transition: right 0.25s ease;
}

.detail-panel.open {
  right: 0;
}

.detail-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--surface);
  z-index: 1;
}

.detail-header h2 {
  font-size: 16px;
  font-weight: 600;
}

.detail-body {
  padding: 20px;
}

.detail-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 20px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
}

.detail-close:hover {
  color: var(--text);
  background: var(--surface-hover);
}

/* ── Metadata Grid ──────────────────────────────────── */

.meta-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 20px;
}

.meta-item label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 2px;
}

.meta-item span {
  font-size: 13px;
}

/* ── JSON Viewer ────────────────────────────────────── */

.json-viewer {
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 12px;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  font-size: 12px;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 300px;
  overflow-y: auto;
  margin-bottom: 16px;
}

.collapsible-header {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  font-weight: 600;
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 8px;
  user-select: none;
}

.collapsible-header:hover {
  color: var(--text);
}

.collapsible-content {
  display: none;
}

.collapsible-content.open {
  display: block;
}

/* ── Buttons ────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  background: var(--surface);
  color: var(--text);
  text-decoration: none;
}

.btn:hover {
  background: var(--surface-hover);
  border-color: var(--text-muted);
}

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

.btn-primary:hover {
  background: var(--accent-hover);
}

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

.btn-danger:hover {
  background: rgba(248, 81, 73, 0.1);
}

.btn-sm {
  padding: 3px 10px;
  font-size: 11px;
}

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

/* ── Forms ──────────────────────────────────────────── */

.form-group {
  margin-bottom: 12px;
}

.form-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.form-input, .form-select, .form-textarea {
  width: 100%;
  padding: 6px 10px;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  font-family: inherit;
}

.form-textarea {
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  font-size: 12px;
  resize: vertical;
  min-height: 60px;
}

.form-input:focus, .form-select:focus, .form-textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 22%, transparent);
}

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

.form-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 16px;
}

/* ── Cards / Sections ───────────────────────────────── */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 16px;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  font-size: 14px;
}

.card-body {
  padding: 16px;
}

.section-title {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 16px;
}

/* ── Pagination ─────────────────────────────────────── */

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

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

/* ── Search / Filters ───────────────────────────────── */

.toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.search-input {
  padding: 6px 10px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  min-width: 240px;
}

.search-input:focus {
  outline: none;
  border-color: var(--accent);
}

.filter-select {
  padding: 6px 10px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
}

/* ── Event Timeline ─────────────────────────────────── */

.event-timeline {
  border-left: 2px solid var(--border);
  margin-left: 8px;
  padding-left: 16px;
}

.event-item {
  position: relative;
  margin-bottom: 12px;
  cursor: pointer;
}

.event-item::before {
  content: "";
  position: absolute;
  left: -21px;
  top: 6px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--border);
  border: 2px solid var(--surface);
}

.event-item .event-header {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
}

.event-item .event-type {
  font-weight: 600;
  color: var(--accent);
}

.event-item .event-time {
  font-size: 12px;
  color: var(--text-muted);
}

.event-payload {
  display: none;
  margin-top: 6px;
}

.event-payload.open {
  display: block;
}

/* ── Error display ──────────────────────────────────── */

.error-box {
  background: rgba(248, 81, 73, 0.1);
  border: 1px solid var(--red);
  border-radius: 6px;
  padding: 12px;
  color: var(--red);
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 12px;
  margin-bottom: 16px;
  white-space: pre-wrap;
}

/* ── Warning icon ───────────────────────────────────── */

.warning-icon {
  color: var(--yellow);
  font-weight: bold;
}

/* ── Empty state ────────────────────────────────────── */

.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-muted);
}

.empty-state p {
  font-size: 14px;
}

/* ── Mobile Sidebar ─────────────────────────────────── */

.sidebar-toggle {
  display: none;
  position: fixed;
  top: 8px;
  left: 8px;
  z-index: 200;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 18px;
  cursor: pointer;
}

@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    top: 0;
    left: -220px;
    height: calc(100vh - 32px);
    z-index: 150;
    transition: left 0.25s ease;
  }

  .sidebar.open {
    left: 0;
  }

  .sidebar-toggle {
    display: block;
  }

  .main-content {
    padding: 16px;
    padding-top: 48px;
  }

  .detail-panel {
    width: 100%;
    right: -100%;
  }

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

/* ── Toast notifications (tier-1 dashboard) ─────────────────────────
   Transient feedback for mutation results. Bottom-right stack, one
   toast per action. Colour-coded by kind (success / error / info). */

.toast-container {
  position: fixed;
  bottom: 40px;
  right: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 300;
  pointer-events: none;
}

.toast {
  background: var(--surface-2);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-left-width: 4px;
  padding: 10px 14px;
  border-radius: 6px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  min-width: 200px;
  max-width: 420px;
  opacity: 0;
  transform: translateX(12px);
  transition: opacity 0.2s ease, transform 0.2s ease;
  font-size: 13px;
  pointer-events: auto;
}

.toast-show {
  opacity: 1;
  transform: translateX(0);
}

.toast-success {
  border-left-color: var(--accent);
}

.toast-error {
  border-left-color: #d04040;
}

.toast-info {
  border-left-color: var(--text-muted, #888);
}

/* ── Action buttons + inline forms (tier-1 dashboard) ───────────────
   Reused across workflow detail, schedule rows, settings namespace
   list. Minimal: outline by default, solid on primary action. */

.action-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin: 12px 0;
}

.btn-action {
  background: transparent;
  color: var(--text-primary);
  border: 1px solid var(--border);
  padding: 6px 12px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 13px;
  font-family: inherit;
}

.btn-action:hover {
  background: var(--surface-2);
}

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

.btn-action-primary:hover {
  filter: brightness(1.1);
}

.btn-action-danger {
  color: #d04040;
  border-color: #d04040;
}

.btn-action-danger:hover {
  background: rgba(208, 64, 64, 0.08);
}

.inline-form {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 12px;
  margin: 12px 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.inline-form label {
  font-size: 12px;
  color: var(--text-muted, #888);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.inline-form input[type="text"],
.inline-form textarea,
.inline-form select {
  background: var(--surface-1);
  color: var(--text-primary);
  border: 1px solid var(--border);
  padding: 6px 8px;
  border-radius: 4px;
  font-family: var(--font-mono, ui-monospace, monospace);
  font-size: 13px;
}

.inline-form textarea {
  min-height: 80px;
  resize: vertical;
}

.inline-form .form-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 4px;
}
