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

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

:root {
  --sidebar-w: 248px;
  --header-h: 52px;
  --toolbar-h: 44px;
  --radius: 12px;
  --radius-sm: 8px;
  --radius-lg: 16px;
}

/* ============ THEME: LIGHT (default, Proton-style clean) ============ */
html[data-theme="light"] {
  --bg: #FAFAFB;
  --surface: #FFFFFF;
  --surface-2: #F4F3F6;
  --purple: #6D4AFF;
  --purple-strong: #5A37E6;
  --purple-light: #8567FF;
  --purple-faint: rgba(109,74,255,0.08);
  --text: #16151C;
  --text-muted: #6C6A78;
  --border: #E7E6EC;
  --sheet-bg: #FFFFFF;
  --sheet-text: #1B1A22;
  --shadow: 0 8px 28px rgba(20,17,40,0.10), 0 2px 6px rgba(20,17,40,0.05);
  --shadow-sm: 0 1px 3px rgba(20,17,40,0.06);
  --danger: #D6334A;
  --success: #2F9E5B;
  --warn: #B58900;
}

/* ============ THEME: DARK ============ */
html[data-theme="dark"] {
  --bg: #17151F;
  --surface: #1D1B27;
  --surface-2: #262330;
  --purple: #8B72FF;
  --purple-strong: #7A5CFF;
  --purple-light: #A594FF;
  --purple-faint: rgba(139,114,255,0.14);
  --text: #F1F0F5;
  --text-muted: #948FA3;
  --border: rgba(255,255,255,0.08);
  --sheet-bg: #FDFCFF;
  --sheet-text: #1B1725;
  --shadow: 0 8px 30px rgba(0,0,0,0.4), 0 2px 8px rgba(0,0,0,0.25);
  --shadow-sm: 0 2px 8px rgba(0,0,0,0.25);
  --danger: #FC8181;
  --success: #48BB78;
  --warn: #ECC94B;
}

html, body { height: 100%; font-family: 'Satoshi', sans-serif; background: var(--bg); color: var(--text); overflow: hidden; }
body { transition: background 0.2s ease, color 0.2s ease; }

#app { display: flex; height: 100vh; overflow: hidden; }

/* ============ SIDEBAR ============ */
.docs-sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: width 0.25s cubic-bezier(0.22,1,0.36,1), transform 0.25s cubic-bezier(0.22,1,0.36,1), background 0.2s ease;
  z-index: 50;
}
.docs-sidebar.collapsed { width: 0; }

.docs-sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 14px 12px;
  flex-shrink: 0;
  gap: 8px;
}
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  font-family: 'Clash Display', sans-serif;
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
}
.sidebar-nx-logo { width: 22px; height: 22px; border-radius: 6px; object-fit: contain; flex-shrink: 0; }

.btn-new-doc {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px;
  background: var(--purple);
  border: none;
  border-radius: 20px;
  font-family: 'Satoshi', sans-serif;
  font-size: 12px;
  font-weight: 700;
  color: white;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
  transition: background 0.15s;
}
.btn-new-doc:hover { background: var(--purple-strong); }
.btn-new-doc:active { transform: translateY(1px); }

.docs-search {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 6px 12px 6px;
  padding: 8px 10px;
  background: var(--surface-2);
  border: 1px solid transparent;
  border-radius: 20px;
  color: var(--text-muted);
  flex-shrink: 0;
  transition: border-color 0.15s;
}
.docs-search:focus-within { border-color: var(--purple); }
.docs-search input {
  flex: 1; border: none; outline: none; background: transparent;
  font-family: 'Satoshi', sans-serif; font-size: 12.5px; color: var(--text);
}
.docs-search input::placeholder { color: var(--text-muted); }

.docs-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 8px 4px;
  display: flex;
  flex-direction: column;
  gap: 1px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.doc-item {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 9px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.12s;
  min-width: 0;
}
.doc-item:hover { background: var(--surface-2); }
.doc-item.active { background: var(--purple-faint); }
.doc-item-icon {
  width: 28px; height: 28px;
  border-radius: 7px;
  background: var(--surface-2);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  color: var(--purple);
}
.doc-item.active .doc-item-icon { background: rgba(109,74,255,0.14); }
.doc-item-info { flex: 1; min-width: 0; }
.doc-item-name {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.doc-item-date { font-size: 10.5px; color: var(--text-muted); margin-top: 1px; }
.doc-item-del {
  background: none; border: none;
  color: var(--text-muted);
  cursor: pointer; padding: 4px;
  border-radius: 6px;
  opacity: 0;
  transition: all 0.15s;
  flex-shrink: 0;
  display: flex; align-items: center;
}
.doc-item:hover .doc-item-del { opacity: 1; }
.doc-item-del:hover { color: var(--danger); background: rgba(214,51,74,0.1); }

.sidebar-bottom { border-top: 1px solid var(--border); flex-shrink: 0; padding: 10px 12px 12px; display: flex; flex-direction: column; gap: 6px; }

.btn-theme-toggle, .btn-install {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 10px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: 'Satoshi', sans-serif; font-size: 12.5px; font-weight: 600;
  color: var(--text-muted); cursor: pointer; transition: all 0.15s;
  width: 100%;
}
.btn-theme-toggle:hover, .btn-install:hover { border-color: var(--purple); color: var(--purple); background: var(--purple-faint); }
.btn-install.hidden { display: none; }

.sidebar-plan { padding-top: 4px; }
.plan-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  font-size: 12px;
  font-weight: 600;
  color: var(--purple);
}
.plan-chip.one {
  background: var(--purple);
  color: white;
}
.plan-chip-count { margin-left: auto; font-size: 11px; opacity: 0.75; }

/* ============ MAIN AREA / HEADER ============ */
.main-area { flex: 1; display: flex; flex-direction: column; overflow: hidden; min-width: 0; position: relative; }

.nx-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 14px;
  height: var(--header-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  gap: 10px;
  flex-shrink: 0;
  z-index: 30;
}
.header-left { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0; }
.header-right { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.header-doc-icon { width: 19px; height: 19px; border-radius: 5px; object-fit: contain; flex-shrink: 0; }

.btn-sidebar-toggle {
  background: none; border: none;
  color: var(--text-muted); cursor: pointer;
  padding: 7px; border-radius: 7px;
  display: flex; align-items: center;
  transition: all 0.15s; flex-shrink: 0;
}
.btn-sidebar-toggle:hover { background: var(--surface-2); color: var(--text); }

/* Proton-style title dropdown pill: title + chevron act as one control */
.doc-title-wrap {
  position: relative; display: flex; align-items: center; min-width: 0;
  border-radius: 20px; padding: 3px 4px 3px 10px;
  transition: background 0.15s;
}
.doc-title-wrap:hover { background: var(--surface-2); }
.doc-title {
  font-family: 'Clash Display', sans-serif;
  font-size: 14.5px; font-weight: 600; color: var(--text);
  background: transparent; border: none; outline: none;
  width: 100%; max-width: 260px; padding: 5px 2px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.btn-doc-menu {
  background: none; border: none; color: var(--text-muted); cursor: pointer;
  padding: 6px; border-radius: 50%; display: flex; align-items: center; flex-shrink: 0;
  transition: all 0.15s;
}
.btn-doc-menu:hover { background: var(--border); color: var(--text); }

.doc-menu {
  position: absolute; top: calc(100% + 8px); left: 0;
  width: 258px; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 6px; z-index: 120; display: flex; flex-direction: column; gap: 1px;
  overflow: hidden;
}
.doc-menu.hidden { display: none; }
.doc-menu-item {
  display: flex; align-items: center; gap: 11px;
  padding: 9px 10px; border-radius: var(--radius-sm);
  background: none; border: none; color: var(--text); cursor: pointer;
  font-family: 'Satoshi', sans-serif; font-size: 13px; font-weight: 500;
  text-align: left; width: 100%; transition: background 0.1s;
}
.doc-menu-item:hover { background: var(--surface-2); color: var(--text); }
.doc-menu-item svg { flex-shrink: 0; color: var(--text-muted); }
.doc-menu-divider { height: 1px; background: var(--border); margin: 5px 4px; }
.doc-menu-footer {
  display: flex; align-items: center; gap: 8px;
  margin: 6px -6px -6px;
  padding: 11px 16px;
  background: var(--purple-faint);
  color: var(--purple);
  font-size: 11.5px; font-weight: 600;
  border-top: 1px solid var(--border);
}
.doc-menu-footer svg { flex-shrink: 0; }

.save-status { display: flex; align-items: center; gap: 6px; font-size: 11.5px; color: var(--text-muted); font-weight: 500; padding: 0 4px; }
.save-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--success); transition: background 0.3s; }
.save-dot.saving { background: var(--warn); }
.save-dot.error { background: var(--danger); }

.btn-icon {
  display: flex; align-items: center; gap: 6px;
  padding: 7px 12px;
  background: transparent; border: 1px solid var(--border);
  border-radius: 20px;
  font-family: 'Satoshi', sans-serif; font-size: 12.5px; font-weight: 600;
  color: var(--text-muted); cursor: pointer; transition: all 0.15s; white-space: nowrap;
}
.btn-icon:hover { border-color: var(--text-muted); color: var(--text); background: var(--surface-2); }

.download-wrap { position: relative; }
.download-menu {
  position: absolute; top: calc(100% + 6px); right: 0;
  width: 170px; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 6px; z-index: 120;
}
.download-menu.hidden { display: none; }

.btn-history {
  display: flex; align-items: center; gap: 6px;
  padding: 7px 12px;
  background: transparent; border: 1px solid var(--border);
  border-radius: 20px;
  font-family: 'Satoshi', sans-serif; font-size: 12.5px; font-weight: 600;
  color: var(--text-muted); cursor: pointer; transition: all 0.15s; white-space: nowrap;
}
.btn-history:hover { border-color: var(--text-muted); color: var(--text); background: var(--surface-2); }

.one-badge {
  display: inline-flex; align-items: center;
  padding: 1px 5px; border-radius: 4px;
  background: var(--purple);
  color: white; font-size: 9px; font-weight: 800;
  letter-spacing: 0.5px; margin-left: auto;
}

.btn-kora-toggle {
  display: flex; align-items: center; gap: 6px;
  padding: 7px 14px;
  background: var(--purple);
  border: none; border-radius: 20px;
  font-family: 'Satoshi', sans-serif; font-size: 12.5px; font-weight: 700;
  color: white; cursor: pointer; transition: all 0.15s; white-space: nowrap;
}
.btn-kora-toggle:hover { background: var(--purple-strong); }
.btn-kora-toggle.active { background: var(--surface-2); color: var(--purple); border: 1px solid var(--purple); }

/* ============ TOOLBAR (Proton single-row style) ============ */
.toolbar {
  display: flex;
  align-items: center;
  gap: 2px;
  height: var(--toolbar-h);
  padding: 0 10px;
  margin: 8px 16px 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  box-shadow: var(--shadow-sm);
  overflow-x: auto;
  overflow-y: hidden;
  flex-shrink: 0;
  scrollbar-width: none;
  z-index: 20;
}
.toolbar::-webkit-scrollbar { display: none; }

/* File-action buttons (Abrir/Descargar/Historial) now live inside the rounded
   toolbar, so they collapse to compact icon-only controls like the other tools */
.toolbar .btn-icon,
.toolbar .btn-history {
  display: flex; align-items: center; justify-content: center;
  gap: 0; min-width: 28px; height: 28px; padding: 0 6px;
  background: none; border: none; border-radius: 6px;
  font-size: 0;
  color: var(--text-muted);
}
.toolbar .btn-icon svg, .toolbar .btn-history svg { flex-shrink: 0; }
.toolbar .btn-icon:hover, .toolbar .btn-history:hover { background: var(--surface-2); color: var(--text); border: none; }
.toolbar .download-wrap { position: relative; display: flex; }
.toolbar .btn-history { position: relative; }
.one-dot {
  position: absolute; top: 3px; right: 3px;
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--purple);
}

.toolbar-group { display: flex; align-items: center; gap: 2px; flex-shrink: 0; }
.toolbar-divider { width: 1px; height: 20px; background: var(--border); margin: 0 6px; flex-shrink: 0; }

.tool-btn {
  display: flex; align-items: center; justify-content: center;
  min-width: 28px; height: 28px; padding: 0 6px;
  background: none; border: none; border-radius: 6px;
  color: var(--text-muted); font-size: 13px; font-family: 'Satoshi', sans-serif;
  cursor: pointer; transition: all 0.12s; position: relative; flex-shrink: 0;
}
.tool-btn:hover { background: var(--surface-2); color: var(--text); }
.tool-btn.active { background: var(--purple-faint); color: var(--purple); }

.toolbar-select {
  height: 28px; padding: 0 6px;
  background: transparent; border: 1px solid transparent; border-radius: 6px;
  font-family: 'Satoshi', sans-serif; font-size: 12px; font-weight: 600;
  color: var(--text); cursor: pointer; outline: none; flex-shrink: 0;
  transition: background 0.12s;
}
.toolbar-select:hover { background: var(--surface-2); }
.toolbar-select--sm { width: 52px; }

.color-wrap { position: relative; display: flex; align-items: center; }
.color-swatch { position: absolute; bottom: 3px; left: 50%; transform: translateX(-50%); width: 16px; height: 3px; border-radius: 2px; background: #000; }
.color-input-hidden { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; border: none; padding: 0; }

.format-group { gap: 8px; }
.format-label { font-size: 12px; color: var(--text-muted); font-weight: 600; white-space: nowrap; }
.btn-apply-format {
  display: flex; align-items: center; gap: 6px;
  height: 28px; padding: 0 12px;
  background: var(--purple); border: none; border-radius: 20px;
  color: white; font-family: 'Satoshi', sans-serif; font-size: 12px; font-weight: 700;
  cursor: pointer; white-space: nowrap; transition: background 0.15s;
}
.btn-apply-format:hover { background: var(--purple-strong); }
.btn-apply-format:disabled { opacity: 0.6; cursor: default; }

.link-popover {
  position: absolute; top: calc(var(--header-h) + var(--toolbar-h) + 8px); left: 16px;
  z-index: 60; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 10px; display: flex; gap: 8px;
}
.link-popover.hidden { display: none; }
.link-popover input {
  width: 220px; padding: 8px 10px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface-2); color: var(--text); font-family: 'Satoshi', sans-serif; font-size: 13px; outline: none;
}
.link-popover input:focus { border-color: var(--purple); }
.link-popover button {
  padding: 8px 12px; border: none; border-radius: var(--radius-sm); cursor: pointer;
  font-family: 'Satoshi', sans-serif; font-size: 12.5px; font-weight: 700;
}
#link-confirm { background: var(--purple); color: white; }
#link-cancel { background: var(--surface-2); color: var(--text-muted); border: 1px solid var(--border); }

/* ============ EDITOR ============ */
.workspace { flex: 1; display: flex; overflow: hidden; min-height: 0; }

.editor-area {
  flex: 1;
  overflow-y: auto;
  overflow-x: auto;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 32px 24px 120px;
  background: var(--bg);
}

.editor-sheet {
  width: 816px;
  max-width: 100%;
  background: var(--sheet-bg);
  border-radius: 6px;
  box-shadow: var(--shadow);
  min-height: calc(100vh - var(--header-h) - var(--toolbar-h) - 64px);
}

.editor {
  width: 100%;
  min-height: inherit;
  padding: 96px;
  outline: none;
  font-family: 'Arial', sans-serif;
  font-size: 11pt;
  line-height: 1.15;
  color: var(--sheet-text);
  caret-color: var(--purple);
}

.editor:empty::before {
  content: attr(data-placeholder);
  color: #A9A3B8;
  pointer-events: none;
  font-style: italic;
}
.editor h1 { font-family: 'Arial', sans-serif; font-size: 20pt; font-weight: 700; margin: 16pt 0 4pt; line-height: 1.2; }
.editor h2 { font-family: 'Arial', sans-serif; font-size: 16pt; font-weight: 700; margin: 14pt 0 4pt; line-height: 1.2; }
.editor h3 { font-family: 'Arial', sans-serif; font-size: 12pt; font-weight: 700; opacity: 0.85; margin: 12pt 0 2pt; line-height: 1.2; }
.editor p { margin: 0 0 11pt; text-align: left; }
.editor ul, .editor ol { padding-left: 36pt; margin: 4pt 0 11pt; }
.editor li { margin: 2pt 0; line-height: 1.15; }
.editor blockquote {
  margin: 10pt 0; padding: 4pt 14pt; border-left: 3px solid var(--purple);
  color: var(--text-muted); font-style: italic;
}
.editor pre {
  margin: 10pt 0; padding: 12pt; background: rgba(109,74,255,0.06); border-radius: 8px;
  font-family: 'JetBrains Mono', monospace; font-size: 10pt; white-space: pre-wrap; overflow-x: auto;
}
.editor a { color: var(--purple); text-decoration: underline; }
.editor img { max-width: 100%; border-radius: 6px; margin: 6pt 0; }
.editor table { border-collapse: collapse; width: 100%; margin: 10pt 0; }
.editor table td { border: 1px solid rgba(109,74,255,0.3); padding: 6pt 8pt; min-width: 60px; }
.editor hr { border: none; border-top: 1px solid rgba(109,74,255,0.25); margin: 14pt 0; }
.editor .task-item { list-style: none; display: flex; align-items: flex-start; gap: 8px; margin: 3pt 0; }
.editor .task-item input { margin-top: 3px; }

/* ============ KORA PANEL (styled like Proton's comment sidebar) ============ */
.kora-panel { width: 0; overflow: hidden; display: flex; flex-direction: column; background: var(--surface); border-left: 1px solid var(--border); transition: width 0.25s cubic-bezier(0.22,1,0.36,1); flex-shrink: 0; }
.kora-panel.open { width: 320px; }
.kora-header { display: flex; align-items: center; gap: 8px; padding: 14px; border-bottom: 1px solid var(--border); flex-shrink: 0; }
.kora-panel-title { font-family: 'Clash Display', sans-serif; font-size: 14px; font-weight: 700; color: var(--text); flex: 1; }
.kora-limit { font-size: 11px; color: var(--text-muted); font-weight: 600; }
.kora-close { background: none; border: none; color: var(--text-muted); cursor: pointer; padding: 5px; border-radius: 50%; display: flex; align-items: center; transition: background 0.15s; }
.kora-close:hover { background: var(--surface-2); }
.kora-messages { flex: 1; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 10px; scrollbar-width: thin; scrollbar-color: var(--border) transparent; }
.kora-bubble { padding: 10px 13px; border-radius: 10px; font-size: 13px; line-height: 1.6; max-width: 92%; word-break: break-word; }
.kora-bubble--ai { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); align-self: flex-start; box-shadow: var(--shadow-sm); }
.kora-bubble--user { background: var(--purple); color: white; align-self: flex-end; }
.kora-bubble--loading { background: var(--surface-2); color: var(--text-muted); align-self: flex-start; font-style: italic; border: 1px solid var(--border); }
.kora-input-wrap { display: flex; align-items: flex-end; gap: 8px; padding: 12px; border-top: 1px solid var(--border); flex-shrink: 0; }
.kora-input { flex: 1; padding: 10px 12px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; font-family: 'Satoshi', sans-serif; font-size: 13px; color: var(--text); outline: none; resize: none; line-height: 1.5; transition: border-color 0.15s; max-height: 100px; }
.kora-input:focus { border-color: var(--purple); }
.kora-input::placeholder { color: var(--text-muted); }
.kora-send { width: 34px; height: 34px; background: var(--purple); border: none; border-radius: 10px; color: white; cursor: pointer; display: flex; align-items: center; justify-content: center; flex-shrink: 0; transition: background 0.15s; }
.kora-send:hover { background: var(--purple-strong); }
.kora-send:disabled { opacity: 0.5; cursor: not-allowed; }

/* ============ MODALS ============ */
.history-modal {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(20,17,31,0.4);
  display: flex; align-items: center; justify-content: center;
  backdrop-filter: blur(3px);
}
.history-modal.hidden { display: none; }
.history-content {
  background: var(--surface); border-radius: var(--radius-lg);
  width: 90%; max-width: 480px; max-height: 70vh;
  display: flex; flex-direction: column;
  box-shadow: var(--shadow);
  overflow: hidden;
}
.history-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 18px; border-bottom: 1px solid var(--border);
}
.history-title { font-family: 'Clash Display', sans-serif; font-size: 15.5px; font-weight: 700; color: var(--text); }
.history-list { flex: 1; overflow-y: auto; padding: 10px; display: flex; flex-direction: column; gap: 6px; }
.history-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 12px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); cursor: pointer; transition: all 0.12s;
}
.history-item:hover { border-color: var(--purple); background: var(--purple-faint); }
.history-item-date { font-size: 13px; font-weight: 600; color: var(--text); }
.history-item-size { font-size: 11px; color: var(--text-muted); }
.history-restore {
  padding: 6px 12px; background: var(--purple); border: none;
  border-radius: 20px; color: white; font-size: 12px; font-weight: 700;
  cursor: pointer; font-family: 'Satoshi', sans-serif;
}

.wordcount-content { max-width: 360px; }
.wordcount-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; padding: 20px; }
.wordcount-stat { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 14px; text-align: center; }
.wordcount-num { font-family: 'Clash Display', sans-serif; font-size: 22px; font-weight: 700; color: var(--purple); }
.wordcount-label { font-size: 11.5px; color: var(--text-muted); margin-top: 4px; }

.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(80px); background: var(--surface); border: 1px solid var(--border); color: var(--text); padding: 11px 22px; border-radius: 40px; font-size: 13px; font-weight: 600; font-family: 'Satoshi', sans-serif; z-index: 9999; opacity: 0; transition: all 0.25s cubic-bezier(0.22,1,0.36,1); white-space: nowrap; box-shadow: var(--shadow); pointer-events: none; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.editor-area::-webkit-scrollbar { width: 6px; }
.editor-area::-webkit-scrollbar-track { background: transparent; }
.editor-area::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 99;
}
.sidebar-overlay.visible { display: block; }

@media print {
  .docs-sidebar, .sidebar-overlay, .nx-header, .toolbar, .kora-panel, .toast, .link-popover, .history-modal { display: none !important; }
  .editor-area { padding: 0; overflow: visible; background: white; }
  .editor-sheet { box-shadow: none; width: 100%; }
  html, body { overflow: visible; height: auto; }
}

@media (max-width: 768px) {
  .only-desktop { display: none !important; }
  .docs-sidebar {
    position: fixed; top: 0; left: 0; height: 100vh;
    z-index: 100; width: var(--sidebar-w);
    transform: translateX(-100%);
    transition: transform 0.25s cubic-bezier(0.22,1,0.36,1);
    box-shadow: 4px 0 20px rgba(0,0,0,0.15);
  }
  .docs-sidebar:not(.collapsed) { transform: translateX(0); }
  .editor-area { padding: 16px 10px 90px; }
  .editor-sheet { width: 100%; border-radius: 10px; }
  .editor { padding: 26px 20px; font-size: 12pt; }
  .kora-panel.open { width: 100vw; position: fixed; inset: 0; z-index: 200; }
  .save-status { display: none; }
  .doc-title { max-width: 130px; font-size: 13.5px; }
  .header-doc-icon { display: none; }
  .toolbar-select { font-size: 11.5px; }
  .link-popover { left: 8px; right: 8px; }
  .link-popover input { width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 0.001ms !important; animation-duration: 0.001ms !important; }
}

/* ============ MASTER PASSWORD SCREEN ============ */
.nx-master-screen {
  position: fixed; inset: 0; z-index: 1000;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg);
}
.nx-master-screen.hidden { display: none; }
.nx-master-card {
  width: 100%; max-width: 340px; padding: 34px 28px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); box-shadow: var(--shadow);
  text-align: center;
}
.nx-master-logo { width: 42px; height: 42px; border-radius: 11px; margin-bottom: 14px; }
.nx-master-title { font-family: 'Clash Display', sans-serif; font-size: 20px; font-weight: 600; margin: 0 0 6px; }
.nx-master-sub { font-size: 13px; color: var(--text-muted); margin: 0 0 20px; line-height: 1.4; }
.nx-master-form { display: flex; flex-direction: column; gap: 10px; }
.nx-master-input-wrap { position: relative; }
.nx-master-input-wrap.hidden { display: none; }
.nx-master-input {
  width: 100%; box-sizing: border-box; padding: 11px 38px 11px 12px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  font-size: 14px; font-family: inherit; color: var(--text); background: var(--surface-2);
  outline: none; transition: border-color 0.15s;
}
.nx-master-input:focus { border-color: var(--purple); }
.nx-master-eye {
  position: absolute; right: 8px; top: 50%; transform: translateY(-50%);
  background: none; border: none; color: var(--text-muted); cursor: pointer;
  display: flex; padding: 4px;
}
.nx-master-error { font-size: 12px; color: var(--danger); min-height: 16px; margin: 0; text-align: left; }
.nx-master-btn {
  padding: 11px; border: none; border-radius: 24px;
  background: var(--purple); color: white; font-weight: 700; font-size: 14px;
  cursor: pointer; font-family: inherit; transition: background 0.15s;
}
.nx-master-btn:hover:not(:disabled) { background: var(--purple-strong); }
.nx-master-btn:disabled { opacity: 0.6; cursor: default; }
.nx-master-btn-ghost {
  padding: 8px; border: none; background: none; color: var(--text-muted);
  font-size: 12px; cursor: pointer; font-family: inherit;
}
