/* Context Canvas — cloud webui — emergenesis earthy-light palette
   Ported from v1.5/public/style.css with palette swap to align with the
   instant-prototype form theme (warm parchment + forest green accent).
   Geometry, layout, drag-handle behaviour and pane animations are unchanged. */

:root {
  /* Surface — warm paper instead of pure white so the canvas reads as a
     workspace, not an app. Cards stay pure white for content legibility. */
  --bg: #faf7f1;
  --surface: #ffffff;
  --surface-2: #f0ebe2;
  --surface-hover: #e6e0d4;

  /* Ink — warm dark brown, easier on the eyes than #1F1F1C on cream. */
  --ink: #2c2416;
  --ink-2: #4a3f2e;
  --muted: #6b5f4f;
  --muted-2: #9a8e7c;

  /* Lines — derived from --surface so dividers feel like creases, not borders. */
  --border: #d5ccba;
  --border-strong: #bfb39c;
  --grid: #ece5d4;
  --grid-major: #ddd2bb;

  /* Brand — forest green primary; matches L2 tier intentionally so buttons
     and L2 panes share a visual language (the operator's primary tier). */
  --brand: #4a7c59;
  --brand-2: #3e6d4d;
  --brand-tint: #e8eee9;

  /* Accent — rust/copper for pinned panes and warm highlights. */
  --accent: #b06840;
  --accent-tint: #f5e8df;

  /* Semantic — re-tinted to stay coherent on cream. */
  --info: #5b8a8a;
  --info-tint: #e6efef;
  --success: #4a7c59;
  --success-tint: #e8eee9;
  --warn: #b8963e;
  --warn-tint: #f7eed5;
  --error: #b04030;
  --error-tint: #f5dfd9;

  /* Tiers — aligned with the link-edge gradients in index.html so a
     brown→green line visibly carries L3→L2 colour. */
  --l1: #9a8e7c;
  --l2: #4a7c59;
  --l3: #8b7355;
  --pres: #b06840;
  --widget: #5b8a8a;
  --widget-tint: #e6efef;

  /* Effects */
  --shadow-xs: 0 1px 2px rgba(44, 36, 22, 0.05);
  --shadow-sm: 0 1px 2px rgba(44, 36, 22, 0.04), 0 1px 3px rgba(44, 36, 22, 0.06);
  --shadow-md: 0 4px 10px rgba(44, 36, 22, 0.06), 0 8px 24px rgba(44, 36, 22, 0.08);
  --shadow-lg: 0 12px 32px rgba(44, 36, 22, 0.14);
  --shadow-pane: 0 1px 0 rgba(44, 36, 22, 0.04), 0 4px 14px rgba(44, 36, 22, 0.06);
  --shadow-pane-drag: 0 18px 48px rgba(44, 36, 22, 0.18);

  --radius: 8px;
  --radius-sm: 6px;
  --radius-xs: 4px;

  --font-serif: "Fraunces", "Source Serif 4", "Iowan Old Style", Georgia, "Times New Roman", serif;
  --font-sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-sans);
  font-feature-settings: "ss01", "cv11";
  font-size: 13px;
  overflow: hidden;
}

/* --- Auth gate — only visible until Supabase reports SIGNED_IN ---
   The canvas DOM is rendered eagerly and hidden via body:not(.signed-in)
   so the gate doesn't depend on JS to mount its own children. */

#auth-gate {
  position: fixed;
  inset: 0;
  z-index: 500;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
body.signed-in #auth-gate { display: none; }

.auth-card {
  width: min(400px, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 28px 26px 24px;
  box-shadow: var(--shadow-md);
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.auth-brand {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 4px;
}
.auth-brand .brand-mark {
  font-family: var(--font-serif);
  font-weight: 600;
  font-size: 17px;
  color: var(--brand);
}
.auth-brand .brand-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--accent);
  display: inline-block;
}
.auth-brand .brand-product {
  font-family: var(--font-serif);
  font-style: italic;
  color: var(--muted);
  font-size: 13px;
}

.auth-title {
  font-family: var(--font-serif);
  font-weight: 500;
  font-size: 22px;
  margin: 0;
  color: var(--ink);
  letter-spacing: -0.01em;
}

.auth-help {
  margin: 0;
  color: var(--muted);
  font-size: 12.5px;
  line-height: 1.5;
}

#auth-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 4px;
}
#auth-email {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 13.5px;
  outline: none;
  transition: border-color 120ms, box-shadow 120ms;
}
#auth-email:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-tint);
}
#auth-submit {
  background: var(--brand);
  color: #fff;
  border: 1px solid var(--brand);
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-family: var(--font-sans);
  font-weight: 500;
  font-size: 13.5px;
  cursor: pointer;
  transition: background 120ms;
}
#auth-submit:hover { background: var(--brand-2); border-color: var(--brand-2); }
#auth-submit:disabled { background: var(--muted-2); border-color: var(--muted-2); cursor: not-allowed; }

.auth-status {
  font-size: 12px;
  font-family: var(--font-mono);
  color: var(--muted);
  min-height: 16px;
}
.auth-status.error { color: var(--error); }
.auth-status.success { color: var(--success); }

/* --- Top-right toolbar (signed-in only) --- */

#toolbar {
  position: fixed;
  top: 12px;
  right: 14px;
  z-index: 60;
  display: flex;
  align-items: center;
  gap: 8px;
}
body:not(.signed-in) #toolbar { display: none; }

.runner-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: 0.02em;
  color: var(--muted);
  user-select: none;
}
.runner-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--muted-2);
  flex-shrink: 0;
}
.runner-status.status-online {
  color: var(--success);
  border-color: var(--success);
  background: var(--success-tint);
}
.runner-status.status-online .runner-dot {
  background: var(--success);
  box-shadow: 0 0 0 2px var(--success-tint);
  animation: pulse 1.8s ease-in-out infinite;
}
.runner-status.status-offline {
  color: var(--error);
  border-color: var(--error);
  background: var(--error-tint);
}
.runner-status.status-offline .runner-dot { background: var(--error); }
.runner-status.status-restarting {
  color: var(--warn);
  border-color: var(--warn);
  background: var(--warn-tint);
}
.runner-status.status-restarting .runner-dot {
  background: var(--warn);
  animation: pulse 1s ease-in-out infinite;
}

.toolbar-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: background 120ms, border-color 120ms, color 120ms;
}
.toolbar-btn:hover {
  background: var(--surface-hover);
  border-color: var(--border-strong);
}
.toolbar-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.toolbar-btn .icon { width: 13px; height: 13px; }
.toolbar-btn.ghost {
  background: transparent;
  color: var(--muted);
}
.toolbar-btn.ghost:hover {
  background: var(--surface-hover);
  color: var(--ink);
}

/* --- Canvas — warm paper grid --- */

#canvas {
  position: fixed;
  inset: 0;
  background-color: var(--bg);
  background-image:
    linear-gradient(to right, var(--grid) 1px, transparent 1px),
    linear-gradient(to bottom, var(--grid) 1px, transparent 1px),
    linear-gradient(to right, var(--grid-major) 1px, transparent 1px),
    linear-gradient(to bottom, var(--grid-major) 1px, transparent 1px);
  background-size: 24px 24px, 24px 24px, 120px 120px, 120px 120px;
  background-position: 0 0;
  overflow: hidden;
  cursor: grab;
}
body:not(.signed-in) #canvas,
body:not(.signed-in) #brand,
body:not(.signed-in) #status-bar { display: none; }

body.canvas-panning,
body.canvas-panning #canvas { cursor: grabbing; }

#canvas-viewport {
  position: absolute;
  inset: 0;
  transform-origin: 0 0;
  transform: translate(0px, 0px) scale(1);
  will-change: transform;
}

#links {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 1;
  overflow: visible;
}

#panes { position: absolute; inset: 0; z-index: 2; }

/* --- Brand mark (top-left overlay) --- */

#brand {
  position: fixed;
  top: 14px;
  left: 18px;
  z-index: 60;
  display: flex;
  align-items: baseline;
  gap: 10px;
  pointer-events: none;
  user-select: none;
}
#brand .brand-mark {
  font-family: var(--font-serif);
  font-weight: 600;
  font-size: 18px;
  letter-spacing: 0.02em;
  color: var(--brand);
  font-variation-settings: "opsz" 32, "SOFT" 30;
}
#brand .brand-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  display: inline-block;
  transform: translateY(-2px);
}
#brand .brand-product {
  font-family: var(--font-serif);
  font-style: italic;
  font-size: 14px;
  color: var(--muted);
  font-variation-settings: "opsz" 14;
}

/* --- Zoom indicator --- */

#zoom-indicator {
  position: fixed;
  bottom: 38px;
  right: 14px;
  z-index: 60;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 4px 10px;
  font-size: 11px;
  font-family: var(--font-mono);
  color: var(--muted);
  pointer-events: none;
  user-select: none;
  box-shadow: var(--shadow-xs);
}

/* --- Dock --- */

#dock {
  position: absolute;
  bottom: 38px;
  left: 16px;
  right: 16px;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  z-index: 3;
  min-height: 0;
}
#dock:empty { display: none; }

/* --- Pane --- */

.pane {
  position: absolute;
  width: 380px;
  height: 480px;
  min-width: 260px;
  min-height: 180px;
  max-height: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-pane);
  overflow: hidden;
  transition: border-color 160ms, box-shadow 160ms;
  cursor: default;
  resize: none;
}
.pane:hover { box-shadow: var(--shadow-md); }
.pane.dragging {
  z-index: 50;
  box-shadow: var(--shadow-pane-drag);
  transition: none;
}

.pane.minimized {
  position: relative;
  width: 280px;
  min-height: 0;
  max-height: none;
  height: auto;
  left: auto !important;
  top: auto !important;
}
.pane.minimized .pane-diag,
.pane.minimized .pane-body { display: none; }

/* Tier accent — left rail keeps borders neutral, color stays distinct */
.pane { border-left-width: 3px; }
.pane.tier-L1 { border-left-color: var(--l1); }
.pane.tier-L2 { border-left-color: var(--l2); }
.pane.tier-L3 { border-left-color: var(--l3); }

.pane.status-error { border-color: var(--error); border-left-color: var(--error); }
.pane.status-error .pane-header { background: var(--error-tint); }
.pane.status-done { opacity: 0.78; }

/* Cloud-only: a session whose runner can't reach it (offline) shows
   a softened state with an explanatory banner. */
.pane.status-pending {
  border-style: dashed;
  opacity: 0.92;
}

.pane-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 10px 9px 12px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  user-select: none;
  cursor: grab;
}
.pane-header:active { cursor: grabbing; }
.pane-header button { cursor: pointer; }

.tier-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 26px;
  padding: 2px 7px;
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 10px;
  letter-spacing: 0.06em;
  border-radius: var(--radius-xs);
  background: var(--ink);
  color: #fff;
  text-transform: uppercase;
}
.tier-badge.tier-L1 { background: var(--l1); }
.tier-badge.tier-L2 { background: var(--l2); }
.tier-badge.tier-L3 { background: var(--l3); }
.tier-badge.tier-PRES {
  background: var(--pres);
  padding: 2px 5px;
  min-width: 0;
}
.tier-badge.tier-PRES .icon { width: 12px; height: 12px; }

.pane-title {
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--ink);
  font-family: var(--font-serif);
  font-weight: 500;
  font-size: 13.5px;
  font-variation-settings: "opsz" 14;
  letter-spacing: -0.005em;
}

.pane-model {
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: 0.02em;
}

.pane-actions { display: flex; gap: 2px; }

.pane-actions button {
  background: transparent;
  border: 1px solid transparent;
  color: var(--muted);
  width: 24px;
  height: 24px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  line-height: 1;
  cursor: pointer;
  border-radius: var(--radius-xs);
  padding: 0;
  transition: background 120ms, color 120ms;
}
.pane-actions button:hover {
  background: var(--surface-hover);
  color: var(--ink);
}
.pane-actions button.danger:hover {
  background: var(--error-tint);
  color: var(--error);
}

/* Lucide icon sizing */
.icon { width: 14px; height: 14px; stroke-width: 2; display: inline-block; vertical-align: middle; }
.pane-actions .icon { width: 13px; height: 13px; }

.pane-diag {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 5px 12px;
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--muted);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.activity-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--muted-2);
  flex-shrink: 0;
  box-shadow: 0 0 0 2px var(--surface);
}
.activity-dot.active {
  background: var(--success);
  box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--success-tint);
  animation: pulse 1.6s ease-in-out infinite;
}
.activity-dot.error { background: var(--error); }
.activity-dot.done  { background: var(--muted-2); }

@keyframes pulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50%      { transform: scale(1.35); opacity: 0.65; }
}

.pane-body {
  flex: 1;
  overflow-y: auto;
  font-family: var(--font-mono);
  font-size: 11.5px;
  line-height: 1.55;
  padding: 10px 12px;
  color: var(--ink-2);
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
  background: var(--surface);
}
.pane-body::-webkit-scrollbar { width: 8px; }
.pane-body::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 4px;
  border: 2px solid var(--surface);
}

/* Event log entries — semantic colors on cream */
.evt {
  padding: 2px 0;
  white-space: pre-wrap;
  word-break: break-word;
}
.evt.evt-text   { color: var(--ink); }
.evt.evt-tool   { color: var(--accent); }
.evt.evt-result { color: var(--success); }
.evt.evt-meta   { color: var(--muted-2); font-size: 10px; }
.evt.evt-error  { color: var(--error); }

/* Collapsible tool calls + results — Lucide icon + name + summary on one line. */
.tool-details { margin: 0; }
.tool-details > summary {
  list-style: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 1px 4px;
  border-radius: var(--radius-xs);
  user-select: none;
}
.tool-details > summary::-webkit-details-marker { display: none; }
.tool-details > summary::marker { content: ''; }
.tool-details > summary:hover { background: var(--surface-hover); }
.tool-details > summary .icon {
  width: 12px;
  height: 12px;
  flex-shrink: 0;
}
.tool-details > summary .tool-name {
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 10.5px;
  letter-spacing: 0.02em;
  flex-shrink: 0;
}
.tool-details > summary .tool-summary-text {
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  min-width: 0;
}
.evt-tool   .tool-details > summary .tool-name,
.evt-tool   .tool-details > summary .icon { color: var(--accent); }
.evt-result .tool-details > summary .tool-name,
.evt-result .tool-details > summary .icon { color: var(--success); }
.evt-error  .tool-details > summary .tool-name,
.evt-error  .tool-details > summary .icon { color: var(--error); }
.tool-details[open] > summary .tool-summary-text { white-space: normal; }
.tool-details > .tool-input {
  margin: 4px 0 8px 22px;
  padding: 8px 10px;
  background: var(--surface-2);
  border-radius: var(--radius-xs);
  font-family: var(--font-mono);
  font-size: 10.5px;
  line-height: 1.5;
  color: var(--ink-2);
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 280px;
  overflow: auto;
  border: 1px solid var(--border);
}

/* User-message bubble */
.evt.evt-user {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  padding: 6px 9px;
  margin: 5px 0;
  background: var(--brand-tint);
  border-left: 3px solid var(--brand);
  border-radius: var(--radius-xs);
}
.evt.evt-user .user-pill {
  font-family: var(--font-mono);
  font-size: 9.5px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--brand);
  padding-top: 2px;
  flex-shrink: 0;
}
.evt.evt-user .user-text {
  flex: 1;
  min-width: 0;
  font-family: var(--font-sans);
  font-size: 12px;
  line-height: 1.5;
  color: var(--ink);
  white-space: pre-wrap;
  word-break: break-word;
}

/* Hide-noise mode */
.pane-body.hide-noise .evt-tool,
.pane-body.hide-noise .evt-result,
.pane-body.hide-noise .evt-meta { display: none; }

.pane-noise-btn {
  margin-left: auto;
  background: transparent;
  border: 1px solid transparent;
  color: var(--muted);
  width: 22px;
  height: 22px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  border-radius: var(--radius-xs);
  padding: 0;
  transition: background 120ms, color 120ms;
}
.pane-noise-btn:hover {
  background: var(--surface-hover);
  color: var(--ink);
}
.pane-noise-btn .icon { width: 12px; height: 12px; }

/* --- Chat row --- */

.pane-chat {
  display: flex;
  gap: 6px;
  padding: 8px 10px;
  border-top: 1px solid var(--border);
  background: var(--surface-2);
}
.pane-chat.hidden { display: none; }
.pane-chat-input {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--ink);
  border-radius: var(--radius-xs);
  padding: 6px 9px;
  font-family: var(--font-sans);
  font-size: 12.5px;
  outline: none;
  transition: border-color 120ms, box-shadow 120ms;
}
.pane-chat-input::placeholder { color: var(--muted-2); }
.pane-chat-input:focus {
  border-color: var(--brand-2);
  box-shadow: 0 0 0 3px var(--brand-tint);
}
.pane-chat-input:disabled { opacity: 0.5; }
.pane-chat-send {
  background: var(--brand);
  border: 1px solid var(--brand);
  color: #fff;
  border-radius: var(--radius-xs);
  padding: 6px 14px;
  font-family: var(--font-sans);
  font-weight: 500;
  font-size: 12px;
  letter-spacing: 0.01em;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: background 120ms;
}
.pane-chat-send:hover { background: var(--brand-2); border-color: var(--brand-2); }
.pane-chat-send:disabled { background: var(--muted-2); border-color: var(--muted-2); cursor: not-allowed; }

.pane.minimized .pane-chat,
.pane.minimized .pane-perm-banner { display: none; }

/* --- Permission banner --- */

.pane-perm-banner {
  background: var(--warn-tint);
  border-bottom: 1px solid #d6b066;
  color: #6b4d18;
  padding: 8px 12px;
  font-size: 11.5px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}
.pane-perm-banner.hidden { display: none; }
.pane-perm-banner::before {
  content: "";
  width: 14px; height: 14px;
  background: var(--warn);
  -webkit-mask: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'><path d='M10.29 3.86 1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z'/><line x1='12' y1='9' x2='12' y2='13'/><line x1='12' y1='17' x2='12.01' y2='17'/></svg>") center/contain no-repeat;
          mask: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'><path d='M10.29 3.86 1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z'/><line x1='12' y1='9' x2='12' y2='13'/><line x1='12' y1='17' x2='12.01' y2='17'/></svg>") center/contain no-repeat;
  flex-shrink: 0;
}
.pane-perm-label { flex: 1; min-width: 0; }
.pane-perm-btn {
  background: var(--surface);
  border: 1px solid var(--border-strong);
  color: var(--ink);
  border-radius: var(--radius-xs);
  padding: 4px 12px;
  font-family: var(--font-sans);
  font-weight: 500;
  font-size: 11.5px;
  cursor: pointer;
  transition: all 120ms;
}
.pane-perm-btn:hover { background: var(--surface-hover); }
.pane-perm-btn.approve {
  border-color: var(--success);
  color: var(--success);
  background: var(--success-tint);
}
.pane-perm-btn.approve:hover { background: var(--success); color: #fff; }
.pane-perm-btn.deny {
  border-color: var(--error);
  color: var(--error);
  background: var(--error-tint);
}
.pane-perm-btn.deny:hover { background: var(--error); color: #fff; }
.pane-perm-btn:disabled { opacity: 0.5; cursor: not-allowed; }

.pane.status-stopped {
  border-style: dashed;
  opacity: 0.85;
}

/* --- Context menu --- */

#context-menu {
  position: fixed;
  z-index: 100;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 4px;
  min-width: 160px;
  box-shadow: var(--shadow-md);
  font-family: var(--font-sans);
}
#context-menu.hidden { display: none; }
.menu-item {
  padding: 7px 10px;
  font-size: 13px;
  cursor: pointer;
  border-radius: var(--radius-xs);
  user-select: none;
  display: flex;
  align-items: center;
  gap: 9px;
  color: var(--ink);
}
.menu-item .icon { color: var(--muted); }
.menu-item:hover { background: var(--surface-hover); }
.menu-item[data-tier="L2"]:hover .icon { color: var(--l2); }
.menu-item[data-tier="L3"]:hover .icon { color: var(--l3); }
.menu-item-hint {
  margin-left: auto;
  color: var(--muted-2);
  font-family: var(--font-mono);
  font-size: 10.5px;
}

/* --- Modal --- */

#modal {
  position: fixed;
  inset: 0;
  background: rgba(44, 36, 22, 0.32);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
}
#modal.hidden { display: none; }
.modal-card {
  width: min(640px, 92vw);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 22px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  box-shadow: var(--shadow-lg);
}
.modal-header {
  font-family: var(--font-serif);
  font-weight: 500;
  font-size: 20px;
  color: var(--ink);
  font-variation-settings: "opsz" 24;
  letter-spacing: -0.01em;
}
#modal-prompt {
  width: 100%;
  min-height: 160px;
  padding: 12px 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--ink);
  border-radius: var(--radius-sm);
  font-family: var(--font-sans);
  font-size: 13.5px;
  line-height: 1.55;
  resize: vertical;
  outline: none;
  transition: border-color 120ms, box-shadow 120ms;
}
#modal-prompt:focus {
  border-color: var(--brand-2);
  box-shadow: 0 0 0 3px var(--brand-tint);
  background: var(--surface);
}
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}
.modal-actions button {
  padding: 7px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--ink);
  font-family: var(--font-sans);
  font-weight: 500;
  font-size: 13px;
  cursor: pointer;
  transition: all 120ms;
}
.modal-actions button:hover { background: var(--surface-hover); }
.modal-actions button.primary {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
}
.modal-actions button.primary:hover { background: var(--brand-2); border-color: var(--brand-2); }
.modal-hint {
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--muted-2);
  text-align: right;
}

/* --- Status bar --- */

#status-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 30px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 0 16px;
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--muted);
  z-index: 50;
  box-shadow: 0 -1px 2px rgba(44, 36, 22, 0.02);
}
#status-bar > span { display: inline-flex; align-items: center; gap: 6px; }
#status-conn::before {
  content: "";
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--muted-2);
}
#status-conn.connected { color: var(--success); }
#status-conn.connected::before { background: var(--success); box-shadow: 0 0 0 2px var(--success-tint); }
#status-conn.error { color: var(--error); }
#status-conn.error::before { background: var(--error); }
#status-help { margin-left: auto; color: var(--muted-2); font-style: normal; }

/* --- Presentation pane --- */

.pane.presentation {
  width: 480px;
  height: 420px;
  max-height: none;
  min-width: 320px;
  min-height: 220px;
  border-left-color: var(--pres);
}
.pane.presentation.mode-form     { border-left-color: var(--info); }
.pane.presentation.mode-question { border-left-color: var(--warn); }
.pane.presentation.resolved      { opacity: 0.85; }
.pane.presentation.resolved::after {
  content: 'submitted';
  position: absolute; top: 10px; right: 38px;
  background: var(--success-tint);
  color: var(--success);
  border: 1px solid var(--success);
  border-radius: var(--radius-xs);
  padding: 1px 7px;
  font-family: var(--font-mono);
  font-size: 9.5px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  pointer-events: none;
}
.pane-iframe-wrap {
  flex: 1;
  position: relative;
  min-height: 0;
  background: var(--surface);
}
.pane-iframe-wrap > iframe {
  width: 100%;
  height: 100%;
  border: 0;
  display: block;
  background: var(--surface);
}
.pane.presentation.resolved .pane-iframe-wrap > iframe { pointer-events: none; }
.pane.resizing { transition: none; }

/* SE corner resize handle */
.pane-resize-handle {
  position: absolute;
  right: 0;
  bottom: 0;
  width: 14px;
  height: 14px;
  cursor: se-resize;
  background:
    linear-gradient(135deg, transparent 50%, var(--border-strong) 50%);
  z-index: 5;
  opacity: 0.7;
}
.pane-resize-handle:hover { opacity: 1; }
.pane.minimized .pane-resize-handle { display: none; }

/* --- Pinned panes --- */

.pane.pinned {
  border-left-color: var(--accent);
  border-left-width: 4px;
  box-shadow: var(--shadow-pane), inset 4px 0 0 -2px var(--accent-tint);
}
.pane.pinned .pane-header { cursor: default; }
.pane.pinned .pane-header:active { cursor: default; }
.pane-pin-btn.active { color: var(--accent); }
.pane-pin-btn.active:hover { background: var(--accent-tint); color: var(--accent); }

/* --- Widget pane --- */

.pane.widget {
  width: 520px;
  height: 460px;
  max-height: none;
  min-width: 320px;
  min-height: 220px;
  border-left-color: var(--widget);
}
.pane.widget .tier-badge.tier-WIDGET {
  background: var(--widget);
  padding: 2px 5px;
  min-width: 0;
}
.pane.widget .tier-badge.tier-WIDGET .icon { width: 12px; height: 12px; }
.pane.widget .pane-iframe-wrap { background: var(--surface-2); }

/* Cloud-only: server-kind widgets explain why they can't render in cloud
   and offer no Play button (we have no tunnel to localhost in v1). */
.pane.widget.kind-server .widget-server-notice {
  display: flex;
  position: absolute;
  inset: 0;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 8px;
  padding: 24px;
  text-align: center;
  color: var(--muted);
  font-family: var(--font-sans);
  font-size: 12px;
  background: var(--surface-2);
  pointer-events: auto;
}
.pane.widget.kind-server .widget-server-notice .notice-title {
  font-weight: 600;
  color: var(--ink-2);
  font-size: 13px;
}

.widget-keep-btn {
  background: var(--surface);
  border: 1px solid var(--border-strong);
  color: var(--ink);
  border-radius: var(--radius-xs);
  padding: 3px 10px;
  font-family: var(--font-sans);
  font-weight: 500;
  font-size: 10.5px;
  letter-spacing: 0.02em;
  cursor: pointer;
  height: 22px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  transition: all 120ms;
  margin-right: 4px;
}
.widget-keep-btn:hover {
  background: var(--widget-tint);
  border-color: var(--widget);
  color: var(--widget);
}
.widget-keep-btn .icon { width: 11px; height: 11px; }

/* --- Minimap --- */

#minimap {
  position: fixed;
  bottom: 76px;
  right: 14px;
  width: 252px;
  z-index: 60;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-sm);
  font-family: var(--font-mono);
  user-select: none;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
#minimap.hidden { display: none; }
.minimap-header {
  display: flex;
  align-items: center;
  padding: 4px 8px;
  font-size: 10px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
}
.minimap-label { flex: 1; }
.minimap-toggle {
  background: transparent;
  border: 1px solid transparent;
  color: var(--muted);
  width: 20px;
  height: 20px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  border-radius: var(--radius-xs);
  padding: 0;
  transition: background 120ms, color 120ms;
}
.minimap-toggle:hover { background: var(--surface-hover); color: var(--ink); }
.minimap-toggle .icon { width: 12px; height: 12px; }
#minimap-canvas {
  display: block;
  width: 240px;
  height: 160px;
  margin: 6px;
  cursor: crosshair;
  background:
    linear-gradient(to right, var(--grid) 1px, transparent 1px) 0 0 / 24px 24px,
    linear-gradient(to bottom, var(--grid) 1px, transparent 1px) 0 0 / 24px 24px,
    var(--bg);
  border-radius: var(--radius-xs);
  border: 1px solid var(--border);
}

#minimap-show {
  position: fixed;
  bottom: 76px;
  right: 14px;
  z-index: 60;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: var(--radius-sm);
  width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: var(--shadow-xs);
  transition: background 120ms, color 120ms;
}
#minimap-show.hidden { display: none; }
#minimap-show:hover { background: var(--surface-hover); color: var(--ink); }
#minimap-show .icon { width: 14px; height: 14px; }

/* --- Toast --- */

#toast {
  position: fixed;
  top: 14px;
  right: 14px;
  z-index: 300;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}
.toast-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--ink);
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  font-size: 12.5px;
  color: var(--ink);
  pointer-events: auto;
  box-shadow: var(--shadow-md);
  animation: fadeIn 200ms ease;
  max-width: 360px;
}
.toast-item.toast-error   { border-left-color: var(--error); }
.toast-item.toast-success { border-left-color: var(--success); }
.toast-item.toast-warn    { border-left-color: var(--warn); }
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(-4px); }
  to   { opacity: 1; transform: translateY(0); }
}
