:root {
  color-scheme: light;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --bg: #f7f3ec;
  --surface: #fffaf3;
  --surface-2: #f0e8dd;
  --border: #ded2c4;
  --border-input: #d6cabe;
  --border-soft: #eadfcc;
  --text: #241c15;
  --muted: #6f6257;
  --meta: #8a7c6f;
  --accent: #7b4b1f;
  --gold: #efe2bf;
  --hover-border: #c9b9a8;
  --danger: #8f2f26;
  --button-bg: #241c15;
  --button-text: #ffffff;
  background: var(--bg);
  color: var(--text);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
}

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

button {
  border: 1px solid var(--button-bg);
  border-radius: 0.5rem;
  padding: 0.65rem 0.9rem;
  background: var(--button-bg);
  color: var(--button-text);
  cursor: pointer;
  font-weight: 700;
}

button.secondary, .nav-button {
  background: transparent;
  color: var(--text);
  border-color: var(--border-input);
}

button.danger { background: var(--danger); border-color: var(--danger); color: white; }
button:disabled { cursor: not-allowed; opacity: 0.45; }

input, select, textarea {
  width: 100%;
  border: 1px solid var(--border-input);
  border-radius: 0.5rem;
  padding: 0.75rem;
  background: var(--surface);
  color: var(--text);
}

:where(button, input, select, textarea):focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

textarea { resize: vertical; }

label {
  display: grid;
  gap: 0.45rem;
  margin: 0.85rem 0;
  font-weight: 700;
}

.shell {
  width: min(920px, calc(100% - 2rem));
  margin: 0 auto;
  padding: 2rem 0 4rem;
}

.is-app .shell {
  width: 100%;
  padding: 0;
}

.is-app .hero { display: none; }

.hero {
  margin: 2rem 0;
  max-width: 680px;
}

.hero-brand {
  display: flex;
  align-items: center;
  gap: 0.9rem;
  margin-bottom: 1rem;
}

.hero-logo {
  display: block;
}

.hero-name {
  font-size: clamp(1.6rem, 6vw, 2rem);
  font-weight: 900;
  letter-spacing: -0.02em;
}

.hero h1 {
  margin: 0;
  font-size: clamp(2.5rem, 8vw, 5rem);
  line-height: 0.95;
  letter-spacing: -0.06em;
}

.hero p { font-size: 1.05rem; max-width: 38rem; color: var(--muted); }
.eyebrow { text-transform: uppercase; letter-spacing: 0.14em; font-size: 0.72rem; font-weight: 900; color: var(--accent); }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0.75rem;
  padding: 1rem;
}

.auth-card { max-width: 480px; margin: 0 auto; }
.hidden { display: none !important; }

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

.dashboard {
  min-height: 100vh;
  padding-top: 64px;
}

.app-bar {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 20;
  width: 100%;
  min-height: 64px;
  display: grid;
  grid-template-columns: 180px minmax(180px, 560px) auto;
  align-items: center;
  gap: 1rem;
  padding: 0.65rem 1rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.brand-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.brand-row strong { font-size: 1.25rem; font-weight: 900; }

.search-box {
  display: block;
  margin: 0;
  padding-left: 20px;
}

.search-box input {
  border-color: transparent;
  background: var(--surface-2);
}

.topbar-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.65rem;
}

.avatar {
  display: grid;
  place-items: center;
  width: 2rem;
  height: 2rem;
  border-radius: 50%;
  background: var(--accent);
  color: white;
  font-weight: 800;
  font-size: 0.9rem;
}

.topbar-actions #user-avatar {
  margin-right: 0.4rem;
}

.topbar-username {
  color: var(--muted);
  font-weight: 700;
  white-space: nowrap;
  font-size: 0.9rem;
}

.topbar-button {
  padding: 0.5rem 0.9rem;
  font-size: 0.9rem;
}

.nav-button.active {
  background: var(--gold);
  border-color: var(--gold);
}

.keep-shell {
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
}

.keep-sidebar {
  position: fixed;
  top: 64px;
  bottom: 0;
  left: 0;
  width: 220px;
  padding: 1rem 0.75rem;
  overflow-y: auto;
  background: var(--bg);
  border-right: 1px solid var(--border-soft);
}

.side-item {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.25rem;
  border: 0;
  border-radius: 0.5rem;
  padding: 0.75rem 0.85rem;
  background: transparent;
  color: var(--text);
  text-align: left;
}

.side-item.active {
  background: var(--gold);
  font-weight: 800;
}

.side-item:hover:not(.active) {
  background: var(--surface-2);
}

.side-badge {
  display: inline-block;
  padding: 0.05rem 0.5rem;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
}

.side-item.active .side-badge { background: var(--surface); }

.dashboard-main {
  grid-column: 2;
  min-width: 0;
  padding: 2rem;
}

.dashboard-view {
  display: grid;
  gap: 1rem;
}

.note-composer {
  width: min(680px, 100%);
  margin: 0 auto 1.5rem;
  border: 1px solid var(--border);
  border-radius: 0.75rem;
  background: var(--surface);
  overflow: hidden;
}

.note-composer textarea {
  min-height: 3.3rem;
  border: 0;
  border-radius: 0;
  padding: 1rem;
  background: transparent;
  color: var(--text);
  outline: none;
  line-height: 1.5;
}

.composer-details {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem;
  border-top: 1px solid var(--border-soft);
}

.composer-details select { max-width: 220px; }

.page-heading {
  width: min(1120px, 100%);
  margin: 0 auto 1rem;
  color: var(--muted);
}

.page-heading h2 {
  margin: 0;
  color: var(--text);
}

.page-heading p { margin: 0.25rem 0 0; }

.notes-controls {
  width: min(1120px, 100%);
  margin: 0 auto;
  display: flex;
  gap: 0.5rem;
}

.notes-controls select { max-width: 220px; }

.bin-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
}

.plain-list, .notes-list {
  list-style: none;
  padding: 0;
  margin: 1rem 0 0;
  display: grid;
  gap: 0.75rem;
}

.notes-list {
  width: min(1120px, 100%);
  margin: 0 auto;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  align-items: start;
}

.plain-list li, .notes-list li {
  border: 1px solid var(--border);
  border-radius: 0.75rem;
  padding: 1rem;
  background: var(--surface);
  color: var(--text);
}

.notes-list li {
  min-height: 8rem;
  display: grid;
  gap: 0.65rem;
  padding: 1.1rem;
  line-height: 1.5;
  transition: border-color 0.15s ease;
}

.notes-list li:hover {
  border-color: var(--hover-border);
}

.notes-list li p { white-space: pre-wrap; }
.meta { margin: 0; color: var(--muted); font-size: 0.85rem; }
.notes-list li .meta {
  font-size: 0.8rem;
  color: var(--meta);
  letter-spacing: 0.01em;
}
.meta .category-name { font-weight: 700; color: var(--text); }

.note-text {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 8;
  overflow: hidden;
  overflow-wrap: anywhere;
}
.notes-list li.expanded .note-text { -webkit-line-clamp: unset; }
.clamp-toggle {
  justify-self: start;
  padding: 0.35rem 0.75rem;
  font-size: 0.8rem;
}

.note-editor {
  display: grid;
  gap: 0.6rem;
}
.note-editor textarea {
  width: 100%;
  min-height: 3.3rem;
  border: 1px solid var(--border-input);
  border-radius: 0.5rem;
  padding: 0.75rem;
  background: var(--surface);
  color: var(--text);
  line-height: 1.5;
  resize: vertical;
}
.note-editor select { max-width: 220px; }

.empty {
  color: var(--muted);
  display: grid;
  place-items: center;
  min-height: 6rem;
  text-align: center;
  border: 1px dashed var(--border);
  border-radius: 0.75rem;
  font-weight: 600;
  background: var(--surface);
}

.actions, .plain-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.manage-list li {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 0.5rem;
}

.manage-list .count {
  color: var(--muted);
  font-weight: 600;
  font-size: 0.85rem;
  margin-left: 0.4rem;
}

.actions button {
  padding: 0.45rem 0.8rem;
  font-size: 0.85rem;
}

.manage-card {
  width: min(680px, 100%);
  margin: 0 auto;
}

.category-create-panel {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0.75rem;
  align-items: center;
  margin: 1rem 0;
}

.settings-card,
#admin-panel {
  padding: 1.5rem;
  display: grid;
  gap: 0.25rem;
}

.settings-card p:last-child { margin-bottom: 0; }
.settings-card h2,
#admin-panel h2 {
  margin: 0;
}

#account-summary {
  margin: 0.25rem 0 0;
}

.password-form {
  display: grid;
  gap: 0.5rem;
  margin-top: 0.75rem;
  max-width: 420px;
}
.password-form button { margin-top: 0.5rem; }

.user-form { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 0.75rem; align-items: end; }
.check-label { display: flex; align-items: center; gap: 0.55rem; margin-bottom: 0.85rem; }
.check-label input { width: auto; }

#message {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  z-index: 40;
  min-height: 1.5rem;
  font-weight: 800;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0.6rem;
  padding: 0.6rem 0.9rem;
  box-shadow: 0 4px 12px rgba(36, 28, 21, 0.08);
  opacity: 0;
  transform: translateY(4px);
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

#message.visible { opacity: 1; transform: none; }

#message.error { color: var(--danger); }

@media (max-width: 760px) {
  .app-bar {
    grid-template-columns: 1fr auto;
    gap: 0.75rem;
  }

  .search-box {
    grid-column: 1 / -1;
    order: 3;
  }

  .topbar-actions { gap: 0.4rem; }
  .topbar-button { padding: 0.45rem 0.7rem; font-size: 0.85rem; }
  .topbar-username { display: none; }
  .dashboard { padding-top: 116px; }
  .keep-shell { grid-template-columns: 1fr; }
  .keep-sidebar {
    position: static;
    width: auto;
    display: flex;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
    border-right: 0;
    border-bottom: 1px solid var(--border-soft);
    overflow-x: auto;
  }
  .side-item { width: auto; white-space: nowrap; }
  .dashboard-main { grid-column: 1; padding: 1rem; }
  .notes-list { grid-template-columns: 1fr; }
  .composer-details { align-items: stretch; flex-direction: column; }
  .composer-details select { max-width: none; }
  .category-create-panel, .user-form { grid-template-columns: 1fr; }
  .settings-card,
  #admin-panel { padding: 1.1rem; }
  .hero h1 { letter-spacing: -0.05em; }
  .bin-heading { flex-direction: column; align-items: stretch; }
}
