:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-soft: #fbfbfc;
  --text: #15171a;
  --muted: #6a717c;
  --line: #dfe3e8;
  --navy: #172238;
  --gold: #a77a2d;
  --danger: #b42318;
  --ok: #0b7a53;
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--text);
  background: var(--bg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.6;
}

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

img {
  max-width: 100%;
  display: block;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 24px;
  min-height: 64px;
  padding: 0 28px;
  background: rgba(255, 255, 255, 0.96);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(8px);
}

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

.sidebar {
  position: sticky;
  top: 0;
  align-self: start;
  display: flex;
  flex-direction: column;
  gap: 18px;
  min-height: 100vh;
  padding: 22px 16px;
  border-right: 1px solid var(--line);
  background: #ffffff;
}

.brand {
  font-weight: 700;
  letter-spacing: 0;
  color: var(--navy);
  white-space: nowrap;
}

.nav {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
}

.sidebar .nav {
  display: grid;
  align-content: start;
  flex: 1;
}

.nav a,
.account a {
  padding: 8px 10px;
  border-radius: 6px;
  color: var(--muted);
  font-size: 14px;
}

.nav a.active,
.nav a:hover,
.account a:hover {
  color: var(--text);
  background: #eef1f5;
}

.account {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  color: var(--muted);
}

.sidebar .account {
  display: grid;
  align-items: stretch;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.page {
  width: min(1440px, 100%);
  margin: 0 auto;
  padding: 28px;
}

.app-shell .page {
  width: 100%;
}

h1,
h2,
h3 {
  margin: 0;
  line-height: 1.25;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(28px, 4vw, 42px);
}

h2 {
  font-size: 20px;
}

h3 {
  font-size: 16px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--gold);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

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

.page-head,
.section-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 18px;
  margin-bottom: 22px;
}

.head-actions,
.button-row,
.export-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.wrap {
  flex-wrap: wrap;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  padding: 8px 14px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 14px;
  cursor: pointer;
  white-space: nowrap;
}

.button:hover {
  border-color: #b8c0ca;
  background: #f9fafb;
}

.button.primary {
  border-color: var(--navy);
  background: var(--navy);
  color: white;
}

.button.danger {
  border-color: #f2c7c2;
  color: var(--danger);
}

.button.small {
  min-height: 32px;
  padding: 5px 10px;
  font-size: 13px;
}

.flash,
.alert {
  margin-bottom: 18px;
  padding: 12px 14px;
  border-radius: var(--radius);
  white-space: pre-wrap;
}

.flash.success {
  color: var(--ok);
  background: #eaf7f1;
  border: 1px solid #b9e5d4;
}

.flash.error,
.alert {
  color: var(--danger);
  background: #fff0ef;
  border: 1px solid #f1c1bc;
}

.flash.notice {
  color: #7b5318;
  background: #fff7e8;
  border: 1px solid #efd3a7;
}

.progress-overlay {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(246, 247, 249, 0.82);
  backdrop-filter: blur(4px);
}

.progress-overlay[hidden] {
  display: none;
}

.progress-box {
  width: min(420px, 100%);
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: white;
  box-shadow: 0 14px 36px rgba(23, 34, 56, 0.14);
}

.progress-track {
  overflow: hidden;
  height: 10px;
  margin: 14px 0 8px;
  border-radius: 999px;
  background: #e8edf3;
}

.progress-track span {
  display: block;
  width: 18%;
  height: 100%;
  border-radius: inherit;
  background: var(--gold);
  animation: progress-slide 1.1s ease-in-out infinite;
}

@keyframes progress-slide {
  0% {
    transform: translateX(-120%);
  }
  100% {
    transform: translateX(560%);
  }
}

.card,
.section,
.panel,
.metric,
.image-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.auth-panel {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 420px);
  gap: 40px;
  align-items: center;
  min-height: calc(100vh - 150px);
}

.form-card {
  padding: 22px;
}

label {
  display: grid;
  gap: 6px;
  color: #2d333b;
  font-size: 14px;
  font-weight: 600;
}

label b {
  color: var(--danger);
  font-size: 12px;
}

input,
select,
textarea {
  width: 100%;
  min-height: 40px;
  border: 1px solid #cfd6df;
  border-radius: 6px;
  padding: 9px 10px;
  background: white;
  color: var(--text);
  font: inherit;
  letter-spacing: 0;
}

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

input:focus,
select:focus,
textarea:focus {
  outline: 2px solid rgba(23, 34, 56, 0.2);
  border-color: var(--navy);
}

.filters {
  display: grid;
  grid-template-columns: repeat(9, minmax(120px, 1fr));
  gap: 10px;
  margin-bottom: 18px;
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: white;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 900px;
}

th,
td {
  padding: 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
  font-size: 14px;
}

th {
  background: #f1f3f6;
  color: #394150;
  font-size: 12px;
  text-transform: uppercase;
}

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

.empty {
  padding: 24px;
  color: var(--muted);
  text-align: center;
}

.tag,
.tag-list span {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 2px 8px;
  border-radius: 999px;
  background: #eef1f5;
  color: #394150;
  font-size: 12px;
  font-weight: 600;
}

.tag.selected {
  background: #f8ecd7;
  color: #7b5318;
}

.stepper {
  display: grid;
  grid-template-columns: repeat(7, minmax(110px, 1fr));
  gap: 8px;
  margin-bottom: 16px;
}

.stepper span {
  min-height: 36px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f9fafb;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}

.section {
  margin-bottom: 16px;
  padding: 0;
}

.section.static {
  padding: 20px;
}

details.section > summary {
  padding: 16px 18px;
  font-weight: 700;
  cursor: pointer;
}

details.section > .form-grid,
details.section > .part-grid,
details.section > .reference-list,
details.section > .muted,
details.section > .custom-parts {
  margin: 0 18px 18px;
}

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

.form-grid.wide label:nth-child(1),
.form-grid.wide label:nth-child(7),
.form-grid.wide label:nth-child(10),
.form-grid.wide label:nth-child(15),
.form-grid.wide label:nth-child(18),
.form-grid.wide label:nth-child(19),
.form-grid.wide label:nth-child(20),
.form-grid.wide label:nth-child(21) {
  grid-column: span 3;
}

.form-grid.compact {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin: 12px 0;
}

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

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

.switch-row,
.checkline {
  display: flex;
  grid-template-columns: none;
  align-items: center;
  gap: 8px;
}

.switch-row input,
.checkline input,
.checkbox-grid input,
.quality input {
  width: auto;
  min-height: auto;
}

.part-detail {
  display: none;
  margin-top: 12px;
}

.part-detail.open {
  display: block;
}

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

.checkbox-grid label,
.quality label {
  display: flex;
  gap: 8px;
  align-items: center;
  font-weight: 500;
}

.custom-parts {
  padding: 16px;
}

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

.custom-row textarea {
  grid-column: span 2;
  min-height: 70px;
}

.submit-bar {
  position: sticky;
  bottom: 0;
  display: flex;
  justify-content: flex-end;
  padding: 14px 0;
  background: var(--bg);
}

.reference-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.reference-list a {
  padding: 6px 10px;
  border-radius: 6px;
  background: #eef1f5;
  font-size: 13px;
}

.reference-list.detail {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin-top: 12px;
}

.reference-list.detail article {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-soft);
}

.reference-list.detail p,
.subhead {
  margin-top: 14px;
}

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

.metric {
  padding: 16px;
}

.metric span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.metric strong {
  display: block;
  margin-top: 6px;
  font-size: 22px;
}

.workbench,
.edit-layout,
.admin-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  margin-bottom: 16px;
}

.admin-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.panel {
  padding: 18px;
}

.base-preview {
  width: min(100%, 420px);
  max-height: 560px;
  object-fit: contain;
  margin: 14px 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #f1f3f6;
}

.prompt-box {
  overflow: auto;
  max-height: 280px;
  padding: 12px;
  border-radius: 6px;
  background: #111827;
  color: #e5e7eb;
  font-size: 12px;
  line-height: 1.55;
  white-space: pre-wrap;
}

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

.plan-list label {
  display: grid;
  grid-template-columns: auto 160px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-soft);
  font-weight: 500;
}

.plan-list input {
  width: auto;
  min-height: auto;
}

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

.info-grid div {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-soft);
}

.info-grid span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.info-grid p {
  margin: 5px 0 0;
}

.export-actions {
  flex-wrap: wrap;
}

.image-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
}

.image-card {
  overflow: hidden;
}

.image-open {
  width: 100%;
  padding: 0;
  border: 0;
  background: #eef1f5;
  cursor: zoom-in;
}

.image-open img {
  width: 100%;
  aspect-ratio: 2 / 3;
  object-fit: cover;
}

.image-card-body {
  display: grid;
  gap: 10px;
  padding: 14px;
}

.image-title {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: center;
}

.tag-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.estimate-box,
.change-scope,
.quality-summary {
  display: grid;
  gap: 4px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-soft);
}

.estimate-box span,
.quality-summary span,
.quality-summary small {
  color: var(--muted);
  font-size: 13px;
}

.quality-summary.warning {
  border-color: #efd3a7;
  background: #fff8ed;
}

.quality-summary.failed {
  border-color: #f1c1bc;
  background: #fff0ef;
}

.preset-help {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  margin-bottom: 10px;
}

.preset-help span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.preset-chip {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: white;
  padding: 4px 9px;
  color: var(--text);
  font: inherit;
  font-size: 12px;
  cursor: pointer;
}

.status-form,
.comment-form {
  display: grid;
  gap: 8px;
}

.compare-slider {
  position: relative;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #eef1f5;
}

.compare-slider img {
  width: 100%;
  aspect-ratio: 2 / 3;
  object-fit: cover;
}

.compare-after {
  position: absolute;
  inset: 0;
}

.compare-slider input[type="range"] {
  position: absolute;
  left: 10px;
  right: 10px;
  bottom: 10px;
  width: calc(100% - 20px);
}

.template-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
  margin-bottom: 16px;
}

.template-card {
  display: grid;
  gap: 10px;
  padding: 16px;
}

.comment-list {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

.comment-list article {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-soft);
}

.comment-list span {
  margin-left: 8px;
  color: var(--muted);
  font-size: 12px;
}

.quality form {
  display: grid;
  gap: 8px;
  margin-top: 8px;
}

.preview-pane {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: white;
  padding: 12px;
}

.preview-pane img {
  max-height: 760px;
  margin: 0 auto;
  object-fit: contain;
}

.narrow {
  max-width: 620px;
  margin: 0 auto;
}

dialog {
  max-width: min(94vw, 980px);
  max-height: 94vh;
  padding: 0;
  border: 0;
  border-radius: var(--radius);
  background: transparent;
}

dialog::backdrop {
  background: rgba(0, 0, 0, 0.72);
}

dialog img {
  max-width: 94vw;
  max-height: 90vh;
  object-fit: contain;
  border-radius: var(--radius);
  background: white;
}

.modal-close {
  position: absolute;
  top: -14px;
  right: -14px;
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 50%;
  background: white;
  font-size: 24px;
  cursor: pointer;
}

@media (max-width: 1100px) {
  .filters,
  .form-grid,
  .part-grid,
  .summary-grid,
  .workbench,
  .edit-layout,
  .admin-grid,
  .image-grid,
  .template-grid,
  .info-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .form-grid.wide label:nth-child(n) {
    grid-column: span 2;
  }

  .stepper {
    grid-template-columns: repeat(4, minmax(110px, 1fr));
  }
}

@media (max-width: 760px) {
  .app-shell {
    display: block;
  }

  .sidebar {
    position: static;
    min-height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .topbar {
    position: static;
    flex-wrap: wrap;
    padding: 14px;
  }

  .nav,
  .account {
    width: 100%;
    flex-wrap: wrap;
  }

  .page {
    padding: 16px;
  }

  .auth-panel,
  .filters,
  .form-grid,
  .form-grid.compact,
  .part-grid,
  .summary-grid,
  .workbench,
  .edit-layout,
  .admin-grid,
  .image-grid,
  .template-grid,
  .info-grid,
  .custom-row {
    grid-template-columns: 1fr;
  }

  .form-grid.wide label:nth-child(n),
  .custom-row textarea {
    grid-column: span 1;
  }

  .page-head,
  .section-head {
    display: grid;
  }

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

  .plan-list label {
    grid-template-columns: auto 1fr;
  }

  .plan-list small {
    grid-column: 2;
  }
}
