@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500;700&display=swap');

:root{
  --bg: #14171a;
  --panel: #1b2025;
  --panel-2: #20262c;
  --line: #2b323a;
  --line-soft: #232a30;
  --text: #e7ecef;
  --text-dim: #8b94a0;
  --text-faint: #5b6570;
  --accent: #00e5c7;
  --accent-dim: #0a3d38;
  --hazard: #ff7a1a;
  --hazard-dim: #4a2c10;
  --danger: #ff5757;
  --ok: #4ade80;
  --radius: 4px;
  --mono: 'JetBrains Mono', ui-monospace, 'SF Mono', Consolas, monospace;
  --sans: 'Inter', -apple-system, 'Segoe UI', sans-serif;
}

*{ box-sizing: border-box; }
html,body{ height:100%; margin:0; }
body{
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 13px;
  overflow: hidden;
}
button, input, select{ font-family: var(--sans); font-size: 12px; color: var(--text); }
::-webkit-scrollbar{ width:8px; height:8px; }
::-webkit-scrollbar-thumb{ background: var(--line); border-radius: 4px; }
::-webkit-scrollbar-track{ background: transparent; }

/* ---------- shell ---------- */
#app{ display:flex; flex-direction:column; height:100vh; }

.topbar{
  display:flex; align-items:center; gap:14px;
  padding: 8px 14px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  flex-shrink:0;
}
.brand{ display:flex; align-items:center; gap:9px; margin-right: 6px; }
.brand-mark{
  width:22px; height:22px; border-radius:3px;
  background: repeating-linear-gradient(45deg, var(--hazard) 0 4px, #1a1a1a 4px 8px);
  flex-shrink:0;
}
.brand-text{ font-weight:700; letter-spacing:0.3px; font-size:13px; }
.brand-sub{ color:var(--text-faint); font-size:10px; letter-spacing:1.2px; text-transform:uppercase; }

.topbar .field{ display:flex; flex-direction:column; gap:2px; }
.topbar label{ font-size:9px; text-transform:uppercase; letter-spacing:0.6px; color:var(--text-faint); }
.topbar input[type=text], .topbar select, .field-input{
  background: var(--panel-2); border:1px solid var(--line); color:var(--text);
  border-radius: var(--radius); padding:4px 7px; height:26px; min-width:70px;
}
.spacer{ flex:1; }

.btn{
  background: var(--panel-2); border:1px solid var(--line); color:var(--text);
  border-radius: var(--radius); padding:6px 12px; height:30px;
  cursor:pointer; display:inline-flex; align-items:center; gap:6px; white-space:nowrap;
  transition: border-color .12s, background .12s;
}
.btn:hover{ border-color: var(--accent); }
.btn:active{ transform: translateY(1px); }
.btn-primary{
  background: repeating-linear-gradient(135deg, var(--hazard) 0 10px, #b85a10 10px 20px);
  border: none; color:#14171a; font-weight:700;
}
.btn-primary:hover{ filter: brightness(1.08); }
.btn-accent{ border-color: var(--accent); color: var(--accent); }
.btn-ghost{ background: transparent; border-color: transparent; color: var(--text-dim); }
.btn-ghost:hover{ color: var(--text); }
.btn-sm{ height:24px; padding:3px 8px; font-size:11px; }
.btn-danger{ color: var(--danger); }
.btn:disabled{ opacity:.35; cursor:not-allowed; }

/* DRO strip */
.dro{
  display:flex; gap:0; background:#0f1214; border-bottom:1px solid var(--line);
  font-family: var(--mono); font-size:11px; flex-shrink:0;
}
.dro-cell{ padding:5px 16px; border-right:1px solid var(--line); color:var(--text-dim); }
.dro-cell b{ color: var(--accent); font-weight:600; }
.dro-cell.warn b{ color: var(--hazard); }

/* ---------- layout ---------- */
.main{ flex:1; display:flex; min-height:0; }
.panel{ background: var(--panel); display:flex; flex-direction:column; min-height:0; }
.panel-left{ width:290px; border-right:1px solid var(--line); }
.panel-right{ width:380px; border-left:1px solid var(--line); }
.panel-center{ flex:1; position:relative; background:
  linear-gradient(var(--line-soft) 1px, transparent 1px) 0 0/28px 28px,
  linear-gradient(90deg, var(--line-soft) 1px, transparent 1px) 0 0/28px 28px,
  #101317;
}

.tabs{ display:flex; border-bottom:1px solid var(--line); flex-shrink:0; }
.tab{ flex:1; padding:9px 0; text-align:center; cursor:pointer; color:var(--text-dim); font-size:11px; text-transform:uppercase; letter-spacing:0.5px; border-bottom:2px solid transparent; }
.tab.active{ color:var(--accent); border-bottom-color: var(--accent); }
.tab-content{ flex:1; overflow-y:auto; display:none; padding:10px; min-height:0; }
.tab-content.active{ display:block; }

/* ---------- feature list ---------- */
.group-title{ font-size:10px; text-transform:uppercase; letter-spacing:0.8px; color:var(--text-faint); margin: 12px 0 6px; display:flex; justify-content:space-between; }
.group-title:first-child{ margin-top:0; }
.feat-row{
  display:flex; align-items:center; gap:7px; padding:6px 8px; border-radius:var(--radius);
  border:1px solid transparent; cursor:pointer; font-size:12px;
}
.feat-row:hover{ background: var(--panel-2); border-color:var(--line); }
.feat-row.sel{ background: var(--accent-dim); border-color: var(--accent); }
.feat-row .tag{ font-family:var(--mono); font-size:10px; color:var(--text-faint); }
.feat-row .dot{ width:8px; height:8px; border-radius:50%; flex-shrink:0; }
.feat-empty{ color:var(--text-faint); font-size:11.5px; padding:14px 4px; line-height:1.5; }

.addop-bar{ display:flex; gap:6px; margin-top:10px; align-items:center; }
.addop-bar select{ flex:1; background:var(--panel-2); border:1px solid var(--line); color:var(--text); border-radius:var(--radius); height:28px; }

/* ---------- setup form ---------- */
.form-row{ display:flex; flex-direction:column; gap:3px; margin-bottom:10px; }
.form-row label{ font-size:10px; text-transform:uppercase; letter-spacing:0.5px; color:var(--text-faint); }
.form-row input, .form-row select{
  background: var(--panel-2); border:1px solid var(--line); color:var(--text);
  border-radius: var(--radius); padding:6px 8px; height:30px;
}
.form-2col{ display:grid; grid-template-columns:1fr 1fr; gap:8px; }
.checkbox-row{ display:flex; align-items:center; gap:7px; font-size:12px; color:var(--text-dim); }

/* ---------- operations list ---------- */
.op-card{ border:1px solid var(--line); border-radius:var(--radius); margin-bottom:8px; background:var(--panel-2); overflow:hidden; }
.op-head{ display:flex; align-items:center; gap:7px; padding:8px 9px; cursor:pointer; }
.op-head .badge{ font-family:var(--mono); font-size:9px; padding:2px 6px; border-radius:3px; text-transform:uppercase; }
.badge-drill{ background:#2b3350; color:#9db4ff; }
.badge-profile{ background:#1e3d38; color:var(--accent); }
.badge-pocket{ background:#3d2e1e; color:#ffb066; }
.badge-face{ background:#3a2438; color:#e08fd8; }
.op-head .name{ flex:1; font-size:12.5px; }
.op-head .tools{ display:flex; gap:3px; }
.op-body{ display:none; padding:10px; border-top:1px solid var(--line); }
.op-body.open{ display:block; }
.op-body .form-2col{ margin-bottom:8px; }
.op-body .form-row{ margin-bottom:8px; }
.op-body .form-row label{ font-size:9px; }
.op-body input, .op-body select{ height:26px; padding:4px 6px; font-size:11.5px; }

.empty-state{ color:var(--text-faint); font-size:12px; text-align:center; padding:30px 10px; line-height:1.6; }

/* ---------- center viewport ---------- */
.viewport-toolbar{
  position:absolute; top:10px; left:10px; display:flex; gap:6px; z-index:5;
}
.viewport-toolbar .btn{ background: rgba(27,32,37,0.9); backdrop-filter: blur(4px); }
.legend{
  position:absolute; bottom:10px; left:10px; z-index:5;
  background: rgba(27,32,37,0.9); border:1px solid var(--line); border-radius:var(--radius);
  padding:8px 12px; font-size:10.5px; color:var(--text-dim); display:flex; flex-direction:column; gap:4px;
}
.legend-item{ display:flex; align-items:center; gap:6px; }
.legend-swatch{ width:14px; height:2px; }
.empty-viewport{
  position:absolute; inset:0; display:flex; align-items:center; justify-content:center;
  flex-direction:column; gap:14px; color:var(--text-faint); text-align:center; pointer-events:none;
}
.empty-viewport .stripe{ width:64px; height:64px; border-radius:6px; background: repeating-linear-gradient(45deg, var(--line) 0 6px, transparent 6px 12px); }
svg#viewport-svg{ width:100%; height:100%; display:block; cursor:grab; }
svg#viewport-svg:active{ cursor:grabbing; }
canvas#viewport-3d{ display:block; cursor:grab; }
canvas#viewport-3d:active{ cursor:grabbing; }
.btn.view-active{ background: var(--accent-dim); border-color: var(--accent); color: var(--accent); }

/* ---------- code tab ---------- */
.code-actions{ display:flex; gap:6px; margin-bottom:8px; }
pre#gcode-out, textarea#gcode-out{
  font-family: var(--mono); font-size:11.5px; line-height:1.6; color:var(--text);
  background:#0f1214; border:1px solid var(--line); border-radius:var(--radius);
  padding:12px; white-space:pre-wrap; word-break:break-all; margin:0;
  max-height: calc(100vh - 320px); min-height:260px; overflow-y:auto;
  width:100%; resize:vertical;
}
textarea#gcode-out:focus{ outline:none; border-color:var(--accent); }
.stat-strip{ display:flex; gap:14px; margin-bottom:10px; font-size:11px; color:var(--text-dim); }
.stat-strip b{ color:var(--text); font-family:var(--mono); }

/* ---------- simulate tab ---------- */
.sim-controls{ display:flex; align-items:center; gap:8px; margin-bottom:10px; }
.sim-progress{ width:100%; }
.sim-op-line{ padding:5px 8px; border-radius:var(--radius); font-size:11.5px; color:var(--text-dim); }
.sim-op-line.current{ background: var(--accent-dim); color: var(--accent); }

.warn-banner{
  background: var(--hazard-dim); border:1px solid var(--hazard); color:#ffcf9e;
  border-radius: var(--radius); padding:8px 10px; font-size:11px; line-height:1.5; margin-bottom:10px;
}

input[type=range]{ accent-color: var(--accent); }
input[type=checkbox]{ accent-color: var(--accent); width:14px; height:14px; }

/* ---------- printable setup sheet ---------- */
#setup-sheet{ display:none; }
#setup-sheet h1{ font-size:20px; margin-bottom:4px; }
#setup-sheet h2{ font-size:14px; margin:18px 0 6px; border-bottom:1px solid #333; padding-bottom:4px; }
#setup-sheet table{ border-collapse: collapse; width:100%; margin-bottom:10px; }
#setup-sheet td, #setup-sheet th{ border:1px solid #999; padding:5px 8px; font-size:12px; text-align:left; }
#setup-sheet .ss-warn{ font-size:11px; margin-top:20px; border:1px solid #999; padding:8px; }

@media print{
  body *{ visibility:hidden; }
  #setup-sheet, #setup-sheet *{ visibility:visible; }
  #setup-sheet{ display:block; position:absolute; top:0; left:0; width:100%; color:#000; background:#fff; padding:20px; }
}

/* ---------- photo import modal ---------- */
.modal-overlay{
  position:fixed; inset:0; background:rgba(10,12,14,0.75); z-index:50;
  display:flex; align-items:center; justify-content:center;
}
.modal-box{
  background: var(--panel); border:1px solid var(--line); border-radius:6px;
  width:min(1180px, 96vw); max-height:92vh; overflow-y:auto;
}
.modal-head{ display:flex; justify-content:space-between; align-items:flex-start; padding:14px 16px; border-bottom:1px solid var(--line); }
.modal-body{ display:flex; gap:16px; padding:16px; flex-wrap:wrap; }
.modal-col-canvas{ flex:1; min-width:420px; }
.modal-col-controls{ width:300px; flex-shrink:0; }
#photo-canvas{ width:100%; height:auto; background:#0a0c0d; border:1px solid var(--line); border-radius:4px; cursor:crosshair; }
#photo-file{ margin-bottom:8px; color:var(--text-dim); font-size:12px; }
.photo-help{ margin-top:8px; font-size:11.5px; color:var(--accent); min-height:16px; }
