/* ===== CSS Variables & Themes ===== */
:root {
  --transition-speed: 0.2s;
  --border-radius: 8px;
  --border-radius-sm: 4px;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.1);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.15);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.2);
}

/* Dark (Default) */
[data-theme="dark"] {
  --bg-primary: #1a1a1a;
  --bg-secondary: #242424;
  --bg-tertiary: #2d2d2d;
  --bg-hover: #363636;
  --text-primary: #e4e4e4;
  --text-secondary: #a0a0a0;
  --text-muted: #666666;
  --border-color: #333333;
  --accent: #6b9fff;
  --accent-hover: #5a8fee;
  --accent-muted: rgba(107, 159, 255, 0.15);
  --tag-bg: #2d3748;
  --tag-text: #a0aec0;
  --scrollbar-bg: #2d2d2d;
  --scrollbar-thumb: #4a4a4a;
}

/* Light */
[data-theme="light"] {
  --bg-primary: #ffffff;
  --bg-secondary: #f5f5f5;
  --bg-tertiary: #ebebeb;
  --bg-hover: #e0e0e0;
  --text-primary: #1a1a1a;
  --text-secondary: #555555;
  --text-muted: #888888;
  --border-color: #dddddd;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-muted: rgba(37, 99, 235, 0.1);
  --tag-bg: #e2e8f0;
  --tag-text: #475569;
  --scrollbar-bg: #f0f0f0;
  --scrollbar-thumb: #cccccc;
}

/* Dracula */
[data-theme="dracula"] {
  --bg-primary: #282a36;
  --bg-secondary: #1e1f29;
  --bg-tertiary: #343746;
  --bg-hover: #44475a;
  --text-primary: #f8f8f2;
  --text-secondary: #bfbfbf;
  --text-muted: #6272a4;
  --border-color: #44475a;
  --accent: #bd93f9;
  --accent-hover: #caa8fc;
  --accent-muted: rgba(189, 147, 249, 0.15);
  --tag-bg: #44475a;
  --tag-text: #ff79c6;
  --scrollbar-bg: #1e1f29;
  --scrollbar-thumb: #44475a;
}

/* Nord */
[data-theme="nord"] {
  --bg-primary: #2e3440;
  --bg-secondary: #272c36;
  --bg-tertiary: #3b4252;
  --bg-hover: #434c5e;
  --text-primary: #eceff4;
  --text-secondary: #d8dee9;
  --text-muted: #7b88a1;
  --border-color: #3b4252;
  --accent: #88c0d0;
  --accent-hover: #8fbcbb;
  --accent-muted: rgba(136, 192, 208, 0.15);
  --tag-bg: #3b4252;
  --tag-text: #81a1c1;
  --scrollbar-bg: #272c36;
  --scrollbar-thumb: #434c5e;
}

/* Solarized Dark */
[data-theme="solarized-dark"] {
  --bg-primary: #002b36;
  --bg-secondary: #002028;
  --bg-tertiary: #073642;
  --bg-hover: #0a4555;
  --text-primary: #fdf6e3;
  --text-secondary: #93a1a1;
  --text-muted: #657b83;
  --border-color: #073642;
  --accent: #b58900;
  --accent-hover: #cb9a00;
  --accent-muted: rgba(181, 137, 0, 0.15);
  --tag-bg: #073642;
  --tag-text: #2aa198;
  --scrollbar-bg: #002028;
  --scrollbar-thumb: #073642;
}

/* Gruvbox Dark */
[data-theme="gruvbox-dark"] {
  --bg-primary: #282828;
  --bg-secondary: #1d2021;
  --bg-tertiary: #3c3836;
  --bg-hover: #504945;
  --text-primary: #ebdbb2;
  --text-secondary: #bdae93;
  --text-muted: #7c6f64;
  --border-color: #3c3836;
  --accent: #fe8019;
  --accent-hover: #fabd2f;
  --accent-muted: rgba(254, 128, 25, 0.15);
  --tag-bg: #3c3836;
  --tag-text: #8ec07c;
  --scrollbar-bg: #1d2021;
  --scrollbar-thumb: #504945;
}

/* Tokyo Night */
[data-theme="tokyo-night"] {
  --bg-primary: #1a1b26;
  --bg-secondary: #13141c;
  --bg-tertiary: #24283b;
  --bg-hover: #2f3549;
  --text-primary: #c0caf5;
  --text-secondary: #9aa5ce;
  --text-muted: #565f89;
  --border-color: #24283b;
  --accent: #7aa2f7;
  --accent-hover: #89b4fa;
  --accent-muted: rgba(122, 162, 247, 0.15);
  --tag-bg: #24283b;
  --tag-text: #bb9af7;
  --scrollbar-bg: #13141c;
  --scrollbar-thumb: #2f3549;
}

/* Kanagawa */
[data-theme="kanagawa"] {
  --bg-primary: #1f1f28;
  --bg-secondary: #16161d;
  --bg-tertiary: #2a2a37;
  --bg-hover: #363646;
  --text-primary: #dcd7ba;
  --text-secondary: #c8c093;
  --text-muted: #727169;
  --border-color: #2a2a37;
  --accent: #7e9cd8;
  --accent-hover: #7fb4ca;
  --accent-muted: rgba(126, 156, 216, 0.15);
  --tag-bg: #2a2a37;
  --tag-text: #957fb8;
  --scrollbar-bg: #16161d;
  --scrollbar-thumb: #363646;
}

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

html {
  font-size: 16px;
  scroll-behavior: smooth;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
  transition: background var(--transition-speed), color var(--transition-speed);
}

/* Scrollbar */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: var(--scrollbar-bg);
}

::-webkit-scrollbar-thumb {
  background: var(--scrollbar-thumb);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

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

.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.5rem;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  position: sticky;
  top: 0;
  z-index: 100;
}

.logo {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.02em;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 1rem;
}

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

/* ===== Sidebar ===== */
.sidebar {
  width: 260px;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border-color);
  padding: 1.5rem;
  overflow-y: auto;
  height: calc(100vh - 65px);
  position: sticky;
  top: 65px;
}

.sidebar-section {
  margin-bottom: 2rem;
}

.sidebar-title {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 0.75rem;
}

.category-filters {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.category-btn {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 0.75rem;
  background: transparent;
  border: none;
  border-radius: var(--border-radius-sm);
  color: var(--text-secondary);
  font-size: 0.875rem;
  cursor: pointer;
  transition: all var(--transition-speed);
  text-align: left;
}

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

.category-btn.active {
  background: var(--accent-muted);
  color: var(--accent);
}

.category-btn .count {
  font-size: 0.75rem;
  color: var(--text-muted);
  background: var(--bg-tertiary);
  padding: 0.125rem 0.5rem;
  border-radius: 10px;
}

.category-btn.active .count {
  background: var(--accent);
  color: var(--bg-primary);
}

/* Stats */
.stats {
  display: flex;
  gap: 1rem;
}

.stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  flex: 1;
  padding: 1rem;
  background: var(--bg-tertiary);
  border-radius: var(--border-radius);
}

.stat-value {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--accent);
}

.stat-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* ===== Content ===== */
.content {
  flex: 1;
  padding: 1.5rem;
  overflow-y: auto;
}

.notes-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 1rem;
}

/* ===== Note Card ===== */
.note-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius);
  padding: 1.25rem;
  cursor: pointer;
  transition: all var(--transition-speed);
}

.note-card:hover {
  border-color: var(--accent);
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}

.note-card-title {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 0.5rem;
  line-height: 1.3;
}

.note-card-preview {
  font-size: 0.875rem;
  color: var(--text-secondary);
  margin-bottom: 1rem;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.note-card-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.note-card-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.375rem;
}

.tag {
  font-size: 0.7rem;
  padding: 0.2rem 0.5rem;
  background: var(--tag-bg);
  color: var(--tag-text);
  border-radius: 4px;
  font-weight: 500;
}

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

/* ===== Search ===== */
.search-container {
  position: relative;
}

.search-input {
  width: 280px;
  padding: 0.625rem 1rem 0.625rem 2.5rem;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius);
  color: var(--text-primary);
  font-size: 0.875rem;
  transition: all var(--transition-speed);
}

.search-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-muted);
}

.search-input::placeholder {
  color: var(--text-muted);
}

.search-icon {
  position: absolute;
  left: 0.75rem;
  top: 50%;
  transform: translateY(-50%);
  width: 1rem;
  height: 1rem;
  color: var(--text-muted);
  pointer-events: none;
}

/* ===== Buttons ===== */
.icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition-speed);
}

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

.icon-btn svg {
  width: 20px;
  height: 20px;
}

/* ===== Modal ===== */
.modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
}

.modal.hidden {
  display: none;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
}

.modal-content {
  position: relative;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius);
  box-shadow: var(--shadow-lg);
  max-height: 90vh;
  overflow-y: auto;
}

.note-modal-content {
  width: 100%;
  max-width: 800px;
  padding: 2rem;
}

.settings-modal-content {
  width: 100%;
  max-width: 500px;
  padding: 1.5rem;
}

.modal-close {
  position: absolute;
  top: 1rem;
  right: 1rem;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-tertiary);
  border: none;
  border-radius: var(--border-radius-sm);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition-speed);
}

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

.modal-close svg {
  width: 18px;
  height: 18px;
}

.modal-title {
  font-size: 1.25rem;
  font-weight: 600;
  margin-bottom: 1.5rem;
  padding-right: 2rem;
}

/* ===== Settings ===== */
.settings-section {
  margin-bottom: 1.5rem;
}

.settings-label {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 0.75rem;
}

.theme-options {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.5rem;
}

.theme-btn {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem;
  background: var(--bg-tertiary);
  border: 2px solid var(--border-color);
  border-radius: var(--border-radius);
  color: var(--text-primary);
  font-size: 0.875rem;
  cursor: pointer;
  transition: all var(--transition-speed);
}

.theme-btn:hover {
  border-color: var(--text-muted);
}

.theme-btn.active {
  border-color: var(--accent);
  background: var(--accent-muted);
}

.theme-preview {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 2px solid var(--border-color);
  flex-shrink: 0;
}

/* ===== Note Full View ===== */
.note-full {
  padding-right: 2rem;
}

.note-full-header {
  margin-bottom: 1.5rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border-color);
}

.note-full-title {
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 0.75rem;
  line-height: 1.2;
}

.note-full-meta {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

.note-full-date {
  font-size: 0.875rem;
  color: var(--text-muted);
}

.note-full-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.375rem;
}

.note-full-body {
  color: var(--text-primary);
  line-height: 1.7;
}

.note-full-body h1,
.note-full-body h2,
.note-full-body h3,
.note-full-body h4,
.note-full-body h5,
.note-full-body h6 {
  margin-top: 1.5em;
  margin-bottom: 0.5em;
  font-weight: 600;
  line-height: 1.3;
}

.note-full-body h1 { font-size: 1.5rem; }
.note-full-body h2 { font-size: 1.3rem; }
.note-full-body h3 { font-size: 1.15rem; }

.note-full-body p {
  margin-bottom: 1em;
}

.note-full-body ul,
.note-full-body ol {
  margin-bottom: 1em;
  padding-left: 1.5em;
}

.note-full-body li {
  margin-bottom: 0.25em;
}

.note-full-body code {
  font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
  font-size: 0.875em;
  background: var(--bg-tertiary);
  padding: 0.2em 0.4em;
  border-radius: 4px;
}

.note-full-body pre {
  background: var(--bg-tertiary);
  padding: 1rem;
  border-radius: var(--border-radius);
  overflow-x: auto;
  margin-bottom: 1em;
}

.note-full-body pre code {
  background: none;
  padding: 0;
}

.note-full-body blockquote {
  border-left: 3px solid var(--accent);
  padding-left: 1rem;
  margin: 1em 0;
  color: var(--text-secondary);
  font-style: italic;
}

.note-full-body a {
  color: var(--accent);
  text-decoration: none;
}

.note-full-body a:hover {
  text-decoration: underline;
}

.note-full-body hr {
  border: none;
  border-top: 1px solid var(--border-color);
  margin: 2em 0;
}

.note-full-body img {
  max-width: 100%;
  border-radius: var(--border-radius);
}

.note-full-body table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 1em;
}

.note-full-body th,
.note-full-body td {
  padding: 0.5rem;
  border: 1px solid var(--border-color);
  text-align: left;
}

.note-full-body th {
  background: var(--bg-tertiary);
  font-weight: 600;
}

/* AI gathered section */
.note-full-body h2:has(+ *),
.note-full-body h3:has(+ *) {
  /* Style for AI gathered headers if needed */
}

/* ===== Empty State ===== */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 4rem 2rem;
  color: var(--text-muted);
}

.empty-state svg {
  width: 64px;
  height: 64px;
  margin-bottom: 1rem;
  opacity: 0.5;
}

.empty-state p {
  font-size: 1.1rem;
}

/* ===== Utilities ===== */
.hidden {
  display: none !important;
}

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

  .search-input {
    width: 200px;
  }
}

@media (max-width: 600px) {
  .header {
    flex-direction: column;
    gap: 1rem;
    padding: 1rem;
  }

  .header-actions {
    width: 100%;
    justify-content: space-between;
  }

  .search-input {
    flex: 1;
    width: auto;
  }

  .notes-list {
    grid-template-columns: 1fr;
  }

  .note-modal-content {
    padding: 1.5rem;
  }

  .note-full-title {
    font-size: 1.4rem;
  }

  .theme-options {
    grid-template-columns: 1fr;
  }
}
