* {
  padding: 0;
  margin: 0;
  box-sizing: border-box;
}
html {
  font-family: "Montserrat", sans-serif;
}

#root {
  position: relative;
  min-height: 100vh;
}
body {
  --primary: #ff7a18;
  --primary-accent: #ff9337;
  --primary-soft: #fff3e8;
  --bg: #faf9f7;
  --bg-alt: #ffffff;
  --text: #222222;
  --border: #e5e1da;
  --danger: #d7263d;
  background: var(--bg);
  min-height: 100vh;
  padding: 0 16px;
  color: var(--text);
  transition: background-color 0.3s ease, color 0.3s ease;
}

body.dark {
  --bg: #1f1f1f;
  --bg-alt: #2a2a2a;
  --text: #e9e9e9;
  --border: #3a3a3a;
  background: var(--bg);
}

body.dark form.create-note input,
body.dark form.create-note textarea,
body.dark .note-edit-title,
body.dark .note-edit-content {
  background: var(--bg-alt);
  color: var(--text);
}

header {
  background-color: var(--primary);
  margin: auto -16px;
  padding: 16px 32px;
  box-shadow: 0 0 10px 0 rgba(0, 0, 0, 0.3);
}

header h1 {
  color: #fff;
  font-family: "McLaren", cursive;
  font-weight: 200;
}
/* Header action buttons */
.header-btn {
  background: #ffffff22;
  border: 1px solid #ffffff44;
  color: #fff;
  padding: 6px 16px;
  border-radius: 24px;
  cursor: pointer;
  font-weight: 600;
  letter-spacing: 0.5px;
  font-size: 0.7rem;
  backdrop-filter: blur(2px);
  transition: background-color 0.25s, border-color 0.25s, color 0.25s,
    box-shadow 0.25s;
}
.header-btn:hover {
  background: #ffffff33;
  border-color: #ffffff66;
  box-shadow: 0 2px 6px -2px rgba(0, 0, 0, 0.35);
}
.header-btn:active {
  background: #ffffff28;
  box-shadow: 0 1px 3px -1px rgba(0, 0, 0, 0.45) inset;
}

.header-theme-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
}
.header-theme-toggle .theme-toggle {
  background: #ffffff22;
  border: 1px solid #ffffff44;
  padding: 4px 10px;
  border-radius: 24px;
  transition: background-color 0.25s, border-color 0.25s, color 0.25s;
}
.header-theme-toggle .theme-toggle:hover {
  background: #ffffff33;
  border-color: #ffffff66;
}
.header-theme-toggle .theme-toggle span {
  font-size: 1rem;
}
.header-theme-toggle input {
  display: none;
}
/* New icon toggle button */
.theme-toggle-btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 46px;
  height: 100%; /* match header button height */
  background: #ffffff22;
  border: 1px solid #ffffff44;
  color: #fff;
  border-radius: 24px;
  cursor: pointer;
  overflow: hidden;
  transition: background-color 0.3s, border-color 0.3s, box-shadow 0.3s;
  padding: 0; /* remove default */
}
.header-actions {
  align-items: center;
  display: flex;
  gap: 12px;
}
.header-actions .header-btn,
.header-actions .theme-toggle-btn {
  height: 35px;
}

.theme-toggle-btn:hover {
  background: #ffffff33;
  border-color: #ffffff66;
}
.theme-toggle-btn:active {
  background: #ffffff28;
}
.theme-toggle-btn:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 2px;
}
.theme-toggle-btn .icon-wrapper {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transform: scale(0.6) rotate(-20deg);
  transition: opacity 0.4s, transform 0.5s;
}
.theme-toggle-btn .icon-wrapper.visible {
  opacity: 1;
  transform: scale(1) rotate(0);
}
.theme-toggle-btn .icon-wrapper.hidden {
  opacity: 0;
}
.theme-toggle-focus-ring {
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
  box-shadow: 0 0 0 0 rgba(255, 255, 255, 0.4);
  transition: box-shadow 0.4s;
}
.theme-toggle-btn:active .theme-toggle-focus-ring {
  box-shadow: 0 0 0 6px rgba(255, 255, 255, 0.15);
}
body.dark .theme-toggle-btn {
  background: #ffffff22;
  border-color: #ffffff34;
}
body.dark .theme-toggle-btn:hover {
  background: #ffffff33;
  border-color: #ffffff66;
}

footer {
  position: absolute;
  text-align: center;
  bottom: 24px;
  width: 100%;
  height: fit-content;
}

footer p {
  color: #ccc;
}
.notes-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 20px;
  margin: 30px auto 0;
  padding-bottom: 200px;
  max-width: 1200px;
}

.note {
  background: var(--bg-alt);
  border-radius: 12px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  padding: 12px 48px 12px 16px;
  position: relative;
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
  transition: transform 0.15s, box-shadow 0.2s, background-color 0.3s,
    color 0.3s, border-color 0.3s;
  overflow: hidden; /* evita scrollbar di default nel contenitore nota */
}
.note.note-editing {
  box-shadow: 0 4px 22px -4px rgba(0, 0, 0, 0.35),
    0 0 0 2px var(--accent-soft, rgba(0, 0, 0, 0.05));
  border-color: var(--accent, var(--primary));
  animation: notePulse 0.4s ease;
}
@keyframes notePulse {
  0% {
    transform: scale(0.985);
  }
  100% {
    transform: scale(1);
  }
}
.note:hover {
  transform: translateY(-3px);
  box-shadow: 0 4px 18px -4px rgba(0, 0, 0, 0.18);
}
.note-archived {
  opacity: 0.72;
  filter: grayscale(0.2) saturate(0.6);
  position: relative;
}
.note-archived:before {
  content: attr(data-archived-label, "ARCHIVED");
  position: absolute;
  top: 13px;
  right: 48px;
  background: var(--accent, var(--primary));
  color: #fff;
  font-size: 0.55rem;
  letter-spacing: 1px;
  padding: 3px 8px;
  border-radius: 4px;
}
.note h1 {
  font-size: 1.1em;
  margin-bottom: 6px;
  color: inherit;
  overflow-y: auto;
  overflow-x: hidden;
  max-height: 4.5em; /* ~4 lines */
  padding-right: 2px; /* space for custom scrollbar */
  word-break: break-word; /* legacy */
  overflow-wrap: anywhere; /* modern */
  /* fallback for very old browsers */
  word-wrap: break-word;
}
.note p {
  font-size: 1.1em;
  margin-bottom: 10px;
  white-space: pre-wrap;
  word-wrap: break-word;
  color: inherit;
  overflow-y: auto;
  max-height: 150px;
}
/* Custom scrollbars for note title + content (WebKit) */
.note p::-webkit-scrollbar,
.note h1::-webkit-scrollbar {
  width: 8px;
}
.note p::-webkit-scrollbar-track,
.note h1::-webkit-scrollbar-track {
  background: transparent;
}
.note p::-webkit-scrollbar-thumb,
.note h1::-webkit-scrollbar-thumb {
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.18);
}
/* Hide default scrollbar arrows for consistency */
.note p::-webkit-scrollbar-button,
.note-edit-content::-webkit-scrollbar-button,
.note-edit-title::-webkit-scrollbar-button {
  display: none;
  width: 0;
  height: 0;
}
/* Edit mode scrollbars (title + content) */
.note-edit-content::-webkit-scrollbar,
.note-edit-title::-webkit-scrollbar {
  width: 8px;
  height: 8px; /* horizontal for title input */
}
.note-edit-content::-webkit-scrollbar-track,
.note-edit-title::-webkit-scrollbar-track {
  background: transparent;
}
.note-edit-content::-webkit-scrollbar-thumb,
.note-edit-title::-webkit-scrollbar-thumb {
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.18);
}
.note[data-accent] .note-edit-content::-webkit-scrollbar-thumb,
.note[data-accent] .note-edit-title::-webkit-scrollbar-thumb {
  background: var(--accent) !important;
}
/* Ensure horizontal dimension matches when horizontal appears */
.note-edit-title::-webkit-scrollbar {
  height: 8px;
}
/* Accent mapping per data-accent (fallback generic rule above) */
.note[data-accent="#ff7a18"] p::-webkit-scrollbar-thumb,
.note[data-accent="#ff7a18"] h1::-webkit-scrollbar-thumb {
  background: #ff7a18cc;
}
.note[data-accent="#e6a400"] p::-webkit-scrollbar-thumb,
.note[data-accent="#e6a400"] h1::-webkit-scrollbar-thumb {
  background: #e6a400cc;
}
.note[data-accent="#d44333"] p::-webkit-scrollbar-thumb,
.note[data-accent="#d44333"] h1::-webkit-scrollbar-thumb {
  background: #d44333cc;
}
.note[data-accent="#d63a8a"] p::-webkit-scrollbar-thumb,
.note[data-accent="#d63a8a"] h1::-webkit-scrollbar-thumb {
  background: #d63a8acc;
}
.note[data-accent="#8644d8"] p::-webkit-scrollbar-thumb,
.note[data-accent="#8644d8"] h1::-webkit-scrollbar-thumb {
  background: #8644d8cc;
}
.note[data-accent="#2086d7"] p::-webkit-scrollbar-thumb,
.note[data-accent="#2086d7"] h1::-webkit-scrollbar-thumb {
  background: #2086d7cc;
}
.note[data-accent="#079b8d"] p::-webkit-scrollbar-thumb,
.note[data-accent="#079b8d"] h1::-webkit-scrollbar-thumb {
  background: #079b8dcc;
}
.note[data-accent="#249d4d"] p::-webkit-scrollbar-thumb,
.note[data-accent="#249d4d"] h1::-webkit-scrollbar-thumb {
  background: #249d4dcc;
}
.note[data-accent="#54616d"] p::-webkit-scrollbar-thumb,
.note[data-accent="#54616d"] h1::-webkit-scrollbar-thumb {
  background: #54616dcc;
}
.note[data-accent="#303030ff"] p::-webkit-scrollbar-thumb,
.note[data-accent="#303030ff"] h1::-webkit-scrollbar-thumb {
  background: #5a5a5acc;
}
/* Edit mode accent mapping (WebKit) */
.note[data-accent="#ff7a18"] .note-edit-content::-webkit-scrollbar-thumb,
.note[data-accent="#ff7a18"] .note-edit-title::-webkit-scrollbar-thumb {
  background: #ff7a18cc;
}
.note[data-accent="#e6a400"] .note-edit-content::-webkit-scrollbar-thumb,
.note[data-accent="#e6a400"] .note-edit-title::-webkit-scrollbar-thumb {
  background: #e6a400cc;
}
.note[data-accent="#d44333"] .note-edit-content::-webkit-scrollbar-thumb,
.note[data-accent="#d44333"] .note-edit-title::-webkit-scrollbar-thumb {
  background: #d44333cc;
}
.note[data-accent="#d63a8a"] .note-edit-content::-webkit-scrollbar-thumb,
.note[data-accent="#d63a8a"] .note-edit-title::-webkit-scrollbar-thumb {
  background: #d63a8acc;
}
.note[data-accent="#8644d8"] .note-edit-content::-webkit-scrollbar-thumb,
.note[data-accent="#8644d8"] .note-edit-title::-webkit-scrollbar-thumb {
  background: #8644d8cc;
}
.note[data-accent="#2086d7"] .note-edit-content::-webkit-scrollbar-thumb,
.note[data-accent="#2086d7"] .note-edit-title::-webkit-scrollbar-thumb {
  background: #2086d7cc;
}
.note[data-accent="#079b8d"] .note-edit-content::-webkit-scrollbar-thumb,
.note[data-accent="#079b8d"] .note-edit-title::-webkit-scrollbar-thumb {
  background: #079b8dcc;
}
.note[data-accent="#249d4d"] .note-edit-content::-webkit-scrollbar-thumb,
.note[data-accent="#249d4d"] .note-edit-title::-webkit-scrollbar-thumb {
  background: #249d4dcc;
}
.note[data-accent="#54616d"] .note-edit-content::-webkit-scrollbar-thumb,
.note[data-accent="#54616d"] .note-edit-title::-webkit-scrollbar-thumb {
  background: #54616dcc;
}
.note[data-accent="#303030ff"] .note-edit-content::-webkit-scrollbar-thumb,
.note[data-accent="#303030ff"] .note-edit-title::-webkit-scrollbar-thumb {
  background: #5a5a5acc;
}

/* Firefox */
.note p,
.note h1 {
  scrollbar-width: thin;
  scrollbar-color: rgba(0, 0, 0, 0.3) transparent;
}
.note[data-accent="#ff7a18"] p,
.note[data-accent="#ff7a18"] h1 {
  scrollbar-color: #ff7a18cc transparent;
}
.note[data-accent="#e6a400"] p,
.note[data-accent="#e6a400"] h1 {
  scrollbar-color: #e6a400cc transparent;
}
.note[data-accent="#d44333"] p,
.note[data-accent="#d44333"] h1 {
  scrollbar-color: #d44333cc transparent;
}
.note[data-accent="#d63a8a"] p,
.note[data-accent="#d63a8a"] h1 {
  scrollbar-color: #d63a8acc transparent;
}
.note[data-accent="#8644d8"] p,
.note[data-accent="#8644d8"] h1 {
  scrollbar-color: #8644d8cc transparent;
}
.note[data-accent="#2086d7"] p,
.note[data-accent="#2086d7"] h1 {
  scrollbar-color: #2086d7cc transparent;
}
.note[data-accent="#079b8d"] p,
.note[data-accent="#079b8d"] h1 {
  scrollbar-color: #079b8dcc transparent;
}
.note[data-accent="#249d4d"] p,
.note[data-accent="#249d4d"] h1 {
  scrollbar-color: #249d4dcc transparent;
}
.note[data-accent="#54616d"] p,
.note[data-accent="#54616d"] h1 {
  scrollbar-color: #54616dcc transparent;
}
.note[data-accent="#303030ff"] p,
.note[data-accent="#303030ff"] h1 {
  scrollbar-color: #5a5a5acc transparent;
}
/* Edit mode (Firefox) */
.note-edit-content,
.note-edit-title {
  scrollbar-width: thin;
  scrollbar-color: rgba(0, 0, 0, 0.3) transparent;
}
.note[data-accent="#ff7a18"] .note-edit-content,
.note[data-accent="#ff7a18"] .note-edit-title {
  scrollbar-color: #ff7a18cc transparent;
}
.note[data-accent="#e6a400"] .note-edit-content,
.note[data-accent="#e6a400"] .note-edit-title {
  scrollbar-color: #e6a400cc transparent;
}
.note[data-accent="#d44333"] .note-edit-content,
.note[data-accent="#d44333"] .note-edit-title {
  scrollbar-color: #d44333cc transparent;
}
.note[data-accent="#d63a8a"] .note-edit-content,
.note[data-accent="#d63a8a"] .note-edit-title {
  scrollbar-color: #d63a8acc transparent;
}
.note[data-accent="#8644d8"] .note-edit-content,
.note[data-accent="#8644d8"] .note-edit-title {
  scrollbar-color: #8644d8cc transparent;
}
.note[data-accent="#2086d7"] .note-edit-content,
.note[data-accent="#2086d7"] .note-edit-title {
  scrollbar-color: #2086d7cc transparent;
}
.note[data-accent="#079b8d"] .note-edit-content,
.note[data-accent="#079b8d"] .note-edit-title {
  scrollbar-color: #079b8dcc transparent;
}
.note[data-accent="#249d4d"] .note-edit-content,
.note[data-accent="#249d4d"] .note-edit-title {
  scrollbar-color: #249d4dcc transparent;
}
.note[data-accent="#54616d"] .note-edit-content,
.note[data-accent="#54616d"] .note-edit-title {
  scrollbar-color: #54616dcc transparent;
}
.note[data-accent="#303030ff"] .note-edit-content,
.note[data-accent="#303030ff"] .note-edit-title {
  scrollbar-color: #5a5a5acc transparent;
}
/* Forza colore accent su Firefox (fallback uniforme) */
.note[data-accent] .note-edit-content,
.note[data-accent] .note-edit-title {
  scrollbar-color: var(--accent) transparent;
}

.note-actions {
  margin-top: auto;
}
.note-edit-title,
.note-edit-content {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 8px;
  font-family: inherit;
  background: var(--bg-alt);
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.04);
  transition: background-color 0.3s, color 0.3s, border-color 0.3s,
    box-shadow 0.2s;
}
.note-edit-title {
  font-size: 1.05em;
  font-weight: 600;
}
.note-edit-content {
  resize: vertical;
  min-height: 90px;
}
.note-edit-title:focus,
.note-edit-content:focus {
  border-color: var(--accent, var(--primary));
  box-shadow: 0 0 0 2px var(--accent-soft, rgba(0, 0, 0, 0.08));
}
body.dark .note-edit-title,
body.dark .note-edit-content {
  background: #262626;
}
body.dark .note-edit-title:focus,
body.dark .note-edit-content:focus {
  background: #2c2c2c;
}

/* Edit mode color button */
.note-color-btn {
  position: relative;
  align-self: flex-start;
  background: var(--accent-soft, var(--primary-soft));
  color: var(--accent, var(--primary));
  border: 1px solid var(--accent, var(--primary));
  padding: 4px 14px 5px;
  border-radius: 22px;
  font-size: 0.65rem;
  letter-spacing: 0.5px;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.25s, color 0.25s, transform 0.15s,
    box-shadow 0.25s;
}
.note-color-btn:hover {
  background: var(--accent, var(--primary));
  color: #fff;
  transform: translateY(-2px);
  box-shadow: 0 4px 14px -4px var(--accent, var(--primary));
}
.note-color-wrapper {
  position: relative;
  display: inline-block;
}
.note-color-btn:active {
  transform: translateY(0);
  box-shadow: 0 2px 8px -2px var(--accent, var(--primary));
}
body.dark .note-color-btn {
  background: #303030;
  color: var(--accent, var(--primary));
}
body.dark .note-color-btn:hover {
  background: var(--accent, var(--primary));
  color: #fff;
}

/* Refined color pop inside editing note */
.note-color-pop {
  background: var(--bg-alt);
  border: 1px solid var(--accent, var(--primary));
  padding: 14px 16px 16px;
  border-radius: 18px;
  grid-template-columns: repeat(10, 30px);
  gap: 8px;
  box-shadow: 0 10px 32px -8px rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(6px);
}
.note-color-pop .color-pop-swatch {
  border-radius: 8px;
  position: relative;
  outline: none;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25), 0 0 0 1px #00000015;
  transition: transform 0.15s, box-shadow 0.25s, outline-color 0.25s;
}
.note-color-pop .color-pop-swatch:hover {
  transform: translateY(-4px);
  box-shadow: 0 4px 12px -3px rgba(0, 0, 0, 0.4), 0 0 0 1px #00000022;
}
.note-color-pop .color-pop-swatch.active {
  outline: 2px solid #fff;
  box-shadow: 0 0 0 3px var(--accent, var(--primary)),
    0 1px 4px rgba(0, 0, 0, 0.5);
}
body.dark .note-color-pop {
  background: #262626;
}
body.dark .note-color-pop .color-pop-swatch {
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.5), 0 0 0 1px #00000055;
}
body.dark .note-color-pop .color-pop-swatch:hover {
  box-shadow: 0 4px 12px -3px rgba(0, 0, 0, 0.7), 0 0 0 1px #000000aa;
}

form.create-note {
  position: relative;
  width: 100%;
  max-width: 640px;
  margin: 30px auto 10px auto;
  background: var(--bg-alt);
  padding: 18px 18px 26px;
  border-radius: 14px;
  box-shadow: 0 3px 10px -2px rgba(0, 0, 0, 0.18);
  border: 1px solid var(--border);
  transition: background-color 0.3s, color 0.3s, border-color 0.3s;
}
form.create-note input,
form.create-note textarea {
  width: 100%;
  border: none;
  padding: 4px;
  outline: none;
  font-size: 1.2em;
  font-family: inherit;
  resize: none;
  background: var(--bg-alt);
  color: var(--text);
  transition: background-color 0.3s, color 0.3s, border-color 0.3s;
}
/* rimosso posizionamento assoluto del pulsante principale */

/* Color picker + tags in create area */
.color-picker-wrapper {
  position: relative;
  display: inline-block;
  margin-top: 8px;
}
.color-picker-trigger {
  border: 1px solid var(--border);
  padding: 6px 14px;
  border-radius: 24px;
  font-size: 0.7rem;
  letter-spacing: 0.5px;
  font-weight: 600;
  cursor: pointer;
  background: var(--bg-alt);
  box-shadow: 0 2px 6px -2px rgba(0, 0, 0, 0.25);
  transition: background-color 0.3s, color 0.3s, border-color 0.3s;
}
.color-picker-trigger:hover {
  background: var(--primary-soft);
  color: var(--primary);
}
body.dark .color-picker-trigger {
  color: #fff;
}
body.dark .color-picker-trigger:hover {
  background: #3a3a3a;
  color: #fff;
}
.color-pop {
  position: absolute;
  top: 100%;
  left: 0;
  margin-top: 6px;
  background: var(--bg-alt);
  border: 1px solid var(--border);
  padding: 10px 12px;
  border-radius: 14px;
  display: grid;
  grid-template-columns: repeat(5, 32px);
  gap: 10px;
  box-shadow: 0 8px 28px -6px rgba(0, 0, 0, 0.3);
  z-index: 10;
}
.color-pop-swatch {
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  position: relative;
  outline: 2px solid transparent;
  outline-offset: 2px;
  transition: transform 0.15s, outline-color 0.25s;
}
.color-pop-swatch:hover {
  transform: translateY(-3px);
}
.color-pop-swatch.active {
  outline-color: var(--primary-accent);
  box-shadow: 0 0 0 2px #fff inset;
}
.color-dot {
  display: inline-block;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  margin-right: 6px;
  box-shadow: 0 0 0 2px #fff, 0 0 0 3px rgba(0, 0, 0, 0.15);
  vertical-align: middle;
}
.create-note-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
  margin-top: 10px;
}
.add-btn {
  margin-left: auto;
}
.tags-input {
  font-size: 0.85em;
  margin-top: 4px;
  border: 1px solid var(--border);
  padding: 6px 8px;
  border-radius: 8px;
  background: var(--bg-alt);
  transition: background-color 0.3s, color 0.3s, border-color 0.3s;
}
body.dark .tags-input {
  background: var(--bg-alt);
}

svg {
  fill: rgb(255 255 255 / 92%) !important;
}

.tag-pill {
  background: var(--primary);
  color: #fff;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 0.6rem;
  letter-spacing: 0.5px;
}
.tags-row {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.select {
  background: var(--bg-alt);
  border: 1px solid var(--border);
  padding: 8px 12px;
  padding-right: 38px; /* space for arrow */
  border-radius: 8px;
  font-family: inherit;
  cursor: pointer;
  transition: background-color 0.3s, color 0.3s, border-color 0.3s;
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--text) 50%),
    linear-gradient(135deg, var(--text) 50%, transparent 50%);
  background-position: calc(100% - 22px) 55%, calc(100% - 14px) 55%;
  background-size: 7px 7px, 7px 7px;
  background-repeat: no-repeat;
  font-size: 0.85rem;
}
.select:focus {
  outline: 2px solid var(--primary-accent);
}

/* Custom dropdown component */
.dropdown {
  position: relative;
}
.dropdown-trigger {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 150px;
  position: relative;
  background-image: none !important; /* remove native arrow */
  padding-right: 30px; /* room for custom arrow */
}
.dropdown-trigger .dropdown-arrow {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  transition: transform 0.25s ease;
  transform-origin: center;
  pointer-events: none;
  width: 18px;
  height: 12px;
  font-size: 0; /* nasconde il carattere ▾ */
  background-image: linear-gradient(45deg, transparent 50%, currentColor 50%),
    linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position: 2px 58%, 10px 58%;
  background-size: 7px 7px, 7px 7px;
  background-repeat: no-repeat;
}
.dropdown.open .dropdown-trigger .dropdown-arrow {
  transform: translateY(-50%) rotate(180deg);
}
.dropdown.open .dropdown-trigger {
  border-color: var(--primary-accent);
  box-shadow: 0 0 0 2px var(--primary-soft);
}
.dropdown-menu {
  position: absolute;
  top: 100%;
  left: 0;
  margin-top: 6px;
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 10px 28px -6px rgba(0, 0, 0, 0.35);
  padding: 6px;
  display: flex;
  flex-direction: column;
  min-width: 100%;
  max-height: 260px;
  overflow: auto;
  z-index: 20;
}
.dropdown-option {
  text-align: left;
  background: transparent;
  border: none;
  padding: 8px 12px;
  border-radius: 10px;
  font-size: 0.8rem;
  cursor: pointer;
  color: var(--text);
  transition: background 0.2s, color 0.2s;
}
.dropdown-option:hover,
.dropdown-option:focus {
  background: var(--primary-soft);
  color: var(--primary);
  outline: none;
}
.dropdown-option.selected {
  background: var(--primary-accent);
  color: #fff;
}
body.dark .dropdown-menu {
  background: #262626;
  border-color: #444;
}
body.dark .dropdown-option:hover,
body.dark .dropdown-option:focus {
  background: #333;
  color: #fff;
}
body.dark .dropdown-option.selected {
  background: var(--primary);
  color: #fff;
}

.bulk-bar {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-top: 10px;
  flex-wrap: wrap;
  font-size: 0.85rem;
}

.note-select {
  position: absolute;
  top: 12px;
  right: 16px;
}
.note-select input {
  width: 18px;
  height: 18px;
  cursor: pointer;
}
.note-checkbox {
  -webkit-appearance: none;
  appearance: none;
  display: inline-block;
  width: 18px;
  height: 18px;
  border: 2px solid var(--chk-border, var(--primary));
  border-radius: 4px;
  position: relative;
  background: transparent;
  transition: background 0.2s, border-color 0.2s, box-shadow 0.2s,
    outline-color 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
}
.note-checkbox:hover {
  box-shadow: 0 0 0 3px rgba(0, 0, 0, 0.08);
}
.note-checkbox:focus-visible {
  outline: 2px solid var(--chk-border, var(--primary));
  outline-offset: 2px;
}
.note-checkbox:checked {
  background: var(--chk-fill, var(--primary));
  border-color: var(--chk-fill, var(--primary));
}
.note-checkbox:checked:after {
  content: "";
  position: absolute;
  width: 5px; /* smaller tick for inner padding */
  height: 8px;
  border: 2px solid #fff;
  border-top: 0;
  border-left: 0;
  transform: translate(-50%, -50%) rotate(45deg);
  left: 52%;
  top: 40%;
}
.note-checkbox:focus-visible,
.note-checkbox:checked:focus-visible {
  outline: 2px solid var(--chk-fill, var(--chk-border, var(--primary)));
  outline-offset: 2px;
}
.note-checkbox:focus {
  /* override global input:focus rule */
  outline: 2px solid var(--chk-fill, var(--chk-border, var(--primary)));
  outline-offset: 2px;
}
.note-checkbox:not(:checked):active {
  background: var(--chk-border, var(--primary));
  opacity: 0.15;
}

/* Toolbar / search / buttons */
.toolbar {
  max-width: 1200px;
  margin: 0 auto;
}
.toolbar-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
  margin-top: 24px;
}
.search-bar {
  flex: 1;
  min-width: 180px;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 30px;
  font-size: 0.95rem;
  background: var(--bg-alt);
  transition: background-color 0.3s, color 0.3s, border-color 0.3s;
}
.stats {
  display: flex;
  gap: 16px;
  font-size: 0.8rem;
  margin-top: 8px;
  color: #666;
}
.btn-secondary {
  background: var(--bg-alt);
  border: 1px solid var(--border);
  padding: 8px 16px;
  border-radius: 30px;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.2s, color 0.2s, box-shadow 0.2s;
  -webkit-tap-highlight-color: transparent;
  font-size: 0.8rem;
}
.btn-secondary:hover {
  background: var(--primary-accent);
  color: #fff;
  box-shadow: 0 2px 6px -1px rgba(0, 0, 0, 0.25);
}
.btn-secondary.active {
  background: var(--primary-soft);
  border-color: var(--primary-accent);
  color: var(--primary);
}
.btn-secondary.toggle-archived.active {
  background: var(--primary-accent);
  color: #fff;
}

.btn-danger {
  background: var(--danger);
  color: #fff;
  border: none;
  padding: 8px 18px;
  border-radius: 30px;
  cursor: pointer;
  font-family: inherit;
  font-weight: 600;
  letter-spacing: 0.3px;
  box-shadow: 0 2px 6px -2px rgba(0, 0, 0, 0.35);
}
.btn-danger:hover {
  filter: brightness(1.05);
}

.dropdown button {
  width: 100%;
}

.empty {
  text-align: center;
  padding: 40px 20px;
  opacity: 0.7;
}

.theme-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  font-size: 1.1rem;
}
/* Prevent selecting/highlighting the sun/moon emoji */
.theme-toggle span {
  user-select: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
}
.theme-toggle input {
  display: none;
}

.app-dark body,
.app.app-dark {
  color: var(--text);
}
body.app-dark header {
  box-shadow: 0 0 10px 0 rgba(0, 0, 0, 0.6);
}

/* MUI button overrides for visibility */
button.MuiButton-root {
  text-transform: none;
  font-weight: 600;
  letter-spacing: 0.3px;
}
button.MuiButton-contained {
  box-shadow: none;
}
button.MuiButton-contained:hover {
  filter: brightness(1.05);
  box-shadow: 0 3px 10px -2px rgba(0, 0, 0, 0.35);
}
button.MuiButton-outlined {
  background-color: #00000015;
}
button.MuiButton-outlined {
  border-color: var(--primary-accent);
  color: var(--primary);
}
button.MuiButton-outlined:hover {
  background: rgba(255, 255, 255, 0.274) !important;
  border-color: var(--primary);
}
button.MuiButton-text.MuiButton-colorError {
  background-color: #00000015;
  color: var(--danger);
}
button.MuiButton-text.MuiButton-colorError:hover {
  background: rgba(215, 38, 61, 0.08);
}
button.MuiButton-text.MuiButton-colorError {
  font-weight: 700;
}
button.MuiButton-text.MuiButton-colorError:hover {
  background: rgba(215, 38, 61, 0.15);
  color: var(--danger);
}

/* Dynamic archive button using data-accent */
.archive-btn {
  transition: background-color 0.2s, color 0.2s, border-color 0.2s;
}
.archive-btn:hover {
  background: attr(data-accent color, var(--primary));
  color: #fff !important;
  border-color: currentColor;
}

/* Focus states */
input:focus,
textarea:focus,
.search-bar:focus {
  outline: 2px solid var(--primary-accent);
  outline-offset: 2px;
}

@media (max-width: 600px) {
  form.create-note {
    margin-top: 20px;
  }
  header {
    padding: 14px 20px;
  }
  .notes-grid {
    gap: 16px;
  }
}

@media (max-width: 480px) {
  .toolbar-row {
    flex-wrap: wrap;
    gap: 10px;
  }
  .toolbar-row .search-bar {
    flex: 1 1 100%;
  }
  .toolbar-row .toggle-archived {
    flex: 1 1 100%;
    order: 2;
  }
  .toolbar-row .select,
  .toolbar-row .toolbar-dropdown {
    flex: 1 1 calc(50% - 5px);
    min-width: 140px;
  }
  .theme-toggle {
    order: 3;
  }
  .toolbar-row .btn-secondary,
  .toolbar-row select {
    justify-content: center;
  }
  .notes-grid {
    grid-template-columns: 1fr;
  }
  form.create-note {
    padding: 14px 14px 22px;
  }
  .bulk-bar {
    flex-direction: column;
    align-items: stretch;
  }
  .bulk-bar > * {
    width: 100%;
    text-align: center;
  }
  .stats {
    flex-wrap: wrap;
    gap: 8px;
  }
  .note {
    padding: 12px 48px 12px 14px;
  }
  .note-edit-content {
    min-height: 110px;
  }
  .color-pop {
    grid-template-columns: repeat(5, 28px);
    gap: 8px;
  }
  .color-pop-swatch {
    width: 28px;
    height: 28px;
  }
}

/* Dark theme toolbar & bulk bar contrast improvements */
body.dark .toolbar,
body.dark .bulk-bar {
  color: #f2f2f2;
}
body.dark .bulk-bar span,
body.dark .bulk-bar button,
body.dark .bulk-bar .btn-secondary {
  color: #f2f2f2;
}
body.dark .btn-secondary {
  background: #303030;
  border-color: #444;
  color: #e9e9e9;
  transition: background-color 0.3s, color 0.3s, border-color 0.3s;
}
body.dark .btn-secondary:hover {
  background: #3a3a3a;
  color: #fff;
}
body.dark .select {
  background-color: #303030; /* use background-color so we don't reset positions/sizes */
  border-color: #444;
  color: #e9e9e9;
  /* White arrow (override only color) */
  background-image: linear-gradient(45deg, transparent 50%, #ffffff 50%),
    linear-gradient(135deg, #ffffff 50%, transparent 50%);
  background-position: calc(100% - 22px) 55%, calc(100% - 14px) 55%;
  background-size: 7px 7px, 7px 7px;
  background-repeat: no-repeat;
}
body.dark .search-bar {
  background: #2a2a2a;
  border-color: #3a3a3a;
  color: #e9e9e9;
}
body.dark .search-bar::placeholder {
  color: #777;
}
body.dark .stats {
  color: #9a9a9a;
}
