:root {
  color-scheme: light;
  --black: #000000;
  --near-black: #121212;
  --dark-gray: #333333;
  --mid-gray: #707070;
  --line: #d9d9d9;
  --soft-line: #ececec;
  --paper: #ffffff;
  --wash: #f6f6f6;
  --danger: #9d1111;
  --sidebar-width: 270px;
  --radius: 14px;
  --shadow: 0 20px 60px rgba(0, 0, 0, 0.13);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
  margin: 0;
  background: var(--paper);
  color: var(--black);
}

body {
  min-width: 320px;
}

button,
input,
textarea,
select {
  font: inherit;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--paper);
  color: var(--black);
  outline: none;
  transition: border-color 140ms ease, box-shadow 140ms ease;
}

input,
select {
  height: 46px;
  padding: 0 13px;
}

textarea {
  min-height: 220px;
  resize: vertical;
  padding: 13px;
  line-height: 1.55;
}

input:focus,
textarea:focus,
select:focus {
  border-color: var(--black);
  box-shadow: 0 0 0 3px rgba(0, 0, 0, 0.08);
}

label {
  display: block;
  margin-bottom: 7px;
  font-size: 0.86rem;
  font-weight: 700;
}

code {
  padding: 2px 6px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: var(--wash);
}

[hidden] {
  display: none !important;
}

.noscript {
  padding: 18px;
  background: var(--black);
  color: var(--paper);
  text-align: center;
}

.screen {
  min-height: 100vh;
}

.center-screen,
.auth-screen {
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(to right, transparent 49.8%, rgba(0, 0, 0, 0.035) 50%, transparent 50.2%),
    linear-gradient(to bottom, transparent 49.8%, rgba(0, 0, 0, 0.035) 50%, transparent 50.2%),
    var(--paper);
  background-size: 52px 52px;
}

.auth-panel,
.setup-card {
  width: min(100%, 430px);
  border: 1px solid var(--black);
  border-radius: 20px;
  background: var(--paper);
  padding: clamp(28px, 6vw, 52px);
  box-shadow: var(--shadow);
}

.auth-panel h1,
.setup-card h1 {
  margin: 8px 0 6px;
  font-size: clamp(2.4rem, 9vw, 4.5rem);
  line-height: 0.95;
  letter-spacing: -0.065em;
}

.auth-copy {
  margin: 0 0 32px;
  color: var(--mid-gray);
}

.eyebrow {
  margin: 0;
  color: var(--mid-gray);
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.16em;
}

.brand-mark {
  display: grid;
  width: 50px;
  height: 50px;
  place-items: center;
  border-radius: 11px;
  background: var(--black);
  color: var(--paper);
  font-size: 1.45rem;
  font-weight: 900;
}

.brand-mark.small {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  font-size: 1rem;
}

.auth-form {
  display: grid;
  gap: 8px;
}

.auth-form label:not(:first-child) {
  margin-top: 10px;
}

.password-field {
  position: relative;
}

.password-field input {
  padding-right: 74px;
}

.password-toggle {
  position: absolute;
  top: 50%;
  right: 12px;
  transform: translateY(-50%);
}

.button {
  min-height: 44px;
  border: 1px solid var(--black);
  border-radius: 10px;
  padding: 0 17px;
  font-weight: 800;
  transition: transform 120ms ease, background 120ms ease, color 120ms ease;
}

.button:active:not(:disabled) {
  transform: translateY(1px);
}

.button.primary {
  background: var(--black);
  color: var(--paper);
}

.button.primary:hover:not(:disabled) {
  background: var(--dark-gray);
}

.button.secondary,
.button.ghost {
  background: var(--paper);
  color: var(--black);
}

.button.secondary:hover:not(:disabled),
.button.ghost:hover:not(:disabled) {
  background: var(--wash);
}

.button.danger {
  border-color: var(--danger);
  background: var(--danger);
  color: var(--paper);
}

.full-width {
  width: 100%;
  margin-top: 18px;
}

.text-button,
.icon-button,
.clear-search {
  border: 0;
  background: transparent;
  color: inherit;
}

.text-button {
  padding: 2px;
  font-size: 0.82rem;
  font-weight: 800;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.icon-button {
  display: inline-grid;
  width: 40px;
  height: 40px;
  flex: 0 0 auto;
  place-items: center;
  border-radius: 9px;
  font-size: 1.35rem;
  line-height: 1;
}

.icon-button:hover {
  background: var(--wash);
}

.icon-button.compact {
  width: 30px;
  height: 30px;
}

.form-error {
  margin: 9px 0 0;
  color: var(--danger);
  font-size: 0.82rem;
  font-weight: 700;
}

.muted {
  color: var(--mid-gray);
  font-weight: 500;
}

.app {
  min-height: 100vh;
}

.sidebar {
  position: fixed;
  z-index: 20;
  inset: 0 auto 0 0;
  display: flex;
  width: var(--sidebar-width);
  flex-direction: column;
  border-right: 1px solid var(--line);
  background: var(--paper);
}

.sidebar-header {
  display: flex;
  min-height: 76px;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--soft-line);
  padding: 0 18px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  color: var(--black);
  font-size: 1.15rem;
  font-weight: 900;
  letter-spacing: -0.03em;
  text-decoration: none;
}

.main-nav,
.folder-list {
  display: grid;
  gap: 4px;
  padding: 14px 12px 0;
}

.nav-item,
.folder-item {
  display: flex;
  width: 100%;
  min-height: 43px;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--dark-gray);
  padding: 0 12px;
  text-align: left;
  font-size: 0.9rem;
  font-weight: 650;
}

.nav-item:hover,
.folder-item:hover,
.nav-item.active,
.folder-item.active {
  background: var(--black);
  color: var(--paper);
}

.count {
  min-width: 20px;
  color: currentColor;
  font-variant-numeric: tabular-nums;
  text-align: right;
  opacity: 0.66;
}

.folders-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 24px 19px 0;
  color: var(--mid-gray);
  font-size: 0.69rem;
  font-weight: 900;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.folder-list {
  overflow-y: auto;
  padding-bottom: 16px;
}

.folder-item-wrapper {
  position: relative;
}

.folder-item {
  padding-right: 68px;
}

.folder-item-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.folder-actions {
  position: absolute;
  top: 50%;
  right: 8px;
  display: flex;
  gap: 1px;
  transform: translateY(-50%);
  opacity: 0;
  transition: opacity 120ms ease;
}

.folder-item-wrapper:hover .folder-actions,
.folder-item-wrapper:focus-within .folder-actions {
  opacity: 1;
}

.folder-item.active + .folder-actions .mini-action,
.folder-item:hover + .folder-actions .mini-action {
  color: var(--paper);
}

.mini-action {
  display: grid;
  width: 26px;
  height: 26px;
  place-items: center;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--black);
  font-size: 0.76rem;
  font-weight: 900;
}

.mini-action:hover {
  background: rgba(127, 127, 127, 0.22);
}

.sidebar-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: auto;
  border-top: 1px solid var(--soft-line);
  padding: 17px 18px;
}

.sidebar-footer div {
  min-width: 0;
}

.sidebar-footer strong,
.sidebar-footer span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar-footer strong {
  font-size: 0.83rem;
}

.sidebar-footer span {
  margin-top: 2px;
  color: var(--mid-gray);
  font-size: 0.7rem;
}

.workspace {
  min-height: 100vh;
  margin-left: var(--sidebar-width);
}

.topbar {
  position: sticky;
  z-index: 10;
  top: 0;
  display: flex;
  min-height: 92px;
  align-items: center;
  gap: 18px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.95);
  padding: 17px clamp(20px, 4vw, 54px);
  backdrop-filter: blur(12px);
}

.page-heading {
  min-width: 160px;
}

.page-heading h1 {
  margin: 0;
  overflow: hidden;
  font-size: clamp(1.3rem, 2.4vw, 1.85rem);
  letter-spacing: -0.04em;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.page-heading p {
  margin: 3px 0 0;
  color: var(--mid-gray);
  font-size: 0.75rem;
}

.topbar-actions {
  display: flex;
  flex: 1;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
}

.search-box {
  position: relative;
  display: flex;
  width: min(100%, 390px);
  align-items: center;
  margin: 0;
}

.search-box > span {
  position: absolute;
  left: 13px;
  color: var(--mid-gray);
  font-size: 1.3rem;
  pointer-events: none;
}

.search-box input {
  padding: 0 42px 0 39px;
  background: var(--wash);
}

.clear-search {
  position: absolute;
  right: 8px;
  width: 32px;
  height: 32px;
  border-radius: 7px;
  font-size: 1.2rem;
}

.clear-search:hover {
  background: var(--soft-line);
}

.content {
  padding: clamp(24px, 4vw, 52px);
}

.notes-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 280px), 1fr));
  gap: 16px;
  align-items: start;
}

.note-card {
  position: relative;
  display: flex;
  min-height: 190px;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--paper);
  padding: 19px;
  text-align: left;
  transition: border-color 130ms ease, box-shadow 130ms ease, transform 130ms ease;
}

.note-card:hover,
.note-card:focus-within {
  border-color: var(--black);
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.08);
  transform: translateY(-2px);
}

.note-card.pinned {
  border-width: 2px;
  border-color: var(--black);
}

.note-card-main {
  width: 100%;
  flex: 1;
  border: 0;
  background: transparent;
  color: inherit;
  padding: 0;
  text-align: left;
}

.note-card-topline {
  display: flex;
  min-height: 20px;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 13px;
}

.folder-badge,
.pin-badge {
  display: inline-block;
  overflow: hidden;
  max-width: 70%;
  color: var(--mid-gray);
  font-size: 0.65rem;
  font-weight: 850;
  letter-spacing: 0.08em;
  text-overflow: ellipsis;
  text-transform: uppercase;
  white-space: nowrap;
}

.pin-badge {
  color: var(--black);
}

.note-title {
  margin: 0 0 10px;
  overflow-wrap: anywhere;
  font-size: 1.03rem;
  line-height: 1.28;
  letter-spacing: -0.02em;
}

.note-content {
  display: -webkit-box;
  margin: 0;
  overflow: hidden;
  color: var(--dark-gray);
  font-size: 0.88rem;
  line-height: 1.5;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 7;
}

.note-card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 22px;
  border-top: 1px solid var(--soft-line);
  padding-top: 12px;
}

.note-date {
  color: var(--mid-gray);
  font-size: 0.68rem;
}

.note-actions {
  display: flex;
  gap: 3px;
}

.card-action {
  min-height: 30px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  padding: 0 8px;
  color: var(--dark-gray);
  font-size: 0.7rem;
  font-weight: 800;
}

.card-action:hover {
  background: var(--wash);
  color: var(--black);
}

.card-action.delete:hover {
  background: #f9e9e9;
  color: var(--danger);
}

.empty-state,
.loading-state {
  display: grid;
  min-height: calc(100vh - 210px);
  place-items: center;
  align-content: center;
  text-align: center;
}

.empty-state h2 {
  margin: 8px 0;
  font-size: 1.5rem;
  letter-spacing: -0.04em;
}

.empty-state p {
  max-width: 440px;
  margin: 0 0 20px;
  color: var(--mid-gray);
  line-height: 1.55;
}

.empty-symbol {
  display: grid;
  width: 62px;
  height: 62px;
  place-items: center;
  border: 2px solid var(--black);
  border-radius: 14px;
  font-size: 2rem;
}

.loading-state {
  min-height: calc(100vh - 210px);
  color: var(--mid-gray);
  gap: 12px;
}

.spinner {
  width: 28px;
  height: 28px;
  border: 3px solid var(--line);
  border-top-color: var(--black);
  border-radius: 50%;
  animation: spin 700ms linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.dialog {
  width: min(calc(100% - 28px), 680px);
  max-height: min(90vh, 840px);
  overflow: auto;
  border: 1px solid var(--black);
  border-radius: 18px;
  background: var(--paper);
  color: var(--black);
  padding: 0;
  box-shadow: var(--shadow);
}

.dialog::backdrop {
  background: rgba(0, 0, 0, 0.48);
  backdrop-filter: blur(3px);
}

.small-dialog,
.confirm-dialog {
  width: min(calc(100% - 28px), 480px);
}

.dialog-header,
.dialog-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 20px 22px;
}

.dialog-header {
  border-bottom: 1px solid var(--line);
}

.dialog-header h2 {
  margin: 4px 0 0;
  font-size: 1.25rem;
  letter-spacing: -0.03em;
}

.dialog-body {
  padding: 22px;
}

.dialog-body label:not(:first-child) {
  margin-top: 20px;
}

.dialog-footer {
  justify-content: flex-end;
  border-top: 1px solid var(--line);
}

.field-meta {
  display: flex;
  justify-content: flex-end;
  margin-top: 6px;
  color: var(--mid-gray);
  font-size: 0.7rem;
}

.form-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
  gap: 20px;
  margin-top: 17px;
}

.field-group label {
  margin-top: 0 !important;
}

.check-field {
  display: flex;
  min-height: 46px;
  align-items: center;
  gap: 9px;
  margin: 0 !important;
  white-space: nowrap;
}

.check-field input {
  width: 18px;
  height: 18px;
  accent-color: var(--black);
}

.toast-region {
  position: fixed;
  z-index: 100;
  right: 20px;
  bottom: 20px;
  display: grid;
  width: min(calc(100% - 40px), 360px);
  gap: 9px;
}

.toast {
  border: 1px solid var(--black);
  border-radius: 10px;
  background: var(--black);
  color: var(--paper);
  padding: 13px 15px;
  box-shadow: var(--shadow);
  font-size: 0.84rem;
  line-height: 1.4;
  animation: toast-in 180ms ease-out;
}

.toast.error {
  border-color: var(--danger);
  background: var(--danger);
}

@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
}

.sidebar-overlay {
  position: fixed;
  z-index: 15;
  inset: 0;
  background: rgba(0, 0, 0, 0.42);
}

.mobile-only {
  display: none;
}

@media (max-width: 840px) {
  .mobile-only {
    display: inline-grid;
  }

  .sidebar {
    width: min(86vw, var(--sidebar-width));
    transform: translateX(-103%);
    transition: transform 180ms ease;
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .workspace {
    margin-left: 0;
  }

  .topbar {
    min-height: auto;
    flex-wrap: wrap;
    gap: 12px;
    padding: 14px 16px;
  }

  .page-heading {
    flex: 1;
  }

  .topbar-actions {
    width: 100%;
  }

  .search-box {
    max-width: none;
  }

  .content {
    padding: 20px 16px 36px;
  }
}

@media (max-width: 540px) {
  .topbar-actions .button {
    padding-inline: 12px;
  }

  .notes-grid {
    grid-template-columns: 1fr;
  }

  .form-row {
    grid-template-columns: 1fr;
    gap: 4px;
  }

  .check-field {
    min-height: 40px;
  }

  .dialog-header,
  .dialog-body,
  .dialog-footer {
    padding: 17px;
  }

  .dialog-footer .button {
    flex: 1;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
