:root {
  color-scheme: light;
  --ink: #10213e;
  --muted: #64748a;
  --line: #d8e0ea;
  --paper: #f7f9fc;
  --white: #ffffff;
  --navy: #091a33;
  --blue: #176bff;
  --cyan: #5fd2f4;
  --amber: #d88916;
  --red: #cf3d4b;
  --green: #137864;
  --shadow: 0 18px 48px rgba(15, 34, 64, 0.1);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html { min-width: 320px; background: var(--paper); }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    radial-gradient(circle at 88% 8%, rgba(95, 210, 244, 0.12), transparent 26rem),
    var(--paper);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 1rem;
}

button, input { font: inherit; }
button { color: inherit; }

.topbar {
  height: 68px;
  padding: 0 clamp(1rem, 3vw, 3rem);
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: white;
  background: var(--navy);
  border-bottom: 1px solid rgba(255,255,255,.12);
}

.brand { display: flex; align-items: center; gap: .65rem; color: inherit; text-decoration: none; font-weight: 750; letter-spacing: -.02em; }
.brand small { margin-left: .25rem; padding-left: .9rem; color: #9fb1c9; border-left: 1px solid #31415a; font-size: .78rem; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; }
.brand-mark { width: 29px; height: 29px; display: grid; grid-template-columns: 1fr 1fr; gap: 2px; transform: rotate(45deg); }
.brand-mark i { display: block; background: var(--cyan); }
.brand-mark i:nth-child(2) { background: #2d84ff; }
.brand-mark i:nth-child(3) { grid-column: span 2; background: #8de8ff; }
.privacy-note { color: #b9c9dc; font-size: .82rem; }
.privacy-note span { margin-right: .45rem; color: #53d5b5; font-size: .65rem; }

.workspace {
  width: min(1480px, 100%);
  min-height: calc(100vh - 68px);
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(300px, 390px) minmax(0, 1fr);
}

.controls { padding: clamp(1.6rem, 3vw, 3.1rem); border-right: 1px solid var(--line); background: rgba(255,255,255,.72); }
.section-kicker, .eyebrow { color: var(--blue); font-size: .75rem; font-weight: 800; letter-spacing: .13em; text-transform: uppercase; }
h1 { max-width: 310px; margin: .55rem 0 .75rem; font-family: Georgia, "Times New Roman", serif; font-size: clamp(2rem, 3vw, 2.65rem); line-height: 1.03; letter-spacing: -.035em; font-weight: 500; }
.intro { margin: 0 0 1.5rem; color: var(--muted); line-height: 1.55; }

.upload-card {
  display: flex;
  min-height: 198px;
  padding: 1.25rem;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  border: 1.5px dashed #9aabc0;
  border-radius: 8px;
  background: #fff;
  transition: .18s ease;
}
.upload-card.dragging { border-color: var(--blue); background: #edf5ff; transform: translateY(-2px); }
.upload-card strong { font-size: 1rem; }
.upload-card > span { margin: .25rem 0 1rem; color: var(--muted); font-size: .82rem; }
.upload-icon { width: 38px; height: 38px; margin-bottom: .65rem; display: grid; place-items: center; color: var(--blue); border: 1px solid #bcd1f2; border-radius: 50%; background: #f3f8ff; font-size: 1.4rem; }
.demo-link { width: 100%; padding: .8rem; border: 0; background: transparent; color: var(--blue); cursor: pointer; font-size: .88rem; font-weight: 700; }

.button { min-height: 44px; padding: .7rem 1.1rem; border-radius: 5px; cursor: pointer; font-weight: 750; transition: .15s ease; }
.button.secondary { border: 1px solid #b7c4d4; background: white; }
.button.secondary:hover { border-color: var(--blue); color: var(--blue); }
.button.primary { width: 100%; margin-top: 1.35rem; border: 1px solid var(--blue); color: #fff; background: var(--blue); box-shadow: 0 8px 20px rgba(23, 107, 255, .2); }
.button.primary:hover:not(:disabled) { background: #0d57d8; transform: translateY(-1px); }
.button:disabled { border-color: #c5cdd8; background: #c5cdd8; box-shadow: none; cursor: not-allowed; }

fieldset { margin: 1.2rem 0 0; padding: 0; border: 0; }
legend, .sensitivity-label { width: 100%; margin-bottom: .6rem; color: #263752; font-size: .86rem; font-weight: 750; }
.select-label { margin-top: 1.2rem; display: grid; gap: .45rem; color: #263752; font-size: .86rem; font-weight: 750; }
.select-label select { width: 100%; min-height: 42px; padding: .55rem .7rem; color: var(--ink); border: 1px solid #bec9d7; border-radius: 5px; background: white; }
.select-label select:focus { border-color: var(--blue); outline: 3px solid rgba(23,107,255,.12); }
.select-label small { color: var(--muted); font-size: .7rem; font-weight: 500; line-height: 1.4; }
.material-row { display: grid; grid-template-columns: 1fr 1fr; gap: .65rem; }
.material-row .select-label { margin-top: 1rem; }
.context-note { margin: .45rem 0 0; color: var(--muted); font-size: .7rem; line-height: 1.4; }
.check-row { margin-top: 1rem; display: flex; align-items: flex-start; gap: .6rem; color: #263752; cursor: pointer; }
.check-row input { width: 17px; height: 17px; margin-top: .15rem; accent-color: var(--blue); }
.check-row span { display: grid; gap: .15rem; }
.check-row strong { font-size: .82rem; }
.check-row small { color: var(--muted); font-size: .7rem; font-weight: 500; line-height: 1.35; }
.dimension-row { display: grid; grid-template-columns: 1fr auto 1fr; align-items: end; gap: .65rem; }
.dimension-row label { color: var(--muted); font-size: .75rem; }
.dimension-row label span { margin-top: .3rem; display: flex; align-items: center; color: var(--muted); border: 1px solid #bec9d7; border-radius: 5px; background: #fff; overflow: hidden; }
.dimension-row input { width: 100%; min-width: 0; padding: .65rem .25rem .65rem .7rem; color: var(--ink); border: 0; outline: none; font-weight: 700; }
.dimension-row label span:focus-within { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(23,107,255,.12); }
.dimension-x { padding-bottom: .65rem; color: #8090a5; }
.segmented { display: grid; grid-template-columns: 1fr 1fr; padding: 3px; background: #e7ecf3; border-radius: 6px; }
.segmented input { position: absolute; opacity: 0; }
.segmented span { display: block; padding: .62rem .5rem; border-radius: 4px; text-align: center; cursor: pointer; color: var(--muted); font-size: .84rem; font-weight: 700; }
.segmented input:checked + span { color: var(--ink); background: white; box-shadow: 0 1px 4px rgba(18,38,67,.14); }
.segmented input:focus-visible + span { outline: 2px solid var(--blue); outline-offset: 1px; }
.sensitivity-label { margin-top: 1.2rem; display: flex; justify-content: space-between; }
.sensitivity-label span { color: var(--blue); font-weight: 700; }
.range { width: 100%; accent-color: var(--blue); }
.range-labels { display: flex; justify-content: space-between; color: var(--muted); font-size: .7rem; }

.review-area { min-width: 0; padding: clamp(1rem, 2.5vw, 2.4rem); display: grid; grid-template-rows: auto auto minmax(430px, 1fr) auto auto; gap: .9rem; }
.review-toolbar { display: flex; min-height: 42px; align-items: center; justify-content: space-between; }
.review-toolbar > div:first-child { display: grid; gap: .2rem; }
.review-toolbar strong { max-width: 42vw; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.view-switcher { padding: 3px; border: 1px solid var(--line); border-radius: 5px; background: #edf1f6; }
.view-switcher button { padding: .42rem .7rem; border: 0; border-radius: 3px; color: var(--muted); background: transparent; cursor: pointer; font-size: .78rem; font-weight: 700; }
.view-switcher button.active { color: var(--ink); background: #fff; box-shadow: 0 1px 4px rgba(15,34,64,.1); }

.edit-toolbar { min-width: 0; padding: .55rem .65rem; display: flex; align-items: center; gap: .55rem; border: 1px solid var(--line); border-radius: 6px; background: white; }
.tool-label { flex: 0 0 auto; color: var(--muted); font-size: .72rem; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; }
.tool-buttons { min-width: 0; display: flex; gap: .25rem; overflow-x: auto; }
.tool-buttons button, .undo-button, .report-actions button, .review-actions button, .saved-case button { min-height: 34px; padding: .4rem .62rem; border: 1px solid #c5cfdb; border-radius: 4px; background: white; cursor: pointer; font-size: .73rem; font-weight: 700; white-space: nowrap; }
.tool-buttons button:hover, .undo-button:hover:not(:disabled), .report-actions button:hover, .review-actions button:hover, .saved-case button:hover { color: var(--blue); border-color: #91b4ec; }
.tool-buttons button.active { color: white; border-color: var(--blue); background: var(--blue); }
.undo-button:disabled { opacity: .45; cursor: not-allowed; }
.tool-hint { min-width: 150px; margin-left: auto; color: var(--muted); font-size: .7rem; text-align: right; }
#display-canvas.editing { cursor: crosshair; }

.drawing-stage {
  position: relative;
  min-height: 430px;
  display: grid;
  place-items: center;
  overflow: hidden;
  border: 1px solid #b9c5d4;
  border-radius: 7px;
  background-color: #e8edf3;
  background-image: linear-gradient(rgba(113,132,156,.09) 1px, transparent 1px), linear-gradient(90deg, rgba(113,132,156,.09) 1px, transparent 1px);
  background-size: 24px 24px;
  box-shadow: inset 0 0 80px rgba(20,45,75,.05), var(--shadow);
}
#display-canvas { display: none; max-width: 100%; max-height: 68vh; background: white; box-shadow: 0 12px 40px rgba(16,33,62,.16); }
.empty-state { display: grid; justify-items: center; text-align: center; }
.empty-state > span { margin-top: .3rem; color: var(--muted); font-size: .88rem; }
.empty-diagram { width: 116px; margin-bottom: .85rem; color: #8fa0b4; }
.empty-diagram svg { width: 100%; fill: rgba(95,210,244,.09); stroke: currentColor; stroke-width: 3; }
.empty-diagram circle { fill: var(--cyan); stroke: white; }

.results-panel { border: 1px solid var(--line); border-radius: 7px; background: rgba(255,255,255,.9); overflow: hidden; }
.calibration-panel { padding: .75rem .85rem; display: grid; grid-template-columns: minmax(190px, auto) 1fr; align-items: center; gap: .7rem 1rem; border: 1px solid #b9cbe2; border-radius: 7px; background: #f2f7fd; }
.expert-toggle { display: flex; align-items: flex-start; gap: .55rem; cursor: pointer; }
.expert-toggle input { width: 17px; height: 17px; margin-top: .1rem; accent-color: var(--blue); }
.expert-toggle span { display: grid; gap: .08rem; }
.expert-toggle strong { font-size: .82rem; }
.expert-toggle small { color: var(--muted); font-size: .68rem; }
.report-actions { display: flex; justify-content: flex-end; gap: .35rem; flex-wrap: wrap; }
.saved-cases { grid-column: 1 / -1; border-top: 1px solid #d5e1ef; padding-top: .55rem; }
.saved-cases summary { color: #49627f; cursor: pointer; font-size: .75rem; font-weight: 700; }
#saved-case-list { margin-top: .55rem; display: grid; gap: .35rem; }
.saved-case { padding: .45rem .55rem; display: flex; align-items: center; gap: .5rem; border-radius: 4px; background: white; }
.saved-case span { min-width: 0; display: grid; flex: 1; gap: .05rem; }
.saved-case strong { overflow: hidden; font-size: .75rem; text-overflow: ellipsis; white-space: nowrap; }
.saved-case small { color: var(--muted); font-size: .66rem; }
.results-empty { min-height: 76px; padding: 1rem 1.15rem; display: flex; align-items: center; gap: .85rem; }
.result-count { width: 40px; height: 40px; display: grid; flex: 0 0 auto; place-items: center; border-radius: 50%; color: var(--muted); background: #edf1f5; font-weight: 800; }
.results-empty div { display: grid; gap: .16rem; }
.results-empty small { color: var(--muted); font-size: .8rem; }
.summary { padding: .95rem 1.1rem; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--line); }
.summary-title { display: flex; align-items: center; gap: .7rem; }
.summary-title .result-count { color: white; background: var(--navy); }
.summary-title div { display: grid; gap: .12rem; }
.summary-title small { color: var(--muted); }
.summary-badges { display: flex; gap: .4rem; }
.badge { padding: .3rem .52rem; border-radius: 99px; font-size: .7rem; font-weight: 800; }
.badge.warning { color: #8a5100; background: #fff0cf; }
.badge.blocking { color: #a02634; background: #ffe0e4; }
.badge.note { color: #1a5e8f; background: #dff4ff; }
.findings { max-height: 270px; overflow: auto; }
.finding { width: 100%; padding: .85rem 1.1rem; display: grid; grid-template-columns: auto 1fr auto; gap: .8rem; align-items: start; border: 0; border-bottom: 1px solid #e7ebf0; background: white; text-align: left; cursor: pointer; }
.finding:hover, .finding.active { background: #f4f8fd; }
.finding.reviewed { box-shadow: inset 3px 0 0 var(--green); }
.finding-index { width: 27px; height: 27px; display: grid; place-items: center; border-radius: 50%; color: white; background: var(--amber); font-size: .75rem; font-weight: 800; }
.finding.blocking .finding-index, .finding.critical .finding-index { background: var(--red); }
.finding.note .finding-index, .finding.advisory .finding-index { background: #2784b9; }
.finding.high .finding-index { background: var(--amber); }
.finding.caution .finding-index { color: #744500; background: #ffd375; }
.finding-copy { display: grid; gap: .18rem; }
.finding-copy strong { font-size: .88rem; }
.finding-copy span { color: var(--muted); font-size: .78rem; line-height: 1.4; }
.finding-copy small { color: #49627f; font-size: .7rem; line-height: 1.35; }
.finding-severity { padding-top: .22rem; color: var(--muted); font-size: .68rem; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; }
.review-actions { grid-column: 2 / -1; display: flex; align-items: center; gap: .35rem; flex-wrap: wrap; }
.review-actions button.selected { color: white; border-color: var(--green); background: var(--green); }
.review-actions select, .review-actions input { min-height: 34px; padding: .35rem .48rem; border: 1px solid #c5cfdb; border-radius: 4px; background: white; font-size: .72rem; }
.review-actions input { min-width: 180px; flex: 1; }
.review-status { color: var(--green); font-size: .68rem; font-weight: 800; text-transform: uppercase; }
.disclaimer { margin: .65rem 0 0; color: var(--muted); font-size: .72rem; line-height: 1.45; }

@media (max-width: 860px) {
  .workspace { grid-template-columns: 1fr; }
  .controls { border-right: 0; border-bottom: 1px solid var(--line); }
  h1 { max-width: 520px; }
  .review-area { min-height: 700px; }
  .edit-toolbar { align-items: flex-start; flex-wrap: wrap; }
  .tool-hint { width: 100%; margin-left: 0; text-align: left; }
  .calibration-panel { grid-template-columns: 1fr; }
  .report-actions { justify-content: flex-start; }
  .privacy-note { display: none; }
}

@media (max-width: 520px) {
  .topbar { height: 58px; }
  .brand small { display: none; }
  .controls { padding: 1.35rem 1rem; }
  .review-area { padding: 1rem; grid-template-rows: auto auto minmax(360px, 1fr) auto auto; }
  .drawing-stage { min-height: 360px; }
  .review-toolbar { align-items: flex-start; gap: .5rem; flex-direction: column; }
  .review-toolbar strong { max-width: 88vw; }
  .summary { align-items: flex-start; gap: .8rem; flex-direction: column; }
  .finding { grid-template-columns: auto 1fr; }
  .finding-severity { grid-column: 2; padding: 0; }
  .review-actions { grid-column: 1 / -1; }
  .material-row { grid-template-columns: 1fr; gap: 0; }
}

@media print {
  .topbar, .controls, .edit-toolbar, .view-switcher, .calibration-panel { display: none !important; }
  .workspace { display: block; }
  .review-area { padding: 0; display: block; }
  .drawing-stage { min-height: 0; margin-bottom: 1rem; border: 0; box-shadow: none; background: white; }
  #display-canvas { max-height: 52vh; box-shadow: none; }
  .results-panel { border: 0; }
  .findings { max-height: none; overflow: visible; }
  .finding { break-inside: avoid; }
  .review-actions { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}
