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

:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface2: #22263a;
  --border: #2e3250;
  --accent: #4A90D9;
  --text: #e8eaf0;
  --text-muted: #7a7f9a;
  --danger: #e74c3c;
  --success: #27ae60;
  --radius: 10px;
  --toolbar-h: 52px;
  --sidebar-w: 220px;
}

body { background: var(--bg); color: var(--text); font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; height: 100vh; overflow: hidden; }

/* ─── LOGIN ─── */
#login-overlay { position: fixed; inset: 0; background: rgba(10,11,18,0.97); display: flex; align-items: center; justify-content: center; z-index: 9999; }
#login-box { background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 40px; width: 340px; text-align: center; }
#login-box h2 { font-size: 1.5rem; margin-bottom: 8px; }
#login-box p { color: var(--text-muted); margin-bottom: 24px; font-size: 0.9rem; }
#login-pw { width: 100%; padding: 12px 16px; background: var(--surface2); border: 1px solid var(--border); border-radius: var(--radius); color: var(--text); font-size: 1rem; margin-bottom: 12px; }
#login-pw:focus { outline: none; border-color: var(--accent); }
#login-box button { width: 100%; padding: 12px; background: var(--accent); color: #fff; border: none; border-radius: var(--radius); font-size: 1rem; cursor: pointer; font-weight: 600; }
#login-box button:hover { background: #3a7bc8; }
#login-err { color: var(--danger); margin-top: 10px; font-size: 0.85rem; }

/* ─── TOOLBAR ─── */
#toolbar { position: fixed; top: 0; left: 0; right: 0; height: var(--toolbar-h); background: var(--surface); border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; padding: 0 16px; z-index: 100; gap: 12px; }
#toolbar-left { display: flex; align-items: center; gap: 10px; min-width: 160px; }
#app-title { font-weight: 700; font-size: 0.95rem; }
#toolbar-center { display: flex; align-items: center; gap: 8px; }
#toolbar-right { display: flex; align-items: center; min-width: 160px; justify-content: flex-end; }

.tb-btn { padding: 7px 14px; background: var(--surface2); color: var(--text); border: 1px solid var(--border); border-radius: 8px; cursor: pointer; font-size: 0.85rem; font-weight: 500; transition: all 0.15s; white-space: nowrap; }
.tb-btn:hover { background: var(--border); }
.tb-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.tb-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.tb-btn:disabled:hover { background: var(--surface2); }

#color-picker { padding: 7px 10px; background: var(--surface2); color: var(--text); border: 1px solid var(--border); border-radius: 8px; font-size: 0.85rem; cursor: pointer; }
#color-picker:focus { outline: none; border-color: var(--accent); }

#save-indicator { font-size: 0.8rem; color: var(--text-muted); transition: color 0.3s; }
#save-indicator.saving { color: var(--accent); }
#save-indicator.saved { color: var(--success); }

/* ─── SIDEBAR ─── */
#sidebar {
  position: fixed; top: var(--toolbar-h); left: 0; bottom: 28px;
  width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  z-index: 90;
  transform: translateX(-100%);
  transition: transform 0.22s ease;
}
#sidebar.open { transform: translateX(0); }

.sidebar-header { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px 10px; border-bottom: 1px solid var(--border); }
.sidebar-title { font-weight: 700; font-size: 0.875rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.06em; }
.sidebar-add-btn { width: 28px; height: 28px; background: var(--surface2); border: 1px solid var(--border); border-radius: 8px; color: var(--text); cursor: pointer; font-size: 1.1rem; display: flex; align-items: center; justify-content: center; }
.sidebar-add-btn:hover { background: var(--accent); border-color: var(--accent); }
.sidebar-title-group { display: flex; align-items: center; gap: 10px; }
.sidebar-add-btn.active { background: var(--accent); border-color: var(--accent); }
.page-masked { color: var(--text-muted); letter-spacing: 0.02em; }
.page-item.dragging { opacity: 0.4; }
.page-item.drop-before { box-shadow: inset 0 2px 0 var(--accent); }
.page-item.drop-after { box-shadow: inset 0 -2px 0 var(--accent); }

#page-list { flex: 1; overflow-y: auto; padding: 8px 0; }

.page-item {
  display: flex; align-items: center; gap: 8px;
  padding: 9px 16px; cursor: pointer;
  border-left: 3px solid transparent;
  transition: background 0.12s;
  user-select: none;
}
.page-item:hover { background: var(--surface2); }
.page-item.active { background: rgba(74,144,217,0.1); border-left-color: var(--accent); }

.page-name { flex: 1; font-size: 0.875rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.page-item.active .page-name { color: var(--accent); font-weight: 600; }

.page-name-input { flex: 1; background: transparent; border: none; border-bottom: 1px solid var(--accent); color: var(--text); font-size: 0.875rem; outline: none; padding: 1px 0; }

.page-del { width: 20px; height: 20px; background: none; border: none; color: var(--text-muted); cursor: pointer; font-size: 0.8rem; border-radius: 4px; display: none; align-items: center; justify-content: center; flex-shrink: 0; }
.page-item:hover .page-del { display: flex; }
.page-del:hover { background: var(--danger); color: #fff; }

/* ─── CANVAS ─── */
#canvas { position: fixed; top: var(--toolbar-h); left: 0; right: 0; bottom: 28px; background: var(--bg); transition: left 0.22s ease; }
#canvas.sidebar-open { left: var(--sidebar-w); }

/* ─── HINT BAR ─── */
#hint-bar { position: fixed; bottom: 0; left: 0; right: 0; height: 28px; line-height: 28px; background: var(--surface); border-top: 1px solid var(--border); text-align: center; font-size: 0.75rem; color: var(--text-muted); z-index: 100; }

/* ─── CONTEXT MENU ─── */
#ctx-menu { position: fixed; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 6px 0; z-index: 500; min-width: 160px; box-shadow: 0 8px 24px rgba(0,0,0,0.5); display: none; }
.ctx-item { padding: 9px 16px; cursor: pointer; font-size: 0.875rem; }
.ctx-item:hover { background: var(--surface2); }
.ctx-sep { height: 1px; background: var(--border); margin: 4px 0; }

/* ─── MODAL OVERLAY ─── */
.modal-grip { cursor: grab; color: var(--text-muted); font-size: 1.2rem; line-height: 1; user-select: none; touch-action: none; flex-shrink: 0; }
.modal-grip:hover { color: var(--text); }
.modal-header { touch-action: none; }
.modal-box.dragging, .modal-box.dragging * { cursor: grabbing !important; user-select: none; }
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.3); display: none; align-items: center; justify-content: center; z-index: 200; padding: 20px; }
.modal-overlay.open { display: flex; }
.modal-box { background: var(--surface); border: 1px solid var(--border); border-radius: 16px; width: 100%; max-width: 720px; max-height: 88vh; display: flex; flex-direction: column; box-shadow: 0 20px 60px rgba(0,0,0,0.6); }
.modal-box-sm { max-width: 400px; }

.modal-header { display: flex; align-items: center; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.modal-title-input { flex: 1; background: transparent; border: none; color: var(--text); font-size: 1.2rem; font-weight: 700; }
.modal-title-input:focus { outline: none; }
.modal-title-input::placeholder { color: var(--text-muted); }
.modal-header-actions { display: flex; gap: 8px; align-items: center; }
.modal-color-select { padding: 6px 8px; background: var(--surface2); color: var(--text); border: 1px solid var(--border); border-radius: 8px; font-size: 0.8rem; cursor: pointer; }
.modal-close-btn { width: 32px; height: 32px; background: var(--surface2); color: var(--text-muted); border: 1px solid var(--border); border-radius: 8px; cursor: pointer; font-size: 1rem; display: flex; align-items: center; justify-content: center; }
.modal-close-btn:hover { color: var(--text); }

.modal-body { flex: 1; overflow-y: auto; padding: 20px; display: flex; flex-direction: column; gap: 16px; }

#modal-content { width: 100%; min-height: 180px; background: var(--surface2); border: 1px solid var(--border); border-radius: var(--radius); color: var(--text); font-size: 0.95rem; line-height: 1.7; padding: 14px 16px; resize: vertical; font-family: inherit; }
#modal-content:focus { outline: none; border-color: var(--accent); }

/* ─── MEDIA ─── */
#media-section { display: flex; flex-direction: column; gap: 10px; }
#media-gallery { display: flex; flex-wrap: wrap; gap: 10px; }
.media-thumb { position: relative; border-radius: 8px; overflow: hidden; border: 1px solid var(--border); width: 140px; height: 100px; background: var(--surface2); flex-shrink: 0; }
.media-thumb img, .media-thumb video { width: 100%; height: 100%; object-fit: cover; }
.media-thumb .media-del { position: absolute; top: 4px; right: 4px; width: 22px; height: 22px; background: rgba(0,0,0,0.7); color: #fff; border: none; border-radius: 50%; cursor: pointer; font-size: 0.75rem; display: flex; align-items: center; justify-content: center; }
.media-thumb .media-del:hover { background: var(--danger); }
.media-thumb .media-play { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 2rem; pointer-events: none; }
.upload-btn { display: inline-flex; align-items: center; gap: 8px; padding: 9px 16px; background: var(--surface2); color: var(--text-muted); border: 1px dashed var(--border); border-radius: var(--radius); cursor: pointer; font-size: 0.875rem; transition: all 0.15s; width: fit-content; }
.upload-btn:hover { border-color: var(--accent); color: var(--text); }
.upload-btn input { display: none; }

/* ─── MODAL FOOTER ─── */
.modal-footer { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; gap: 10px; justify-content: flex-end; }
.btn-save { padding: 9px 22px; background: var(--accent); color: #fff; border: none; border-radius: var(--radius); cursor: pointer; font-weight: 600; font-size: 0.9rem; }
.btn-save:hover { background: #3a7bc8; }
.btn-delete { padding: 9px 22px; background: transparent; color: var(--danger); border: 1px solid var(--danger); border-radius: var(--radius); cursor: pointer; font-size: 0.9rem; }
.btn-delete:hover { background: var(--danger); color: #fff; }

#canvas.pan-mode, #canvas.pan-mode * { cursor: grab !important; }

/* ─── KOTAK SELEKSI (tarik di area kosong) ─── */
#select-box { position: absolute; display: none; border: 1.5px dashed var(--accent); background: rgba(74,144,217,0.12); pointer-events: none; z-index: 50; }

/* ─── NODE TOOLTIP (hover) ─── */
div.vis-tooltip { background: var(--surface2) !important; border: 1px solid var(--border) !important; border-radius: var(--radius) !important; color: var(--text) !important; padding: 10px 14px !important; max-width: 360px; white-space: normal !important; box-shadow: 0 8px 24px rgba(0,0,0,0.5) !important; font-family: inherit !important; z-index: 150; }
.node-tip-title { font-weight: 600; font-size: 0.9rem; margin-bottom: 6px; }
.node-tip-body { font-size: 0.85rem; line-height: 1.5; white-space: pre-wrap; word-break: break-word; }
.node-tip-empty { font-size: 0.8rem; color: var(--text-muted); font-style: italic; margin-top: 4px; }

/* ─── CONNECTIONS (NODE MODAL) ─── */
.connections-section { display: flex; flex-direction: column; gap: 8px; }
.connections-label { font-size: 0.78rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; }
.connection-row { display: flex; gap: 8px; align-items: center; }
.connection-arrow { color: var(--text-muted); font-size: 0.9rem; flex-shrink: 0; }
.connection-row select { flex: 1; padding: 8px 12px; background: var(--surface2); border: 1px solid var(--border); border-radius: var(--radius); color: var(--text); font-size: 0.85rem; cursor: pointer; }
.connection-row select:focus { outline: none; border-color: var(--accent); }
.connection-del-btn { width: 30px; height: 30px; flex-shrink: 0; background: var(--surface2); border: 1px solid var(--border); border-radius: 8px; color: var(--text-muted); cursor: pointer; font-size: 0.85rem; transition: all 0.15s; }
.connection-del-btn:hover { background: rgba(231,76,60,0.15); border-color: #e74c3c; color: #e74c3c; }
.connection-add-select { width: 100%; padding: 9px 12px; background: var(--surface2); border: 1px dashed var(--border); border-radius: var(--radius); color: var(--text-muted); font-size: 0.85rem; cursor: pointer; }
.connection-add-select:focus { outline: none; border-color: var(--accent); }

/* ─── EDGE MODAL OPTIONS ─── */
.edge-label-field { width: 100%; padding: 10px 14px; background: var(--surface2); border: 1px solid var(--border); border-radius: var(--radius); color: var(--text); font-size: 0.95rem; }
.edge-label-field:focus { outline: none; border-color: var(--accent); }

.edge-option-group { display: flex; flex-direction: column; gap: 8px; }
.edge-option-label { font-size: 0.78rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; }

.edge-style-picker, .edge-dir-picker { display: flex; gap: 8px; }

.edge-opt-btn { flex: 1; display: flex; align-items: center; justify-content: center; gap: 8px; padding: 9px 12px; background: var(--surface2); color: var(--text-muted); border: 1px solid var(--border); border-radius: var(--radius); cursor: pointer; font-size: 0.85rem; transition: all 0.15s; }
.edge-opt-btn:hover { border-color: var(--accent); color: var(--text); }
.edge-opt-btn.active { border-color: var(--accent); color: var(--text); background: rgba(74,144,217,0.12); }

.edge-preview { display: inline-block; width: 32px; height: 2px; }
.solid-preview { background: currentColor; }
.dashed-preview { background: repeating-linear-gradient(to right, currentColor 0, currentColor 5px, transparent 5px, transparent 9px); }

/* ─── CONNECTION HANDLES ─── */
#handles-overlay { position: absolute; inset: 0; pointer-events: none; z-index: 10; }
#drag-svg { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 9; overflow: visible; }
.conn-handle { position: absolute; width: 14px; height: 14px; background: var(--accent); border: 2.5px solid #fff; border-radius: 50%; transform: translate(-50%, -50%); cursor: crosshair; pointer-events: all; transition: transform 0.12s, background 0.12s; z-index: 11; box-shadow: 0 0 6px rgba(74,144,217,0.6); }
.conn-handle:hover { transform: translate(-50%, -50%) scale(1.5); background: #fff; border-color: var(--accent); }

/* ─── LIGHTBOX ─── */
#lightbox { position: fixed; inset: 0; background: rgba(0,0,0,0.92); display: none; align-items: center; justify-content: center; z-index: 999; cursor: zoom-out; }
#lightbox.open { display: flex; }
#lightbox img, #lightbox video { max-width: 90vw; max-height: 90vh; border-radius: 8px; cursor: default; }
#lightbox-close { position: absolute; top: 20px; right: 24px; color: #fff; font-size: 2rem; cursor: pointer; background: none; border: none; line-height: 1; }

/* ─── VIS OVERRIDES ─── */
.vis-network { cursor: grab; }
.vis-network:active { cursor: grabbing; }

/* ─── SCROLLBAR ─── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--surface2); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }
