:root {
  --bg: #f7f8fb;
  --surface: #ffffff;
  --surface-muted: #f2f4f7;
  --text: #111827;
  --muted: #667085;
  --line: #d9dee8;
  --blue: #2563eb;
  --blue-bg: #dbeafe;
  --green: #047857;
  --green-bg: #d1fae5;
  --amber: #b45309;
  --amber-bg: #fef3c7;
  --red: #b42318;
  --red-bg: #fee4e2;
  --shadow: 0 12px 28px rgba(16, 24, 40, 0.08);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

body {
  min-height: 100%;
  margin: 0;
  background: var(--bg);
}

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

button,
input,
select,
textarea {
  font: inherit;
}

textarea {
  resize: vertical;
}

.app-shell {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  overflow: auto;
  border-right: 1px solid var(--line);
  background: #111827;
  color: #f9fafb;
  padding: 20px;
}

.brand-block {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 24px;
}

.brand-link {
  font-size: 1.2rem;
  font-weight: 750;
}

.brand-status {
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 999px;
  color: #cbd5e1;
  font-size: 0.75rem;
  padding: 4px 8px;
}

.primary-nav {
  display: grid;
  gap: 6px;
  margin-bottom: 24px;
}

.nav-link,
.project-link {
  border-radius: var(--radius);
  color: #e5e7eb;
  display: grid;
  gap: 3px;
  padding: 10px 12px;
}

.nav-link:hover,
.project-link:hover,
.project-link.is-active {
  background: rgba(255, 255, 255, 0.1);
}

.sidebar-section {
  display: grid;
  gap: 10px;
}

.section-label {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 750;
  text-transform: uppercase;
}

.sidebar .section-label,
.project-meta {
  color: #9ca3af;
}

.project-list {
  display: grid;
  gap: 4px;
}

.project-name {
  font-weight: 650;
}

.project-meta {
  font-size: 0.82rem;
}

.main-content {
  min-width: 0;
  padding: 28px;
}

.page-header {
  align-items: flex-start;
  display: flex;
  gap: 18px;
  justify-content: space-between;
  margin: 0 auto 24px;
  max-width: 1220px;
}

.page-header h1 {
  font-size: 2rem;
  line-height: 1.15;
  margin: 4px 0 0;
}

.page-summary {
  color: var(--muted);
  line-height: 1.5;
  margin: 10px 0 0;
  max-width: 760px;
}

.header-stats {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(3, minmax(86px, 1fr));
}

.header-stats div {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  display: grid;
  gap: 2px;
  min-height: 64px;
  padding: 10px 12px;
}

.header-stats strong {
  font-size: 1.35rem;
}

.header-stats span {
  color: var(--muted);
  font-size: 0.78rem;
}

.content-grid,
.task-layout {
  display: grid;
  gap: 20px;
  grid-template-columns: minmax(0, 1fr) 360px;
  margin: 0 auto;
  max-width: 1220px;
}

.task-layout {
  align-items: start;
}

.thread-column,
.side-column {
  display: grid;
  gap: 20px;
  min-width: 0;
}

.panel,
.status-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
}

.panel-header,
.status-panel {
  align-items: flex-start;
  display: flex;
  gap: 14px;
  justify-content: space-between;
}

.panel-header {
  margin-bottom: 14px;
}

.panel h2 {
  font-size: 1.05rem;
  margin: 3px 0 0;
}

.status-panel {
  align-items: center;
  flex-wrap: wrap;
}

.status-title {
  font-size: 1.4rem;
  font-weight: 750;
  margin-top: 3px;
}

.status-metrics,
.action-strip,
.task-row-badges {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.action-strip {
  margin-left: auto;
}

.task-list,
.activity-list,
.thread-list,
.artifact-list,
.run-list {
  display: grid;
  gap: 10px;
}

.task-row {
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  display: grid;
  gap: 12px;
  grid-template-columns: minmax(0, 1fr) auto;
  min-height: 82px;
  padding: 14px;
}

.task-row:hover,
.activity-item:hover,
.artifact-link:hover {
  border-color: #a7b3c7;
}

.task-row-title {
  font-weight: 700;
  overflow-wrap: anywhere;
}

.task-row-subtitle {
  color: var(--muted);
  display: flex;
  flex-wrap: wrap;
  font-size: 0.85rem;
  gap: 10px;
  margin-top: 5px;
}

.pill {
  border-radius: 999px;
  display: inline-flex;
  font-size: 0.75rem;
  font-weight: 700;
  line-height: 1;
  max-width: 100%;
  padding: 6px 9px;
  text-transform: capitalize;
}

.tone-neutral {
  background: var(--surface-muted);
  color: #344054;
}

.tone-blue {
  background: var(--blue-bg);
  color: var(--blue);
}

.tone-green {
  background: var(--green-bg);
  color: var(--green);
}

.tone-amber {
  background: var(--amber-bg);
  color: var(--amber);
}

.tone-red {
  background: var(--red-bg);
  color: var(--red);
}

.stack-form {
  display: grid;
  gap: 12px;
}

.compact-form {
  gap: 10px;
}

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

.field {
  display: grid;
  gap: 6px;
}

.field label {
  color: #344054;
  font-size: 0.82rem;
  font-weight: 700;
}

.field input,
.field select,
.field textarea {
  background: #fff;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  color: var(--text);
  min-height: 42px;
  padding: 10px 11px;
  width: 100%;
}

.field textarea {
  line-height: 1.45;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.14);
  outline: none;
}

.button {
  align-items: center;
  border: 1px solid transparent;
  border-radius: var(--radius);
  cursor: pointer;
  display: inline-flex;
  font-weight: 750;
  justify-content: center;
  min-height: 40px;
  padding: 9px 13px;
  white-space: nowrap;
}

.button.primary {
  background: #111827;
  color: #fff;
}

.button.secondary {
  background: #fff;
  border-color: #cbd5e1;
  color: #1f2937;
}

.button:hover {
  filter: brightness(0.97);
}

.inline-form {
  display: inline-flex;
}

.thread-message {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  display: grid;
  gap: 8px;
  padding: 14px;
}

.message-human {
  border-left: 4px solid var(--blue);
}

.message-agent {
  border-left: 4px solid var(--green);
}

.message-system {
  background: var(--surface-muted);
  border-left: 4px solid #98a2b3;
}

.message-header {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.message-author {
  font-weight: 750;
  text-transform: capitalize;
}

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

.message-body {
  line-height: 1.5;
  overflow-wrap: anywhere;
}

.message-body p {
  margin: 0 0 10px;
}

.message-body p:last-child {
  margin-bottom: 0;
}

.metadata-list {
  border-top: 1px solid var(--line);
  display: grid;
  gap: 6px;
  margin: 4px 0 0;
  padding-top: 10px;
}

.metadata-list div {
  display: grid;
  gap: 6px;
  grid-template-columns: 96px minmax(0, 1fr);
}

.metadata-list dt,
.metadata-list dd {
  margin: 0;
}

.metadata-list dt {
  color: var(--muted);
  font-weight: 700;
}

.metadata-list dd {
  overflow-wrap: anywhere;
}

.activity-item,
.artifact-link,
.run-item,
.empty-state,
.placeholder-cell {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  display: grid;
  gap: 5px;
  padding: 12px;
}

.activity-item small,
.run-item small,
.run-item span {
  color: var(--muted);
}

.artifact-link {
  align-items: center;
  grid-template-columns: minmax(0, 1fr) auto;
}

.artifact-title {
  font-weight: 650;
  overflow-wrap: anywhere;
}

.run-item {
  grid-template-columns: minmax(0, 1fr) auto;
}

.run-item small,
.run-item p {
  grid-column: 1 / -1;
}

.run-item strong,
.run-item span {
  display: block;
}

.error-text {
  background: var(--red-bg);
  border-radius: 6px;
  color: var(--red);
  margin: 4px 0 0;
  padding: 8px;
}

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

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

.placeholder-cell strong {
  font-size: 1rem;
}

.flash-stack {
  display: grid;
  gap: 8px;
  left: 50%;
  max-width: 520px;
  position: fixed;
  top: 14px;
  transform: translateX(-50%);
  width: calc(100% - 28px);
  z-index: 10;
}

.flash {
  background: #111827;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  color: #fff;
  padding: 10px 12px;
}

.flash-alert {
  background: var(--red);
}

.form-errors {
  background: var(--red-bg);
  border-radius: 6px;
  color: var(--red);
  padding: 10px;
}

.tight {
  margin: 6px 0 0;
}

.auth-shell {
  align-items: center;
  display: grid;
  min-height: 100vh;
  padding: 24px;
}

.auth-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: grid;
  gap: 22px;
  margin: 0 auto;
  max-width: 420px;
  padding: 24px;
  width: 100%;
}

.auth-panel h1 {
  font-size: 1.7rem;
  margin: 4px 0 6px;
}

.auth-panel p {
  color: var(--muted);
  margin: 0;
}

.command-shell {
  display: grid;
  grid-template-columns: 224px minmax(0, 1fr) 340px;
  min-height: 100vh;
}

.compact-sidebar {
  padding: 16px;
}

.compact-sidebar .brand-block {
  margin-bottom: 18px;
}

.pinned-nav .nav-link {
  align-items: center;
  grid-template-columns: minmax(0, 1fr) auto;
  min-height: 40px;
  padding: 8px 10px;
}

.pinned-nav .nav-link small {
  color: #cbd5e1;
  font-size: 0.72rem;
}

.nav-link.is-active,
.system-link:hover {
  background: rgba(255, 255, 255, 0.12);
}

.system-nav {
  border-top: 1px solid rgba(255, 255, 255, 0.12);
  display: grid;
  gap: 4px;
  margin-top: 20px;
  padding-top: 14px;
}

.system-link,
.button-link {
  border: 0;
  border-radius: var(--radius);
  color: #cbd5e1;
  display: block;
  font-size: 0.82rem;
  padding: 8px 10px;
  text-align: left;
  width: 100%;
}

.button-link {
  background: transparent;
  cursor: pointer;
}

.system-form {
  margin: 0;
}

.command-main {
  min-width: 0;
  padding: 20px;
}

.command-rail {
  align-content: start;
  background: #eef2f6;
  border-left: 1px solid var(--line);
  display: grid;
  gap: 14px;
  min-width: 0;
  padding: 16px;
}

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

.deck-header h1 {
  font-size: 1.45rem;
  line-height: 1.1;
  margin: 3px 0;
}

.deck-header p {
  color: var(--muted);
  margin: 0;
}

.deck-metrics {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.deck-metrics span {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--muted);
  font-size: 0.82rem;
  padding: 7px 9px;
}

.deck-metrics strong {
  color: var(--text);
}

.board-panel,
.rail-panel,
.drawer-section {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 8px 20px rgba(16, 24, 40, 0.06);
  padding: 14px;
}

.board-header {
  align-items: center;
  display: flex;
  justify-content: space-between;
  margin-bottom: 10px;
}

.board-header h2,
.rail-panel h2,
.drawer-section h2 {
  font-size: 1rem;
  margin: 2px 0 0;
}

.task-board-list {
  display: grid;
  gap: 6px;
}

.task-board-list .task-row {
  box-shadow: none;
}

.task-row {
  gap: 10px;
  grid-template-columns: minmax(0, 1fr) auto auto;
  min-height: 58px;
  padding: 10px 11px;
}

.task-row-title {
  color: var(--text);
  display: inline-block;
  font-size: 0.95rem;
}

.task-row-title:hover {
  color: var(--blue);
}

.task-row-subtitle {
  font-size: 0.78rem;
  gap: 8px;
  margin-top: 3px;
}

.row-actions {
  align-items: center;
  display: flex;
  flex-wrap: nowrap;
  gap: 5px;
}

.icon-button {
  align-items: center;
  background: #fff;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  color: #344054;
  cursor: pointer;
  display: inline-flex;
  font-size: 0.75rem;
  font-weight: 750;
  justify-content: center;
  min-height: 30px;
  padding: 5px 8px;
  white-space: nowrap;
}

.icon-button.primary {
  background: #111827;
  border-color: #111827;
  color: #fff;
}

.rail-panel {
  box-shadow: none;
}

.rail-panel .field input,
.rail-panel .field select,
.rail-panel .field textarea {
  min-height: 36px;
  padding: 8px 9px;
}

.rail-panel .button {
  min-height: 36px;
}

.compact-create .stack-form {
  gap: 9px;
}

.activity-list {
  gap: 6px;
}

.activity-item {
  background: #fff;
  gap: 4px;
  padding: 9px 10px;
}

.activity-item span {
  font-size: 0.9rem;
  font-weight: 650;
  overflow-wrap: anywhere;
}

.activity-item small {
  font-size: 0.75rem;
}

turbo-frame.task-drawer-frame:empty {
  display: none;
}

turbo-frame.task-drawer-frame:not(:empty) {
  bottom: 0;
  left: 0;
  position: fixed;
  right: 0;
  top: 0;
  z-index: 30;
}

.drawer-backdrop {
  background: rgba(17, 24, 39, 0.36);
  bottom: 0;
  left: 0;
  position: absolute;
  right: 0;
  top: 0;
}

.task-drawer {
  background: var(--surface);
  border-left: 1px solid var(--line);
  bottom: 0;
  box-shadow: -18px 0 36px rgba(16, 24, 40, 0.18);
  display: grid;
  gap: 14px;
  grid-auto-rows: max-content;
  max-width: 620px;
  overflow: auto;
  padding: 18px;
  position: absolute;
  right: 0;
  top: 0;
  width: min(620px, 100%);
}

.drawer-header {
  align-items: flex-start;
  display: flex;
  gap: 12px;
  justify-content: space-between;
}

.drawer-header h2 {
  font-size: 1.25rem;
  margin: 3px 0 0;
  overflow-wrap: anywhere;
}

.drawer-summary {
  color: var(--muted);
  line-height: 1.45;
  margin: 0;
  overflow-wrap: anywhere;
}

.compact-thread {
  max-height: 320px;
  overflow: auto;
}

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

  .command-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    height: auto;
    position: static;
  }

  .primary-nav,
  .project-list {
    grid-auto-flow: column;
    grid-auto-columns: minmax(138px, max-content);
    overflow-x: auto;
    padding-bottom: 4px;
  }

  .content-grid,
  .task-layout {
    grid-template-columns: 1fr;
  }

  .command-rail {
    border-left: 0;
    border-top: 1px solid var(--line);
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 680px) {
  .main-content,
  .command-main {
    padding: 18px 14px 28px;
  }

  .page-header,
  .panel-header,
  .deck-header,
  .status-panel {
    display: grid;
  }

  .page-header h1 {
    font-size: 1.65rem;
  }

  .header-stats,
  .form-grid,
  .placeholder-grid {
    grid-template-columns: 1fr;
  }

  .task-row {
    grid-template-columns: 1fr;
  }

  .command-rail {
    grid-template-columns: 1fr;
  }

  .task-row-badges,
  .action-strip,
  .row-actions {
    justify-content: flex-start;
    margin-left: 0;
  }

  .metadata-list div {
    grid-template-columns: 1fr;
  }
}
