/* -------------------------
   Variables
------------------------- */
:root {
  --primary: #6c5ce7;
  --primary-dark: #4c3acb;
  --primary-light: #8b7fee;
  --accent: #00d4ff;
  --success: #22c55e;

  --text-light: #1f2937;
  --text-dark: #f8fafc;
  --text-muted-light: #6b7280;
  --text-muted-dark: #cbd5e1;

  --bg-light: #f8fafc;
  --bg-dark: #0f172a;

  --surface-light: #ffffff;
  --surface-dark: #1e293b;

  --border-light: #e2e8f0;
  --border-dark: #334155;

  --muted-light: #9ca3af;
  --muted-dark: #94a3b8;

  /* Note colors */
  --note-yellow: #fef08a;
  --note-red: #fecaca;
  --note-green: #bbf7d0;
  --note-blue: #bfdbfe;
  --note-purple: #e9d5ff;

  /* UI */
  --radius-lg: 20px;
  --radius-md: 14px;
  --radius-sm: 10px;

  --shadow-sm: 0 4px 12px rgba(0, 0, 0, 0.08);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.12);
  --shadow-lg: 0 16px 40px rgba(0, 0, 0, 0.16);
  --shadow-xl: 0 20px 50px rgba(0, 0, 0, 0.2);

  --transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* -------------------------
   Global Reset
------------------------- */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  font-family: "Poppins", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg-dark);
  color: var(--text-dark);
  transition: background var(--transition), color var(--transition);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* -------------------------
   Layout
------------------------- */
#app {
  max-width: 1100px;
  margin: 0 auto;
  padding: 34px 22px;
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 32px;
  padding: 16px 0;
  border-bottom: 1px solid var(--border-dark);
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.logo {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  box-shadow: var(--shadow-md);
  display: grid;
  place-items: center;
  font-size: 24px;
  position: relative;
  overflow: hidden;
}

.logo::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(255,255,255,0.1), transparent);
  pointer-events: none;
}

h1 {
  font-size: 28px;
  font-weight: 800;
  letter-spacing: -0.5px;
  line-height: 1.2;
}

.subtitle {
  font-size: 13px;
  color: var(--text-muted-dark);
  font-weight: 600;
  letter-spacing: 0.3px;
  margin-top: 4px;
}

h1 span {
  background: linear-gradient(135deg, var(--primary), var(--primary-light));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

/* -------------------------
   Toolbar Section
------------------------- */
#toolbar {
  margin-bottom: 26px;
  background: linear-gradient(135deg, rgba(30, 41, 59, 0.8), rgba(15, 23, 42, 0.6));
  padding: 18px;
  border: 1px solid var(--border-dark);
  border-radius: var(--radius-md);
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 16px;
  box-shadow: var(--shadow-sm);
  backdrop-filter: blur(8px);
}

.search-wrap {
  display: flex;
  gap: 10px;
}

#sort-controls {
  display: flex;
  align-items: center;
  gap: 12px;
}

/* -------------------------
   Inputs & Buttons
------------------------- */
input,
textarea,
select {
  width: 100%;
  padding: 12px 14px;
  background: #1b1b1b;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-dark);
  color: var(--text-dark);
  transition: all var(--transition);
}

/* -------------------------
   Search Area Enhancements
------------------------- */
.search-area {
  display: flex;
  align-items: center;
  gap: 12px;
}
.search-input-wrap {
  display: flex;
  gap: 8px;
  align-items: center;
  flex: 1 1 auto;
}
.search-input-wrap input[type="search"] {
  flex: 1 1 auto;
  padding: 12px 14px;
  font-size: 15px;
  border-radius: 10px;
}
.touch-clear {
  padding: 10px 14px;
  min-width: 84px;
  border-radius: 10px;
  font-weight: 600;
}
.search-count {
  font-size: 13px;
  color: var(--muted-dark);
  min-width: 120px;
  text-align: right;
}

@media (max-width: 600px) {
  .search-count { display: none; }
}

input:focus,
textarea:focus,
select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(108, 92, 231, 0.25);
}

button {
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  border: none;
  cursor: pointer;
  font-weight: 600;
  transition: all var(--transition);
  position: relative;
  overflow: hidden;
}

button:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 16px rgba(0, 0, 0, 0.2);
}

button:active {
  transform: scale(0.96);
}

button:focus {
  outline: 3px solid rgba(108, 92, 231, 0.3);
  outline-offset: 2px;
}

button.ghost {
  background: rgba(255, 255, 255, 0.04);
  color: var(--text-dark);
  border: 1px solid var(--border-dark);
}
button.ghost:hover {
  background: rgba(108, 92, 231, 0.12);
  border-color: var(--primary);
  color: var(--primary);
  box-shadow: 0 4px 12px rgba(108, 92, 231, 0.15);
}

/* -------------------------
   Note Input Section
------------------------- */
#note-input {
  background: linear-gradient(135deg, rgba(30, 41, 59, 0.9), rgba(15, 23, 42, 0.7));
  padding: 24px;
  border: 1px solid var(--border-dark);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  display: grid;
  gap: 16px;
  backdrop-filter: blur(10px);
}

#colorPicker {
  display: flex;
  gap: 12px;
}

.color-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0);
  transition: all var(--transition-fast);
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.color-btn:hover {
  transform: scale(1.15) translateY(-2px);
  border-color: rgba(255, 255, 255, 0.2);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.3);
}

.color-btn.selected {
  border-color: rgba(255, 255, 255, 0.3);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.4);
  transform: scale(1.1);
}

.input-footer {
  display: flex;
  gap: 12px;
  justify-content: flex-end;
  align-items: center;
}

#addNoteBtn {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: white;
  box-shadow: var(--shadow-md);
  padding: 11px 20px;
  font-weight: 700;
  position: relative;
}
#addNoteBtn:hover {
  box-shadow: var(--shadow-lg);
  transform: translateY(-3px);
  background: linear-gradient(135deg, var(--primary-dark), var(--primary));
}

/* Save Draft button - friendlier, subtle in dark mode */
#saveDraftBtn {
  background: rgba(255, 255, 255, 0.04);
  color: var(--muted-dark);
  border: 1px solid rgba(255, 255, 255, 0.06);
  padding: 10px 14px;
  font-weight: 600;
  border-radius: var(--radius-sm);
}

#saveDraftBtn:hover {
  background: rgba(108, 92, 231, 0.12);
  color: var(--primary);
  border-color: var(--primary);
}

#saveDraftBtn:focus {
  outline: 3px solid rgba(108, 92, 231, 0.12);
  outline-offset: 2px;
}

.hint {
  font-size: 13px;
  color: var(--muted-dark);
}

/* -------------------------
   Notes Section
------------------------- */
.section-title {
  margin: 20px 0 14px;
  color: var(--text-muted-dark);
  font-weight: 700;
  font-size: 14px;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  opacity: 0.8;
}

.notes-grid {
  display: grid;
  gap: 18px;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
}

/* Empty Message */
.empty {
  grid-column: 1 / -1;
  text-align: center;
  padding: 60px 24px;
  color: var(--text-muted-dark);
  border-radius: var(--radius-lg);
  border: 2px dashed var(--border-dark);
  background: rgba(30, 41, 59, 0.5);
}

.empty-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.emoji {
  font-size: 48px;
  opacity: 0.5;
}

/* -------------------------
   Note Card
------------------------- */
.note-card {
  background: var(--surface-dark);
  padding: 18px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-dark);
  box-shadow: var(--shadow-sm);
  transition: all var(--transition);
  animation: fadeIn 0.25s ease-out;
  position: relative;
  overflow: hidden;
}

.note-card::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(255,255,255,0.05), transparent);
  pointer-events: none;
}

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

.note-content {
  font-size: 15px;
  font-weight: 600;
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.6;
  color: #000;
  position: relative;
  z-index: 1;
}

/* Ensure dark text on light/yellow notes */
.note-card[style*="fff6a8"],
.note-card[style*="fff8b0"],
.note-card[style*="ffff80"],
.note-card[style*="b7ffd1"],
.note-card[style*="bad8ff"] {
  color: #000;
}

.note-card[style*="fff6a8"] .note-content,
.note-card[style*="fff8b0"] .note-content,
.note-card[style*="ffff80"] .note-content,
.note-card[style*="b7ffd1"] .note-content,
.note-card[style*="bad8ff"] .note-content {
  color: #000;
}

/* Ensure light text on darker notes */
.note-card[style*="ffb3b3"],
.note-card[style*="e7bdff"] {
  color: #fff;
}

.note-card[style*="ffb3b3"] .note-content,
.note-card[style*="e7bdff"] .note-content {
  color: #fff;
}

.note-meta {
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px solid rgba(0, 0, 0, 0.08);
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: relative;
  z-index: 1;
}

.note-tag {
  background: rgba(0, 0, 0, 0.12);
  padding: 5px 12px;
  border-radius: var(--radius-full);
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.note-tag:hover {
  background: rgba(0, 0, 0, 0.2);
  transform: scale(1.05);
}

.note-timestamp {
  font-size: 11px;
  color: rgba(0, 0, 0, 0.5);
  font-weight: 500;
}

.card-actions {
  margin-top: 16px;
  display: flex;
  gap: 8px;
  position: relative;
  z-index: 1;
}

.card-actions button {
  background: rgba(0, 0, 0, 0.1);
  padding: 8px 12px;
  color: rgba(0, 0, 0, 0.7);
  border: 1px solid rgba(0, 0, 0, 0.08);
  font-size: 13px;
  font-weight: 600;
  border-radius: 8px;
  cursor: pointer;
  transition: all var(--transition-fast);
}
.card-actions button:hover {
  background: rgba(0, 0, 0, 0.15);
  border-color: rgba(0, 0, 0, 0.15);
  transform: translateY(-2px);
}

/* -------------------------
   Edit Modal (FIXED)
------------------------- */
#modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  backdrop-filter: blur(4px);
}

#modal-backdrop.show {
  display: flex;
  animation: fadeIn 0.25s ease-out;
}

#modal {
  width: 100%;
  max-width: 520px;
  margin: 0 16px;
  background: var(--surface-dark);
  padding: 24px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-dark);
  box-shadow: var(--shadow-xl);
  max-height: 80vh;
  overflow-y: auto;
  animation: slideUp 0.3s ease-out;
}

#modal header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border-dark);
}

#modal header h3 {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-dark);
}

/* Modal actions layout + Save button styling (friendly green) */
#modal .modal-actions {
  display: flex;
  gap: 12px;
  justify-content: flex-end;
  margin-top: 20px;
}

#modalSave {
  background: var(--success);
  color: #ffffff;
  box-shadow: var(--shadow-sm);
  border: none;
  padding: 11px 20px;
  font-weight: 700;
}

#modalSave:hover {
  background: #16a34a;
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}

#modalSave:focus {
  outline: 3px solid rgba(34, 197, 94, 0.18);
  outline-offset: 2px;
}

/* -------------------------
   Snackbar
------------------------- */
#snackbar {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%);
  background: linear-gradient(135deg, rgba(30, 41, 59, 0.95), rgba(15, 23, 42, 0.9));
  padding: 14px 18px;
  border: 1px solid var(--border-dark);
  border-radius: var(--radius-md);
  display: none;
  color: var(--text-dark);
  box-shadow: var(--shadow-lg);
  backdrop-filter: blur(10px);
  gap: 12px;
}

#snackbar.show {
  display: flex;
  animation: slideUp 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

#snackUndo {
  background: var(--success);
  color: white;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 700;
}

/* -------------------------
   Light Mode
------------------------- */
body.light {
  background: var(--bg-light);
  color: var(--text-light);
}

body.light #toolbar,
body.light #note-input,
body.light .note-card,
body.light #modal {
  background: var(--surface-light);
}

body.light input,
body.light textarea,
body.light select {
  background: var(--surface-light);
  border-color: var(--border-light);
  color: var(--text-light);
}

body.light .note-tag {
  background: #eef1ff;
  color: #333;
}

/* -------------------------
   Animations
------------------------- */
@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

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

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.8; }
}

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

@keyframes scaleIn {
  from {
    opacity: 0;
    transform: scale(0.95);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

/* -------------------------
   Responsive
------------------------- */
@media (max-width: 600px) {
  header {
    flex-direction: column;
    gap: 12px;
  }
  #toolbar {
    grid-template-columns: 1fr;
  }
  .notes-grid {
    grid-template-columns: 1fr;
  }
}

/* FIX: Make ghost buttons visible in Light Mode */
body.light button.ghost {
  background: #f5f5f5;
  border-color: #ccc;
  color: #333;
}

body.light button.ghost:hover {
  background: #e9e9e9;
  border-color: #999;
  color: #111;
}

/* Fix for small utility buttons like Clear + Save Draft */
body.light #resetFilter,
body.light #themeToggle {
  background: #f5f5f5;
  color: #333;
  border-color: #ccc;
}

body.light #resetFilter:hover,
body.light #themeToggle:hover {
  background: #e9e9e9;
  color: #111;
  border-color: #999;
}

/* In light mode make Save Draft an outlined primary-style button */
body.light #saveDraftBtn {
  background: transparent;
  color: var(--primary);
  border: 1px solid rgba(108, 92, 231, 0.18);
}

body.light #saveDraftBtn:hover {
  background: var(--primary);
  color: #ffffff;
  border-color: var(--primary);
}

body.light #saveDraftBtn:focus {
  outline: 3px solid rgba(76, 58, 203, 0.16);
  outline-offset: 2px;
}

/* -------------------------
   Professional Footer
------------------------- */
.footer {
  border-top: 1px solid var(--border-dark);
  padding: 24px 22px;
  margin-top: 40px;
  color: var(--muted-dark);
  font-size: 13px;
  background: linear-gradient(180deg, rgba(15, 23, 42, 0.3), transparent);
}
.footer-inner {
  max-width: 1100px;
  margin: 0 auto;
  display: flex;
  gap: 16px;
  align-items: center;
  justify-content: space-between;
}
.footer-left {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.brand-mini {
  font-weight: 800;
  font-size: 15px;
  background: linear-gradient(135deg, var(--primary), var(--primary-light));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.brand-mini span {
  background: inherit;
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}
.footer-meta {
  color: #c0c0c0;
  font-size: 12px;
  margin-top: 8px;
  font-weight: 600;
  letter-spacing: 0.3px;
  opacity: 1;
}
.footer-center {
  display: flex;
  gap: 12px;
  align-items: center;
}
.footer-link {
  color: var(--muted-dark);
  text-decoration: none;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  transition: all var(--transition-fast);
  font-weight: 500;
}
.footer-link:hover {
  background: rgba(108, 92, 231, 0.1);
  color: var(--primary);
  transform: translateY(-1px);
}
.footer-right {
  display: flex;
  gap: 14px;
  align-items: center;
}
.footer-version {
  color: var(--muted-dark);
  font-size: 12px;
  padding: 6px 10px;
  background: rgba(108, 92, 231, 0.08);
  border-radius: var(--radius-sm);
  font-weight: 600;
  letter-spacing: 0.5px;
}

@media (max-width: 720px) {
  .footer-inner {
    flex-direction: column;
    gap: 16px;
    align-items: center;
    text-align: center;
  }
  .footer-brand {
    justify-content: center;
  }
  .footer-center {
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px;
  }
  .footer-left {
    align-items: center;
  }
}
