:root {
  color-scheme: light;
  --bg: #f5f7fb;
  --panel: #ffffff;
  --panel-2: #eef3f8;
  --text: #18202f;
  --muted: #647085;
  --line: #dce3ec;
  --accent: #0f766e;
  --accent-2: #2563eb;
  --danger: #dc2626;
  --shadow: 0 18px 48px rgba(25, 35, 55, .12);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  background: var(--bg);
  font: 14px/1.5 Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
button, input, textarea, select { font: inherit; }
button {
  border: 0;
  border-radius: 8px;
  background: var(--panel-2);
  color: var(--text);
  cursor: pointer;
}
button:hover { filter: brightness(.97); }
.hidden { display: none !important; }
.eyebrow {
  margin: 0 0 6px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}
.auth-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(135deg, rgba(15,118,110,.18), transparent 36%),
    linear-gradient(315deg, rgba(37,99,235,.14), transparent 38%),
    var(--bg);
}
.auth-panel {
  width: min(420px, 100%);
  padding: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255,255,255,.94);
  box-shadow: var(--shadow);
}
.auth-panel h1 { margin: 0 0 24px; font-size: 30px; }
.auth-form { display: grid; gap: 12px; }
.auth-form input, .searchbar input, .meta-row input, .meta-row select, .searchbar select, .title-input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  outline: none;
}
.auth-form input { padding: 13px 14px; }
.auth-form input:focus, .searchbar input:focus, .meta-row input:focus, .meta-row select:focus, .searchbar select:focus, .title-input:focus, .tiptap-surface:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(15,118,110,.12);
}
.auth-form button, .primary {
  padding: 12px 14px;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
}
.auth-form .ghost {
  background: transparent;
  color: var(--accent-2);
}
.error { min-height: 20px; margin: 0; color: var(--danger); }

.app {
  height: 100vh;
  display: grid;
  grid-template-columns: 260px minmax(280px, 390px) minmax(0, 1fr);
  overflow: hidden;
}
.sidebar, .notes-pane, .editor-pane {
  min-width: 0;
  min-height: 0;
  border-right: 1px solid var(--line);
  background: var(--panel);
}
.sidebar {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 20px;
}
.brand, .section-head, .editor-top, .tabs, .attachments {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.brand strong { display: block; font-size: 18px; overflow: hidden; text-overflow: ellipsis; }
.icon-btn {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
}
.views, .category-list { display: grid; gap: 6px; }
.views button, .category-list button {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  padding: 10px 12px;
  background: transparent;
  text-align: left;
}
.views button.active, .category-list button.active {
  background: #e7f4f2;
  color: #0f5f59;
  font-weight: 700;
}
.section-head {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}
.notes-pane {
  display: grid;
  grid-template-rows: auto 1fr;
}
.searchbar {
  display: grid;
  grid-template-columns: 1fr 116px;
  gap: 8px;
  padding: 16px;
  border-bottom: 1px solid var(--line);
}
.searchbar input, .searchbar select, .meta-row input, .meta-row select {
  min-height: 38px;
  padding: 8px 10px;
}
.note-list {
  overflow: auto;
  padding: 8px;
}
.note-card {
  display: grid;
  gap: 7px;
  width: 100%;
  padding: 13px;
  border-radius: 8px;
  background: transparent;
  text-align: left;
}
.note-card.active { background: #edf6f5; }
.note-card strong {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.note-card p {
  height: 42px;
  margin: 0;
  overflow: hidden;
  color: var(--muted);
}
.note-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
}
.chip {
  padding: 2px 7px;
  border-radius: 999px;
  background: var(--panel-2);
}
.editor-pane {
  position: relative;
  display: grid;
  min-width: 0;
  background: #fbfcfe;
}
.empty-state {
  place-self: center;
  color: var(--muted);
  text-align: center;
}
.editor {
  height: 100vh;
  display: grid;
  grid-template-rows: auto auto auto minmax(0, 1fr) auto;
}
.editor-top {
  padding: 18px 22px 12px;
  border-bottom: 1px solid var(--line);
  background: #fff;
}
.title-input {
  min-width: 0;
  border: 0;
  padding: 4px 0;
  background: transparent;
  font-size: 26px;
  font-weight: 800;
}
.toolbar { display: flex; gap: 6px; }
.toolbar button {
  width: 36px;
  height: 36px;
  font-weight: 800;
}
.toolbar button.on { background: #d9f0ec; color: var(--accent); }
.toolbar button#restoreBtn {
  background: #e7f4f2;
  color: var(--accent);
}
.meta-row {
  display: grid;
  grid-template-columns: 150px 120px minmax(140px, 1fr) 50px;
  gap: 8px;
  padding: 12px 22px;
  border-bottom: 1px solid var(--line);
  background: #fff;
}
.tabs {
  justify-content: flex-start;
  flex-wrap: wrap;
  padding: 8px 22px;
  border-bottom: 1px solid var(--line);
  background: #fff;
}
.tabs button {
  min-width: 34px;
  height: 32px;
  padding: 6px 9px;
  background: transparent;
  font-weight: 700;
}
.tabs button.active { background: var(--panel-2); color: var(--accent); }
#saveState {
  margin-left: auto;
  color: var(--muted);
  font-size: 12px;
}
#editorStats {
  margin-left: auto;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}
#editorStats + #saveState { margin-left: 0; }
.rich-editor {
  width: 100%;
  min-width: 0;
  height: 100%;
  background: #fbfcfe;
  overflow: auto;
}
.tiptap-surface {
  min-height: 100%;
  padding: 24px;
  border: 0;
  outline: none;
  color: var(--text);
  font: 16px/1.7 ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
.tiptap-surface > *:first-child { margin-top: 0; }
.tiptap-surface > *:last-child { margin-bottom: 0; }
.tiptap-surface h1, .tiptap-surface h2, .tiptap-surface h3 {
  line-height: 1.25;
  margin: 1.1em 0 .45em;
}
.tiptap-surface p { margin: .65em 0; }
.tiptap-surface ul, .tiptap-surface ol {
  padding-left: 1.4em;
}
.tiptap-surface ul[data-type="taskList"] {
  padding-left: 0;
  list-style: none;
}
.tiptap-surface li[data-type="taskItem"] {
  display: flex;
  gap: 8px;
}
.tiptap-surface li[data-type="taskItem"] > label {
  flex: 0 0 auto;
  user-select: none;
}
.tiptap-surface li[data-type="taskItem"] > div {
  flex: 1 1 auto;
}
.tiptap-surface a {
  color: var(--accent-2);
}
.tiptap-surface pre {
  overflow: auto;
  padding: 12px;
  border-radius: 8px;
  background: #111827;
  color: #f9fafb;
}
.tiptap-surface code {
  padding: 2px 5px;
  border-radius: 5px;
  background: #e8edf4;
}
.tiptap-surface pre code {
  padding: 0;
  background: transparent;
}
.tiptap-surface blockquote {
  margin-left: 0;
  padding-left: 14px;
  border-left: 4px solid var(--line);
  color: var(--muted);
}
.tiptap-surface p.is-editor-empty:first-child::before {
  content: attr(data-placeholder);
  float: left;
  height: 0;
  color: #9aa5b5;
  pointer-events: none;
}
.attachments {
  align-items: flex-start;
  padding: 12px 22px;
  border-top: 1px solid var(--line);
  background: #fff;
}
.file-btn {
  display: inline-flex;
  min-width: 88px;
  padding: 9px 12px;
  border-radius: 8px;
  background: var(--panel-2);
  cursor: pointer;
}
.file-btn input { display: none; }
#attachmentList {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 240px));
  justify-content: end;
  gap: 8px;
  max-width: 76%;
}
.attachment-card {
  position: relative;
  display: grid;
  gap: 7px;
  min-width: 0;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfe;
  color: var(--text);
}
.attachment-card a {
  color: var(--text);
  text-decoration: none;
}
.attachment-card button {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 22px;
  height: 22px;
  border-radius: 999px;
  color: var(--danger);
  background: rgba(255,255,255,.92);
}
.media-preview {
  display: grid;
  place-items: center;
  width: 100%;
  min-height: 92px;
  border-radius: 6px;
  overflow: hidden;
  background: var(--panel-2);
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}
.media-preview img,
.media-preview video {
  width: 100%;
  max-height: 180px;
  object-fit: contain;
  background: #eef3f8;
}
.audio-preview {
  min-height: 54px;
  padding: 8px;
}
.audio-preview audio { width: 100%; }
.attachment-meta {
  display: grid;
  gap: 2px;
  min-width: 0;
}
.attachment-meta > a {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding-right: 20px;
}
.attachment-meta span a {
  color: var(--accent-2);
}
.attachment-meta span {
  color: var(--muted);
  font-size: 12px;
}
.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  max-width: min(360px, calc(100vw - 36px));
  padding: 12px 14px;
  border-radius: 8px;
  background: #111827;
  color: #fff;
  box-shadow: var(--shadow);
}

@media (max-width: 980px) {
  .app { grid-template-columns: 210px minmax(220px, 320px) minmax(0, 1fr); }
  .sidebar { padding: 14px; }
  .meta-row { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 760px) {
  .app {
    height: auto;
    min-height: 100vh;
    grid-template-columns: 1fr;
    overflow: auto;
  }
  .sidebar, .notes-pane, .editor-pane { border-right: 0; border-bottom: 1px solid var(--line); }
  .sidebar { min-height: auto; }
  .editor, .editor-pane { height: 72vh; }
  .searchbar { grid-template-columns: 1fr; }
  .title-input { font-size: 22px; }
  .attachments { flex-direction: column; }
  #attachmentList {
    width: 100%;
    max-width: none;
    justify-content: stretch;
    grid-template-columns: 1fr;
  }
}
