:root {
  color-scheme: light dark;
  --background: #f8fafc;
  --foreground: #111827;
  --muted: #64748b;
  --border: #d7dde5;
  --panel: #ffffff;
  --panel-subtle: #f1f5f9;
  --field: #ffffff;
  --topbar-background: rgba(248, 250, 252, 0.94);
  --accent: #0f766e;
  --accent-foreground: #ffffff;
  --focus-ring: rgba(15, 118, 110, 0.18);
  --hover-border: #94a3b8;
  --warning: #a16207;
  --success: #15803d;
  --error: #b91c1c;
  --ai-action-border: oklch(40.8% 0.123 38.172);
  --ai-action-icon: oklch(55.3% 0.195 38.402);
  --ai-action-border-hover: oklch(47% 0.157 37.304);
  --ai-action-icon-hover: oklch(64.6% 0.222 41.116);
  --ai-action-background-hover: oklch(98% 0.016 73.684);
  --popover-shadow:
    0 20px 40px -12px rgb(15 23 42 / 0.32), 0 8px 16px -8px rgb(15 23 42 / 0.2);
  font-family:
    Inter,
    ui-sans-serif,
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --background: #0a0a0a;
    --foreground: #f5f5f5;
    --muted: #a3a3a3;
    --border: #2f2f2f;
    --panel: #141414;
    --panel-subtle: #1f1f1f;
    --field: #101010;
    --topbar-background: rgba(10, 10, 10, 0.92);
    --accent: #2dd4bf;
    --accent-foreground: #042f2e;
    --focus-ring: rgba(45, 212, 191, 0.24);
    --hover-border: #525252;
    --warning: #facc15;
    --success: #86efac;
    --error: #fca5a5;
    --ai-action-background-hover: oklch(26.6% 0.079 36.259);
    --popover-shadow:
      0 20px 40px -12px rgb(0 0 0 / 0.65), 0 8px 16px -8px rgb(0 0 0 / 0.45);
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--background);
  color: var(--foreground);
}

body.board-shell {
  /*
   * Every ancestor in the Board sizing chain must be allowed to shrink so
   * overflow reaches the Board and task stacks instead of the document.
   */
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  height: 100dvh;
  overflow: hidden;
}

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

button,
input,
textarea {
  font: inherit;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  min-height: 64px;
  padding: 0 24px;
  border-bottom: 1px solid var(--border);
  background: var(--topbar-background);
  backdrop-filter: blur(10px);
}

.brand {
  flex: none;
  font-weight: 650;
}

.nav {
  display: flex;
  gap: 6px;
}

.project-subnav {
  display: flex;
  gap: 4px;
  margin-bottom: 22px;
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
}

.project-subnav a {
  flex: none;
  margin-bottom: -1px;
  border-bottom: 2px solid transparent;
  padding: 8px 10px 10px;
  color: var(--muted);
  font-size: 0.875rem;
}

.project-subnav a:hover,
.project-subnav a[aria-current] {
  color: var(--foreground);
}

.project-subnav a[aria-current] {
  border-bottom-color: var(--accent);
  font-weight: 650;
}

.project-subnav a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

.nav-icon-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.nav-icon {
  flex: none;
}

.nav a,
.button-link {
  border-radius: 6px;
  padding: 8px 10px;
  color: var(--muted);
}

.nav a:hover,
.button-link:hover {
  background: var(--panel-subtle);
  color: var(--foreground);
}

.nav a[aria-current] {
  background: var(--panel-subtle);
  color: var(--foreground);
  font-weight: 650;
}

.nav a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

@media (hover: hover) {
  .nav a[aria-current]:hover {
    box-shadow: inset 0 0 0 1px var(--border);
  }
}

main {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0 56px;
}

.board-page {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  width: calc(100vw - 32px);
  max-width: none;
  height: 100%;
  min-height: 0;
  padding: 28px 0 16px;
  overflow: hidden;
}

.page-header {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
}

.page-header h1,
.section-header h2 {
  margin: 0;
  letter-spacing: 0;
}

.page-header h1 {
  font-size: clamp(1.6rem, 4vw, 2.2rem);
}

.page-header > div > .muted {
  margin: 4px 0 0;
}

.page-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 4px;
}

.page-header-tools {
  /* The live status comes first so feedback grows left while action order stays stable. */
  position: relative;
  display: flex;
  min-width: 0;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
}

.page-action-buttons {
  display: flex;
  min-width: 0;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
}

.page-copy-status {
  min-width: 0;
  text-align: end;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 28px 0 12px;
}

.muted,
.empty {
  color: var(--muted);
}

.empty {
  margin: 0;
  padding: 12px 0;
}

.list-item,
.task-card,
.detail-panel,
.inbox-composer,
.profile-form,
.instructions-form,
.board-column {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
}

.list {
  display: grid;
  gap: 10px;
}

.list-item {
  display: grid;
  gap: 6px;
  padding: 14px;
}

.item-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.item-id,
.badge {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 650;
  text-transform: uppercase;
}

.item-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
}

.badge {
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px 8px;
  background: var(--panel-subtle);
}

.project-badge {
  color: var(--foreground);
  text-transform: none;
}

.board {
  display: flex;
  min-width: 0;
  min-height: 0;
  gap: 12px;
  overflow-x: auto;
  overflow-y: hidden;
  padding-bottom: 6px;
}

.board-column {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  /* Fill sparse boards evenly without letting columns become hard to scan. */
  flex: 1 0 min(17rem, 100%);
  max-width: 24rem;
  min-width: 0;
  min-height: 0;
  padding: 12px;
}

.column-header {
  margin-bottom: 12px;
}

.column-header h2 {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin: 0;
  font-size: 0.9rem;
  text-transform: capitalize;
}

.status-marker {
  width: 8px;
  height: 8px;
  flex: 0 0 auto;
  border-radius: 999px;
  background: var(--muted);
  opacity: 0.55;
}

.column-label {
  min-width: 0;
  overflow-wrap: anywhere;
}

.column-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 22px;
  min-height: 20px;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 1px 6px;
  background: var(--panel-subtle);
  color: var(--muted);
  font-size: 0.72rem;
  line-height: 1;
}

.task-stack {
  display: grid;
  align-content: start;
  min-height: 0;
  gap: 8px;
  padding: 2px;
  overflow-y: auto;
}

.task-card {
  display: grid;
  gap: 8px;
  padding: 12px;
}

.list-item:hover {
  border-color: var(--hover-border);
}

.task-card-title {
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.task-card-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 10px;
  color: var(--muted);
  font-size: 0.78rem;
}

.task-meta-label {
  font-weight: 650;
}

.task-card:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

@media (hover: hover) {
  .task-card:hover {
    border-color: var(--hover-border);
    background: var(--panel-subtle);
  }
}

.detail-panel {
  padding: 20px;
}

.metadata {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 20px;
}

.prose {
  line-height: 1.65;
}

.prose :first-child {
  margin-top: 0;
}

.prose :last-child {
  margin-bottom: 0;
}

.profile-form {
  display: grid;
  width: min(560px, 100%);
  gap: 14px;
  padding: 16px;
}

.instructions-form {
  display: grid;
  gap: 14px;
  margin-top: 16px;
  padding: 16px;
}

.instructions-form textarea {
  min-height: 16rem;
  resize: vertical;
}

.profile-header > div {
  display: grid;
  gap: 6px;
}

.profile-header p {
  margin: 0;
}

.inbox-composer {
  overflow: hidden;
}

.inbox-composer[data-dragging] {
  border-color: var(--accent);
  background: var(--panel-subtle);
}

.composer-identity {
  min-height: 45px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.85rem;
}

.composer-identity p {
  margin: 0;
}

.composer-identity strong {
  color: var(--foreground);
}

.text-link {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 3px;
}

.composer-form {
  display: grid;
}

.composer-form textarea {
  min-height: 150px;
  border: 0;
  border-radius: 0;
  padding: 16px;
  background: transparent;
  resize: vertical;
}

.composer-form textarea:focus {
  border: 0;
  outline: 0;
}

.composer-form textarea:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

.composer-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border-top: 1px solid var(--border);
}

.drop-hint {
  flex: 1;
  color: var(--muted);
  font-size: 0.82rem;
}

.secondary-button {
  display: inline-flex;
  align-items: center;
  width: auto;
  min-height: 37px;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 12px;
  background: var(--panel);
  color: var(--foreground);
  cursor: pointer;
}

.secondary-button:hover {
  border-color: var(--hover-border);
  background: var(--panel-subtle);
}

.attachment-list {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0 14px 12px;
  list-style: none;
}

.attachment-item {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  min-height: 48px;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 7px;
  background: var(--panel-subtle);
}

.attachment-item img {
  width: 42px;
  height: 42px;
  border-radius: 4px;
  object-fit: cover;
}

.attachment-item > span {
  display: grid;
  min-width: 0;
}

.attachment-item strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.attachment-item small,
.message-file small {
  color: var(--muted);
}

.attachment-remove {
  padding: 6px 8px;
  background: transparent;
  color: var(--muted);
}

.attachment-remove:hover {
  background: var(--panel);
  color: var(--foreground);
}

.composer-form > .form-status {
  margin: 0;
  padding: 0 14px 12px;
}

.message-attachments {
  margin-top: 24px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
}

.message-attachments h2 {
  margin: 0 0 12px;
  font-size: 1rem;
}

.attachment-gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 10px;
}

.message-image,
.message-file {
  display: grid;
  gap: 8px;
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px;
  background: var(--panel-subtle);
}

.message-image:hover,
.message-file:hover {
  border-color: var(--hover-border);
}

.message-image img {
  width: 100%;
  aspect-ratio: 4 / 3;
  border-radius: 4px;
  object-fit: cover;
}

.message-image span,
.message-file span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 0.9rem;
}

input,
textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 9px 10px;
  background: var(--field);
  color: var(--foreground);
}

input:focus,
textarea:focus {
  border-color: var(--accent);
  outline: 2px solid var(--focus-ring);
}

button {
  border: 0;
  border-radius: 6px;
  padding: 9px 14px;
  background: var(--accent);
  color: var(--accent-foreground);
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.icon-button {
  display: inline-grid;
  width: 38px;
  height: 38px;
  flex: 0 0 auto;
  place-items: center;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0;
  background: var(--panel);
  color: var(--muted);
  cursor: pointer;
}

.icon-button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.ai-action {
  border-color: var(--ai-action-border);
  color: var(--ai-action-icon);
}

.ai-action:focus-visible {
  outline-color: var(--ai-action-icon);
}

.action-icon {
  display: block;
  width: 19px;
  height: 19px;
}

.prompt-list {
  position: fixed;
  inset: var(--prompt-popover-top) auto auto var(--prompt-popover-left);
  display: grid;
  width: min(32rem, calc(100vw - 32px));
  max-height: min(24rem, 60dvh);
  margin: 0;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px;
  background: var(--panel);
  box-shadow: var(--popover-shadow);
  list-style: none;
}

.prompt-list:not(:popover-open) {
  display: none;
}

.prompt-list-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  padding: 10px;
}

.prompt-list-item + .prompt-list-item {
  margin-block-start: 6px;
  border-block-start: 1px solid var(--border);
  padding-block-start: 16px;
}

.prompt-content {
  min-width: 0;
}

.prompt-text {
  margin: 0;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.prompt-eyebrow {
  margin: 0;
  margin-block-end: 4px;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  line-height: 1.3;
  text-transform: uppercase;
}

@media (hover: hover) {
  .icon-button:hover {
    border-color: var(--hover-border);
    background: var(--panel-subtle);
    color: var(--foreground);
  }

  .ai-action:hover {
    border-color: var(--ai-action-border-hover);
    background: var(--ai-action-background-hover);
    color: var(--ai-action-icon-hover);
  }
}

.form-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.form-status {
  margin: 0;
  color: var(--muted);
}

.form-status[data-state="success"] {
  color: var(--success);
}

.form-status[data-state="warning"] {
  color: var(--warning);
}

.form-status[data-state="error"] {
  color: var(--error);
}

@media (max-width: 760px) {
  .topbar,
  .page-header,
  .item-line,
  .form-row,
  .composer-actions {
    align-items: stretch;
    flex-direction: column;
  }

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

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

  .page-header-tools {
    width: 100%;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
  }

  .page-action-buttons {
    flex-wrap: wrap;
    justify-content: flex-start;
  }

  .page-copy-status {
    text-align: start;
  }

  .nav {
    width: 100%;
  }

  .nav a {
    flex: 1;
    text-align: center;
  }

  .drop-hint {
    display: none;
  }

  .composer-actions button,
  .secondary-button {
    justify-content: center;
    width: 100%;
  }
}
