@import url('https://fonts.googleapis.com/css2?family=JetBrains+Mono:ital,wght@0,300;0,400;0,500;0,700;1,400&display=swap');

/* ============================================================
   THEME TOKENS
   ============================================================ */
[data-theme="dark"] {
  --bg: #0d0d0d;
  --surface: #111111;
  --surface-2: #181818;
  --surface-3: #1f1f1f;
  --border: #252525;
  --border-subtle: #1a1a1a;
  --text: #e0e0e0;
  --text-bright: #f5f5f5;
  --text-muted: #8a8a9a;
  --text-dim: #555568;
  --accent: #00ffcc;
  --accent-muted: #00c4a0;
  --accent-dim: rgba(0, 255, 204, 0.07);
  --accent-glow: rgba(0, 255, 204, 0.18);
  --danger: #ff4d4d;
  --danger-dim: rgba(255, 77, 77, 0.1);
  --overlay-bg: rgba(0, 0, 0, 0.88);
  --shadow: 0 12px 48px rgba(0,0,0,0.8);
  --shadow-sm: 0 4px 16px rgba(0,0,0,0.5);
  --ctx-bg: #131313;
  --scrollbar-thumb: #222;
  --scrollbar-thumb-hover: #333;
}

[data-theme="light"] {
  --bg: #fafaf8;
  --surface: #ffffff;
  --surface-2: #f0f0ec;
  --surface-3: #e8e8e4;
  --border: #e0e0d8;
  --border-subtle: #ebebea;
  --text: #1a1a1a;
  --text-bright: #000000;
  --text-muted: #888880;
  --text-dim: #c0c0b8;
  --accent: #007a65;
  --accent-muted: #006050;
  --accent-dim: rgba(0, 122, 101, 0.07);
  --accent-glow: rgba(0, 122, 101, 0.18);
  --danger: #c22;
  --danger-dim: rgba(204, 34, 34, 0.08);
  --overlay-bg: rgba(0, 0, 0, 0.4);
  --shadow: 0 12px 48px rgba(0,0,0,0.14);
  --shadow-sm: 0 4px 16px rgba(0,0,0,0.08);
  --ctx-bg: #ffffff;
  --scrollbar-thumb: #d8d8d0;
  --scrollbar-thumb-hover: #c0c0b8;
}

/* ============================================================
   RESET & BASE
   ============================================================ */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  height: 100%;
}

body {
  font-family: 'JetBrains Mono', monospace;
  font-size: 13px;
  background-color: var(--bg);
  color: var(--text);
  height: 100%;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

button {
  font-family: 'JetBrains Mono', monospace;
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.4;
}

input {
  font-family: 'JetBrains Mono', monospace;
  color: inherit;
}

/* ============================================================
   SCROLLBARS
   ============================================================ */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--scrollbar-thumb); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--scrollbar-thumb-hover); }

/* ============================================================
   FOCUS
   ============================================================ */
:focus-visible {
  outline: 1.5px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

/* Keyboard focus on div-based interactive items */
[tabindex="0"]:focus-visible {
  outline: 1.5px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

/* Remove focus outline from the editor contenteditable area */
#editor:focus-visible,
#editor:focus,
.ProseMirror:focus-visible,
.ProseMirror:focus {
  outline: none;
}

/* ============================================================
   APP LAYOUT — full viewport, column
   ============================================================ */
#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
  position: relative;
  background: var(--bg);
}

/* ============================================================
   EDITOR AREA
   ============================================================ */
#editor-area {
  flex: 1;
  overflow-y: auto;
  display: flex;
  justify-content: center;
  padding: 80px 24px 40px;
  position: relative;
}

/* Drop zone feedback */
#editor-area.drop-active::before {
  content: '⬇ Drop to insert';
  position: fixed;
  inset: 0;
  z-index: 500;
  background: var(--accent-dim);
  border: 2px dashed var(--accent);
  border-radius: 0;
  color: var(--accent);
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.06em;
  pointer-events: none;
  display: grid;
  place-items: center;
}

#editor {
  width: 100%;
  max-width: 680px;
  min-height: 100%;
  outline: none;
}

/* ProseMirror (Tiptap) */
.ProseMirror {
  outline: none;
  min-height: calc(100vh - 160px);
  caret-color: var(--accent);
  font-size: 15px;
  line-height: 1.8;
  color: var(--text);
  letter-spacing: 0.01em;
}

.ProseMirror p {
  margin-bottom: 0.6em;
}
.ProseMirror p:last-child {
  margin-bottom: 0;
}

.ProseMirror h1 {
  font-size: 1.85em;
  font-weight: 700;
  color: var(--text-bright);
  margin: 1.4em 0 0.5em;
  line-height: 1.2;
  letter-spacing: -0.02em;
}
.ProseMirror h1:first-child { margin-top: 0; }

.ProseMirror h2 {
  font-size: 1.35em;
  font-weight: 600;
  color: var(--text-bright);
  margin: 1.2em 0 0.4em;
  line-height: 1.3;
}

.ProseMirror h3 {
  font-size: 1.1em;
  font-weight: 600;
  color: var(--text-muted);
  margin: 1em 0 0.3em;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.ProseMirror blockquote {
  border-left: 2px solid var(--accent);
  margin: 1em 0;
  padding: 6px 0 6px 16px;
  color: var(--text-muted);
  font-style: italic;
}

.ProseMirror ul, .ProseMirror ol {
  padding-left: 1.5em;
  margin: 0.5em 0;
}

.ProseMirror li { margin-bottom: 0.2em; }
.ProseMirror li > p { margin: 0; }

.ProseMirror code {
  background: var(--surface-3);
  color: var(--accent);
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 0.88em;
  border: 1px solid var(--border);
}

.ProseMirror pre {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 12px 16px;
  margin: 1em 0;
  overflow-x: auto;
}

.ProseMirror pre code {
  background: none;
  border: none;
  padding: 0;
  color: var(--text);
}

.ProseMirror a { color: var(--accent); text-decoration: underline; text-underline-offset: 3px; }
.ProseMirror hr { border: none; border-top: 1px solid var(--border); margin: 1.5em 0; }

.ProseMirror img {
  max-width: 100%;
  height: auto;
  border-radius: 4px;
  margin: 0.75em 0;
  display: block;
}

.ProseMirror strong { font-weight: 700; }
.ProseMirror em { font-style: italic; }
.ProseMirror u { text-decoration: underline; text-underline-offset: 3px; text-decoration-color: var(--accent-muted); }
.ProseMirror s { color: var(--text-muted); text-decoration: line-through; }

/* Placeholder */
.ProseMirror p.is-editor-empty:first-child::before {
  content: attr(data-placeholder);
  color: var(--text-dim);
  pointer-events: none;
  float: left;
  height: 0;
}

/* Selection */
.ProseMirror ::selection { background: var(--accent-dim); }

/* ============================================================
   STATUS BAR
   ============================================================ */
#status-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 26px;
  padding: 0 20px;
  border-top: 1px solid var(--border-subtle);
  background: var(--bg);
  flex-shrink: 0;
  font-size: 10.5px;
  color: var(--text-muted);
  letter-spacing: 0.03em;
  user-select: none;
  z-index: 5;
}

.status-left, .status-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.status-sep {
  opacity: 0.25;
}

#status-save.saved { color: var(--accent); }
#status-save.saving {
  color: var(--text-muted);
  opacity: 0.6;
}

/* Format indicators */
#status-format {
  display: flex;
  align-items: center;
  gap: 4px;
}

.fmt-tag {
  display: inline-flex;
  align-items: center;
  padding: 0 5px;
  height: 16px;
  border-radius: 3px;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.04em;
  background: var(--accent-dim);
  color: var(--accent);
  border: 1px solid rgba(0,255,204,0.2);
}

[data-theme="light"] .fmt-tag {
  border-color: rgba(0,122,101,0.2);
}

.status-hint {
  opacity: 0.35;
}

.status-hint:hover {
  opacity: 0.6;
  cursor: pointer;
}

/* ============================================================
   LOADING BAR
   ============================================================ */
#loading-bar {
  height: 1.5px;
  width: 100%;
  position: fixed;
  top: 0;
  left: 0;
  z-index: 999;
  overflow: hidden;
  background: transparent;
  pointer-events: none;
}

#loading-bar.active::after {
  content: '';
  position: absolute;
  top: 0; left: 0;
  height: 100%;
  width: 100%;
  background: var(--accent);
  opacity: 0.75;
}



/* ============================================================
   CONTEXT MENU (right-click formatting)
   ============================================================ */
#context-menu {
  position: fixed;
  z-index: 2000;
  background: var(--ctx-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 5px;
  min-width: 210px;
  box-shadow: var(--shadow-sm);
}

#context-menu.hidden { display: none; }

.ctx-section-label {
  padding: 6px 10px 3px;
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-dim);
  user-select: none;
}

.ctx-sep {
  height: 1px;
  background: var(--border-subtle);
  margin: 4px 0;
}

.ctx-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 6px 10px;
  border-radius: 5px;
  font-size: 11.5px;
  color: var(--text-muted);
  background: none;
  border: none;
  cursor: pointer;
  text-align: left;
}

.ctx-item:hover,
.ctx-item.active,
.ctx-item:focus-visible {
  background: var(--accent-dim);
  color: var(--accent);
  outline: none;
}

.ctx-item:focus-visible {
  box-shadow: inset 0 0 0 1.5px var(--accent);
}

.ctx-item.active .ctx-shortcut,
.ctx-item:focus-visible .ctx-shortcut {
  color: var(--accent-muted);
}

.ctx-label {
  display: flex;
  align-items: center;
  gap: 6px;
}

.ctx-label b { font-weight: 700; }
.ctx-label i { font-style: italic; }
.ctx-label u { text-decoration: underline; text-underline-offset: 2px; }
.ctx-label s { text-decoration: line-through; }
.ctx-label code {
  background: var(--surface-3);
  color: var(--accent);
  padding: 0 4px;
  border-radius: 3px;
  font-size: 0.9em;
}

.ctx-shortcut {
  font-size: 9.5px;
  color: var(--text-dim);
  opacity: 0.8;
  white-space: nowrap;
  margin-left: 8px;
}

/* ============================================================
   OVERLAY BASE
   ============================================================ */
.overlay {
  position: fixed;
  inset: 0;
  background: var(--overlay-bg);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.overlay.hidden { display: none; }

.overlay-box {
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 28px 32px;
  min-width: 360px;
  max-width: 520px;
  max-height: 80vh;
  overflow-y: auto;
  border-radius: 10px;
  box-shadow: var(--shadow);
}

.overlay-box h2 {
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 18px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

/* ============================================================
   SPOTLIGHT
   ============================================================ */
#spotlight-overlay {
  align-items: flex-start;
  padding-top: 16vh;
}

#spotlight-container {
  background: var(--surface);
  border: 1px solid var(--border);
  width: 560px;
  max-width: calc(100vw - 32px);
  border-radius: 10px;
  overflow: hidden;
  box-shadow: var(--shadow);
}

.spotlight-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  color: var(--text-muted);
}

#spotlight-input {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  font-size: 14px;
  color: var(--text);
}

#spotlight-input::placeholder { color: var(--text-muted); }

.spotlight-header kbd {
  font-family: 'JetBrains Mono', monospace;
  font-size: 9px;
  color: var(--text-dim);
  border: 1px solid var(--border);
  padding: 2px 6px;
  border-radius: 3px;
  flex-shrink: 0;
}

#spotlight-results {
  max-height: 380px;
  overflow-y: auto;
  padding: 6px;
}

.spotlight-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 9px 12px;
  border-radius: 6px;
  cursor: pointer;
  color: var(--text-muted);
}

.spotlight-item:hover,
.spotlight-item.selected {
  background: var(--accent-dim);
  color: var(--accent);
}

.spotlight-item-left {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.spotlight-item-icon {
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  opacity: 0.6;
  font-size: 11px;
}

.spotlight-item.selected .spotlight-item-icon { opacity: 1; }

.spotlight-item-label {
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.spotlight-item-meta {
  font-size: 10px;
  color: var(--text-dim);
  white-space: nowrap;
  margin-left: 8px;
  flex-shrink: 0;
}

.spotlight-item.selected .spotlight-item-meta { color: var(--accent-muted); }

.spotlight-section {
  padding: 8px 12px 4px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-dim);
}

.spotlight-footer {
  padding: 8px 16px;
  border-top: 1px solid var(--border);
  font-size: 10px;
  color: var(--text-dim);
  text-align: center;
}

/* ============================================================
   CONFIRM DIALOG
   ============================================================ */
#confirm-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 28px 28px 24px;
  width: 360px;
  max-width: calc(100vw - 32px);
  text-align: center;
  box-shadow: var(--shadow);
}

#confirm-icon { font-size: 26px; margin-bottom: 12px; }

.confirm-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 8px;
  letter-spacing: 0.04em;
}

.confirm-msg {
  font-size: 11px;
  color: var(--text-muted);
  line-height: 1.7;
  margin-bottom: 22px;
}

.confirm-actions {
  display: flex;
  gap: 8px;
  justify-content: center;
}

.confirm-actions .btn { flex: 1; max-width: 150px; }

/* ============================================================
   BUTTONS
   ============================================================ */
.btn {
  padding: 9px 16px;
  border-radius: 6px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  letter-spacing: 0.04em;
  white-space: nowrap;
}

.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary {
  flex: 1;
  background: var(--accent);
  color: #000;
  border-color: var(--accent);
}
.btn-primary:hover:not(:disabled) {
  background: var(--accent-muted);
}

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border-color: var(--border);
}
.btn-ghost:hover:not(:disabled) {
  background: var(--surface-2);
  color: var(--text);
  border-color: var(--text-muted);
}

.btn-danger {
  background: var(--danger-dim);
  color: var(--danger);
  border-color: var(--danger);
}
.btn-danger:hover:not(:disabled) {
  background: var(--danger);
  color: #fff;
}

.btn-secondary {
  flex: 1;
  background: var(--surface-2);
  color: var(--text-muted);
  border-color: var(--border);
}
.btn-secondary:hover:not(:disabled) {
  color: var(--text);
  border-color: var(--text-muted);
}

/* ============================================================
   AUTH FORM
   ============================================================ */
.auth-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 16px;
}

.auth-input {
  padding: 10px 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 12px;
  color: var(--text);
  outline: none;
}
.auth-input:focus { border-color: var(--accent); }
.auth-input::placeholder { color: var(--text-muted); }

.auth-actions { display: flex; gap: 8px; margin-top: 4px; }

.auth-error {
  font-size: 11px;
  color: var(--danger);
  min-height: 16px;
}

/* ============================================================
   ACCOUNT / LIST OVERLAYS
   ============================================================ */
.account-section {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.account-label {
  font-size: 9.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-dim);
  margin-bottom: 8px;
}

.account-actions { display: flex; flex-direction: column; gap: 5px; }

.account-action-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 5px;
  font-size: 11px;
  color: var(--text-muted);
  width: 100%;
  text-align: left;
}
.account-action-btn:hover { background: var(--surface-2); color: var(--text); }
.account-action-btn.danger { color: var(--danger); }
.account-action-btn.danger:hover { background: var(--danger-dim); }

.list-overlay-items {
  max-height: 55vh;
  overflow-y: auto;
  margin-top: 12px;
}

.list-overlay-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 5px;
  cursor: pointer;
}
.list-overlay-item:hover,
.list-overlay-item:focus-visible {
  background: var(--surface-2);
  outline: 1.5px solid var(--accent);
  outline-offset: -1px;
}

.list-overlay-date {
  font-size: 10px;
  color: var(--text-muted);
  flex-shrink: 0;
  min-width: 76px;
}

.list-overlay-title {
  font-size: 12px;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ============================================================
   HELP
   ============================================================ */
.help-section { margin-bottom: 16px; }

.help-section-title {
  font-size: 9.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-dim);
  margin-bottom: 8px;
}

.help-grid {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 8px 16px;
}

.kbd {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 10px;
  color: var(--accent);
  white-space: nowrap;
}

.help-desc {
  font-size: 11px;
  color: var(--text-muted);
}

/* ============================================================
   RENAME INPUT (inline in spotlight)
   ============================================================ */
.spotlight-rename-input {
  flex: 1;
  background: var(--surface-2);
  border: 1px solid var(--accent);
  border-radius: 4px;
  padding: 4px 8px;
  font-size: 12px;
  color: var(--text);
  outline: none;
  font-family: 'JetBrains Mono', monospace;
}

/* ============================================================
   TABLES
   ============================================================ */
.tableWrapper {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 16px 0;
  border-radius: 6px;
}

table {
  border-collapse: collapse;
  width: max-content;
  min-width: 100%;
  font-size: 13px;
  table-layout: fixed;
}

th, td {
  border: 1px solid var(--border);
  padding: 7px 10px;
  min-width: 80px;
  vertical-align: top;
  position: relative;
}

th {
  background: var(--surface-2);
  color: var(--accent);
  font-weight: 600;
  text-align: left;
  letter-spacing: 0.02em;
  font-size: 11px;
  text-transform: uppercase;
}

td { color: var(--text); }

tr:nth-child(even) td { background: rgba(255,255,255,0.015); }
[data-theme="light"] tr:nth-child(even) td { background: rgba(0,0,0,0.02); }

/* Column resize handle (from Tiptap table resizing) */
.column-resize-handle {
  position: absolute;
  right: -2px;
  top: 0;
  bottom: 0;
  width: 4px;
  background: var(--accent);
  opacity: 0;
  cursor: col-resize;
  pointer-events: auto;
}
.column-resize-handle:hover,
.resize-cursor .column-resize-handle { opacity: 0.6; }
.resize-cursor { cursor: col-resize !important; }

/* Selected cell highlight */
.selectedCell::after {
  content: '';
  position: absolute;
  inset: 0;
  background: var(--accent-dim);
  pointer-events: none;
  border-radius: 2px;
}

/* ============================================================
   CHECKLISTS (Task Lists)
   ============================================================ */
ul[data-type="taskList"] {
  list-style: none;
  padding: 0;
  margin: 10px 0;
}

ul[data-type="taskList"] li {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 2px 0;
}

ul[data-type="taskList"] li > label {
  flex-shrink: 0;
  margin-top: 2px;
  cursor: pointer;
  display: flex;
  align-items: center;
}

ul[data-type="taskList"] li > label input[type="checkbox"] {
  appearance: none;
  -webkit-appearance: none;
  width: 15px;
  height: 15px;
  border: 1.5px solid var(--border);
  border-radius: 3px;
  background: transparent;
  cursor: pointer;
  position: relative;
  flex-shrink: 0;
}

ul[data-type="taskList"] li > label input[type="checkbox"]:checked {
  background: var(--accent);
  border-color: var(--accent);
}

ul[data-type="taskList"] li > label input[type="checkbox"]:checked::after {
  content: '';
  position: absolute;
  left: 2px;
  top: 5px;
  width: 5px;
  height: 3px;
  border-left: 1.5px solid #fff;
  border-bottom: 1.5px solid #fff;
  transform: rotate(-45deg);
}

ul[data-type="taskList"] li > div {
  flex: 1;
  min-width: 0;
}

ul[data-type="taskList"] li[data-checked="true"] > div {
  opacity: 0.45;
  text-decoration: line-through;
}

/* Nested task lists */
ul[data-type="taskList"] ul[data-type="taskList"] {
  margin: 4px 0 0 20px;
}

/* ============================================================
   MOBILE (< 768px) — base overrides
   ============================================================ */
@media (max-width: 767px) {
  /* Hide desktop-only elements */
  #status-bar  { display: none; }
  #context-menu { display: none; } /* use bottom toolbar instead */

  /* Editor sits between top bar and bottom toolbar */
  #editor-area {
    padding: 16px 16px 8px;
    padding-top: calc(48px + 16px); /* room for top bar */
    padding-bottom: calc(48px + 24px); /* room for bottom toolbar */
  }

  .ProseMirror {
    font-size: 16px; /* prevent iOS zoom on focus */
    line-height: 1.7;
  }

  .overlay-box {
    min-width: unset;
    width: calc(100vw - 24px);
    max-width: 100%;
    padding: 20px 16px;
    max-height: 88vh;
  }

  #context-menu { min-width: 180px; }

  /* ── MOBILE TOP BAR ── */
  #mobile-top-bar {
    display: flex !important;
    align-items: center;
    gap: 10px;
    position: fixed;
    top: 0; left: 0; right: 0;
    height: 48px;
    padding: 0 12px;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
    z-index: 200;
    box-shadow: 0 1px 8px rgba(0,0,0,0.15);
  }

  .mob-icon-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 6px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    min-width: 36px;
    min-height: 36px;
    flex-shrink: 0;
  }
  .mob-icon-btn:hover { background: var(--surface-2); color: var(--text); }
  .mob-icon-btn:active { background: var(--accent-dim); color: var(--accent); }

  .mob-title {
    flex: 1;
    font-size: 14px;
    font-weight: 500;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    cursor: pointer;
    padding: 4px 6px;
    border-radius: 5px;
  }
  .mob-title:hover { background: var(--surface-2); }

  .mob-save-status {
    font-size: 11px;
    color: var(--text-muted);
    white-space: nowrap;
    min-width: 36px;
    text-align: right;
    flex-shrink: 0;
  }
  .mob-save-status.saving { color: var(--accent); }
  .mob-save-status.saved  { color: #4caf87; }
  .mob-save-status.dirty  { color: var(--text-dim); }

  /* ── MOBILE BOTTOM TOOLBAR ── */
  #mobile-toolbar {
    display: flex !important;
    align-items: center;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    gap: 2px;
    position: fixed;
    left: 0; right: 0;
    bottom: 0;
    height: 48px;
    padding: 0 6px;
    background: var(--bg);
    border-top: 1px solid var(--border);
    z-index: 200;
    box-shadow: 0 -1px 8px rgba(0,0,0,0.12);
  }
  #mobile-toolbar::-webkit-scrollbar { display: none; }

  .mob-fmt-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    min-width: 40px;
    height: 38px;
    border-radius: 6px;
    font-size: 13px;
    font-family: 'JetBrains Mono', monospace;
    font-weight: 500;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    -webkit-tap-highlight-color: transparent;
  }
  .mob-fmt-btn:active  { background: var(--accent-dim); color: var(--accent); }
  .mob-fmt-btn.active  { background: var(--accent-dim); color: var(--accent); }

  .mob-sep {
    width: 1px;
    height: 22px;
    background: var(--border);
    flex-shrink: 0;
    margin: 0 4px;
  }

  /* ── JOURNAL LIST SCREEN ── */
  #journal-list-screen {
    display: flex !important;
    flex-direction: column;
    position: fixed;
    inset: 0;
    background: var(--bg);
    z-index: 300;
    overflow: hidden;
  }
  #journal-list-screen.hidden { display: none !important; }

  #jls-top-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 52px;
    padding: 0 16px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
  }
  .jls-title {
    font-size: 18px;
    font-weight: 700;
    color: var(--accent);
    letter-spacing: -0.02em;
    font-family: 'JetBrains Mono', monospace;
  }
  .jls-actions {
    display: flex;
    gap: 4px;
  }

  #jls-search-wrap {
    padding: 10px 16px 6px;
    flex-shrink: 0;
  }
  #jls-search {
    width: 100%;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 9px 14px;
    font-size: 14px;
    color: var(--text);
    font-family: 'JetBrains Mono', monospace;
    outline: none;
    box-sizing: border-box;
  }
  #jls-search::placeholder { color: var(--text-muted); }
  #jls-search:focus { border-color: var(--accent); }

  #jls-grid {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    padding: 10px 12px 24px;
    align-content: start;
  }

  .jls-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 14px 12px;
    cursor: pointer;
    min-height: 100px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
  }
  .jls-card:active { background: var(--surface-2); }

  .jls-card-new {
    border: 1.5px dashed var(--accent);
    background: var(--accent-dim);
    align-items: center;
    justify-content: center;
    color: var(--accent);
  }
  .jls-card-new .jls-card-plus {
    font-size: 28px;
    line-height: 1;
    font-weight: 300;
  }
  .jls-card-new .jls-card-label {
    font-size: 11px;
    font-weight: 500;
    letter-spacing: 0.04em;
    text-transform: uppercase;
  }

  .jls-card-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
    line-height: 1.3;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }
  .jls-card-date {
    font-size: 10px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
  }
  .jls-card-preview {
    font-size: 11px;
    color: var(--text-dim);
    line-height: 1.5;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    flex: 1;
  }

  /* ── MOBILE ACTION SHEET ── */
  #mob-action-sheet-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.45);
    z-index: 500;
  }
  #mob-action-sheet-backdrop.hidden { display: none; }

  #mob-action-sheet {
    position: fixed;
    left: 0; right: 0; bottom: 0;
    z-index: 501;
    background: var(--surface);
    border-top-left-radius: 12px;
    border-top-right-radius: 12px;
    border-top: 1px solid var(--border);
    padding-bottom: env(safe-area-inset-bottom, 16px);
  }
  #mob-action-sheet.visible { display: block; }
  #mob-action-sheet.hidden  { display: none; }

  #mob-action-sheet-inner { padding: 12px 0 8px; }

  .mob-sheet-title {
    font-size: 12px;
    color: var(--text-muted);
    text-align: center;
    padding: 0 20px 12px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .mob-sheet-btn {
    display: block;
    width: 100%;
    padding: 14px 20px;
    background: none;
    border: none;
    text-align: left;
    font-size: 15px;
    font-family: 'JetBrains Mono', monospace;
    color: var(--text);
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
  }
  .mob-sheet-btn:active  { background: var(--surface-2); }
  .mob-sheet-btn.danger  { color: #e06060; }
  .mob-sheet-btn.cancel  { color: var(--text-muted); border-top: 1px solid var(--border); margin-top: 4px; font-weight: 500; }
}

/* Desktop: hide all mobile-only elements */
@media (min-width: 768px) {
  #mobile-top-bar,
  #mobile-toolbar,
  #journal-list-screen,
  #mob-action-sheet,
  #mob-action-sheet-backdrop { display: none !important; }
}


/* ============================================================
   MEDIA NODES (Audio / Video inline Tiptap blocks)
   ============================================================ */
.media-node {
  position: relative;
  margin: 14px 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 12px 8px;
  display: inline-flex;
  flex-direction: column;
  gap: 6px;
  max-width: 100%;
  box-sizing: border-box;
}
.media-node audio,
.media-node video {
  width: 100%;
  border-radius: 4px;
  outline: none;
}
.media-node-label {
  font-size: 10px;
  color: var(--text-muted);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.media-resize-handle {
  position: absolute;
  bottom: 4px;
  right: 4px;
  width: 12px;
  height: 12px;
  cursor: se-resize;
  opacity: 0.4;
  background:
    linear-gradient(135deg, transparent 50%, var(--accent) 50%),
    linear-gradient(135deg, transparent 60%, var(--accent) 60%);
  background-size: 6px 6px, 10px 10px;
  background-repeat: no-repeat;
  background-position: bottom right;
}
.media-node:hover .media-resize-handle { opacity: 0.9; }

/* ============================================================
   FLOAT CANVAS (PDF / DOCX floating elements)
   ============================================================ */
.float-el {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.28);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  cursor: default;
  user-select: none;
}
.float-el.float-active {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-dim), 0 6px 28px rgba(0,0,0,0.35);
}
.float-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 28px;
  padding: 0 10px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  cursor: grab;
  flex-shrink: 0;
}
.float-toolbar:active { cursor: grabbing; }
.float-name {
  font-size: 10px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: calc(100% - 30px);
  letter-spacing: 0.03em;
}
.float-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 14px;
  padding: 2px 4px;
  border-radius: 3px;
  flex-shrink: 0;
}
.float-close:hover { background: rgba(220,80,80,0.15); color: #e06060; }

.float-inner {
  flex: 1;
  overflow: hidden;
  position: relative;
}
.float-docx-content {
  color: var(--text);
  font-size: 12px;
  line-height: 1.6;
}
.float-docx-content h1, .float-docx-content h2, .float-docx-content h3 {
  color: var(--text); margin: 8px 0 4px;
}

/* Rotate handle (top-center) */
.float-rot-handle {
  position: absolute;
  top: -24px;
  left: 50%;
  transform: translateX(-50%);
  width: 16px;
  height: 16px;
  background: var(--surface-2);
  border: 1px solid var(--accent);
  border-radius: 50%;
  cursor: grab;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 9px;
  color: var(--accent);
  opacity: 0;
  pointer-events: auto;
}
.float-el:hover .float-rot-handle,
.float-el.float-active .float-rot-handle { opacity: 1; }
.float-rot-handle::after { content: '↻'; }

/* Resize handle (bottom-right corner) */
.float-res-handle {
  position: absolute;
  bottom: 0;
  right: 0;
  width: 18px;
  height: 18px;
  cursor: se-resize;
  pointer-events: auto;
  opacity: 0.4;
  background:
    linear-gradient(135deg, transparent 50%, var(--accent) 50%),
    linear-gradient(135deg, transparent 60%, var(--accent) 60%);
  background-size: 8px 8px, 14px 14px;
  background-repeat: no-repeat;
  background-position: bottom right;
}
.float-el:hover .float-res-handle,
.float-el.float-active .float-res-handle { opacity: 0.9; }

/* ============================================================
   SPOTIFY — MOBILE OVERRIDES
   ============================================================ */
@media (max-width: 767px) {
  .spotify-node {
    max-width: 100%;
  }
  .spotify-node iframe {
    width: 100% !important;
  }
}

/* ============================================================
   SPOTIFY EMBED NODE
   ============================================================ */
.spotify-node {
  margin: 16px 0;
  border-radius: 10px;
  overflow: hidden;
  max-width: 560px;
  user-select: none;
  line-height: 0; /* collapse whitespace around iframe */
}

.spotify-node iframe {
  display: block;
  border: none;
  border-radius: 10px;
  width: 100%;
}
