:root {
  --bg: #1e1e1e;
  --bg-alt: #262626;
  --bg-hover: #2e2e2e;
  --border: #363636;
  --text: #dcddde;
  --text-muted: #9a9a9a;
  --accent: #8c6cf7;
  --accent-hover: #a084ff;
  --danger: #e05252;
  --danger-hover: #ef6b6b;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

/* ---------- Auth pages ---------- */
.auth-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 16px;
}
.auth-box {
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 32px;
  width: 100%;
  max-width: 360px;
}
.auth-box h1 { margin-top: 0; font-size: 22px; }
.auth-box form { display: flex; flex-direction: column; gap: 14px; margin-top: 16px; }
.auth-box label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--text-muted); }

input[type=text], input[type=password], textarea {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  padding: 9px 10px;
  font-size: 14px;
  font-family: inherit;
}
input:focus, textarea:focus { outline: none; border-color: var(--accent); }

.muted { color: var(--text-muted); font-size: 14px; }
.small { font-size: 12px; }

.alert { padding: 10px 12px; border-radius: 6px; font-size: 13px; margin-bottom: 8px; }
.alert-error { background: rgba(224,82,82,0.15); color: #ff8f8f; border: 1px solid rgba(224,82,82,0.4); }
.alert-success { background: rgba(87,180,120,0.15); color: #8fe0ac; border: 1px solid rgba(87,180,120,0.4); }

.btn {
  display: inline-block;
  text-align: center;
  border-radius: 6px;
  border: 1px solid var(--border);
  padding: 9px 14px;
  font-size: 14px;
  cursor: pointer;
  background: var(--bg-hover);
  color: var(--text);
  text-decoration: none;
}
.btn:hover { background: #3a3a3a; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn-outline { background: transparent; }
.btn-danger { background: transparent; color: var(--danger); border-color: var(--danger); }
.btn-danger:hover:not(:disabled) { background: rgba(224,82,82,0.12); color: var(--danger-hover); }
.btn-block { width: 100%; }

/* ---------- App layout ---------- */
.app-page, #app { height: 100vh; }
#app { display: flex; }

.sidebar {
  width: 280px;
  min-width: 220px;
  background: var(--bg-alt);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}
.sidebar-header {
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
}
.user-badge { font-size: 12px; color: var(--text-muted); }
.sidebar-actions { padding: 12px 14px; display: flex; flex-direction: column; gap: 8px; }
.sidebar-footer { padding: 12px 14px; border-top: 1px solid var(--border); }

.note-list { list-style: none; margin: 0; padding: 0 8px; overflow-y: auto; flex: 1; }
.note-item {
  padding: 9px 10px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.note-item:hover { background: var(--bg-hover); }
.note-item.active { background: rgba(140,108,247,0.18); color: #cbb8ff; }

.editor-area { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.editor-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
}
.editor-toolbar #noteTitle {
  flex: 1;
  font-size: 16px;
  font-weight: 600;
  background: transparent;
  border: none;
}
.toolbar-buttons { display: flex; gap: 8px; }

.editor-body { flex: 1; position: relative; overflow: hidden; }
#noteContent {
  width: 100%;
  height: 100%;
  border: none;
  border-radius: 0;
  resize: none;
  font-size: 15px;
  line-height: 1.6;
  padding: 20px 24px;
}
.note-preview {
  width: 100%;
  height: 100%;
  overflow-y: auto;
  padding: 20px 24px;
  line-height: 1.7;
}
.note-preview h1, .note-preview h2, .note-preview h3 { color: #fff; }
.note-preview a.wikilink { color: var(--accent); text-decoration: none; border-bottom: 1px dashed var(--accent); }
.note-preview a.wikilink:hover { color: var(--accent-hover); }
.note-preview code { background: var(--bg-alt); padding: 2px 5px; border-radius: 4px; }
.note-preview pre { background: var(--bg-alt); padding: 12px; border-radius: 6px; overflow-x: auto; }

.hidden { display: none !important; }

.status-bar {
  padding: 6px 16px;
  font-size: 12px;
  color: var(--text-muted);
  min-height: 24px;
  border-top: 1px solid var(--border);
}

@media (max-width: 720px) {
  #app { flex-direction: column; }
  .sidebar { width: 100%; max-height: 40vh; border-right: none; border-bottom: 1px solid var(--border); }
}

/* ---------- Animations ---------- */
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideIn { from { opacity: 0; transform: translateX(-8px); } to { opacity: 1; transform: translateX(0); } }
@keyframes pulseSave { 0% { transform: scale(1); } 40% { transform: scale(1.08); box-shadow: 0 0 0 4px rgba(140,108,247,0.25); } 100% { transform: scale(1); } }
@keyframes flashStatus { from { opacity: 0; transform: translateY(3px); } to { opacity: 1; transform: translateY(0); } }

.fade-in { animation: fadeIn 0.25s ease; }
.slide-in { animation: slideIn 0.28s ease both; }
.pulse { animation: pulseSave 0.4s ease; }
.status-bar.flash { animation: flashStatus 0.25s ease; }
.note-item, .btn, .wikilink { transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease, transform 0.1s ease; }
.btn:active { transform: scale(0.97); }

/* ---------- New/note row ---------- */
.new-note-row { display: flex; gap: 6px; }
.new-note-row .btn { flex: 1; padding: 8px 6px; font-size: 12px; }

.note-item { display: flex; justify-content: space-between; align-items: center; gap: 6px; }
.note-item-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.note-item-by { font-size: 10px; color: var(--text-muted); flex-shrink: 0; }

.tag-pill {
  background: rgba(140,108,247,0.18);
  color: #cbb8ff;
  border-radius: 10px;
  padding: 1px 8px;
  font-size: 12px;
}

/* ---------- Meta bar (last edited / backlinks) ---------- */
.meta-bar {
  padding: 8px 16px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.backlink-chip {
  display: inline-block;
  background: var(--bg-hover);
  color: var(--accent);
  border-radius: 10px;
  padding: 2px 9px;
  margin: 2px 2px 0 0;
  font-size: 11px;
  text-decoration: none;
}
.backlink-chip:hover { background: rgba(140,108,247,0.2); }

/* ---------- Shape toolbar & canvas ---------- */
.shape-toolbar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-alt);
  flex-wrap: wrap;
}
.shape-btn {
  background: var(--bg-hover);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 12px;
  cursor: pointer;
}
.shape-btn:hover { background: #3a3a3a; }
.shape-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }
#shapeColor { width: 32px; height: 28px; border: none; background: none; padding: 0; cursor: pointer; }

.canvas-wrap { width: 100%; height: 100%; }
#shapeCanvas { width: 100%; height: 100%; display: block; cursor: crosshair; background: #181818; }

/* ---------- Graph page ---------- */
.graph-page { margin: 0; height: 100vh; display: flex; flex-direction: column; }
.graph-topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-alt);
}
#graphCanvas { flex: 1; overflow: hidden; }
#graphCanvas svg { width: 100%; height: 100%; display: block; }
.graph-node { cursor: pointer; }
.graph-node circle { transition: r 0.15s ease; }
.graph-node:hover circle { r: 12; }

/* ---------- Shape toolbar tambahan ---------- */
.toolbar-sep { width: 1px; height: 20px; background: var(--border); margin: 0 4px; }
.btn-sm { padding: 6px 10px; font-size: 12px; }

/* ---------- Admin page ---------- */
.admin-page { margin: 0; min-height: 100vh; }
.admin-topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-alt);
}
.admin-wrap {
  max-width: 820px;
  margin: 24px auto;
  padding: 0 16px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}
.admin-card {
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px 22px;
}
.admin-card h2 { margin-top: 0; font-size: 16px; }
.inline-form { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.inline-form input, .inline-form select {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  padding: 8px 10px;
  font-size: 13px;
}
.admin-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.admin-table th, .admin-table td {
  text-align: left;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
}
.admin-table th { color: var(--text-muted); font-weight: 500; font-size: 12px; }
.role-badge { padding: 2px 8px; border-radius: 10px; font-size: 11px; }
.role-badge.role-admin { background: rgba(140,108,247,0.2); color: #cbb8ff; }
.role-badge.role-user { background: rgba(255,255,255,0.08); color: var(--text-muted); }
.trash-actions { display: flex; gap: 6px; }
.trash-actions .btn { padding: 5px 9px; font-size: 11px; }

/* ---------- Calendar ---------- */
.calendar-topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
}
.month-label { font-size: 15px; flex: 1; }

.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 1px;
  background: var(--border);
  flex: 1;
  overflow-y: auto;
}
.cal-dow {
  background: var(--bg-alt);
  text-align: center;
  font-size: 11px;
  color: var(--text-muted);
  padding: 6px 0;
}
.cal-cell {
  background: var(--bg);
  min-height: 68px;
  padding: 6px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.cal-cell:hover { background: var(--bg-hover); }
.cal-empty { cursor: default; background: #191919; }
.cal-empty:hover { background: #191919; }
.cal-daynum { font-size: 12px; color: var(--text-muted); }
.cal-today .cal-daynum {
  background: var(--accent);
  color: #fff;
  width: 20px; height: 20px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 11px;
}
.cal-selected { outline: 1.5px solid var(--accent); outline-offset: -1.5px; }
.cal-dots { display: flex; gap: 3px; }
.cal-dot { width: 5px; height: 5px; border-radius: 50%; background: var(--accent); }
.cal-event-label {
  font-size: 10px;
  color: #cbb8ff;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Panel tambah/edit event */
.event-panel {
  border-top: 1px solid var(--border);
  background: var(--bg-alt);
  padding: 12px 16px;
  max-height: 46vh;
  overflow-y: auto;
}
.event-panel-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.event-day-list { list-style: none; margin: 0 0 10px; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.event-day-item {
  background: var(--bg-hover);
  border-radius: 6px;
  padding: 7px 10px;
  font-size: 13px;
  cursor: pointer;
  display: flex;
  gap: 8px;
  align-items: center;
}
.event-day-item:hover { background: #3a3a3a; }
.event-time-badge {
  background: rgba(140,108,247,0.2);
  color: #cbb8ff;
  border-radius: 8px;
  padding: 1px 7px;
  font-size: 10px;
  flex-shrink: 0;
}

.event-form { display: flex; flex-direction: column; gap: 10px; margin-top: 6px; }
.event-form label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--text-muted); }
.event-form input, .event-form select, .event-form textarea {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  padding: 8px 10px;
  font-size: 13px;
  font-family: inherit;
}
.event-form-actions { display: flex; gap: 8px; }

/* Sidebar: akan datang */
.upcoming-wrap { padding: 10px 14px; border-top: 1px solid var(--border); flex: 1; overflow-y: auto; }
.upcoming-title { font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-muted); margin-bottom: 8px; }
.upcoming-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.upcoming-item {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  background: var(--bg-hover);
  border-radius: 6px;
  padding: 6px 8px;
  cursor: pointer;
  font-size: 12px;
}
.upcoming-item:hover { background: #3a3a3a; }
.upcoming-date {
  background: rgba(140,108,247,0.2);
  color: #cbb8ff;
  border-radius: 6px;
  padding: 3px 6px;
  font-size: 10px;
  flex-shrink: 0;
  white-space: nowrap;
}

@media (max-width: 720px) {
  .cal-cell { min-height: 52px; padding: 4px; }
  .cal-event-label { display: none; }
}
