:root {
  --bg: #f4f1ea;
  --surface: #fffdf7;
  --surface-2: #fcf7ea;
  --ink: #23201c;
  --muted: #766d5f;
  --line: #ddd2bf;
  --walnut: #6c3f25;
  --brass: #bd8a3a;
  --charcoal: #242524;
  --sage: #5f7b70;
  --blue: #3f657c;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

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

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

.app-shell {
  min-height: 100vh;
  padding: 18px;
}

.hero,
.panel {
  max-width: 1360px;
  margin: 0 auto 14px;
  border: 1px solid var(--line);
  background: var(--surface);
  box-shadow: 0 16px 36px rgba(54, 39, 24, 0.08);
}

.hero {
  display: grid;
  grid-template-columns: 68px 1fr;
  gap: 14px;
  align-items: center;
  background: var(--charcoal);
  color: #fffaf0;
  padding: 14px 16px;
}

.app-icon {
  width: 68px;
  height: 68px;
  border-radius: 16px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--brass);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

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

h1 {
  margin-bottom: 0;
  font-size: 36px;
  line-height: 1;
}

h2 {
  margin-bottom: 0;
  font-size: 22px;
}

h3 {
  margin-bottom: 12px;
  font-size: 17px;
}

.sync-panel {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 520px);
  gap: 12px;
  align-items: center;
  max-width: 1360px;
  margin: 0 auto 14px;
  border: 1px solid var(--line);
  background: var(--surface);
  padding: 13px 16px;
}

.sync-panel strong,
.sync-panel span {
  display: block;
}

.sync-panel span {
  margin-top: 4px;
  color: var(--muted);
  line-height: 1.35;
}

.sync-controls {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 8px;
}

.sync-controls button {
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffefa;
  color: var(--ink);
  padding: 0 12px;
  font-weight: 900;
}

.sync-panel.has-sync-code .sync-controls {
  grid-template-columns: minmax(140px, 220px);
  justify-content: end;
}

.sync-panel.has-sync-code #sync-now {
  border-color: var(--walnut);
  background: var(--walnut);
  color: #fffaf0;
}

.sync-panel.connected {
  border-color: var(--sage);
  background: rgba(95, 123, 112, 0.12);
}

.sync-panel.error {
  border-color: #8e463c;
  background: rgba(142, 70, 60, 0.1);
}

.grid {
  display: grid;
  grid-template-columns: minmax(280px, 360px) minmax(300px, 1fr);
  gap: 14px;
  max-width: 1360px;
  margin: 0 auto;
}

.panel {
  margin: 0;
  padding: 16px;
}

.wide {
  grid-column: 1 / -1;
}

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

.intake-heading {
  align-items: center;
  margin-bottom: 0;
}

.intake:not(.intake-collapsed) .intake-heading {
  margin-bottom: 14px;
}

.intake-collapsed .intake-body {
  display: none;
}

.panel-help {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.split {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.transfer-actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-top: 10px;
}

.utility-drawer {
  margin-top: 14px;
  border-top: 1px solid var(--line);
  padding-top: 12px;
}

.utility-drawer summary {
  color: var(--muted);
  cursor: pointer;
  font-size: 13px;
  font-weight: 900;
}

.import-button {
  display: grid;
  place-items: center;
  text-align: center;
}

.import-button input {
  display: none;
}

label {
  display: grid;
  gap: 7px;
  margin-bottom: 13px;
  color: var(--ink);
  font-size: 13px;
  font-weight: 800;
}

input,
select,
textarea {
  width: 100%;
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffefa;
  color: var(--ink);
  padding: 11px 12px;
  outline: none;
  font-size: 16px;
}

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

input:focus,
select:focus,
textarea:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(63, 101, 124, 0.16);
}

input.user-filled,
select.user-filled,
textarea.user-filled {
  border-color: rgba(95, 123, 112, 0.65);
  background: rgba(95, 123, 112, 0.1);
  color: #2f5f49;
  font-weight: 800;
}

input.user-filled:focus,
select.user-filled:focus,
textarea.user-filled:focus {
  border-color: var(--sage);
  box-shadow: 0 0 0 3px rgba(95, 123, 112, 0.18);
}

.field-group {
  margin: 16px 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
  padding: 14px;
}

.field-group label:last-child {
  margin-bottom: 0;
}

.upload-box {
  border: 1px dashed var(--brass);
  border-radius: 8px;
  background: var(--surface-2);
  padding: 12px;
}

.upload-box input {
  min-height: auto;
  border: 0;
  padding: 0;
  background: transparent;
}

.upload-box span {
  color: var(--muted);
  font-weight: 600;
}

.reference-photo {
  border-color: var(--blue);
  background: #eef5f6;
}

.staged-photos {
  margin: -2px 0 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffefa;
  padding: 10px;
}

.staged-photos-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.staged-photos-header button {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--ink);
  padding: 0 10px;
  font-size: 12px;
  font-weight: 900;
}

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

.staged-photo-grid:empty {
  display: none;
}

.staged-card figcaption {
  font-size: 11px;
}

.check-row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  margin-top: -4px;
  color: var(--muted);
  font-weight: 700;
}

.check-row input {
  width: 20px;
  min-height: 20px;
  height: 20px;
  margin: 0;
  flex: 0 0 auto;
}

.primary-button,
.secondary-button {
  min-height: 48px;
  border-radius: 8px;
  font-weight: 900;
  cursor: pointer;
}

.primary-button {
  width: 100%;
  border: 0;
  background: var(--walnut);
  color: #fffaf0;
}

.secondary-button {
  border: 1px solid var(--line);
  background: #fffefa;
  color: var(--ink);
  padding: 0 12px;
}

.project-list,
.component-list,
.photo-grid {
  display: grid;
  gap: 10px;
}

.project-button {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffefa;
  padding: 12px;
  text-align: left;
  cursor: pointer;
}

.project-button.active {
  border-color: var(--blue);
  background: #eef5f6;
}

.project-button.active.needs-info {
  border-color: var(--brass);
  background: #fff7df;
}

.project-button.active.ready {
  border-color: var(--sage);
  background: rgba(95, 123, 112, 0.12);
}

.project-button strong,
.project-button span {
  display: block;
}

.project-button span,
.muted,
.photo-card figcaption {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.status-pill {
  display: inline-block;
  margin: 6px 6px 0 0;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  padding: 4px 8px;
  font-size: 11px;
  font-weight: 900;
  line-height: 1;
}

.status-pill.active {
  background: rgba(63, 101, 124, 0.14);
  color: var(--blue);
}

.status-pill.needs-info {
  background: rgba(189, 138, 58, 0.2);
  color: #7b4d15;
}

.status-pill.ready {
  background: rgba(95, 123, 112, 0.16);
  color: var(--sage);
}

.detail-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
  padding: 13px;
}

.project-editor label:last-of-type {
  margin-bottom: 0;
}

.project-photo-adder,
.research-editor {
  margin-top: 12px;
}

.project-photo-adder .upload-box {
  margin-bottom: 8px;
}

.research-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.research-heading h3 {
  margin-bottom: 0;
}

.workflow-action {
  display: grid;
  gap: 12px;
  margin-bottom: 12px;
  border: 2px solid var(--line);
  border-radius: 8px;
  background: #fffefa;
  padding: 12px;
}

.workflow-action h4 {
  margin: 0 0 6px;
  font-size: 18px;
}

.workflow-action p {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
}

.workflow-action.active {
  border-color: var(--blue);
  background: #eef5f6;
}

.workflow-action.needs-info {
  border-color: var(--brass);
  background: #fff7df;
}

.workflow-action.ready {
  border-color: var(--sage);
  background: rgba(95, 123, 112, 0.12);
}

.workflow-progress {
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  border: 1px solid rgba(63, 101, 124, 0.3);
  border-radius: 8px;
  background: #fffefa;
  padding: 10px;
}

.workflow-progress strong,
.workflow-progress small {
  display: block;
}

.workflow-progress small {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.3;
}

.progress-spinner {
  width: 24px;
  height: 24px;
  border: 3px solid rgba(63, 101, 124, 0.22);
  border-top-color: var(--blue);
  border-radius: 999px;
  animation: spin 0.85s linear infinite;
}

.workflow-progress.queued .progress-spinner {
  animation: pulse-ring 1.5s ease-in-out infinite;
}

.progress-track {
  display: block;
  grid-column: 1 / -1;
  height: 6px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(63, 101, 124, 0.14);
}

.progress-track i {
  display: block;
  width: 34%;
  height: 100%;
  border-radius: inherit;
  background: var(--blue);
  animation: progress-sweep 1.35s ease-in-out infinite;
}

.workflow-progress.queued .progress-track i {
  width: 18%;
  background: var(--brass);
  animation-duration: 1.9s;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@keyframes pulse-ring {
  0%,
  100% {
    transform: scale(0.92);
    opacity: 0.72;
  }
  50% {
    transform: scale(1);
    opacity: 1;
  }
}

@keyframes progress-sweep {
  0% {
    transform: translateX(-110%);
  }
  100% {
    transform: translateX(260%);
  }
}

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

.workflow-action-buttons .primary-button,
.workflow-action-buttons .secondary-button {
  width: 100%;
}

.turn-board {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}

.turn-board div {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffefa;
  padding: 10px;
}

.turn-board span,
.workflow-steps li small {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
  line-height: 1.2;
  text-transform: uppercase;
}

.turn-board strong {
  display: block;
  margin-top: 5px;
  color: var(--ink);
  font-size: 14px;
  line-height: 1.25;
}

.turn-board.active div {
  border-color: rgba(63, 101, 124, 0.35);
  background: #eef5f6;
}

.turn-board.needs-info div {
  border-color: rgba(189, 138, 58, 0.5);
  background: #fff7df;
}

.turn-board.needs-info div:nth-child(2) {
  border-color: var(--brass);
  box-shadow: inset 4px 0 0 var(--brass);
}

.turn-board.ready div {
  border-color: rgba(95, 123, 112, 0.45);
  background: rgba(95, 123, 112, 0.12);
}

.workflow-overview {
  display: grid;
  gap: 12px;
  margin-bottom: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #eef5f6;
  padding: 12px;
}

.workflow-overview strong,
.workflow-overview span {
  display: block;
}

.workflow-overview span {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.workflow-steps {
  display: grid;
  gap: 7px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.workflow-steps li {
  display: grid;
  grid-template-columns: 60px minmax(0, 1fr);
  gap: 8px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffefa;
  padding: 8px;
}

.workflow-steps li span {
  display: inline-grid;
  place-items: center;
  min-height: 26px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
}

.workflow-steps li strong {
  font-size: 13px;
  line-height: 1.25;
}

.workflow-steps li small {
  grid-column: 2;
  margin-top: -3px;
  text-transform: none;
}

.workflow-steps li.current {
  border-color: var(--blue);
  background: #eef5f6;
  box-shadow: inset 5px 0 0 var(--blue);
}

.workflow-steps li.current span {
  background: rgba(63, 101, 124, 0.16);
  color: var(--blue);
}

.workflow-action.needs-info + .turn-board + .workflow-overview .workflow-steps li.current {
  border-color: var(--brass);
  background: #fff7df;
  box-shadow: inset 5px 0 0 var(--brass);
}

.workflow-action.needs-info + .turn-board + .workflow-overview .workflow-steps li.current span {
  background: rgba(189, 138, 58, 0.2);
  color: #7b4d15;
}

.workflow-steps li.complete {
  border-color: rgba(95, 123, 112, 0.5);
}

.workflow-steps li.complete span {
  background: rgba(95, 123, 112, 0.16);
  color: var(--sage);
}

.workflow-steps li.waiting {
  opacity: 0.72;
}

.compact-button {
  min-height: 40px;
  flex: 0 0 auto;
  width: auto;
  padding: 0 12px;
}

.caution-button {
  color: #8e463c;
}

.research-editor textarea {
  min-height: 150px;
}

.research-sections {
  display: grid;
  gap: 8px;
}

.research-section {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffefa;
  overflow: hidden;
}

.research-section summary {
  display: grid;
  gap: 5px;
  cursor: pointer;
  list-style: none;
  padding: 10px 12px;
}

.research-section summary::-webkit-details-marker {
  display: none;
}

.research-section summary span {
  font-size: 13px;
  font-weight: 900;
}

.research-section summary small {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  line-height: 1.35;
}

.research-section[open] summary {
  border-bottom: 1px solid var(--line);
  background: var(--surface-2);
}

.research-section.current-section {
  border-color: var(--blue);
  box-shadow: inset 5px 0 0 var(--blue);
}

.workflow-action.needs-info ~ .research-sections .research-section.current-section {
  border-color: var(--brass);
  box-shadow: inset 5px 0 0 var(--brass);
}

.research-section label {
  margin: 0;
  padding: 10px;
}

.research-section textarea {
  min-height: 140px;
}

.seller-answer {
  border-top: 1px solid var(--line);
  background: #fff7df;
}

.seller-answer span {
  color: #7b4d15;
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

.pricing-rule {
  display: grid;
  gap: 5px;
  margin: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
}

.pricing-rule strong,
.pricing-rule span {
  display: block;
}

.pricing-rule span {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.pricing-rule.needs-evidence {
  border-color: var(--brass);
  background: #fff7df;
}

.pricing-rule.ready {
  border-color: rgba(95, 123, 112, 0.45);
  background: rgba(95, 123, 112, 0.12);
}

.research-section:nth-of-type(5) textarea {
  min-height: 74px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
}

.edit-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.project-check {
  margin-top: 0;
}

.photo-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin-top: 12px;
}

.photo-count {
  grid-column: 1 / -1;
  color: var(--muted);
  font-size: 13px;
  font-weight: 900;
}

.photo-card {
  margin: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: #fffefa;
}

.photo-card img {
  display: block;
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
}

.photo-card figcaption {
  padding: 8px;
}

.component-list {
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
}

.component-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 14px;
}

.component-more {
  margin-top: 10px;
  border-top: 1px solid var(--line);
  padding-top: 10px;
}

.component-more summary {
  color: var(--blue);
  cursor: pointer;
  font-size: 13px;
  font-weight: 900;
}

.component-more label:first-of-type {
  margin-top: 12px;
}

.component-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 14px;
}

.type {
  border-radius: 999px;
  background: rgba(95, 123, 112, 0.16);
  color: var(--sage);
  padding: 5px 9px;
  font-size: 12px;
  font-weight: 900;
}

.price-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

@media (min-width: 980px) {
  .grid {
    grid-template-columns: minmax(0, 1fr);
    align-items: start;
  }

  .workspace-create {
    grid-column: 1;
    grid-row: 2;
  }

  .workspace-create.intake-collapsed {
    padding: 14px 16px;
  }

  .workspace-create .intake-body {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px 14px;
  }

  .workspace-create.intake-collapsed .intake-body {
    display: none;
  }

  .workspace-create .field-group,
  .workspace-create .upload-box,
  .workspace-create .staged-photos,
  .workspace-create .check-row,
  .workspace-create .primary-button {
    grid-column: span 3;
  }

  .project-browser {
    grid-column: 1;
    grid-row: 1;
  }

  .project-browser .panel-heading {
    margin-bottom: 12px;
  }

  .project-list {
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  }

  .utility-drawer {
    margin-top: 10px;
  }

  .selected-workspace {
    display: grid;
    grid-column: 1;
    grid-row: 3;
    grid-template-columns: minmax(0, 1.35fr) minmax(390px, 0.8fr);
    gap: 16px;
    align-items: start;
    min-height: 620px;
  }

  .selected-workspace .panel-heading {
    grid-column: 1 / -1;
    margin-bottom: 0;
  }

  #selected-detail {
    display: grid;
    grid-column: 1;
    grid-template-columns: minmax(300px, 0.9fr) minmax(260px, 0.7fr);
    gap: 12px;
  }

  .project-photo-adder,
  .research-editor {
    margin-top: 0;
  }

  #photo-grid {
    grid-column: 1;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    align-content: start;
    max-height: 650px;
    overflow: auto;
    padding-right: 4px;
    margin-top: 0;
  }

  #research-detail {
    grid-column: 2;
    grid-row: 2 / span 2;
  }

  .research-editor {
    position: sticky;
    top: 12px;
  }

  .component-list {
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  }

  .component-card label {
    margin-bottom: 10px;
  }
}

@media (max-width: 780px) {
  .app-shell {
    padding: 10px;
  }

  .hero {
    grid-template-columns: 70px 1fr;
    padding: 14px;
  }

  .app-icon {
    width: 70px;
    height: 70px;
    border-radius: 17px;
  }

  h1 {
    font-size: 30px;
  }

  .grid,
  .sync-panel,
  .sync-controls,
  .transfer-actions,
  .price-row,
  .photo-grid,
  .staged-photo-grid,
  .edit-grid,
  .turn-board,
  .research-heading {
    grid-template-columns: 1fr;
  }

  .research-heading {
    display: grid;
  }

  #research-detail,
  .component-workspace {
    display: none;
  }

  .upload-box {
    border-width: 2px;
    padding: 14px;
    font-size: 15px;
  }

  .upload-box input[type="file"] {
    display: block;
    width: 100%;
    margin: 8px 0 6px;
    font-size: 15px;
  }

  .upload-box input[type="file"]::file-selector-button {
    min-height: 52px;
    margin-right: 10px;
    border: 0;
    border-radius: 8px;
    background: var(--walnut);
    color: #fffaf0;
    padding: 0 16px;
    font-weight: 900;
  }

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