:root {
  color-scheme: light;
  --bg: #f6f7f8;
  --panel: #ffffff;
  --panel-soft: #f0f3f5;
  --text: #1f2933;
  --muted: #62707f;
  --border: #d8dee5;
  --blue: #2d6cdf;
  --green: #17835b;
  --amber: #b26a00;
  --red: #b23b3b;
  --cyan: #1d9aa8;
  --shadow: 0 12px 36px rgba(31, 41, 51, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 13px;
}

.auth-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: #eef2f5;
}

.auth-shell {
  width: min(420px, 100%);
  display: grid;
  gap: 14px;
  justify-items: start;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 28px;
}

.auth-mark {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border-radius: 6px;
  background: #143a5a;
  color: #fff;
  font-weight: 800;
}

.auth-shell h1 {
  font-size: 22px;
}

.auth-shell p {
  color: var(--muted);
  line-height: 1.45;
}

.auth-button {
  width: 100%;
}

.auth-status {
  min-height: 20px;
}

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

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

.sidebar {
  border-right: 1px solid var(--border);
  background: #ffffff;
  padding: 14px 12px;
  overflow-y: auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
}

.mark {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: 6px;
  background: #143a5a;
  color: #fff;
  font-weight: 800;
  letter-spacing: 0;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: 16px;
  line-height: 1.15;
}

.brand p,
.topbar p,
.meta,
.small {
  color: var(--muted);
}

.side-section {
  display: grid;
  gap: 8px;
  margin-top: 14px;
}

label {
  font-size: 11px;
  font-weight: 750;
  text-transform: uppercase;
  color: #536170;
  letter-spacing: 0;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 9px;
  background: #fff;
  color: var(--text);
}

.main {
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  min-height: 64px;
  border-bottom: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.92);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 12px 14px;
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar h2 {
  font-size: 19px;
  line-height: 1.2;
}

.top-actions {
  display: flex;
  gap: 8px;
}

.button,
.icon-button {
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  border-radius: 6px;
  padding: 8px 10px;
  text-decoration: none;
  cursor: pointer;
  font-weight: 700;
}

.button:not(.secondary) {
  background: #143a5a;
  color: #fff;
  border-color: #143a5a;
}

.board {
  display: grid;
  grid-template-columns: repeat(5, minmax(225px, 1fr));
  gap: 8px;
  padding: 10px;
  overflow-x: auto;
  align-items: start;
  height: calc(100vh - 64px);
}

.column {
  min-height: 0;
  max-height: calc(100vh - 84px);
  background: var(--panel-soft);
  border: 1px solid var(--border);
  border-radius: 6px;
  display: flex;
  flex-direction: column;
}

.column-header {
  padding: 9px 10px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 800;
}

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

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-left: 4px solid var(--blue);
  border-radius: 6px;
  padding: 8px;
  box-shadow: 0 1px 0 rgba(31, 41, 51, 0.04);
}

.card.is-working {
  border-color: rgba(29, 154, 168, 0.55);
  box-shadow: 0 0 0 1px rgba(29, 154, 168, 0.22), 0 0 24px rgba(29, 154, 168, 0.22);
  animation: workingGlow 1.8s ease-in-out infinite;
}

@keyframes workingGlow {
  0%, 100% {
    box-shadow: 0 0 0 1px rgba(29, 154, 168, 0.16), 0 0 16px rgba(29, 154, 168, 0.16);
  }
  50% {
    box-shadow: 0 0 0 1px rgba(29, 154, 168, 0.42), 0 0 30px rgba(29, 154, 168, 0.32);
  }
}

.card[data-confidence="High"] {
  border-left-color: var(--green);
}

.card[data-confidence="Medium"] {
  border-left-color: var(--amber);
}

.card[data-column="rejected"] {
  opacity: 0.76;
  border-left-color: var(--red);
}

.card-topline {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  gap: 8px;
  align-items: start;
  margin-bottom: 8px;
}

.drag-surface,
.drag-zone {
  cursor: grab;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

.drag-surface:active,
.drag-zone:active {
  cursor: grabbing;
}

.drag-handle {
  width: 34px;
  min-height: 54px;
  border: 1px solid var(--border);
  border-radius: 5px;
  background: #f8fafc;
  color: #536170;
  cursor: grab;
  line-height: 1.1;
  padding: 0;
  touch-action: none;
  font-size: 18px;
  display: grid;
  place-items: center;
}

.drag-handle:active {
  cursor: grabbing;
}

.open-card {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  padding: 0;
  text-align: left;
  font-weight: 800;
  font-size: 12.5px;
  line-height: 1.25;
  min-width: 0;
}

.open-card:hover {
  color: #143a5a;
}

.card-title,
.card-subtitle {
  display: block;
  min-width: 0;
}

.card-title {
  font-weight: 800;
}

.card-subtitle {
  margin-top: 3px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 650;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.card-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  align-items: center;
}

.card-scope {
  margin: 7px 0;
  color: var(--text);
  font-size: 11.5px;
  line-height: 1.35;
  max-height: 48px;
  overflow: hidden;
}

.action-pill {
  display: grid;
  grid-template-columns: 9px minmax(0, auto) minmax(0, 1fr);
  gap: 6px;
  align-items: center;
  margin-bottom: 8px;
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 5px 6px;
  background: #f7fafb;
  color: #385160;
  font-size: 10.5px;
  line-height: 1.2;
}

.action-pill span:last-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.action-pill.running,
.action-pill.queued {
  border-color: rgba(29, 154, 168, 0.4);
  background: #eefafb;
  color: #176f79;
}

.action-pill.completed {
  border-color: rgba(23, 131, 91, 0.28);
  background: #eef8f3;
  color: #17633f;
}

.action-pill.failed {
  border-color: rgba(178, 59, 59, 0.28);
  background: #fff3f2;
  color: #8d2929;
}

.pulse-dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: currentColor;
  opacity: 0.6;
}

.action-pill.running .pulse-dot,
.action-pill.queued .pulse-dot {
  animation: pulseDot 1.2s ease-in-out infinite;
}

@keyframes pulseDot {
  0%, 100% {
    opacity: 0.35;
    transform: scale(0.85);
  }
  50% {
    opacity: 1;
    transform: scale(1.15);
  }
}

.card-fields {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 5px;
  margin-top: 8px;
}

.field-chip {
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 5px 6px;
  background: #fbfcfd;
  color: var(--text);
  font-size: 10.5px;
  line-height: 1.2;
  overflow-wrap: anywhere;
}

.field-chip b {
  display: block;
  color: var(--muted);
  font-size: 9.5px;
  text-transform: uppercase;
  margin-bottom: 2px;
}

.field-chip.missing {
  color: #7d8791;
  background: #f4f6f7;
}

.tag {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  min-height: 20px;
  padding: 2px 6px;
  border-radius: 999px;
  background: #edf3fa;
  color: #24425e;
  font-size: 10.5px;
  font-weight: 700;
}

.move-select {
  margin-top: 8px;
  height: 30px;
  padding: 5px 7px;
  font-size: 12px;
  cursor: default;
  user-select: auto;
}

.sortable-ghost {
  opacity: 0.35;
  background: #dce9f8;
}

.sortable-chosen {
  box-shadow: var(--shadow);
}

.sortable-drag {
  cursor: grabbing;
}

.is-sorting .column-body {
  outline: 1px dashed rgba(45, 108, 223, 0.28);
  outline-offset: -4px;
}

.drawer {
  position: fixed;
  top: 0;
  right: 0;
  width: min(540px, 100vw);
  height: 100vh;
  background: #fff;
  border-left: 1px solid var(--border);
  box-shadow: var(--shadow);
  z-index: 50;
  overflow-y: auto;
  padding: 18px;
}

.hidden {
  display: none;
}

.icon-button {
  position: sticky;
  top: 0;
  float: right;
  width: 34px;
  height: 34px;
  padding: 0;
  display: grid;
  place-items: center;
  font-size: 22px;
}

.drawer h2 {
  font-size: 20px;
  line-height: 1.2;
  padding-right: 42px;
  margin-bottom: 8px;
}

.detail-section {
  margin-top: 15px;
  border-top: 1px solid var(--border);
  padding-top: 14px;
  display: grid;
  gap: 10px;
}

.scope-section p {
  font-size: 14px;
  line-height: 1.45;
  font-weight: 700;
}

.action-panel {
  margin-top: 14px;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px;
  background: #fbfcfd;
  display: grid;
  gap: 6px;
}

.action-panel > div:first-child {
  display: grid;
  gap: 3px;
}

.action-panel span {
  color: var(--muted);
}

.action-panel.running,
.action-panel.queued {
  border-color: rgba(29, 154, 168, 0.42);
  background: #eefafb;
}

.action-panel.completed {
  border-color: rgba(23, 131, 91, 0.32);
  background: #eef8f3;
}

.action-panel.failed {
  border-color: rgba(178, 59, 59, 0.32);
  background: #fff3f2;
}

.field-table {
  display: grid;
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
}

.field-row {
  display: grid;
  grid-template-columns: 150px minmax(0, 1fr);
  gap: 10px;
  padding: 8px 10px;
  background: #fff;
  border-bottom: 1px solid var(--border);
}

.field-row:last-child {
  border-bottom: 0;
}

.field-row span {
  color: var(--muted);
  font-weight: 700;
}

.field-row strong {
  min-width: 0;
  overflow-wrap: anywhere;
}

.field-row.missing strong {
  color: #8a949e;
  font-weight: 650;
}

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

.link-list a {
  color: var(--blue);
  overflow-wrap: anywhere;
}

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

.decision-row .button {
  width: 100%;
}

textarea {
  min-height: 86px;
  resize: vertical;
}

.health-list {
  display: grid;
  gap: 8px;
}

.health-item {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px;
  background: #fff;
}

.action-list {
  display: grid;
  gap: 8px;
}

.action-item {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px;
  background: #fff;
  display: grid;
  gap: 6px;
}

.action-item.running,
.action-item.queued {
  border-color: rgba(29, 154, 168, 0.35);
}

.action-item.completed {
  border-color: rgba(23, 131, 91, 0.3);
}

.action-item.failed {
  border-color: rgba(178, 59, 59, 0.35);
}

.action-item-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
}

.action-request {
  border: 1px solid var(--border);
  border-radius: 5px;
  background: #f7f9fb;
  padding: 8px;
  color: #425466;
  line-height: 1.35;
}

.action-item details,
.action-panel details {
  border-top: 1px solid var(--border);
  padding-top: 6px;
}

.action-item summary,
.action-panel summary {
  cursor: pointer;
  font-weight: 700;
}

.action-item pre,
.action-panel pre {
  max-height: 260px;
  overflow: auto;
  white-space: pre-wrap;
  background: #f7f9fb;
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 8px;
  font-size: 11px;
  line-height: 1.35;
}

.chat-log {
  display: grid;
  gap: 8px;
  max-height: 240px;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px;
  background: #fbfcfd;
}

.chat-message {
  padding: 8px;
  border-radius: 6px;
  background: #fff;
  border: 1px solid var(--border);
}

@media (max-width: 1100px) {
  #app {
    grid-template-columns: 1fr;
  }
  .sidebar {
    position: static;
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }
  .board {
    grid-template-columns: repeat(5, 220px);
    height: auto;
  }
}
