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

:root {
  --accent: #f5a623;
  --accent-dark: #d4891a;
  --bg: #fafaf8;
  --surface: #ffffff;
  --surface2: #f5f4f0;
  --border: #e8e6e0;
  --text: #1a1a1a;
  --text-muted: #888880;
  --danger: #e53935;
  --shadow: 0 1px 4px rgba(0,0,0,0.10);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.12);
  --radius: 12px;
  --sidebar-w: 300px;
  --header-h: 56px;
  --min-tap: 44px;
  --font: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

/* ===== Dark theme ===== */
[data-theme="dark"] {
  --bg: #1a1a1a;
  --surface: #242424;
  --surface2: #2e2e2e;
  --border: #3e3e3e;
  --text: #e8e8e8;
  --text-muted: #a0a0a0;
  --shadow: 0 1px 4px rgba(0,0,0,0.40);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.50);
}

html, body { height: 100%; overflow: hidden; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
}

/* ===== Layout ===== */
#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

#offline-banner {
  display: none;
  background: #ff8f00;
  color: #fff;
  text-align: center;
  padding: 6px 16px;
  font-size: 13px;
  font-weight: 500;
}
#offline-banner.visible { display: block; }

.main-layout {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* ===== Sidebar ===== */
.sidebar {
  width: var(--sidebar-w);
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-right: 1px solid var(--border);
  flex-shrink: 0;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  height: var(--header-h);
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  position: sticky;
  top: 0;
  z-index: 10;
  flex-shrink: 0;
}

.sidebar-header h1 {
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.3px;
}

/* ===== Search bar ===== */
.search-bar {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.search-input {
  width: 100%;
  height: 34px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0 12px;
  font-size: 13px;
  font-family: var(--font);
  background: var(--surface2);
  color: var(--text);
  outline: none;
  transition: border-color 0.12s, background 0.12s;
}
.search-input:focus {
  border-color: var(--accent);
  background: var(--surface);
}
.search-input::placeholder { color: var(--text-muted); }

/* ===== Filter tabs ===== */
.filter-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
}

.filter-tab {
  flex: 1;
  padding: 8px 4px;
  border: none;
  background: none;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  font-family: var(--font);
  border-bottom: 2px solid transparent;
  transition: color 0.12s, border-color 0.12s;
  min-height: 36px;
}
.filter-tab:hover { color: var(--text); }
.filter-tab.active {
  color: var(--accent-dark);
  border-bottom-color: var(--accent);
  font-weight: 600;
}

/* ===== Folder section ===== */
.folder-section {
  flex-shrink: 0;
  border-bottom: 1px solid var(--border);
}
.folder-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 16px;
}
.folder-section-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}
.btn-link {
  border: none;
  background: none;
  cursor: pointer;
  font-size: 16px;
  color: var(--text-muted);
  padding: 2px 6px;
  border-radius: 6px;
  transition: background 0.12s, color 0.12s;
  font-family: var(--font);
  line-height: 1;
}
.btn-link:hover { background: var(--surface2); color: var(--text); }

.new-folder-form {
  padding: 4px 12px 6px;
}
.new-folder-input {
  width: 100%;
  height: 30px;
  border: 1px solid var(--accent);
  border-radius: 6px;
  padding: 0 10px;
  font-size: 13px;
  font-family: var(--font);
  outline: none;
  background: var(--surface);
}

.folder-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 16px;
  cursor: pointer;
  font-size: 13px;
  border-left: 2px solid transparent;
  transition: background 0.1s, border-color 0.1s;
  min-height: 32px;
  position: relative;
}
.folder-item:hover { background: var(--surface2); }
.folder-item.active {
  background: #fff8ec;
  border-left-color: var(--accent);
  font-weight: 600;
  color: var(--accent-dark);
}
[data-theme="dark"] .folder-item.active {
  background: #2e2200;
  color: var(--accent);
}
.folder-icon { font-size: 14px; flex-shrink: 0; }
.folder-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.btn-delete-folder {
  display: none;
  border: none;
  background: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 16px;
  padding: 2px 4px;
  border-radius: 4px;
  line-height: 1;
  flex-shrink: 0;
}
.folder-item:hover .btn-delete-folder { display: block; }
.btn-delete-folder:hover { background: #fdecea; color: var(--danger); }

/* ===== Sort bar ===== */
.sort-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.sort-label {
  font-size: 11px;
  color: var(--text-muted);
  flex-shrink: 0;
}
.sort-select {
  flex: 1;
  height: 28px;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0 8px;
  font-size: 12px;
  font-family: var(--font);
  background: var(--surface);
  color: var(--text);
  outline: none;
  cursor: pointer;
}
.sort-select:focus { border-color: var(--accent); }

/* ===== Sidebar footer ===== */
.sidebar-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  background: var(--surface);
}
.sidebar-user {
  font-size: 13px;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.btn-signout {
  height: 32px;
  padding: 0 12px;
  background: var(--surface2);
  border: none;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
  font-family: var(--font);
  transition: background 0.12s;
  flex-shrink: 0;
}
.btn-signout:hover { background: var(--border); }

.btn-new {
  width: var(--min-tap);
  height: var(--min-tap);
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: #fff;
  font-size: 24px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  transition: background 0.15s, transform 0.1s;
  flex-shrink: 0;
}
.btn-new:hover { background: var(--accent-dark); }
.btn-new:active { transform: scale(0.93); }

#note-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
}

.note-item {
  padding: 12px 16px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  min-height: var(--min-tap);
  transition: background 0.12s;
  position: relative;
}
.note-item:last-child { border-bottom: none; }
.note-item:hover { background: var(--surface2); }
.note-item.active {
  background: #fff8ec;
  border-left: 3px solid var(--accent);
  padding-left: 13px;
}
[data-theme="dark"] .note-item.active {
  background: #2e2200;
  border-left: 3px solid var(--accent);
}

.note-item-header {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 3px;
}
.note-item-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}
.note-pin-badge {
  font-size: 11px;
  flex-shrink: 0;
  opacity: 0.7;
}

.note-item-subtitle {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 3px;
}
.note-item-date {
  font-size: 11px;
  color: #bbb8b0;
}

/* Tag chips in note list */
.note-item-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
  margin-top: 4px;
  margin-bottom: 2px;
}
.note-tag-chip {
  display: inline-block;
  background: #eef4ff;
  color: #3a5fc8;
  border-radius: 4px;
  padding: 1px 6px;
  font-size: 10px;
  font-weight: 600;
  white-space: nowrap;
}
.note-tag-more {
  display: inline-block;
  color: var(--text-muted);
  font-size: 10px;
  padding: 1px 4px;
}

/* ===== Empty state ===== */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text-muted);
  gap: 10px;
  padding: 32px;
  text-align: center;
}
.empty-state .icon { font-size: 40px; opacity: 0.4; }
.empty-state p { font-size: 14px; }

/* ===== Editor Pane ===== */
.editor-pane {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  min-width: 0;
}

/* ===== Formatting toolbar ===== */
.fmt-bar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 2px;
  padding: 4px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
}

.fmt-btn {
  min-width: 28px;
  height: 28px;
  padding: 0 6px;
  border: none;
  background: none;
  cursor: pointer;
  font-size: 13px;
  border-radius: 5px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text);
  opacity: 0.65;
  transition: background 0.1s, opacity 0.1s;
  flex-shrink: 0;
}
.fmt-btn:hover { background: var(--surface2); opacity: 1; }
.fmt-btn.active { background: var(--surface2); opacity: 1; box-shadow: inset 0 0 0 1.5px var(--border); }

.fmt-italic { font-style: italic; }
.fmt-underline { text-decoration: underline; }
.fmt-strike { text-decoration: line-through; }

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

.fmt-color-wrap {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 28px;
  height: 28px;
  border-radius: 5px;
  cursor: pointer;
  transition: background 0.1s;
}
.fmt-color-wrap:hover { background: var(--surface2); }
.fmt-color-wrap input[type="color"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
  width: 100%;
  height: 100%;
  border: none;
  padding: 0;
}
.fmt-color-icon {
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
  opacity: 0.65;
  pointer-events: none;
  line-height: 1;
}
.fmt-hl-icon {
  background: #ffff00;
  color: #333;
  padding: 1px 3px;
  border-radius: 2px;
  font-size: 11px;
}

.fmt-size-select {
  height: 28px;
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 0 4px;
  font-size: 12px;
  font-family: var(--font);
  background: var(--surface2);
  color: var(--text);
  outline: none;
  cursor: pointer;
  min-width: 70px;
}
.fmt-size-select:focus { border-color: var(--accent); }

/* Formatting styles in note body */
.note-body-input b, .note-body-input strong { font-weight: 700; }
.note-body-input i, .note-body-input em { font-style: italic; }
.note-body-input u { text-decoration: underline; }
.note-body-input s, .note-body-input strike { text-decoration: line-through; }
.note-body-input ul { list-style: disc; padding-left: 1.4em; margin: 4px 0; }
.note-body-input ol { list-style: decimal; padding-left: 1.4em; margin: 4px 0; }
.note-body-after-input b, .note-body-after-input strong { font-weight: 700; }
.note-body-after-input i, .note-body-after-input em { font-style: italic; }
.note-body-after-input u { text-decoration: underline; }
.note-body-after-input s, .note-body-after-input strike { text-decoration: line-through; }
.note-body-after-input ul { list-style: disc; padding-left: 1.4em; margin: 4px 0; }
.note-body-after-input ol { list-style: decimal; padding-left: 1.4em; margin: 4px 0; }

.editor-header {
  display: flex;
  align-items: center;
  padding: 0 16px;
  height: var(--header-h);
  border-bottom: 1px solid var(--border);
  gap: 8px;
  flex-shrink: 0;
}

#btn-back {
  display: none;
  width: var(--min-tap);
  height: var(--min-tap);
  border: none;
  background: none;
  cursor: pointer;
  font-size: 22px;
  color: var(--accent);
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  flex-shrink: 0;
  transition: background 0.12s;
}
#btn-back:hover { background: var(--surface2); }

.autosave-indicator {
  flex: 1;
  font-size: 12px;
  color: var(--text-muted);
  min-width: 0;
  cursor: default;
  border-radius: 6px;
  padding: 2px 4px;
  transition: background 0.12s, color 0.12s;
}
.autosave-indicator[data-sync-state="failed"] {
  color: var(--danger);
  cursor: pointer;
  text-decoration: underline dotted;
}
.autosave-indicator[data-sync-state="local"] {
  color: #b97800;
}
.autosave-indicator[data-sync-state="synced"] {
  color: #2e7d32;
}

/* ===== Sync badges in note list ===== */
.sync-badge {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
  vertical-align: middle;
  margin-left: 4px;
}
.sync-badge[data-state="local"] {
  background: #f5a623;
}
.sync-badge[data-state="saving"] {
  background: #64b5f6;
  animation: sync-pulse 1s ease-in-out infinite;
}
.sync-badge[data-state="failed"] {
  background: var(--danger);
}
@keyframes sync-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

/* Folder selector in editor header */
.note-folder-select {
  height: 30px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0 8px;
  font-size: 12px;
  font-family: var(--font);
  background: var(--surface2);
  color: var(--text);
  outline: none;
  cursor: pointer;
  max-width: 130px;
  transition: border-color 0.12s;
  flex-shrink: 0;
}
.note-folder-select:focus { border-color: var(--accent); }
.note-folder-select:disabled { opacity: 0.5; cursor: default; }

/* ===== Icon buttons in editor header ===== */
.btn-icon {
  width: var(--min-tap);
  height: var(--min-tap);
  border: none;
  background: none;
  cursor: pointer;
  font-size: 18px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.12s, opacity 0.12s;
  flex-shrink: 0;
  opacity: 0.55;
}
.btn-icon:hover { background: var(--surface2); opacity: 1; }
.btn-icon.active { opacity: 1; }
.btn-icon.btn-danger:hover { background: #fdecea; }

/* Legacy selector kept for backward compat */
.btn-delete {
  width: var(--min-tap);
  height: var(--min-tap);
  border: none;
  background: none;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 20px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.12s, color 0.12s;
  flex-shrink: 0;
}
.btn-delete:hover { background: #fdecea; color: var(--danger); }

/* ===== Tag bar ===== */
.tag-bar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  padding: 6px 28px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  min-height: 40px;
}
.tag-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  align-items: center;
}
.tag-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: #eef4ff;
  color: #3a5fc8;
  border-radius: 6px;
  padding: 2px 8px;
  font-size: 12px;
  font-weight: 600;
}
.tag-chip-remove {
  border: none;
  background: none;
  cursor: pointer;
  color: #3a5fc8;
  font-size: 14px;
  padding: 0;
  line-height: 1;
  opacity: 0.6;
  transition: opacity 0.1s;
}
.tag-chip-remove:hover { opacity: 1; }

.tag-input {
  border: none;
  outline: none;
  font-size: 12px;
  font-family: var(--font);
  color: var(--text-muted);
  background: transparent;
  min-width: 80px;
  flex: 1;
}
.tag-input::placeholder { color: #ccc; }

.editor-body {
  flex: 1;
  overflow-y: auto;
  padding: 24px 28px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* contenteditable title */
.note-title-input {
  font-size: 22px;
  font-weight: 700;
  color: var(--text);
  outline: none;
  border: none;
  width: 100%;
  min-height: 36px;
  caret-color: var(--accent);
  line-height: 1.3;
}
.note-title-input:empty::before {
  content: 'Title';
  color: #ccc;
}

/* contenteditable body */
.note-body-input {
  flex: 0 0 auto;
  font-size: 15px;
  color: var(--text);
  outline: none;
  border: none;
  width: 100%;
  min-height: 300px;
  white-space: pre-wrap;
  word-break: break-word;
  caret-color: var(--accent);
  line-height: 1.7;
}
.note-body-input:empty::before {
  content: 'Start writing…';
  color: #ccc;
}

/* contenteditable body after images */
.note-body-after-input {
  flex: 0 0 auto;
  font-size: 15px;
  color: var(--text);
  outline: none;
  border: none;
  width: 100%;
  min-height: 120px;
  white-space: pre-wrap;
  word-break: break-word;
  caret-color: var(--accent);
  line-height: 1.7;
  padding-bottom: 16px;
}
.note-body-after-input:empty::before {
  content: 'Continue writing after images…';
  color: #ccc;
}
.note-body-after-input[style*="display:none"],
.note-body-after-input[style*="display: none"] {
  display: none;
}

/* Welcome / no-selection state */
.editor-welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text-muted);
  gap: 12px;
  text-align: center;
  padding: 32px;
}
.editor-welcome .icon { font-size: 52px; opacity: 0.25; }
.editor-welcome p { font-size: 14px; }

/* ===== Confirm Dialog ===== */
.dialog-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s;
}
.dialog-overlay.visible { opacity: 1; pointer-events: all; }

.dialog {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 24px;
  width: min(320px, 90vw);
  box-shadow: var(--shadow-md);
  transform: scale(0.96);
  transition: transform 0.18s;
}
.dialog-overlay.visible .dialog { transform: scale(1); }

.dialog h2 { font-size: 17px; font-weight: 700; margin-bottom: 8px; }
.dialog p { font-size: 14px; color: var(--text-muted); margin-bottom: 20px; }

.dialog-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

.btn { 
  padding: 0 18px;
  height: 40px;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  transition: background 0.12s, transform 0.1s;
  min-width: var(--min-tap);
}
.btn:active { transform: scale(0.97); }
.btn-cancel { background: var(--surface2); color: var(--text); }
.btn-cancel:hover { background: var(--border); }
.btn-confirm-delete { background: var(--danger); color: #fff; }
.btn-confirm-delete:hover { background: #c62828; }

/* ===== Scrollbars ===== */
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 99px; }

/* ===== Responsive / Mobile ===== */
@media (max-width: 767px) {
  .sidebar { width: 100%; border-right: none; }
  .editor-pane { display: none; position: fixed; inset: 0; z-index: 100; }
  .editor-pane.mobile-visible { display: flex; }
  #btn-back { display: flex; }

  .main-layout.editor-open .sidebar { display: none; }
  .main-layout.editor-open .editor-pane { display: flex; }

  .note-folder-select { max-width: 100px; }
}

/* ===== Image toolbar & blocks ===== */
.image-toolbar {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  padding-top: 4px;
}
.image-toolbar-bottom {
  padding-top: 8px;
  padding-bottom: 4px;
  border-top: 1px solid var(--border);
  margin-top: 4px;
}

.btn-image-add {
  height: 32px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface2);
  color: var(--text);
  font-size: 13px;
  font-family: var(--font);
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s;
  white-space: nowrap;
}
.btn-image-add:hover { background: var(--border); border-color: var(--accent); }
.btn-image-add:disabled { opacity: 0.5; cursor: default; }

.image-upload-status {
  font-size: 12px;
  color: var(--text-muted);
  min-height: 18px;
}
.image-upload-status.error { color: var(--danger); }

.image-blocks {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding-bottom: 16px;
}

.image-block {
  position: relative;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--surface2);
}

.image-block img {
  display: block;
  max-width: 100%;
  max-height: 480px;
  width: auto;
  height: auto;
  object-fit: contain;
  margin: 0 auto;
}

.image-block-controls {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 8px;
  background: rgba(255,255,255,0.92);
  border-top: 1px solid var(--border);
}

.btn-image-ctrl {
  border: none;
  background: none;
  cursor: pointer;
  font-size: 16px;
  padding: 3px 6px;
  border-radius: 6px;
  color: var(--text-muted);
  line-height: 1;
  transition: background 0.1s, color 0.1s;
  min-width: 28px;
  min-height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.btn-image-ctrl:hover { background: var(--surface2); color: var(--text); }
.btn-image-ctrl.btn-danger:hover { background: #fdecea; color: var(--danger); }
.btn-image-ctrl:disabled { opacity: 0.3; cursor: default; }

.image-caption {
  display: block;
  width: 100%;
  box-sizing: border-box;
  padding: 6px 10px;
  border: none;
  border-top: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text);
  font-size: 13px;
  font-family: inherit;
  resize: vertical;
  min-height: 36px;
  line-height: 1.4;
  outline: none;
}
.image-caption:focus {
  background: var(--surface);
  box-shadow: inset 0 0 0 2px var(--accent);
}
.image-caption[readonly] { color: var(--text-muted); cursor: default; }
.image-caption::placeholder { color: var(--text-muted); font-style: italic; }

.image-section-text {
  display: block;
  width: 100%;
  box-sizing: border-box;
  padding: 8px 10px;
  border: none;
  border-top: 1px dashed var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  font-family: inherit;
  resize: vertical;
  min-height: 60px;
  line-height: 1.5;
  outline: none;
  white-space: pre-wrap;
}
.image-section-text:focus {
  background: var(--surface);
  box-shadow: inset 0 0 0 2px var(--accent);
}
.image-section-text[readonly] { color: var(--text-muted); cursor: default; }
.image-section-text::placeholder { color: var(--text-muted); font-style: italic; }

/* ===== Annotation Editor ===== */

/* Full-screen modal overlay */
.annotation-modal {
  position: fixed;
  inset: 0;
  z-index: 500;
  display: flex;
  flex-direction: column;
  background: #1a1a1a;
  color: #f0f0f0;
}

/* Header toolbar */
.ann-header {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  padding: 6px 10px;
  background: #2a2a2a;
  border-bottom: 1px solid #444;
  flex-shrink: 0;
  min-height: 52px;
}

.ann-tools {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
}

.ann-tool-btn {
  min-width: var(--min-tap);
  min-height: var(--min-tap);
  padding: 4px 8px;
  border: 1px solid #555;
  border-radius: 8px;
  background: #3a3a3a;
  color: #f0f0f0;
  font-size: 16px;
  font-family: var(--font);
  cursor: pointer;
  transition: background 0.1s, border-color 0.1s;
  display: flex;
  align-items: center;
  justify-content: center;
}
.ann-tool-btn:hover { background: #4a4a4a; border-color: var(--accent); }
.ann-tool-btn.active {
  background: var(--accent);
  border-color: var(--accent-dark);
  color: #fff;
}

.ann-color-input {
  width: 36px;
  height: 36px;
  border: 1px solid #555;
  border-radius: 6px;
  background: none;
  cursor: pointer;
  padding: 2px;
}

.ann-width-slider {
  width: 80px;
  accent-color: var(--accent);
}

/* Action buttons */
.ann-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
  margin-left: auto;
}

.ann-action-btn {
  min-width: var(--min-tap);
  min-height: var(--min-tap);
  padding: 4px 8px;
  border: 1px solid #555;
  border-radius: 8px;
  background: #3a3a3a;
  color: #f0f0f0;
  font-size: 15px;
  font-family: var(--font);
  cursor: pointer;
  transition: background 0.1s;
}
.ann-action-btn:hover:not(:disabled) { background: #4a4a4a; }
.ann-action-btn:disabled { opacity: 0.35; cursor: default; }
.ann-action-btn.ann-btn-danger:hover { background: #7a1f1f; color: #fdd; }

.ann-status {
  font-size: 12px;
  color: #aaa;
  min-width: 60px;
  text-align: center;
}

.ann-btn-save {
  height: var(--min-tap);
  padding: 0 16px;
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  font-family: var(--font);
  cursor: pointer;
  transition: background 0.12s;
}
.ann-btn-save:hover:not(:disabled) { background: var(--accent-dark); }
.ann-btn-save:disabled { opacity: 0.5; cursor: default; }

.ann-btn-cancel {
  height: var(--min-tap);
  padding: 0 12px;
  border: 1px solid #555;
  border-radius: 8px;
  background: #3a3a3a;
  color: #f0f0f0;
  font-size: 16px;
  font-family: var(--font);
  cursor: pointer;
  transition: background 0.1s;
}
.ann-btn-cancel:hover { background: #555; }

.ann-btn-close {
  height: var(--min-tap);
  padding: 0 12px;
  border: 1px solid #744;
  border-radius: 8px;
  background: #4a2a2a;
  color: #f0f0f0;
  font-size: 16px;
  font-family: var(--font);
  cursor: pointer;
  transition: background 0.1s;
}
.ann-btn-close:hover { background: #7a3a3a; }

/* Canvas wrap — takes remaining space, centred */
.ann-canvas-wrap {
  flex: 1;
  overflow: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  background: #111;
  touch-action: none;   /* prevent browser pan/zoom interfering */
}

/* Stage wraps image + canvas together so they overlap */
.ann-stage {
  position: relative;
  display: inline-block;
  transform-origin: center center;
  line-height: 0;         /* prevent gap below img */
}

.ann-source-img {
  display: block;
  user-select: none;
  -webkit-user-drag: none;
  pointer-events: none;   /* canvas is on top */
  max-width: none;        /* override global img max-width */
}

.ann-canvas {
  position: absolute;
  inset: 0;
  cursor: crosshair;
  touch-action: none;
}

/* Floating text input for the text tool */
.ann-text-overlay {
  position: fixed;
  z-index: 600;
  min-width: 120px;
  min-height: 36px;
  padding: 4px 8px;
  border: 2px solid var(--accent);
  border-radius: 6px;
  background: rgba(0,0,0,0.75);
  color: #fff;
  font-size: 16px;
  font-family: var(--font);
  resize: none;
  outline: none;
}

/* Annotated-image canvas preview in note view */
.image-block-canvas {
  display: block;
  max-width: 100%;
  max-height: 480px;
  width: auto;
  height: auto;
  margin: 0 auto;
}

/* Responsive adjustments for annotation editor on small screens */
@media (max-width: 600px) {
  .ann-header { padding: 4px 6px; gap: 4px; }
  .ann-tool-btn { min-width: 36px; min-height: 36px; font-size: 14px; padding: 2px 6px; }
  .ann-action-btn { min-width: 36px; min-height: 36px; font-size: 13px; padding: 2px 6px; }
  .ann-width-slider { width: 60px; }
  .ann-actions { margin-left: 0; }
}

/* ===== Version History Panel (Milestone 9) ===== */
.history-panel {
  position: fixed;
  inset: 0;
  z-index: 500;
  display: flex;
  align-items: stretch;
  justify-content: flex-end;
  background: rgba(0,0,0,0.45);
}

.history-panel-inner {
  width: min(380px, 100vw);
  background: var(--bg-secondary, #2a2a2a);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: -4px 0 24px rgba(0,0,0,0.4);
}

.history-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 16px 8px;
  border-bottom: 1px solid var(--border, #3a3a3a);
}

.history-panel-header h2 {
  margin: 0;
  font-size: 17px;
  font-weight: 600;
  color: var(--text-primary, #f0f0f0);
}

.history-panel-hint {
  font-size: 12px;
  color: var(--text-muted, #888);
  margin: 8px 16px 4px;
}

.history-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
}

.history-loading,
.history-empty {
  padding: 24px 16px;
  color: var(--text-muted, #888);
  font-size: 13px;
  text-align: center;
}

.history-item {
  padding: 10px 16px;
  border-bottom: 1px solid var(--border, #3a3a3a);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.history-item:last-child {
  border-bottom: none;
}

.history-item-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.history-item-date {
  font-size: 11px;
  color: var(--text-muted, #888);
}

.history-item-title {
  font-size: 13px;
  color: var(--text-primary, #f0f0f0);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.btn-restore-version {
  align-self: flex-start;
  margin-top: 4px;
  padding: 4px 12px;
  font-size: 12px;
  font-family: var(--font);
  border: 1px solid var(--accent, #f5a623);
  border-radius: 6px;
  background: transparent;
  color: var(--accent, #f5a623);
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
}

.btn-restore-version:hover {
  background: var(--accent, #f5a623);
  color: #fff;
}

/* ===== Conflict Banner (Milestone 9) ===== */
.conflict-banner {
  position: fixed;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 450;
  background: #7b3a00;
  color: #ffe0a0;
  border: 1px solid #c07000;
  border-radius: 8px;
  padding: 10px 16px;
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 10px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.4);
  max-width: 90vw;
}

.conflict-banner .btn-link {
  color: #ffe0a0;
  text-decoration: underline;
  font-weight: 600;
  background: none;
  border: none;
  cursor: pointer;
  font-size: 13px;
  font-family: var(--font);
  padding: 0;
}

/* ===== Conflict item in note list ===== */
.note-item.conflict-item .note-item-title::before {
  content: '⚠ ';
}

@media (max-width: 600px) {
  .history-panel-inner { width: 100vw; }
}
