/* ============================================================
   NOTES — Apple Notes-style layout
   Uses CSS vars from base.css: --surface, --surface-2, --border,
   --border-soft, --text, --muted, --accent, --primary, --radius,
   --radius-sm, --shadow-sm
   ============================================================ */

.notes-app {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 0;
  height: calc(100vh - 220px);
  min-height: 560px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}

/* ---- Left list ---- */
.notes-list {
  border-right: 1px solid var(--border);
  background: var(--surface-2);
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.notes-list-head {
  padding: 10px;
  display: flex;
  gap: 8px;
  border-bottom: 1px solid var(--border-soft);
}
.notes-new-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  font-size: 13px;
  white-space: nowrap;
}
.notes-list-head input[type="search"] {
  flex: 1;
  min-width: 0;
  padding: 5px 8px;
  font-size: 13px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
}
.notes-items {
  overflow-y: auto;
  flex: 1;
}
.note-item {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border-soft);
  cursor: pointer;
  user-select: none;
}
.note-item:hover { background: var(--surface); }
.note-item.active { background: var(--accent); color: #fff; }
.note-item.active .ni-snippet,
.note-item.active .ni-date { color: rgba(255,255,255,.85); }
.ni-title {
  font-weight: 600;
  font-size: 14px;
  margin-bottom: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ni-snippet {
  font-size: 12px;
  color: var(--muted);
  line-height: 1.35;
  max-height: 32px;
  overflow: hidden;
}
.ni-date {
  font-size: 11px;
  color: var(--muted);
  margin-top: 4px;
}

/* ---- Right editor ---- */
.notes-editor {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}
.notes-editor-head {
  display: flex;
  gap: 10px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border-soft);
  align-items: center;
  flex-wrap: wrap;
}
.note-title-input {
  flex: 1;
  font-size: 18px;
  font-weight: 700;
  border: 0;
  background: transparent;
  padding: 4px 0;
  color: var(--text);
  outline: none;
  min-width: 100px;
}
.note-title-input::placeholder { color: var(--muted); font-weight: 400; }
.notes-view-switch {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  flex-shrink: 0;
}
.nvs-btn {
  background: transparent;
  color: var(--muted);
  padding: 5px 10px;
  font-size: 12px;
  box-shadow: none;
  border-radius: 0;
  border: 0;
  cursor: pointer;
}
.nvs-btn.active { background: var(--accent); color: #fff; }
button.ghost {
  background: transparent;
  border: 0;
  box-shadow: none;
  color: var(--muted);
  font-size: 16px;
  cursor: pointer;
  padding: 4px 6px;
  border-radius: var(--radius-sm);
  flex-shrink: 0;
}
button.ghost:hover { background: var(--surface-2); color: var(--text); }

/* ---- Text toolbar ---- */
.notes-text-toolbar {
  display: flex;
  gap: 4px;
  padding: 6px 14px;
  border-bottom: 1px solid var(--border-soft);
  align-items: center;
  flex-wrap: wrap;
}
.notes-text-toolbar button {
  background: transparent;
  color: var(--text);
  border: 1px solid transparent;
  padding: 4px 8px;
  font-size: 13px;
  box-shadow: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
}
.notes-text-toolbar button:hover {
  background: var(--surface-2);
  border-color: var(--border-soft);
  transform: none;
}
.nt-sep { flex: 1; }
.nt-meta { font-size: 11px; color: var(--muted); white-space: nowrap; }

/* ---- Notes body (split / text / draw) ---- */
.notes-body {
  display: grid;
  grid-template-rows: 1fr 1fr;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}
/* Explicit grid placement so display:none items don't collapse the wrong track */
.note-text         { grid-row: 1; min-height: 0; overflow-y: auto; }
.note-sketch-wrap  { grid-row: 2; min-height: 0; }

.notes-body.view-text  { grid-template-rows: 1fr; }
.notes-body.view-text  .note-sketch-wrap { display: none; }
.notes-body.view-draw  { grid-template-rows: 1fr; }
.notes-body.view-draw  .note-text        { display: none; }
.notes-body.view-draw  .note-sketch-wrap { grid-row: 1; }

.note-text {
  padding: 16px 18px;
  overflow-y: auto;
  outline: none;
  font-size: 15px;
  line-height: 1.6;
  color: var(--text);
  min-height: 80px;
}
.note-text:empty:before {
  content: attr(data-placeholder);
  color: var(--muted);
  pointer-events: none;
}
.note-text h3 { margin: 0.5em 0; font-size: 16px; }
.note-text ul, .note-text ol { padding-left: 1.4em; margin: 0.3em 0; }

/* ---- Sketch area ---- */
.note-sketch-wrap {
  display: flex;
  flex-direction: column;
  border-top: 1px solid var(--border-soft);
  min-height: 0;
  overflow: hidden;
}
.notes-body.view-draw .note-sketch-wrap { border-top: 0; }

.sketch-toolbar {
  display: flex;
  gap: 6px;
  padding: 6px 10px;
  align-items: center;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border-soft);
  flex-wrap: wrap;
  flex-shrink: 0;
}
.st-tool, .st-act {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border-soft);
  padding: 4px 8px;
  font-size: 14px;
  box-shadow: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
}
.st-tool:hover, .st-act:hover { background: var(--surface); }
.st-tool.active { background: var(--accent); color: #fff; border-color: transparent; }
.st-color input[type="color"] {
  width: 30px;
  height: 24px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  background: transparent;
}
.st-size {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--muted);
}
.st-size input[type="range"] { width: 80px; }
.st-sep {
  width: 1px;
  align-self: stretch;
  background: var(--border-soft);
  margin: 0 4px;
}
.st-meta {
  margin-left: auto;
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
}

.note-canvas {
  flex: 1;
  width: 100%;
  background: #fff;
  cursor: crosshair;
  touch-action: none;
  display: block;
  min-height: 0;
}
[data-theme="dark"] .note-canvas,
[data-theme="circuit"] .note-canvas { background: #0f1419; }

/* ---- Empty state ---- */
.notes-empty {
  padding: 20px;
  text-align: center;
  color: var(--muted);
}

/* ---- Mobile: stack list above editor ---- */
@media (max-width: 720px) {
  .notes-app {
    grid-template-columns: 1fr;
    height: calc(100vh - 180px);
    position: relative;
  }
  .notes-list {
    display: none;
  }
  .notes-app.show-list .notes-list {
    display: flex;
    position: absolute;
    inset: 0;
    z-index: 2;
    background: var(--surface-2);
  }
  .notes-editor-head::before {
    content: '‹ ';
    font-size: 20px;
    font-weight: 300;
    color: var(--accent);
    cursor: pointer;
    margin-right: 4px;
  }
}
