:root {
  color-scheme: light;
  --bg: #ffffff;
  --surface: #ffffff;
  --soft-surface: #f2f3f5;
  --line: #dde1e5;
  --text: #2f3438;
  --muted: #767d84;
  --accent: #111111;
  --grid-gap: 18px;
  --left-rail: 320px;
  --right-rail: 360px;
  --micro-panel: 240px;
  --preview-width: 760px;
  --preview-height: 428px;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  font-size: 16px;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: "Barlow", "DIN Alternate", "Helvetica Neue", Arial, sans-serif;
  font-variant-numeric: tabular-nums;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

.page-shell {
  width: min(1680px, calc(100% - 22px));
  margin: 0 auto;
  padding: 8px 0 22px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: grid;
  gap: 8px;
  padding: 6px 0 10px;
  background: #fff;
}

.topbar-copy {
  display: grid;
  gap: 3px;
}

.topbar h1,
.panel-head h2,
.rule-list h3 {
  margin: 0;
  font-family: "Barlow", "DIN Alternate", "Helvetica Neue", Arial, sans-serif;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.topbar h1 {
  font-size: clamp(1.2rem, 1.8vw, 1.75rem);
  line-height: 1;
}

.topbar-lede,
.topbar-note,
.status-text,
.legend-row p,
.mini-note,
.insight-list,
.detection-list,
.rule-list p {
  margin: 0;
}

.topbar-lede {
  font-size: 0.82rem;
}

.topbar-note {
  font-size: 0.66rem;
  color: var(--muted);
}

.workspace-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) var(--right-rail);
  gap: var(--grid-gap);
  align-items: start;
}

.workspace-main {
  display: grid;
  gap: var(--grid-gap);
  align-content: start;
  min-width: 0;
}

.dashboard {
  display: grid;
  grid-template-columns: var(--left-rail) minmax(0, 1fr);
  gap: var(--grid-gap);
  align-items: start;
}

.left-rail-stack {
  display: grid;
  gap: var(--grid-gap);
  align-content: start;
}

.main-column-stack {
  display: grid;
  gap: var(--grid-gap);
  align-content: start;
  min-width: 0;
}

.control-panel,
.preview-panel,
.score-panel,
.checklist-panel,
.insight-card {
  display: grid;
  gap: 12px;
  align-content: start;
  padding: 14px;
  background: var(--soft-surface);
  min-width: 0;
}

.panel-head,
.subhead-row {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 10px;
}

.panel-head {
  margin-bottom: 12px;
}

.panel-kicker,
.mini-kicker {
  margin: 0;
  font-size: 0.56rem;
  line-height: 1;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}

.panel-head h2 {
  font-size: 0.92rem;
  line-height: 1;
}

.upload-dropzone {
  display: grid;
  gap: 8px;
  padding: 18px 16px;
  background: #fff;
}

.file-input {
  width: 100%;
}

.upload-copy {
  display: grid;
  gap: 2px;
  font-size: 0.72rem;
}

.upload-copy strong {
  font-size: 0.82rem;
}

.button-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 10px;
}

.action-button,
.ghost-button {
  min-height: 38px;
  padding: 0 12px;
  border: 0;
  border-radius: 0;
}

.action-button {
  background: #111111;
  color: #fff;
}

.action-button:disabled {
  background: #9aa1a8;
  cursor: default;
}

.ghost-button {
  background: #fff;
  color: var(--text);
}

.status-text {
  min-height: 32px;
  margin-top: 10px;
  font-size: 0.68rem;
  color: var(--muted);
}

.preview-stage {
  position: relative;
  width: min(100%, var(--preview-width));
  aspect-ratio: 16 / 9;
  background: #fff;
  overflow: hidden;
}

.image-canvas,
.overlay-layer {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.image-canvas {
  display: block;
}

.overlay-layer {
  pointer-events: none;
}

.overlay-box {
  position: absolute;
  border: 1px solid rgba(255, 255, 255, 0.92);
  box-shadow: inset 0 0 0 1px rgba(17, 17, 17, 0.4);
}

.overlay-box span {
  position: absolute;
  top: 0;
  left: 0;
  padding: 2px 4px;
  background: rgba(255, 255, 255, 0.9);
  color: #111111;
  font-size: 0.52rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.overlay-focus {
  position: absolute;
  width: 24px;
  height: 24px;
  margin: -12px 0 0 -12px;
  border: 1px solid rgba(255, 255, 255, 0.95);
  transform: rotate(45deg);
}

.empty-state {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 0.76rem;
}

.total-score-card {
  display: grid;
  gap: 4px;
  padding: 12px 14px;
  background: #fff;
}

.score-summary {
  display: flex;
  align-items: end;
  justify-content: flex-start;
  gap: 12px;
}

.total-score-label,
.score-chip-label,
.breakdown-card p,
.palette-chip-code,
.detection-list dt,
.detection-list dd,
.rule-list article,
.mini-note {
  margin: 0;
}

.total-score-label {
  font-size: 0.62rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}

.total-score-value {
  margin: 0;
  font-size: clamp(2.5rem, 4vw, 4.1rem);
  line-height: 0.9;
  letter-spacing: -0.05em;
  font-weight: 700;
}

.total-score-value.is-critical {
  color: #c62828;
}

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

.breakdown-card {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: end;
  padding: 10px 12px;
  background: #fff;
}

.breakdown-card strong {
  font-size: 0.74rem;
  line-height: 1;
}

.breakdown-card p {
  font-size: 0.64rem;
  color: var(--muted);
}

.breakdown-card span {
  font-size: 1.34rem;
  line-height: 0.9;
  font-weight: 700;
}

.palette-panel {
  display: grid;
  gap: 10px;
  margin-top: 0;
  padding: 10px 12px;
  background: #fff;
}

.palette-panel-head {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 12px;
}

.palette-hint {
  margin: 0;
  font-size: 0.66rem;
  line-height: 1.4;
  color: var(--muted);
  text-align: right;
}

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

.palette-chip {
  display: grid;
  grid-template-columns: 36px minmax(0, 1fr);
  gap: 8px;
  align-items: center;
}

.palette-chip-color {
  min-height: 24px;
  background: var(--chip-color);
}

.palette-chip-code {
  font-size: 0.56rem;
  line-height: 1.2;
  color: var(--muted);
  text-transform: uppercase;
  word-break: break-all;
}

.checklist-panel {
  position: sticky;
  top: 72px;
  max-height: calc(100vh - 92px);
  overflow: auto;
}

.analysis-section {
  margin-top: 0;
}

.analysis-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, var(--micro-panel));
  gap: var(--grid-gap);
  align-items: start;
}

.suggestion-panel {
  min-height: 174px;
}

.detection-panel {
  min-height: 174px;
}

.insight-list {
  display: grid;
  gap: 10px;
  padding-left: 16px;
  font-size: 0.72rem;
  line-height: 1.5;
}

.detection-list {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 8px 12px;
  align-content: start;
}

.detection-list dt {
  font-size: 0.62rem;
  color: var(--muted);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.detection-list dd {
  font-size: 0.72rem;
}

.rule-list {
  display: grid;
  gap: 12px;
}

.rule-group {
  display: grid;
  gap: 8px;
  padding: 10px 12px;
  background: #fff;
}

.rule-group-head {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 12px;
}

.rule-list h3 {
  font-size: 0.8rem;
  line-height: 1;
}

.rule-group-count {
  font-size: 0.58rem;
  line-height: 1;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.rule-check-items {
  display: grid;
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.rule-check-items li {
  margin: 0;
}

.rule-check {
  display: grid;
  grid-template-columns: 16px 1fr;
  gap: 10px;
  align-items: start;
}

.rule-check-input {
  width: 16px;
  height: 16px;
  margin: 2px 0 0;
  accent-color: var(--accent);
}

.rule-check-text {
  font-size: 0.67rem;
  line-height: 1.45;
  color: var(--text);
}

.rule-check-input:checked + .rule-check-text {
  font-weight: 600;
}

.evidence-panel {
  display: grid;
  gap: 10px;
  padding: 12px;
  background: #fff;
}

.evidence-copy {
  display: grid;
  gap: 4px;
}

.evidence-actions {
  display: grid;
  gap: 8px;
}

.evidence-button {
  width: 100%;
}

.share-button {
  border: 1px solid var(--line);
}

.share-status {
  line-height: 1.45;
}

.alert-list {
  display: grid;
  gap: 4px;
  margin-top: 8px;
}

.alert-item {
  display: grid;
  grid-template-columns: 18px 1fr;
  gap: 6px;
  align-items: start;
  padding: 6px 10px;
  border-left: 2px solid #d97706;
  background: #fffbf0;
  font-size: 0.68rem;
  line-height: 1.4;
}

.alert-item.is-danger {
  border-left-color: #c62828;
  background: #fff1f1;
  color: #7f1d1d;
}

.alert-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 14px;
  height: 14px;
  margin-top: 1px;
  background: #d97706;
  color: #fff;
  font-size: 0.54rem;
  font-weight: 700;
  line-height: 1;
  flex-shrink: 0;
}

.alert-item.is-danger .alert-icon {
  background: #c62828;
}

.suggestion-chip {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 5px;
  background: var(--soft-surface);
  font-size: 0.58rem;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: 0.04em;
  vertical-align: middle;
  white-space: nowrap;
}

.action-button:focus-visible,
.ghost-button:focus-visible,
.file-input:focus-visible,
.rule-check-input:focus-visible {
  outline: 2px solid #9aa1a8;
  outline-offset: 2px;
}

/* ── Tab nav ── */
.tab-nav {
  display: flex;
  align-items: flex-end;
  gap: 0;
}

.tab-btn {
  padding: 0 28px 10px 0;
  background: none;
  border: 0;
  font-family: "Barlow", "DIN Alternate", "Helvetica Neue", Arial, sans-serif;
  font-size: clamp(1.2rem, 1.8vw, 1.75rem);
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1;
  color: var(--muted);
  white-space: nowrap;
  transition: color 0.12s;
}

.tab-btn.is-active {
  color: var(--text);
}

.tab-btn:hover:not(.is-active) {
  color: #555;
}

/* ── Check view ── */
.check-view {
  height: calc(100vh - 58px);
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 20px;
  overflow: hidden;
}

.check-view-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
}

.check-view-title {
  margin: 4px 0 0;
  font-family: "Barlow", "DIN Alternate", "Helvetica Neue", Arial, sans-serif;
  font-size: clamp(1.6rem, 2.8vw, 2.8rem);
  font-weight: 700;
  letter-spacing: -0.04em;
  line-height: 1;
}

.check-view-meta {
  display: flex;
  align-items: center;
  gap: 20px;
  flex-shrink: 0;
}

.check-progress {
  display: flex;
  align-items: baseline;
  gap: 3px;
}

.sheet-progress-val {
  font-family: "Barlow", "DIN Alternate", "Helvetica Neue", Arial, sans-serif;
  font-size: clamp(2.4rem, 3.4vw, 3.8rem);
  font-weight: 700;
  letter-spacing: -0.05em;
  line-height: 1;
}

.sheet-progress-sep {
  font-size: 0.9rem;
  color: var(--muted);
  font-weight: 400;
}

.sheet-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: auto auto;
  gap: 16px;
  align-content: start;
  overflow: hidden;
}

.sheet-group {
  background: var(--soft-surface);
  padding: 20px 22px;
}

.sheet-group-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.sheet-group-name {
  margin: 0;
  font-family: "Barlow", "DIN Alternate", "Helvetica Neue", Arial, sans-serif;
  font-size: 1.32rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  line-height: 1;
}

.sheet-group-count {
  margin: 0;
  font-size: 0.6rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
}

.sheet-items {
  display: grid;
  gap: 10px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.sheet-item label {
  display: grid;
  grid-template-columns: 15px 1fr;
  gap: 10px;
  align-items: start;
  cursor: pointer;
}

.sheet-item-input {
  width: 15px;
  height: 15px;
  margin: 2px 0 0;
  accent-color: var(--accent);
  cursor: pointer;
}

.sheet-item-text {
  font-size: 1.11rem;
  line-height: 1.5;
  color: var(--text);
  transition: color 0.1s;
}

.sheet-item-input:checked + .sheet-item-text {
  color: var(--muted);
}

.sheet-item-input:focus-visible {
  outline: 2px solid #9aa1a8;
  outline-offset: 2px;
}

@media (max-width: 1120px) {
  .workspace-layout,
  .dashboard,
  .analysis-grid {
    grid-template-columns: 1fr;
  }

  .checklist-panel {
    position: static;
    max-height: none;
    overflow: visible;
  }

  .preview-stage {
    width: 100%;
    aspect-ratio: 16 / 9;
  }
}

@media (max-width: 720px) {
  .page-shell {
    width: min(100% - 14px, 100%);
  }

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

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