:root {
  --bg-primary: #313338;
  --bg-secondary: #2b2d31;
  --bg-tertiary: #1e1f22;
  --bg-modifier-hover: rgba(79, 84, 92, 0.32);
  --bg-modifier-active: rgba(79, 84, 92, 0.48);
  --text-normal: #dbdee1;
  --text-muted: #949ba4;
  --text-link: #00a8fc;
  --brand: #5865f2;
  --brand-hover: #4752c4;
  --danger: #da373c;
  --danger-hover: #a12828;
  --header-primary: #f2f3f5;
  --interactive-normal: #b5bac1;
  --spoiler-bg: #1e1f22;
  --spoiler-revealed: #949ba4;
  --code-bg: #2b2d31;
  --blockquote-border: #4e5058;
  --scrollbar: #1a1b1e;
  --font: "Noto Sans", "gg sans", "Helvetica Neue", Helvetica, Arial, sans-serif;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  font-family: var(--font);
  background: var(--bg-primary);
  color: var(--text-normal);
  font-size: 16px;
  line-height: 1.375;
}

button, input, textarea {
  font-family: inherit;
}

.app {
  display: flex;
  height: 100vh;
}

/* Sidebar */
.sidebar {
  width: 300px;
  min-width: 260px;
  background: var(--bg-secondary);
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--bg-tertiary);
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px;
  border-bottom: 1px solid var(--bg-tertiary);
}

.sidebar-header h1 {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--header-primary);
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-search {
  padding: 8px 12px;
}

.sidebar-search input {
  width: 100%;
  padding: 8px 10px;
  border: none;
  border-radius: 4px;
  background: var(--bg-tertiary);
  color: var(--text-normal);
  font-size: 14px;
  outline: none;
}

.sidebar-search input::placeholder {
  color: var(--text-muted);
}

.sidebar-header-actions {
  display: flex;
  gap: 4px;
  align-items: center;
}

.btn-icon {
  background: transparent;
  border: none;
  color: var(--interactive-normal);
  min-width: 32px;
  height: 32px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 13px;
  line-height: 1;
  padding: 0 8px;
  white-space: nowrap;
}

.btn-icon:hover:not(:disabled) {
  background: var(--bg-modifier-hover);
}

.btn-icon:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.sidebar-tree {
  list-style: none;
  flex: 1;
  overflow-y: auto;
  padding: 4px 8px 8px;
}

.sidebar-tree::-webkit-scrollbar {
  width: 8px;
}

.sidebar-tree::-webkit-scrollbar-thumb {
  background: var(--scrollbar);
  border-radius: 4px;
}

.folder-group {
  margin-bottom: 4px;
}

.folder-header {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 10px;
  border-radius: 4px;
  cursor: pointer;
  user-select: none;
  transition: background 0.1s;
}

.folder-header:hover {
  background: var(--bg-modifier-hover);
}

.folder-header.active {
  background: var(--bg-modifier-active);
}

.folder-toggle {
  width: 20px;
  height: 20px;
  font-size: 10px;
  color: var(--text-muted);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 3px;
  border: none;
  background: transparent;
  cursor: pointer;
  padding: 0;
}

.folder-toggle:hover {
  background: var(--bg-tertiary);
  color: var(--header-primary);
}

.folder-icon {
  font-size: 14px;
  flex-shrink: 0;
}

.folder-name {
  flex: 1;
  font-size: 13px;
  font-weight: 600;
  color: var(--header-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.folder-count {
  font-size: 11px;
  color: var(--text-muted);
  flex-shrink: 0;
}

.folder-actions {
  display: none;
  gap: 2px;
  flex-shrink: 0;
}

.folder-header:hover .folder-actions {
  display: flex;
}

.folder-actions button {
  background: transparent;
  border: none;
  color: var(--text-muted);
  width: 22px;
  height: 22px;
  border-radius: 3px;
  cursor: pointer;
  font-size: 12px;
  padding: 0;
}

.folder-actions button:hover {
  background: var(--bg-tertiary);
  color: var(--header-primary);
}

.folder-actions .btn-folder-delete:hover {
  color: var(--danger);
}

.folder-notes {
  list-style: none;
  padding-left: 12px;
  margin-left: 10px;
  border-left: 1px solid var(--bg-tertiary);
}

.folder-notes.collapsed {
  display: none;
}

.folder-select {
  background: var(--bg-tertiary);
  border: none;
  border-radius: 4px;
  color: var(--text-normal);
  font-size: 13px;
  padding: 6px 10px;
  outline: none;
  max-width: 160px;
  cursor: pointer;
}

.folder-select:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.folder-select option {
  background: var(--bg-secondary);
}

.folder-label {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
}

.editor-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding: 6px 16px;
  background: var(--bg-secondary);
  border-top: 1px solid var(--bg-tertiary);
  font-size: 12px;
}

.char-count {
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.user-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--bg-tertiary);
}

.user-avatar {
  border-radius: 50%;
  flex-shrink: 0;
}

.user-name {
  flex: 1;
  font-size: 13px;
  color: var(--header-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-logout {
  color: var(--text-muted);
  text-decoration: none;
  font-size: 16px;
  padding: 4px;
  border-radius: 4px;
}

.user-logout:hover {
  background: var(--bg-modifier-hover);
  color: var(--danger);
}

.note-item[draggable="true"] {
  cursor: grab;
}

.note-item.dragging {
  opacity: 0.5;
}

.folder-header.drag-over,
.folder-notes.drag-over {
  outline: 2px dashed var(--brand);
  outline-offset: -2px;
  background: rgba(88, 101, 242, 0.1);
}

.discord-avatar.has-image {
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
}

/* Login */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-primary);
  padding: 24px;
}

.login-card {
  background: var(--bg-secondary);
  border-radius: 8px;
  padding: 32px;
  max-width: 400px;
  width: 100%;
  text-align: center;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}

.login-card h1 {
  color: var(--header-primary);
  margin-bottom: 12px;
}

.login-card p {
  color: var(--text-muted);
  font-size: 14px;
  line-height: 1.5;
  margin-bottom: 24px;
}

.login-hint {
  font-size: 13px !important;
  margin-top: 16px !important;
}

.login-hint code {
  background: var(--bg-tertiary);
  padding: 2px 5px;
  border-radius: 3px;
  font-size: 12px;
}

.login-error {
  color: var(--danger);
  font-size: 13px;
  margin-top: 16px;
}

.btn-discord {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: #5865f2;
  color: #fff;
  text-decoration: none;
  padding: 12px 24px;
  border-radius: 4px;
  font-weight: 600;
  font-size: 15px;
  transition: background 0.15s;
}

.btn-discord:hover {
  background: #4752c4;
}

.denied-card .btn {
  margin-top: 8px;
}

.note-list {
  list-style: none;
  flex: 1;
  overflow-y: auto;
  padding: 4px 8px;
}

.note-list::-webkit-scrollbar {
  width: 8px;
}

.note-list::-webkit-scrollbar-thumb {
  background: var(--scrollbar);
  border-radius: 4px;
}

.note-item {
  padding: 10px 12px;
  border-radius: 4px;
  cursor: pointer;
  margin-bottom: 2px;
  transition: background 0.1s;
}

.note-item:hover {
  background: var(--bg-modifier-hover);
}

.note-item.active {
  background: var(--bg-modifier-active);
}

.note-item-title {
  font-size: 14px;
  font-weight: 500;
  color: var(--header-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.note-item-preview {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
}

.note-item-date {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
}

.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--bg-tertiary);
  font-size: 12px;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.server-status {
  font-size: 11px;
}

.server-status.online {
  color: #45ba6d;
}

.server-status.offline {
  color: var(--danger);
}

/* Editor area */
.editor-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--bg-tertiary);
}

.title-input {
  flex: 1;
  background: transparent;
  border: none;
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--header-primary);
  outline: none;
}

.title-input::placeholder {
  color: var(--text-muted);
}

.toolbar-actions {
  display: flex;
  gap: 8px;
}

.btn {
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  padding: 8px 16px;
  transition: background 0.15s, opacity 0.15s;
}

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--brand);
  color: #fff;
  width: 32px;
  height: 32px;
  padding: 0;
  font-size: 20px;
  line-height: 1;
}

.btn-primary:hover:not(:disabled) {
  background: var(--brand-hover);
}

.btn-accent {
  background: var(--brand);
  color: #fff;
}

.btn-accent:hover:not(:disabled) {
  background: var(--brand-hover);
}

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  padding: 8px 10px;
}

.btn-ghost:hover:not(:disabled) {
  background: var(--bg-modifier-hover);
  color: var(--danger);
}

/* Split view */
.split-view {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 1fr;
  min-height: 0;
}

.pane {
  display: flex;
  flex-direction: column;
  min-height: 0;
  border-right: 1px solid var(--bg-tertiary);
}

.pane:last-child {
  border-right: none;
}

.pane-label {
  padding: 8px 16px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--bg-tertiary);
}

.pane-editor {
  display: flex;
  flex-direction: column;
}

.editor-textarea {
  flex: 1;
  width: 100%;
  resize: none;
  border: none;
  outline: none;
  padding: 16px;
  background: var(--bg-primary);
  color: var(--text-normal);
  font-size: 16px;
  line-height: 1.5;
  font-family: "Consolas", "Courier New", monospace;
}

.editor-textarea::placeholder {
  color: var(--text-muted);
  font-family: var(--font);
  white-space: pre-line;
}

.preview-wrapper {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  background: var(--bg-primary);
}

.preview-wrapper::-webkit-scrollbar {
  width: 8px;
}

.preview-wrapper::-webkit-scrollbar-thumb {
  background: var(--scrollbar);
  border-radius: 4px;
}

/* Discord message mock */
.discord-message {
  display: flex;
  gap: 16px;
  padding: 2px 0;
}

.discord-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--brand), #7289da);
  flex-shrink: 0;
}

.discord-body {
  flex: 1;
  min-width: 0;
}

.discord-header {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 4px;
}

.discord-username {
  font-weight: 500;
  color: var(--header-primary);
  font-size: 1rem;
}

.discord-timestamp {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 400;
}

.discord-content {
  color: var(--text-normal);
  font-size: 1rem;
  line-height: 1.375;
  word-wrap: break-word;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

/* Discord markdown styles */
.discord-content h1 {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--header-primary);
  line-height: 1.2;
  margin: 0;
}

.discord-content h2 {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--header-primary);
  line-height: 1.2;
  margin: 0;
}

.discord-content h3 {
  font-size: 1.125rem;
  font-weight: 700;
  color: var(--header-primary);
  line-height: 1.2;
  margin: 0;
}

.discord-content .dc-subtext {
  font-size: 0.75rem;
  color: var(--text-muted);
  display: block;
}

.discord-content strong {
  font-weight: 700;
}

.discord-content em {
  font-style: italic;
}

.discord-content u {
  text-decoration: underline;
}

.discord-content s {
  text-decoration: line-through;
}

.discord-content code {
  background: var(--code-bg);
  padding: 0.1em 0.25em;
  border-radius: 3px;
  font-family: "Consolas", "Courier New", monospace;
  font-size: 0.875em;
  line-height: 1.125;
}

.discord-content pre {
  background: var(--code-bg);
  border: 1px solid var(--bg-tertiary);
  border-radius: 4px;
  padding: 8px;
  margin: 4px 0;
  overflow-x: auto;
  max-width: 100%;
}

.discord-content pre code {
  background: none;
  padding: 0;
  font-size: 0.875rem;
  white-space: pre;
  display: block;
}

.discord-content blockquote {
  border-left: 4px solid var(--blockquote-border);
  padding-left: 8px;
  margin: 0;
  color: var(--text-muted);
}

.discord-content .dc-spoiler {
  background: var(--spoiler-bg);
  color: transparent;
  border-radius: 3px;
  padding: 0 2px;
  cursor: pointer;
  transition: background 0.1s, color 0.1s;
  user-select: none;
}

.discord-content .dc-spoiler:hover {
  background: rgba(30, 31, 34, 0.8);
}

.discord-content .dc-spoiler.revealed {
  background: rgba(148, 155, 164, 0.15);
  color: var(--spoiler-revealed);
}

.discord-content a {
  color: var(--text-link);
  text-decoration: none;
}

.discord-content a:hover {
  text-decoration: underline;
}

.discord-content .dc-mention {
  background: rgba(88, 101, 242, 0.3);
  color: #c9cdfb;
  padding: 0 2px;
  border-radius: 3px;
  font-weight: 500;
  cursor: pointer;
}

.discord-content .dc-mention:hover {
  background: var(--brand);
  color: #fff;
}

.discord-content .dc-channel {
  background: rgba(88, 101, 242, 0.15);
  color: var(--text-link);
  padding: 0 2px;
  border-radius: 3px;
  cursor: pointer;
}

.discord-content .dc-channel:hover {
  text-decoration: underline;
}

.discord-content .dc-emoji {
  width: 1.375em;
  height: 1.375em;
  vertical-align: -0.3em;
  object-fit: contain;
}

.discord-content ul,
.discord-content ol {
  margin: 0;
  padding-left: 1.5em;
}

.discord-content li {
  margin: 0;
}

/* Syntax highlighting (Discord-like) */
.hljs-addition,
.dc-diff-add {
  color: #45ba6d;
}

.hljs-deletion,
.dc-diff-del {
  color: #f23f43;
}

.hljs-keyword { color: #c678dd; }
.hljs-string { color: #98c379; }
.hljs-number { color: #d19a66; }
.hljs-comment { color: #7f848e; }
.hljs-function { color: #61afef; }
.hljs-title { color: #e5c07b; }
.hljs-built_in { color: #e5c07b; }
.hljs-attr { color: #d19a66; }
.hljs-tag { color: #e06c75; }

/* Format bar */
.format-bar {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 8px 16px;
  background: var(--bg-secondary);
  border-top: 1px solid var(--bg-tertiary);
  flex-wrap: wrap;
}

.format-bar button {
  background: transparent;
  border: none;
  color: var(--interactive-normal);
  width: 32px;
  height: 28px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
}

.format-bar button:hover {
  background: var(--bg-modifier-hover);
  color: var(--header-primary);
}

.format-divider {
  width: 1px;
  height: 20px;
  background: var(--bg-tertiary);
  margin: 0 4px;
}

/* Server-Banner */
.server-banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  background: var(--danger);
  color: #fff;
  text-align: center;
  padding: 10px 16px;
  font-size: 13px;
  z-index: 1001;
}

.server-banner code {
  background: rgba(0, 0, 0, 0.25);
  padding: 2px 6px;
  border-radius: 3px;
  font-family: Consolas, monospace;
}

body.server-offline .app {
  padding-top: 40px;
}

body.server-offline .btn-new,
body.server-offline .btn-icon,
body.server-offline #btnSave {
  pointer-events: none;
  opacity: 0.5;
}

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  z-index: 2000;
  padding: 16px;
  align-items: center;
  justify-content: center;
}

.modal-overlay:not([hidden]) {
  display: flex;
}

.modal-input[hidden] {
  display: none !important;
}

.modal {
  background: var(--bg-secondary);
  border-radius: 8px;
  padding: 20px;
  width: 100%;
  max-width: 360px;
  box-shadow: 0 16px 32px rgba(0, 0, 0, 0.5);
}

.modal-title {
  font-size: 1.1rem;
  color: var(--header-primary);
  margin-bottom: 12px;
}

.modal-text {
  font-size: 14px;
  color: var(--text-muted);
  margin-bottom: 12px;
  line-height: 1.4;
}

.modal-input {
  width: 100%;
  padding: 10px 12px;
  border: none;
  border-radius: 4px;
  background: var(--bg-tertiary);
  color: var(--text-normal);
  font-size: 15px;
  outline: none;
  margin-bottom: 16px;
}

.modal-input:focus {
  box-shadow: 0 0 0 2px var(--brand);
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--bg-tertiary);
  color: var(--header-primary);
  padding: 12px 20px;
  border-radius: 8px;
  box-shadow: 0 8px 16px rgba(0, 0, 0, 0.4);
  font-size: 14px;
  z-index: 1000;
  animation: slideIn 0.2s ease;
}

@keyframes slideIn {
  from { transform: translateY(12px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

.empty-state {
  padding: 24px 16px;
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
}

@media (max-width: 900px) {
  .split-view {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr 1fr;
  }

  .sidebar {
    width: 220px;
  }
}
