/* ============================================================
   NoteVault — App CSS (Mobile First, Dark Theme, Evernote-like)
   ============================================================ */

:root {
  --bg-primary:     #000000;
  --bg-secondary:   #1a1a1a;
  --bg-tertiary:    #2c2c2c;
  --border-color:   #333333;
  --text-primary:   #ffffff;
  --text-secondary: #999999;
  --text-muted:     #666666;
  --accent-green:   #00CC66;
  --accent-blue:    #0066CC;
  --danger:         #CC3300;
  --warning:        #FF9900;
  --tag-bg:         #2a2a2a;
  --font-sans:      -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Segoe UI', sans-serif;
  --font-mono:      'SF Mono', 'Cascadia Code', 'Consolas', monospace;
  --radius:         8px;
  --radius-sm:      4px;
  --transition:     0.15s ease;
}

/* ── Reset & Base ─────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 16px; scroll-behavior: smooth; }

body {
  background: var(--bg-primary);
  color: var(--text-primary);
  font-family: var(--font-sans);
  line-height: 1.5;
  min-height: 100vh;
}

a { color: var(--accent-green); text-decoration: none; }
a:hover { text-decoration: underline; }

hr { border: none; border-top: 1px solid var(--border-color); margin: 1rem 0; }

/* ── Scrollbar ────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg-secondary); }
::-webkit-scrollbar-thumb { background: var(--border-color); border-radius: 3px; }

/* ── Layout ──────────────────────────────────────────────── */
.app-wrapper {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* Desktop sidebar layout */
@media (min-width: 768px) {
  .app-wrapper {
    flex-direction: row;
  }
  .sidebar {
    display: flex !important;
    width: 240px;
    min-height: 100vh;
    flex-shrink: 0;
  }
  .main-content {
    flex: 1;
    padding-bottom: 0;
  }
  .bottom-nav { display: none !important; }
}

/* ── Sidebar ─────────────────────────────────────────────── */
.sidebar {
  display: none;
  flex-direction: column;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border-color);
  padding: 0;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 16px 16px;
  border-bottom: 1px solid var(--border-color);
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-primary);
}

.sidebar-brand svg { width: 28px; height: 28px; }

.sidebar-nav { padding: 8px 0; flex: 1; }

.sidebar-section-title {
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  padding: 16px 16px 4px;
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 16px;
  color: var(--text-secondary);
  font-size: 0.875rem;
  border-radius: 0;
  transition: background var(--transition), color var(--transition);
}

.sidebar-link:hover, .sidebar-link.active {
  background: var(--bg-tertiary);
  color: var(--text-primary);
  text-decoration: none;
}

.sidebar-link.active { border-left: 3px solid var(--accent-green); }
.sidebar-link svg { width: 18px; height: 18px; flex-shrink: 0; }

.sidebar-badge {
  margin-left: auto;
  background: var(--bg-tertiary);
  color: var(--text-muted);
  font-size: 0.7rem;
  padding: 1px 6px;
  border-radius: 10px;
}

/* ── Top Header ──────────────────────────────────────────── */
.top-header {
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  position: sticky;
  top: 0;
  z-index: 100;
}

.top-header .brand-mobile {
  font-weight: 700;
  font-size: 1rem;
  color: var(--accent-green);
  flex: 1;
}

.top-header .search-btn,
.top-header .menu-btn {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 6px;
  border-radius: var(--radius-sm);
}

.top-header .search-btn:hover,
.top-header .menu-btn:hover {
  color: var(--text-primary);
  background: var(--bg-tertiary);
}

.breadcrumb-header {
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.875rem;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border-color);
}

.breadcrumb-header a { color: var(--text-secondary); }
.breadcrumb-header a:hover { color: var(--text-primary); }
.breadcrumb-header .sep { color: var(--text-muted); }
.breadcrumb-header .current { color: var(--text-primary); font-weight: 500; }

/* ── Main Content ────────────────────────────────────────── */
.main-content {
  flex: 1;
  padding-bottom: 80px; /* espaço para bottom nav */
  overflow-x: hidden;
}

.page-header {
  padding: 20px 16px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border-color);
}

.page-title {
  font-size: 1.25rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ── Bottom Navigation (Mobile) ──────────────────────────── */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border-color);
  display: flex;
  z-index: 1000;
  padding-bottom: env(safe-area-inset-bottom);
}

.bottom-nav__item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 8px 4px 6px;
  color: var(--text-muted);
  font-size: 0.65rem;
  gap: 4px;
  text-decoration: none;
  transition: color var(--transition);
  cursor: pointer;
}

.bottom-nav__item svg { width: 22px; height: 22px; }
.bottom-nav__item.active { color: var(--accent-green); }
.bottom-nav__item:hover { color: var(--text-primary); text-decoration: none; }

/* ── Buttons ─────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background var(--transition), border-color var(--transition), color var(--transition);
}

.btn-primary {
  background: var(--accent-green);
  color: #000;
  border-color: var(--accent-green);
}
.btn-primary:hover { background: #00b359; border-color: #00b359; text-decoration: none; }

.btn-secondary {
  background: var(--bg-tertiary);
  color: var(--text-primary);
  border-color: var(--border-color);
}
.btn-secondary:hover { background: #3a3a3a; text-decoration: none; }

.btn-danger {
  background: transparent;
  color: var(--danger);
  border-color: var(--danger);
}
.btn-danger:hover { background: var(--danger); color: #fff; text-decoration: none; }

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border-color: transparent;
}
.btn-ghost:hover { background: var(--bg-tertiary); color: var(--text-primary); text-decoration: none; }

.btn-sm { padding: 5px 10px; font-size: 0.8rem; }
.btn-lg { padding: 12px 24px; font-size: 1rem; }
.btn-icon { padding: 8px; border-radius: var(--radius-sm); }

/* ── Forms ───────────────────────────────────────────────── */
.form-group { margin-bottom: 16px; }

.form-label {
  display: block;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.form-control {
  width: 100%;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-size: 0.9rem;
  padding: 10px 14px;
  font-family: var(--font-sans);
  transition: border-color var(--transition);
  color-scheme: dark;
}

.form-control:focus {
  outline: none;
  border-color: var(--accent-green);
}

.form-control::placeholder { color: var(--text-muted); }

textarea.form-control { resize: vertical; min-height: 100px; }

select.form-control {
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23999' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
  cursor: pointer;
}

select.form-control option {
  background: #1a1a1a;
  color: #ffffff;
}

/* ── Custom Dropdown ─────────────────────────────────────── */
.custom-select {
  position: relative;
  display: inline-block;
}

.custom-select-trigger {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-size: 0.85rem;
  padding: 6px 10px 6px 12px;
  cursor: pointer;
  transition: border-color var(--transition), background var(--transition);
  white-space: nowrap;
  user-select: none;
  min-width: 140px;
}

.custom-select-trigger:hover {
  background: var(--bg-tertiary);
  border-color: #555;
}

.custom-select-trigger.open {
  border-color: var(--accent-green);
}

.custom-select-trigger svg { flex-shrink: 0; transition: transform 0.2s; }
.custom-select-trigger.open svg { transform: rotate(180deg); }

.custom-select-panel {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  min-width: 100%;
  max-width: 280px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(0,0,0,0.5);
  z-index: 500;
  overflow: hidden;
  display: none;
}

.custom-select-panel.open {
  display: block;
  animation: dropdownIn 0.12s ease;
}

@keyframes dropdownIn {
  from { opacity: 0; transform: translateY(-6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.custom-select-option {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  font-size: 0.85rem;
  color: var(--text-primary);
  cursor: pointer;
  transition: background var(--transition);
  border-bottom: 1px solid var(--border-color);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.custom-select-option:last-child { border-bottom: none; }
.custom-select-option:hover { background: var(--bg-tertiary); }
.custom-select-option.selected {
  background: rgba(0,204,102,0.1);
  color: var(--accent-green);
}

.custom-select-option .nb-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.custom-select-option .nb-count {
  margin-left: auto;
  font-size: 0.7rem;
  color: var(--text-muted);
}

.form-error {
  font-size: 0.8rem;
  color: var(--danger);
  margin-top: 4px;
}

/* ── Alert ───────────────────────────────────────────────── */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: 0.875rem;
  margin-bottom: 16px;
  border: 1px solid;
}

.alert-error {
  background: rgba(204, 51, 0, 0.1);
  border-color: var(--danger);
  color: #ff6644;
}

.alert-success {
  background: rgba(0, 204, 102, 0.1);
  border-color: var(--accent-green);
  color: var(--accent-green);
}

.alert-info {
  background: rgba(0, 102, 204, 0.1);
  border-color: var(--accent-blue);
  color: #4499ff;
}

/* ── Cards ───────────────────────────────────────────────── */
.card {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  overflow: hidden;
}

.card-body { padding: 16px; }

/* ── Note Card ───────────────────────────────────────────── */
.note-card {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border-color);
  cursor: pointer;
  position: relative;
  transition: background var(--transition);
  text-decoration: none;
  color: inherit;
}

.note-card:hover { background: var(--bg-secondary); text-decoration: none; color: inherit; }
.note-card.pinned { border-left: 3px solid var(--warning); }

.note-card__thumb {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-sm);
  object-fit: cover;
  flex-shrink: 0;
  background: var(--bg-tertiary);
}

.note-card__body { flex: 1; min-width: 0; }
.note-card__title {
  font-weight: 600;
  font-size: 0.9rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 4px;
}
.note-card__preview {
  font-size: 0.8rem;
  color: var(--text-muted);
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  margin-bottom: 6px;
}

.note-card__meta {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.note-card__date { font-size: 0.72rem; color: var(--text-muted); }

/* ── Notebook Card ───────────────────────────────────────── */
.notebook-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-color);
  text-decoration: none;
  color: var(--text-primary);
  transition: background var(--transition);
  min-width: 0;
}

.notebook-item:hover { background: var(--bg-secondary); text-decoration: none; color: var(--text-primary); }

.notebook-item__icon {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.notebook-item__info { flex: 1; min-width: 0; }
.notebook-item__name {
  font-weight: 500;
  font-size: 0.9rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.notebook-item__meta { font-size: 0.75rem; color: var(--text-muted); margin-top: 2px; }

.badge-count {
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  font-size: 0.72rem;
  padding: 2px 8px;
  border-radius: 10px;
  flex-shrink: 0;
}

/* ── Row Actions (substituem swipe) ─────────────────────── */
.row-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
  opacity: 0;
  transition: opacity var(--transition);
}

.list-row:hover .row-actions,
.list-row:focus-within .row-actions {
  opacity: 1;
}

/* No mobile sempre visível */
@media (max-width: 767px) {
  .row-actions { opacity: 1; }
}

.row-action-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  font-size: 0.75rem;
  white-space: nowrap;
  transition: background var(--transition), color var(--transition);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.row-action-btn:hover { background: var(--bg-tertiary); color: var(--text-primary); text-decoration: none; }
.row-action-btn.danger:hover { background: rgba(204,51,0,0.15); color: var(--danger); }
.row-action-btn.warning:hover { background: rgba(255,153,0,0.15); color: var(--warning); }

/* ── Tags ────────────────────────────────────────────────── */
.tag-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 0.72rem;
  font-weight: 500;
  background: var(--tag-bg);
  border: 1px solid var(--border-color);
}

/* ── Auth Pages ──────────────────────────────────────────── */
.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: var(--bg-primary);
}

.auth-box {
  width: 100%;
  max-width: 400px;
}

.auth-logo {
  text-align: center;
  margin-bottom: 32px;
}

.auth-logo svg { width: 48px; height: 48px; margin-bottom: 12px; }
.auth-logo h1 { font-size: 1.5rem; font-weight: 700; }
.auth-logo p { color: var(--text-muted); font-size: 0.875rem; margin-top: 4px; }

/* ── Note Editor ─────────────────────────────────────────── */
.editor-page {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.editor-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  padding: 10px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.editor-header .save-status {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-left: auto;
}

.editor-title {
  width: 100%;
  background: transparent;
  border: none;
  color: var(--text-primary);
  font-size: 1.4rem;
  font-weight: 700;
  padding: 16px 16px 8px;
  outline: none;
  font-family: var(--font-sans);
}
.editor-title::placeholder { color: var(--text-muted); }

.editor-meta {
  padding: 0 16px 12px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  border-bottom: 1px solid var(--border-color);
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.editor-toolbar {
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  padding: 6px 16px;
  display: flex;
  align-items: center;
  gap: 2px;
  flex-wrap: wrap;
  position: sticky;
  top: 57px;
  z-index: 99;
}

.toolbar-btn {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 500;
  transition: background var(--transition), color var(--transition);
  line-height: 1;
}

.toolbar-btn:hover, .toolbar-btn.active {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

.toolbar-sep {
  width: 1px;
  height: 20px;
  background: var(--border-color);
  margin: 0 4px;
}

.editor-body {
  flex: 1;
  padding: 16px;
  outline: none;
  min-height: 60vh;
  font-size: 0.95rem;
  line-height: 1.75;
  caret-color: var(--accent-green);
}

.editor-body:empty::before {
  content: attr(data-placeholder);
  color: var(--text-muted);
  pointer-events: none;
}

/* Editor content styles */
.editor-body h1 { font-size: 1.6rem; margin: 0.5em 0; }
.editor-body h2 { font-size: 1.3rem; margin: 0.5em 0; }
.editor-body h3 { font-size: 1.1rem; margin: 0.5em 0; }
.editor-body ul, .editor-body ol { padding-left: 1.5em; margin: 0.5em 0; }
.editor-body blockquote {
  border-left: 3px solid var(--accent-green);
  padding-left: 12px;
  color: var(--text-secondary);
  margin: 0.5em 0;
  font-style: italic;
}
.editor-body pre {
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 12px;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  overflow-x: auto;
  margin: 0.5em 0;
}
.editor-body code {
  background: var(--bg-tertiary);
  padding: 2px 5px;
  border-radius: 3px;
  font-family: var(--font-mono);
  font-size: 0.85em;
}
.editor-body img { max-width: 100%; border-radius: var(--radius); margin: 4px 0; }
.editor-body a { color: var(--accent-green); }
.editor-body hr { border-color: var(--border-color); }

.editor-body ul[data-checklist="true"],
.note-view__body ul[data-checklist="true"] {
  list-style: none;
  padding-left: 0;
}
.editor-body ul[data-checklist="true"] li,
.note-view__body ul[data-checklist="true"] li {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin: 5px 0;
}
.editor-body input[type="checkbox"],
.note-view__body input[type="checkbox"] {
  accent-color: var(--accent-green);
  margin-top: 5px;
}

.tasks-page { max-width: 820px; margin: 0 auto; padding: 16px; }
.task-create-card, .note-tasks {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  padding: 16px;
}
.task-date-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 12px 0; }
.task-section { margin-top: 24px; }
.task-section h2 { font-size: 0.8rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: .08em; }
.task-item { display: flex; align-items: center; gap: 10px; min-height: 54px; border-bottom: 1px solid var(--border-color); }
.task-item.completed .task-title { color: var(--text-muted); text-decoration: line-through; }
.task-check {
  width: 24px; height: 24px; border-radius: 50%; border: 2px solid var(--accent-green);
  background: transparent; color: #000; cursor: pointer; font-weight: 800; line-height: 18px;
}
.task-item.completed .task-check { background: var(--accent-green); }
.task-copy { flex: 1; min-width: 0; }
.task-title { color: var(--text-primary); overflow-wrap: anywhere; }
.task-meta { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 3px; font-size: .72rem; color: var(--text-muted); }
.task-meta a { color: var(--accent-green); }
.note-tasks { margin: 8px 16px 16px; }
.note-tasks__header { display: flex; justify-content: space-between; color: var(--text-secondary); margin-bottom: 6px; }
.note-tasks__header span { color: var(--text-muted); font-size: .75rem; }
.note-task-form { display: grid; grid-template-columns: 2fr 1fr 1fr auto; gap: 8px; margin-top: 12px; }
@media (max-width: 767px) {
  .task-date-grid, .note-task-form { grid-template-columns: 1fr; }
}

/* ── Note View ───────────────────────────────────────────── */
.note-view {
  padding: 0 0 40px;
}

.note-view__header {
  padding: 20px 16px 12px;
  border-bottom: 1px solid var(--border-color);
}

.note-view__title {
  font-size: 1.5rem;
  font-weight: 700;
  line-height: 1.3;
  margin-bottom: 12px;
}

.note-view__meta {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  font-size: 0.78rem;
  color: var(--text-muted);
}

.note-view__body {
  padding: 20px 16px;
  font-size: 0.95rem;
  line-height: 1.75;
}

.note-view__body h1 { font-size: 1.5rem; margin: 0.6em 0 0.3em; }
.note-view__body h2 { font-size: 1.25rem; margin: 0.6em 0 0.3em; }
.note-view__body h3 { font-size: 1.05rem; margin: 0.6em 0 0.3em; }
.note-view__body p { margin: 0.4em 0; }
.note-view__body ul, .note-view__body ol { padding-left: 1.5em; margin: 0.4em 0; }
.note-view__body blockquote {
  border-left: 3px solid var(--accent-green);
  padding-left: 12px;
  color: var(--text-secondary);
  margin: 0.5em 0;
  font-style: italic;
}
.note-view__body pre {
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 12px;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  overflow-x: auto;
}
.note-view__body code {
  background: var(--bg-tertiary);
  padding: 2px 5px;
  border-radius: 3px;
  font-family: var(--font-mono);
  font-size: 0.85em;
}
.note-view__body img { max-width: 100%; border-radius: var(--radius); }

/* ── Related Notes Section ───────────────────────────────── */
.relations-section {
  border-top: 1px solid var(--border-color);
  margin-top: 24px;
  padding: 20px 16px;
}

.relations-title {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 12px;
}

.relation-tabs {
  display: flex;
  gap: 0;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--border-color);
}

.relation-tab {
  padding: 8px 14px;
  font-size: 0.8rem;
  color: var(--text-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  background: none;
  border-top: none;
  border-left: none;
  border-right: none;
}

.relation-tab.active {
  color: var(--text-primary);
  border-bottom-color: var(--accent-green);
}

.relation-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border-color);
  text-decoration: none;
  color: inherit;
}

.relation-item:last-child { border-bottom: none; }
.relation-item:hover { text-decoration: none; }
.relation-item:hover .relation-item__title { color: var(--accent-green); }

.relation-item__icon {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  background: var(--bg-tertiary);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.relation-item__info { flex: 1; min-width: 0; }
.relation-item__title { font-size: 0.875rem; font-weight: 500; }
.relation-item__meta { font-size: 0.72rem; color: var(--text-muted); margin-top: 2px; }
.relation-item__score {
  font-size: 0.72rem;
  color: var(--accent-green);
  font-weight: 600;
}

/* ── Attachments ─────────────────────────────────────────── */
.attachments-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 16px;
}

.attachment-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  font-size: 0.8rem;
  cursor: pointer;
  transition: background var(--transition);
  max-width: 200px;
}

.attachment-item:hover { background: var(--bg-tertiary); }
.attachment-item__name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}

.attachment-thumb {
  width: 40px;
  height: 40px;
  object-fit: cover;
  border-radius: var(--radius-sm);
}

/* ── Search ──────────────────────────────────────────────── */
.search-header {
  padding: 16px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
}

.search-input-wrap {
  position: relative;
}

.search-input {
  width: 100%;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: 24px;
  color: var(--text-primary);
  font-size: 0.9rem;
  padding: 10px 16px 10px 42px;
  outline: none;
  transition: border-color var(--transition);
  font-family: var(--font-sans);
}

.search-input:focus { border-color: var(--accent-green); }

.search-icon {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
}

.search-result-score {
  font-size: 0.72rem;
  color: var(--accent-green);
  font-weight: 600;
}

.search-section-title {
  padding: 18px 16px 8px;
  color: var(--text-secondary);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.attachment-search-card {
  border-left: 3px solid var(--accent-green);
}

/* ── Note templates ─────────────────────────────────────── */
.templates-header {
  min-height: 82px;
  padding: 17px 20px;
  display: flex;
  align-items: center;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
}

.templates-header h1 { margin: 0; color: var(--text-primary); font-size: 1.25rem; }
.templates-header p { margin: 4px 0 0; color: var(--text-muted); font-size: 0.82rem; }
.templates-page { display: grid; grid-template-columns: minmax(270px, 360px) minmax(0, 1fr); min-height: calc(100vh - 82px); }
.template-create-panel { padding: 22px 20px 110px; background: #111; border-right: 1px solid var(--border-color); }
.template-create-panel h2, .template-library h2 { margin: 0; color: var(--text-primary); font-size: 1rem; }
.template-form { display: grid; gap: 9px; margin-top: 17px; }
.template-form label { color: var(--text-secondary); font-size: 0.76rem; font-weight: 600; }
.template-form textarea { resize: vertical; min-height: 130px; }
.template-source-note { display: flex; flex-direction: column; gap: 5px; margin-top: 14px; padding: 13px; border: 1px solid var(--border-color); border-radius: var(--radius); background: var(--bg-secondary); }
.template-source-note strong { color: var(--text-primary); }
.template-source-note span { color: var(--text-muted); font-size: 0.8rem; line-height: 1.45; }
.template-library { min-width: 0; padding: 22px 20px 110px; }
.template-library__title { display: flex; align-items: center; gap: 9px; margin-bottom: 15px; }
.template-library__title span { min-width: 24px; padding: 2px 7px; color: var(--accent-green); background: rgba(0, 204, 102, 0.12); border-radius: 20px; text-align: center; font-size: 0.75rem; }
.template-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 13px; }
.template-card { display: grid; grid-template-columns: 38px minmax(0, 1fr); gap: 11px; padding: 16px; background: var(--bg-secondary); border: 1px solid var(--border-color); border-radius: var(--radius); }
.template-card__icon { width: 38px; height: 38px; display: grid; place-items: center; border-radius: var(--radius-sm); background: rgba(0, 204, 102, 0.12); }
.template-card__copy { min-width: 0; }
.template-card__copy h3 { overflow: hidden; margin: 0; color: var(--text-primary); font-size: 0.96rem; text-overflow: ellipsis; white-space: nowrap; }
.template-card__copy strong { display: block; overflow: hidden; margin-top: 4px; color: var(--text-secondary); font-size: 0.77rem; text-overflow: ellipsis; white-space: nowrap; }
.template-card__copy p { min-height: 38px; margin: 9px 0 0; color: var(--text-muted); font-size: 0.78rem; line-height: 1.45; }
.template-card__copy small { display: block; margin-top: 8px; color: var(--accent-green); }
.template-use-form { grid-column: 1 / -1; display: flex; gap: 8px; margin-top: 4px; }
.template-use-form select { min-width: 0; flex: 1; }
.template-card > form:last-child { grid-column: 1 / -1; }
.template-delete { width: 100%; color: var(--danger); }
.template-empty { min-height: 280px; }

@media (max-width: 767.98px) {
  .templates-page { display: block; }
  .template-create-panel { padding-bottom: 24px; border-right: 0; border-bottom: 1px solid var(--border-color); }
  .template-library { padding-bottom: 110px; }
  .template-grid { grid-template-columns: 1fr; }
  .template-use-form { flex-direction: column; }
}

/* ── Trash ───────────────────────────────────────────────── */
.trash-note {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-color);
}

.trash-note__info { flex: 1; min-width: 0; }
.trash-note__title { font-size: 0.875rem; font-weight: 500; }
.trash-note__meta { font-size: 0.72rem; color: var(--text-muted); margin-top: 2px; }

/* ── Empty State ─────────────────────────────────────────── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  text-align: center;
  color: var(--text-muted);
}

.empty-state svg { width: 64px; height: 64px; opacity: 0.3; margin-bottom: 16px; }
.empty-state h3 { font-size: 1rem; font-weight: 600; color: var(--text-secondary); margin-bottom: 8px; }
.empty-state p { font-size: 0.875rem; max-width: 280px; line-height: 1.6; }

/* ── Attachment item action buttons ─────────────────────── */
.att-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 3px 5px;
  border-radius: var(--radius-sm);
  display: inline-flex;
  align-items: center;
  flex-shrink: 0;
  text-decoration: none;
  transition: background var(--transition), color var(--transition);
}
.att-btn:hover { background: var(--bg-tertiary); color: var(--text-primary); text-decoration: none; }
.att-btn-danger:hover { background: rgba(204,51,0,0.15); color: var(--danger); }

/* ── Drag over editor ────────────────────────────────────── */
.editor-body.drag-over {
  box-shadow: inset 0 0 0 2px var(--accent-green);
  background: rgba(0, 204, 102, 0.04);
}

/* ── Attachment area ─────────────────────────────────────── */
#attachments-area {
  min-height: 44px;
}

/* ── Graph Page ──────────────────────────────────────────── */
#graph-container {
  width: 100%;
  height: calc(100vh - 120px);
  background: var(--bg-primary);
}

/* ── Utilities ───────────────────────────────────────────── */
.text-muted { color: var(--text-muted); }
.text-success { color: var(--accent-green); }
.text-danger { color: var(--danger); }
.text-secondary-color { color: var(--text-secondary); }
.d-flex { display: flex; }
.align-items-center { align-items: center; }
.justify-content-between { justify-content: space-between; }
.gap-2 { gap: 8px; }
.mt-1 { margin-top: 4px; }
.mt-2 { margin-top: 8px; }
.mt-3 { margin-top: 16px; }
.mb-0 { margin-bottom: 0; }
.mb-2 { margin-bottom: 8px; }
.mb-3 { margin-bottom: 16px; }
.p-3 { padding: 16px; }
.w-100 { width: 100%; }

/* ── Spinner ─────────────────────────────────────────────── */
.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid var(--border-color);
  border-top-color: var(--accent-green);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Floating Action Button ──────────────────────────────── */
.fab {
  position: fixed;
  bottom: 80px;
  right: 20px;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--accent-green);
  color: #000;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 16px rgba(0, 204, 102, 0.4);
  cursor: pointer;
  border: none;
  font-size: 1.4rem;
  transition: transform var(--transition), box-shadow var(--transition);
  text-decoration: none;
  z-index: 500;
}

.fab:hover { transform: scale(1.08); box-shadow: 0 6px 20px rgba(0, 204, 102, 0.5); text-decoration: none; color: #000; }

@media (min-width: 768px) {
  .fab { bottom: 24px; }
}
.history-header {
  min-height: 76px;
  padding: 14px 18px;
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
}

.history-header h1 { margin: 0; font-size: 1.15rem; color: var(--text-primary); }
.history-header p { margin: 3px 0 0; color: var(--text-muted); font-size: 0.8rem; }
.history-alert { margin: 14px 18px 0; padding: 10px 14px; color: var(--accent-green); background: rgba(0, 204, 102, 0.1); border: 1px solid rgba(0, 204, 102, 0.3); border-radius: var(--radius); }
.history-layout { display: grid; grid-template-columns: minmax(250px, 320px) minmax(0, 1fr); min-height: calc(100vh - 76px); }
.history-list { border-right: 1px solid var(--border-color); background: #111; overflow-y: auto; }
.history-list__title { padding: 15px 16px; display: flex; justify-content: space-between; color: var(--text-secondary); border-bottom: 1px solid var(--border-color); }
.history-list__title span { color: var(--text-muted); }
.history-item { display: flex; flex-direction: column; gap: 4px; padding: 14px 16px; color: var(--text-secondary); text-decoration: none; border-bottom: 1px solid var(--border-color); border-left: 3px solid transparent; }
.history-item:hover, .history-item.active { background: var(--bg-secondary); border-left-color: var(--accent-green); }
.history-item strong { font-size: 0.9rem; color: var(--text-primary); }
.history-item span { color: var(--accent-green); font-size: 0.74rem; }
.history-item small { color: var(--text-muted); line-height: 1.35; }
.history-preview { min-width: 0; background: var(--bg-primary); }
.history-preview__toolbar { min-height: 68px; padding: 12px 18px; display: flex; align-items: center; justify-content: space-between; gap: 16px; border-bottom: 1px solid var(--border-color); background: var(--bg-secondary); }
.history-preview__toolbar > div:first-child { display: flex; flex-direction: column; gap: 3px; }
.history-preview__toolbar span { color: var(--text-muted); font-size: 0.75rem; }
.history-actions { display: flex; align-items: center; gap: 8px; }
.history-actions form { margin: 0; }
.history-document { max-width: 880px; margin: 0 auto; padding: 34px 28px 120px; }
.history-document h2 { margin: 0 0 24px; font-size: 1.65rem; color: var(--text-primary); }
.history-empty { padding: 20px 16px; color: var(--text-muted); font-size: 0.84rem; line-height: 1.5; }
.history-empty--large { min-height: 45vh; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; text-align: center; }
.history-empty--large strong { color: var(--text-secondary); font-size: 1rem; }

@media (max-width: 767.98px) {
  .history-layout { display: block; padding-bottom: 86px; }
  .history-list { max-height: 250px; border-right: 0; border-bottom: 1px solid var(--border-color); }
  .history-preview__toolbar { align-items: flex-start; flex-direction: column; }
  .history-actions { width: 100%; }
  .history-actions .btn, .history-actions form { flex: 1; }
  .history-actions form .btn { width: 100%; }
  .history-document { padding: 26px 18px 110px; }
}
