:root {
  --paper: #f4f6f3;
  --panel: #fff;
  --ink: #1b2528;
  --muted: #637174;
  --line: #d4ddda;
  --teal: #007b72;
  --amber: #c98e2d;
  --shadow: 0 14px 38px rgba(27, 37, 40, .09);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--paper); color: var(--ink); }
a { color: inherit; text-decoration: none; }
button, input { font: inherit; }

.topbar {
  position: static;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 18px;
  align-items: center;
  padding: 12px 22px;
  border-bottom: 1px solid var(--line);
  background: #f4f6f3;
}

.brand { display: flex; align-items: center; gap: 11px; }
.brand span {
  width: 42px;
  height: 42px;
  border-radius: 8px;
  background: var(--ink);
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 1000;
}
.brand small { display: block; color: var(--muted); font-weight: 800; }
.nav { display: flex; justify-content: center; gap: 10px; flex-wrap: wrap; }
.nav a,
.langs button,
.viewer-actions button,
.plain-link,
.primary-link,
.transfer-actions button {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  padding: 9px 12px;
  font-weight: 900;
}
.langs { display: flex; gap: 6px; }
.langs .on,
.primary-link {
  background: var(--ink);
  border-color: var(--ink);
  color: #fff;
}

.viewer-page {
  display: grid;
  gap: 12px;
  padding: 14px;
}
.viewer-intro,
.viewer-actions,
.viewer-shell,
.fallback-panel,
.transfer-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}
.viewer-intro {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 280px;
  gap: 14px;
  align-items: center;
  padding: 16px;
}
.eyebrow {
  margin: 0 0 8px;
  color: var(--teal);
  font-size: .76rem;
  font-weight: 1000;
  letter-spacing: .08em;
  text-transform: uppercase;
}
.viewer-intro h1 { margin: 0; font-size: clamp(1.9rem, 3.5vw, 4rem); line-height: .98; letter-spacing: 0; }
.viewer-intro p:not(.eyebrow) { margin: 10px 0 0; color: var(--muted); line-height: 1.55; max-width: 860px; }
.status-card {
  display: grid;
  gap: 6px;
  justify-items: end;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f9fbfa;
  padding: 12px;
}
.status-card span { color: var(--muted); font-weight: 900; }
.status-card b { color: var(--teal); text-align: right; overflow-wrap: anywhere; }

.viewer-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  padding: 12px;
}
.file-action {
  position: relative;
  display: inline-flex;
  min-height: 42px;
  align-items: center;
  border: 1px dashed var(--line);
  border-radius: 8px;
  padding: 10px 14px;
  background: #f9fbfa;
  font-weight: 1000;
  overflow: hidden;
  cursor: pointer;
}
.primary-file { border-color: rgba(0, 123, 114, .45); background: #edf6f3; }
.transfer-file { border-color: rgba(201, 142, 45, .55); background: #fffaf0; }
.file-action input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.transfer-panel {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 16px;
  align-items: center;
  padding: 14px;
}
.transfer-panel[hidden] { display: none; }
.transfer-panel h2 { margin: 0 0 8px; }
.transfer-panel p { color: var(--muted); line-height: 1.45; margin: 0; }
.transfer-summary { color: var(--ink) !important; font-weight: 1000; margin: 8px 0 !important; }
.transfer-card {
  display: grid;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f9fbfa;
  padding: 12px;
}
.transfer-card span { color: var(--muted); font-weight: 900; }
.transfer-card b { overflow-wrap: anywhere; }
.transfer-actions { display: flex; flex-wrap: wrap; gap: 8px; }

.viewer-shell {
  overflow: visible;
  isolation: isolate;
}
.viewer-head,
.fallback-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 14px;
  align-items: center;
  padding: 14px;
  border-bottom: 1px solid var(--line);
  background: #fbfcfb;
}
.viewer-head h2,
.fallback-head h2 { margin: 0; }
.viewer-meta {
  display: grid;
  gap: 5px;
  text-align: right;
  color: var(--muted);
  font-size: .84rem;
  font-weight: 900;
}
.mlightcad-mount {
  position: relative;
  z-index: 10;
  height: 760px;
  min-height: 68vh;
  background: #11181b;
}
.mlightcad-mount .ml-cad-viewer { height: 100%; }
.mlightcad-mount :is(.el-popper, .el-dropdown-popper, .el-menu, .el-sub-menu, .dropdown-menu, .ant-dropdown, [role="menu"], [role="toolbar"], [class*="toolbar"], [class*="menu"]) {
  z-index: 20000 !important;
}

.fallback-panel {
  display: grid;
  gap: 10px;
  padding-bottom: 12px;
  overflow: hidden;
}
.fallback-panel[hidden] { display: none; }
.fallback-panel p {
  margin: 0 14px;
  color: var(--muted);
  line-height: 1.45;
  font-weight: 800;
}
.fallback-head span {
  color: var(--teal);
  font-weight: 1000;
}
#viewerFallbackSvg {
  width: calc(100% - 28px);
  height: 420px;
  margin: 0 14px;
  display: block;
  border: 1px solid rgba(27, 37, 40, .16);
  border-radius: 8px;
  background: #0c1113;
}
#viewerFallbackSvg .fallback-line {
  stroke: #f6fbfb;
  stroke-width: 2.8px;
  stroke-linecap: round;
  stroke-linejoin: round;
  fill: none;
  vector-effect: non-scaling-stroke;
}
#viewerFallbackSvg .fallback-grid {
  stroke: rgba(255, 255, 255, .12);
  stroke-width: 1px;
  vector-effect: non-scaling-stroke;
}

@media (max-width: 900px) {
  .topbar,
  .viewer-intro,
  .transfer-panel,
  .viewer-head,
  .fallback-head {
    grid-template-columns: 1fr;
  }
  .nav { justify-content: flex-start; }
  .status-card,
  .viewer-meta { justify-items: start; text-align: left; }
  .mlightcad-mount { min-height: 64vh; height: 680px; }
}
