/* ============================================
   Design Tokens & Variables
   ============================================ */
:root {
  /* Colors */
  --bg-primary: #0f0f1a;
  --bg-secondary: #1a1a2e;
  --bg-card: rgba(30, 30, 50, 0.6);
  --bg-header: rgba(15, 15, 26, 0.85);
  --bg-modal: rgba(20, 20, 35, 0.95);
  --bg-input: rgba(255, 255, 255, 0.06);

  --text-primary: #f0f0f5;
  --text-secondary: #a0a0b8;
  --text-muted: #6b6b85;

  --accent: #7c5cfc;
  --accent-hover: #9178ff;
  --accent-glow: rgba(124, 92, 252, 0.3);

  --danger: #ff4d6a;
  --danger-hover: #ff6b82;

  --border: rgba(255, 255, 255, 0.08);
  --border-hover: rgba(255, 255, 255, 0.15);

  /* Shadows */
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.2);
  --shadow-md: 0 8px 30px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 16px 60px rgba(0, 0, 0, 0.4);
  --shadow-glow: 0 0 40px var(--accent-glow);

  /* Radius */
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;

  /* Transitions */
  --transition-fast: 0.15s ease;
  --transition-normal: 0.25s ease;
  --transition-smooth: 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ============================================
   Reset & Base
   ============================================ */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  font-size: 16px;
  scroll-behavior: smooth;
}

body {
  font-family: 'Inter', 'Noto Sans SC', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  overflow-x: hidden;
  line-height: 1.6;
}

/* Animated background gradient */
body::before {
  content: '';
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background:
    radial-gradient(ellipse 80% 60% at 20% 10%, rgba(124, 92, 252, 0.12) 0%, transparent 60%),
    radial-gradient(ellipse 60% 50% at 80% 80%, rgba(248, 187, 208, 0.08) 0%, transparent 60%),
    radial-gradient(ellipse 50% 40% at 50% 50%, rgba(100, 200, 255, 0.06) 0%, transparent 60%);
  pointer-events: none;
  z-index: 0;
  animation: bgShift 20s ease-in-out infinite alternate;
}

@keyframes bgShift {
  0% { opacity: 1; transform: scale(1); }
  100% { opacity: 0.8; transform: scale(1.05); }
}

/* ============================================
   Header
   ============================================ */
.app-header {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 32px;
  background: var(--bg-header);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border);
}

.header-left {
  flex: 0 0 auto;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo-icon {
  font-size: 1.6rem;
  animation: logoFloat 3s ease-in-out infinite;
}

@keyframes logoFloat {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-3px); }
}

.logo h1 {
  font-size: 1.3rem;
  font-weight: 700;
  background: linear-gradient(135deg, var(--accent), #c084fc);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: 0.5px;
}

/* Search */
.header-center {
  flex: 1;
  max-width: 420px;
  margin: 0 24px;
}

.search-box {
  position: relative;
  display: flex;
  align-items: center;
}

.search-icon {
  position: absolute;
  left: 14px;
  width: 18px;
  height: 18px;
  color: var(--text-muted);
  pointer-events: none;
  transition: color var(--transition-fast);
}

.search-box:focus-within .search-icon {
  color: var(--accent);
}

#searchInput {
  width: 100%;
  padding: 10px 40px 10px 42px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 100px;
  color: var(--text-primary);
  font-size: 0.9rem;
  font-family: inherit;
  outline: none;
  transition: all var(--transition-normal);
}

#searchInput::placeholder {
  color: var(--text-muted);
}

#searchInput:focus {
  border-color: var(--accent);
  background: rgba(255, 255, 255, 0.08);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.search-clear {
  position: absolute;
  right: 8px;
  width: 28px;
  height: 28px;
  display: none;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  border-radius: 50%;
  transition: all var(--transition-fast);
}

.search-clear:hover {
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.1);
}

.search-clear.visible {
  display: flex;
}

.search-clear svg {
  width: 14px;
  height: 14px;
}

/* Header Right */
.header-right {
  display: flex;
  align-items: center;
  gap: 16px;
  flex: 0 0 auto;
}

.note-count {
  font-size: 0.85rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.btn-add {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 20px;
  background: linear-gradient(135deg, var(--accent), #6c4ce0);
  color: white;
  border: none;
  border-radius: 100px;
  font-size: 0.9rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: all var(--transition-normal);
  box-shadow: 0 4px 15px var(--accent-glow);
}

.btn-add:hover {
  background: linear-gradient(135deg, var(--accent-hover), #7c5cfc);
  transform: translateY(-1px);
  box-shadow: 0 6px 25px var(--accent-glow);
}

.btn-add:active {
  transform: translateY(0);
}

.btn-add svg {
  width: 18px;
  height: 18px;
}

/* ============================================
   Main Content
   ============================================ */
.main-content {
  position: relative;
  z-index: 1;
  max-width: 1400px;
  margin: 0 auto;
  padding: 32px;
}

/* Empty State */
.empty-state {
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 80px 20px;
  text-align: center;
  animation: fadeInUp 0.5s ease;
}

.empty-state.visible {
  display: flex;
}

.empty-illustration {
  position: relative;
  width: 160px;
  height: 120px;
  margin-bottom: 32px;
}

.empty-note {
  position: absolute;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-sm);
}

.empty-note.n1 {
  width: 80px;
  height: 80px;
  background: #FFF9C4;
  top: 20px;
  left: 10px;
  transform: rotate(-8deg);
  animation: emptyFloat 4s ease-in-out infinite;
}

.empty-note.n2 {
  width: 70px;
  height: 70px;
  background: #BBDEFB;
  top: 10px;
  left: 60px;
  transform: rotate(5deg);
  animation: emptyFloat 4s ease-in-out 0.5s infinite;
}

.empty-note.n3 {
  width: 60px;
  height: 60px;
  background: #F8BBD0;
  top: 30px;
  left: 40px;
  transform: rotate(-3deg);
  animation: emptyFloat 4s ease-in-out 1s infinite;
}

@keyframes emptyFloat {
  0%, 100% { transform: translateY(0) rotate(var(--r, -8deg)); }
  50% { transform: translateY(-8px) rotate(var(--r, -8deg)); }
}

.empty-state h2 {
  font-size: 1.3rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 8px;
}

.empty-state p {
  font-size: 0.95rem;
  color: var(--text-muted);
  max-width: 320px;
}

/* ============================================
   Notes Grid
   ============================================ */
.notes-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 20px;
  animation: fadeInUp 0.4s ease;
}

@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Note Card */
.note-card {
  position: relative;
  border-radius: var(--radius-lg);
  padding: 20px;
  min-height: 160px;
  display: flex;
  flex-direction: column;
  cursor: pointer;
  transition: all var(--transition-smooth);
  overflow: hidden;
  animation: cardEnter 0.35s ease backwards;
}

.note-card::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: var(--radius-lg);
  background: rgba(0, 0, 0, 0.05);
  opacity: 0;
  transition: opacity var(--transition-fast);
}

.note-card:hover {
  transform: translateY(-4px) scale(1.01);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.25);
}

.note-card:hover::before {
  opacity: 1;
}

@keyframes cardEnter {
  from { opacity: 0; transform: translateY(20px) scale(0.95); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.note-card .note-title {
  font-size: 1.05rem;
  font-weight: 600;
  color: #2d2d2d;
  margin-bottom: 8px;
  line-height: 1.4;
  word-break: break-word;
}

.note-card .note-excerpt {
  font-size: 0.88rem;
  color: rgba(45, 45, 45, 0.7);
  line-height: 1.6;
  flex: 1;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 5;
  -webkit-box-orient: vertical;
  word-break: break-word;
  white-space: pre-wrap;
}

.note-card .note-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 14px;
  padding-top: 10px;
  border-top: 1px solid rgba(0, 0, 0, 0.06);
}

.note-card .note-date {
  font-size: 0.75rem;
  color: rgba(45, 45, 45, 0.45);
}

.note-card .note-actions {
  display: flex;
  gap: 4px;
  opacity: 0;
  transform: translateY(4px);
  transition: all var(--transition-fast);
}

.note-card:hover .note-actions {
  opacity: 1;
  transform: translateY(0);
}

.note-action-btn {
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.08);
  border: none;
  border-radius: var(--radius-sm);
  color: rgba(45, 45, 45, 0.6);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.note-action-btn:hover {
  background: rgba(0, 0, 0, 0.15);
  color: rgba(45, 45, 45, 0.9);
}

.note-action-btn.pinned {
  color: var(--accent);
  background: rgba(124, 92, 252, 0.15);
}

.note-action-btn svg {
  width: 15px;
  height: 15px;
}

/* Pin Badge */
.pin-badge {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent);
  opacity: 0.7;
}

.pin-badge svg {
  width: 16px;
  height: 16px;
  fill: currentColor;
}

/* ============================================
   Modal
   ============================================ */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  padding: 20px;
  animation: overlayIn 0.2s ease;
}

.modal-overlay.visible {
  display: flex;
}

@keyframes overlayIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal {
  width: 100%;
  max-width: 560px;
  background: var(--bg-modal);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  animation: modalIn 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.modal-small {
  max-width: 380px;
}

@keyframes modalIn {
  from { opacity: 0; transform: scale(0.9) translateY(20px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px 0;
}

.modal-header h2 {
  font-size: 1.1rem;
  font-weight: 600;
}

.modal-close {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: all var(--transition-fast);
}

.modal-close:hover {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text-primary);
}

.modal-close svg {
  width: 18px;
  height: 18px;
}

.modal-body {
  padding: 20px 24px;
}

.note-title-input {
  width: 100%;
  padding: 12px 16px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: 1.05rem;
  font-weight: 600;
  font-family: inherit;
  outline: none;
  transition: all var(--transition-normal);
  margin-bottom: 12px;
}

.note-title-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.note-title-input::placeholder,
.note-content-input::placeholder {
  color: var(--text-muted);
}

.note-content-input {
  width: 100%;
  padding: 12px 16px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: 0.95rem;
  font-family: inherit;
  outline: none;
  resize: vertical;
  min-height: 160px;
  line-height: 1.7;
  transition: all var(--transition-normal);
}

.note-content-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

/* Color Picker */
.color-picker {
  margin-top: 16px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.color-label {
  font-size: 0.85rem;
  color: var(--text-secondary);
  white-space: nowrap;
}

.color-options {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.color-btn {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  transition: all var(--transition-fast);
  position: relative;
}

.color-btn:hover {
  transform: scale(1.15);
}

.color-btn.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-glow);
}

/* Modal Footer */
.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 0 24px 20px;
}

.btn-primary,
.btn-secondary,
.btn-danger {
  padding: 10px 24px;
  border: none;
  border-radius: var(--radius-md);
  font-size: 0.9rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: all var(--transition-normal);
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent), #6c4ce0);
  color: white;
  box-shadow: 0 4px 15px var(--accent-glow);
}

.btn-primary:hover {
  background: linear-gradient(135deg, var(--accent-hover), #7c5cfc);
  transform: translateY(-1px);
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-secondary);
}

.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.12);
  color: var(--text-primary);
}

.btn-danger {
  background: linear-gradient(135deg, var(--danger), #e8365a);
  color: white;
}

.btn-danger:hover {
  background: linear-gradient(135deg, var(--danger-hover), var(--danger));
  transform: translateY(-1px);
}

/* ============================================
   Toast Notifications
   ============================================ */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 300;
  display: flex;
  flex-direction: column-reverse;
  gap: 8px;
}

.toast {
  padding: 12px 20px;
  background: var(--bg-modal);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: 0.88rem;
  box-shadow: var(--shadow-md);
  animation: toastIn 0.3s ease;
  display: flex;
  align-items: center;
  gap: 8px;
}

.toast.leaving {
  animation: toastOut 0.25s ease forwards;
}

.toast-icon {
  font-size: 1.1rem;
}

@keyframes toastIn {
  from { opacity: 0; transform: translateY(12px) scale(0.95); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes toastOut {
  from { opacity: 1; transform: translateY(0) scale(1); }
  to { opacity: 0; transform: translateY(12px) scale(0.95); }
}

/* ============================================
   Scrollbar
   ============================================ */
::-webkit-scrollbar {
  width: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.12);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.2);
}

/* ============================================
   Responsive
   ============================================ */
@media (max-width: 768px) {
  .app-header {
    flex-wrap: wrap;
    padding: 12px 16px;
    gap: 10px;
  }

  .header-center {
    order: 3;
    flex: 1 1 100%;
    max-width: 100%;
    margin: 0;
  }

  .header-right {
    margin-left: auto;
  }

  .note-count {
    display: none;
  }

  .btn-add span {
    display: none;
  }

  .btn-add {
    padding: 10px 14px;
  }

  .main-content {
    padding: 20px 16px;
  }

  .notes-grid {
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 14px;
  }

  .modal {
    margin: 10px;
    max-height: calc(100vh - 20px);
    overflow-y: auto;
  }
}

@media (max-width: 480px) {
  .notes-grid {
    grid-template-columns: 1fr;
  }
}
