/* ============================================================
   CSiBridge — New Project (template parameter editor)
   Reuses the WinUI 3 / Fluent design language from startup.css.
   Tokens are re-declared here scoped to .np-overlay so this page is
   self-contained (same values as .startup-overlay). Theme follows the
   WebView color scheme via @media (prefers-color-scheme: dark), driven
   by the native title bar (see App.xaml.cs / WebBridge).
   ============================================================ */

.np-overlay {
  --radius-control: 4px;
  --radius-card: 6px;
  --radius-flyout: 7px;
  --panel-w: 460px;

  --font: "Segoe UI Variable Text", "Segoe UI Variable", "Segoe UI",
    -apple-system, system-ui, "Helvetica Neue", Arial, sans-serif;
  --font-display: "Segoe UI Variable Display", "Segoe UI Variable",
    "Segoe UI", -apple-system, system-ui, sans-serif;

  position: fixed;
  inset: 0;
  z-index: 1000;
  overflow: hidden;
  font-family: var(--font);
  color: var(--text-primary);
  font-size: 12px;
  line-height: 1.35;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
.np-overlay *,
.np-overlay *::before,
.np-overlay *::after { box-sizing: border-box; }

/* ---------- LIGHT (default) ---------- */
.np-overlay {
  --accent: #0067c0;
  --accent-hover: #1975c5;
  --accent-pressed: #3183cb;
  --accent-fill-text: #ffffff;

  --text-primary: rgba(0, 0, 0, 0.8956);
  --text-secondary: rgba(0, 0, 0, 0.6063);
  --text-tertiary: rgba(0, 0, 0, 0.4458);
  --text-disabled: rgba(0, 0, 0, 0.3614);

  --mica-base: #f3f3f3;
  --mica-tint: rgba(0, 103, 192, 0.05);
  --mica-tint-2: rgba(0, 103, 192, 0.035);

  --layer: #ffffff;
  --card: #ffffff;
  --card-secondary: #fbfbfb;
  --card-stroke: rgba(0, 0, 0, 0.0578);
  --border: 1px solid #CCC;   /* .mdl-card outline — matches the main page */

  --control-fill: rgba(255, 255, 255, 0.7);
  --control-fill-hover: rgba(249, 249, 249, 0.5);
  --control-fill-pressed: rgba(249, 249, 249, 0.3);
  --control-stroke: rgba(0, 0, 0, 0.0578);
  --control-stroke-bottom: rgba(0, 0, 0, 0.1622);

  --subtle-hover: rgba(0, 0, 0, 0.0373);
  --subtle-pressed: rgba(0, 0, 0, 0.0241);
  --subtle-selected: rgba(0, 0, 0, 0.0606);

  --divider: rgba(0, 0, 0, 0.0803);
  --flyout: #fcfcfc;
  --flyout-stroke: rgba(0, 0, 0, 0.0578);

  --shadow-card: 0 1px 3px rgba(0, 0, 0, 0.08), 0 0.3px 0.9px rgba(0, 0, 0, 0.06);
  --shadow-flyout: 0 8px 16px rgba(0, 0, 0, 0.14), 0 0 1px rgba(0, 0, 0, 0.12);

  --ok: #0f7b0f;
  --error: #c42b1c;
}

/* ---------- DARK ---------- */
@media (prefers-color-scheme: dark) {
  .np-overlay {
    --accent: #4cc2ff;
    --accent-hover: #47b1e8;
    --accent-pressed: #42a1d2;
    --accent-fill-text: #00131f;

    --text-primary: #ffffff;
    --text-secondary: rgba(255, 255, 255, 0.786);
    --text-tertiary: rgba(255, 255, 255, 0.5442);
    --text-disabled: rgba(255, 255, 255, 0.3628);

    --mica-base: #202020;
    --mica-tint: rgba(76, 194, 255, 0.06);
    --mica-tint-2: rgba(76, 194, 255, 0.04);

    --layer: #272727;
    --card: #2b2b2b;
    --card-secondary: #2d2d2d;
    --card-stroke: rgba(255, 255, 255, 0.0837);
    --border: 1px solid #555555;   /* .mdl-card outline — matches the main page */

    --control-fill: rgba(255, 255, 255, 0.0605);
    --control-fill-hover: rgba(255, 255, 255, 0.0837);
    --control-fill-pressed: rgba(255, 255, 255, 0.0326);
    --control-stroke: rgba(255, 255, 255, 0.0698);
    --control-stroke-bottom: rgba(255, 255, 255, 0.0954);

    --subtle-hover: rgba(255, 255, 255, 0.0605);
    --subtle-pressed: rgba(255, 255, 255, 0.0419);
    --subtle-selected: rgba(255, 255, 255, 0.0837);

    --divider: rgba(255, 255, 255, 0.0837);
    --flyout: #2c2c2c;
    --flyout-stroke: rgba(255, 255, 255, 0.0698);

    --shadow-card: 0 1px 3px rgba(0, 0, 0, 0.28), 0 0.3px 0.9px rgba(0, 0, 0, 0.22);
    --shadow-flyout: 0 8px 16px rgba(0, 0, 0, 0.4), 0 0 1px rgba(0, 0, 0, 0.5);

    --ok: #6ccb5f;
    --error: #ff99a4;
  }
}

/* ============================================================
   Window shell
   ============================================================ */
.np-window {
  position: relative;
  height: 100%;
  display: flex;
  flex-direction: row;            /* shared nav on the left, content frame on the right */
  padding-left: 4px;
  background:
    radial-gradient(135% 110% at 12% -10%, var(--mica-tint), transparent 55%),
    radial-gradient(120% 130% at 105% 115%, var(--mica-tint-2), transparent 50%),
    var(--mica-base);
}

/* Right-hand content frame (solid Layer with rounded top-left), mirroring the
   Startup screen's .content. Holds the title, toolbar, status and body. */
.np-content {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  background: var(--layer);
  border-top-left-radius: 8px;
  border-left: 1px solid var(--card-stroke);
  border-top: 1px solid var(--card-stroke);
  overflow: hidden;
}

.np-titlebar { padding: 14px 24px; }
.np-title {
  font-family: var(--font-display);
  font-size: 20px; font-weight: 600;
  margin: 0; letter-spacing: -0.2px;
}

/* ============================================================
   Toolbar
   ============================================================ */
.np-toolbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 8px 20px 10px;
}
.np-toolbar-left, .np-toolbar-right { display: flex; align-items: center; gap: 8px; }
.np-toolbar-sep { width: 1px; height: 22px; background: var(--divider); margin: 0 2px; }

.np-btn {
  height: 30px; padding: 0 14px;
  background: var(--control-fill);
  border: 1px solid var(--control-stroke);
  border-bottom-color: var(--control-stroke-bottom);
  border-radius: var(--radius-control);
  color: var(--text-primary); cursor: pointer;
  font-family: inherit; font-size: 12px; font-weight: 600;
}
.np-btn:hover { background: var(--control-fill-hover); }
.np-btn:active { background: var(--control-fill-pressed); color: var(--text-secondary); }
.np-btn-accent {
  background: var(--accent); color: var(--accent-fill-text);
  border-color: transparent;
}
.np-btn-accent:hover { background: var(--accent-hover); color: var(--accent-fill-text); }
.np-btn-accent:active { background: var(--accent-pressed); }

.np-icon-btn {
  width: 32px; height: 30px;
  display: grid; place-items: center;
  background: transparent; border: 1px solid transparent;
  border-radius: var(--radius-control);
  color: var(--text-secondary); cursor: pointer;
}
.np-icon-btn:hover { background: var(--subtle-hover); color: var(--text-primary); }
.np-icon-btn:active { background: var(--subtle-pressed); }
.np-icon-btn svg { width: 18px; height: 18px; }

/* ============================================================
   Panel action bar (Update Display / Cancel / Generate) — pinned to the top of
   the properties panel, WinUI-style. Contained within the panel's width; the
   primary "Generate" action wraps to its own full-width row.
   ============================================================ */
.np-panel-actions {
  position: sticky; top: 0; z-index: 5;
  display: flex; flex-wrap: wrap; gap: 8px;
  padding: 10px 12px;
  background: var(--layer);
  border-bottom: 1px solid var(--divider);
}
.np-panel-actions .np-btn { flex: 0 0 auto; }
.np-panel-actions .np-btn-accent { flex: 1 1 40%; }

/* ============================================================
   Status line
   ============================================================ */
.np-status {
  margin: 0 20px 8px; padding: 6px 12px;
  border-radius: var(--radius-control); font-size: 11.5px;
  border: 1px solid var(--card-stroke); background: var(--card-secondary);
}
.np-status.is-ok { color: var(--ok); }
.np-status.is-error { color: var(--error); }
/* Inside the panel (below the action bar), inset consistently with the cards. */
.np-panel .np-status { margin: 8px 8px 0; }

/* ============================================================
   Body — panel + viewport
   ============================================================ */
.np-body {
  flex: 1 1 auto; min-height: 0;
  display: flex; gap: 0;
  padding: 0;
}

/* ---- Parameter panel ---- */
.np-panel {
  border: var(--border);
  width: var(--panel-w); flex: 0 0 var(--panel-w);
  overflow-y: auto; overflow-x: hidden;
  /* Inner .mdl-prop-body supplies the 8px card padding; leave only bottom room. */
  padding: 0 0 16px;
  margin: 0 0 8px 8px;
  display: flex; flex-direction: column;
}
.np-panel::-webkit-scrollbar { width: 10px; }
.np-panel::-webkit-scrollbar-thumb {
  background: var(--text-disabled); border-radius: 5px;
  border: 3px solid transparent; background-clip: padding-box;
}
.np-panel::-webkit-scrollbar-track { background: transparent; }

/* ---- Drag-to-resize splitter between panel and viewport ---- */
.np-splitter {
  flex: 0 0 6px;
  position: relative;
  z-index: 2;
  cursor: e-resize;
  background: transparent;
  align-self: stretch;
}
/* The visible 1px divider, centered in the 6px hit area. */
.np-splitter::before {
  content: "";
  position: absolute;
  top: 0; bottom: 0; left: 50%;
  width: 1px;
  transform: translateX(-50%);
  background: var(--card-stroke);
  transition: background 0.12s ease, width 0.12s ease;
}
.np-splitter:hover::before,
.np-splitter.is-dragging::before {
  width: 2px;
  background: var(--accent);
}

/* ---- Collapsible card ---- */
.np-card {
  /* The panel is a flex column; without this, cards get flex-shrink:1 and are
     squashed to fit the panel height instead of overflowing — which clips each
     card's content mid-row and defeats the panel's scrollbar. Keeping natural
     height lets .np-panel's overflow-y:auto scroll the whole list. */
  flex: 0 0 auto;
  background: var(--card);
  border: 1px solid var(--card-stroke);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  overflow: hidden;
}
.np-card-head {
  width: 100%; height: 38px;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 12px; border: 0; background: transparent; cursor: pointer;
  color: var(--text-primary); font-family: inherit; text-align: left;
}
.np-card-head:hover { background: var(--subtle-hover); }
.np-card-title { font-family: var(--font-display); font-size: 13px; font-weight: 600; }
.np-card-chevron { color: var(--text-secondary); display: grid; place-items: center; transition: transform 0.18s ease; }
.np-card-chevron svg { width: 12px; height: 12px; }
.np-card.collapsed .np-card-chevron { transform: rotate(-90deg); }

/* Collapse animation: clip the body with overflow + max-height. Unlike the
   grid `0fr` trick (whose track keeps a min-content minimum, leaving a one-line
   sliver), max-height:0 + overflow:hidden hides the body completely regardless
   of how many children it has. 1200px comfortably exceeds any card's content. */
.np-card-body {
  overflow: hidden;
  max-height: 1200px;
  transition: max-height 0.22s ease;
}
.np-card.collapsed .np-card-body { max-height: 0; }
.np-card-body-inner { padding: 2px 12px 12px; }

.np-subhead {
  font-family: var(--font-display);
  font-size: 11px; font-weight: bold; font-style: italic;
  color: var(--text-secondary);
  margin: 10px 0 4px; padding-bottom: 3px;
  border-bottom: 1px solid var(--divider);
}
.np-subhead:first-child { margin-top: 2px; }

/* ============================================================
   Field rows
   ============================================================ */
.np-field {
  display: grid;
  grid-template-columns: 1fr 168px;
  align-items: center; gap: 8px;
  margin-left: 12px;
  min-height: 30px; padding: 3px 0;
}
.np-field.is-disabled { opacity: 0.55; }
.np-field-label {
  font-size: 12px; color: var(--text-primary);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.np-input, .np-select {
  width: 100%; height: 26px;
  background: var(--control-fill);
  border: 1px solid var(--control-stroke);
  border-bottom-color: var(--control-stroke-bottom);
  border-radius: var(--radius-control);
  color: var(--text-primary);
  font-family: inherit; font-size: 12px;
  padding: 0 8px;
}
.np-input:focus, .np-select:focus {
  outline: none;
  border-bottom: 2px solid var(--accent);
  padding-bottom: 0;
}
.np-input:disabled, .np-select:disabled { color: var(--text-disabled); cursor: not-allowed; }

.np-input-wrap { position: relative; display: flex; align-items: center; }
.np-input-wrap .np-input { padding-right: 28px; }
.np-unit {
  position: absolute; right: 8px;
  font-size: 11px; color: var(--text-tertiary); pointer-events: none;
}

.np-readonly {
  font-size: 12px; color: var(--text-secondary);
  height: 26px; display: flex; align-items: center;
  padding: 0 4px; font-style: italic;
}

/* ---- Checkbox (Fluent) ---- */
.np-check {
  display: inline-flex; align-items: center; cursor: pointer;
  justify-self: start;
}
.np-check input { position: absolute; opacity: 0; width: 0; height: 0; }
.np-check-box {
  width: 18px; height: 18px;
  border: 1px solid var(--control-stroke-bottom);
  border-radius: var(--radius-control);
  background: var(--control-fill);
  display: grid; place-items: center;
  color: transparent;
}
.np-check-box svg { width: 12px; height: 12px; }
.np-check input:checked + .np-check-box {
  background: var(--accent); border-color: var(--accent); color: var(--accent-fill-text);
}
.np-check input:focus-visible + .np-check-box { outline: 2px solid var(--accent); outline-offset: 1px; }

/* ============================================================
   3D viewport
   ============================================================ */
.np-viewport {
  border: var(--border);
  flex: 1 1 auto; min-width: 0;
  display: flex; flex-direction: column; /* hosts the <BridgeViewport3D> (toolbar + canvas) */
  background: var(--layer);
  /* divider is provided by .np-splitter */
  position: relative;
  margin: 0 8px 8px 0;
  overflow: hidden;
}
.np-viewport-canvas { position: absolute; inset: 0; }
/* Pin the WebGL canvas to its container's CSS size. Viewport3D calls
   renderer.setSize(w, h, false), which sizes the drawing buffer to
   w × devicePixelRatio (crisp on HiDPI) but does NOT set the canvas CSS size.
   Without this rule the canvas displays at its buffer size — 1.5× too large on
   a 1.5-DPI screen — so it overflows and the camera aspect / zoom-fit no longer
   match what's shown. width/height:100% makes the displayed size track the
   container regardless of DPI. */
.np-viewport-canvas canvas {
  display: block;
  width: 100% !important;
  height: 100% !important;
}

/* ---- One-line performance HUD (bottom-right), injected by Hud.ts ---- */
.np-overlay .bridge-hud {
  position: absolute;
  right: 10px;
  bottom: 10px;
  z-index: 6;
  pointer-events: none;           /* never blocks orbit/pan over the canvas */
  -webkit-user-select: none;
  user-select: none;
  white-space: nowrap;
  font-family: "Cascadia Code", "Cascadia Mono", ui-monospace, Consolas, monospace;
  font-size: 11px;
  line-height: 1;
  color: var(--text-secondary);
  background: var(--flyout);
  border: 1px solid var(--flyout-stroke);
  border-radius: var(--radius-control);
  box-shadow: var(--shadow-card);
  padding: 5px 9px;
}

/* ---- Viewport toolbar overlay injected by Viewport3D.ts ---- */
.np-overlay .viewport-toolbar {
  position: absolute; top: 10px; left: 10px;
  display: flex; flex-direction: column; gap: 4px;
  z-index: 5; pointer-events: auto;
}
.np-overlay .viewport-toolbar button {
  width: 32px; height: 32px;
  display: grid; place-items: center;
  background: var(--flyout);
  border: 1px solid var(--flyout-stroke);
  border-radius: var(--radius-control);
  box-shadow: var(--shadow-card);
  color: var(--text-secondary); cursor: pointer;
}
.np-overlay .viewport-toolbar button:hover { background: var(--control-fill-hover); color: var(--text-primary); }
.np-overlay .viewport-toolbar button:active { background: var(--control-fill-pressed); }
.np-overlay .viewport-toolbar button.is-active { color: var(--accent); border-color: var(--accent); }
.np-overlay .viewport-toolbar svg { width: 18px; height: 18px; }
