/* ── RESET & BASE ── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
}

body {
  font-family: 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
}

/* ── DESIGN TOKENS ── */
:root {
  --bg:         #0f0f13;
  --surface:    #17171d;
  --surface2:   #1e1e26;
  --surface3:   #27272f;
  --border:     #2e2e3a;
  --border2:    #3d3d4d;
  --text:       #eeedf0;
  --muted:      #888899;
  --accent:     #7c6af7;
  --accent-lt:  #a99df9;
  --danger:     #e05555;
  --success:    #52c07a;
  --warning:    #e0a050;
  --radius:     12px;
  --radius-sm:  8px;
  --sidebar-w:  270px;
}

/* ── SCROLLBAR ── */
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 4px; }

/* ── APP LAYOUT ── */
.app {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ── SIDEBAR ── */
.sidebar {
  width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  height: 100vh;
  overflow: hidden;
}

.sidebar-header {
  padding: 24px 20px 16px;
  border-bottom: 1px solid var(--border);
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo-icon {
  font-size: 22px;
}

.logo-text {
  font-size: 18px;
  font-weight: 600;
  color: var(--accent-lt);
  letter-spacing: -0.3px;
}

.search-wrap {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
}

.search-icon {
  font-size: 13px;
  flex-shrink: 0;
}

.search-input {
  flex: 1;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 13px;
  padding: 9px 12px;
  outline: none;
  transition: border-color 0.2s;
}

.search-input:focus { border-color: var(--accent); }
.search-input::placeholder { color: var(--muted); }

.search-clear {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 13px;
  padding: 4px;
  display: none;
}

.search-clear.visible { display: block; }

.search-input {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 13px;
  padding: 9px 12px;
  outline: none;
  transition: border-color 0.2s;
}

.search-input:focus {
  border-color: var(--accent);
}

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

/* ── SIDEBAR NAV ── */
.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
}

.nav-section-label {
  font-size: 10px;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 600;
  padding: 12px 16px 4px;
}

.nav-item {
  padding: 9px 16px;
  font-size: 13.5px;
  color: var(--muted);
  cursor: pointer;
  border-left: 3px solid transparent;
  transition: all 0.15s;
  user-select: none;
}

.nav-item:hover {
  background: var(--surface2);
  color: var(--text);
}

.nav-item.active {
  background: var(--surface2);
  color: var(--accent-lt);
  border-left-color: var(--accent);
}

/*  TAG CHIPS IN SIDEBAR ── */
.tag-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 16px;
  font-size: 13px;
  color: var(--muted);
  cursor: pointer;
  transition: all 0.15s;
  user-select: none;
}

.tag-chip:hover {
  background: var(--surface2);
  color: var(--text);
}

.tag-chip.active {
  color: var(--accent-lt);
}

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

/* ── NEW NOTE BUTTON ── */
.new-note-btn {
  margin: 16px;
  padding: 11px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}

.new-note-btn:hover {
  background: var(--accent-lt);
}

.new-note-btn:active {
  transform: scale(0.97);
}

/* ── MAIN AREA ── */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 28px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
}

.topbar-title {
  font-size: 19px;
  font-weight: 600;
  color: var(--text);
}

.topbar-controls select {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--muted);
  font-size: 12.5px;
  padding: 7px 10px;
  outline: none;
  cursor: pointer;
}

/* ── NOTES GRID ── */
.notes-grid {
  flex: 1;
  overflow-y: auto;
  padding: 24px 28px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
  align-content: start;
}

/* ── NOTE CARD ── */
.note-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 10px;
  transition: border-color 0.2s, transform 0.15s;
  position: relative;
  animation: fadeUp 0.2s ease both;
}

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

.note-card:hover {
  border-color: var(--border2);
  transform: translateY(-2px);
}

.note-card.pinned {
  border-top: 3px solid var(--accent);
}

.note-color-bar {
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  border-radius: var(--radius) var(--radius) 0 0;
}

.note-card-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  word-break: break-word;
}

.note-card-body {
  font-size: 13px;
  color: var(--muted);
  line-height: 1.6;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
}

.note-card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: auto;
}

.note-card-date {
  font-size: 11px;
  color: var(--muted);
}

.note-card-tags {
  display: flex;
  gap: 5px;
  flex-wrap: wrap;
}

.note-tag-badge {
  font-size: 10.5px;
  padding: 2px 8px;
  border-radius: 20px;
  font-weight: 500;
}

.card-actions {
  display: flex;
  gap: 4px;
  position: absolute;
  top: 12px;
  right: 12px;
  opacity: 0;
  transition: opacity 0.15s;
}

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

.card-action-btn {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--muted);
  font-size: 13px;
  padding: 3px 7px;
  cursor: pointer;
  transition: color 0.15s;
}

.card-action-btn:hover       { color: var(--text); }
.card-action-btn.pin-active  { color: var(--accent-lt); }
.card-action-btn.danger:hover{ color: var(--danger); }

/* ── EMPTY STATE ── */
.empty-state {
  grid-column: 1 / -1;
  text-align: center;
  padding: 80px 20px;
  color: var(--muted);
}

.empty-state h3 {
  font-size: 18px;
  color: var(--text);
  margin-bottom: 8px;
}

.empty-state p {
  font-size: 13.5px;
}

/* ── MODALS ── */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(5, 5, 10, 0.75);
  z-index: 100;
  align-items: center;
  justify-content: center;
  padding: 20px;
  animation: fadeIn 0.2s ease;
}

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

@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.modal {
  background: var(--surface);
  border: 1px solid var(--border2);
  border-radius: 16px;
  width: 100%;
  max-width: 620px;
  max-height: 90vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  animation: modalIn 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.modal-sm {
  max-width: 380px;
  padding: 28px;
  gap: 12px;
}

.modal-sm h3 {
  font-size: 17px;
  color: var(--text);
}

.modal-sm p {
  font-size: 13.5px;
  color: var(--muted);
}

@keyframes modalIn {
  from { opacity: 0; transform: scale(0.94); }
  to   { opacity: 1; transform: scale(1); }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 22px 14px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.modal-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--accent-lt);
}

.modal-close {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 18px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
  transition: color 0.15s;
}

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

.modal-body {
  padding: 18px 22px;
  overflow-y: auto;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.modal-footer {
  padding: 14px 22px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-shrink: 0;
  gap: 10px;
}

/* ── MODAL INPUTS ── */
.note-title-input {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 15px;
  padding: 10px 14px;
  outline: none;
  transition: border-color 0.2s;
}

.note-title-input:focus { border-color: var(--accent); }
.note-title-input::placeholder { color: var(--muted); }

/* ── EDITOR TABS ── */
.editor-tabs {
  display: flex;
  gap: 6px;
}

.tab-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--muted);
  font-size: 12.5px;
  padding: 5px 14px;
  cursor: pointer;
  transition: all 0.15s;
}

.tab-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.note-content-input {
  width: 100%;
  min-height: 160px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 13.5px;
  font-family: 'Courier New', monospace;
  padding: 12px 14px;
  outline: none;
  resize: vertical;
  line-height: 1.7;
  transition: border-color 0.2s;
}

.note-content-input:focus { border-color: var(--accent); }
.note-content-input::placeholder { color: var(--muted); }

.note-preview {
  min-height: 160px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-size: 13.5px;
  line-height: 1.7;
  color: var(--text);
  overflow-y: auto;
}

.note-preview h1, .note-preview h2, .note-preview h3 {
  color: var(--accent-lt);
  margin-bottom: 8px;
}

.note-preview code {
  background: var(--surface3);
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 12.5px;
}

.note-preview pre {
  background: var(--surface3);
  padding: 12px;
  border-radius: var(--radius-sm);
  overflow-x: auto;
}

.note-preview ul, .note-preview ol {
  padding-left: 20px;
}

.note-preview a { color: var(--accent-lt); }

/* ── MODAL META ── */
.modal-meta {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.color-picker {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.color-swatch {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  cursor: pointer;
  border: 2px solid transparent;
  transition: transform 0.15s, border-color 0.15s;
}

.color-swatch:hover   { transform: scale(1.2); }
.color-swatch.selected { border-color: var(--text); }

.tag-input-wrap {
  display: flex;
  gap: 8px;
}

.tag-input-wrap input {
  flex: 1;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 13px;
  padding: 8px 12px;
  outline: none;
  transition: border-color 0.2s;
}

.tag-input-wrap input:focus { border-color: var(--accent); }
.tag-input-wrap input::placeholder { color: var(--muted); }

.tag-input-wrap button {
  background: var(--surface3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 13px;
  padding: 8px 14px;
  cursor: pointer;
  transition: background 0.15s;
}

.tag-input-wrap button:hover { background: var(--border2); }

#tagsPreview {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.tag-preview-chip {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  padding: 3px 10px;
  border-radius: 20px;
  cursor: pointer;
  font-weight: 500;
  transition: opacity 0.15s;
}

.tag-preview-chip:hover { opacity: 0.7; }

/* ── AI TOOLBAR ── */
.ai-toolbar {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.ai-btn {
  background: var(--surface2);
  border: 1px solid var(--accent);
  border-radius: var(--radius-sm);
  color: var(--accent-lt);
  font-size: 12.5px;
  padding: 7px 14px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.ai-btn:hover {
  background: var(--accent);
  color: #fff;
}

.ai-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.ai-output {
  background: var(--surface2);
  border: 1px solid var(--accent);
  border-radius: var(--radius-sm);
  padding: 14px;
  font-size: 13px;
  color: var(--text);
  line-height: 1.7;
}

/* ── BUTTONS ── */
.btn-primary {
  background: var(--accent);
  border: none;
  border-radius: var(--radius-sm);
  color: #fff;
  font-size: 13.5px;
  font-weight: 600;
  padding: 9px 20px;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}

.btn-primary:hover  { background: var(--accent-lt); }
.btn-primary:active { transform: scale(0.97); }

.btn-secondary {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--muted);
  font-size: 13.5px;
  padding: 9px 16px;
  cursor: pointer;
  transition: all 0.15s;
}

.btn-secondary:hover {
  color: var(--text);
  border-color: var(--border2);
}

.btn-danger {
  background: var(--danger);
  border: none;
  border-radius: var(--radius-sm);
  color: #fff;
  font-size: 13.5px;
  font-weight: 600;
  padding: 9px 18px;
  cursor: pointer;
  transition: opacity 0.15s;
}

.btn-danger:hover { opacity: 0.85; }

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

/* ── UTILITY ── */
.hidden { display: none !important; }
/* ── POLISH ── */

/* smooth transition on all cards */
.note-card {
  transition: border-color 0.2s, transform 0.15s, box-shadow 0.2s;
}

.note-card:hover {
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
}

/* ai button pulse animation */
.ai-btn:not(:disabled):hover {
  animation: pulse 0.6s ease;
}

@keyframes pulse {
  0%   { box-shadow: 0 0 0 0 rgba(124, 106, 247, 0.4); }
  70%  { box-shadow: 0 0 0 8px rgba(124, 106, 247, 0); }
  100% { box-shadow: 0 0 0 0 rgba(124, 106, 247, 0); }
}

/* pinned card glow */
.note-card.pinned {
  box-shadow: 0 0 0 1px var(--accent), 0 4px 16px rgba(124, 106, 247, 0.15);
}

/* modal body smooth scroll */
.modal-body {
  scroll-behavior: smooth;
}

/* tag chips hover in sidebar */
.tag-chip {
  transition: background 0.15s, color 0.15s;
}

/* note card body no markdown symbols */
.note-card-body p { margin: 0; }
.note-card-body h1,
.note-card-body h2,
.note-card-body h3 {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}