/* Dark theme — neutral base + purple accent */
:root {
  color-scheme: dark;
  --bg: #121212;
  --bg-elevated: #161616;
  --surface: #1e1e1e;
  --surface-hover: #252525;
  --border: #333333;
  --border-subtle: #2a2a2a;
  --text: #ececec;
  --muted: #a3a3a3;
  --accent: #b49cff;
  --accent-hover: #cab8ff;
  --accent-pressed: #9575f5;
  --accent-soft: rgba(180, 156, 255, 0.18);
  --success: #6bcf7a;
  --danger: #f08080;
  --radius: 12px;
  --nav-height: auto;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-x: env(safe-area-inset-left, 0px) env(safe-area-inset-right, 0px);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-tap-highlight-color: rgba(180, 156, 255, 0.28);
}

body.menu-open {
  overflow: hidden;
  touch-action: none;
}

.top {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
  padding-top: var(--safe-top);
}

.nav {
  max-width: 920px;
  margin: 0 auto;
  padding: 0.55rem max(1rem, env(safe-area-inset-right)) 0.55rem
    max(1rem, env(safe-area-inset-left));
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.brand {
  font-weight: 700;
  color: var(--text) !important;
  letter-spacing: -0.02em;
  text-decoration: none;
  padding: 0.35rem 0;
  border-radius: 8px;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
}

/* Mobile: hamburger only (links live in drawer) */
.nav-toggle {
  margin-left: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: none;
  border-radius: 10px;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  flex-shrink: 0;
}

.nav-toggle:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.nav-toggle-bars {
  width: 22px;
  height: 16px;
  position: relative;
  display: block;
}

.nav-toggle-bars span {
  display: block;
  height: 2px;
  background: var(--text);
  border-radius: 1px;
  position: absolute;
  left: 0;
  right: 0;
  transition: transform 0.2s ease, opacity 0.2s ease, top 0.2s ease;
}

.nav-toggle-bars span:nth-child(1) {
  top: 0;
}

.nav-toggle-bars span:nth-child(2) {
  top: 7px;
}

.nav-toggle-bars span:nth-child(3) {
  top: 14px;
}

body.menu-open .nav-toggle-bars span:nth-child(1) {
  top: 7px;
  transform: rotate(45deg);
}

body.menu-open .nav-toggle-bars span:nth-child(2) {
  opacity: 0;
}

body.menu-open .nav-toggle-bars span:nth-child(3) {
  top: 7px;
  transform: rotate(-45deg);
}

.nav-desktop {
  display: none;
  flex: 1;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.35rem 0.65rem;
  min-width: 0;
}

.nav-desktop a {
  color: var(--muted);
  text-decoration: none;
  font-weight: 500;
  padding: 0.45rem 0.65rem;
  border-radius: 8px;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
}

.nav-desktop a:hover,
.nav-desktop a:focus-visible {
  color: var(--text);
  background: var(--surface-hover);
  outline: none;
}

.nav-desktop a.active {
  color: var(--accent);
  background: var(--accent-soft);
}

/* Desktop: Completed under ToDo, flyout on hover / focus-within */
.nav-dd {
  position: relative;
  align-self: stretch;
  display: flex;
  align-items: stretch;
}

.nav-desktop .nav-dd-trigger.nav-dd-trigger--parent {
  color: var(--text);
  background: rgba(180, 156, 255, 0.1);
}

.nav-dd-menu {
  position: absolute;
  top: 100%;
  left: 0;
  padding-top: 6px;
  min-width: 11rem;
  z-index: 220;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-4px);
  transition: opacity 0.15s ease, transform 0.15s ease, visibility 0.15s;
  pointer-events: none;
}

.nav-dd:hover .nav-dd-menu,
.nav-dd:focus-within .nav-dd-menu {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
  pointer-events: auto;
}

.nav-dd-menu-inner {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.45);
  padding: 0.3rem 0;
}

.nav-dd-item {
  display: flex;
  align-items: center;
  padding: 0.42rem 0.9rem;
  color: var(--muted);
  text-decoration: none;
  font-weight: 500;
  font-size: 0.9rem;
  border-radius: 0;
}

.nav-dd-item:hover,
.nav-dd-item:focus-visible {
  color: var(--text);
  background: var(--surface-hover);
  outline: none;
}

.nav-dd-item.active {
  color: var(--accent);
  background: var(--accent-soft);
}

.nav-add-cat {
  flex: 0 1 13.5rem;
  min-width: 0;
  max-width: 15rem;
}

.nav-add-cat-form {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.nav-add-cat-form input[type="text"] {
  flex: 1;
  min-width: 0;
  width: 0;
  padding: 0.32rem 0.5rem;
  font-size: 0.8125rem;
  line-height: 1.3;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-elevated);
  color: var(--text);
  height: 28px;
}

.nav-add-cat-form input[type="text"]:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-soft);
}

.nav-add-cat-btn {
  flex-shrink: 0;
  min-height: 28px;
  height: 28px;
  padding: 0 0.5rem;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  border-radius: 5px;
  line-height: 1;
}

.spacer {
  flex: 1;
  min-width: 0.5rem;
}

.nav-account {
  display: flex;
  align-items: center;
  gap: 0.35rem 0.75rem;
  flex-wrap: nowrap;
  flex-shrink: 0;
}

.user {
  color: var(--muted);
  font-size: 0.875rem;
}

.logout {
  color: var(--danger) !important;
}

.nav-desktop .logout:hover,
.nav-desktop .logout:focus-visible {
  background: rgba(240, 128, 128, 0.12) !important;
}

/* Full-screen overlay + slide panel (mobile) */
.nav-mobile {
  position: fixed;
  inset: 0;
  z-index: 200;
  pointer-events: none;
  visibility: hidden;
  transition: visibility 0.25s;
}

.nav-mobile.is-open {
  pointer-events: auto;
  visibility: visible;
}

.nav-mobile-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  opacity: 0;
  transition: opacity 0.25s ease;
  overscroll-behavior: none;
}

.nav-mobile.is-open .nav-mobile-backdrop {
  opacity: 1;
}

.nav-mobile-panel {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(18.5rem, 88vw);
  max-width: 100%;
  background: var(--surface);
  border-left: 1px solid var(--border);
  box-shadow: -12px 0 40px rgba(0, 0, 0, 0.35);
  display: flex;
  flex-direction: column;
  padding: calc(var(--safe-top) + 0.75rem) 0 0;
  transform: translateX(100%);
  transition: transform 0.28s cubic-bezier(0.32, 0.72, 0, 1);
  overscroll-behavior: contain;
}

.nav-mobile.is-open .nav-mobile-panel {
  transform: translateX(0);
}

.nav-mobile-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1rem 0.75rem;
  border-bottom: 1px solid var(--border-subtle);
  flex-shrink: 0;
}

.nav-mobile-title {
  font-size: 0.8125rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.nav-mobile-close {
  width: 44px;
  height: 44px;
  margin: -0.35rem -0.5rem -0.35rem 0;
  border: none;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  font-size: 1.75rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

.nav-mobile-close:hover,
.nav-mobile-close:focus-visible {
  color: var(--text);
  background: var(--surface-hover);
  outline: none;
}

.nav-mobile-links {
  flex: 1;
  overflow-y: auto;
  padding: 0.5rem 0.65rem;
  -webkit-overflow-scrolling: touch;
}

.nav-mobile-link {
  display: flex;
  align-items: center;
  min-height: 52px;
  padding: 0 0.85rem;
  margin-bottom: 0.2rem;
  border-radius: 10px;
  color: var(--text);
  text-decoration: none;
  font-weight: 500;
  font-size: 1.05rem;
}

.nav-mobile-link:hover,
.nav-mobile-link:focus-visible {
  background: var(--surface-hover);
  outline: none;
}

.nav-mobile-link.active {
  color: var(--accent);
  background: var(--accent-soft);
}

.nav-mobile-group {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.nav-mobile-sublink {
  padding-left: 1.65rem !important;
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--muted);
  border-left: 2px solid var(--border-subtle);
  margin-left: 0.65rem;
}

.nav-mobile-sublink:hover,
.nav-mobile-sublink:focus-visible {
  border-left-color: var(--accent);
}

.nav-mobile-sublink.active {
  border-left-color: var(--accent);
}

.nav-mobile-add-cat {
  margin-top: 0.5rem;
  padding: 0.85rem 0.85rem 0.25rem;
  border-top: 1px solid var(--border-subtle);
}

.nav-mobile-add-cat-form {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.nav-mobile-add-cat-label {
  display: block;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}

.nav-mobile-add-cat-form input[type="text"] {
  width: 100%;
  padding: 0.55rem 0.65rem;
  font-size: 16px;
  line-height: 1.35;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-elevated);
  color: var(--text);
}

.nav-mobile-add-cat-form input[type="text"]:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-soft);
}

.nav-mobile-add-cat-btn {
  width: 100%;
  min-height: 44px;
  font-weight: 600;
  font-size: 0.875rem;
}

.nav-mobile-foot {
  flex-shrink: 0;
  padding: 1rem max(1rem, env(safe-area-inset-right)) calc(1rem + var(--safe-bottom))
    max(1rem, env(safe-area-inset-left));
  border-top: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.nav-mobile-foot .user {
  font-size: 0.9rem;
}

.nav-mobile-logout {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  padding: 0 1rem;
  border-radius: 10px;
  border: 1px solid rgba(240, 128, 128, 0.4);
  background: rgba(240, 128, 128, 0.08);
  text-decoration: none;
  font-weight: 600;
  width: 100%;
}

.nav-mobile-logout:hover,
.nav-mobile-logout:focus-visible {
  background: rgba(240, 128, 128, 0.16);
  outline: none;
}

@media (prefers-reduced-motion: reduce) {
  .nav-mobile,
  .nav-mobile-backdrop,
  .nav-mobile-panel,
  .nav-toggle-bars span {
    transition: none !important;
  }

  body.menu-open .nav-toggle-bars span:nth-child(1),
  body.menu-open .nav-toggle-bars span:nth-child(3) {
    transition: none !important;
  }
}

.container {
  max-width: 920px;
  margin: 0 auto;
  padding: 1rem max(1rem, env(safe-area-inset-right)) calc(1.5rem + var(--safe-bottom))
    max(1rem, env(safe-area-inset-left));
  min-width: 0;
  overflow-x: hidden;
}

.flashes {
  list-style: none;
  padding: 0;
  margin: 0 0 1rem;
}

.flash {
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  margin-bottom: 0.5rem;
  font-size: 0.9375rem;
}

.flash-error {
  background: rgba(240, 128, 128, 0.12);
  border: 1px solid rgba(240, 128, 128, 0.45);
  color: #ffc9c9;
}

.flash-info {
  background: var(--accent-soft);
  border: 1px solid rgba(180, 156, 255, 0.38);
  color: #ece6ff;
}

h1 {
  font-size: clamp(1.35rem, 4vw, 1.6rem);
  font-weight: 600;
  margin: 0 0 0.65rem;
  letter-spacing: -0.02em;
}

h2 {
  font-size: clamp(1rem, 3vw, 1.125rem);
  font-weight: 600;
  margin: 0;
  color: var(--text);
}

.muted {
  color: var(--muted);
  font-size: 0.9375rem;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
}

.login-card {
  max-width: 420px;
  margin: 2rem auto;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.stack label {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  font-size: 0.9rem;
  color: var(--muted);
}

/* 16px+ prevents iOS zoom on focus */
input[type="text"],
input[type="password"] {
  padding: 0.75rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg-elevated);
  color: var(--text);
  font-size: 16px;
  width: 100%;
  max-width: 100%;
}

input[type="text"]:focus,
input[type="password"]:focus {
  outline: 2px solid var(--accent);
  outline-offset: 0;
  border-color: var(--accent);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.65rem 1rem;
  min-height: 44px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text);
  font-size: 0.9375rem;
  cursor: pointer;
  text-decoration: none;
  touch-action: manipulation;
}

.btn:hover {
  border-color: #555;
  background: var(--surface-hover);
}

.btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #12081f;
  font-weight: 600;
}

.btn.primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
  color: #12081f;
}

.btn.primary:active {
  background: var(--accent-pressed);
  border-color: var(--accent-pressed);
}

.btn.small {
  padding: 0.4rem 0.65rem;
  min-height: 40px;
  min-width: 44px;
  font-size: 0.875rem;
}

.page-intro {
  margin-bottom: 1.1rem;
}

/* Category sections: light dividers, no heavy cards */
.category-block {
  margin: 0;
  padding: 0.65rem 0 1rem;
  background: transparent;
  border: none;
  border-radius: 0;
  border-top: 1px solid var(--border-subtle);
  min-width: 0;
  max-width: 100%;
}

.category-block:first-of-type {
  border-top: none;
  padding-top: 0;
}

.category-head {
  display: flex;
  align-items: center;
  gap: 0.35rem 0.5rem;
  margin-bottom: 0.35rem;
  padding: 0;
  border: none;
}

.category-name {
  flex: 1;
  min-width: 0;
  margin: 0;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--muted);
  word-break: break-word;
  line-height: 1.3;
}

.category-block--accent .category-name {
  color: var(--cat-accent);
}

.category-actions {
  display: flex;
  align-items: flex-start;
  gap: 0.15rem;
  flex-shrink: 0;
}

.category-edit {
  position: relative;
}

.category-edit-summary {
  list-style: none;
  cursor: pointer;
  min-height: 36px;
  min-width: 44px;
  padding: 0 0.45rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  border-radius: 6px;
  user-select: none;
}

.category-edit-summary::-webkit-details-marker {
  display: none;
}

.category-edit-summary:hover {
  background: var(--surface-hover);
  color: var(--text);
}

.category-edit[open] > .category-edit-summary {
  color: var(--accent);
  background: var(--accent-soft);
}

.category-edit-panel {
  position: absolute;
  right: 0;
  top: calc(100% + 4px);
  z-index: 30;
  width: min(calc(100vw - 2rem), 17rem);
  padding: 0.75rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.45);
}

.category-edit-form {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.category-edit-label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.8rem;
  color: var(--muted);
}

.category-edit-label input[type="text"] {
  font-size: 16px;
}

.category-edit-label input[type="color"] {
  height: 42px;
  padding: 0.2rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-elevated);
  cursor: pointer;
}

.category-edit-check {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.8rem;
  color: var(--muted);
  cursor: pointer;
}

.category-edit-save {
  width: 100%;
  margin-top: 0.25rem;
}

.category-delete-form {
  margin-top: 0.5rem;
  padding-top: 0.65rem;
  border-top: 1px solid var(--border-subtle);
}

.btn.category-delete-btn {
  width: 100%;
  background: transparent;
  border: 1px solid rgba(240, 128, 128, 0.45);
  color: var(--danger);
  font-weight: 600;
}

.btn.category-delete-btn:hover {
  background: rgba(240, 128, 128, 0.12);
  border-color: rgba(240, 128, 128, 0.65);
  color: #ff9a9a;
}

.reorder {
  display: flex;
  gap: 0.15rem;
  flex-shrink: 0;
}

.btn.reorder-btn {
  min-width: 36px;
  min-height: 36px;
  width: 36px;
  height: 36px;
  padding: 0;
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 0.85rem;
  line-height: 1;
  border-radius: 6px;
  opacity: 0.75;
}

.btn.reorder-btn:hover {
  opacity: 1;
  color: var(--accent);
  background: var(--accent-soft);
}

.btn.reorder-btn:active {
  opacity: 1;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.category-head--notes {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-bottom: 0.35rem;
}

.category-head--notes .category-name {
  flex: 1 1 auto;
  min-width: 0;
}

.notes-add-link {
  flex-shrink: 0;
  text-decoration: none;
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.28rem 0.75rem;
  font-size: 0.78rem;
  font-weight: 600;
  border-radius: 8px;
}

.notes-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 15.5rem), 1fr));
  gap: 0.65rem;
  margin: 0.35rem 0 0.75rem;
  min-width: 0;
}

/* Notes cards — dark theme (match app surface) */
.note-card {
  position: relative;
  display: flex;
  flex-direction: column;
  min-width: 0;
  padding: 0.65rem 0.7rem;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 3px 14px rgba(0, 0, 0, 0.35);
}

.note-card--pinned {
  border-color: rgba(180, 156, 255, 0.45);
  box-shadow: 0 0 0 1px rgba(180, 156, 255, 0.15), 0 4px 18px rgba(0, 0, 0, 0.35);
}

.category-block--accent .note-card--pinned {
  border-color: var(--cat-accent);
  box-shadow: 0 0 0 1px var(--cat-accent), 0 4px 18px rgba(0, 0, 0, 0.38);
}

.note-card-link {
  text-decoration: none;
  color: inherit;
  flex: 1 1 auto;
  min-width: 0;
  padding-right: 1.35rem;
}

.note-card-link:hover .note-card-title {
  color: var(--accent-hover);
}

.category-block--accent .note-card-link:hover .note-card-title {
  color: var(--cat-accent);
}

.note-card-title {
  margin: 0 0 0.35rem;
  font-size: 1rem;
  font-weight: 700;
  line-height: 1.3;
  letter-spacing: -0.02em;
  color: var(--text);
}

.note-card-preview {
  margin: 0;
  font-size: 0.84rem;
  line-height: 1.45;
  color: var(--muted);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
  min-height: 2.2rem;
}

.note-card-empty {
  color: var(--muted);
  font-style: italic;
  opacity: 0.85;
}

.note-pin-badge {
  position: absolute;
  top: 0.4rem;
  right: 0.45rem;
  font-size: 0.85rem;
  line-height: 1;
  opacity: 0.9;
  pointer-events: none;
}

.note-card-meta {
  margin-top: 0.45rem;
  font-size: 0.72rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.note-card-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem;
  margin-top: 0.55rem;
  padding-top: 0.45rem;
  border-top: 1px solid var(--border-subtle);
}

.note-card .btn.btn-ghost {
  border-color: var(--border);
  color: var(--muted);
}

.note-card .btn.btn-ghost:hover {
  background: var(--surface-hover);
  color: var(--text);
  border-color: var(--border);
}

.note-card a.btn.btn-ghost {
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.note-action-form {
  margin: 0;
}

.btn.btn-ghost {
  padding: 0.28rem 0.55rem;
  font-size: 0.78rem;
  font-weight: 600;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 6px;
  cursor: pointer;
}

.btn.btn-ghost:hover {
  color: var(--text);
  background: var(--surface-hover);
  border-color: var(--border);
}

.btn.note-delete-btn:hover {
  color: var(--danger);
  border-color: rgba(240, 128, 128, 0.45);
  background: rgba(240, 128, 128, 0.1);
}

/* Immersive note editor (OneNote-style): full-height canvas; revisions desktop-only */
body.note-write-immersive .container {
  max-width: none;
}

body.note-write-immersive .flashes {
  padding-left: max(0.75rem, env(safe-area-inset-left));
  padding-right: max(0.75rem, env(safe-area-inset-right));
}

.note-write-page {
  max-width: 1400px;
  margin: 0 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  min-height: calc(100dvh - 3.75rem - var(--safe-top));
}

.note-write-toolbar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  flex-shrink: 0;
  padding: 0.15rem 0 0.65rem;
}

.note-write-back {
  color: var(--muted);
  text-decoration: none;
  font-weight: 600;
  font-size: 0.9rem;
}

.note-write-back:hover {
  color: var(--accent);
}

.note-save-status {
  font-size: 0.8rem;
  color: var(--muted);
  min-height: 1.25rem;
}

.note-save-status--error {
  color: var(--danger);
}

.note-write-layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0;
  align-items: stretch;
  flex: 1;
  min-height: 0;
}

.note-write-main {
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.note-write-sheet {
  background: var(--surface);
  color: var(--text);
  border-radius: 12px;
  border: 1px solid var(--border);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.45);
  padding: 1.25rem 1.35rem 1.5rem;
  min-width: 0;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.note-write-field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin: 0 0 1rem;
  flex-shrink: 0;
}

.note-write-field--body {
  flex: 1 1 auto;
  min-height: 0;
  margin-bottom: 0;
  display: flex;
  flex-direction: column;
}

.note-write-field-label {
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  flex-shrink: 0;
}

.note-write-title-input {
  width: 100%;
  font-size: clamp(1.2rem, 2.5vw, 1.55rem);
  font-weight: 650;
  line-height: 1.25;
  padding: 0.4rem 0.2rem;
  border: none;
  border-bottom: 1px solid var(--border);
  border-radius: 0;
  background: transparent;
  color: var(--text);
  font-family: inherit;
}

.note-write-title-input:focus {
  outline: none;
  border-bottom-color: var(--accent);
}

.note-write-title-input::placeholder {
  color: var(--muted);
}

.note-write-body-input {
  width: 100%;
  flex: 1 1 auto;
  min-height: 12rem;
  padding: 0.65rem 0.75rem;
  font-size: 16px;
  line-height: 1.55;
  font-family: inherit;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-elevated);
  color: var(--text);
  resize: none;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.note-write-body-input:focus {
  outline: 2px solid var(--accent-soft);
  outline-offset: 1px;
  border-color: var(--accent);
}

/* Version history: desktop / wide screens only (always hidden on narrow viewports) */
.note-revisions-panel {
  display: none !important;
}

@media (min-width: 800px) {
  .note-write-layout {
    grid-template-columns: 1fr min(18rem, 28vw);
    gap: 1rem;
    align-items: stretch;
  }

  .note-revisions-panel:not([hidden]) {
    display: block !important;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 0.75rem 0.65rem;
    max-height: calc(100dvh - 5.5rem - var(--safe-top));
    overflow: auto;
    position: sticky;
    top: calc(0.75rem + var(--safe-top));
    align-self: start;
  }
}

@media (min-width: 800px) {
  body.note-write-immersive .container {
    padding: 0.65rem max(1rem, env(safe-area-inset-right)) 1rem
      max(1rem, env(safe-area-inset-left));
  }

  .note-write-page {
    min-height: calc(100dvh - 4rem - var(--safe-top));
  }

  .note-write-sheet {
    min-height: calc(100dvh - 6.25rem - var(--safe-top));
    max-height: calc(100dvh - 5rem - var(--safe-top));
  }

  .note-write-body-input {
    min-height: 22rem;
    resize: vertical;
  }
}

/* Mobile: true full-width canvas (safe-area only); hide revisions */
@media (max-width: 799px) {
  body.note-write-immersive {
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    width: 100%;
    overflow-x: hidden;
  }

  body.note-write-immersive > .top {
    flex-shrink: 0;
    width: 100%;
  }

  body.note-write-immersive .top .nav {
    max-width: none;
    width: 100%;
    margin: 0;
    padding: 0.55rem max(0.65rem, env(safe-area-inset-right)) 0.55rem
      max(0.65rem, env(safe-area-inset-left));
    box-sizing: border-box;
  }

  body.note-write-immersive .container {
    width: 100%;
    max-width: none;
    margin: 0;
    padding: 0;
    padding-bottom: env(safe-area-inset-bottom, 0);
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
  }

  body.note-write-immersive .flashes {
    width: 100%;
    padding: 0.5rem max(0.75rem, env(safe-area-inset-left)) 0
      max(0.75rem, env(safe-area-inset-right));
    margin: 0;
    box-sizing: border-box;
  }

  .note-write-page {
    width: 100%;
    max-width: none;
    margin: 0;
    flex: 1;
    min-height: 0;
    box-sizing: border-box;
  }

  .note-write-toolbar {
    width: 100%;
    box-sizing: border-box;
    padding: 0.55rem max(0.65rem, env(safe-area-inset-left)) 0.55rem
      max(0.65rem, env(safe-area-inset-right));
    margin: 0;
    background: var(--surface);
    border-bottom: 1px solid var(--border-subtle);
  }

  .note-write-layout {
    width: 100%;
    flex: 1;
    min-height: 0;
    box-sizing: border-box;
  }

  .note-write-main {
    width: 100%;
    flex: 1;
    min-height: 0;
    box-sizing: border-box;
  }

  .note-write-sheet {
    width: 100%;
    max-width: none;
    flex: 1;
    border-radius: 0;
    border: none;
    border-top: 1px solid var(--border-subtle);
    box-shadow: none;
    box-sizing: border-box;
    padding: 0.75rem max(0.65rem, env(safe-area-inset-left)) 0.75rem
      max(0.65rem, env(safe-area-inset-right));
    padding-bottom: calc(0.75rem + env(safe-area-inset-bottom, 0));
    max-height: none;
  }

  .note-write-title-input {
    font-size: 1.25rem;
    padding-left: 0;
    padding-right: 0;
  }

  .note-write-body-input {
    min-height: 0;
    width: 100%;
    box-sizing: border-box;
  }
}

.note-revisions-heading {
  margin: 0 0 0.35rem;
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text);
}

.note-revisions-hint {
  margin: 0 0 0.65rem;
  font-size: 0.72rem;
  line-height: 1.4;
  color: var(--muted);
}

.note-revisions-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

.note-revision-item {
  padding-bottom: 0.55rem;
  border-bottom: 1px solid var(--border-subtle);
}

.note-revision-item:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.note-revision-restore-form {
  margin: 0 0 0.35rem;
}

.note-revision-time {
  display: block;
  font-size: 0.68rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  margin-bottom: 0.2rem;
}

.note-revision-snippet {
  font-size: 0.75rem;
  line-height: 1.35;
  color: var(--text);
  word-break: break-word;
}

.task-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0.05rem;
  min-width: 0;
}

.task-row-wrap {
  list-style: none;
  min-width: 0;
  max-width: 100%;
  margin: 0;
  padding: 0;
}

.task-swipe {
  position: relative;
  overflow: hidden;
  border-radius: 6px;
}

.task-swipe-actions {
  position: absolute;
  right: 0;
  top: 0;
  bottom: 0;
  width: 5.5rem;
  z-index: 0;
  display: flex;
  align-items: stretch;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.12s ease;
}

.task-row-wrap.task-swipe--open .task-swipe-actions,
.task-row-wrap.task-swipe--armed .task-swipe-actions {
  opacity: 1;
  pointer-events: auto;
}

.task-delete-form {
  flex: 1;
  display: flex;
  margin: 0;
}

.task-delete-btn {
  flex: 1;
  margin: 0;
  padding: 0.5rem 0.35rem;
  border: none;
  border-radius: 0;
  background: rgba(176, 56, 56, 0.96);
  color: #fff;
  font-weight: 600;
  font-size: 0.78rem;
  letter-spacing: 0.02em;
  cursor: pointer;
  touch-action: manipulation;
}

.task-delete-btn:hover,
.task-delete-btn:focus-visible {
  background: #c43d3d;
  outline: none;
}

/* Desktop-only row delete (hidden & off-layout below 640px) */
.task-delete-desktop-wrap {
  display: none;
  margin: 0;
  flex-shrink: 0;
  align-self: flex-start;
  padding-top: 0.1rem;
}

.task-delete-desktop {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin: 0;
  padding: 0.28rem;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  line-height: 0;
  transition: color 0.15s ease, background 0.15s ease;
}

.task-delete-desktop:hover,
.task-delete-desktop:focus-visible {
  color: var(--danger);
  background: rgba(240, 128, 128, 0.12);
  outline: none;
}

.task-row-front {
  position: relative;
  z-index: 1;
  background: var(--bg);
  transition: transform 0.2s ease;
}

/* Zebra: default row uses --bg (see .task-row-front); even rows get a dark category tint or neutral lift. */
.category-block--accent .task-list > .task-row-wrap:nth-child(even) .task-row-front {
  background: var(--cat-row-tint, var(--bg-elevated));
}

.category-block:not(.category-block--accent) .task-list > .task-row-wrap:nth-child(even) .task-row-front {
  background: var(--bg-elevated);
}

.task-row {
  display: flex;
  align-items: flex-start;
  gap: 0.45rem;
  padding: 0.35rem 0;
  margin: 0;
  border: none;
  border-radius: 6px;
  min-width: 0;
  max-width: 100%;
}

.task-list .task-row-front:hover::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.045);
  pointer-events: none;
}

.task-list--sortable .task-row-wrap {
  cursor: grab;
  touch-action: manipulation;
}

.task-list--sortable .task-row-wrap:active {
  cursor: grabbing;
}

.task-list > .task-row-wrap.task-row-wrap--chosen .task-row-front {
  background: rgba(180, 156, 255, 0.12);
}

.task-row-wrap--drag {
  opacity: 0.95;
}

.task-list > .task-row-wrap.task-row-wrap--ghost .task-row-front {
  background: rgba(180, 156, 255, 0.1);
}

.task-row-wrap--ghost {
  opacity: 0.45;
}

.task-row form {
  margin: 0;
  padding-top: 0.12rem;
  flex-shrink: 0;
}

.task-row input[type="checkbox"] {
  width: 1.15rem;
  height: 1.15rem;
  min-width: 1.15rem;
  min-height: 1.15rem;
  margin: 0;
  cursor: pointer;
  accent-color: var(--accent);
}

.task-row label {
  cursor: pointer;
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  flex: 1;
  margin: 0;
  min-height: 40px;
  padding-top: 0.1rem;
}

.task-title {
  flex: 1 1 0;
  min-width: 0;
  max-width: 100%;
  word-break: break-word;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
  padding-top: 0.08rem;
  line-height: 1.4;
  font-size: 0.9375rem;
}

.task-row-done .task-title {
  color: rgba(236, 236, 236, 0.92);
}

.completed-meta {
  font-size: 0.75rem;
  color: var(--muted);
  margin-top: 0.15rem;
  font-variant-numeric: tabular-nums;
}

.check-done {
  color: var(--success);
  font-weight: 600;
  font-size: 0.95rem;
  line-height: 1.25;
  flex-shrink: 0;
  margin-top: 0.2rem;
  width: 1.1rem;
  text-align: center;
}

.add-task {
  margin-top: 0.4rem;
  padding-top: 0;
  border: none;
  min-width: 0;
  max-width: 100%;
}

/* Stacked: contenteditable editor (grows with text) + button */
.add-task form {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  align-items: stretch;
  min-width: 0;
  max-width: 100%;
  width: 100%;
}

.add-task-field-wrap {
  display: block;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  overflow-x: hidden;
  overflow-y: visible;
}

.add-task-editor {
  display: block;
  box-sizing: border-box;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  /* One line + padding when empty; grows with content (pre-wrap). */
  min-height: calc(2 * 0.55rem + 1.45em);
  margin: 0;
  padding: 0.55rem 0.65rem;
  font-size: 16px;
  line-height: 1.45;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg-elevated);
  color: var(--text);
  font-family: inherit;
  word-break: break-word;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
  tab-size: 4;
  overflow-x: hidden;
  overflow-y: visible;
  cursor: text;
  -webkit-user-select: text;
  user-select: text;
}

.add-task-editor:focus {
  outline: 2px solid var(--accent);
  outline-offset: 0;
  border-color: var(--accent);
}

.add-task-editor.is-empty::before {
  content: attr(data-placeholder);
  color: var(--muted);
  pointer-events: none;
}

.add-task .add-task-btn {
  width: 100%;
  min-height: 40px;
  padding: 0.45rem 0.75rem;
  font-size: 0.875rem;
  font-weight: 600;
}

.add-task .add-task-btn.add-task-btn--accent {
  background: var(--cat-accent);
  border-color: var(--cat-accent);
  color: var(--cat-btn-fg);
}

.add-task .add-task-btn.add-task-btn--accent:hover {
  filter: brightness(1.08);
  border-color: var(--cat-accent);
  color: var(--cat-btn-fg);
}

.add-task .add-task-btn.add-task-btn--accent:active {
  filter: brightness(0.94);
}

.empty-cats {
  color: var(--muted);
  padding: 1.75rem 1rem;
  text-align: center;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  font-size: 0.9375rem;
}

.empty-cats-hint-mobile {
  display: none;
}

.empty-cats strong {
  color: var(--accent);
  font-weight: 600;
}

@media (max-width: 639px) {
  .empty-cats-hint-desktop {
    display: none;
  }

  .empty-cats-hint-mobile {
    display: inline;
  }
}

/* Desktop nav: full bar, no drawer + compact “Add” controls */
@media (min-width: 640px) {
  .nav-toggle {
    display: none !important;
  }

  .nav-desktop {
    display: flex;
  }

  .nav-mobile {
    display: none !important;
  }

  body.menu-open {
    overflow: unset;
    touch-action: unset;
  }

  .nav-add-cat-form input[type="text"] {
    height: 26px;
    padding: 0.18rem 0.45rem;
    font-size: 0.75rem;
    border-radius: 5px;
  }

  .nav-add-cat-btn {
    min-height: 26px;
    height: 26px;
    padding: 0 0.48rem;
    font-size: 0.65rem;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    border-radius: 5px;
  }

  .add-task-editor {
    min-height: calc(2 * 0.38rem + 1.45em);
    padding: 0.38rem 0.55rem;
    font-size: 14px;
    border-radius: 7px;
  }

  .add-task .add-task-btn {
    min-height: 30px;
    padding: 0.26rem 0.65rem;
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.03em;
    border-radius: 6px;
    width: auto;
    align-self: flex-start;
  }

  .category-edit-save {
    width: auto;
    align-self: flex-start;
    min-height: 30px;
    padding: 0.28rem 0.8rem;
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    border-radius: 6px;
  }

  .task-delete-desktop-wrap {
    display: block;
  }

  /* Swipe delete is mobile-only; hide red strip (no hover/drag peek). */
  .task-swipe {
    overflow: visible;
  }

  .task-swipe-actions {
    display: none !important;
  }
}

@media (min-width: 720px) {
  .container {
    padding-top: 1.35rem;
  }

  .card {
    padding: 1.15rem 1.35rem;
  }
}
