@font-face {
  font-family: 'Inter';
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
  src: url('fonts/inter.woff2') format('woff2');
}

@font-face {
  font-family: 'Inter';
  font-style: italic;
  font-weight: 100 900;
  font-display: swap;
  src: url('fonts/inter-italic.woff2') format('woff2');
}

@font-face {
  font-family: 'Lora';
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: url('fonts/lora.woff2') format('woff2');
}

@font-face {
  font-family: 'Lora';
  font-style: italic;
  font-weight: 400 700;
  font-display: swap;
  src: url('fonts/lora-italic.woff2') format('woff2');
}

@font-face {
  font-family: 'Roboto';
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
  src: url('fonts/roboto.woff2') format('woff2');
}

@font-face {
  font-family: 'Roboto';
  font-style: italic;
  font-weight: 100 900;
  font-display: swap;
  src: url('fonts/roboto-italic.woff2') format('woff2');
}

@font-face {
  font-family: 'Montserrat';
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
  src: url('fonts/montserrat.woff2') format('woff2');
}

@font-face {
  font-family: 'Fira Code';
  font-style: normal;
  font-weight: 300 700;
  font-display: swap;
  src: url('fonts/fira-code.woff2') format('woff2');
}

:root{
  --bg:#0e0e0e;
  --viewer:#000000;
  --glass:rgba(255,255,255,0.06);
  --border:rgba(255,255,255,0.1);
  --text:#f5f6f7;
  --muted:#9aa0a6;
  --accent:#3b82f6;
  --radius:20px;
  --body-font-size: 18px;
  --editor-width: 1080px;
  --sidebar-width: 400px;
  --app-gap: 28px;
  --focus-dur: 0.42s;
  --title-font: 'Montserrat', sans-serif;
  --body-font: 'Inter', system-ui, sans-serif;
}

*{box-sizing:border-box}
html,body{height:100%}

body{
  margin:0;
  background: #0e0e0e;
  color:var(--text);
  font-family:'Inter',system-ui;
  padding:32px;
  transition: background-color 0.3s ease;
}

body.focus-mode {
  background: #000000;
}

/* Light Mode */
body.light-mode {
  background: #f5f5f5;
}

body.light-mode .reader {
  background: #ffffff;
  color: #1a1a1a;
}

body.light-mode #editTitle,
body.light-mode #editBody,
body.light-mode .meta {
  color: #1a1a1a;
}

body.light-mode .meta {
  color: #666666;
}

body.light-mode .meta-divider,
body.light-mode .content-divider {
  background: rgba(0,0,0,0.12);
}

body.light-mode .sidebar {
  background: rgba(255,255,255,0.8);
  border-color: rgba(0,0,0,0.08);
}

body.light-mode .btn {
  background: rgba(0,0,0,0.03);
  border-color: rgba(0,0,0,0.08);
  color: rgba(0,0,0,0.6);
}

body.light-mode .btn:hover {
  background: rgba(0,0,0,0.08);
  border-color: rgba(0,0,0,0.2);
  color: rgba(0,0,0,0.9);
}

body.light-mode .section-title {
  color: rgba(0,0,0,0.4);
}

body.light-mode .divider {
  background: linear-gradient(90deg, transparent, rgba(0,0,0,0.1), transparent);
}

body.light-mode .typography-select {
  background: rgba(0,0,0,0.03);
  border-color: rgba(0,0,0,0.08);
  color: rgba(0,0,0,0.7);
}

body.light-mode .typography-select:hover {
  background: rgba(0,0,0,0.08);
  border-color: rgba(0,0,0,0.2);
  color: rgba(0,0,0,0.9);
}

body.light-mode .footer-stats {
  background: rgba(255,255,255,0.8);
  border-color: rgba(0,0,0,0.08);
  color: rgba(0,0,0,0.6);
}

body.light-mode #toolbar {
  background: rgba(255,255,255,0.95);
  border-color: rgba(0,0,0,0.15);
}

body.light-mode #toolbar button {
  color: rgba(0,0,0,0.6);
}

body.light-mode #toolbar button:hover {
  color: rgba(0,0,0,0.9);
  background: rgba(0,0,0,0.08);
}

body.light-mode #commandPalette {
  background: rgba(255,255,255,0.95);
  border-color: rgba(0,0,0,0.1);
}

body.light-mode .cmd-item {
  color: rgba(0,0,0,0.6);
}

body.light-mode .cmd-item:hover {
  background: rgba(0,0,0,0.1);
  color: rgba(0,0,0,0.9);
}

body.light-mode .inline-dropzone {
  border-color: rgba(59,130,246,0.4);
  background: rgba(59,130,246,0.05);
  color: rgba(59,130,246,0.9);
}

body.light-mode.focus-mode {
  background: #ffffff;
}

/* Version History Modal */
#historyModal {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(0,0,0,0.95);
  backdrop-filter: blur(20px);
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 16px;
  padding: 30px;
  max-width: 600px;
  width: 90%;
  max-height: 70vh;
  overflow-y: auto;
  z-index: 1000;
  display: none;
}

body.light-mode #historyModal {
  background: rgba(255,255,255,0.95);
  border-color: rgba(0,0,0,0.2);
}

#historyModal.active {
  display: block;
}

#historyOverlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0,0,0,0.7);
  z-index: 999;
  display: none;
}

#historyOverlay.active {
  display: block;
}

.history-item {
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 12px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.history-item:hover {
  background: rgba(255,255,255,0.1);
  border-color: rgba(255,255,255,0.2);
}

body.light-mode .history-item {
  background: rgba(0,0,0,0.03);
  border-color: rgba(0,0,0,0.1);
}

body.light-mode .history-item:hover {
  background: rgba(0,0,0,0.08);
  border-color: rgba(0,0,0,0.2);
}

.history-time {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 4px;
}

.history-title {
  font-weight: 600;
  margin-bottom: 4px;
}

.history-preview {
  font-size: 13px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* WriteAssist in Sidebar */
.assist-header {
  padding: 12px 16px;
  border-bottom: 1px solid rgba(255,255,255,0.1);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-shrink: 0;
}

body.light-mode .assist-header {
  border-bottom-color: rgba(0,0,0,0.1);
}

.assist-header h3 {
  margin: 0;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: rgba(255,255,255,0.6);
  font-weight: 600;
}

body.light-mode .assist-header h3 {
  color: rgba(0,0,0,0.6);
}

.assist-model-select {
  background: rgba(255,255,255,0.03);
  border: 1px solid rgba(255,255,255,0.08);
  color: rgba(255,255,255,0.6);
  padding: 4px 8px;
  border-radius: 6px;
  font-size: 10px;
  cursor: pointer;
  transition: all 0.2s ease;
  font-family: 'Inter', sans-serif;
}

.assist-model-select:hover {
  background: rgba(255,255,255,0.08);
  border-color: rgba(255,255,255,0.2);
  color: rgba(255,255,255,0.8);
}

body.light-mode .assist-model-select {
  background: rgba(0,0,0,0.03);
  border-color: rgba(0,0,0,0.08);
  color: rgba(0,0,0,0.6);
}

body.light-mode .assist-model-select:hover {
  background: rgba(0,0,0,0.08);
  border-color: rgba(0,0,0,0.2);
  color: rgba(0,0,0,0.9);
}

.assist-model-select option {
  background: #1a1a1a;
  color: var(--text);
}

#chatHistory {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  min-height: 0;
}

/* Scrollbar styling for chat history - Dark Mode */
#chatHistory::-webkit-scrollbar {
  width: 6px;
}

#chatHistory::-webkit-scrollbar-track {
  background: rgba(255,255,255,0.05);
  border-radius: 3px;
}

#chatHistory::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,0.15);
  border-radius: 3px;
}

#chatHistory::-webkit-scrollbar-thumb:hover {
  background: rgba(255,255,255,0.25);
}

/* Scrollbar styling for chat history - Light Mode */
body.light-mode #chatHistory::-webkit-scrollbar-track {
  background: rgba(0,0,0,0.05);
}

body.light-mode #chatHistory::-webkit-scrollbar-thumb {
  background: rgba(0,0,0,0.15);
}

body.light-mode #chatHistory::-webkit-scrollbar-thumb:hover {
  background: rgba(0,0,0,0.25);
}

.chat-message {
  margin-bottom: 12px;
  animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

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

.message-bubble {
  display: inline-block;
  max-width: 90%;
  padding: 10px 12px;
  border-radius: 10px;
  position: relative;
}

/* Fixed: User message bubble now uses glass style matching the UI */
.chat-message.user .message-bubble {
  background: rgba(255,255,255,0.1);
  border: 1px solid rgba(255,255,255,0.15);
}

.chat-message.assistant .message-bubble {
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.12);
}

body.light-mode .chat-message.user .message-bubble {
  background: rgba(0,0,0,0.06);
  border-color: rgba(0,0,0,0.1);
}

body.light-mode .chat-message.assistant .message-bubble {
  background: rgba(0,0,0,0.04);
  border-color: rgba(0,0,0,0.08);
}

.message-text {
  font-size: 13px;
  line-height: 1.5;
  white-space: pre-wrap;
  color: var(--text);
}

body.light-mode .message-text {
  color: #1a1a1a;
}

.message-actions {
  margin-top: 6px;
  display: flex;
  gap: 6px;
  justify-content: flex-end;
}

/* Icon buttons for message actions */
.message-btn {
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.1);
  color: rgba(255,255,255,0.5);
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 12px;
  cursor: pointer;
  transition: all 0.2s ease;
  min-width: 28px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.message-btn:hover {
  background: rgba(255,255,255,0.15);
  color: rgba(255,255,255,0.9);
  border-color: rgba(255,255,255,0.2);
}

.message-btn.success {
  color: #4ade80;
}

body.light-mode .message-btn {
  background: rgba(0,0,0,0.05);
  border-color: rgba(0,0,0,0.08);
  color: rgba(0,0,0,0.5);
}

body.light-mode .message-btn:hover {
  background: rgba(0,0,0,0.1);
  color: rgba(0,0,0,0.9);
  border-color: rgba(0,0,0,0.15);
}

body.light-mode .message-btn.success {
  color: #16a34a;
}

.assist-input-area {
  padding: 16px;
  border-top: 1px solid rgba(255,255,255,0.1);
  flex-shrink: 0;
}

body.light-mode .assist-input-area {
  border-top-color: rgba(0,0,0,0.1);
}

/* Quick actions - always visible, styled for UI */
.quick-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}

.quick-action-btn {
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.12);
  color: rgba(255,255,255,0.6);
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 11px;
  cursor: pointer;
  transition: all 0.2s ease;
  font-family: 'Inter', sans-serif;
}

.quick-action-btn:hover {
  background: rgba(255,255,255,0.15);
  border-color: rgba(255,255,255,0.25);
  color: rgba(255,255,255,0.9);
}

/* BUG FIX: Active/pressed state for glass UI */
.quick-action-btn:active {
  background: rgba(255,255,255,0.2);
  border-color: rgba(255,255,255,0.35);
  transform: scale(0.97);
  box-shadow: 0 2px 8px rgba(255,255,255,0.1);
}

/* Active state when button is toggled on */
.quick-action-btn.active {
  background: rgba(59, 130, 246, 0.2);
  border-color: rgba(59, 130, 246, 0.5);
  color: rgba(255,255,255,0.95);
}

.quick-action-btn.active:hover {
  background: rgba(59, 130, 246, 0.25);
  border-color: rgba(59, 130, 246, 0.6);
}

/* Light mode quick action buttons */
body.light-mode .quick-action-btn {
  background: rgba(0,0,0,0.05);
  border-color: rgba(0,0,0,0.1);
  color: rgba(0,0,0,0.6);
}

body.light-mode .quick-action-btn:hover {
  background: rgba(0,0,0,0.1);
  border-color: rgba(0,0,0,0.2);
  color: rgba(0,0,0,0.9);
}

body.light-mode .quick-action-btn:active {
  background: rgba(0,0,0,0.15);
  border-color: rgba(0,0,0,0.25);
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

body.light-mode .quick-action-btn.active {
  background: rgba(59, 130, 246, 0.15);
  border-color: rgba(59, 130, 246, 0.4);
  color: rgba(0,0,0,0.85);
}

body.light-mode .quick-action-btn.active:hover {
  background: rgba(59, 130, 246, 0.2);
  border-color: rgba(59, 130, 246, 0.5);
}

#chatInput {
  width: 100%;
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 8px;
  padding: 10px;
  color: var(--text);
  font-family: 'Inter', sans-serif;
  font-size: 13px;
  resize: vertical;
  min-height: 60px;
  max-height: 120px;
}

body.light-mode #chatInput {
  background: rgba(0,0,0,0.03);
  border-color: rgba(0,0,0,0.1);
  color: #1a1a1a;
}

#chatInput::placeholder {
  color: rgba(255,255,255,0.3);
}

body.light-mode #chatInput::placeholder {
  color: rgba(0,0,0,0.3);
}

#chatInput:focus {
  outline: none;
  border-color: rgba(59,130,246,0.5);
}

/* Send button removed - using Enter key instead */
.assist-send {
  display: none;
}

.loading-indicator {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: rgba(255,255,255,0.6);
  animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 0.4; }
  50% { opacity: 1; }
}


/* --- UPDATED APP LAYOUT --- */
.app {
  max-width: calc(var(--editor-width) + var(--app-gap) + var(--sidebar-width));
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(0, var(--editor-width)) var(--sidebar-width);
  gap: var(--app-gap);
  justify-content: center;
  /* Focus mode animates the grid tracks (not the container), so the whole layout
     re-centres smoothly instead of jumping once the max-width finally shrinks. */
  transition:
    grid-template-columns var(--focus-dur) cubic-bezier(0.4, 0, 0.2, 1),
    gap var(--focus-dur) cubic-bezier(0.4, 0, 0.2, 1);
}

/* --- UPDATED FOCUS MODE --- */
/* The panel's width is driven by the grid track only, so it can never snap:
   it fades + slides while the track closes underneath it. */
body.focus-mode .sidebar {
  opacity: 0;
  pointer-events: none;
  transform: translateX(24px);
  transition:
    opacity 0.2s ease,
    transform var(--focus-dur) cubic-bezier(0.4, 0, 0.2, 1);
}

body.focus-mode .app {
  grid-template-columns: minmax(0, var(--editor-width)) 0px;
  gap: 0;
}

/* Ensure the reader itself doesn't overflow */
.reader {
  width: 100%;
  max-width: var(--editor-width);
  background: var(--viewer);
  border-radius: var(--radius);
  padding: 70px;
  min-height: 85vh;
  box-shadow: 0 30px 80px rgba(0,0,0,0.8);
  position: relative;
  overflow: hidden;
}

.doc{max-width:940px;margin:0 auto}

#editTitle {
  font-family: var(--title-font);
  font-weight:700;
  font-size:46px;
  margin-bottom:22px;
  border: none;
  outline: none;
  width: 100%;
  background: transparent;
  color: var(--text);
  line-height: 1.2;
}

.meta{font-size:13px;color:var(--muted);margin-bottom:34px; letter-spacing: 0.5px;}

.meta-divider {
  height: 1px;
  background: rgba(255,255,255,0.12);
  margin: 32px 0;
}

.content-divider {
  height: 1px;
  background: rgba(255,255,255,0.12);
  margin: 32px 0;
  width: 100%;
}

#editBody {
  font-family: var(--body-font);
  font-size: var(--body-font-size);
  line-height: 1.67;
  outline: none;
  min-height: 500px;
}

/* Images & Command UI */
.img-container { 
    display: flex; 
    justify-content: center; 
    align-items: center;
    margin: 30px 0; 
    width: 100%;
    position: relative;
}
.img-container img { 
    max-width: 100%; 
    border-radius: 8px; 
    cursor: nwse-resize; 
    display: block;
    user-select: none;
    -webkit-user-drag: none;
}

.img-container .img-delete {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 32px;
  height: 32px;
  background: rgba(0,0,0,0.8);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 50%;
  display: none;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  color: rgba(255,255,255,0.8);
  cursor: pointer;
  z-index: 100;
  transition: all 0.2s ease;
  user-select: none;
}

.img-container:hover .img-delete {
  display: flex;
}

.img-container .img-delete:hover {
  background: rgba(220,38,38,0.9);
  color: white;
  transform: scale(1.1);
}

/* Title Image - Core Structure */
.title-image-container {
  display: none;
  position: relative;
  width: 100%;
  margin-bottom: 30px;
  justify-content: center;
  align-items: center;
}

.title-image-container.has-image {
  display: flex;
}

.title-image-container img {
  max-width: 100%;
  border-radius: 12px;
  cursor: nwse-resize;
  display: block;
  user-select: none;
  -webkit-user-drag: none;
}

.title-image-delete {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 32px;
  height: 32px;
  background: rgba(0,0,0,0.8);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 50%;
  display: none;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  color: rgba(255,255,255,0.8);
  cursor: pointer;
  z-index: 100;
  transition: all 0.2s ease;
  user-select: none;
}

.title-image-container:hover .title-image-delete {
  display: flex;
}

.title-image-delete:hover {
  background: rgba(220,38,38,0.9);
  color: white;
  transform: scale(1.1);
}

/* Title Image Insert Button - Floating Above Center */
.title-add-btn {
  position: absolute;
  top: -20px;
  left: 50%;
  transform: translateX(-50%);
  width: 28px;
  height: 28px;
  background: rgba(0,0,0,0.8);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 50%;
  display: none;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  color: rgba(255,255,255,0.8);
  cursor: pointer;
  z-index: 100;
  box-shadow: 0 4px 12px rgba(0,0,0,0.4);
  transition: all 0.2s ease;
  user-select: none;
}

.title-add-btn:hover {
  background: rgba(255,255,255,0.15);
  color: white;
  transform: translateX(-50%) scale(1.1);
}

/* Show button when hovering near the title area (top 100px) */
#editTitle:hover ~ .title-add-btn,
.title-add-btn:hover {
  display: flex !important;
}

/* Hide + button if title image exists */
.title-image-container.has-image ~ .title-add-btn {
  display: none !important;
}

.doc {
  position: relative;
}

#editBody h2, #editBody h3, #editBody h4 {
  position: relative;
  font-family: var(--body-font);
  font-weight: 700;
}

#editBody h2 {
  font-size: 1.56em;
  margin: 32px 0 16px 0;
}

#editBody h3 {
  font-size: 1.33em;
  margin: 28px 0 14px 0;
}

#editBody h4 {
  font-size: 1.11em;
  margin: 24px 0 12px 0;
}

#editBody a {
  color: #3b82f6;
  text-decoration: underline;
}

body.light-mode #editBody a {
  color: #2563eb;
}

#editBody pre {
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 8px;
  padding: 20px;
  overflow-x: auto;
  font-family: 'Fira Code', monospace;
  font-size: 15px;
  line-height: 1.7;
  color: #e8e8e8;
  position: relative;
}

body.light-mode #editBody pre {
  background: #f5f5f5;
  border: 1px solid #e0e0e0;
  color: #2d2d2d;
}

#editBody h1 {
  font-family: var(--body-font);
  font-weight: 700;
  font-size: 1.9em;
  margin: 36px 0 18px 0;
}

#editBody code {
  font-family: 'Fira Code', monospace;
  font-size: 0.9em;
  background: rgba(255,255,255,0.08);
  padding: 2px 5px;
  border-radius: 4px;
}

#editBody pre code {
  background: none;
  padding: 0;
  font-size: 15px;
}

body.light-mode #editBody code {
  background: rgba(0,0,0,0.06);
}

/* Editable tables */
#editBody table.editor-table {
  width: 100%;
  border-collapse: collapse;
  margin: 24px 0;
}

#editBody table.editor-table th,
#editBody table.editor-table td {
  border: 1px solid rgba(255,255,255,0.15);
  padding: 8px 12px;
  text-align: left;
  vertical-align: top;
}

#editBody table.editor-table th {
  background: rgba(255,255,255,0.06);
  font-weight: 600;
  font-family: var(--body-font);
}

body.light-mode #editBody table.editor-table th,
body.light-mode #editBody table.editor-table td {
  border-color: rgba(0,0,0,0.15);
}

body.light-mode #editBody table.editor-table th {
  background: rgba(0,0,0,0.04);
}

/* Syntax highlighting classes */
#editBody pre .keyword { color: #ff79c6; font-weight: 500; }
#editBody pre .string { color: #50fa7b; }
#editBody pre .number { color: #bd93f9; }
#editBody pre .comment { color: #6272a4; font-style: italic; }
#editBody pre .function { color: #8be9fd; }
#editBody pre .operator { color: #ff79c6; }

body.light-mode #editBody pre .keyword { color: #d73a49; }
body.light-mode #editBody pre .string { color: #22863a; }
body.light-mode #editBody pre .number { color: #005cc5; }
body.light-mode #editBody pre .comment { color: #6a737d; }
body.light-mode #editBody pre .function { color: #6f42c1; }
body.light-mode #editBody pre .operator { color: #d73a49; }

#commandPalette {
    position: absolute; 
    background: rgba(0, 0, 0, 0.7); 
    backdrop-filter: blur(20px);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 12px; 
    padding: 6px; 
    display: none; 
    flex-direction: column;
    min-width: 200px; 
    box-shadow: 0 12px 40px rgba(0,0,0,0.6), inset 0 1px 0 rgba(255,255,255,0.05); 
    z-index: 3000;
}
.cmd-item { 
  padding: 10px 14px; 
  cursor: pointer; 
  border-radius: 6px; 
  font-size: 13px; 
  color: rgba(255,255,255,0.6); 
  transition: all 0.2s ease;
}
.cmd-item:hover { 
  background: rgba(255,255,255,0.1); 
  color: white; 
}

.inline-dropzone {
    border: 2px dashed rgba(59, 130, 246, 0.4);
    background: rgba(59, 130, 246, 0.03);
    border-radius: 12px;
    padding: 30px;
    text-align: center;
    color: rgba(59, 130, 246, 0.8);
    margin: 20px 0;
    cursor: pointer;
}

.inline-dropzone.dragover {
    background: rgba(59, 130, 246, 0.12);
    border-color: rgba(59, 130, 246, 0.8);
    color: rgba(59, 130, 246, 1);
}

/* Sidebar */
.sidebar{
  background: rgba(0,0,0,0.4);
  backdrop-filter: blur(20px);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: var(--radius);
  padding: 20px 16px;
  position: sticky;
  top: 32px;
  height: calc(100vh - 64px);
  display: flex;
  flex-direction: column;
  box-shadow: 0 8px 32px rgba(0,0,0,0.4), inset 0 1px 0 rgba(255,255,255,0.05);
  /* Collapse/expand: fade + slide. The fade-in on expand is slightly delayed so the
     panel doesn't appear while it is still squeezed. */
  transition:
    opacity 0.3s ease 0.08s,
    transform var(--focus-dur) cubic-bezier(0.4, 0, 0.2, 1);
  overflow-y: auto;
  overflow-x: hidden;
}

body.light-mode .sidebar {
  background: rgba(255,255,255,0.8);
  border-color: rgba(0,0,0,0.08);
}

/* While the panel collapses, keep its contents at full width so they clip rather than
   re-flow (re-wrapping buttons mid-animation looked janky). Desktop grid only. */
@media (min-width: 1181px) {
  .sidebar > * {
    min-width: calc(var(--sidebar-width) - 32px);
  }
}

/* Sidebar brand */
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 2px 14px;
  margin-bottom: 14px;
  border-bottom: 1px solid rgba(255,255,255,0.1);
  flex: 0 0 auto;
}
.brand-icon {
  width: 32px;
  height: 32px;
  display: block;
  flex: 0 0 auto;
}
.brand-name {
  font-family: var(--title-font);
  font-weight: 700;
  font-size: 1.35rem;
  letter-spacing: -0.01em;
  color: var(--text);
  line-height: 1;
}
body.light-mode .sidebar-brand {
  border-bottom-color: rgba(0,0,0,0.1);
}
body.light-mode .brand-icon {
  filter: invert(1);
}
body.light-mode .brand-name {
  color: #1a1a1a;
}

.sidebar-section {
  margin-bottom: 14px;
  flex: 0 0 auto;
}

.sidebar-section:last-of-type {
  margin-bottom: 0;
}

.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.btn-row .btn {
  flex: 1 1 auto;
  min-width: 42px;
  padding: 8px 10px;
}

.btn-row .btn.btn-icon {
  flex: 0 0 auto;
  min-width: 38px;
}

.more-panel {
  margin-top: 6px;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
}

.more-panel[hidden] {
  display: none;
}

.heading-select {
  background: rgba(255,255,255,0.03);
  border: 1px solid rgba(255,255,255,0.08);
  color: rgba(255,255,255,0.6);
  padding: 6px 8px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 11px;
  width: 100%;
  margin-bottom: 6px;
  transition: all 0.2s ease;
  font-family: 'Inter', sans-serif;
}

.heading-select:hover {
  background: rgba(255,255,255,0.08);
  border-color: rgba(255,255,255,0.2);
  color: rgba(255,255,255,0.8);
}

.heading-select option {
  background: #1a1a1a;
  color: var(--text);
  padding: 8px;
}

body.light-mode .heading-select {
  background: rgba(0,0,0,0.03);
  border-color: rgba(0,0,0,0.08);
  color: rgba(0,0,0,0.7);
}

body.light-mode .heading-select:hover {
  background: rgba(0,0,0,0.08);
  border-color: rgba(0,0,0,0.2);
  color: rgba(0,0,0,0.9);
}

.sidebar-writeassist {
  flex: 1;
  display: flex;
  flex-direction: column;
  border-top: 1px solid rgba(255,255,255,0.1);
  min-height: 0;
  margin-bottom: 20px;
  margin-top: 8px;
}

body.light-mode .sidebar-writeassist {
  border-top-color: rgba(0,0,0,0.1);
}

.section-title{
  font-weight: 600;
  font-size: 9px;
  text-transform: uppercase;
  color: rgba(255,255,255,0.3);
  margin-bottom: 8px;
  letter-spacing: 1.5px;
}

body.light-mode .section-title {
  color: rgba(0,0,0,0.4);
}

.btn-group {
  display: grid;
  gap: 6px;
}

.btn-group.grid-2 {
  grid-template-columns: 1fr 1fr;
}

.btn-group.grid-3 {
  grid-template-columns: 1fr 1fr 1fr;
}

.btn{
  background: rgba(255,255,255,0.03);
  border: 1px solid rgba(255,255,255,0.08);
  color: rgba(255,255,255,0.4);
  padding: 8px;
  border-radius: 8px;
  cursor: pointer;
  text-align: center;
  font-size: 13px;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
  white-space: nowrap;
}

.btn::before {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at center, rgba(255,255,255,0.1), transparent);
  opacity: 0;
  transition: opacity 0.3s ease;
}

.btn:hover {
  background: rgba(255,255,255,0.08);
  border-color: rgba(255,255,255,0.2);
  color: rgba(255,255,255,0.8);
  transform: translateY(-1px);
}

.btn:hover::before {
  opacity: 1;
}

.btn:active {
  transform: translateY(0);
}

.btn.wide {
  grid-column: 1 / -1;
}

.btn-block {
  width: 100%;
  padding: 10px 12px;
}

.divider {
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.1), transparent);
  margin: 2px 0;
}

/* Typography Dropdown */
.typography-select {
  background: rgba(255,255,255,0.03);
  border: 1px solid rgba(255,255,255,0.08);
  color: rgba(255,255,255,0.6);
  padding: 6px 8px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 11px;
  width: 100%;
  transition: all 0.2s ease;
  font-family: 'Inter', sans-serif;
  margin-bottom: 6px;
}

.typography-select:hover {
  background: rgba(255,255,255,0.08);
  border-color: rgba(255,255,255,0.2);
  color: rgba(255,255,255,0.8);
}

.typography-select option {
  background: #1a1a1a;
  color: var(--text);
  padding: 8px;
}

/* Floating Selection Toolbar */
#toolbar {
  position: absolute;
  background: rgba(15, 15, 15, 0.9);
  backdrop-filter: blur(20px);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 10px;
  padding: 5px;
  display: none;
  z-index: 1000;
  box-shadow: 0 16px 40px rgba(0,0,0,0.7), inset 0 1px 0 rgba(255,255,255,0.06);
  white-space: nowrap;
}
#toolbar button { 
  background: transparent; 
  border: none; 
  color: rgba(255,255,255,0.5); 
  padding: 8px 9px; 
  cursor: pointer; 
  font-size: 11px; 
  font-weight: 600;
  transition: all 0.2s ease;
  border-radius: 6px;
}
#toolbar button:hover { 
  color: white; 
  background: rgba(255,255,255,0.08); 
}

.footer-stats {
    position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.3); 
    backdrop-filter: blur(20px);
    padding: 10px 24px; 
    border-radius: 30px; 
    border: 1px solid rgba(255,255,255,0.08);
    display: flex; gap: 24px; font-size: 12px; 
    color: rgba(255,255,255,0.5); 
    z-index: 2000;
    box-shadow: 0 8px 24px rgba(0,0,0,0.3), inset 0 1px 0 rgba(255,255,255,0.05);
}

blockquote { border-left: 2px solid #444; padding-left: 24px; margin: 32px 0; color: #e0e0e0; font-style: italic; }

/* contenteditable placeholders (the old `placeholder` attribute is ignored on divs) */
[data-placeholder]:empty::before {
  content: attr(data-placeholder);
  color: var(--muted);
  pointer-events: none;
}

/* Transient toast / storage warning */
#appToast {
  position: fixed;
  bottom: 76px;
  left: 50%;
  transform: translateX(-50%) translateY(10px);
  max-width: min(520px, 90vw);
  background: rgba(20,20,20,0.96);
  border: 1px solid rgba(255,255,255,0.15);
  color: #f5f6f7;
  padding: 12px 18px;
  border-radius: 12px;
  font-size: 13px;
  line-height: 1.4;
  z-index: 5000;
  opacity: 0;
  transition: opacity 0.25s ease, transform 0.25s ease;
  pointer-events: none;
  box-shadow: 0 12px 40px rgba(0,0,0,0.5);
}
#appToast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
body.light-mode #appToast { background: rgba(255,255,255,0.98); border-color: rgba(0,0,0,0.15); color: #1a1a1a; }

/* --- Responsive layout (the original had none outside of print) --- */
@media (max-width: 1180px) {
  body { padding: 20px; }
  .app {
    grid-template-columns: minmax(0, 1fr);
    max-width: 100%;
    gap: 20px;
  }
  .reader { padding: 44px; }
  .sidebar {
    position: static;
    top: auto;
    height: auto;
    max-height: 70vh;
  }
  body.focus-mode .app { grid-template-columns: minmax(0, 1fr); max-width: 100%; }
  body.focus-mode .sidebar { display: none; }
}

@media (max-width: 720px) {
  body { padding: 12px; }
  .app { gap: 14px; }
  .reader { padding: 24px; border-radius: 14px; min-height: auto; }
  #editTitle { font-size: 30px; margin-bottom: 14px; }
  #editBody { font-size: 17px; }
  .footer-stats { gap: 12px; padding: 8px 14px; font-size: 11px; bottom: 12px; }
  .sidebar { padding: 14px 12px; }
}

@media print{
  .sidebar, #toolbar, .footer-stats, .meta, .inline-dropzone, .title-add-btn, .title-image-delete, .img-delete {display:none !important}
  body{padding:0; margin:0;}
  
  /* Dark mode print */
  body:not(.light-mode) {background:white !important;}
  body:not(.light-mode) .reader{background: white !important; color: #000 !important; box-shadow: none;}
  body:not(.light-mode) #editTitle,
  body:not(.light-mode) #editBody {color: #000 !important;}
  body:not(.light-mode) .content-divider {background: rgba(0,0,0,0.12);}
  body:not(.light-mode) #editBody pre {background: #f5f5f5 !important; border-color: #e0e0e0 !important; color: #2d2d2d !important;}
  body:not(.light-mode) #editBody a {color: #2563eb !important;}
  
  /* Light mode print - preserve existing styles */
  body.light-mode .reader {box-shadow: none;}
  
  .reader{box-shadow: none; padding: 20px; border-radius: 0; min-height: auto; margin: 0; max-width: 100%;}
  .app{display: block; max-width: 100%; grid-template-columns: none;}
  .doc{max-width: 100%;}
}

/* --- Added for strict CSP: replaces former inline style attributes --- */
#fileInput { display: none; }
#titleImage { width: 700px; }
#historyModal h2 { margin-top: 0; }
.modal-close {
  margin-top: 20px;
  padding: 10px 20px;
  background: rgba(255,255,255,0.1);
  border: 1px solid rgba(255,255,255,0.2);
  color: #fff;
  border-radius: 8px;
  cursor: pointer;
}
body.light-mode .modal-close { background: rgba(0,0,0,0.06); border-color: rgba(0,0,0,0.15); color: #1a1a1a; }
.version-empty { color: var(--muted); }
