/* Foundations: cream surfaces, high-contrast green, readable workspace type. */
:root {
  color-scheme: light;
  --bg: #f5f5f0;
  --paper: #ffffff;
  --ink: #24332f;
  --muted: #56665c;
  --line: #d6ded5;
  --green: #235a46;
  --light: #e9f1ea;
  --gold: #765617;
  --danger: #9b2832;
  --sidebar-width: 232px;
  --radius: 10px;
}

* { box-sizing: border-box; }
html { scroll-padding-top: 76px; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 "Segoe UI", Arial, sans-serif;
  overflow-wrap: anywhere;
}
button, input, select, textarea { font: inherit; }
button, a { touch-action: manipulation; }
button {
  min-height: 44px;
  padding: 9px 14px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--paper);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.4;
  cursor: pointer;
  white-space: normal;
}
button:hover { border-color: var(--green); background: var(--light); }
button:disabled { color: var(--muted); background: #edf0eb; cursor: not-allowed; }
.primary { color: #fff; background: var(--green); border-color: var(--green); }
.primary:hover { color: #fff; background: #174934; }
button.primary:disabled { color: #fff; background: #536c60; border-color: #536c60; }
a { color: var(--green); text-underline-offset: 3px; }
a:hover { text-decoration-thickness: 2px; }
:focus-visible { outline: 3px solid #2869ac; outline-offset: 3px; }
h1, h2, h3, h4, p { margin-top: 0; }
h1 { margin-bottom: 8px; font-size: 28px; line-height: 1.2; letter-spacing: -.6px; font-weight: 650; }
h2 { margin-bottom: 12px; font-size: 22px; line-height: 1.3; font-weight: 600; }
h3 { margin-bottom: 10px; font-size: 17px; line-height: 1.4; font-weight: 600; }
h4 { margin-bottom: 8px; font-size: 15px; }
small, .muted { color: var(--muted); font-size: 13px; }
img { max-width: 100%; height: auto; }
svg { max-width: 100%; }
[hidden] { display: none !important; }
.skip-link {
  position: fixed;
  top: 8px;
  left: 12px;
  z-index: 100;
  padding: 12px 18px;
  background: var(--paper);
  border: 2px solid var(--green);
  border-radius: 7px;
  transform: translateY(-160%);
}
.skip-link:focus { transform: translateY(0); }

/* Application shell and navigation. */
.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 30;
  display: flex;
  flex-direction: column;
  width: var(--sidebar-width);
  padding: 24px 16px;
  overflow-y: auto;
  background: #1b3028;
  color: #dce6de;
}
.brand { display: flex; align-items: center; gap: 10px; margin: 0 4px 30px; color: #fff; text-decoration: none; }
.brand-mark { font-size: 32px; }
.brand > span:last-child { font-size: 17px; letter-spacing: 1.5px; font-weight: 700; }
.brand small { display: block; margin-top: 3px; color: #bed0c3; font-size: 13px; letter-spacing: .1px; font-weight: 400; }
.side-label { margin: 0 8px 10px; color: #bed0c3; font-size: 13px; letter-spacing: .4px; }
.nav-button { display: block; width: 100%; margin: 4px 0; padding: 11px 12px; border-color: transparent; background: transparent; color: #dce6de; text-align: left; }
.nav-button:hover, .nav-button.active, .nav-button[aria-current="page"] { color: #fff; background: #304b3e; }
.sidebar-bottom { margin-top: auto; padding: 28px 8px 0; font-size: 13px; color: #bed0c3; }
.sidebar-bottom p { margin: 10px 0; color: #bed0c3; font-size: 13px; }
.sidebar-bottom a { display: inline-flex; align-items: center; min-height: 44px; color: #dce6de; }
.live-dot { display: inline-block; width: 7px; height: 7px; margin-right: 5px; border-radius: 50%; background: #92c6a6; }
.workspace { min-width: 0; margin-left: var(--sidebar-width); }
.app-header {
  display: flex;
  align-items: center;
  gap: 16px;
  min-height: 60px;
  padding: 8px 24px;
  border-bottom: 1px solid var(--line);
  background: var(--paper);
}
#breadcrumb { flex: 1; min-width: 0; color: var(--muted); font-size: 14px; }
#breadcrumb a { display: inline-flex; align-items: center; min-height: 44px; padding: 0 3px; }
.header-actions { display: flex; align-items: center; flex-wrap: wrap; gap: 12px; }
.pill { display: inline-block; padding: 4px 8px; border: 1px solid var(--line); border-radius: 20px; color: var(--green); background: var(--light); font-size: 13px; font-weight: 600; }
.menu-toggle, .sidebar-backdrop { display: none; }
main { min-width: 0; min-height: calc(100dvh - 142px); padding: 24px; }
footer { padding: 18px 24px; border-top: 1px solid var(--line); color: var(--muted); font-size: 13px; }
footer span { display: inline-block; }

/* Project header, filters and gallery. */
.eyebrow { margin-bottom: 8px; color: var(--green); font-size: 13px; font-weight: 600; letter-spacing: 1px; }
.hero, .project-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 16px; }
.hero > *, .project-heading > * { min-width: 0; }
.hero p, .project-heading p, .project-summary { max-width: 76ch; margin-bottom: 8px; color: var(--muted); }
.hero-meta { flex-shrink: 0; min-width: 80px; text-align: right; }
.hero-meta strong { color: var(--green); font-size: 28px; line-height: 1.2; }
.hero-meta p { font-size: 13px; }
.summary-chips, .status-meta, .workflow { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }
.summary-chips { margin: 8px 0 16px; }
.summary-chips > span, .summary-chip { padding: 4px 10px; border: 1px solid var(--line); border-radius: 6px; background: var(--paper); color: var(--muted); font-size: 13px; }
.stats { display: flex; flex-wrap: wrap; gap: 8px 24px; margin: 12px 0 16px; }
.stat { display: flex; align-items: baseline; gap: 8px; }
.stat b { color: var(--green); font-size: 20px; }
.stat span { color: var(--muted); font-size: 13px; }
.toolbar, .filter-row, .actions, .form-actions { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; }
.toolbar, .filter-row { margin-bottom: 16px; }
.toolbar > *, .filter-row > * { min-width: 0; max-width: 100%; }
.toolbar input, .filter-row input { flex: 1 1 240px; }
.toolbar select { flex: 0 1 280px; }
.toolbar label, .filter-row label { margin: 0; font-size: 14px; }
.toolbar label:has(input, select), .filter-row label:has(input, select) { flex: 1 1 200px; }
.grid, .resource-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 280px), 1fr)); gap: 20px; }
.card, .concept-card { min-width: 0; overflow: hidden; border: 1px solid var(--line); border-radius: var(--radius); background: var(--paper); }
.card > a { display: block; height: 100%; color: inherit; text-decoration: none; }
.card:focus-within, .card:hover, .concept-card:hover { border-color: var(--green); box-shadow: 0 3px 12px #1b302810; }
.cover { position: relative; display: grid; place-items: center; aspect-ratio: 16 / 10; overflow: hidden; background: #e5ebe1; }
.cover img { width: 100%; height: 100%; object-fit: cover; }
.cover img { object-fit: contain; }
.nav-button { text-decoration: none; }
.cover .badge { position: absolute; top: 12px; left: 12px; max-width: calc(100% - 24px); }
.placeholder { color: var(--green); font-size: 64px; }
.card-body { padding: 18px; }
.card-body h2 { margin-bottom: 8px; font-size: 19px; }
.card-body p { margin-bottom: 16px; color: var(--muted); font-size: 14px; }
.card-foot { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px; padding-top: 12px; border-top: 1px solid var(--line); color: var(--muted); font-size: 13px; }
.card-foot span { color: var(--green); font-weight: 600; }
.badge { display: inline-block; padding: 4px 9px; border: 1px solid #cbdace; border-radius: 5px; background: var(--light); color: var(--green); font-size: 13px; line-height: 1.4; }
.badge.warning { background: #fff1ce; border-color: #dfce9a; color: #715010; }
.badge.warn { background: #fff1ce; border-color: #dfce9a; color: #715010; }
.check-label { display: flex; align-items: center; gap: 8px; min-height: 44px; }
.mobile-view-options { display: none; }
.version-summary { margin-top: 20px; }
.attachment-list { max-height: 240px; overflow: auto; }
fieldset { min-width: 0; margin: 16px 0; padding: 16px; border: 1px solid var(--line); border-radius: 7px; }
legend { padding: 0 6px; font-size: 16px; font-weight: 600; }
.file-picker { padding: 16px; }
.detail-grid { grid-template-columns: minmax(130px, 1fr) minmax(0, 3fr); }
.preview-image { display: block; margin: auto; }
.badge.error { background: #fcebed; border-color: #e8bcc2; color: var(--danger); }
.tabs { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 16px; padding-bottom: 8px; border-bottom: 1px solid var(--line); }
.tabs button { border-color: transparent; background: transparent; }
.tabs button.active, .tabs button[aria-selected="true"] { border-color: #c5d7c9; background: var(--light); color: var(--green); font-weight: 600; }
.tabs button:hover { border-color: var(--green); }

/* Standalone assembly view: no library chrome or technical record panels. */
.assembly-page #sidebar, .assembly-page #sidebar-backdrop, .assembly-page .app-header,
.assembly-page .workspace > footer, .assembly-page .skip-link { display: none; }
.assembly-page .workspace { margin-left: 0; width: 100%; }
.assembly-page #main { padding: 12px; max-width: none; }
.assembly-heading { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 10px; }
.assembly-page .viewer-layout { grid-template-columns: minmax(0, 1fr) 260px; }
.assembly-page .viewport { height: calc(100dvh - 92px); min-height: 320px; }
.assembly-page .view-controls { max-height: calc(100dvh - 92px); }
.viewer-simple .view-controls .viewer-keepout, .viewer-simple .viewer-groups,
.viewer-simple .viewer-part small, .viewer-simple .viewer-part button,
.viewer-simple .viewer-part[data-group="keepout"], .viewer-simple .viewer-selection,
.viewer-simple .viewer-visibility { display: none; }
.viewer-simple .viewer-part { display: block; padding: 4px 0; }
@media (max-width: 760px) {
  .assembly-page .viewer-layout { grid-template-columns: minmax(0, 1fr); }
  .assembly-page .viewport { height: 56dvh; min-height: 260px; }
  .assembly-page .view-controls { max-height: 32dvh; border-left: 0; border-top: 1px solid var(--line); }
  .assembly-heading { font-size: 13px; }
}

/* Viewer stays in the initial project viewport; panels scroll locally. */
#content, #views, #views > *, .compare-views > * { min-width: 0; }
.viewer-layout { display: grid; grid-template-columns: minmax(0, 1fr) 248px; min-width: 0; overflow: hidden; border: 1px solid var(--line); border-radius: var(--radius); background: var(--paper); }
.viewport { position: relative; min-width: 0; height: clamp(320px, 48vh, 540px); overflow: hidden; background: #e8ede5; }
.viewport canvas { display: block; width: 100%; height: 100%; }
.viewer-label { position: absolute; top: 12px; left: 12px; z-index: 1; max-width: calc(100% - 24px); padding: 6px 9px; border: 1px solid #d0dbce; border-radius: 5px; background: #fffffff2; color: var(--ink); font-size: 13px; pointer-events: none; }
.view-controls { min-width: 0; max-height: 540px; max-height: clamp(320px, 48vh, 540px); padding: 16px; overflow-y: auto; border-left: 1px solid var(--line); font-size: 14px; scrollbar-gutter: stable; }
.view-controls h3 { font-size: 16px; }
.view-controls h4, .view-controls .group-heading { margin: 18px 0 8px; color: var(--muted); font-size: 13px; font-weight: 600; }
.view-controls label { margin: 10px 0; font-size: 14px; }
.view-controls label:has(input[type="checkbox"]) { display: flex; align-items: center; gap: 8px; min-height: 44px; margin: 0; }
.camera-buttons, .viewer-actions, .control-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.camera-buttons button, .viewer-actions button, .control-actions button { flex: 1 1 auto; padding: 8px 10px; }
.view-controls details { margin-top: 10px; }
.view-controls summary { font-size: 14px; }
.compare-views { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.compare-views .viewer-layout { grid-template-columns: minmax(0, 1fr); }
.compare-views .view-controls { max-height: 260px; border-left: 0; border-top: 1px solid var(--line); }
.viewer-layout:fullscreen, .viewer-layout.is-expanded { width: 100%; height: 100%; border: 0; border-radius: 0; background: var(--paper); }
.viewer-layout.is-expanded { position: fixed; inset: 0; z-index: 70; width: 100vw; height: 100dvh; }
.viewer-layout:fullscreen .viewport, .viewer-layout.is-expanded .viewport { height: 100%; min-height: 0; }
.viewer-layout:fullscreen .view-controls, .viewer-layout.is-expanded .view-controls { max-height: 100dvh; }

/* Evidence, human-readable records and locally scrolling technical tables. */
.panel, .resource-grid > article { min-width: 0; margin-bottom: 16px; padding: 18px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--paper); }
.panel-head { display: flex; align-items: center; flex-wrap: wrap; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.panel-head h2, .panel-head h3 { margin: 0; }
.panel p:last-child { margin-bottom: 0; }
.note, .empty { padding: 14px 16px; border: 1px solid var(--line); border-radius: 7px; background: #edf2e9; color: #435749; font-size: 14px; }
.note { margin-bottom: 16px; }
.note:empty, .error:empty { display: none; }
.empty { margin: 16px 0; padding: 28px 20px; text-align: center; }
.error { color: var(--danger); font-size: 14px; }
dl.detail-grid { display: grid; grid-template-columns: minmax(130px, 1fr) minmax(0, 3fr); gap: 12px 24px; }
dl { min-width: 0; margin: 0 0 16px; }
dt { margin: 0 0 4px; color: var(--muted); font-size: 13px; font-weight: 600; }
dd { margin: 0 0 14px; overflow-wrap: anywhere; }
.detail-grid > div { min-width: 0; }
.timeline { margin: 16px 0; padding: 0 0 0 20px; border-left: 2px solid var(--line); list-style: none; }
.timeline-item { position: relative; margin: 0 0 20px; padding: 0 0 0 8px; }
.timeline-item::before { position: absolute; top: 7px; left: -26px; width: 10px; height: 10px; border: 2px solid var(--paper); border-radius: 50%; background: var(--green); content: ""; }
.timeline-item time { color: var(--muted); font-size: 13px; }
.status-meta { color: var(--muted); font-size: 13px; }
.workflow { margin: 12px 0; font-size: 14px; }
.thumbs { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 14px; }
.thumbs a { display: block; max-width: 100%; }
.thumbs img { display: block; width: 120px; height: 90px; border: 1px solid var(--line); border-radius: 6px; object-fit: cover; }
.file-row { display: flex; align-items: center; flex-wrap: wrap; gap: 12px; padding: 14px 0; border-bottom: 1px solid var(--line); }
.file-row:last-child { border-bottom: 0; }
.file-row > div:first-child { flex: 1 1 240px; min-width: 0; }
.file-row small { display: block; margin-top: 4px; overflow-wrap: anywhere; }
.file-row > a, .file-row .actions a { display: inline-flex; align-items: center; min-height: 44px; padding: 8px; }
.file-row .actions { flex-shrink: 0; max-width: 100%; }
.table-wrap { max-width: 100%; margin: 16px 0; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; text-align: left; }
th, td { padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { background: var(--light); color: var(--green); font-weight: 600; }
pre { max-width: 100%; padding: 16px; overflow: auto; border: 1px solid var(--line); border-radius: 7px; background: #f1f4ee; font-size: 13px; white-space: pre-wrap; overflow-wrap: anywhere; }
code { font-size: .9em; overflow-wrap: anywhere; }
summary { min-height: 44px; padding: 10px 0; font-size: 15px; font-weight: 600; cursor: pointer; }

/* Forms and native modal dialog. */
label { display: block; margin-bottom: 14px; color: var(--ink); font-size: 14px; font-weight: 500; }
input:not([type="checkbox"]):not([type="radio"]):not([type="range"]), select, textarea {
  display: block;
  width: 100%;
  min-width: 0;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid #9aa99e;
  border-radius: 6px;
  background: var(--paper);
  color: var(--ink);
  font-size: 16px;
}
label input, label select, label textarea { margin-top: 5px; }
input::placeholder, textarea::placeholder { color: var(--muted); opacity: 1; }
textarea { min-height: 100px; resize: vertical; }
input[type="checkbox"], input[type="radio"] { flex-shrink: 0; width: 20px; height: 20px; margin: 0; accent-color: var(--green); }
input[type="range"] { display: block; width: 100%; min-height: 32px; margin: 4px 0; accent-color: var(--green); }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 16px; }
.form-grid > *, .component-row > * { min-width: 0; }
.form-grid .full-width { grid-column: 1 / -1; }
.component-row { display: flex; align-items: end; flex-wrap: wrap; gap: 10px; margin-bottom: 12px; padding: 12px; border: 1px solid var(--line); border-radius: 7px; }
.component-row label { flex: 1 1 160px; margin: 0; }
.form-actions { justify-content: flex-end; margin-top: 20px; }
dialog { width: min(760px, calc(100% - 32px)); max-width: calc(100% - 32px); max-height: calc(100dvh - 32px); padding: 0; overflow: auto; border: 1px solid var(--line); border-radius: 12px; background: var(--paper); color: var(--ink); box-shadow: 0 20px 70px #152b2840; }
dialog::backdrop { background: #14271fb3; }
.dialog-head { position: sticky; top: 0; z-index: 2; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--line); background: var(--paper); }
.dialog-head h2 { min-width: 0; margin: 0; font-size: 20px; }
#dialog-close { flex-shrink: 0; width: 44px; padding: 8px; }
#dialog-body { min-width: 0; padding: 20px; }
#toast { position: fixed; right: 24px; bottom: 24px; z-index: 90; max-width: min(480px, calc(100% - 32px)); padding: 13px 18px; border-radius: 8px; background: #1b3028; color: #fff; box-shadow: 0 4px 24px #152b2833; opacity: 0; transform: translateY(10px); pointer-events: none; transition: opacity .15s, transform .15s; }
#toast.show { opacity: 1; transform: translateY(0); }

/* Responsive layouts also cover increased text and browser zoom. */
@media (min-width: 1600px) {
  main { max-width: 1720px; margin-inline: auto; }
}
@media (max-width: 1100px) {
  .viewer-layout { grid-template-columns: minmax(0, 1fr) 220px; }
  .compare-views { grid-template-columns: minmax(0, 1fr); }
  .header-actions .pill { display: none; }
}
@media (max-width: 900px) {
  .sidebar { width: min(280px, calc(100vw - 56px)); visibility: hidden; transform: translateX(-100%); transition: transform .18s ease, visibility .18s; }
  .sidebar.open { visibility: visible; transform: translateX(0); }
  .sidebar-backdrop { position: fixed; inset: 0; z-index: 20; width: 100%; height: 100%; padding: 0; border: 0; border-radius: 0; background: #14271f99; }
  .sidebar.open + .sidebar-backdrop { display: block; }
  .sidebar-backdrop:hover { background: #14271f99; }
  .workspace { margin-left: 0; }
  .menu-toggle { display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0; width: 44px; padding: 8px; font-size: 21px; }
  .app-header { gap: 12px; }
}
@media (max-width: 640px) {
  .app-header { flex-wrap: wrap; gap: 8px; padding: 8px 16px; }
  #breadcrumb { flex-basis: calc(100% - 60px); }
  .header-actions { width: 100%; justify-content: flex-end; }
  main { padding: 20px 16px; }
  footer { padding: 16px; }
  .hero, .project-heading { flex-wrap: wrap; gap: 10px; }
  .hero-meta { min-width: 0; text-align: left; }
  .hero-meta p { display: inline; margin-left: 6px; }
  .toolbar > select, .toolbar > input, .filter-row > select { flex: 1 1 100%; }
  .viewer-layout { grid-template-columns: minmax(0, 1fr); }
  .viewport { height: clamp(280px, 46vh, 420px); }
  .view-controls { max-height: 300px; border-top: 1px solid var(--line); border-left: 0; }
  .viewer-layout:fullscreen, .viewer-layout.is-expanded { grid-template-rows: minmax(0, 1fr) minmax(140px, 32dvh); }
  .viewer-layout:fullscreen .view-controls, .viewer-layout.is-expanded .view-controls { max-height: 32dvh; }
  .form-grid { grid-template-columns: minmax(0, 1fr); }
  .panel, .resource-grid > article { padding: 14px; }
  .grid, .resource-grid { gap: 16px; }
  .tabs { gap: 4px; }
  .tabs button { flex: 1 1 auto; }
  .app-header { display: grid; grid-template-columns: 44px minmax(0, 1fr) auto; }
  #breadcrumb { font-size: 13px; }
  .header-actions { width: auto; }
  #new-project { max-width: 86px; padding: 8px; }
  .project-heading { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: start; }
  .project-heading h1 { font-size: 24px; }
  .project-heading .summary-chips { margin-bottom: 0; }
  .project-heading #snapshot { max-width: 100px; }
  .summary-chips > span { padding: 0; border: 0; background: transparent; }
  .tabs { flex-wrap: nowrap; overflow-x: auto; padding-bottom: 6px; }
  .tabs button { flex: 0 0 auto; white-space: nowrap; }
  .version-toolbar { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: end; }
  .mobile-view-options { display: inline-flex; align-items: center; }
  .version-toolbar:not(.comparison-open) .compare-field,
  .version-toolbar:not(.comparison-open) .viewer-options { display: none; }
  .version-toolbar .compare-field, .version-toolbar .viewer-options { grid-column: 1 / -1; }
  dl.detail-grid { grid-template-columns: 1fr; gap: 0; }
  .file-row .actions { width: 100%; }
  dialog { width: calc(100% - 16px); max-width: calc(100% - 16px); max-height: calc(100dvh - 16px); }
  .dialog-head, #dialog-body { padding: 16px; }
  #toast { right: 16px; bottom: 16px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation: none !important; transition: none !important; }
}
