:root {
  --bg: #0f0f0f;
  --bg2: #161616;
  --bg3: #1e1e1e;
  --bg4: #252525;
  --border: #2a2a2a;
  --border2: #333;
  --text: #e8e4dc;
  --text2: #9a9589;
  --text3: #5a5550;
  --accent: #d4a853;
  --accent2: #b8872d;
  --accent-dim: rgba(212, 168, 83, 0.12);
  --accent-dim2: rgba(212, 168, 83, 0.06);
  --red: #c0392b;
  --green: #27ae60;
  --sidebar-w: 260px;
  --rs-w: 340px;
  --r: 8px;
  --r2: 12px;
  --top-nav-h: 56px;
  --status-bar-h: 30px;
  --toolbar-h: 48px;
  --bottom-bar-h: 100px;
  --shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  height: 100%;
  font-family: 'DM Sans', sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}

::-webkit-scrollbar {
  width: 3px;
  height: 3px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--border2);
  border-radius: 2px;
}

/* ===== ONBOARDING ===== */
#onboarding {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 16px;
  overflow-y: auto;
}

.onboard-card {
  width: 100%;
  max-width: 460px;
  padding: 40px 36px;
  background: var(--bg2);
  border: 1px solid var(--border2);
  border-radius: 16px;
  position: relative;
  overflow: hidden;
}

.onboard-card::before {
  content: '';
  position: absolute;
  top: -60px;
  right: -60px;
  width: 200px;
  height: 200px;
  background: radial-gradient(circle, rgba(212, 168, 83, 0.15) 0%, transparent 70%);
  pointer-events: none;
}

.onboard-logo {
  font-family: 'Lora', serif;
  font-size: 28px;
  font-weight: 600;
  color: var(--accent);
  margin-bottom: 6px;
}

.onboard-sub {
  font-size: 13px;
  color: var(--text2);
  margin-bottom: 28px;
  line-height: 1.6;
}

.onboard-step {
  display: none;
}

.onboard-step.active {
  display: block;
}

.step-label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--text3);
  margin-bottom: 16px;
}

.form-group {
  margin-bottom: 14px;
}

.form-label {
  display: block;
  font-size: 12px;
  color: var(--text2);
  margin-bottom: 5px;
  font-weight: 500;
}

.form-input,
.form-select,
.form-textarea {
  width: 100%;
  background: var(--bg3);
  border: 1px solid var(--border2);
  border-radius: var(--r);
  padding: 11px 12px;
  color: var(--text);
  font-size: 14px;
  font-family: 'DM Sans', sans-serif;
  outline: none;
  transition: border-color .2s;
  -webkit-appearance: none;
  appearance: none;
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
  border-color: var(--accent);
}

.form-select option {
  background: var(--bg3);
}

.form-textarea {
  resize: vertical;
  min-height: 72px;
  line-height: 1.5;
}

.btn-primary {
  width: 100%;
  padding: 13px;
  background: var(--accent);
  color: #0f0f0f;
  border: none;
  border-radius: var(--r);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  font-family: 'DM Sans', sans-serif;
  transition: background .2s, transform .1s;
  margin-top: 6px;
}

.btn-primary:hover {
  background: var(--accent2);
}

.btn-primary:active {
  transform: scale(.98);
}

.btn-secondary {
  width: 100%;
  padding: 11px;
  background: var(--bg3);
  color: var(--text2);
  border: 1px solid var(--border2);
  border-radius: var(--r);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  font-family: 'DM Sans', sans-serif;
  transition: all .2s;
  margin-top: 6px;
}

.btn-secondary:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.step-dots {
  display: flex;
  gap: 6px;
  margin-bottom: 24px;
}

.step-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--border2);
  transition: background .3s;
}

.step-dot.active {
  background: var(--accent);
}

.provider-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 10px;
}

.provider-btn {
  padding: 11px 10px;
  background: var(--bg3);
  border: 1px solid var(--border2);
  border-radius: var(--r);
  color: var(--text2);
  font-size: 12px;
  font-family: 'DM Sans', sans-serif;
  cursor: pointer;
  transition: all .2s;
  text-align: left;
  line-height: 1.3;
}

.provider-btn:hover {
  border-color: var(--accent);
  color: var(--text);
}

.provider-btn.active {
  border-color: var(--accent);
  background: var(--accent-dim);
  color: var(--accent);
}

/* ===== MODAL ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .7);
  backdrop-filter: blur(4px);
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  animation: fadeIn .2s ease;
}

.modal {
  width: 100%;
  max-width: 500px;
  max-height: 88vh;
  background: var(--bg2);
  border: 1px solid var(--border2);
  border-radius: 14px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.modal-header {
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.modal-title {
  font-family: 'Lora', serif;
  font-size: 17px;
  font-weight: 500;
}

.modal-close {
  background: none;
  border: none;
  color: var(--text2);
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
  padding: 6px;
  border-radius: 4px;
  min-width: 32px;
  min-height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-body {
  padding: 20px;
  overflow-y: auto;
  flex: 1;
}

.modal-section {
  margin-bottom: 24px;
}

.modal-section-title {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--accent);
  margin-bottom: 12px;
}

/* ===== MAIN APP LAYOUT ===== */
#app {
  display: flex;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  padding-bottom: var(--status-bar-h);
}

#workspace {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  position: relative;
  background: var(--bg);
}

.view {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  padding: 20px;
  max-width: 1200px;
  margin: 0 auto;
  width: 100%;
}

@media (max-width: 900px) {
  #workspace {
    padding-bottom: calc(var(--status-bar-h) + var(--bottom-bar-h));
  }
}

/* TOP NAV / BREADCRUMBS */
#top-nav {
  height: var(--top-nav-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  flex-shrink: 0;
}

#breadcrumbs {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  font-weight: 500;
}

.bc-item {
  color: var(--text3);
  cursor: pointer;
  transition: color .2s;
  white-space: nowrap;
}

.bc-item:hover {
  color: var(--text2);
}

.bc-item.active {
  color: var(--text);
}

.bc-sep {
  color: var(--text3);
  font-size: 10px;
}

.top-nav-actions {
  display: flex;
  gap: 4px;
}

/* ===== SIDEBAR ===== */
#sidebar {
  width: var(--sidebar-w);
  background: var(--bg2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow: hidden;
  transition: transform .25s ease;
  padding-bottom: 30px;
}

.sidebar-header {
  padding: 14px 14px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.logo {
  font-family: 'Lora', serif;
  font-size: 19px;
  font-weight: 600;
  color: var(--accent);
}

.sidebar-actions {
  display: flex;
  gap: 2px;
}



.icon-btn {
  background: none;
  border: none;
  color: var(--text2);
  cursor: pointer;
  min-width: 36px;
  min-height: 36px;
  border-radius: var(--r);
  font-size: 16px;
  transition: all .15s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.icon-btn:hover {
  color: var(--text);
  background: var(--bg3);
}

.sidebar-search {
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.search-input {
  width: 100%;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 8px 10px;
  color: var(--text);
  font-size: 13px;
  font-family: 'DM Sans', sans-serif;
  outline: none;
  transition: border-color .2s;
}

.search-input:focus {
  border-color: var(--accent);
}

.search-input::placeholder {
  color: var(--text3);
}

.sidebar-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.sidebar-tab {
  flex: 1;
  padding: 9px 6px;
  background: none;
  border: none;
  color: var(--text3);
  font-size: 11px;
  font-family: 'DM Sans', sans-serif;
  cursor: pointer;
  font-weight: 500;
  letter-spacing: .04em;
  text-transform: uppercase;
  border-bottom: 2px solid transparent;
  transition: all .2s;
}

.sidebar-tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.sidebar-content {
  flex: 1;
  overflow-y: auto;
  padding: 6px;
}

.note-item {
  padding: 10px 10px;
  border-radius: var(--r);
  cursor: pointer;
  transition: background .15s;
  margin-bottom: 2px;
  position: relative;
  border: 1px solid transparent;
}

.note-item:hover {
  background: var(--bg3);
}

.note-item.active {
  background: var(--accent-dim);
  border-color: rgba(212, 168, 83, .2);
}

.note-item-title {
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 2px;
  padding-right: 28px;
}

.note-item-preview {
  font-size: 11px;
  color: var(--text3);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 3px;
}

.note-item-meta {
  font-size: 10px;
  color: var(--text3);
  font-family: 'JetBrains Mono', monospace;
}

.note-item-del {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: var(--text3);
  cursor: pointer;
  width: 32px;
  height: 32px;
  border-radius: 4px;
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity .15s;
  line-height: 1;
}

.note-item:hover .note-item-del {
  opacity: 1;
}

.note-item-del:hover {
  color: var(--text);
  background: var(--bg4);
}

@media(hover:none) {
  .note-item-del {
    opacity: 1;
  }
}

/* Folder */
.folder-item {
  padding: 8px 10px;
  border-radius: var(--r);
  cursor: pointer;
  transition: background .15s;
  margin-bottom: 1px;
  display: flex;
  align-items: center;
  gap: 8px;
  user-select: none;
}

.folder-item:hover {
  background: var(--bg3);
}

.folder-item.open .folder-icon-arrow {
  transform: rotate(90deg);
}

.folder-icon-arrow {
  display: inline-block;
  font-size: 10px;
  color: var(--text3);
  transition: transform .2s;
  width: 14px;
}

.folder-emoji {
  font-size: 14px;
  width: 18px;
  text-align: center;
  flex-shrink: 0;
}

.folder-name {
  font-size: 12px;
  font-weight: 600;
  color: var(--text2);
  flex: 1;
  letter-spacing: .02em;
}

.folder-count {
  font-size: 10px;
  color: var(--text3);
  font-family: 'JetBrains Mono', monospace;
}

.folder-del {
  background: none;
  border: none;
  color: transparent;
  cursor: pointer;
  width: 24px;
  height: 24px;
  border-radius: 3px;
  font-size: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.folder-item:hover .folder-del {
  color: var(--text3);
}

.folder-del:hover {
  color: var(--red) !important;
}

@media(hover:none) {
  .folder-del {
    color: var(--text3) !important;
  }
  
  .note-menu-btn {
    opacity: 1 !important;
  }
}

.folder-notes {
  padding-left: 14px;
  border-left: 1px solid var(--border);
  margin-left: 8px;
  margin-bottom: 4px;
  display: none;
}

.folder-notes.open {
  display: block;
}

.folder-add-btn {
  width: 100%;
  padding: 7px 10px;
  background: none;
  border: 1px dashed var(--border2);
  border-radius: var(--r);
  color: var(--text3);
  font-size: 11px;
  font-family: 'DM Sans', sans-serif;
  cursor: pointer;
  text-align: left;
  transition: all .15s;
  margin-bottom: 6px;
}

.folder-add-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.ungrouped-label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text3);
  padding: 8px 10px 4px;
  margin-top: 4px;
}

.template-item {
  padding: 10px;
  border-radius: var(--r);
  margin-bottom: 4px;
  border: 1px solid var(--border);
  background: var(--bg2);
  display: flex;
  align-items: center;
  gap: 8px;
  transition: border-color .15s;
}

.template-item:hover {
  border-color: var(--border2);
  background: var(--bg3);
}

.template-info {
  flex: 1;
  min-width: 0;
}

.template-name {
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.template-desc {
  font-size: 11px;
  color: var(--text3);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.template-actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

.tmpl-use-btn {
  padding: 5px 12px;
  background: var(--accent);
  border: none;
  color: #0f0f0f;
  cursor: pointer;
  border-radius: 4px;
  font-size: 11px;
  font-family: 'DM Sans', sans-serif;
  font-weight: 600;
  transition: all .15s;
  white-space: nowrap;
}

.tmpl-use-btn:hover {
  background: var(--accent2);
}

.tmpl-del-btn {
  width: 28px;
  height: 28px;
  background: none;
  border: none;
  color: var(--text3);
  cursor: pointer;
  border-radius: 4px;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.tmpl-del-btn:hover {
  color: var(--red);
}

/* ===== SIDEBAR ITEMS ===== */
.sidebar-menu {
  padding: 10px;
  border-bottom: 1px solid var(--border);
  overflow-y: auto;
  flex: 1;
}

.sidebar-item {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 12px;
  background: none;
  border: none;
  font-size: 13px;
  color: var(--text2);
  cursor: pointer;
  border-radius: var(--r);
  text-align: left;
  transition: all .2s;
  margin-bottom: 2px;
}

.sidebar-item:hover {
  background: var(--bg3);
  color: var(--text);
}

.sidebar-item.active {
  background: var(--accent-dim);
  color: var(--accent);
}

/* Folder & Tree Styles */
.tree-item {
  margin-bottom: 2px;
}

.tree-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 12px;
  font-size: 13px;
  color: var(--text2);
  border-radius: var(--r);
  transition: background .2s;
}

.tree-row:hover {
  background: var(--bg3);
  color: var(--text);
}

.tree-row.active {
  background: var(--accent-dim);
  color: var(--accent);
}

.tree-arrow {
  width: 16px;
  font-size: 10px;
  opacity: .5;
  transition: transform .2s;
  display: inline-block;
  text-align: center;
  cursor: pointer;
  user-select: none;
  flex-shrink: 0;
}

.tree-arrow.open {
  transform: rotate(90deg);
}

.tree-arrow:hover {
  opacity: 1;
}

.tree-children {
  padding-left: 12px;
  display: none;
}

.tree-children.open {
  display: block;
}

.tree-icon {
  opacity: .7;
  flex-shrink: 0;
}

/* Note Menu Button */
.note-menu-btn {
  background: none;
  border: none;
  color: white;
  opacity: 0;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
  flex-shrink: 0;
  transition: opacity .2s;
}

.note-menu-btn:hover {
  background: var(--bg4);
}

.tree-row:hover .note-menu-btn {
  opacity: 1;
}


/* Sidebar Footer & Persona Badge */
.sidebar-footer {
  padding: 10px;
  border-top: 1px solid var(--border);
}

.persona-badge {
  padding: 8px;
  background: var(--accent-dim2);
  border: 1px solid rgba(212, 168, 83, .12);
  border-radius: var(--r);
  font-size: 11px;
  color: var(--text2);
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.persona-avatar {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 600;
  color: #0f0f0f;
  flex-shrink: 0;
}

.persona-name {
  font-weight: 600;
  color: var(--text);
  font-size: 12px;
}

.persona-role {
  color: var(--text3);
  font-size: 10px;
}

/* ===== MAIN ===== */
#main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}

/* TOOLBAR - horizontal scroll on mobile */
#toolbar {
  padding: 0 8px;
  border-bottom: 1px solid var(--border);
  background: var(--bg2);
  display: flex;
  align-items: center;
  gap: 1px;
  overflow-x: auto;
  overflow-y: visible;
  flex-shrink: 0;
  height: var(--toolbar-h);
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

#toolbar::-webkit-scrollbar {
  display: none;
}

.tb {
  background: none;
  border: none;
  color: var(--text2);
  cursor: pointer;
  min-width: 32px;
  height: 32px;
  border-radius: var(--r);
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 2px;
  transition: all .15s;
  font-family: 'DM Sans', sans-serif;
  font-weight: 600;
  flex-shrink: 0;
  white-space: nowrap;
  padding: 0 6px;
}

.tb:hover {
  color: var(--text);
  background: var(--bg3);
}

.tb.on {
  color: var(--accent);
  background: var(--accent-dim);
}

.tb svg {
  flex-shrink: 0;
}

/* Toolbar Dropdown */
.tb-dropdown {
  position: relative;
  display: inline-flex;
  flex-shrink: 0;
}

.tb-menu {
  position: fixed;
  background: var(--bg2);
  border: 1px solid var(--border2);
  border-radius: var(--r2);
  padding: 4px;
  min-width: 180px;
  z-index: 10000;
  visibility: hidden;
  opacity: 0;
  transform: translateY(-10px);
  box-shadow: 0 8px 32px rgba(0, 0, 0, .6);
  transition: visibility .2s, opacity .2s, transform .2s;
  pointer-events: none;
}

.tb-menu.show {
  visibility: visible;
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

.tb-menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: var(--r);
  cursor: pointer;
  font-size: 13px;
  color: var(--text2);
  border: none;
  background: none;
  width: 100%;
  font-family: 'DM Sans', sans-serif;
  text-align: left;
  transition: all .15s;
  white-space: nowrap;
}

.tb-menu-item:hover {
  background: var(--bg3);
  color: var(--text);
}

.tb-menu-item svg {
  flex-shrink: 0;
  opacity: .7;
}

.tb-sep {
  width: 1px;
  min-width: 1px;
  height: 20px;
  background: var(--border2);
  margin: 0 3px;
  flex-shrink: 0;
}

.tb-spacer {
  flex: 1;
}

/* AI Dropdown - Desktop */
.ai-drop {
  position: relative;
  display: inline-flex;
  align-items: center;
  flex-shrink: 0;
  z-index: 100;
}

.ai-btn {
  padding: 0 12px;
  height: 32px;
  background: var(--accent-dim);
  border: 1px solid rgba(212, 168, 83, .3);
  border-radius: var(--r);
  color: var(--accent);
  font-size: 12px;
  font-family: 'DM Sans', sans-serif;
  font-weight: 600;
  cursor: pointer;
  transition: all .2s;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  white-space: nowrap;
  position: relative;
  z-index: 101;
  pointer-events: auto;
}

.ai-btn:hover {
  background: var(--accent);
  color: #0f0f0f;
}

.ai-btn:active {
  transform: scale(0.98);
}

.ai-menu {
  position: fixed;
  background: var(--bg2);
  border: 1px solid var(--border2);
  border-radius: var(--r2);
  padding: 6px;
  min-width: 200px;
  z-index: 10000;
  visibility: hidden;
  opacity: 0;
  transform: translateY(-10px);
  box-shadow: 0 8px 32px rgba(0, 0, 0, .6);
  transition: visibility .2s, opacity .2s, transform .2s;
  pointer-events: none;
}

.ai-menu.show {
  visibility: visible;
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

.ai-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--r);
  cursor: pointer;
  font-size: 13px;
  color: var(--text2);
  border: none;
  background: none;
  width: 100%;
  font-family: 'DM Sans', sans-serif;
  text-align: left;
  transition: all .15s;
}

.ai-item:hover {
  background: var(--bg3);
  color: var(--text);
}

.ai-item .ic {
  font-size: 14px;
  width: 18px;
  text-align: center;
  flex-shrink: 0;
}

/* NOTE HEADER */
#note-header {
  padding: 16px 20px 0;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

#note-title {
  width: 100%;
  background: none;
  border: none;
  font-family: 'Lora', serif;
  font-size: 24px;
  font-weight: 600;
  color: var(--text);
  outline: none;
  padding-bottom: 12px;
  line-height: 1.3;
  letter-spacing: -.3px;
}

#note-title::placeholder {
  color: var(--text3);
}

.meta-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 7px 0;
  border-top: 1px solid var(--border);
  font-size: 10px;
  color: var(--text3);
  font-family: 'JetBrains Mono', monospace;
  flex-wrap: wrap;
}

.meta-item {
  display: flex;
  align-items: center;
  gap: 3px;
}

#meta-saved {
  margin-left: auto;
  color: var(--green);
}

/* EDITOR - Tiptap */
#editor-wrap {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  background: var(--bg);
  -webkit-overflow-scrolling: touch;
}

#editor {
  min-height: 200px;
  outline: none;
  font-size: 16px;
  line-height: 1.85;
  color: var(--text);
  font-family: 'DM Sans', sans-serif;
  max-width: 720px;
  caret-color: var(--accent);
  word-wrap: break-word;
  overflow-wrap: break-word;
}

/* Contenteditable fallback styles */
#editor[contenteditable="true"] {
  word-wrap: break-word;
  overflow-wrap: break-word;
  white-space: pre-wrap;
}

#editor[contenteditable="true"]:empty::before {
  content: 'Mulai menulis...';
  color: var(--text3);
  pointer-events: none;
}

/* Tiptap base styles */
.tiptap {
  outline: none;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.tiptap p.is-editor-empty:first-child::before {
  content: 'Mulai menulis...';
  color: var(--text3);
  pointer-events: none;
  float: left;
  height: 0;
}

/* Ensure all content respects max-width */
.tiptap > *,
#editor[contenteditable="true"] > * {
  max-width: 100%;
}

/* Prevent horizontal overflow */
.tiptap,
#editor[contenteditable="true"] {
  overflow-x: hidden;
}

/* Tiptap content styles */
.tiptap h1,
#editor[contenteditable="true"] h1 {
  font-family: 'Lora', serif;
  font-size: 28px;
  font-weight: 600;
  margin: 24px 0 12px;
  color: var(--text);
  line-height: 1.3;
  letter-spacing: -0.02em;
}

.tiptap h2,
#editor[contenteditable="true"] h2 {
  font-family: 'Lora', serif;
  font-size: 22px;
  font-weight: 600;
  margin: 20px 0 10px;
  color: var(--text);
  line-height: 1.35;
  letter-spacing: -0.01em;
}

.tiptap h3,
#editor[contenteditable="true"] h3 {
  font-family: 'Lora', serif;
  font-size: 18px;
  font-weight: 600;
  margin: 16px 0 8px;
  color: var(--text);
  line-height: 1.4;
}

.tiptap h4,
#editor[contenteditable="true"] h4 {
  font-family: 'Lora', serif;
  font-size: 16px;
  font-weight: 600;
  margin: 14px 0 7px;
  color: var(--text);
  line-height: 1.45;
}

.tiptap p,
#editor[contenteditable="true"] p {
  margin: 0 0 12px 0;
  line-height: 1.75;
  word-wrap: break-word;
  overflow-wrap: break-word;
  color: var(--text);
}

.tiptap p:last-child,
#editor[contenteditable="true"] p:last-child {
  margin-bottom: 0;
}

.tiptap strong,
#editor[contenteditable="true"] strong,
.tiptap b,
#editor[contenteditable="true"] b {
  font-weight: 600;
  color: var(--text);
}

.tiptap em,
#editor[contenteditable="true"] em,
.tiptap i,
#editor[contenteditable="true"] i {
  font-style: italic;
  font-family: 'Lora', serif;
}

.tiptap ul,
#editor[contenteditable="true"] ul {
  margin: 12px 0;
  padding-left: 24px;
  list-style-type: disc;
}

.tiptap ol,
#editor[contenteditable="true"] ol {
  margin: 12px 0;
  padding-left: 24px;
  list-style-type: decimal;
}

.tiptap li,
#editor[contenteditable="true"] li {
  margin-bottom: 6px;
  line-height: 1.7;
  color: var(--text);
}

.tiptap li:last-child,
#editor[contenteditable="true"] li:last-child {
  margin-bottom: 0;
}

.tiptap li p,
#editor[contenteditable="true"] li p {
  margin: 0;
  display: inline;
}

.tiptap ul ul,
.tiptap ol ul,
#editor[contenteditable="true"] ul ul,
#editor[contenteditable="true"] ol ul {
  list-style-type: circle;
  margin: 6px 0;
}

.tiptap ul ul ul,
.tiptap ol ul ul,
#editor[contenteditable="true"] ul ul ul,
#editor[contenteditable="true"] ol ul ul {
  list-style-type: square;
}

.tiptap ol ol,
.tiptap ul ol,
#editor[contenteditable="true"] ol ol,
#editor[contenteditable="true"] ul ol {
  list-style-type: lower-alpha;
  margin: 6px 0;
}

.tiptap blockquote,
#editor[contenteditable="true"] blockquote {
  border-left: 3px solid var(--accent);
  padding: 12px 16px;
  margin: 16px 0;
  background: var(--accent-dim2);
  border-radius: 0 var(--r) var(--r) 0;
  color: var(--text2);
  font-style: italic;
  font-family: 'Lora', serif;
  font-size: 15px;
}

.tiptap blockquote p,
#editor[contenteditable="true"] blockquote p {
  margin: 0;
  color: var(--text2);
}

.tiptap code,
#editor[contenteditable="true"] code {
  font-family: 'JetBrains Mono', monospace;
  font-size: 13px;
  background: var(--bg3);
  border: 1px solid var(--border2);
  padding: 2px 6px;
  border-radius: 4px;
  color: var(--accent);
  white-space: pre-wrap;
  word-break: break-word;
}

.tiptap pre,
#editor[contenteditable="true"] pre,
.tiptap .code-block,
#editor[contenteditable="true"] .code-block {
  background: var(--bg2);
  border: 1px solid var(--border2);
  border-radius: var(--r2);
  padding: 16px;
  margin: 16px 0;
  overflow-x: auto;
  overflow-y: auto;
  line-height: 1.5;
  max-height: 500px;
  white-space: pre;
  word-wrap: normal;
  overflow-wrap: normal;
  font-family: 'JetBrains Mono', monospace;
  font-size: 13px;
  position: relative;
}

.tiptap pre code,
#editor[contenteditable="true"] pre code,
.tiptap .code-block code,
#editor[contenteditable="true"] .code-block code {
  background: none;
  border: none;
  padding: 0;
  font-size: 13px;
  color: var(--text);
  line-height: 1.6;
  white-space: pre;
  display: block;
  font-family: 'JetBrains Mono', monospace;
  outline: none;
  min-height: 1.6em;
}

/* Make code blocks editable */
.tiptap pre code[contenteditable="true"],
#editor[contenteditable="true"] pre code[contenteditable="true"] {
  cursor: text;
}

/* Ensure code blocks preserve formatting when editing */
.tiptap pre[contenteditable="true"],
#editor[contenteditable="true"] pre[contenteditable="true"],
.tiptap .code-block[contenteditable="true"],
#editor[contenteditable="true"] .code-block[contenteditable="true"] {
  white-space: pre;
}

/* Code block in Tiptap */
.tiptap pre.hljs,
.tiptap pre[class*="language-"] {
  background: var(--bg2);
  margin: 16px 0;
  padding: 16px;
  border-radius: var(--r2);
  border: 1px solid var(--border2);
}

/* Add subtle indicator for code blocks */
.tiptap pre::before,
#editor[contenteditable="true"] pre::before {
  content: 'CODE';
  position: absolute;
  top: 4px;
  right: 8px;
  font-size: 9px;
  font-weight: 600;
  color: var(--text3);
  letter-spacing: 0.05em;
  opacity: 0.5;
  font-family: 'DM Sans', sans-serif;
}

.tiptap hr,
#editor[contenteditable="true"] hr {
  border: none;
  border-top: 2px solid var(--border2);
  margin: 24px 0;
}

/* Better spacing for consecutive elements */
.tiptap h1 + p,
.tiptap h2 + p,
.tiptap h3 + p,
.tiptap h4 + p,
#editor[contenteditable="true"] h1 + p,
#editor[contenteditable="true"] h2 + p,
#editor[contenteditable="true"] h3 + p,
#editor[contenteditable="true"] h4 + p {
  margin-top: 0;
}

.tiptap ul + p,
.tiptap ol + p,
.tiptap blockquote + p,
.tiptap pre + p,
#editor[contenteditable="true"] ul + p,
#editor[contenteditable="true"] ol + p,
#editor[contenteditable="true"] blockquote + p,
#editor[contenteditable="true"] pre + p {
  margin-top: 12px;
}

/* Remove extra spacing from first/last children */
.tiptap > *:first-child,
#editor[contenteditable="true"] > *:first-child {
  margin-top: 0 !important;
}

.tiptap > *:last-child,
#editor[contenteditable="true"] > *:last-child {
  margin-bottom: 0 !important;
}

/* Tiptap Table */
.tiptap table,
#editor[contenteditable="true"] table {
  width: 100%;
  border-collapse: collapse;
  margin: 16px 0;
  font-size: 14px;
  table-layout: auto;
  border: 1px solid var(--border);
}

.tiptap table th,
#editor[contenteditable="true"] table th {
  background: var(--bg2);
  padding: 10px 14px;
  text-align: left;
  font-weight: 600;
  font-size: 12px;
  color: var(--accent);
  letter-spacing: .03em;
  text-transform: uppercase;
  border: 1px solid var(--border2);
  vertical-align: top;
}

.tiptap table td,
#editor[contenteditable="true"] table td {
  padding: 10px 14px;
  border: 1px solid var(--border);
  color: var(--text);
  line-height: 1.6;
  vertical-align: top;
}

.tiptap table tr:nth-child(even) td,
#editor[contenteditable="true"] table tr:nth-child(even) td {
  background: rgba(255, 255, 255, 0.02);
}

.tiptap table tr:hover td,
#editor[contenteditable="true"] table tr:hover td {
  background: var(--bg3);
}

.tiptap table .selectedCell {
  background: var(--accent-dim);
}

/* Table in lists */
.tiptap li table,
#editor[contenteditable="true"] li table {
  margin: 8px 0;
}

/* Tiptap Task List */
.tiptap ul[data-type="taskList"],
#editor[contenteditable="true"] ul[data-type="taskList"] {
  list-style: none;
  padding: 0;
  margin: 8px 0;
}

.tiptap ul[data-type="taskList"] li,
#editor[contenteditable="true"] ul[data-type="taskList"] li {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin: 3px 0;
  padding: 2px 0;
}

.tiptap ul[data-type="taskList"] li > label,
#editor[contenteditable="true"] ul[data-type="taskList"] li > label {
  flex: 0 0 auto;
  margin-top: 4px;
  user-select: none;
}

.tiptap ul[data-type="taskList"] li > label input[type="checkbox"],
#editor[contenteditable="true"] ul[data-type="taskList"] li > label input[type="checkbox"],
#editor[contenteditable="true"] input[type="checkbox"] {
  width: 17px;
  height: 17px;
  border: 2px solid var(--border2);
  border-radius: 4px;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  background: transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all .15s;
}

.tiptap ul[data-type="taskList"] li > label input[type="checkbox"]:hover,
#editor[contenteditable="true"] ul[data-type="taskList"] li > label input[type="checkbox"]:hover,
#editor[contenteditable="true"] input[type="checkbox"]:hover {
  border-color: var(--accent);
}

.tiptap ul[data-type="taskList"] li > label input[type="checkbox"]:checked,
#editor[contenteditable="true"] ul[data-type="taskList"] li > label input[type="checkbox"]:checked,
#editor[contenteditable="true"] input[type="checkbox"]:checked {
  background: var(--accent);
  border-color: var(--accent);
}

.tiptap ul[data-type="taskList"] li > label input[type="checkbox"]:checked::after,
#editor[contenteditable="true"] ul[data-type="taskList"] li > label input[type="checkbox"]:checked::after,
#editor[contenteditable="true"] input[type="checkbox"]:checked::after {
  content: '✓';
  font-size: 11px;
  font-weight: 700;
  color: #0f0f0f;
}

.tiptap ul[data-type="taskList"] li > div,
#editor[contenteditable="true"] ul[data-type="taskList"] li > div {
  flex: 1;
  min-width: 0;
}

.tiptap ul[data-type="taskList"] li[data-checked="true"] > div,
#editor[contenteditable="true"] ul[data-type="taskList"] li[data-checked="true"] > div {
  text-decoration: line-through;
  color: var(--text3);
}


/* Empty state */
#empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--text3);
  text-align: center;
  padding: 40px;
}

.empty-icon {
  font-size: 44px;
  margin-bottom: 14px;
  opacity: .35;
}

.empty-title {
  font-family: 'Lora', serif;
  font-size: 20px;
  color: var(--text2);
  margin-bottom: 8px;
}

.empty-sub {
  font-size: 13px;
  line-height: 1.6;
  max-width: 260px;
}

/* ===== DASHBOARD & STATS ===== */
.view-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
  gap: 12px;
}

.view-header h1 {
  font-family: 'Lora', serif;
  font-size: 24px;
  font-weight: 600;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 16px;
  margin-bottom: 32px;
}

.stat-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--r2);
  padding: 16px;
  transition: border-color .2s;
}

.stat-card:hover {
  border-color: var(--border2);
}

.stat-label {
  font-size: 11px;
  color: var(--text3);
  text-transform: uppercase;
  letter-spacing: .05em;
  margin-bottom: 4px;
}

.stat-value {
  font-size: 24px;
  font-weight: 600;
  color: var(--accent);
  font-family: 'JetBrains Mono', monospace;
}

.section-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.projects-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}

.project-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--r2);
  overflow: hidden;
  cursor: pointer;
  transition: all .2s;
  display: flex;
  flex-direction: column;
}

.project-card:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
  box-shadow: var(--shadow);
}

.pc-header {
  height: 80px;
  background: var(--accent);
  padding: 16px;
  display: flex;
  align-items: flex-end;
}

.pc-title {
  font-size: 18px;
  font-weight: 600;
  color: #0f0f0f;
  font-family: 'Lora', serif;
}

.pc-body {
  padding: 16px;
  flex: 1;
}

.pc-meta {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--text3);
  margin-top: 12px;
  font-family: 'JetBrains Mono', monospace;
}

/* ===== PROJECT DASHBOARD ===== */
.view-toggles {
  display: flex;
  background: var(--bg3);
  padding: 4px;
  border-radius: var(--r);
  gap: 2px;
}

.toggle-btn {
  background: none;
  border: none;
  padding: 6px 16px;
  color: var(--text3);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  border-radius: 4px;
  transition: all .2s;
  font-family: inherit;
}

.toggle-btn.active {
  background: var(--bg2);
  color: var(--text);
}

/* KANBAN BOARD */
.kanban-board {
  display: flex;
  gap: 20px;
  overflow-x: auto;
  padding-bottom: 20px;
  flex: 1;
}

.kanban-col {
  min-width: 300px;
  width: 300px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.col-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 4px;
}

.col-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--text3);
  text-transform: uppercase;
  letter-spacing: .05em;
}

.col-count {
  font-size: 10px;
  background: var(--bg3);
  padding: 2px 6px;
  border-radius: 10px;
  color: var(--text2);
}

.kanban-cards {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 100px;
}

.note-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 12px;
  cursor: pointer;
  transition: border-color .2s;
}

.note-card:hover {
  border-color: var(--text3);
}

.note-card-title {
  font-size: 14px;
  font-weight: 500;
  margin-bottom: 6px;
  color: var(--text);
}

.note-card-preview {
  font-size: 12px;
  color: var(--text3);
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ===== RIGHT SIDEBAR (ASSISTANT) ===== */
#right-sidebar {
  width: var(--rs-w);
  background: var(--bg2);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  transition: transform .25s ease;
}

#right-sidebar.hidden {
  display: none;
}

.rs-tab-close {
  width: 32px;
  height: 32px;
  background: none;
  border: none;
  color: var(--text3);
  cursor: pointer;
  font-size: 16px;
  border-radius: var(--r);
  display: flex;
  align-items: center;
  justify-content: center;
}

.rs-tab-close:hover {
  background: var(--bg3);
  color: var(--text);
}

.rs-view {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.rs-header {
  padding: 16px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  border-bottom: 1px solid var(--border);
}

/* Assistant View specifics */
.badge {
  font-size: 8px;
  vertical-align: middle;
  background: var(--accent-dim);
  color: var(--accent);
  padding: 1px 4px;
  border-radius: 4px;
  border: 1px solid rgba(212, 168, 83, .2);
  margin-left: 4px;
}

.chips-row {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding: 0 10px 10px;
  scrollbar-width: none;
}

.chips-row::-webkit-scrollbar {
  display: none;
}

.chip {
  white-space: nowrap;
  background: var(--bg2);
  border: 1px solid var(--border2);
  border-radius: 20px;
  padding: 6px 12px;
  color: var(--text2);
  font-size: 11px;
  font-family: inherit;
  cursor: pointer;
  transition: all .2s;
}

.chip:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-dim2);
}

.model-picker-wrap {
  border-bottom: 1px solid var(--border);
  padding: 8px;
  background: var(--bg2);
}

.model-select {
  width: 100%;
  min-height: 32px;
  border: 1px solid var(--border2);
  background: var(--bg3);
  color: var(--text);
  font-size: 12px;
  font-family: inherit;
  border-radius: 6px;
  padding: 6px 8px;
  outline: none;
  cursor: pointer;
}

/* ===== STATUS BAR ===== */
#status-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: var(--status-bar-h);
  background: var(--bg2);
  border-top: 1px solid var(--border);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  font-size: 10px;
  color: var(--text3);
  font-family: 'JetBrains Mono', monospace;
}

.sb-sep {
  margin: 0 8px;
  opacity: .3;
}

#sb-save-status {
  color: var(--green);
}

/* ===== CHAT PANEL ===== */
#chat-panel {
  width: var(--chat-w);
  background: var(--bg2);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow: hidden;
  transition: transform .25s ease;
}

#chat-panel.hidden {
  display: none;
}

.chat-header {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.chat-title-row {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}

.chat-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
  animation: pulse 2s infinite;
}

@keyframes pulse {

  0%,
  100% {
    opacity: 1;
  }

  50% {
    opacity: .4;
  }
}

.chat-ctx {
  margin: 0 10px 0;
  padding: 6px 10px;
  background: var(--accent-dim2);
  border: 1px solid rgba(212, 168, 83, .12);
  border-radius: 6px;
  font-size: 11px;
  color: var(--text3);
  display: flex;
  align-items: center;
  gap: 5px;
  flex-shrink: 0;
}

#chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  -webkit-overflow-scrolling: touch;
}

.chat-msg {
  max-width: 92%;
  animation: slideUp .2s ease;
}

.chat-msg.user {
  align-self: flex-end;
}

.chat-msg.ai {
  align-self: flex-start;
  max-width: 95%;
}

.chat-bubble {
  padding: 10px 12px;
  border-radius: 12px;
  font-size: 13px;
  line-height: 1.5;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.user .chat-bubble {
  background: var(--accent-dim);
  border: 1px solid rgba(212, 168, 83, .2);
  color: var(--text);
  border-radius: 12px 12px 4px 12px;
}

.ai .chat-bubble {
  background: var(--bg3);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 12px 12px 12px 4px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
  max-width: 100%;
  overflow: hidden;
}

.chat-bubble p {
  margin: 0 0 8px 0;
  line-height: 1.5;
}

.chat-bubble p:last-child {
  margin-bottom: 0;
}

.chat-bubble p:empty {
  display: none;
}

.chat-bubble code {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  background: var(--bg);
  padding: 2px 5px;
  border-radius: 3px;
  color: var(--accent);
  white-space: pre-wrap;
}

.chat-bubble pre {
  background: var(--bg);
  padding: 10px;
  border-radius: 6px;
  margin: 8px 0;
  overflow-x: auto;
  line-height: 1.4;
}

.chat-bubble pre code {
  background: none;
  padding: 0;
  font-size: 11px;
  color: var(--text);
  white-space: pre;
}

.chat-bubble ul,
.chat-bubble ol {
  margin: 6px 0;
  padding-left: 20px;
}

.chat-bubble li {
  margin-bottom: 4px;
  line-height: 1.5;
}

.chat-bubble li:last-child {
  margin-bottom: 0;
}

.chat-bubble strong {
  font-weight: 600;
  color: var(--text);
}

.chat-bubble em {
  font-style: italic;
}

.chat-bubble h1,
.chat-bubble h2,
.chat-bubble h3 {
  font-family: 'Lora', serif;
  margin: 10px 0 6px 0;
  line-height: 1.3;
}

.chat-bubble h1:first-child,
.chat-bubble h2:first-child,
.chat-bubble h3:first-child {
  margin-top: 0;
}

.chat-bubble h1 {
  font-size: 16px;
  font-weight: 600;
}

.chat-bubble h2 {
  font-size: 15px;
  font-weight: 600;
}

.chat-bubble h3 {
  font-size: 14px;
  font-weight: 600;
}

.chat-bubble blockquote {
  border-left: 3px solid var(--accent);
  padding-left: 10px;
  margin: 8px 0;
  color: var(--text2);
  font-style: italic;
}

.chat-bubble table {
  width: 100%;
  border-collapse: collapse;
  margin: 10px 0;
  font-size: 12px;
  display: block;
  overflow-x: auto;
}

.chat-bubble table th {
  background: var(--bg2);
  padding: 6px 8px;
  text-align: left;
  font-weight: 600;
  font-size: 11px;
  color: var(--accent);
  border: 1px solid var(--border2);
  white-space: nowrap;
}

.chat-bubble table td {
  padding: 6px 8px;
  border: 1px solid var(--border);
  color: var(--text2);
  white-space: nowrap;
}

.chat-bubble table tr:hover td {
  background: var(--bg2);
}

/* Remove excessive spacing */
.chat-bubble > *:first-child {
  margin-top: 0 !important;
}

.chat-bubble > *:last-child {
  margin-bottom: 0 !important;
}

.chat-time {
  font-size: 10px;
  color: var(--text3);
  font-family: 'JetBrains Mono', monospace;
  margin-top: 3px;
  padding: 0 2px;
}

.user .chat-time {
  text-align: right;
}

.chat-typing {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 10px 12px;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 12px 12px 12px 4px;
  width: fit-content;
}

.t-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--accent);
  animation: bounce 1.2s infinite;
}

.t-dot:nth-child(2) {
  animation-delay: .2s;
}

.t-dot:nth-child(3) {
  animation-delay: .4s;
}

@keyframes bounce {

  0%,
  60%,
  100% {
    transform: translateY(0);
    opacity: .4;
  }

  30% {
    transform: translateY(-5px);
    opacity: 1;
  }
}

.chat-input-area {
  padding: 10px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.chat-input-row {
  display: flex;
  gap: 6px;
  align-items: flex-end;
}

.chat-input {
  flex: 1;
  background: var(--bg3);
  border: 1px solid var(--border2);
  border-radius: 10px;
  padding: 9px 11px;
  color: var(--text);
  font-size: 13px;
  font-family: 'DM Sans', sans-serif;
  outline: none;
  resize: none;
  max-height: 90px;
  line-height: 1.5;
  transition: border-color .2s;
}

.chat-input:focus {
  border-color: var(--accent);
}

.chat-input::placeholder {
  color: var(--text3);
}

.chat-send {
  width: 36px;
  height: 36px;
  background: var(--accent);
  border: none;
  border-radius: 10px;
  color: #0f0f0f;
  cursor: pointer;
  font-size: 15px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .2s;
  flex-shrink: 0;
}

.chat-send:hover {
  background: var(--accent2);
}

.chat-send:disabled {
  opacity: .4;
  cursor: not-allowed;
}

/* AI overlay */
#ai-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .55);
  backdrop-filter: blur(3px);
  z-index: 300;
  display: none;
  align-items: center;
  justify-content: center;
}

#ai-overlay.show {
  display: flex;
}

.ai-loader {
  background: var(--bg2);
  border: 1px solid var(--border2);
  border-radius: 14px;
  padding: 28px 36px;
  text-align: center;
}

.ai-spinner {
  width: 34px;
  height: 34px;
  border: 2px solid var(--border2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .8s linear infinite;
  margin: 0 auto 12px;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.ai-loader-txt {
  font-size: 14px;
  color: var(--text2);
}

/* Toast */
#toast {
  position: fixed;
  bottom: 80px;
  right: 16px;
  background: var(--bg2);
  border: 1px solid var(--border2);
  border-radius: var(--r2);
  padding: 11px 16px;
  font-size: 13px;
  color: var(--text);
  z-index: 1000;
  display: none;
  box-shadow: 0 4px 20px rgba(0, 0, 0, .3);
}

#toast.show {
  display: flex;
  align-items: center;
  gap: 7px;
  animation: slideUp .2s ease;
}

#toast.success {
  border-color: rgba(39, 174, 96, .4);
}

#toast.error {
  border-color: rgba(192, 57, 43, .4);
}

@media(min-width:641px) {
  #toast {
    bottom: 20px;
    right: 20px;
  }
}

/* Mobile sidebar overlay */
#sidebar-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .5);
  z-index: 90;
  display: none;
}

#sidebar-overlay.show {
  display: block;
}

/* Desktop only elements - hidden by default, shown in desktop media query */
.desktop-only {
  display: none !important;
}

/* Mobile bottom bar */
#bottom-bar {
  display: none;
  position: fixed;
  bottom: 30px;
  left: 0;
  right: 0;
  height: var(--bottom-bar-h);
  background: var(--bg2);
  border-top: 1px solid var(--border);
  z-index: 80;
  align-items: center;
  justify-content: space-around;
  padding: 0 8px;
  padding-bottom: env(safe-area-inset-bottom);
}

.bb-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  background: none;
  border: none;
  color: var(--text3);
  cursor: pointer;
  padding: 6px 12px;
  border-radius: var(--r);
  transition: color .15s;
  font-size: 10px;
  font-family: 'DM Sans', sans-serif;
}

.bb-btn .bb-icon {
  font-size: 18px;
}

.bb-btn.active,
.bb-btn:hover {
  color: var(--accent);
}

.bb-new {
  background: var(--accent);
  border-radius: 50%;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  color: #0f0f0f;
  border: none;
  cursor: pointer;
  box-shadow: 0 2px 12px rgba(212, 168, 83, .3);
}

/* Responsive */
@media(max-width:640px) {
  #sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 91;
    transform: translateX(-100%);
  }

  #sidebar.open {
    transform: translateX(0);
  }

  #right-sidebar {
    position: fixed;
    top: 0;
    bottom: var(--bottom-bar-h);
    right: 0;
    width: 100%;
    z-index: 85;
  }

  #chat-panel {
    display: none !important;
  }

  #bottom-bar {
    display: flex;
  }

  .desktop-only {
    display: none !important;
  }

  #editor-wrap {
    padding-bottom: calc(var(--bottom-bar-h) + 16px);
  }

  #note-header {
    padding: 14px 16px 0;
  }

  #note-title {
    font-size: 22px;
  }

  #editor {
    font-size: 16px;
  }

  .meta-bar {
    font-size: 10px;
    gap: 8px;
  }
}

@media(min-width:641px) and (max-width:900px) {
  #right-sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    right: 0;
    z-index: 90;
  }

  #chat-panel {
    display: none !important;
  }

  .desktop-only {
    display: inline-flex !important;
  }

  .ai-drop.desktop-only {
    display: inline-block !important;
  }
}

@media(min-width:901px) {
  #bottom-bar {
    display: none !important;
  }

  .desktop-only {
    display: inline-flex !important;
  }

  .ai-drop.desktop-only {
    display: inline-block !important;
  }
}

/* Animations */
@keyframes fadeIn {
  from {
    opacity: 0;
  }

  to {
    opacity: 1;
  }
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(6px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 640px) {
  .hide-m {
    display: none
  }
}


/* ===== COLOR PICKER POPUP ===== */
.color-picker-popup {
  position: fixed;
  background: var(--bg2);
  border: 1px solid var(--border2);
  border-radius: var(--r2);
  padding: 12px;
  z-index: 10000;
  box-shadow: 0 8px 32px rgba(0, 0, 0, .6);
  width: 300px;
}

.color-picker-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
}

.color-picker-grid {
  display: grid;
  grid-template-columns: repeat(10, 1fr);
  gap: 4px;
  margin-bottom: 10px;
}

.color-swatch {
  width: 24px;
  height: 24px;
  border: 1px solid var(--border);
  border-radius: 4px;
  cursor: pointer;
  transition: transform .1s;
}

.color-swatch:hover {
  transform: scale(1.15);
  border-color: var(--accent);
  box-shadow: 0 2px 8px rgba(0, 0, 0, .3);
}

.color-picker-footer {
  border-top: 1px solid var(--border);
  padding-top: 8px;
}

/* ===== EDITOR LINK & IMAGE STYLES ===== */
.tiptap .editor-link,
#editor[contenteditable="true"] a {
  color: var(--accent);
  text-decoration: underline;
  cursor: pointer;
}

.tiptap .editor-link:hover,
#editor[contenteditable="true"] a:hover {
  color: var(--accent2);
}

.tiptap .editor-image,
#editor[contenteditable="true"] img {
  max-width: 100%;
  height: auto;
  border-radius: var(--r);
  margin: 10px 0;
  display: block;
}

/* Text alignment */
.tiptap [style*="text-align: left"],
#editor[contenteditable="true"] [style*="text-align: left"] {
  text-align: left;
}

.tiptap [style*="text-align: center"],
#editor[contenteditable="true"] [style*="text-align: center"] {
  text-align: center;
}

.tiptap [style*="text-align: right"],
#editor[contenteditable="true"] [style*="text-align: right"] {
  text-align: right;
}

.tiptap [style*="text-align: justify"],
#editor[contenteditable="true"] [style*="text-align: justify"] {
  text-align: justify;
}

/* Underline */
.tiptap u,
#editor[contenteditable="true"] u {
  text-decoration: underline;
}

/* Highlight */
.tiptap mark,
#editor[contenteditable="true"] mark {
  background-color: #ffeb3b;
  padding: 2px 0;
  border-radius: 2px;
}


/* ===== AUTH SECTION ===== */
#auth-section {
  font-size: 11px;
}

.auth-info {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  padding: 6px 0;
}

.auth-info span {
  flex: 1;
  min-width: 100px;
  color: var(--text2);
}

.auth-buttons {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.auth-buttons .btn-primary,
.auth-buttons .btn-secondary {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  padding: 10px 14px;
}

.auth-buttons .btn-primary svg {
  flex-shrink: 0;
}
