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

:root {
  --bg: #111827;
  --surface: #1f2937;
  --surface2: #111827;
  --surface3: #0d1520;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --ok: #10b981;
  --warn: #f59e0b;
  --danger: #ef4444;
  --text: #f3f4f6;
  --text-muted: #6b7280;
  --text-soft: #9ca3af;
  --border: #374151;
  --border-light: #1f2937;
  --sidebar-w: 260px;
  --diagram-h: 200px;
}

body { font-family: 'Segoe UI', system-ui, sans-serif; background: var(--bg); color: var(--text); height: 100vh; overflow: hidden; font-size: 14px; }
#app { display: flex; height: 100vh; }

/* SIDEBAR */
#sidebar { width: var(--sidebar-w); background: var(--surface); border-right: 1px solid var(--border); display: flex; flex-direction: column; overflow-y: auto; flex-shrink: 0; }
.sidebar-header { padding: 14px 16px; background: var(--surface3); border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 8px; }
.logo-icon { font-size: 18px; color: var(--accent); }
.sidebar-header h1 { font-size: 14px; font-weight: 600; }
.sidebar-section { padding: 12px 14px; border-bottom: 1px solid var(--border); }
.sidebar-section h2 { font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: .08em; color: var(--text-muted); margin-bottom: 8px; }

/* FORMS */
.form-group { margin-bottom: 6px; }
.form-group label { display: block; font-size: 11px; color: var(--text-soft); margin-bottom: 2px; }
.form-group input, .form-group select {
  width: 100%; padding: 5px 8px; background: var(--bg); border: 1px solid var(--border);
  border-radius: 4px; color: var(--text); font-size: 13px;
}
.form-group input:focus, .form-group select:focus { outline: none; border-color: var(--accent); }
.btn-row { display: flex; gap: 6px; flex-wrap: wrap; }

/* BUTTONS */
.btn { padding: 6px 12px; border-radius: 5px; border: none; cursor: pointer; font-size: 12px; font-weight: 500; transition: all .15s; }
.btn:hover { filter: brightness(1.15); }
.btn:active { filter: brightness(.9); }
.btn-primary { background: var(--accent); color: #fff; width: 100%; margin-top: 6px; padding: 7px; }
.btn-secondary { background: var(--border); color: var(--text); flex: 1; }
.btn-sm { padding: 5px 10px; }
.btn-danger { background: var(--danger); color: #fff; }

/* TOOL BUTTONS */
.tool-btns { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 5px; }
.tool-btn { display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 7px 4px; background: var(--bg); border: 1px solid var(--border); border-radius: 6px; cursor: pointer; color: var(--text-muted); font-size: 10px; transition: all .15s; }
.tool-btn svg { width: 18px; height: 18px; }
.tool-btn:hover { border-color: var(--accent); color: var(--text); }
.tool-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }

/* LOAD TYPE TILES */
.lt-tile {
  display: flex; align-items: center; gap: 8px; padding: 7px 9px;
  background: var(--bg); border: 1px solid var(--border); border-radius: 6px;
  margin-bottom: 5px; cursor: grab; user-select: none;
  transition: border-color .15s;
}
.lt-tile:hover { border-color: var(--accent); }
.lt-tile.dragging { opacity: .5; }
.lt-dot { width: 12px; height: 12px; border-radius: 50%; flex-shrink: 0; }
.lt-name { font-size: 12px; font-weight: 500; flex: 1; }
.lt-weight { font-size: 11px; color: var(--text-muted); }
.lt-edit-btn { background: none; border: none; color: var(--text-muted); cursor: pointer; font-size: 12px; padding: 2px 4px; border-radius: 3px; }
.lt-edit-btn:hover { background: var(--border); color: var(--text); }
.lt-tile.active-tool { border-color: var(--accent); background: rgba(59,130,246,.1); }

/* MAIN */
#main { flex: 1; display: flex; flex-direction: column; overflow: hidden; min-width: 0; }
#canvas-toolbar { display: flex; align-items: center; justify-content: space-between; padding: 6px 12px; background: var(--surface); border-bottom: 1px solid var(--border); gap: 8px; flex-shrink: 0; }
.snap-badge { font-size: 11px; color: var(--accent); background: rgba(59,130,246,.1); border: 1px solid rgba(59,130,246,.3); border-radius: 4px; padding: 2px 7px; }

#canvas-wrap { flex: 1; overflow: hidden; position: relative; background: var(--bg); background-image: radial-gradient(#1f293788 1px, transparent 1px); background-size: 20px 20px; }
#canvas { width: 100%; height: 100%; cursor: default; }
#canvas.tool-support { cursor: crosshair; }
#canvas.tool-load { cursor: crosshair; }
#canvas.tool-distload { cursor: crosshair; }
#canvas.tool-delete { cursor: not-allowed; }
#canvas.drag-over { background-color: rgba(59,130,246,.05); }

/* DIAGRAMS */
#diagrams { height: var(--diagram-h); background: var(--surface3); border-top: 1px solid var(--border); display: flex; flex-shrink: 0; }
.diagram-wrap { flex: 1; padding: 8px 12px 6px; border-right: 1px solid var(--border); display: flex; flex-direction: column; min-width: 0; }
.diagram-wrap:last-child { border-right: none; }
.diagram-title { font-size: 10px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .06em; margin-bottom: 4px; flex-shrink: 0; }
.diagram-limit-label { color: var(--danger); opacity: .7; }
.diagram-wrap canvas { flex: 1; min-height: 0; }

/* STATUS */
.status-badge { padding: 7px 10px; border-radius: 5px; font-weight: 600; text-align: center; font-size: 13px; margin-bottom: 8px; }
.status-badge.ok { background: rgba(16,185,129,.12); color: var(--ok); border: 1px solid rgba(16,185,129,.4); }
.status-badge.warning { background: rgba(245,158,11,.12); color: var(--warn); border: 1px solid rgba(245,158,11,.4); }
.status-badge.overload { background: rgba(239,68,68,.12); color: var(--danger); border: 1px solid rgba(239,68,68,.4); }
#result-details { font-size: 12px; line-height: 1.9; color: var(--text-soft); }
#result-details span { display: block; }

/* MODAL */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.65); display: flex; align-items: center; justify-content: center; z-index: 100; }
.modal-box { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 20px; min-width: 300px; max-width: 90vw; }
.modal-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.modal-header h2 { font-size: 15px; font-weight: 600; }
.modal-header button { background: none; border: none; color: var(--text-muted); cursor: pointer; font-size: 16px; }
#project-list-items { max-height: 300px; overflow-y: auto; }
.project-item { display: flex; align-items: center; justify-content: space-between; padding: 8px 10px; border-radius: 5px; cursor: pointer; border: 1px solid var(--border); margin-bottom: 5px; }
.project-item:hover { border-color: var(--accent); }

/* SEGMENT ADD BUTTON */
.seg-add-btn { cursor: pointer; }
.seg-add-btn:hover rect { fill: rgba(59,130,246,.3); }

/* TOAST */
.toast { position: fixed; bottom: 20px; right: 20px; background: var(--ok); color: #000; padding: 8px 16px; border-radius: 6px; font-size: 13px; font-weight: 600; z-index: 999; transition: opacity .4s; pointer-events: none; }
