/* Notes — warm, quiet, ready to type */
:root {
  --bg: #f4f0e8;
  --paper: #fbfaf7;
  --sidebar: #efeae0;
  --ink: #1c1915;
  --muted: #7a7268;
  --faint: #b3aaa0;
  --line: #e4ddd2;
  --accent: #2d6a4f;
  --accent-soft: #e3efe8;
  --danger: #9b2c2c;
  --danger-soft: #f8e8e8;
  --shadow: 0 12px 40px rgba(40, 30, 16, 0.12);
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --sans: "Segoe UI", "SF Pro Text", "Helvetica Neue", system-ui, -apple-system, sans-serif;
  --sidebar-w: 280px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--sans);
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

.sr-only {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0,0,0,0); border: 0;
}
.hidden { display: none !important; }

/* ----- Login ----- */
.login {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(1200px 600px at 50% -10%, #fff8ee 0%, transparent 60%),
    var(--bg);
}
.login-card {
  width: min(100%, 360px);
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 36px 28px 28px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.login-card h1 {
  font-family: var(--serif);
  font-weight: 600;
  font-size: 32px;
  margin: 0 0 2px;
  letter-spacing: -0.02em;
}
.login-sub { margin: 0 0 14px; color: var(--muted); font-size: 14px; }
.login-card input {
  width: 100%;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 10px;
  padding: 12px 14px;
  font: 16px var(--sans);
  color: var(--ink);
  outline: none;
}
.login-card input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.login-card button {
  margin-top: 6px;
  border: 0;
  background: var(--accent);
  color: #fff;
  font: 600 15px var(--sans);
  padding: 12px 16px;
  border-radius: 10px;
  cursor: pointer;
}
.login-card button:hover { filter: brightness(1.06); }
.login-card button:disabled { opacity: 0.6; cursor: default; }
.login-error { margin: 4px 0 0; color: var(--danger); font-size: 13px; }

.login-warn {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

#username { display: none; } /* single-user; still submitted for password managers */

/* ----- App shell ----- */
.app {
  height: 100%;
  display: flex;
  background: var(--paper);
}
.sidebar {
  width: var(--sidebar-w);
  flex: 0 0 var(--sidebar-w);
  background: var(--sidebar);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding-top: var(--safe-top);
}
.sidebar-head { padding: 18px 16px 10px; }
.brand { display: flex; align-items: center; gap: 8px; margin-bottom: 14px; }
.brand h1 { font-family: var(--serif); font-size: 22px; margin: 0; font-weight: 600; }
.brand-mark {
  width: 12px; height: 12px; border-radius: 4px;
  background: var(--accent); display: inline-block;
}
.new-btn {
  width: 100%;
  border: 1px dashed #cfc6b8;
  background: transparent;
  color: var(--ink);
  font: 600 14px var(--sans);
  padding: 10px 12px;
  border-radius: 10px;
  cursor: pointer;
  margin-bottom: 10px;
}
.new-btn:hover { background: #fff; border-style: solid; border-color: var(--accent); color: var(--accent); }
.search-wrap { display: block; }
.search-wrap input {
  width: 100%;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 10px;
  padding: 9px 12px;
  font: 14px var(--sans);
  color: var(--ink);
  outline: none;
}
.search-wrap input:focus { border-color: var(--accent); }
.note-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px 10px 16px;
  min-height: 0;
}
.sidebar-foot {
  border-top: 1px solid var(--line);
  padding: 10px 16px calc(10px + var(--safe-bottom));
}

.cat-group { margin-bottom: 14px; }
.cat-label {
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 650;
  padding: 4px 8px 6px;
  display: flex;
  justify-content: space-between;
}
.cat-count { color: var(--faint); font-weight: 500; letter-spacing: 0; text-transform: none; }
.note-item {
  width: 100%;
  text-align: left;
  border: 0;
  background: transparent;
  border-radius: 10px;
  padding: 8px 10px;
  cursor: pointer;
  display: block;
  color: var(--ink);
  font: 14px var(--sans);
}
.note-item:hover { background: rgba(255,255,255,0.7); }
.note-item.active { background: #fff; box-shadow: 0 1px 0 var(--line); }
.note-item .title {
  display: block;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.note-item .preview {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.empty-list {
  color: var(--muted);
  font-size: 13px;
  padding: 16px 8px;
  line-height: 1.5;
}

/* ----- Editor ----- */
.editor-pane {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  background: var(--paper);
  padding-top: var(--safe-top);
}
.editor-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 20px;
  border-bottom: 1px solid transparent;
  min-height: 48px;
}
.meta { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0; flex-wrap: wrap; }
.pill {
  font-size: 11px;
  font-weight: 650;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  background: var(--accent-soft);
  color: var(--accent);
  padding: 3px 8px;
  border-radius: 999px;
  white-space: nowrap;
}
.tags { color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.save-state {
  color: var(--muted);
  font-size: 12px;
  min-width: 64px;
  text-align: right;
}
.save-state.saving { color: var(--muted); }
.save-state.saved { color: var(--accent); }
.save-state.error { color: var(--danger); }
.editor-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  width: 100%;
}
.editor {
  padding: 12px 8% 48px;
  max-width: 860px;
  margin: 0 auto;
  width: 100%;
}
.editor.is-empty::before {
  content: attr(data-placeholder);
  color: var(--faint);
  font: 21px/1.65 var(--serif);
  pointer-events: none;
  display: block;
  position: absolute;
}
.editor { position: relative; }
.date-section { margin: 0 0 4px; }
.date-heading {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  border: 0;
  background: transparent;
  color: var(--muted);
  font: 600 12px/1.4 var(--sans);
  letter-spacing: 0.04em;
  cursor: pointer;
  padding: 14px 0 6px;
  margin: 0;
  text-align: left;
  border-radius: 0;
}
.date-heading:hover { color: var(--ink); }
.date-heading .chev {
  display: inline-block;
  width: 0.7em;
  color: var(--faint);
  font-size: 10px;
}
.date-heading .rule {
  flex: 1;
  height: 1px;
  background: var(--line);
  margin-left: 4px;
}
.date-section.collapsed .date-heading { padding-bottom: 10px; }
.date-section.collapsed .date-body { display: none; }
.date-body {
  display: block;
  width: 100%;
  border: 0;
  outline: none;
  resize: none;
  overflow: hidden;
  padding: 0;
  margin: 0;
  background: transparent;
  color: var(--ink);
  font: 21px/1.65 var(--serif);
  min-height: 1.65em;
}
.date-body::placeholder { color: var(--faint); }

.text-btn, .icon-btn {
  border: 0;
  background: transparent;
  color: var(--muted);
  font: 13px var(--sans);
  cursor: pointer;
  padding: 6px 8px;
  border-radius: 8px;
}
.text-btn:hover, .icon-btn:hover { background: var(--sidebar); color: var(--ink); }
.text-btn.danger:hover { background: var(--danger-soft); color: var(--danger); }
.menu-btn { display: none; }

.backdrop {
  display: none;
}

/* ----- Hint ----- */
.hint {
  position: fixed;
  left: 50%;
  bottom: calc(20px + var(--safe-bottom));
  transform: translateX(-50%);
  background: var(--ink);
  color: #f7f3ec;
  padding: 12px 14px 12px 18px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  gap: 14px;
  box-shadow: var(--shadow);
  z-index: 40;
  max-width: calc(100% - 24px);
}
.hint p { margin: 0; font-size: 14px; }
.hint button {
  border: 0;
  background: #fff;
  color: var(--ink);
  font: 600 13px var(--sans);
  padding: 6px 10px;
  border-radius: 8px;
  cursor: pointer;
  white-space: nowrap;
}

/* ----- Mobile ----- */
@media (max-width: 800px) {
  .menu-btn { display: inline-flex; align-items: center; justify-content: center; }
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 30;
    transform: translateX(-105%);
    transition: transform 0.2s ease;
    box-shadow: var(--shadow);
  }
  .sidebar.open { transform: translateX(0); }
  .backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(28, 25, 21, 0.35);
    z-index: 20;
  }
  .backdrop.hidden { display: none !important; }
  .editor { padding: 12px 20px 40px; }
  .date-body { font-size: 19px; }
  .editor-bar { padding: 8px 12px; }
}

.note-item .when {
  display: block;
  color: var(--faint);
  font-size: 11px;
  margin-top: 1px;
}

.view-tabs {
  display: flex;
  gap: 4px;
  margin-top: 10px;
  background: rgba(255,255,255,0.45);
  border-radius: 10px;
  padding: 3px;
}
.view-tab {
  flex: 1;
  border: 0;
  background: transparent;
  color: var(--muted);
  font: 600 13px var(--sans);
  padding: 6px 8px;
  border-radius: 8px;
  cursor: pointer;
}
.view-tab.is-active {
  background: #fff;
  color: var(--ink);
  box-shadow: 0 1px 0 var(--line);
}
.tab-count {
  display: inline-block;
  min-width: 1.25em;
  margin-left: 2px;
  font-weight: 650;
  color: var(--accent);
}

.todo-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px 10px 16px;
  min-height: 0;
}
.todo-group { margin-bottom: 14px; }
.todo-group-head {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 650;
  padding: 4px 8px 6px;
  border: 0;
  background: transparent;
  cursor: pointer;
  text-align: left;
}
.todo-group-head .cat-count { color: var(--faint); font-weight: 500; letter-spacing: 0; text-transform: none; }
.todo-group.collapsed .todo-items { display: none; }
.todo-item {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  width: 100%;
  border: 0;
  background: transparent;
  border-radius: 10px;
  padding: 8px 10px;
  color: var(--ink);
  font: 14px var(--sans);
  text-align: left;
}
.todo-item:hover { background: rgba(255,255,255,0.7); }
.todo-item input[type="checkbox"] {
  margin: 3px 0 0;
  accent-color: var(--accent);
  flex: 0 0 auto;
}
.todo-item .todo-text { flex: 1; min-width: 0; }
.todo-item .todo-label {
  display: block;
  font-weight: 550;
  line-height: 1.35;
}
.todo-item.is-done .todo-label {
  color: var(--muted);
  text-decoration: line-through;
}
.todo-item .todo-src {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.todo-item .todo-open {
  border: 0;
  background: transparent;
  padding: 0;
  margin: 0;
  font: inherit;
  color: inherit;
  text-align: left;
  cursor: pointer;
  flex: 1;
  min-width: 0;
}
