:root {
  --spring: cubic-bezier(0.22, 1, 0.36, 1);
}

[data-mode="ivory"] {
  --bg: #F8F6F2;
  --surface: rgba(255, 255, 255, 0.92);
  --surface-solid: #FFFFFF;
  --ink: #1A1A1A;
  --muted: #6E6A64;
  --subtle: #9E9890;
  --border: rgba(26, 26, 26, 0.08);
  --border-strong: rgba(176, 92, 46, 0.30);
  --accent: #B05C2E;
  --accent-soft: rgba(176, 92, 46, 0.09);
  --glow: #C9933A;
  --glow-soft: rgba(201, 147, 58, 0.14);
  --green: #2F7D4E;
  --green-soft: rgba(47, 125, 78, 0.11);
}

[data-mode="obsidian"] {
  --bg: #13110F;
  --surface: rgba(30, 27, 23, 0.90);
  --surface-solid: #1E1B17;
  --ink: #FAF8F4;
  --muted: #A99F94;
  --subtle: #7A7167;
  --border: rgba(255, 255, 255, 0.09);
  --border-strong: rgba(201, 147, 58, 0.36);
  --accent: #C9933A;
  --accent-soft: rgba(201, 147, 58, 0.15);
  --glow: #E2B15B;
  --glow-soft: rgba(201, 147, 58, 0.16);
  --green: #34D399;
  --green-soft: rgba(52, 211, 153, 0.14);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  background: #DFD9CE;
  color: var(--ink);
  font-size: 13px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  padding: 16px;
}

.serif { font-family: 'DM Serif Display', Georgia, serif; font-weight: 400; }
.num { font-variant-numeric: tabular-nums; }
.mono { font-family: 'JetBrains Mono', monospace; }
.micro { font-size: 10px; font-weight: 700; letter-spacing: 1.25px; text-transform: uppercase; color: var(--subtle); }
.hidden { display: none !important; }

/* OS Shell */
.os-frame {
  position: relative;
  max-width: 1340px;
  margin: 0 auto;
  min-height: calc(100vh - 32px);
  background: var(--bg);
  color: var(--ink);
  border: 1px solid var(--border);
  border-radius: 24px;
  box-shadow: 0 32px 84px rgba(26, 26, 26, 0.16);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: background 0.35s var(--spring), color 0.35s var(--spring);
}

.blueprint-bg {
  position: absolute; inset: 0; pointer-events: none; z-index: 0;
  background-image:
    linear-gradient(to right, rgba(176, 92, 46, 0.035) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(176, 92, 46, 0.035) 1px, transparent 1px);
  background-size: 46px 46px;
  animation: gridDrift 28s linear infinite;
}
@keyframes gridDrift { from { background-position: 0 0; } to { background-position: 46px 46px; } }

/* Startup Window */
.startup {
  position: absolute; inset: 0; z-index: 90;
  background: radial-gradient(circle at 50% 22%, #FFFFFF 0%, #F8F6F2 74%);
  color: #1A1A1A;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 32px; perspective: 1200px;
  transition: opacity 0.65s var(--spring), transform 0.65s var(--spring);
}
.startup.out { opacity: 0; transform: scale(1.06); pointer-events: none; }
.st-ring-outer { position: relative; width: 88px; height: 88px; display: grid; place-items: center; animation: pop 0.7s var(--spring) both; }
.st-ring-outer::before {
  content: ""; position: absolute; inset: -6px; border-radius: 26px;
  border: 1.5px dashed rgba(176, 92, 46, 0.35);
  animation: spinSlow 18s linear infinite;
}
@keyframes spinSlow { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }
.st-logo {
  width: 68px; height: 68px; border-radius: 19px;
  background: #B05C2E; color: #fff;
  font-family: 'DM Serif Display', serif; font-size: 38px;
  display: grid; place-items: center;
  box-shadow: 0 18px 38px rgba(176, 92, 46, 0.32);
}
@keyframes pop { from { opacity: 0; transform: scale(0.6) translateY(16px); } to { opacity: 1; transform: scale(1) translateY(0); } }
@keyframes rise { from { opacity: 0; transform: translateY(18px); } to { opacity: 1; transform: translateY(0); } }

.role-switch {
  display: inline-flex; gap: 4px; background: rgba(26, 26, 26, 0.05);
  padding: 4px; border-radius: 999px; border: 1px solid rgba(26, 26, 26, 0.08);
  margin: 18px 0 8px; animation: rise 0.65s 0.12s var(--spring) both;
}
.role-btn {
  border: none; background: transparent; font-family: inherit;
  font-size: 12px; font-weight: 600; color: #6E6A64;
  padding: 6px 15px; border-radius: 999px; cursor: pointer; transition: all 0.22s var(--spring);
}
.role-btn.active { background: #1A1A1A; color: #fff; box-shadow: 0 4px 12px rgba(26, 26, 26, 0.16); }

.st-cards { display: grid; grid-template-columns: repeat(3, 272px); gap: 16px; margin-top: 22px; }
.st-card {
  background: rgba(255, 255, 255, 0.94); border: 1px solid rgba(26, 26, 26, 0.08);
  border-radius: 18px; padding: 20px; cursor: pointer; text-align: left;
  box-shadow: 0 8px 24px rgba(26, 26, 26, 0.05);
  transition: transform 0.22s var(--spring), border-color 0.22s, box-shadow 0.22s;
  animation: rise 0.65s var(--spring) both; transform-style: preserve-3d;
}
.st-card:nth-child(2) { animation-delay: 0.08s; }
.st-card:nth-child(3) { animation-delay: 0.16s; }
.st-card:hover { border-color: #B05C2E; box-shadow: 0 22px 42px rgba(176, 92, 46, 0.14); }
.st-jump-row { display: flex; gap: 6px; margin-top: 14px; padding-top: 12px; border-top: 1px solid rgba(26, 26, 26, 0.08); }
.st-jump {
  font-size: 11px; font-weight: 600; padding: 4px 10px; border-radius: 999px;
  background: #F8F6F2; color: #6E6A64; border: 1px solid rgba(26, 26, 26, 0.08);
  cursor: pointer; transition: all 0.15s;
}
.st-jump:hover { background: #B05C2E; color: #fff; border-color: #B05C2E; }

/* Top Floating Bar */
.top-bar {
  position: relative; z-index: 20;
  padding: 14px 24px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.glass-pill {
  background: var(--surface); backdrop-filter: blur(18px);
  border: 1px solid var(--border); border-radius: 999px;
  padding: 6px 14px; display: inline-flex; align-items: center; gap: 9px;
  box-shadow: 0 4px 14px rgba(26, 26, 26, 0.04); cursor: pointer;
}
.spotlight {
  flex: 1; max-width: 460px;
  background: var(--surface); backdrop-filter: blur(18px);
  border: 1px solid var(--border); border-radius: 999px;
  padding: 7px 16px; display: flex; align-items: center; gap: 10px;
  box-shadow: 0 4px 16px rgba(26, 26, 26, 0.04);
}
.spotlight input { border: none; outline: none; background: transparent; flex: 1; font-family: inherit; font-size: 12.5px; color: var(--ink); }

.btn {
  font-family: inherit; font-size: 12px; font-weight: 600;
  padding: 7px 14px; border-radius: 999px; border: 1px solid transparent;
  cursor: pointer; display: inline-flex; align-items: center; gap: 6px;
  transition: all 0.18s var(--spring);
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { transform: translateY(-1px); opacity: 0.92; }
.btn-soft { background: var(--surface-solid); color: var(--ink); border-color: var(--border); }
.btn-soft.on { background: var(--green-soft); color: var(--green); border-color: rgba(47, 125, 78, 0.28); }

/* Workspace Views */
.workspace { position: relative; z-index: 10; padding: 4px 24px 96px; flex: 1; display: flex; flex-direction: column; gap: 14px; }
.view { display: none; flex-direction: column; gap: 14px; animation: rise 0.4s var(--spring) both; }
.view.active { display: flex; }

.card {
  background: var(--surface); backdrop-filter: blur(14px);
  border: 1px solid var(--border); border-radius: 16px; padding: 18px 20px;
  box-shadow: 0 2px 12px rgba(26, 26, 26, 0.04);
  transition: transform 0.25s var(--spring), border-color 0.25s, box-shadow 0.25s;
}
.card:hover { transform: translateY(-2px); border-color: var(--border-strong); box-shadow: 0 12px 28px rgba(26, 26, 26, 0.07); }

.kpi-row { display: grid; grid-template-columns: repeat(5, 1fr); gap: 12px; }
.bento-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.bento-2 { display: grid; grid-template-columns: 1.25fr 1fr; gap: 14px; }

.pill { font-size: 10px; font-weight: 700; padding: 3px 8px; border-radius: 99px; text-transform: uppercase; letter-spacing: 0.4px; display: inline-block; }
.pill-green { background: var(--green-soft); color: var(--green); }
.pill-gold { background: var(--glow-soft); color: var(--glow); }
.pill-accent { background: var(--accent-soft); color: var(--accent); }

.live-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--green); display: inline-block; animation: pulse 1.8s infinite; }
@keyframes pulse { 0%, 100% { box-shadow: 0 0 0 0 rgba(47, 125, 78, 0.45); } 60% { box-shadow: 0 0 0 6px rgba(47, 125, 78, 0); } }

/* Animated 2D Plywood + 3D Isometric + S-Curve */
.ply-mini {
  background: var(--bg); border: 1.5px solid var(--ink); border-radius: 8px;
  height: 120px; padding: 6px;
  display: grid; grid-template-columns: 1.8fr 1fr 1fr; grid-template-rows: 1fr 1fr; gap: 5px;
}
.ply-b {
  background: var(--accent-soft); border: 1px solid var(--accent); border-radius: 4px;
  display: flex; align-items: center; justify-content: center;
  font-size: 10px; font-weight: 700; color: var(--accent);
  animation: plyPulse 3.2s ease-in-out infinite;
}
@keyframes plyPulse { 0%, 100% { opacity: 0.85; } 50% { opacity: 1; } }

.iso-stage {
  height: 150px; background: var(--bg); border: 1px solid var(--border);
  border-radius: 12px; display: grid; place-items: center; perspective: 700px; overflow: hidden;
  position: relative;
}
.iso-room {
  width: 120px; height: 120px; position: relative;
  transform-style: preserve-3d;
  transform: rotateX(55deg) rotateZ(45deg);
  animation: isoFloat 6s ease-in-out infinite;
}
@keyframes isoFloat {
  0%, 100% { transform: rotateX(55deg) rotateZ(45deg) translateZ(0px); }
  50% { transform: rotateX(57deg) rotateZ(48deg) translateZ(6px); }
}
.iso-floor { position: absolute; inset: 0; background: var(--accent-soft); border: 2px solid var(--accent); cursor: pointer; }
.iso-wall-a { position: absolute; top: 0; left: 0; width: 120px; height: 50px; background: rgba(255, 255, 255, 0.78); border: 1.5px solid var(--ink); transform-origin: top; transform: rotateX(-90deg); cursor: pointer; }
.iso-wall-b { position: absolute; top: 0; left: 0; width: 50px; height: 120px; background: var(--glow-soft); border: 1.5px solid var(--glow); transform-origin: left; transform: rotateY(90deg); cursor: pointer; }

.scan-line {
  position: absolute; left: 0; right: 0; height: 2px;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  animation: scanSweep 2.6s ease-in-out infinite;
}
@keyframes scanSweep { 0%, 100% { top: 10px; opacity: 0.3; } 50% { top: 136px; opacity: 1; } }

.travel-dot {
  offset-path: path("M0 108 C 90 104, 150 70, 230 48 C 310 26, 370 16, 440 10");
  animation: travel 4.5s ease-in-out infinite;
}
@keyframes travel { 0% { offset-distance: 0%; } 100% { offset-distance: 100%; } }

body.shield .sensitive { filter: blur(7px); opacity: 0.5; transition: all 0.25s; }

/* Tables & Inline Edit */
table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
th { text-align: left; font-size: 9.5px; font-weight: 700; letter-spacing: 1px; text-transform: uppercase; color: var(--subtle); padding: 0 0 8px; border-bottom: 1px solid var(--border); }
td { padding: 10px 0; border-bottom: 1px solid var(--border); }
tr:last-child td { border-bottom: none; }
.inline-edit {
  background: transparent; border: 1px solid transparent; color: var(--ink);
  font-family: 'JetBrains Mono', monospace; font-size: 12.5px;
  padding: 4px 6px; border-radius: 6px; width: 86px;
}
.inline-edit:hover, .inline-edit:focus { outline: none; background: var(--bg); border-color: var(--accent); }

.seg { display: inline-flex; gap: 2px; background: var(--bg); padding: 3px; border-radius: 999px; border: 1px solid var(--border); }
.seg-btn { border: none; background: transparent; font-family: inherit; font-size: 11.5px; font-weight: 600; color: var(--muted); padding: 5px 12px; border-radius: 999px; cursor: pointer; }
.seg-btn.active { background: var(--surface-solid); color: var(--accent); box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08); }

/* Master BOQ Ergonomic Drafting & Customization */
.boq-draft-bar {
  display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap;
  padding: 10px 14px; background: var(--bg); border: 1px solid var(--border); border-radius: 12px;
}
.boq-input {
  height: 32px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface-solid); color: var(--ink); padding: 0 10px;
  font-family: inherit; font-size: 12px;
}
.boq-input:focus { outline: none; border-color: var(--accent); }
.room-folio {
  border: 1px solid var(--border); border-radius: 14px; overflow: hidden;
  background: var(--surface-solid); margin-bottom: 12px;
}
.room-folio-head {
  padding: 11px 16px; background: var(--bg); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between; cursor: pointer;
}
.boq-compact td { padding: 6px 0 !important; font-size: 12px; }
.boq-watermark-tag {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%) rotate(-18deg);
  font-family: 'DM Serif Display', serif; font-size: 54px; letter-spacing: 6px;
  color: rgba(176, 92, 46, 0.06); pointer-events: none; user-select: none; white-space: nowrap;
}

.gantt-bar {
  height: 22px; border-radius: 6px; padding: 0 10px;
  display: flex; align-items: center; justify-content: space-between;
  font-size: 11px; font-weight: 600; color: #fff;
  transition: margin-left 0.3s var(--spring);
}

/* Floating Magnetic Spatial Dock */
.dock {
  position: absolute; bottom: 16px; left: 50%; transform: translateX(-50%); z-index: 50;
  background: var(--surface); backdrop-filter: blur(22px);
  border: 1px solid var(--border); border-radius: 20px;
  padding: 6px 8px; display: flex; gap: 4px;
  box-shadow: 0 16px 40px rgba(26, 26, 26, 0.14);
}
.dock-btn {
  border: none; background: transparent; font-family: inherit;
  padding: 8px 13px; border-radius: 13px; cursor: pointer;
  font-size: 12px; font-weight: 600; color: var(--muted);
  display: flex; align-items: center; gap: 6px; white-space: nowrap;
  transition: all 0.22s var(--spring);
}
.dock-btn:hover { background: var(--bg); color: var(--ink); transform: translateY(-6px) scale(1.08); }
.dock-btn.active { background: var(--accent); color: #fff; box-shadow: 0 6px 16px rgba(176, 92, 46, 0.28); }

/* Edition X Upgrades: 3D Hologram Canvas, Laser Cut Sheet & Voice DPR Wave */
.holo-stage-x {
  position: relative; height: 360px; border-radius: 14px; overflow: hidden;
  border: 1px solid var(--border);
  background: radial-gradient(circle at 50% 42%, rgba(201, 147, 58, 0.08), transparent 70%), var(--bg);
}
#holoTwinCanvas { width: 100%; height: 100%; display: block; cursor: grab; }
#holoTwinCanvas:active { cursor: grabbing; }
.holo-hud-top {
  position: absolute; top: 10px; left: 10px; right: 10px;
  display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap;
  pointer-events: none;
}
.holo-hud-top > * { pointer-events: auto; }
.holo-hud-bottom {
  position: absolute; bottom: 10px; left: 10px; right: 10px;
  display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap;
  pointer-events: none;
}
.holo-hud-bottom > * { pointer-events: auto; }
.holo-pod {
  background: var(--surface); backdrop-filter: blur(14px);
  border: 1px solid var(--border); border-radius: 12px;
  padding: 6px 12px; display: flex; align-items: center; gap: 10px;
}
#cutLaserCanvas {
  width: 100%; height: 255px; border-radius: 12px;
  border: 1px solid var(--border); background: var(--bg); display: block;
}
.wave { display: inline-flex; align-items: center; gap: 3px; height: 22px; }
.wave span {
  width: 3px; border-radius: 99px; background: var(--accent);
  animation: wavePulse 1.05s ease-in-out infinite;
}
@keyframes wavePulse { 0%, 100% { height: 5px; opacity: 0.4; } 50% { height: 20px; opacity: 1; } }

/* Slide-Over Inspector & Command Palette */
.drawer-bg { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.35); backdrop-filter: blur(4px); opacity: 0; pointer-events: none; transition: opacity 0.25s; z-index: 120; }
.drawer-bg.open { opacity: 1; pointer-events: auto; }
.drawer {
  position: fixed; top: 14px; right: 14px; bottom: 14px; width: 330px;
  background: var(--surface-solid); border: 1px solid var(--border-strong);
  border-radius: 18px; padding: 22px; z-index: 130;
  transform: translateX(370px); transition: transform 0.32s var(--spring);
  display: flex; flex-direction: column; gap: 16px;
}
.drawer.open { transform: translateX(0); }

.cmd-bg { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.45); backdrop-filter: blur(8px); display: none; place-items: start center; padding-top: 14vh; z-index: 140; }
.cmd-bg.open { display: grid; }
.cmd-box { width: 520px; max-width: 92vw; background: var(--surface-solid); border: 1px solid var(--border-strong); border-radius: 18px; overflow: hidden; }
.cmd-item { display: flex; justify-content: space-between; padding: 10px 16px; cursor: pointer; font-size: 13px; }
.cmd-item:hover { background: var(--accent-soft); color: var(--accent); }

.toast {
  position: fixed; bottom: 82px; left: 50%; transform: translateX(-50%) translateY(16px);
  background: var(--ink); color: #fff; padding: 9px 18px; border-radius: 999px;
  font-size: 12px; font-weight: 600; opacity: 0; pointer-events: none;
  transition: all 0.25s var(--spring); z-index: 150;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (max-width: 1020px) {
  .kpi-row { grid-template-columns: repeat(2, 1fr); }
  .bento-3, .bento-2, .st-cards { grid-template-columns: 1fr; }
  .dock { width: 94%; overflow-x: auto; }
}

@media print {
  @page { size: A4; margin: 14mm; }
  html, body { background: #fff !important; color: #1a1a1a !important; height: auto !important; overflow: visible !important; }
  .top-bar, .dock, .blueprint-bg, .startup, .drawer, .drawer-bg, .toast, .btn, .seg { display: none !important; }
  .os-frame, .workspace { position: static !important; height: auto !important; overflow: visible !important; padding: 0 !important; margin: 0 !important; width: 100% !important; }
  .card { box-shadow: none !important; border: 1px solid #d4cec4 !important; break-inside: avoid; }
  .cmd-bg.open { position: static !important; background: transparent !important; backdrop-filter: none !important; padding: 0 !important; }
  .cmd-box { box-shadow: none !important; border: none !important; width: 100% !important; max-height: none !important; }
}
