/* ProjectZero design tokens — GitLab-inspired (see docs/stitch/phase-1/.../DESIGN.md) */

:root {
  --pz-font-sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --pz-font-mono: ui-monospace, "Cascadia Code", "Segoe UI Mono", Menlo, Monaco, Consolas, monospace;

  --pz-canvas: #fafafa;
  --pz-surface: #ffffff;
  --pz-surface-muted: #f7f7f8;
  --pz-surface-subtle: #f0f0f0;
  --pz-border: #dbdbdb;
  --pz-border-subtle: #dcdcde;

  --pz-text: #2e2e2e;
  --pz-text-muted: #666666;
  --pz-link: #1068bf;

  --pz-brand: #f97316;
  --pz-brand-hover: #ea580c;
  --pz-brand-active: #c2410c;
  --pz-brand-rgb: 249, 115, 22;

  --pz-success: #108548;
  --pz-success-bg: #eef8f1;
  --pz-warning: #c17d10;
  --pz-warning-bg: #fdf6eb;
  --pz-danger: #db3b21;
  --pz-danger-bg: #faeae7;

  --pz-radius: 0.25rem;
  --pz-radius-lg: 0.5rem;
  --site-header-height: 3.25rem;
  --pz-container-max: 80rem;

  --bs-body-font-family: var(--pz-font-sans);
  --bs-body-font-size: 0.875rem;
  --bs-body-color: var(--pz-text);
  --bs-body-bg: var(--pz-canvas);
  --bs-border-color: var(--pz-border);
  --bs-link-color: var(--pz-link);
  --bs-link-hover-color: #0b4a86;
  --bs-primary: var(--pz-brand);
  --bs-primary-rgb: var(--pz-brand-rgb);
  --bs-secondary-color: var(--pz-text-muted);
  --bs-border-radius: var(--pz-radius);
  --bs-border-radius-lg: var(--pz-radius-lg);
  --bs-focus-ring-color: rgba(var(--pz-brand-rgb), 0.35);
}

html {
  font-size: 14px;
  min-height: 100%;
}

@media (min-width: 768px) {
  html {
    font-size: 16px;
  }
}

body {
  min-height: 100vh;
  margin: 0;
}

body.site-layout {
  background-color: var(--pz-canvas);
  color: var(--pz-text);
}

body.site-guest {
  background-color: var(--pz-canvas);
  color: var(--pz-text);
}

/* —— Layout shell —— */

.site-container {
  width: 100%;
  max-width: var(--pz-container-max);
  margin-left: auto;
  margin-right: auto;
  padding-left: 1rem;
  padding-right: 1rem;
}

@media (min-width: 768px) {
  .site-container {
    padding-left: 1.5rem;
    padding-right: 1.5rem;
  }
}

.site-layout-body {
  padding-top: var(--site-header-height);
  min-height: calc(100vh - var(--site-header-height));
  display: flex;
  flex-direction: column;
}

.site-main {
  flex: 1 1 auto;
  padding-top: 1rem;
  padding-bottom: 2rem;
}

/* —— Site header & main nav —— */

.site-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 1030;
  height: var(--site-header-height);
  background: var(--pz-surface);
  border-bottom: 1px solid var(--pz-border-subtle);
}

.site-header-inner {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.site-header-start {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  min-width: 0;
  flex: 1 1 auto;
}

.site-brand {
  display: inline-flex;
  align-items: center;
  flex-shrink: 0;
  text-decoration: none;
  line-height: 0;
}

.site-brand:hover {
  opacity: 0.92;
}

.site-brand-logo {
  display: block;
  height: auto;
  max-width: 100%;
}

/* Header: vector mark only — stays sharp at any DPI. */
.site-brand--compact .site-brand-logo {
  height: 2.5rem;
  width: auto;
}

/* Sign-in / register: full Stitch SVG (600×600). */
.site-brand--full .site-brand-logo {
  width: min(16rem, 85vw);
  height: auto;
}

.site-nav {
  display: none;
  align-items: stretch;
  height: var(--site-header-height);
  gap: 0.125rem;
}

@media (min-width: 576px) {
  .site-nav {
    display: flex;
  }
}

.site-nav-link {
  display: inline-flex;
  align-items: center;
  height: 100%;
  padding: 0 0.75rem;
  font-size: 0.875rem;
  color: var(--pz-text-muted);
  text-decoration: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: color 0.15s ease, border-color 0.15s ease;
}

.site-nav-link:hover {
  color: var(--pz-text);
}

.site-nav-link.active {
  color: var(--pz-text);
  font-weight: 500;
  border-bottom-color: var(--pz-brand);
}

.site-nav-count {
  margin-left: 0.35rem;
  padding: 0.1rem 0.4rem;
  font-size: 0.6875rem;
  font-weight: 600;
  line-height: 1.2;
  border-radius: 999px;
  background: var(--pz-surface-subtle);
  color: var(--pz-text);
}

.site-header-end {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-shrink: 0;
}

.site-header-user {
  display: none;
  font-family: var(--pz-font-mono);
  font-size: 0.8125rem;
  color: var(--pz-text-muted);
}

@media (min-width: 576px) {
  .site-header-user {
    display: inline;
  }
}

.site-header-toggle {
  border: 1px solid var(--pz-border);
  background: var(--pz-surface);
}

.site-header-collapse {
  flex-basis: 100%;
}

/* Two classes to match Bootstrap's .collapse:not(.show), which would otherwise hide the nav on wide screens. */
@media (min-width: 576px) {
  .site-header-collapse.collapse {
    display: contents;
  }
}

@media (max-width: 575.98px) {
  .site-header-collapse .site-nav {
    display: flex;
    flex-direction: column;
    height: auto;
    padding: 0.5rem 0 0.75rem;
  }

  .site-header-collapse .site-nav-link {
    height: auto;
    padding: 0.5rem 0;
    border-bottom: none;
    border-left: 2px solid transparent;
    padding-left: 0.5rem;
  }

  .site-header-collapse .site-nav-link.active {
    border-left-color: var(--pz-brand);
  }
}

/* —— Footer —— */

.site-footer {
  margin-top: auto;
  padding: 1.25rem 0;
  border-top: 1px solid var(--pz-border-subtle);
  background: var(--pz-surface);
  font-size: 0.8125rem;
  color: var(--pz-text-muted);
  text-align: center;
}

/* —— Guest / auth —— */

.site-guest-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem 1rem;
}

.site-guest-main {
  width: 100%;
  max-width: 28rem;
}

.auth-brand {
  text-align: center;
  margin-bottom: 1.5rem;
}

.auth-brand .site-brand {
  justify-content: center;
}

.auth-brand-tagline {
  font-size: 0.8125rem;
  color: var(--pz-text-muted);
  margin-top: 0.25rem;
}

.auth-card {
  background: var(--pz-surface);
  border: 1px solid var(--pz-border);
  border-radius: var(--pz-radius-lg);
  overflow: hidden;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}

.auth-tabs {
  display: flex;
  background: var(--pz-surface-muted);
  border-bottom: 1px solid var(--pz-border);
}

.auth-tabs-item {
  flex: 1 1 50%;
  text-align: center;
  padding: 0.625rem 0.75rem;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--pz-text-muted);
  text-decoration: none;
  position: relative;
  transition: color 0.15s ease, background 0.15s ease;
}

.auth-tabs-item:hover {
  color: var(--pz-text);
}

.auth-tabs-item.active {
  color: var(--pz-text);
  background: var(--pz-surface);
}

.auth-tabs-item.active::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 2px;
  background: var(--pz-brand);
}

.auth-card-body {
  padding: 1.5rem;
}

.auth-card-footer {
  padding: 0.75rem 1.5rem;
  border-top: 1px solid var(--pz-border);
  background: var(--pz-surface-muted);
  text-align: center;
  font-size: 0.8125rem;
  color: var(--pz-text-muted);
}

.auth-footlinks {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.75rem 1rem;
  margin-top: 1.5rem;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--pz-text-muted);
}

.auth-footlinks a {
  color: inherit;
  text-decoration: none;
}

.auth-footlinks a:hover {
  color: var(--pz-text);
}

/* —— Page chrome —— */

.page-header-block {
  margin-bottom: 1.25rem;
}

.page-title {
  font-size: 1.375rem;
  font-weight: 600;
  line-height: 1.3;
  margin: 0 0 0.25rem;
  color: var(--pz-text);
}

.page-lead {
  font-size: 0.8125rem;
  color: var(--pz-text-muted);
  margin: 0;
}

.page-breadcrumb {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.8125rem;
  color: var(--pz-text-muted);
  margin-bottom: 1rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--pz-border-subtle);
}

.page-breadcrumb a {
  color: inherit;
  text-decoration: none;
}

.page-breadcrumb a:hover {
  color: var(--pz-text);
}

.page-breadcrumb-sep {
  opacity: 0.6;
}

.page-breadcrumb-current {
  color: var(--pz-text);
  font-weight: 500;
}

/* —— Cards & panels —— */

.content-card {
  background: var(--pz-surface);
  border: 1px solid var(--pz-border);
  border-radius: var(--pz-radius-lg);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}

.content-card-header {
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--pz-border-subtle);
}

.content-card-body {
  padding: 1.5rem;
}

.content-card-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  padding-top: 1rem;
  margin-top: 0.5rem;
  border-top: 1px solid var(--pz-border-subtle);
}

.form-hint {
  font-size: 0.75rem;
  color: var(--pz-text-muted);
  margin-top: 0.25rem;
}

/* —— Alerts & messages —— */

#message:empty {
  display: none;
}

.site-flash .alert {
  font-size: 0.875rem;
  border-radius: var(--pz-radius-lg);
  border-width: 1px;
}

.site-flash .alert-success {
  background-color: var(--pz-success-bg);
  border-color: #c2e9cd;
  color: var(--pz-success);
}

.site-flash .alert-danger {
  background-color: var(--pz-danger-bg);
  border-color: #f6c8c1;
  color: var(--pz-danger);
}

.messageAdditionalInvalidForm:not(:empty) {
  display: block;
  margin-bottom: 1rem;
  padding: 0.625rem 0.75rem;
  font-size: 0.8125rem;
  border-radius: var(--pz-radius);
  background: var(--pz-danger-bg);
  border: 1px solid #f6c8c1;
  color: var(--pz-danger);
}

.messageAdditionalInvalidForm.alert.alert-danger {
  background: var(--pz-danger-bg);
  border-color: #f6c8c1;
  color: var(--pz-danger);
}

.help-block.invalid-feedback,
.help-block.d-block:not(.d-none) {
  display: block !important;
  font-size: 0.8125rem;
  color: var(--pz-danger);
  margin-top: 0.25rem;
}

/* Review status (BL-25): the prototype's soft orange, apart from the yellow Medium priority badge. */
.badge-review {
  color: #a35200;
  background-color: #fff4e5;
  border: 1px solid #f5c98f;
}

/* Labels (BL-29): soft chips from the fixed palette; the name is always written, so colour is never the only cue. */
.label-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
}

.label-chip {
  display: inline-block;
  max-width: 100%;
  padding: 0.0625rem 0.5rem;
  border: 1px solid;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 500;
  line-height: 1.4;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.label-chip-gray { color: #3f4650; background-color: #f1f3f5; border-color: #ced4da; }
.label-chip-red { color: #a61b29; background-color: #fdecee; border-color: #f2b8bf; }
.label-chip-orange { color: #a35200; background-color: #fff4e5; border-color: #f5c98f; }
.label-chip-yellow { color: #6d5500; background-color: #fff9db; border-color: #f0d870; }
.label-chip-green { color: #1e6b34; background-color: #e9f7ee; border-color: #a9dcb8; }
.label-chip-teal { color: #0b6461; background-color: #e3f6f5; border-color: #9fd8d5; }
.label-chip-blue { color: #1d4fa3; background-color: #e8f0fe; border-color: #a9c4f5; }
.label-chip-purple { color: #5b2d9e; background-color: #f3ecfd; border-color: #cdb6f2; }

/* A long assignee name would push the select out of the side card. */
#task-assignee {
  min-width: 0;
  text-overflow: ellipsis;
}

/* Task templates (BL-31): the kind of work as a quiet outlined badge, set apart from the filled priority badge. */
.work-type-badge {
  color: #3f4650;
  background-color: #fff;
  border: 1px solid #ced4da;
  font-weight: 500;
}

.template-options-long {
  max-height: 14rem;
  overflow-y: auto;
  padding: 0.5rem 0.75rem;
  border: 1px solid #dee2e6;
  border-radius: 0.375rem;
}

.template-values dt {
  font-weight: 600;
  font-size: 0.875rem;
}

.template-values dd {
  margin-bottom: 0.75rem;
}

.template-markdown {
  white-space: pre-wrap;
  font-size: 0.8125rem;
  padding: 0.5rem;
  background-color: #f8f9fa;
  border-radius: 0.375rem;
}

/* —— Board (FR-26) —— */

/* Four equal columns; on narrow screens the board scrolls sideways instead of stacking. */
.board {
  display: grid;
  grid-template-columns: repeat(4, minmax(16rem, 1fr));
  gap: 1rem;
  overflow-x: auto;
  padding-bottom: 0.5rem;
}

.board-column {
  display: flex;
  flex-direction: column;
  min-height: 16rem;
  padding: 0.75rem;
  background: var(--pz-surface-muted);
  border: 1px solid var(--pz-border);
  border-radius: var(--pz-radius-lg);
  transition: border-color 0.15s ease, background-color 0.15s ease;
}

.board-column.is-drop-target {
  border-color: var(--pz-brand);
  background: rgba(var(--pz-brand-rgb), 0.06);
}

.board-column-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.75rem;
}

.board-cards {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  flex: 1 1 auto;
}

.board-cards:has(.board-card) .board-empty {
  display: none;
}

.board-card[draggable="true"] {
  cursor: grab;
}

.board-card.is-dragging {
  opacity: 0.5;
}

.board-card.is-saving {
  opacity: 0.6;
  pointer-events: none;
}

.board-card-title {
  display: block;
  font-weight: 600;
  color: var(--pz-text);
  text-decoration: none;
  margin-bottom: 0.125rem;
}

/* Above the card-wide stretched link, so the menu opens instead of the task. */
.board-card-menu {
  position: relative;
  z-index: 2;
}

/* An agent's card (06 §8.1): an accent edge, with the "Agent" label so colour is not the only sign. */
.board-card-agent {
  border-left: 4px solid var(--bs-purple, #6f42c1);
}

.board-card-agent-tag {
  color: var(--bs-purple, #6f42c1);
  font-weight: 600;
}

.run-history-summary {
  max-width: 16rem;
  vertical-align: bottom;
}

/* Agent-made page (BL-49b): the frame grows with pz.resize up to 4,000 px. */
.agent-page-frame {
  display: block;
  width: 100%;
  height: 480px;
  border: 1px solid var(--bs-border-color);
  border-radius: var(--bs-border-radius);
  background: #fff;
}

.board-card.is-arriving {
  animation: board-card-arrive 1.2s ease;
}

@keyframes board-card-arrive {
  from { box-shadow: 0 0 0 3px rgba(var(--pz-brand-rgb), 0.5); }
  to { box-shadow: none; }
}

/* —— Due dates —— */

.due-date.is-past {
  color: var(--pz-danger);
  font-weight: 600;
}

/* A done task is never overdue; the status ancestor changes in place when the status does. */
[data-status="Done"] .due-date.is-past {
  color: inherit;
  font-weight: inherit;
}

[data-status="Done"] .due-overdue {
  display: none;
}

/* —— Small helpers (the Content Security Policy blocks style attributes) —— */

.text-pre-line {
  white-space: pre-line;
}

.project-row-description {
  max-width: 32rem;
}

.task-status-column {
  width: 10rem;
}

#page-loading.page-loading {
  z-index: 2000;
}

/* —— Agent result (BL-33): content written by the agent, kept visibly apart from ProjectZero's own UI —— */

.agent-result {
  border: 1px solid var(--pz-border);
  border-left: 3px solid var(--pz-link);
  border-radius: var(--pz-radius);
  background: var(--pz-surface-muted);
  padding: 1rem;
  overflow-wrap: anywhere;
}

.agent-result-label {
  display: inline-block;
  font-size: 0.75rem;
  color: var(--pz-text-muted);
  border: 1px solid var(--pz-border);
  border-radius: var(--pz-radius);
  background: var(--pz-surface);
  padding: 0 0.375rem;
  margin-bottom: 0.5rem;
}

.agent-result-toc .agent-toc-level-3 {
  padding-left: 1rem;
}

.agent-result-toc .agent-toc-level-4 {
  padding-left: 2rem;
}

.agent-block {
  margin-bottom: 1rem;
  scroll-margin-top: 4rem;
}

.agent-block-title {
  font-weight: 600;
  margin-bottom: 0.25rem;
}

.agent-markdown > :last-child {
  margin-bottom: 0;
}

.agent-markdown pre,
.agent-code pre {
  max-height: 24rem;
  overflow: auto;
  background: var(--pz-surface);
  border: 1px solid var(--pz-border);
  border-radius: var(--pz-radius);
  padding: 0.5rem 0.75rem;
  font-family: var(--pz-font-mono);
  font-size: 0.8125rem;
}

.agent-table {
  background: var(--pz-surface);
}

.agent-table caption {
  caption-side: top;
}

.agent-math-display {
  overflow-x: auto;
  text-align: center;
}

.agent-math-inline {
  display: inline-block;
}

.agent-citation blockquote {
  border-left: 3px solid var(--pz-border);
  padding-left: 0.75rem;
}

.agent-unknown {
  border: 1px dashed var(--pz-border);
  border-radius: var(--pz-radius);
  padding: 0.5rem 0.75rem;
}

/* —— Bootstrap controls (GitLab tone) —— */

.form-control,
.form-select {
  font-size: 0.875rem;
  border-color: var(--pz-border);
  border-radius: var(--pz-radius);
}

.form-control:focus,
.form-select:focus {
  border-color: var(--pz-brand);
  box-shadow: 0 0 0 1px var(--pz-brand);
}

.form-control.is-invalid,
.form-select.is-invalid {
  border-color: var(--pz-danger);
}

.form-label {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--pz-text);
  margin-bottom: 0.35rem;
}

.form-check-input:checked {
  background-color: var(--pz-brand);
  border-color: var(--pz-brand);
}

.form-check-input:focus {
  border-color: var(--pz-brand);
  box-shadow: 0 0 0 0.2rem rgba(var(--pz-brand-rgb), 0.25);
}

.btn-primary {
  --bs-btn-bg: var(--pz-brand);
  --bs-btn-border-color: var(--pz-brand-hover);
  --bs-btn-hover-bg: var(--pz-brand-hover);
  --bs-btn-hover-border-color: var(--pz-brand-active);
  --bs-btn-active-bg: var(--pz-brand-active);
  --bs-btn-active-border-color: var(--pz-brand-active);
  font-weight: 500;
}

.btn-outline-primary {
  --bs-btn-color: var(--pz-brand);
  --bs-btn-border-color: var(--pz-brand);
  --bs-btn-hover-color: #fff;
  --bs-btn-hover-bg: var(--pz-brand);
  --bs-btn-hover-border-color: var(--pz-brand);
  --bs-btn-active-color: #fff;
  --bs-btn-active-bg: var(--pz-brand-active);
  --bs-btn-active-border-color: var(--pz-brand-active);
  --bs-btn-disabled-color: var(--pz-brand);
  --bs-btn-disabled-border-color: var(--pz-brand);
}

.btn-outline-secondary {
  --bs-btn-color: var(--pz-text);
  --bs-btn-border-color: var(--pz-border);
  --bs-btn-hover-bg: var(--pz-surface-subtle);
  --bs-btn-hover-border-color: #c7c7c7;
  --bs-btn-hover-color: var(--pz-text);
}

.btn:focus,
.btn:active:focus,
.form-control:focus,
.form-check-input:focus {
  box-shadow: 0 0 0 1px var(--pz-brand), 0 0 0 0.2rem rgba(var(--pz-brand-rgb), 0.2);
}

/* Agent run log on the task page (BL-36): long OpenCode logs scroll inside the card. */
.agent-run-events {
  max-height: 20rem;
  overflow-y: auto;
}

/* Personal agent quota (spec USR-08): My quota bars and the locked Run agent block. <progress> instead of a
   Bootstrap .progress, whose width would need a style attribute (CSP). */
.quota-progress {
    display: block;
    width: 100%;
    height: 0.5rem;
    margin: 0.25rem 0;
    accent-color: var(--bs-success);
}
.quota-progress.quota-warn { accent-color: var(--bs-warning); }
.quota-progress.quota-full { accent-color: var(--bs-danger); }
.agent-run-locked strong { margin-bottom: 0.25rem; }
.quota-row-highlight > td { background-color: var(--bs-warning-bg-subtle); }
