:root {
  --weave-font-sans: "Artifakt Element", "Artifakt", "Avenir Next", "Segoe UI Variable Text", "Segoe UI", Arial, sans-serif;
  --weave-font-mono: "Cascadia Code", Consolas, "Courier New", monospace;
  --weave-accent: #0696a6;
  --weave-accent-strong: #00b6c3;
  --weave-accent-soft: #e7f6f9;
  --weave-bg-light: #f5f8fb;
  --weave-surface-light: #ffffff;
  --weave-surface-light-muted: #f7fbfd;
  --weave-border-light: #c9d9e3;
  --weave-text-light: #14242f;
  --weave-text-light-muted: #5a717f;
  --weave-bg-dark: #23272a;
  --weave-surface-dark: #2d333b;
  --weave-surface-dark-muted: #252b32;
  --weave-border-dark: #455762;
  --weave-text-dark: #edf3f6;
  --weave-text-dark-muted: #b2c4ce;
  --weave-radius-sm: 6px;
  --weave-radius-md: 10px;
  --weave-radius-lg: 14px;
  --weave-shadow-sm: 0 2px 8px rgba(13, 35, 48, 0.08);
  --weave-shadow-md: 0 10px 30px rgba(9, 24, 34, 0.12);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body,
button,
input,
select,
textarea,
table,
th,
td,
label,
legend {
  font-family: var(--weave-font-sans) !important;
}

body {
  background: var(--weave-bg-light);
  color: var(--weave-text-light);
  font-family: var(--weave-font-sans) !important;
  line-height: 1.45;
  letter-spacing: 0;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body[data-theme="dark"],
html[data-theme="dark"] body {
  background: var(--weave-bg-dark);
  color: var(--weave-text-dark);
}

h1,
h2,
h3,
h4 {
  font-family: var(--weave-font-sans) !important;
  font-weight: 600 !important;
  letter-spacing: -0.01em;
  line-height: 1.2;
}

h1 {
  color: var(--weave-accent);
  font-size: clamp(1.75rem, 2.2vw, 2.25rem);
  margin: 18px 0 8px;
  font-family: var(--weave-font-sans) !important;
}

h2 {
  color: var(--weave-accent);
  font-size: clamp(1.2rem, 1.6vw, 1.55rem);
  font-family: var(--weave-font-sans) !important;
}

h3 {
  color: inherit;
  font-size: 1rem;
  font-family: var(--weave-font-sans) !important;
}

p,
li,
span,
div,
small {
  font-family: var(--weave-font-sans) !important;
}

code,
pre,
textarea.code,
.code,
.code-line {
  font-family: var(--weave-font-mono) !important;
}

a {
  color: var(--weave-accent);
}

nav,
.dw-global-nav {
  font-family: var(--weave-font-sans) !important;
  border-bottom: 1px solid var(--weave-border-light);
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.03);
  background: #eaf1f7 !important;
  color: #0f7f8a !important;
}

nav a,
.dw-global-nav a {
  font-family: var(--weave-font-sans) !important;
  font-weight: 600 !important;
  letter-spacing: 0.01em;
  color: #0f7f8a !important;
}

nav button,
.dw-global-nav button {
  color: #0f7f8a !important;
  border-color: #0f7f8a !important;
}

[data-theme="dark"] nav,
[data-theme="dark"] .dw-global-nav {
  background: #2D333B !important;
  color: #00B6C3 !important;
  border-bottom-color: #455762;
}

[data-theme="dark"] nav a,
[data-theme="dark"] .dw-global-nav a {
  color: #00B6C3 !important;
}

[data-theme="dark"] nav a.active-nav,
[data-theme="dark"] .dw-global-nav a.active-nav {
  color: #ffffff !important;
  background: #00B6C3 !important;
}

[data-theme="dark"] nav button,
[data-theme="dark"] .dw-global-nav button {
  color: #00B6C3 !important;
  border-color: #00B6C3 !important;
}

button,
.btn,
input[type="submit"],
input[type="button"] {
  border-radius: var(--weave-radius-sm);
  font-weight: 600;
  letter-spacing: 0.01em;
}

input,
select,
textarea {
  border-radius: var(--weave-radius-sm);
  border: 1px solid #95b8cc;
  min-height: 36px;
}

input:focus,
select:focus,
textarea:focus,
button:focus {
  outline: 2px solid rgba(0, 182, 195, 0.18);
  outline-offset: 1px;
  border-color: var(--weave-accent-strong);
}

table {
  border-radius: var(--weave-radius-md);
  overflow: hidden;
}

th {
  font-weight: 700;
  letter-spacing: 0.01em;
}

.active-nav {
  border-radius: var(--weave-radius-sm) !important;
  color: #ffffff !important;
  background: #00B6C3 !important;
  padding: 6px 16px !important;
  font-weight: 700 !important;
  box-shadow: 0 2px 8px rgba(0, 182, 195, 0.10);
  text-decoration: none !important;
}

.autodesk-panel,
.panel,
.module-summary-card,
.module-placeholder,
.nest-row,
.nesting-controls,
.job-card,
.sheet-card,
.sheet-card-landscape,
.machine-configurator,
.library-panel,
.preview-modal,
.preview-modal-content,
.modal-content {
  border-radius: var(--weave-radius-md) !important;
  box-shadow: var(--weave-shadow-sm);
}

.module-page,
.nesting-page,
.jobs-page {
  width: min(96vw, 1880px);
  margin-left: auto;
  margin-right: auto;
}

.weave-page {
  width: min(96vw, 1880px);
  margin: 14px auto 24px;
  padding: 0 8px;
  box-sizing: border-box;
}

.weave-shell {
  width: min(96vw, 1880px) !important;
  max-width: min(96vw, 1880px) !important;
  margin-left: auto !important;
  margin-right: auto !important;
  box-sizing: border-box;
}

.weave-subtitle {
  margin: 0 0 14px;
  color: var(--weave-text-light-muted);
  font-size: 0.92em;
}

.weave-toolbar {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
}

.weave-section-title {
  margin: 30px 0 12px;
  color: var(--weave-accent);
  font-size: 1.2rem;
  font-weight: 600;
}

.weave-table-wrap {
  border-radius: var(--weave-radius-md);
  overflow: auto;
  box-shadow: var(--weave-shadow-sm);
}

.weave-empty-panel {
  border: 1px dashed var(--weave-border-light);
  border-radius: var(--weave-radius-md);
  background: var(--weave-surface-light-muted);
  color: var(--weave-text-light-muted);
  padding: 16px;
}

.small,
.module-subtitle,
.sheet-card-meta,
.row-summary,
.parts-head,
.job-meta-label,
.density-label {
  color: var(--weave-text-light-muted);
}

.module-link-btn,
.density-save-btn,
.part-guid-chip,
.panel-pill,
.module-stat-pill,
.job-meta-box,
.panel-list-strip {
  box-shadow: none;
}

body[data-theme="dark"] .small,
body[data-theme="dark"] .module-subtitle,
body[data-theme="dark"] .sheet-card-meta,
body[data-theme="dark"] .row-summary,
body[data-theme="dark"] .parts-head,
body[data-theme="dark"] .job-meta-label,
body[data-theme="dark"] .density-label,
html[data-theme="dark"] body .small,
html[data-theme="dark"] body .module-subtitle,
html[data-theme="dark"] body .sheet-card-meta,
html[data-theme="dark"] body .row-summary,
html[data-theme="dark"] body .parts-head,
html[data-theme="dark"] body .job-meta-label,
html[data-theme="dark"] body .density-label,
body[data-theme="dark"] .weave-subtitle,
html[data-theme="dark"] body .weave-subtitle {
  color: var(--weave-text-dark-muted);
}

body[data-theme="dark"] input,
body[data-theme="dark"] select,
body[data-theme="dark"] textarea,
html[data-theme="dark"] body input,
html[data-theme="dark"] body select,
html[data-theme="dark"] body textarea {
  background: #1f252c;
  color: var(--weave-text-dark);
  border-color: #4f6573;
}

body[data-theme="dark"] .autodesk-panel,
body[data-theme="dark"] .panel,
body[data-theme="dark"] .module-summary-card,
body[data-theme="dark"] .module-placeholder,
body[data-theme="dark"] .job-card,
body[data-theme="dark"] .nest-row,
body[data-theme="dark"] .nesting-controls,
body[data-theme="dark"] .sheet-card,
body[data-theme="dark"] .sheet-card-landscape,
body[data-theme="dark"] .machine-configurator,
body[data-theme="dark"] .library-panel,
html[data-theme="dark"] body .autodesk-panel,
html[data-theme="dark"] body .panel,
html[data-theme="dark"] body .module-summary-card,
html[data-theme="dark"] body .module-placeholder,
html[data-theme="dark"] body .job-card,
html[data-theme="dark"] body .nest-row,
html[data-theme="dark"] body .nesting-controls,
html[data-theme="dark"] body .sheet-card,
html[data-theme="dark"] body .sheet-card-landscape,
html[data-theme="dark"] body .machine-configurator,
html[data-theme="dark"] body .library-panel {
  background: var(--weave-surface-dark);
  border-color: var(--weave-border-dark);
}

body[data-theme="light"] .autodesk-panel,
body[data-theme="light"] .panel,
body[data-theme="light"] .module-summary-card,
body[data-theme="light"] .module-placeholder,
body[data-theme="light"] .job-card,
body[data-theme="light"] .nest-row,
body[data-theme="light"] .nesting-controls,
body[data-theme="light"] .sheet-card,
body[data-theme="light"] .sheet-card-landscape,
body[data-theme="light"] .machine-configurator,
body[data-theme="light"] .library-panel,
html[data-theme="light"] body .autodesk-panel,
html[data-theme="light"] body .panel,
html[data-theme="light"] body .module-summary-card,
html[data-theme="light"] body .module-placeholder,
html[data-theme="light"] body .job-card,
html[data-theme="light"] body .nest-row,
html[data-theme="light"] body .nesting-controls,
html[data-theme="light"] body .sheet-card,
html[data-theme="light"] body .sheet-card-landscape,
html[data-theme="light"] body .machine-configurator,
html[data-theme="light"] body .library-panel,
body[data-theme="light"] .weave-empty-panel,
html[data-theme="light"] body .weave-empty-panel {
  background: var(--weave-surface-light);
  border-color: var(--weave-border-light);
}

body[data-theme="dark"] .weave-empty-panel,
html[data-theme="dark"] body .weave-empty-panel {
  background: var(--weave-surface-dark-muted);
  border-color: var(--weave-border-dark);
  color: var(--weave-text-dark-muted);
}

@media (max-width: 900px) {
  .module-page,
  .nesting-page,
  .jobs-page,
  .weave-page {
    width: 98vw;
  }
}

/* =====================================================================
   Shared dark-mode overrides for CRUD pages with inline <style> blocks
   (insulation_specifications, specifications, materials, manufacture_controls,
   nests, machine_setup, etc.). These selectors target the common card-based
   layout patterns that previously rendered with hard-coded light colors.
   Inline <style> blocks have lower specificity than these body-prefixed
   selectors so they will override page-level light defaults in dark mode.
   ===================================================================== */

body[data-theme="dark"] .card {
  background: #2d333b !important;
  border-color: #42535f !important;
  color: #e5eef3;
}
body[data-theme="dark"] label {
  color: #d8e5ed !important;
}
body[data-theme="dark"] .tiny,
body[data-theme="dark"] .module-subtitle,
body[data-theme="dark"] .preview-note,
body[data-theme="dark"] .status,
body[data-theme="dark"] .small {
  color: #a9bfcb !important;
}
body[data-theme="dark"] .btn {
  background: #2a3943 !important;
  border-color: #4a5a66 !important;
  color: #7ddce8 !important;
}
body[data-theme="dark"] .btn:hover {
  background: #354653 !important;
}
body[data-theme="dark"] .btn-primary {
  background: #00B6C3 !important;
  border-color: #00B6C3 !important;
  color: #0b1418 !important;
  font-weight: 700;
}
body[data-theme="dark"] .btn-danger {
  background: #4a1f24 !important;
  border-color: #864249 !important;
  color: #f3a4ab !important;
}
body[data-theme="dark"] .btn-sm { padding: 3px 8px; }

/* Tables in CRUD pages */
body[data-theme="dark"] .table-wrap {
  background: #1f252c !important;
  border-color: #4a5a66 !important;
}
body[data-theme="dark"] .table-wrap table { background: transparent !important; }
body[data-theme="dark"] .table-wrap th,
body[data-theme="dark"] table th {
  background: #32414b !important;
  color: #e5eef3 !important;
  border-bottom-color: #4a5a66 !important;
}
body[data-theme="dark"] .table-wrap td,
body[data-theme="dark"] table td {
  border-bottom-color: #41505b !important;
  color: #d8e5ed;
}

/* Insulation-spec layer editor (and reusable layer-row pattern) */
body[data-theme="dark"] .layer-row {
  background: #1f252c !important;
  border-color: #4a5a66 !important;
}
body[data-theme="dark"] .layer-row .order-badge {
  background: #00B6C3 !important;
  color: #0b1418 !important;
}
body[data-theme="dark"] .layer-metal-extras {
  background: #243038 !important;
  border-color: #4a5a66 !important;
}
body[data-theme="dark"] .layer-metal-extras label { color: #c8d8e2 !important; }
body[data-theme="dark"] .layer-metal-extras .hint { color: #95a8b3 !important; }

/* Application pills (lining/lagging) */
body[data-theme="dark"] .application-pill.pill-lining {
  background: #0d3a40 !important;
  color: #6fe0ec !important;
}
body[data-theme="dark"] .application-pill.pill-lagging {
  background: #4a3415 !important;
  color: #f0c477 !important;
}

/* SVG preview wrapper that uses a hard #fff background */
body[data-theme="dark"] svg[id$="-preview-svg"],
body[data-theme="dark"] .notch-example-svg,
body[data-theme="dark"] .preview-svg-host {
  background: #1a1f25 !important;
}

/* Common bordered detail blocks (per-part overrides etc.) */
body[data-theme="dark"] details > summary {
  color: #e5eef3 !important;
}

/* Inline status/error message backgrounds (jobs.html, etc.) */
body[data-theme="dark"] .error-msg,
body[data-theme="dark"] .alert-error {
  background: #4a1f24 !important;
  border-color: #864249 !important;
  color: #f3a4ab !important;
}
