:root {
  --bg: #f3f2eb;
  --surface: #fffef9;
  --surface-2: #f8f6ed;
  --surface-3: #ece9dc;
  --text: #1b241f;
  --muted: #67716b;
  --muted-2: #89918c;
  --border: #dedfd6;
  --border-strong: #c7cbc0;
  --primary: #1f5b48;
  --primary-strong: #174536;
  --primary-soft: #e1eee8;
  --accent: #d79a2b;
  --danger: #bd3f4d;
  --danger-soft: #fae8e9;
  --shadow: 0 28px 70px -42px rgb(25 56 44 / 45%);
  --shadow-sm: 0 15px 34px -24px rgb(25 56 44 / 45%);
  --scrim: rgb(20 31 25 / 36%);
  color-scheme: light;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

:root[data-theme="dark"] {
  --bg: #111713;
  --surface: #19211c;
  --surface-2: #202b24;
  --surface-3: #2b382f;
  --text: #eef3ef;
  --muted: #a7b4ac;
  --muted-2: #78877e;
  --border: #2e3b33;
  --border-strong: #445449;
  --primary: #7cc9aa;
  --primary-strong: #a1dcc4;
  --primary-soft: #243d32;
  --accent: #efba58;
  --danger: #ff8b96;
  --danger-soft: #44272b;
  --shadow: 0 28px 70px -38px rgb(0 0 0 / 85%);
  --shadow-sm: 0 15px 34px -22px rgb(0 0 0 / 75%);
  --scrim: rgb(0 0 0 / 58%);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--bg); }
body {
  min-height: 100svh;
  margin: 0;
  overflow-x: hidden;
  background:
    radial-gradient(45vmax 32vmax at 96% -8%, rgb(215 154 43 / 10%), transparent 65%),
    radial-gradient(40vmax 34vmax at 2% 108%, rgb(31 91 72 / 12%), transparent 65%),
    var(--bg);
  color: var(--text);
  letter-spacing: -0.012em;
  -webkit-font-smoothing: antialiased;
}
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background: linear-gradient(120deg, transparent, rgb(255 255 255 / 3%));
}
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: wait; opacity: .52; }
input, select, textarea {
  width: 100%;
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  outline: none;
  background: var(--surface);
  color: var(--text);
}
input, select { min-height: 48px; padding: 0 14px; }
textarea { resize: vertical; padding: 13px 14px; line-height: 1.55; }
input::placeholder, textarea::placeholder { color: var(--muted-2); }
input:focus-visible, select:focus-visible, textarea:focus-visible {
  border-color: var(--primary);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--primary) 16%, transparent);
}
button:focus-visible { outline: 3px solid color-mix(in srgb, var(--primary) 24%, transparent); outline-offset: 2px; }
svg {
  display: block;
  width: 1.2rem;
  height: 1.2rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
[hidden] { display: none !important; }
h1, h2, h3, p { margin-top: 0; }
h1, h2, h3 { margin-bottom: 0; letter-spacing: -.04em; }
h1 { font-size: clamp(2rem, 7vw, 3rem); }
h2 { font-size: 1.35rem; }
h3 { font-size: .95rem; letter-spacing: -.015em; }
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.app-shell {
  min-height: 100svh;
  padding: max(18px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right))
    max(30px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}
body:has(.notes-view:not([hidden])) { overflow: hidden; }
.app-shell:has(.notes-view:not([hidden])) { height: 100svh; min-height: 0; overflow: hidden; }

.loading-view {
  min-height: calc(100svh - 48px);
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 24px;
}
.loading-brand { display: flex; align-items: center; gap: 14px; }
.loading-title { margin: 0; font-size: 1.5rem; font-weight: 800; letter-spacing: -.04em; }
.loading-message { margin: 3px 0 0; color: var(--muted); font-size: .88rem; font-weight: 600; }
.loading-spinner {
  width: 30px;
  height: 30px;
  border: 3px solid var(--border-strong);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.brand-mark {
  display: grid;
  width: 70px;
  height: 70px;
  place-items: center;
  border-radius: 22px 22px 8px;
  background: var(--primary-strong);
  color: #fff;
  box-shadow: 0 22px 38px -22px rgb(23 69 54 / 70%);
}
.brand-mark svg { width: 34px; height: 34px; }
.auth-view {
  width: min(100%, 920px);
  min-height: calc(100svh - 48px);
  margin: auto;
  display: grid;
  align-content: center;
  gap: 24px;
}
.auth-brand { display: flex; justify-content: center; }
.auth-panel {
  width: min(100%, 430px);
  margin: auto;
  border: 1px solid var(--border);
  border-radius: 24px;
  padding: clamp(22px, 5vw, 34px);
  background: color-mix(in srgb, var(--surface) 90%, transparent);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}
.auth-heading { margin-bottom: 22px; }
.auth-heading h1 { font-size: 2.35rem; }
.auth-heading > p:last-child { margin: 10px 0 0; color: var(--muted); }
.eyebrow {
  margin: 0 0 7px;
  color: var(--primary);
  font-size: .7rem;
  font-weight: 850;
  letter-spacing: .16em;
  text-transform: uppercase;
}
.auth-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  margin-bottom: 20px;
  border-radius: 14px;
  padding: 4px;
  background: var(--surface-2);
}
.tab-button {
  min-height: 42px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  font-weight: 750;
}
.tab-button.is-active { background: var(--surface); color: var(--primary-strong); box-shadow: var(--shadow-sm); }
.auth-form { display: grid; gap: 14px; }
label { display: grid; gap: 7px; color: var(--muted); font-size: .84rem; font-weight: 700; }
.form-message { min-height: 18px; margin: 10px 0 0; color: var(--danger); font-size: .8rem; font-weight: 700; }
.form-message:empty { min-height: 0; margin: 0; }

.primary-button, .secondary-button, .danger-button {
  min-height: 46px;
  border: 0;
  border-radius: 12px;
  padding: 0 18px;
  font-weight: 800;
}
.primary-button { background: var(--primary-strong); color: #fff; box-shadow: 0 16px 28px -18px rgb(23 69 54 / 75%); }
:root[data-theme="dark"] .primary-button { background: #4ca180; }
.secondary-button { border: 1px solid var(--border-strong); background: var(--surface-2); color: var(--text); }
.danger-button { border: 1px solid color-mix(in srgb, var(--danger) 28%, transparent); background: var(--danger-soft); color: var(--danger); }
.icon-button {
  display: grid;
  width: 44px;
  height: 44px;
  flex: 0 0 auto;
  place-items: center;
  border: 1px solid var(--border);
  border-radius: 13px;
  background: var(--surface);
  color: var(--primary);
}
.icon-button.small { width: 36px; height: 36px; border-radius: 10px; }

.notes-view { width: min(100%, 1480px); height: 100%; margin: auto; overflow: hidden; }
.notes-main {
  display: grid;
  height: 100%;
  min-height: 0;
  grid-template-rows: auto auto minmax(0, 1fr);
}
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin: 6px 0 18px; }
.topbar h1 { max-width: min(72vw, 680px); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar-actions { display: flex; align-items: center; gap: 8px; }
.new-note-button { display: flex; min-height: 44px; align-items: center; gap: 7px; padding: 0 15px; }
.new-note-button svg { width: 18px; height: 18px; }
.topbar-list-button { position: relative; }
.topbar-list-count {
  position: absolute;
  top: -5px;
  right: -5px;
  display: grid;
  min-width: 19px;
  height: 19px;
  place-items: center;
  border: 2px solid var(--bg);
  border-radius: 99px;
  padding: 0 4px;
  background: var(--primary-strong);
  color: #fff;
  font-size: .6rem;
  font-weight: 850;
}
.note-count { margin: 9px 0 0; color: var(--muted); font-size: .82rem; font-weight: 700; }
.note-count strong { color: var(--primary); }
.filter-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 132px;
  gap: 8px;
  margin-bottom: 12px;
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 7px;
  background: color-mix(in srgb, var(--surface) 86%, transparent);
  box-shadow: var(--shadow-sm);
  backdrop-filter: blur(16px);
}
.search-field { position: relative; display: block; }
.search-field svg { position: absolute; top: 50%; left: 13px; width: 18px; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.search-field input { min-height: 42px; border-color: transparent; padding-left: 40px; background: var(--surface-2); }
.tag-filter-field select { min-height: 42px; border-color: transparent; background: var(--surface-2); font-size: .82rem; font-weight: 700; }
.notes-scroll {
  min-height: 0;
  margin: 0 -4px;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 3px 4px 8px;
  scrollbar-gutter: stable;
  -webkit-overflow-scrolling: touch;
}
.notes-list { display: grid; grid-template-columns: 1fr; gap: 10px; margin: 0; padding: 0; list-style: none; }
.note-card {
  position: relative;
  display: grid;
  min-height: 92px;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  border: 1px solid var(--border);
  border-radius: 17px;
  padding: 14px;
  background: var(--surface);
  box-shadow: 0 13px 30px -28px rgb(20 48 37 / 65%);
}
.note-card::before {
  content: "";
  position: absolute;
  top: 14px;
  bottom: 14px;
  left: 0;
  width: 3px;
  border-radius: 0 4px 4px 0;
  background: var(--note-color, transparent);
}
.note-card-main {
  min-width: 0;
  border: 0;
  padding: 0 0 0 3px;
  background: transparent;
  color: inherit;
  text-align: left;
}
.note-card-title { display: block; overflow: hidden; font-size: 1rem; font-weight: 800; text-overflow: ellipsis; white-space: nowrap; }
.note-card-body {
  display: -webkit-box;
  overflow: hidden;
  margin: 7px 0 0;
  color: var(--muted);
  font-size: .84rem;
  line-height: 1.45;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  white-space: pre-wrap;
}
.note-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 7px; margin-top: 9px; color: var(--muted-2); font-size: .7rem; font-weight: 700; }
.tag-badge { display: inline-flex; align-items: center; gap: 5px; border-radius: 99px; padding: 3px 8px; background: color-mix(in srgb, var(--tag-color) 13%, transparent); color: var(--text); }
.tag-badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--tag-color); }
.note-actions { display: flex; align-items: flex-start; gap: 5px; }
.reorder-handle {
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  cursor: grab;
  touch-action: none;
  user-select: none;
}
.reorder-handle:active { cursor: grabbing; }
.notes-list.is-reordering .note-card { transition: none; }
.note-card.is-dragging { z-index: 2; border-color: var(--primary); box-shadow: var(--shadow); opacity: .88; transform: scale(1.012); }
.inline-note-editor {
  display: block;
  min-height: 0;
  grid-column: 1 / -1;
  border-color: color-mix(in srgb, var(--primary) 42%, var(--border));
  padding: 16px;
  box-shadow: var(--shadow-sm);
}
.inline-note-form { display: grid; gap: 10px; }
.inline-note-title {
  min-height: 44px;
  border: 0;
  border-bottom: 1px solid var(--border);
  border-radius: 0;
  padding: 0 3px 8px;
  background: transparent;
  font-size: 1.08rem;
  font-weight: 820;
}
.inline-note-title:focus-visible, .inline-note-body:focus-visible {
  border-color: var(--primary);
  box-shadow: none;
}
.inline-note-body {
  min-height: 150px;
  border: 0;
  padding: 4px 3px;
  background: transparent;
  resize: vertical;
}
.inline-note-controls { display: grid; grid-template-columns: minmax(140px, 1fr) auto; align-items: center; gap: 10px; }
.inline-note-tag { min-height: 42px; background: var(--surface-2); font-size: .8rem; font-weight: 700; }
.inline-note-buttons { display: flex; gap: 7px; }
.inline-note-buttons button { min-height: 42px; }
.inline-note-message { grid-column: 1 / -1; }
.empty-state { display: grid; min-height: 190px; place-content: center; justify-items: center; color: var(--muted); text-align: center; }
.empty-state:empty { display: none; }
.empty-state strong { color: var(--text); font-size: 1.05rem; }
.empty-state p { max-width: 300px; margin: 7px 0 0; font-size: .84rem; line-height: 1.5; }

.list-sidebar {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 50;
  width: min(100%, 540px);
  max-height: min(78svh, 700px);
  margin: auto;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 24px 24px 0 0;
  padding: 20px max(18px, env(safe-area-inset-right)) max(24px, env(safe-area-inset-bottom))
    max(18px, env(safe-area-inset-left));
  background: var(--surface);
  box-shadow: 0 -24px 64px -24px rgb(0 0 0 / 45%);
}
.sidebar-heading, .sheet-header { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-bottom: 18px; }
.list-form { display: grid; grid-template-columns: minmax(0, 1fr) 44px; gap: 8px; margin-bottom: 15px; }
.lists { display: grid; gap: 7px; margin: 0; padding: 0; list-style: none; }
.list-item { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px; border-radius: 13px; background: var(--surface-2); }
.select-list-button {
  min-width: 0;
  min-height: 48px;
  border: 0;
  padding: 0 12px;
  background: transparent;
  color: var(--text);
  text-align: left;
}
.select-list-button span { display: block; overflow: hidden; font-weight: 750; text-overflow: ellipsis; white-space: nowrap; }
.select-list-button small { color: var(--muted); }
.list-item.is-active { background: var(--primary-soft); }
.list-item-actions { display: flex; align-items: center; padding-right: 5px; }
.list-item-actions button { width: 32px; height: 32px; border: 0; border-radius: 9px; background: transparent; color: var(--muted); }
.list-edit-form { display: grid; grid-template-columns: 1fr auto; gap: 5px; padding: 5px; }
.list-edit-form input { min-height: 38px; }
.scrim { position: fixed; inset: 0; z-index: 40; border: 0; background: var(--scrim); backdrop-filter: blur(3px); }

.sheet-backdrop { position: fixed; inset: 0; z-index: 55; background: var(--scrim); backdrop-filter: blur(4px); }
.sheet {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 60;
  width: min(100%, 620px);
  max-height: min(90svh, 850px);
  margin: auto;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 25px 25px 0 0;
  padding: 22px max(18px, env(safe-area-inset-right)) max(26px, env(safe-area-inset-bottom))
    max(18px, env(safe-area-inset-left));
  background: var(--surface);
  box-shadow: 0 -24px 70px -30px rgb(0 0 0 / 60%);
}
.profile-block { display: flex; align-items: center; gap: 12px; margin-bottom: 22px; border-radius: 16px; padding: 13px; background: var(--surface-2); }
.profile-block > span { display: grid; width: 46px; height: 46px; place-items: center; border-radius: 14px; background: var(--primary-strong); color: #fff; font-size: 1.1rem; font-weight: 850; }
.profile-block p { margin: 0; }
#profile-name { font-weight: 800; }
#profile-email { margin-top: 3px; color: var(--muted); font-size: .78rem; }
.settings-section { display: grid; gap: 12px; margin-bottom: 20px; border-top: 1px solid var(--border); padding-top: 18px; }
.settings-section p { margin: 5px 0 0; color: var(--muted); font-size: .8rem; }
.theme-options { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; border-radius: 13px; padding: 4px; background: var(--surface-2); }
.theme-options button { min-height: 40px; border: 0; border-radius: 10px; background: transparent; color: var(--muted); font-weight: 750; }
.theme-options button[aria-pressed="true"] { background: var(--surface); color: var(--primary); box-shadow: var(--shadow-sm); }
.tag-settings-list { display: grid; gap: 7px; }
.tag-setting-row { display: grid; grid-template-columns: 18px minmax(0, 1fr); align-items: center; gap: 9px; }
.tag-setting-row i { width: 13px; height: 13px; border-radius: 50%; background: var(--tag-color); }
.tag-setting-row input { min-height: 42px; }

.app-message {
  position: fixed;
  top: max(12px, env(safe-area-inset-top));
  left: 50%;
  z-index: 80;
  display: flex;
  width: min(92vw, 520px);
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  transform: translateX(-50%);
  border: 1px solid color-mix(in srgb, var(--danger) 30%, transparent);
  border-radius: 14px;
  padding: 10px 10px 10px 14px;
  background: color-mix(in srgb, var(--danger-soft) 95%, transparent);
  color: var(--danger);
  font-size: .84rem;
  font-weight: 750;
  box-shadow: var(--shadow);
}
.app-message button { width: 32px; height: 32px; border: 0; border-radius: 9px; background: var(--danger-soft); color: var(--danger); font-size: 1.2rem; }
.app-update-button {
  position: fixed;
  top: max(70px, calc(env(safe-area-inset-top) + 58px));
  left: 50%;
  z-index: 90;
  min-height: 44px;
  transform: translateX(-50%);
  border: 0;
  border-radius: 99px;
  padding: 0 18px;
  background: var(--primary-strong);
  color: #fff;
  font-weight: 800;
  box-shadow: var(--shadow);
}

@media (max-width: 560px) {
  .app-shell { padding-top: max(13px, env(safe-area-inset-top)); }
  .topbar { gap: 10px; }
  .topbar h1 { max-width: 48vw; }
  .topbar-actions { gap: 6px; }
  .new-note-button { width: 44px; padding: 0; justify-content: center; }
  .new-note-button span { display: none; }
  .filter-row { grid-template-columns: minmax(0, 1fr) 112px; }
  .note-card { min-height: 82px; padding: 11px; }
  .note-actions { gap: 3px; }
  .icon-button.small { width: 34px; height: 34px; }
  .inline-note-editor { padding: 13px; }
  .inline-note-body { min-height: 190px; }
  .inline-note-controls { grid-template-columns: 1fr; }
  .inline-note-buttons { display: grid; grid-template-columns: repeat(2, 1fr); }
  .inline-note-buttons:has(.danger-button) { grid-template-columns: repeat(3, 1fr); }
  .inline-note-buttons button { padding: 0 10px; }
}

@media (min-width: 760px) {
  .auth-view { grid-template-columns: 1fr 430px 1fr; align-items: center; }
  .auth-brand { justify-content: flex-end; }
  .auth-panel { grid-column: 2; }
  .notes-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .note-card { min-height: 128px; }
}

@media (min-width: 980px) {
  .notes-view { display: grid; grid-template-columns: 240px minmax(0, 1fr); gap: 24px; }
  .notes-main { grid-column: 2; }
  .list-sidebar {
    position: sticky;
    top: 0;
    right: auto;
    bottom: auto;
    left: auto;
    z-index: 4;
    display: block;
    width: 100%;
    max-height: calc(100svh - 48px);
    margin: 0;
    grid-column: 1;
    border-radius: 18px;
    padding: 16px;
    box-shadow: var(--shadow-sm);
  }
  #close-lists, #open-lists { display: none; }
  .sheet { top: 50%; bottom: auto; border-radius: 24px; transform: translateY(-50%); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
  .loading-spinner { animation: none; }
}
