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

:root {
  --bg-primary: #f4f4f4;
  --bg-secondary: #ffffff;
  --bg-sidebar: #e8e8e8;
  --text-primary: #333333;
  --text-secondary: #666666;
  --text-muted: #999999;
  --border-color: #cccccc;
  --link-color: #0066cc;
  --link-missing: #cc0000;
  --tag-bg: #e0e0e0;
  --tag-text: #555555;
  --accent-color: #4a90d9;
  --header-bg: #2c3e50;
  --header-text: #ffffff;
  --shadow: 0 2px 4px rgba(0,0,0,0.1);
  --entry-bg: #ffffff;
  --editor-bg: #fafafa;
  --button-bg: #4a90d9;
  --button-text: #ffffff;
  --button-hover: #3a7bc8;
  --danger-color: #dc3545;
  --success-color: #28a745;
}

[data-theme="dark"] {
  --bg-primary: #1a1a2e;
  --bg-secondary: #16213e;
  --bg-sidebar: #0f0f23;
  --text-primary: #e4e4e4;
  --text-secondary: #b0b0b0;
  --text-muted: #777777;
  --border-color: #444444;
  --link-color: #6db3f2;
  --link-missing: #ff6b6b;
  --tag-bg: #2d3748;
  --tag-text: #a0aec0;
  --header-bg: #0f0f23;
  --header-text: #ffffff;
  --entry-bg: #16213e;
  --editor-bg: #1a1a2e;
  --button-bg: #4a90d9;
  --button-text: #ffffff;
  --button-hover: #5ca0e9;
}

body {
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
  font-size: 15px;
  line-height: 1.6;
  background: var(--bg-primary);
  color: var(--text-primary);
}

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

#header {
  background: var(--header-bg);
  color: var(--header-text);
  box-shadow: var(--shadow);
  position: sticky;
  top: 0;
  z-index: 100;
}

#header-inner {
  display: flex;
  justify-content: space-between;
  align-items: center;
  max-width: 1370px;
  margin: 0 auto;
  width: 100%;
  padding: 12px 15px;
  box-sizing: border-box;
}

#header h1 {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 600;
}

#header-subtitle {
  font-size: 0.85rem;
  opacity: 0.8;
  margin-left: 12px;
}

#header-actions {
  display: flex;
  gap: 10px;
  align-items: center;
}

#main-container {
  display: flex;
  flex: 1;
  max-width: 1370px;
  margin: 0 auto;
  width: 100%;
  padding: 0 15px;
  box-sizing: border-box;
}

/* ===== Sidebars ===== */
.sidebar {
  width: 220px;
  min-width: 220px;
  background: var(--bg-sidebar);
  padding: 15px;
  border-right: 1px solid var(--border-color);
  overflow-y: auto;
  max-height: calc(100vh - 60px);
  position: sticky;
  top: 60px;
}

.sidebar-right {
  border-right: none;
  border-left: 1px solid var(--border-color);
}

.sidebar h3 {
  margin: 0 0 10px 0;
  font-size: 0.9rem;
  text-transform: uppercase;
  color: var(--text-muted);
  letter-spacing: 0.5px;
}

.sidebar-section {
  margin-bottom: 20px;
}

/* ===== Search ===== */
#search-box {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  font-size: 14px;
  background: var(--bg-secondary);
  color: var(--text-primary);
  margin-bottom: 15px;
}

#search-box:focus {
  outline: none;
  border-color: var(--accent-color);
  box-shadow: 0 0 0 2px rgba(74, 144, 217, 0.2);
}

#search-results {
  display: none;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 4px;
  margin-bottom: 15px;
  max-height: 200px;
  overflow-y: auto;
}

#search-results.active {
  display: block;
}

.search-result-item {
  padding: 8px 12px;
  cursor: pointer;
  border-bottom: 1px solid var(--border-color);
}

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

.search-result-item:hover {
  background: var(--bg-primary);
}

/* ===== Navigation Lists ===== */
.nav-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.nav-list li {
  padding: 6px 0;
  border-bottom: 1px solid var(--border-color);
}

.nav-list li:last-child {
  border-bottom: none;
}

.nav-list a {
  color: var(--link-color);
  text-decoration: none;
  font-size: 0.9rem;
}

.nav-list a:hover {
  text-decoration: underline;
}

/* ===== Tags ===== */
.tag {
  display: inline-block;
  background: var(--tag-bg);
  color: var(--tag-text);
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 0.8rem;
  margin: 2px;
  cursor: pointer;
  transition: background 0.2s;
}

.tag:hover {
  background: var(--accent-color);
  color: white;
}

.tag-count {
  font-size: 0.7rem;
  opacity: 0.7;
  margin-left: 4px;
}

#tag-cloud {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

/* ===== Story (Main Content Area) ===== */
#story {
  flex: 1;
  padding: 20px;
  max-width: 900px;
  min-width: 0;
}

/* ===== Entry Cards ===== */
.entry {
  background: var(--entry-bg);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  margin-bottom: 20px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.entry-header {
  background: var(--bg-sidebar);
  padding: 12px 15px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.entry-title {
  font-size: 1.2rem;
  font-weight: 600;
  color: var(--text-primary);
  margin: 0;
  cursor: pointer;
}

.entry-title:hover {
  color: var(--link-color);
}

.entry-actions {
  display: flex;
  gap: 8px;
}

.footer-actions {
  display: none;
}

.entry-btn {
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 0.85rem;
  color: var(--text-secondary);
  transition: all 0.2s;
}

.entry-btn:hover {
  background: var(--bg-primary);
  color: var(--text-primary);
}

.entry-btn.danger:hover {
  background: var(--danger-color);
  color: white;
}

.email-btn {
  font-size: 1.15em;
}

.entry-content {
  padding: 15px;
  min-height: 50px;
}

.entry-footer {
  padding: 10px 15px;
  border-top: 1px solid var(--border-color);
  background: var(--bg-sidebar);
  font-size: 0.8rem;
  color: var(--text-muted);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.entry-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.entry-meta {
  font-style: italic;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ===== Entry Content Styling ===== */
.entry-content h1, .entry-content h2, .entry-content h3,
.entry-content h4, .entry-content h5, .entry-content h6 {
  margin-top: 0.5em;
  margin-bottom: 0.3em;
  color: var(--text-primary);
}

.entry-content h1 { font-size: 1.5rem; }
.entry-content h2 { font-size: 1.3rem; }
.entry-content h3 { font-size: 1.1rem; }

.entry-content p {
  margin: 0.5em 0;
}

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

.entry-content code {
  background: var(--bg-sidebar);
  padding: 2px 6px;
  border-radius: 3px;
  font-family: 'SF Mono', Monaco, 'Courier New', monospace;
  font-size: 0.9em;
}

.entry-content pre {
  background: var(--bg-sidebar);
  padding: 12px;
  border-radius: 4px;
  overflow-x: auto;
}

.entry-content pre code {
  background: none;
  padding: 0;
}

/* Code block copy button */
.code-block-wrapper {
  position: relative;
}

.code-block-copy {
  position: absolute;
  top: 8px;
  right: 8px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 4px;
  padding: 4px 8px;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.2s;
  font-size: 14px;
  color: var(--text-secondary);
}

.code-block-wrapper:hover .code-block-copy {
  opacity: 1;
}

.code-block-copy:hover {
  background: var(--bg-sidebar);
  color: var(--text-primary);
}

.entry-content blockquote {
  border-left: 3px solid var(--accent-color);
  margin: 0.5em 0;
  padding-left: 15px;
  color: var(--text-secondary);
}

.entry-content a {
  color: var(--link-color);
  text-decoration: none;
}

.entry-content a:hover {
  text-decoration: underline;
}

.entry-content a.wiki-link-missing {
  color: var(--link-missing);
  font-style: italic;
}

.entry-content img {
  max-width: 100%;
  height: auto;
  border-radius: 4px;
}

/* ===== Markdown Tables ===== */
.entry-content table {
  width: 100%;
  border-collapse: collapse;
  margin: 1em 0;
  font-size: 0.95em;
}

.entry-content th,
.entry-content td {
  border: 1px solid var(--border-color);
  padding: 8px 12px;
  text-align: left;
}

.entry-content th {
  background: var(--bg-sidebar);
  font-weight: 600;
}

.entry-content tr:nth-child(even) {
  background: var(--bg-primary);
}

.entry-content tr:hover {
  background: rgba(74, 144, 217, 0.05);
}

/* ===== Table of Contents ===== */
.entry-content .toc {
  background: var(--bg-sidebar);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  padding: 12px 16px;
  margin: 1em 0;
}

.entry-content .toc ul {
  list-style: none;
  padding: 0;
  margin: 0;
}

.entry-content .toc li {
  margin: 4px 0;
  line-height: 1.4;
}

.entry-content .toc .toc-h1 {
  font-weight: 600;
}

.entry-content .toc .toc-h2 {
  padding-left: 1.5em;
}

.entry-content .toc a {
  color: var(--link-color);
  text-decoration: none;
}

.entry-content .toc a:hover {
  text-decoration: underline;
}

/* Scroll margin for anchor links (accounts for sticky header) */
.entry-content h1[id],
.entry-content h2[id],
.entry-content h3[id],
.entry-content h4[id],
.entry-content h5[id],
.entry-content h6[id] {
  scroll-margin-top: 80px;
}

/* ===== Editor ===== */
.entry-editor {
  padding: 15px;
  background: var(--editor-bg);
}

.editor-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 8px;
  background: var(--bg-sidebar);
  border: 1px solid var(--border-color);
  border-bottom: none;
  border-radius: 4px 4px 0 0;
}

.editor-toolbar button {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  padding: 6px 10px;
  cursor: pointer;
  border-radius: 3px;
  font-size: 0.85rem;
  color: var(--text-primary);
  transition: all 0.2s;
}

.editor-toolbar button:hover {
  background: var(--accent-color);
  color: white;
  border-color: var(--accent-color);
}

.editor-toolbar button.active {
  background: var(--accent-color);
  color: white;
  border-color: var(--accent-color);
}

.editor-toolbar .separator {
  width: 1px;
  background: var(--border-color);
  margin: 0 8px;
}

.editor-textarea {
  width: 100%;
  min-height: 200px;
  padding: 12px;
  border: 1px solid var(--border-color);
  border-radius: 0 0 4px 4px;
  font-family: 'SF Mono', Monaco, 'Courier New', monospace;
  font-size: 14px;
  line-height: 1.5;
  resize: vertical;
  background: var(--bg-secondary);
  color: var(--text-primary);
}

.editor-textarea:focus {
  outline: none;
  border-color: var(--accent-color);
}

.editor-richtext {
  width: 100%;
  min-height: 200px;
  padding: 12px;
  border: 1px solid var(--border-color);
  border-radius: 0 0 4px 4px;
  background: var(--bg-secondary);
  color: var(--text-primary);
  overflow-y: auto;
}

.editor-richtext:focus {
  outline: none;
  border-color: var(--accent-color);
}

.editor-textarea.drag-over,
.editor-richtext.drag-over {
  border-color: var(--accent-color);
  border-style: dashed;
  background: rgba(74, 144, 217, 0.05);
}

.image-drop-hint {
  text-align: center;
  padding: 8px;
  color: var(--text-muted);
  font-size: 0.8rem;
  border-top: 1px solid var(--border-color);
  background: var(--bg-sidebar);
}

.editor-title-input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  font-size: 1.1rem;
  font-weight: 600;
  margin-bottom: 10px;
  background: var(--bg-secondary);
  color: var(--text-primary);
}

.editor-title-input:focus {
  outline: none;
  border-color: var(--accent-color);
}

.editor-tags-input {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  font-size: 0.9rem;
  margin-top: 10px;
  background: var(--bg-secondary);
  color: var(--text-primary);
}

.editor-tags-input:focus {
  outline: none;
  border-color: var(--accent-color);
}

/* ===== Tag Autocomplete ===== */
.tag-input-wrapper {
  position: relative;
}

.tag-suggestions {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-top: none;
  border-radius: 0 0 4px 4px;
  max-height: 200px;
  overflow-y: auto;
  z-index: 100;
}

.tag-suggestions.active {
  display: block;
}

.tag-suggestion {
  padding: 8px 12px;
  cursor: pointer;
  border-bottom: 1px solid var(--border-color);
}

.tag-suggestion:last-child {
  border-bottom: none;
}

.tag-suggestion:hover,
.tag-suggestion.selected {
  background: var(--accent-color);
  color: white;
}

.editor-actions {
  display: flex;
  gap: 10px;
  margin-top: 15px;
}

.editor-mode-toggle {
  margin-left: auto;
  display: flex;
  gap: 4px;
}

/* ===== Buttons ===== */
.btn {
  padding: 8px 16px;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 500;
  transition: all 0.2s;
}

.btn-primary {
  background: var(--button-bg);
  color: var(--button-text);
}

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

.btn-secondary {
  background: var(--bg-sidebar);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
}

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

.btn-danger {
  background: var(--danger-color);
  color: white;
}

.btn-danger:hover {
  background: #c82333;
}

.btn-success {
  background: var(--success-color);
  color: white;
}

.btn-success:hover {
  background: #218838;
}

.btn-icon {
  padding: 6px 10px;
  font-size: 1rem;
}

/* ===== New Entry Button ===== */
#new-entry-btn {
  width: 100%;
  padding: 10px;
  margin-bottom: 15px;
}

/* ===== Save Indicator ===== */
#save-indicator {
  display: none;
  padding: 4px 12px;
  background: var(--success-color);
  color: white;
  border-radius: 4px;
  font-size: 0.85rem;
  animation: fadeInOut 2s ease-in-out;
}

#save-indicator.unsaved {
  background: var(--danger-color);
  display: block;
  animation: none;
}

#save-indicator.saving {
  background: var(--accent-color);
  display: block;
  animation: pulse 1s infinite;
}

#save-indicator.saved {
  display: block;
}

#save-indicator.linked {
  background: var(--success-color);
  display: block;
  animation: none;
}

#link-file-btn {
  background: transparent;
  border: 1px solid var(--header-text);
  color: var(--header-text);
  padding: 4px 10px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.85rem;
  opacity: 0.8;
  transition: opacity 0.2s;
}

#link-file-btn:hover {
  opacity: 1;
}

#link-file-btn.linked {
  border-color: var(--success-color);
  color: var(--success-color);
}

#import-data-btn {
  background: transparent;
  border: 1px solid var(--header-text);
  color: var(--header-text);
  padding: 4px 10px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.85rem;
  opacity: 0.8;
  transition: opacity 0.2s;
}

#import-data-btn:hover {
  opacity: 1;
  background: rgba(255,255,255,0.1);
}

@keyframes fadeInOut {
  0% { opacity: 1; }
  70% { opacity: 1; }
  100% { opacity: 0; }
}

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

/* ===== Empty State ===== */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted);
}

.empty-state h2 {
  color: var(--text-secondary);
  margin-bottom: 10px;
}

/* ===== Timeline ===== */
.timeline-item {
  padding: 6px 0;
  border-bottom: 1px solid var(--border-color);
  font-size: 0.85rem;
}

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

.timeline-date {
  color: var(--text-muted);
  font-size: 0.75rem;
}

/* ===== Responsive ===== */
@media (max-width: 1100px) {
  .sidebar-right {
    display: none;
  }
}

@media (max-width: 768px) {
  #main-container {
    flex-direction: column;
  }

  .sidebar {
    width: 100%;
    max-height: none;
    position: static;
    border-right: none;
    border-bottom: 1px solid var(--border-color);
  }

  .sidebar-left {
    order: -1;
  }

  /* Show right sidebar on mobile, but below main content */
  .sidebar-right {
    display: block;
    order: 1;
    border-top: 1px solid var(--border-color);
    border-bottom: none;
  }

  #story {
    padding: 15px;
  }

  #header {
    flex-wrap: wrap;
    gap: 10px;
  }

  #header-actions {
    width: 100%;
    justify-content: flex-end;
    flex-wrap: wrap;
  }

  /* Hide less important buttons on mobile */
  #import-data-btn,
  #export-html-btn {
    display: none;
  }
}

/* ===== Modal ===== */
.modal-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 200;
  justify-content: center;
  align-items: center;
}

.modal-overlay.active {
  display: flex;
}

.modal {
  background: var(--bg-secondary);
  border-radius: 8px;
  padding: 20px;
  max-width: 500px;
  width: 90%;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

.modal h2 {
  margin-top: 0;
  margin-bottom: 15px;
}

.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 20px;
}

/* ===== Theme Toggle ===== */
.theme-toggle {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1.2rem;
  padding: 4px 8px;
  border-radius: 4px;
  color: var(--header-text);
}

.theme-toggle:hover {
  background: rgba(255, 255, 255, 0.1);
}

/* ===== FVP List Styles ===== */
.fvp-list {
  list-style: none;
  padding: 0;
  margin: 0.5em 0;
}

.fvp-item {
  display: flex;
  align-items: flex-start;
  padding: 2px 0;
  position: relative;
}

.fvp-marker {
  width: 20px;
  min-width: 20px;
  text-align: center;
  font-weight: bold;
  color: var(--accent-color);
  font-size: 1.2em;
  line-height: 1.4;
}

.fvp-text {
  flex: 1;
  line-height: 1.4;
  padding: 1px 4px;
  border-radius: 2px;
}

.fvp-item.dotted .fvp-text {
  background-color: rgba(255, 243, 176, 0.6);
}

[data-theme="dark"] .fvp-item.dotted .fvp-text {
  background-color: rgba(255, 243, 176, 0.15);
}

.fvp-item.completed .fvp-text {
  text-decoration: line-through;
  color: var(--text-muted);
  background-color: transparent;
}

.fvp-item.completed .fvp-marker {
  visibility: hidden;
}

.fvp-actions {
  position: absolute;
  right: 0;
  top: 0;
  display: flex;
  gap: 2px;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.15s ease, visibility 0.15s ease;
  background: var(--bg-secondary);
  padding: 2px 4px;
  border-radius: 4px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.12);
  z-index: 10;
}

.fvp-item:hover .fvp-actions,
.fvp-item.touch-active .fvp-actions {
  opacity: 1;
  visibility: visible;
}

.fvp-action-btn {
  background: var(--bg-sidebar);
  border: 1px solid var(--border-color);
  border-radius: 3px;
  cursor: pointer;
  padding: 2px 6px;
  font-size: 0.75rem;
  color: var(--text-secondary);
  transition: all 0.15s;
  line-height: 1;
}

.fvp-action-btn:hover {
  background: var(--accent-color);
  color: white;
  border-color: var(--accent-color);
}

.fvp-action-btn.active {
  background: var(--accent-color);
  color: white;
  border-color: var(--accent-color);
}

.fvp-action-btn.strikethrough-btn:hover,
.fvp-action-btn.strikethrough-btn.active {
  background: var(--success-color);
  border-color: var(--success-color);
}

.fvp-action-btn.link-btn:hover {
  background: var(--link-color);
  border-color: var(--link-color);
}

/* FVP section headers */
.fvp-section-header {
  font-weight: 600;
  color: var(--text-primary);
  margin-top: 1em;
  margin-bottom: 0.5em;
  padding-bottom: 4px;
  border-bottom: 2px solid var(--accent-color);
}

.fvp-section-header:first-child {
  margin-top: 0;
}

/* FVP Inline Edit Input */
.fvp-edit-input {
  flex: 1;
  font-family: inherit;
  font-size: inherit;
  line-height: 1.4;
  padding: 2px 4px;
  border: 2px solid var(--accent-color);
  border-radius: 3px;
  background: var(--bg-primary);
  color: var(--text-primary);
  outline: none;
  min-width: 100px;
}

.fvp-edit-input:focus {
  box-shadow: 0 0 0 2px rgba(74, 144, 217, 0.3);
}

/* FVP Insert Zone */
.fvp-insert-zone {
  height: 8px;
  position: relative;
  margin: 0;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  padding-left: 20px;
}

.fvp-insert-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 1px solid var(--border-color);
  background: var(--bg-sidebar);
  color: var(--text-secondary);
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  padding: 0;
  opacity: 0;
  visibility: hidden;
  transition: all 0.15s;
}

.fvp-insert-zone:hover .fvp-insert-btn,
.fvp-insert-zone.touch-active .fvp-insert-btn {
  opacity: 1;
  visibility: visible;
}

.fvp-insert-btn:hover {
  background: var(--accent-color);
  color: white;
  border-color: var(--accent-color);
  transform: scale(1.1);
}

/* Touch devices: suppress hover-based reveal, use only touch-active */
@media (hover: none) {
  .fvp-item:hover .fvp-actions {
    opacity: 0;
    visibility: hidden;
  }
  .fvp-item.touch-active .fvp-actions {
    opacity: 1;
    visibility: visible;
  }
  .fvp-insert-zone:hover .fvp-insert-btn {
    opacity: 0;
    visibility: hidden;
  }
  .fvp-insert-zone.touch-active .fvp-insert-btn {
    opacity: 1;
    visibility: visible;
  }
}

/* Cleanup button styling */
.entry-btn.cleanup-btn {
  font-size: 0.9rem;
}

.entry-btn.cleanup-btn:hover {
  background: var(--success-color);
  color: white;
}

/* ===== Sync Status (PWA) ===== */
#sync-container {
  display: flex;
  align-items: center;
  gap: 8px;
}

#sync-sign-in-btn {
  background: transparent;
  border: 1px solid var(--header-text);
  color: var(--header-text);
  padding: 4px 12px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.85rem;
  opacity: 0.8;
  transition: opacity 0.2s, background 0.2s;
}

#sync-sign-in-btn:hover {
  opacity: 1;
  background: rgba(255,255,255,0.1);
}

.hidden {
  display: none !important;
}

#sync-status {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 4px;
  font-size: 0.85rem;
  color: var(--header-text);
  opacity: 0.8;
}

#sync-status.synced {
  color: var(--success-color);
  animation: fadeOut 3s ease-in-out forwards;
}

@keyframes fadeOut {
  0%, 70% { opacity: 0.8; }
  100% { opacity: 0; }
}

#sync-status.syncing {
  color: var(--accent-color);
}

#sync-status.error {
  color: var(--danger-color);
}

#sync-status.offline {
  color: var(--text-muted);
}

#sync-status.needs-reauth {
  color: #e67e22;
  cursor: pointer;
}

.sync-icon {
  font-size: 1rem;
}

.sync-icon.spinning {
  animation: spin 1s linear infinite;
}

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

#sync-btn {
  background: transparent;
  border: 1px solid var(--header-text);
  color: var(--header-text);
  padding: 4px 10px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.85rem;
  opacity: 0.8;
  transition: opacity 0.2s;
}

#sync-btn:hover {
  opacity: 1;
}

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

#sync-clear-btn {
  background: transparent;
  border: 1px solid rgba(220, 53, 69, 0.6);
  color: rgba(220, 53, 69, 0.9);
  padding: 4px 8px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.75rem;
  opacity: 0.8;
  transition: opacity 0.2s, background 0.2s;
}

#sync-clear-btn:hover {
  opacity: 1;
  background: rgba(220, 53, 69, 0.15);
}

#auth-btn {
  background: transparent;
  border: 1px solid var(--header-text);
  color: var(--header-text);
  padding: 4px 10px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.85rem;
  opacity: 0.8;
  transition: opacity 0.2s;
}

#auth-btn:hover {
  opacity: 1;
  background: rgba(255,255,255,0.1);
}

#auth-btn.signed-in {
  border-color: var(--success-color);
  color: var(--success-color);
}

/* ===== Settings Button ===== */
.settings-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1.2rem;
  padding: 4px 8px;
  border-radius: 4px;
  color: var(--header-text);
}

.settings-btn:hover {
  background: rgba(255, 255, 255, 0.1);
}

/* ===== Settings Modal ===== */
.settings-modal {
  max-width: 600px;
  position: relative;
}

.modal-close {
  position: absolute;
  top: 15px;
  right: 15px;
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--text-muted);
  line-height: 1;
  padding: 4px 8px;
  border-radius: 4px;
}

.modal-close:hover {
  background: var(--bg-sidebar);
  color: var(--text-primary);
}

.settings-section {
  margin-bottom: 25px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--border-color);
}

.settings-section:last-child {
  margin-bottom: 0;
  padding-bottom: 0;
  border-bottom: none;
}

.settings-section h3 {
  margin: 0 0 8px 0;
  font-size: 1rem;
  color: var(--text-primary);
}

.settings-desc {
  margin: 0 0 12px 0;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.settings-warning {
  margin: 12px 0 0 0;
  padding: 8px 12px;
  font-size: 0.85rem;
  color: #856404;
  background: #fff3cd;
  border-radius: 6px;
}

/* Sync Location Radio Options */
.sync-location-options {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.radio-option {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  padding: 10px 12px;
  background: var(--bg-sidebar);
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.2s;
}

.radio-option:hover {
  background: var(--bg-primary);
}

.radio-option input[type="radio"] {
  margin: 3px 10px 0 0;
  flex-shrink: 0;
}

.radio-label {
  font-weight: 600;
  flex: 1;
}

.radio-desc {
  width: 100%;
  margin-top: 4px;
  padding-left: 24px;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.settings-links {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.settings-links a {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 12px;
  background: var(--bg-sidebar);
  border-radius: 6px;
  text-decoration: none;
  color: var(--text-primary);
  transition: background 0.2s;
}

.settings-links a:hover {
  background: var(--accent-color);
  color: white;
}

.settings-links a strong {
  font-weight: 600;
}

.settings-links a span {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.settings-links a:hover span {
  color: rgba(255,255,255,0.8);
}

/* ===== Theme Grid ===== */
.theme-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 15px;
}

.theme-grid label {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.theme-grid label span {
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.theme-grid input[type="color"] {
  width: 100%;
  height: 36px;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  cursor: pointer;
  padding: 2px;
  background: var(--bg-secondary);
}

.theme-grid input[type="color"]:hover {
  border-color: var(--accent-color);
}

/* ===== Theme Mode Toggle ===== */
.theme-mode-toggle {
  margin-bottom: 15px;
}

.toggle-label {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.toggle-label span {
  font-size: 0.9rem;
  color: var(--text-primary);
}

.toggle-btn {
  padding: 8px 16px;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  background: var(--bg-secondary);
  cursor: pointer;
  font-size: 1.2rem;
  transition: background-color 0.2s, border-color 0.2s;
}

.toggle-btn:hover {
  border-color: var(--accent-color);
  background: var(--bg-primary);
}

/* ===== Account Sync Status ===== */
.account-sync-status {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px;
  background: var(--bg-primary);
  border-radius: 4px;
  margin-bottom: 15px;
}

.account-sync-status .sync-icon {
  font-size: 1rem;
}

#account-sync-text {
  color: var(--text-secondary);
  font-size: 0.9rem;
}

/* ===== Favicon Input ===== */
.settings-section input[type="text"] {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  font-size: 0.9rem;
  background: var(--bg-secondary);
  color: var(--text-primary);
}

.settings-section input[type="text"]:focus {
  outline: none;
  border-color: var(--accent-color);
}

.settings-buttons {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

/* ===== History Modal ===== */
.history-modal {
  max-width: 500px;
  position: relative;
}

.history-subtitle {
  margin: 0 0 15px 0;
  color: var(--text-secondary);
  font-size: 0.9rem;
}

#history-list {
  max-height: 400px;
  overflow-y: auto;
}

.history-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px;
  background: var(--bg-sidebar);
  border-radius: 6px;
  margin-bottom: 8px;
}

.history-item:last-child {
  margin-bottom: 0;
}

.history-item-info {
  flex: 1;
}

.history-item-date {
  font-size: 0.9rem;
  color: var(--text-primary);
}

.history-item-preview {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 300px;
}

.restore-btn {
  background: var(--accent-color);
  color: white;
  border: none;
  padding: 6px 12px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.85rem;
}

.restore-btn:hover {
  background: var(--button-hover);
}

.history-empty {
  text-align: center;
  padding: 30px;
  color: var(--text-muted);
}

/* ===== Entry Footer History Button ===== */
.history-btn {
  background: none;
  border: 1px solid var(--border-color);
  padding: 4px 8px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-left: 10px;
}

.history-btn:hover {
  background: var(--bg-sidebar);
  color: var(--text-primary);
}

/* ===== Protected Entry Badge ===== */
.protection-badge {
  margin-left: 8px;
  font-size: 0.8em;
  opacity: 0.7;
}

/* ===== Responsive Settings ===== */
@media (max-width: 500px) {
  .theme-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .settings-buttons {
    flex-direction: column;
  }

  .settings-buttons .btn {
    width: 100%;
  }
}

/* ===== Update Banner ===== */
#update-banner {
  position: fixed;
  bottom: 1rem;
  left: 50%;
  transform: translateX(-50%);
  background: var(--accent-color, #4a90d9);
  color: #fff;
  padding: 0.75rem 1rem;
  border-radius: 0.5rem;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
  display: flex;
  align-items: center;
  gap: 0.75rem;
  z-index: 1000;
  font-size: 0.9rem;
}

#update-banner button {
  background: none;
  border: none;
  color: #fff;
  cursor: pointer;
  font-size: 0.9rem;
}

#update-now-btn {
  font-weight: bold;
  text-decoration: underline;
}

#update-dismiss-btn {
  font-size: 1.2rem;
  opacity: 0.7;
}

#update-dismiss-btn:hover {
  opacity: 1;
}

/* ===== Analytics Toggle Switch ===== */
.switch {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 24px;
  vertical-align: middle;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.switch .slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: #ccc;
  transition: 0.3s;
  border-radius: 24px;
}

.switch .slider:before {
  position: absolute;
  content: "";
  height: 18px;
  width: 18px;
  left: 3px;
  bottom: 3px;
  background-color: white;
  transition: 0.3s;
  border-radius: 50%;
}

.switch input:checked + .slider {
  background-color: var(--accent-color, #4a90d9);
}

.switch input:checked + .slider:before {
  transform: translateX(20px);
}

.switch-label {
  margin-left: 10px;
  vertical-align: middle;
}

/* ===== Analytics Consent Modal ===== */
.consent-modal {
  max-width: 400px;
  text-align: center;
  padding: 2rem;
}

.consent-modal h2 {
  margin-bottom: 1rem;
}

.consent-modal p {
  margin-bottom: 1.5rem;
  color: var(--text-secondary, #666);
}

.consent-buttons {
  display: flex;
  gap: 1rem;
  justify-content: center;
}

.consent-buttons .btn {
  min-width: 120px;
}

/* ===== Tag Entry Generated List ===== */

.tag-entry-divider {
  margin: 1.5rem 0;
  border: none;
  border-top: 1px solid var(--text-secondary);
  opacity: 0.3;
}

.tag-entry-generated {
  color: var(--text-secondary);
  font-size: 0.95em;
}

.tag-entry-generated h4 {
  font-weight: 500;
  margin-bottom: 0.5rem;
  font-size: 0.9em;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.tag-entry-generated ul {
  list-style: disc;
  padding-left: 1.5rem;
  margin: 0;
}

.tag-entry-generated li {
  margin: 0.25rem 0;
}

.tag-entry-empty {
  font-style: italic;
  opacity: 0.7;
}

/* Hide generated section during editing */
.entry.editing .tag-entry-generated,
.entry.editing .tag-entry-divider {
  display: none;
}
