:root { font-family: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif; color: #1e293b; background: #f4f6fa; }
* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; }
button, input, textarea { font: inherit; }
button { cursor: pointer; }
button:focus-visible, textarea:focus-visible, input:focus-visible { outline: 2px solid #6366f1; outline-offset: 2px; }
[hidden] { display: none !important; }
.brand { display: flex; align-items: center; gap: 11px; font-size: 16px; font-weight: 750; letter-spacing: .06em; white-space: nowrap; }
.brand-mark { display: grid; place-items: center; width: 32px; height: 32px; border-radius: 9px; background: #6366f1; color: white; letter-spacing: 0; }

.login-page { display: grid; place-items: center; padding: 24px; }
.login-wrap { width: min(100%, 400px); }
.login-page .brand { justify-content: center; margin-bottom: 28px; color: #253047; }
.login-card { padding: 32px; background: white; border: 1px solid #e5eaf1; border-radius: 16px; box-shadow: 0 12px 40px rgba(31, 41, 55, .06); }
.login-card h1 { margin: 0 0 6px; font-size: 25px; letter-spacing: -.03em; }
.muted { margin: 0 0 28px; color: #64748b; font-size: 14px; }
.field { display: block; margin: 0 0 18px; color: #334155; font-size: 13px; font-weight: 600; }
.field input { display: block; width: 100%; height: 44px; margin-top: 8px; padding: 0 13px; border: 1px solid #cfd8e3; border-radius: 9px; background: white; color: #0f172a; }
.field input:focus { outline: none; border-color: #6366f1; box-shadow: 0 0 0 3px #e8e9ff; }
.primary { width: 100%; height: 44px; border: 0; border-radius: 9px; background: #4f46e5; color: white; font-weight: 650; }
.primary:hover { background: #4338ca; }
.error { margin: 0 0 18px; padding: 11px 13px; border-radius: 9px; background: #fff1f2; color: #be123c; font-size: 13px; }
.login-note { margin: 18px 0 0; text-align: center; color: #94a3b8; font-size: 12px; }

.editor-page { overflow: hidden; }
.topbar { display: flex; align-items: center; gap: 36px; height: 64px; padding: 0 24px; border-bottom: 1px solid #e5eaf1; background: white; }
.page-title { color: #26344d; font-size: 14px; font-weight: 650; }
.page-title span { color: #94a3b8; font-weight: 400; }
.logout-form { display: flex; align-items: center; gap: 16px; margin-left: auto; }
.account { display: inline-flex; align-items: center; gap: 8px; color: #475569; font-size: 13px; }
.account::before { content: 'Q'; display: grid; place-items: center; width: 28px; height: 28px; border-radius: 50%; background: #e8e9ff; color: #4f46e5; font-weight: 700; }
.logout { border: 0; background: none; color: #64748b; font-size: 13px; }
.logout:hover { color: #172238; }
.editor-layout { display: grid; grid-template-columns: 260px minmax(0, 1fr); height: calc(100vh - 64px); }
.toolbox { display: flex; flex-direction: column; min-height: 0; padding: 22px 18px; border-right: 1px solid #e5eaf1; background: white; overflow-y: auto; }
.tool-section { padding-bottom: 26px; }
.tool-section h2 { margin: 0 0 13px; color: #64748b; font-size: 11px; font-weight: 750; letter-spacing: .1em; text-transform: uppercase; }
.tool-card { display: flex; align-items: center; gap: 12px; width: 100%; min-height: 62px; padding: 11px; border: 1px solid #e2e8f0; border-radius: 10px; background: white; color: #253047; text-align: left; }
.tool-card:hover, .tool-card.active { border-color: #a5b4fc; background: #f6f7ff; }
#add-rect { cursor: grab; }
.tool-card strong, .tool-card small { display: block; }
.tool-card strong { font-size: 13px; font-weight: 650; }
.tool-card small { margin-top: 3px; color: #94a3b8; font-size: 11px; }
.tool-icon { flex: none; display: grid; place-items: center; width: 32px; height: 32px; border-radius: 7px; background: #eef2ff; color: #4f46e5; }
.rect-icon::before { content: ''; width: 18px; height: 12px; border: 2px solid #6366f1; border-radius: 2px; background: white; }
.arrow-icon { font-size: 24px; line-height: 1; }
.tool-plus { margin-left: auto; color: #94a3b8; font-size: 20px; }
.tool-hint { margin: 10px 2px 0; color: #94a3b8; font-size: 11px; line-height: 1.5; }
.selection-actions { border-top: 1px solid #edf0f5; padding-top: 14px; }
.delete-button { margin-top: 12px; padding: 8px 0; border: 0; background: none; color: #dc3545; font-size: 12px; }
.delete-button:hover { color: #a51d2d; }
.toolbox-footer { margin: auto 2px 0; padding-top: 20px; color: #94a3b8; font-size: 11px; line-height: 1.6; }

.map-area { position: relative; min-width: 0; min-height: 0; overflow: hidden; background: #f8fafc; }
.viewport { position: absolute; inset: 0; overflow: hidden; cursor: grab; background-image: linear-gradient(to right, #e8edf4 1px, transparent 1px), linear-gradient(to bottom, #e8edf4 1px, transparent 1px); background-size: var(--grid-size, 24px) var(--grid-size, 24px); background-position: var(--grid-x, 0px) var(--grid-y, 0px); touch-action: none; }
.viewport.panning { cursor: grabbing; }
.viewport.connecting { cursor: crosshair; }
.world { position: absolute; left: 0; top: 0; width: 1px; height: 1px; transform-origin: 0 0; }
.edges, .nodes { position: absolute; left: 0; top: 0; width: 1px; height: 1px; overflow: visible; }
.edges { pointer-events: none; }
.edge-line { fill: none; stroke: #94a3b8; stroke-width: 2.5; }
.edge-line.selected { stroke: #4f46e5; }
.edge-hit { fill: none; stroke: transparent; stroke-width: 18; pointer-events: stroke; cursor: pointer; }
.edge-label { fill: #475569; stroke: #f8fafc; stroke-width: 7; paint-order: stroke; font-size: 13px; font-weight: 600; text-anchor: middle; dominant-baseline: middle; pointer-events: auto; cursor: pointer; }
.edge-label.selected { fill: #4f46e5; }
.edge-info { pointer-events: all; cursor: pointer; }
.edge-info circle { fill: white; stroke: #94a3b8; stroke-width: 1.5; }
.edge-info.has-info circle { fill: #eef2ff; stroke: #6366f1; }
.edge-info text { fill: #64748b; font-size: 13px; font-weight: 700; text-anchor: middle; dominant-baseline: middle; user-select: none; }
.node { position: absolute; display: flex; flex-direction: column; overflow: visible; border: 1.5px solid #cbd5e1; border-radius: 8px; background: white; box-shadow: 0 3px 12px rgba(31, 41, 55, .08); cursor: grab; user-select: none; }
.node:active { cursor: grabbing; }
.node.editing { cursor: text; }
.node.selected { border-color: #6366f1; box-shadow: 0 0 0 3px #e6e8ff, 0 5px 18px rgba(31, 41, 55, .1); }
.node.connect-target { border-color: #6366f1; cursor: crosshair; }
.node-text { flex: 1; overflow: hidden; padding: 14px 40px 14px 14px; color: #253047; font-size: 14px; line-height: 1.5; white-space: pre-wrap; overflow-wrap: anywhere; }
.node-text.placeholder { color: #a7b3c3; }
.node-editor { position: absolute; inset: 0; width: 100%; height: 100%; padding: 14px 40px 14px 14px; border: 0; border-radius: 7px; outline: none; resize: none; background: white; color: #253047; font-size: 14px; line-height: 1.5; cursor: text; user-select: text; }
.node.editing .resize-handle { z-index: 2; }
.info-button { position: absolute; z-index: 2; top: 8px; right: 8px; display: grid; place-items: center; width: 21px; height: 21px; padding: 0; border: 1.5px solid #94a3b8; border-radius: 50%; background: white; color: #64748b; font-size: 13px; font-weight: 700; font-style: normal; line-height: 1; cursor: pointer; }
.info-button:hover, .info-button.has-info { border-color: #6366f1; background: #eef2ff; color: #4f46e5; }
.resize-handle { position: absolute; right: -2px; bottom: -2px; width: 20px; height: 20px; cursor: nwse-resize; }
.resize-handle::after { content: ''; position: absolute; right: 5px; bottom: 5px; width: 8px; height: 8px; border-right: 2px solid #94a3b8; border-bottom: 2px solid #94a3b8; }
.edge-editor { position: absolute; z-index: 3; width: 180px; height: 34px; padding: 0 9px; transform: translate(-50%, -50%); border: 1px solid #6366f1; border-radius: 7px; outline: none; background: white; box-shadow: 0 4px 14px rgba(31, 41, 55, .12); color: #253047; font-size: 13px; text-align: center; }
.info-dialog { width: min(440px, calc(100vw - 32px)); padding: 0; border: 1px solid #e2e8f0; border-radius: 14px; box-shadow: 0 20px 60px rgba(15, 23, 42, .22); }
.info-dialog.llm-dialog { width: min(900px, calc(100vw - 32px)); }
.info-dialog::backdrop { background: rgba(15, 23, 42, .35); }
.info-heading { display: flex; align-items: center; justify-content: space-between; padding: 20px 22px 12px; }
.info-heading h2 { margin: 0; color: #172238; font-size: 18px; }
.info-heading button { border: 0; background: none; color: #64748b; font-size: 24px; line-height: 1; }
.info-heading #info-back { margin-right: 10px; font-size: 22px; }
.info-heading h2 { flex: 1; }
.llm-sections { display: grid; gap: 8px; padding: 8px 22px 22px; }
.llm-sections button { padding: 12px 14px; border: 1px solid #e2e8f0; border-radius: 8px; background: #f8fafc; color: #4f46e5; text-align: left; text-decoration: underline; }
.llm-sections button:hover { background: #eef2ff; }
.llm-content { max-height: min(65vh, 560px); margin: 0 22px 22px; padding: 14px; overflow: auto; border: 1px solid #e2e8f0; border-radius: 8px; background: #f8fafc; color: #253047; font-size: 12px; line-height: 1.5; white-space: pre-wrap; overflow-wrap: anywhere; }
.info-dialog textarea { display: block; width: calc(100% - 44px); min-height: 180px; margin: 0 22px; padding: 12px; border: 1px solid #cfd8e3; border-radius: 8px; outline: none; resize: vertical; color: #253047; font-size: 14px; line-height: 1.5; }
.info-dialog textarea:focus { border-color: #6366f1; box-shadow: 0 0 0 3px #e8e9ff; }
.info-actions { display: flex; justify-content: flex-end; gap: 8px; padding: 18px 22px 22px; }
.info-actions button { min-width: 90px; height: 36px; border: 1px solid #cfd8e3; border-radius: 8px; background: white; color: #334155; font-size: 13px; font-weight: 600; }
.info-actions #info-save { border-color: #4f46e5; background: #4f46e5; color: white; }
.map-toolbar { position: absolute; top: 18px; right: 18px; display: flex; align-items: center; height: 38px; border: 1px solid #e2e8f0; border-radius: 9px; background: white; box-shadow: 0 4px 16px rgba(31, 41, 55, .07); }
.map-toolbar button { width: 36px; height: 36px; border: 0; background: none; color: #334155; font-size: 20px; }
.map-toolbar button:hover { background: #f1f5f9; }
.map-toolbar button:last-child { border-left: 1px solid #edf0f5; font-size: 21px; }
.map-toolbar span { min-width: 48px; text-align: center; color: #64748b; font-size: 12px; }
.map-footer { position: absolute; right: 18px; bottom: 15px; left: 18px; display: flex; justify-content: space-between; gap: 10px; color: #94a3b8; font-size: 11px; pointer-events: none; }
.map-footer .error-status { color: #dc3545; }

@media (max-width: 760px) {
  .topbar { padding: 0 14px; gap: 14px; }
  .page-title { font-size: 12px; }
  .page-title span, .account { display: none; }
  .editor-layout { grid-template-columns: 1fr; grid-template-rows: auto minmax(0, 1fr); }
  .toolbox { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 14px; max-height: 240px; padding: 14px; }
  .tool-section { padding-bottom: 0; }
  .toolbox-footer { display: none; }
  .selection-actions { grid-column: 1 / -1; }
  .tool-card { min-height: 52px; }
  .tool-hint { display: none; }
  .map-footer span:last-child { display: none; }
}
