:root {
  --bg: #07111d;
  --surface: #101b2b;
  --surface-soft: #17263a;
  --surface-strong: #20324a;
  --ink: #f4f7fb;
  --muted: #a8b3c4;
  --accent: #35d7a7;
  --accent-strong: #7cf7ce;
  --accent-soft: #123c35;
  --warning: #fbbf24;
  --warning-soft: #3a2d12;
  --danger: #ff6b6b;
  --danger-strong: #ff3b3b;
  --danger-soft: #3a171c;
  --border: #2c3d53;
  --shadow: 0 18px 42px rgba(0, 0, 0, 0.28);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-width: 320px;
  font-family: "Segoe UI", "Aptos", Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
}

a {
  color: inherit;
  text-decoration: none;
}

button,
input,
textarea {
  font: inherit;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 18px;
  min-height: 68px;
  padding: 12px max(20px, calc((100vw - 1180px) / 2));
  border-bottom: 1px solid var(--border);
  background: rgba(7, 17, 29, 0.94);
  backdrop-filter: blur(12px);
}

.brand-mark {
  display: inline-flex;
  align-items: center;
  min-height: 40px;
  color: var(--accent-strong);
  font-size: 1.12rem;
  font-weight: 900;
  letter-spacing: 0.02em;
}

.main-menu {
  display: flex;
  align-items: center;
  gap: 6px;
}

.menu-link,
.icon-button,
.primary-button,
.secondary-button,
.ghost-button,
.danger-button,
.pause-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  border: 0;
  border-radius: var(--radius);
  padding: 10px 14px;
  font-weight: 800;
  line-height: 1;
  cursor: pointer;
}

.menu-link {
  color: var(--muted);
}

.menu-link.active,
.menu-link:hover {
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.topbar-actions,
.form-actions,
.job-actions,
.detection-actions,
.row-heading {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.topbar-actions {
  justify-content: flex-end;
}

.health-pill,
.session-pill,
.status-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 30px;
  border-radius: var(--radius);
  padding: 7px 10px;
  font-size: 0.82rem;
  font-weight: 800;
  white-space: nowrap;
}

.health-pill.ok,
.status-chip.ok,
.status-chip.running,
.status-chip.completed,
.status-chip.queued {
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.health-pill.warn,
.status-chip.warn,
.status-chip.reconnecting,
.status-chip.paused,
.status-chip.pause-requested,
.status-chip.cancel-requested {
  background: var(--warning-soft);
  color: var(--warning);
}

.health-pill.error,
.status-chip.error,
.status-chip.stale,
.status-chip.failed {
  background: var(--danger-soft);
  color: var(--danger);
}

.health-pill.neutral,
.status-chip.neutral,
.status-chip.finished,
.session-pill {
  background: var(--surface-soft);
  color: var(--muted);
}

.logout-form {
  margin: 0;
}

.icon-button {
  min-height: 34px;
  padding: 8px 11px;
  background: var(--surface-soft);
  color: var(--ink);
}

.primary-button {
  background: var(--accent);
  color: #06130f;
}

.secondary-button {
  border: 1px solid var(--border);
  background: var(--surface-strong);
  color: var(--accent-strong);
}

.ghost-button {
  background: var(--ink);
  color: var(--bg);
}

.danger-button {
  background: var(--danger-soft);
  color: var(--danger);
}

.pause-button {
  border: 1px solid rgba(255, 107, 107, 0.45);
  background: var(--danger-strong);
  color: #ffffff;
  box-shadow: 0 0 0 3px rgba(255, 59, 59, 0.12);
  min-width: 170px;
}

.full-button {
  width: 100%;
}

.primary-button:hover,
.secondary-button:hover,
.ghost-button:hover,
.danger-button:hover,
.pause-button:hover,
.icon-button:hover {
  filter: brightness(1.08);
}

.page-shell {
  width: min(1180px, calc(100% - 32px));
  margin: 28px auto 56px;
}

.narrow-shell {
  max-width: 760px;
}

.page-intro,
.panel,
.campaign-card,
.empty-panel,
.flash,
.summary-item {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.page-intro {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
  padding: 24px;
}

.page-intro h1 {
  margin: 0;
  font-size: clamp(2rem, 4vw, 3rem);
  line-height: 1.05;
}

.page-intro p,
.panel-heading p,
.campaign-card-header p,
.campaign-notes,
.muted-text,
.error-text {
  margin: 8px 0 0;
  line-height: 1.45;
}

.page-intro p,
.panel-heading p,
.campaign-card-header p,
.campaign-notes,
.muted-text {
  color: var(--muted);
}

.error-text {
  color: var(--danger);
  font-size: 0.9rem;
}

.detail-intro {
  align-items: flex-start;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--accent-strong);
  font-size: 0.76rem;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
}

.flash {
  margin-top: 16px;
  padding: 14px 16px;
}

.flash.success {
  border-left: 5px solid var(--accent);
}

.flash.error {
  border-left: 5px solid var(--danger);
}

.flash-id {
  color: var(--muted);
  margin-left: 8px;
}

.campaign-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 16px;
  margin-top: 20px;
}

.campaign-card {
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 20px;
}

.campaign-card-header,
.job-topline,
.detection-topline,
.table-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
}

.campaign-card h2,
.panel h2,
.empty-panel h2,
.empty-panel h3,
.job-card h3,
.detection-card h3 {
  margin: 0;
  line-height: 1.15;
}

.campaign-card h2 {
  font-size: 1.35rem;
}

.campaign-stats,
.summary-grid,
.job-stats {
  display: grid;
  gap: 10px;
}

.campaign-stats {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin: 0;
}

.campaign-stats div,
.job-stats div {
  min-width: 0;
  border-radius: var(--radius);
  background: var(--surface-soft);
  padding: 11px;
}

.campaign-stats dt,
.job-stats dt,
.summary-item span {
  color: var(--muted);
  font-size: 0.82rem;
}

.campaign-stats dd,
.job-stats dd,
.summary-item strong {
  display: block;
  margin: 5px 0 0;
  font-size: 1.05rem;
  font-weight: 900;
}

.empty-panel {
  margin-top: 20px;
  padding: 28px;
}

.empty-panel p {
  color: var(--muted);
  line-height: 1.45;
}

.compact-empty {
  margin-top: 14px;
  padding: 18px;
}

.notice-box {
  border: 1px solid rgba(251, 191, 36, 0.45);
  border-radius: var(--radius);
  background: var(--warning-soft);
  color: var(--warning);
  padding: 16px;
}

.notice-box h3 {
  margin: 0;
}

.notice-box p {
  margin: 8px 0 0;
  line-height: 1.45;
}

.job-alert {
  margin-top: 12px;
  border-radius: var(--radius);
  padding: 12px;
  line-height: 1.45;
}

.job-alert.warn {
  border: 1px solid rgba(251, 191, 36, 0.45);
  background: var(--warning-soft);
  color: var(--warning);
}

.job-alert.error {
  border: 1px solid rgba(255, 107, 107, 0.45);
  background: var(--danger-soft);
  color: var(--danger);
}

.section-menu {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 14px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.section-menu a {
  min-height: 34px;
  border-radius: var(--radius);
  padding: 8px 12px;
  color: var(--muted);
  font-weight: 800;
}

.section-menu a:hover {
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.summary-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin-top: 20px;
}

.summary-item {
  padding: 16px;
}

.summary-item strong {
  font-size: 1.45rem;
}

.detail-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 20px;
  margin-top: 20px;
}

.section-gap {
  margin-top: 20px;
}

.panel {
  padding: 20px;
}

.panel-heading {
  margin-bottom: 18px;
}

.row-heading {
  justify-content: space-between;
  align-items: flex-start;
}

.secondary-link {
  color: var(--accent-strong);
  font-weight: 900;
}

.secondary-link:hover {
  text-decoration: underline;
}

.stacked-form,
.table-list,
.jobs-list,
.detections-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

fieldset {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  background: var(--surface-soft);
}

legend {
  padding: 0 6px;
  font-weight: 900;
}

label {
  display: flex;
  flex-direction: column;
  gap: 7px;
  margin-bottom: 12px;
  font-weight: 800;
}

label:last-child {
  margin-bottom: 0;
}

input,
textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 11px 12px;
  background: #0b1624;
  color: var(--ink);
}

input[type="file"] {
  min-height: 44px;
}

input::placeholder,
textarea::placeholder {
  color: #7f8fa3;
}

input[type="file"]::file-selector-button {
  margin-right: 10px;
  border: 0;
  border-radius: var(--radius);
  padding: 8px 10px;
  background: var(--surface-strong);
  color: var(--ink);
  font-weight: 800;
}

input:focus,
textarea:focus {
  border-color: var(--accent);
  outline: 3px solid rgba(53, 215, 167, 0.18);
}

.field-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.check-row {
  flex-direction: row;
  align-items: center;
  gap: 9px;
  margin-top: 8px;
}

.check-row input {
  width: auto;
}

.table-list {
  margin-top: 18px;
}

.inline-form {
  margin: 0;
}

.table-row,
.job-card,
.detection-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #0d1827;
  padding: 14px;
}

.row-metric {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  color: var(--muted);
  font-weight: 800;
}

.job-stats {
  grid-template-columns: repeat(5, minmax(120px, 1fr));
  margin: 14px 0;
}

.job-control-row {
  justify-content: space-between;
  align-items: flex-end;
  margin-top: 16px;
}

.job-safe-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.pause-form {
  margin: 0 0 0 auto;
}

.detection-actions {
  justify-content: space-between;
}

.detection-actions audio {
  width: min(100%, 380px);
}

.sample-limit-note {
  margin-bottom: 14px;
}

.sample-stats {
  grid-template-columns: repeat(3, minmax(120px, 1fr));
}

.hero-card {
  padding: 24px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.hero-card h1 {
  margin: 0;
  font-size: 2rem;
  line-height: 1.1;
}

.hero-copy {
  margin: 8px 0 0;
  color: var(--muted);
}

.login-shell {
  max-width: 720px;
}

.login-panel {
  margin-top: 20px;
}

.login-form {
  max-width: 460px;
}

.compact-flash {
  margin-top: 0;
  margin-bottom: 18px;
}

@media (max-width: 980px) {
  .topbar {
    grid-template-columns: 1fr;
  }

  .topbar-actions {
    justify-content: flex-start;
  }

  .detail-grid,
  .summary-grid {
    grid-template-columns: 1fr;
  }

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

@media (max-width: 700px) {
  .page-shell {
    width: min(100% - 20px, 1180px);
    margin-top: 18px;
  }

  .topbar {
    padding: 10px;
    gap: 10px;
  }

  .main-menu {
    width: 100%;
  }

  .menu-link {
    flex: 1;
  }

  .page-intro,
  .campaign-card-header,
  .job-topline,
  .detection-topline,
  .table-row,
  .row-heading,
  .form-actions,
  .job-actions,
  .detection-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .page-intro {
    padding: 18px;
  }

  .page-intro h1 {
    font-size: 2rem;
  }

  .campaign-grid,
  .campaign-stats,
  .job-stats,
  .field-grid {
    grid-template-columns: 1fr;
  }

  .primary-button,
  .secondary-button,
  .ghost-button,
  .danger-button,
  .pause-button {
    width: 100%;
  }

  .job-safe-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .pause-form {
    margin-left: 0;
  }

  .detection-actions audio {
    width: 100%;
  }
}
