*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: #f7f5f0;
  --surface: #ffffff;
  --surface-2: #f0ede8;
  --border: #e5e0d8;
  --text: #1a1816;
  --text-muted: #7c7469;
  --accent: #c96a2e;
  --accent-light: #f5e6d8;
  --accent-hover: #a8561f;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.08), 0 2px 4px rgba(0,0,0,0.04);
  --shadow-lg: 0 12px 40px rgba(0,0,0,0.12);
  --radius: 12px;
  --radius-sm: 8px;
  --transition: 0.2s ease;
  --font-serif: 'Lora', Georgia, serif;
  --font-sans: 'DM Sans', system-ui, sans-serif;

  --cat-personal: #f472b6;
  --cat-study: #60a5fa;
  --cat-work: #34d399;
  --cat-ideas: #fbbf24;
}

[data-theme="dark"] {
  --bg: #131210;
  --surface: #1e1c19;
  --surface-2: #262420;
  --border: #302e2a;
  --text: #f0ede8;
  --text-muted: #8a8278;
  --accent: #e07c3a;
  --accent-light: #2a1e14;
  --accent-hover: #f08c4a;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.3);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.4);
  --shadow-lg: 0 12px 40px rgba(0,0,0,0.6);
}

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

body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  transition: background var(--transition), color var(--transition);
  -webkit-font-smoothing: antialiased;
}

.app-shell {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 28px;
  height: 60px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(12px);
  transition: background var(--transition), border-color var(--transition);
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
  min-width: 140px;
}

.logo-mark {
  width: 32px;
  height: 32px;
  background: var(--accent);
  color: white;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-serif);
  font-weight: 600;
  font-size: 16px;
}

.logo-text {
  font-family: var(--font-serif);
  font-size: 20px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.3px;
}

.topbar-center {
  flex: 1;
  max-width: 480px;
  margin: 0 auto;
}

.search-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.search-icon {
  position: absolute;
  left: 12px;
  width: 16px;
  height: 16px;
  color: var(--text-muted);
  pointer-events: none;
  transition: color var(--transition);
}

.search-input {
  width: 100%;
  padding: 8px 36px 8px 38px;
  border: 1.5px solid var(--border);
  border-radius: 24px;
  background: var(--surface-2);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 14px;
  outline: none;
  transition: border-color var(--transition), background var(--transition), box-shadow var(--transition);
}

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

.search-input:focus {
  border-color: var(--accent);
  background: var(--surface);
  box-shadow: 0 0 0 3px var(--accent-light);
}

.search-clear {
  position: absolute;
  right: 10px;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 12px;
  padding: 4px;
  border-radius: 50%;
  display: none;
  line-height: 1;
  transition: color var(--transition), background var(--transition);
}

.search-clear:hover { color: var(--text); background: var(--surface-2); }
.search-clear.visible { display: block; }

.topbar-right {
  flex-shrink: 0;
  min-width: 140px;
  display: flex;
  justify-content: flex-end;
}

.icon-btn {
  width: 36px;
  height: 36px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
  position: relative;
  overflow: hidden;
}

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

.icon-sun, .icon-moon {
  width: 16px;
  height: 16px;
  position: absolute;
  transition: opacity var(--transition), transform 0.3s ease;
}

[data-theme="light"] .icon-sun { opacity: 1; transform: scale(1); }
[data-theme="light"] .icon-moon { opacity: 0; transform: scale(0.5); }
[data-theme="dark"] .icon-sun { opacity: 0; transform: scale(0.5); }
[data-theme="dark"] .icon-moon { opacity: 1; transform: scale(1); }

.main-content {
  display: flex;
  flex: 1;
  gap: 0;
}

.sidebar {
  width: 220px;
  flex-shrink: 0;
  padding: 28px 20px;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 28px;
  transition: border-color var(--transition);
}

.sidebar-section { display: flex; flex-direction: column; gap: 8px; }

.sidebar-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  padding: 0 8px;
}

.filter-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.filter-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 400;
  color: var(--text-muted);
  cursor: pointer;
  transition: all var(--transition);
  user-select: none;
}

.filter-item:hover { background: var(--surface-2); color: var(--text); }

.filter-item.active {
  background: var(--accent-light);
  color: var(--accent);
  font-weight: 500;
}

.filter-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.sort-select {
  width: 100%;
  padding: 8px 12px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 13px;
  outline: none;
  cursor: pointer;
  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%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 30px;
  transition: border-color var(--transition), background var(--transition);
}

.sort-select:focus { border-color: var(--accent); }

.sidebar-stats {
  margin-top: auto;
  font-size: 12px;
  color: var(--text-muted);
  padding: 0 10px;
}

#totalCount { font-weight: 600; color: var(--accent); }

.notes-area {
  flex: 1;
  padding: 28px 32px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  min-width: 0;
}

.notes-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.notes-heading {
  font-family: var(--font-serif);
  font-size: 26px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.5px;
}

.page-indicator {
  font-size: 13px;
  color: var(--text-muted);
  flex-shrink: 0;
}

.notes-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
  align-content: start;
}

.note-card {
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  cursor: default;
  transition: transform 0.22s ease, box-shadow 0.22s ease, border-color 0.22s ease;
  animation: fadeUp 0.3s ease both;
  position: relative;
  overflow: hidden;
}

.note-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  border-radius: var(--radius) var(--radius) 0 0;
  opacity: 0.7;
  transition: opacity var(--transition);
}

.note-card[data-cat="personal"]::before { background: var(--cat-personal); }
.note-card[data-cat="study"]::before { background: var(--cat-study); }
.note-card[data-cat="work"]::before { background: var(--cat-work); }
.note-card[data-cat="ideas"]::before { background: var(--cat-ideas); }

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

.note-card.pinned {
  border-color: var(--accent);
  background: var(--accent-light);
}

.note-card-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}

.note-title {
  font-family: var(--font-serif);
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
  line-height: 1.3;
  word-break: break-word;
}

.note-title.untitled {
  color: var(--text-muted);
  font-style: italic;
  font-weight: 400;
}

.note-actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
  opacity: 0;
  transition: opacity var(--transition);
}

.note-card:hover .note-actions { opacity: 1; }

.note-action-btn {
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 6px;
  background: var(--surface-2);
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  transition: all var(--transition);
  line-height: 1;
}

.note-action-btn:hover { background: var(--border); color: var(--text); }
.note-action-btn.pin-btn.active { background: var(--accent-light); color: var(--accent); }
.note-action-btn.delete-btn:hover { background: #fee2e2; color: #ef4444; }

.note-content {
  font-size: 14px;
  line-height: 1.6;
  color: var(--text-muted);
  word-break: break-word;
  flex: 1;
  display: -webkit-box;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.note-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 4px;
}

.note-cat-badge {
  font-size: 11px;
  font-weight: 500;
  padding: 3px 8px;
  border-radius: 20px;
  text-transform: capitalize;
  letter-spacing: 0.02em;
}

.note-cat-badge[data-cat="personal"] { background: #fce7f3; color: #be185d; }
.note-cat-badge[data-cat="study"] { background: #dbeafe; color: #1d4ed8; }
.note-cat-badge[data-cat="work"] { background: #d1fae5; color: #065f46; }
.note-cat-badge[data-cat="ideas"] { background: #fef3c7; color: #92400e; }

[data-theme="dark"] .note-cat-badge[data-cat="personal"] { background: #3b1030; color: #f9a8d4; }
[data-theme="dark"] .note-cat-badge[data-cat="study"] { background: #1e3a5f; color: #93c5fd; }
[data-theme="dark"] .note-cat-badge[data-cat="work"] { background: #064e3b; color: #6ee7b7; }
[data-theme="dark"] .note-cat-badge[data-cat="ideas"] { background: #451a03; color: #fcd34d; }

.note-date {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
}

.pin-indicator {
  font-size: 12px;
  color: var(--accent);
  font-weight: 500;
  font-family: var(--font-sans);
}

.empty-state {
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 80px 20px;
  text-align: center;
  gap: 12px;
}

.empty-state.visible { display: flex; }

.empty-title {
  font-family: var(--font-serif);
  font-size: 20px;
  color: var(--text-muted);
}

.empty-sub { font-size: 14px; color: var(--text-muted); opacity: 0.7; }

.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 8px 0 20px;
}

.page-btn {
  padding: 8px 20px;
  border: 1.5px solid var(--border);
  border-radius: 24px;
  background: var(--surface);
  color: var(--text-muted);
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
}

.page-btn:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-light);
}

.page-btn:disabled { opacity: 0.35; cursor: default; }

.page-dots {
  display: flex;
  gap: 6px;
  align-items: center;
}

.page-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--border);
  cursor: pointer;
  transition: all var(--transition);
  border: none;
}

.page-dot.active {
  background: var(--accent);
  width: 22px;
  border-radius: 4px;
}

.page-dot:hover:not(.active) { background: var(--text-muted); }

.fab {
  position: fixed;
  bottom: 32px;
  right: 32px;
  width: 52px;
  height: 52px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 20px rgba(201, 106, 46, 0.45);
  transition: transform 0.2s ease, box-shadow 0.2s ease, background var(--transition);
  z-index: 50;
}

.fab svg { width: 22px; height: 22px; }

.fab:hover {
  transform: translateY(-2px) scale(1.05);
  box-shadow: 0 8px 28px rgba(201, 106, 46, 0.55);
  background: var(--accent-hover);
}

.fab:active { transform: scale(0.96); }

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  backdrop-filter: blur(4px);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.22s ease;
}

.modal-overlay.open {
  opacity: 1;
  pointer-events: all;
}

.modal {
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: 20px;
  width: 100%;
  max-width: 500px;
  box-shadow: var(--shadow-lg);
  transform: translateY(20px) scale(0.97);
  transition: transform 0.25s ease;
}

.modal-overlay.open .modal { transform: translateY(0) scale(1); }

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 24px 24px 0;
}

.modal-title {
  font-family: var(--font-serif);
  font-size: 22px;
  font-weight: 600;
  color: var(--text);
}

.modal-close {
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text-muted);
  font-size: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
}

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

.modal-body {
  padding: 20px 24px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.field-group { display: flex; flex-direction: column; gap: 6px; }

.field-label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
}

.optional { font-weight: 400; font-style: italic; }

.field-input, .field-textarea, .field-select {
  width: 100%;
  padding: 10px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 14px;
  outline: none;
  transition: border-color var(--transition), background var(--transition), box-shadow var(--transition);
}

.field-input::placeholder, .field-textarea::placeholder { color: var(--text-muted); }

.field-input:focus, .field-textarea:focus, .field-select:focus {
  border-color: var(--accent);
  background: var(--surface);
  box-shadow: 0 0 0 3px var(--accent-light);
}

.field-textarea {
  min-height: 130px;
  resize: vertical;
  line-height: 1.6;
}

.char-counter {
  font-size: 12px;
  color: var(--text-muted);
  text-align: right;
  margin-top: 2px;
  transition: color var(--transition);
}

.char-counter.warning { color: #f59e0b; }
.char-counter.danger { color: #ef4444; }

.select-wrap {
  position: relative;
}

.field-select {
  appearance: none;
  cursor: pointer;
  padding-right: 36px;
  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%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
}

.modal-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  padding: 16px 24px 24px;
  border-top: 1px solid var(--border);
}

.btn-ghost {
  padding: 9px 20px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  background: transparent;
  color: var(--text-muted);
  font-family: var(--font-sans);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
}

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

.btn-primary {
  padding: 9px 22px;
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: white;
  font-family: var(--font-sans);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
}

.btn-primary:hover { background: var(--accent-hover); transform: translateY(-1px); }
.btn-primary:active { transform: translateY(0); }

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

@keyframes pulse {
  0%, 100% { opacity: 0.3; transform: scale(1); }
  50% { opacity: 0.6; transform: scale(1.08); }
}

.skeleton {
  background: linear-gradient(90deg, var(--surface-2) 25%, var(--border) 50%, var(--surface-2) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
  border-radius: 6px;
}

@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.note-card.skeleton-card {
  pointer-events: none;
  gap: 12px;
}

.skel-title { height: 18px; width: 60%; }
.skel-line { height: 13px; width: 100%; }
.skel-line.short { width: 40%; }
.skel-footer { height: 20px; width: 80%; margin-top: 8px; }

@media (max-width: 900px) {
  .sidebar { width: 180px; padding: 20px 14px; }
  .notes-area { padding: 24px 20px; }
}

@media (max-width: 720px) {
  .topbar { padding: 0 16px; }
  .topbar-left { min-width: unset; }
  .topbar-right { min-width: unset; }
  .logo-text { display: none; }
  .sidebar { display: none; }
  .notes-area { padding: 20px 16px; }
  .notes-grid { grid-template-columns: 1fr; }
  .fab { bottom: 20px; right: 20px; }
}

@media (max-width: 480px) {
  .notes-heading { font-size: 20px; }
  .modal { border-radius: 16px; }
  .modal-header, .modal-body { padding-left: 18px; padding-right: 18px; }
  .modal-footer { padding-left: 18px; padding-right: 18px; }
}
