/* ── Design tokens ────────────────────────────────────────── */
:root {
  --brand:           rgb(248, 166, 107);
  --link:            rgb(37,  99,  235);
  --bg:              rgb(255, 255, 255);
  --bg-elevated:     rgb(243, 244, 245);
  --text:            rgb(44,  49,  57);
  --text-muted:      rgb(136, 145, 161);
  --text-very-muted: rgb(193, 199, 208);
  --border:          rgb(236, 238, 240);
  --shadow-color:    rgba(0, 0, 0, 0.08);
  --danger:          rgb(225, 29,  72);
}

body.dark {
  --link:            rgb(96,  165, 250);
  --bg:              rgb(34,  38,  44);
  --bg-elevated:     rgb(44,  49,  57);
  --text:            rgb(193, 199, 208);
  --text-muted:      rgb(136, 145, 161);
  --text-very-muted: rgb(94,  107, 128);
  --border:          rgb(60,  66,  77);
  --shadow-color:    transparent;
}

/* ── Reset & base ─────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  height: -webkit-fill-available;
}

body {
  font-family: "Poppins", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.6;
  /* Flex column so header stays pinned and only content-scroll scrolls.
     This prevents iOS from hiding the header when the keyboard opens. */
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ── Site header — flex item, never fixed, always visible ─── */
.site-header {
  flex-shrink: 0;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 1px 6px var(--shadow-color);
  padding-top: env(safe-area-inset-top, 0px);
  padding-left: env(safe-area-inset-left, 0px);
  padding-right: env(safe-area-inset-right, 0px);
}

/* Row 1: logo (left) | + New + actions (right cluster, single row) */
.header-row1 {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.55rem clamp(1rem, 4vw, 3rem);
}

/* Row 2: move-line toolbar, shown only in editor views */
.header-row2 {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.3rem clamp(1rem, 4vw, 3rem);
  border-top: 1px solid var(--border);
}

.toolbar-notebook-select {
  margin-left: auto;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-family: inherit;
  font-size: 0.8rem;
  padding: 0.2rem 0.5rem;
  cursor: pointer;
  max-width: 160px;
  outline: none;
}
.toolbar-notebook-select:focus { border-color: var(--brand); }



.header-logo {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  color: var(--text-muted);
  text-decoration: none;
}
.header-logo:hover { color: var(--brand); }

.header-logo-icon {
  width: 26px;
  height: 26px;
  stroke: currentColor;
}

/* Keeps + New and note actions on one baseline; avoids inline-wrap overlap */
.header-row1-trailing {
  margin-left: auto;
  display: flex;
  align-items: center;
  flex-wrap: nowrap;
  gap: 0.6rem;
  min-width: 0;
}

.header-row1-right {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.6rem;
  flex-wrap: nowrap;
  min-width: 0;
}

.header-actions {
  display: inline-flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 0.6rem;
}

.header-delete-form { display: contents; }

.header-delete-btn {
  padding: 0.35rem 0.5rem;
  color: var(--text-muted);
}
.header-delete-btn:hover { color: var(--danger); border-color: var(--danger); }

/* Spacer no longer needed (header is a flex item, not fixed) */
.header-spacer { display: none; }

/* Note title displayed outside the header */
.note-page-title {
  font-size: 1.8rem;
  font-weight: 700;
  padding: 1.1rem clamp(1rem, 4vw, 3rem) 0.4rem;
  color: var(--text);
  line-height: 1.3;
}

/* ── Buttons ──────────────────────────────────────────────── */
.btn {
  padding: 0.4rem 0.85rem;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.825rem;
  font-weight: 600;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  transition: background 0.15s, opacity 0.15s;
  white-space: nowrap;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover:not(:disabled) { opacity: 0.88; }

.btn-secondary {
  background: var(--bg-elevated);
  color: var(--text-muted);
  border: 1px solid var(--border);
}
.btn-secondary:hover:not(:disabled) { background: var(--border); color: var(--text); }

.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { opacity: 0.88; }

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
}
.btn-ghost:hover:not(:disabled) { color: var(--danger); border-color: var(--danger); }

.btn-saved { background: #22c55e; }

.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.35rem;
  line-height: 1;
  min-width: 0;
}

.icon-lg {
  width: 22px;
  height: 22px;
}

/* ── Main layout ──────────────────────────────────────────── */
.main {
  flex: 1;
  min-height: 0; /* allow flex child to shrink below content size */
  display: flex;
  flex-direction: column;
  width: 100%;
}

/* Flex wrapper inside App() — contains header + scroll area */
.app-layout {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

/* Only this element scrolls; header stays above it always */
.content-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

.content-area {
  padding: 1.25rem clamp(1rem, 4vw, 3rem);
}

/* ── Inline search (home page) ────────────────────────────── */
.content-search {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1.25rem;
}

.search-input {
  flex: 1;
  padding: 0.5rem 0.9rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
  font-size: 1rem; /* ≥16px prevents iOS Safari auto-zoom on focus */
  outline: none;
  transition: border-color 0.15s;
}
.search-input:focus { border-color: var(--brand); }
.search-input::placeholder { color: var(--text-very-muted); }

.search-btn {
  flex-shrink: 0;
  padding: 0.5rem 0.75rem;
}

/* ── Note list ────────────────────────────────────────────── */
.note-list {
  list-style: none;
  display: flex;
  flex-direction: column;
}

.note-item {
  position: relative;
  border-radius: 8px;
  overflow: hidden;
  transition: background 0.15s;
}
.note-row {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  padding: 0.65rem 0.5rem;
  background: var(--bg);
  position: relative;
  z-index: 1;
  touch-action: pan-y;
  user-select: none;
}
.note-item:hover .note-row { background: var(--bg-elevated); }

.note-archive-backdrop {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding: 0 1rem;
  background: #c0392b;
  color: #fff;
  z-index: 0;
}
.note-archive-label {
  font-weight: 600;
  font-size: 0.85rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.note-item-armed .note-archive-backdrop {
  background: #962c20;
}

.settings-help {
  margin: 0.25rem 0 0.6rem;
  color: var(--text-muted);
  font-size: 0.85rem;
}
.settings-save-status {
  margin-left: 0.75rem;
  color: var(--text-muted);
  font-size: 0.85rem;
}

.note-title-link {
  font-weight: 600;
  font-size: 1rem;
  color: var(--text);
  text-decoration: none;
}
.note-title-link:hover { color: var(--brand); }

.note-date {
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* ── Note viewer ──────────────────────────────────────────── */
.note-content {
  padding: 1.25rem clamp(1rem, 4vw, 3rem);
  line-height: 1.8;
}

/* ── Markdown rendering ───────────────────────────────────── */
.note-content h1 { font-size: 1.65rem; margin: 1.5rem 0 0.75rem; }
.note-content h2 { font-size: 1.3rem;  margin: 1.25rem 0 0.6rem; }
.note-content h3 { font-size: 1.1rem;  margin: 1rem 0 0.5rem; }
.note-content p  { margin-bottom: 1rem; }
.note-content a  { color: var(--link); text-decoration: underline; }
.note-content code {
  background: var(--bg-elevated);
  padding: 0.1em 0.35em;
  border-radius: 4px;
  font-size: 0.875em;
  font-family: ui-monospace, monospace;
}
.note-content pre {
  background: var(--bg-elevated);
  padding: 1rem;
  border-radius: 6px;
  overflow-x: auto;
  margin-bottom: 1rem;
}
.note-content blockquote {
  border-left: 3px solid var(--brand);
  padding-left: 1rem;
  color: var(--text-muted);
  margin-bottom: 1rem;
}
.note-content ul, .note-content ol { padding-left: 1.5rem; margin-bottom: 1rem; }
.note-content img { max-width: 100%; border-radius: 6px; }
.note-content table { border-collapse: collapse; width: 100%; margin-bottom: 1rem; }
.note-content th, .note-content td {
  border: 1px solid var(--border);
  padding: 0.5rem 0.75rem;
  text-align: left;
}
.note-content th { background: var(--bg-elevated); font-weight: 600; }

.wikilink { color: var(--link); text-decoration: underline dotted; }

/* ── Note editor ──────────────────────────────────────────── */
.note-editor-form {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding: 1rem clamp(1rem, 4vw, 3rem);
}

.editor-field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.title-input {
  font-size: 1.4rem;
  font-weight: 600;
  font-family: inherit;
  border: none;
  border-bottom: 2px solid var(--border);
  background: transparent;
  color: var(--text);
  padding: 0.25rem 0;
  outline: none;
  width: 100%;
}
.title-input:focus { border-color: var(--brand); }

.content-textarea {
  width: 100%;
  min-height: 70vh;
  padding: 0.75rem 0;
  border: none;
  background: var(--bg);
  color: var(--text);
  font-family: "JetBrains Mono", "Fira Code", ui-monospace, monospace;
  font-size: 1rem; /* ≥16px prevents iOS Safari auto-zoom on focus */
  line-height: 1.7;
  resize: none;
  outline: none;
  border-top: 1px solid var(--border);
}

/* ── Search results page ──────────────────────────────────── */
.search-header {
  display: flex;
  align-items: baseline;
  gap: 1rem;
  margin-bottom: 1rem;
}

.note-count {
  font-size: 0.75rem;
  color: var(--text-very-muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.search-results {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.search-result {
  padding: 0.75rem 0.5rem;
  border-radius: 8px;
  transition: background 0.15s;
}
.search-result:hover { background: var(--bg-elevated); }

.search-snippet {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 0.25rem;
  line-height: 1.5;
}

b.match {
  background: rgba(248, 166, 107, 0.3);
  color: var(--text);
  border-radius: 2px;
  padding: 0 2px;
  font-weight: 600;
}

/* ── Tags ─────────────────────────────────────────────────── */
.tags { display: flex; flex-wrap: wrap; gap: 0.25rem; margin-top: 0.3rem; }

.tag {
  font-size: 0.7rem;
  font-weight: 600;
  padding: 0.1rem 0.55rem;
  background: var(--brand);
  color: #fff;
  border-radius: 999px;
}

/* ── States ───────────────────────────────────────────────── */
.empty-state { padding: 3rem 1rem; text-align: center; color: var(--text-muted); }
.empty-state p { margin-bottom: 1rem; }

/* ── Settings gear icon ──────────────────────────────────── */
.header-settings-btn {
  display: flex;
  align-items: center;
  color: var(--text-muted);
  text-decoration: none;
  padding: 0.2rem;
  border-radius: 4px;
  transition: color 0.15s;
}
.header-settings-btn:hover { color: var(--brand); }

.header-settings-icon {
  width: 22px;
  height: 22px;
  stroke: currentColor;
}

/* ── Settings view ───────────────────────────────────────── */
.settings-view h1 {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 1rem;
}

.settings-list {
  list-style: none;
  display: flex;
  flex-direction: column;
}

.settings-item {
  border-bottom: 1px solid var(--border);
}

.settings-link {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.85rem 0.5rem;
  text-decoration: none;
  color: var(--text);
  border-radius: 6px;
  transition: background 0.15s;
}
.settings-link:hover { background: var(--bg-elevated); }

.settings-link-label { font-weight: 600; font-size: 1rem; }
.settings-link-arrow { font-size: 1.4rem; color: var(--text-muted); }

/* ── Status view ─────────────────────────────────────────── */
.status-header { margin-bottom: 1rem; }

.settings-back {
  font-size: 0.85rem;
  color: var(--brand);
  text-decoration: none;
  font-weight: 600;
}
.settings-back:hover { text-decoration: underline; }

.status-cards {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.status-card {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem 1.1rem;
}

.status-card-label {
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--text);
}

.status-card-value {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--brand);
}

.status-card-value.status-ok   { color: #2a9d2a; }
.status-card-value.status-error { color: #c0392b; }

/* ── Snapshots table ──────────────────────────────────────── */
.snapshots-table-wrap { overflow-x: auto; }

.snapshots-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.snapshots-table th {
  text-align: left;
  font-weight: 600;
  color: var(--text-muted);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 0.5rem 0.6rem;
  border-bottom: 2px solid var(--border);
}

.snapshots-table td {
  padding: 0.6rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.snapshots-table tr:hover td { background: var(--bg-elevated); }

.snapshot-key {
  font-family: ui-monospace, monospace;
  font-size: 0.8rem;
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.snapshot-deleted td { opacity: 0.5; }

.snapshot-badge {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 600;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
}
.badge-active { background: #22c55e; color: #fff; }
.badge-deleted { background: var(--text-very-muted); color: #fff; }

.btn-sm { font-size: 0.75rem; padding: 0.25rem 0.6rem; }

/* ── Login page ───────────────────────────────────────────── */
body.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: auto;
  flex-direction: column;
}

.login-card {
  width: 100%;
  max-width: 360px;
  padding: 2rem;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 4px 24px var(--shadow-color);
}

.login-logo {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--brand);
  text-align: center;
  margin-bottom: 1.5rem;
  letter-spacing: -0.02em;
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.form-field {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.form-field label {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-muted);
}

.form-field input {
  padding: 0.55rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font-size: 0.95rem;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s;
}

.form-field input:focus {
  border-color: var(--brand);
}

.login-error {
  padding: 0.55rem 0.75rem;
  border-radius: 8px;
  background: rgba(225, 29, 72, 0.1);
  color: var(--danger);
  font-size: 0.85rem;
}

.login-btn {
  width: 100%;
  padding: 0.65rem;
  font-size: 0.95rem;
}

/* ── Floating action button (home only) ──────────────────── */
.fab-new {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  width: 3.5rem;
  height: 3.5rem;
  border-radius: 50%;
  background: var(--brand);
  color: #fff;
  font-size: 2rem;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
  z-index: 100;
  transition: opacity 0.15s;
}
.fab-new:hover { opacity: 0.88; }

/* ── Responsive ───────────────────────────────────────────── */
@media (max-width: 600px) {
  .header-row1 { padding: 0.5rem 0.75rem; }
  .header-row2 { padding: 0.3rem 0.75rem; }
  .note-page-title { font-size: 1.4rem; padding: 0.9rem 0.75rem 0.3rem; }
  .content-area { padding: 1rem 0.75rem; }
  .note-content { padding: 1rem 0.75rem; }
  .note-editor-form { padding: 0.75rem; }
}

/* ── Hamburger menu button ────────────────────────────────── */
.header-menu-btn {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  padding: 0.3rem 0.4rem;
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
}
.header-menu-btn:hover { color: var(--brand); border-color: transparent; }
.header-menu-icon { stroke: currentColor; display: block; }

/* ── Sidebar ──────────────────────────────────────────────── */
.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
  z-index: 149;
}
.sidebar-backdrop.sidebar-backdrop-visible { display: block; }

.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: 280px;
  max-width: 85vw;
  background: var(--bg-elevated);
  border-right: 1px solid var(--border);
  box-shadow: 2px 0 16px var(--shadow-color);
  z-index: 150;
  display: flex;
  flex-direction: column;
  transform: translateX(-100%);
  transition: transform 0.22s ease;
}
.sidebar.sidebar-open { transform: translateX(0); }

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.7rem 1rem;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.sidebar-title {
  font-weight: 700;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}

.sidebar-close-btn {
  padding: 0.2rem 0.5rem;
  font-size: 1rem;
  line-height: 1;
  border: none;
}

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 0.6rem 0;
}

.sidebar-link {
  display: block;
  padding: 0.45rem 1rem;
  text-decoration: none;
  color: var(--text);
  font-size: 1rem;
  border-radius: 6px;
  margin: 0 0.5rem;
  transition: background 0.12s;
}
.sidebar-link:hover { background: var(--border); color: var(--text); }
.sidebar-link-all {
  font-weight: 600;
  margin-bottom: 0.4rem;
  color: var(--brand);
}

.sidebar-footer {
  padding: 0.75rem 1rem;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.sidebar-new-notebook {
  width: 100%;
  justify-content: center;
  font-size: 0.82rem;
}

/* ── Notebook tree (sidebar) ──────────────────────────────── */
.sidebar-notebooks { margin-top: 0.15rem; }

.nb-tree-item {
  display: flex;
  flex-direction: column;
}

.nb-tree-row {
  display: flex;
  align-items: center;
  margin: 0 0.5rem;
  border-radius: 6px;
  transition: background 0.12s;
}
.nb-tree-row:hover { background: var(--border); }

.nb-tree-link {
  flex: 1;
  margin: 0;
  border-radius: 0;
  padding-left: 1rem;
}
.nb-tree-link:hover { background: transparent; }

.nb-collapse-btn {
  flex-shrink: 0;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0.45rem 0.65rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  border-radius: 0 6px 6px 0;
}
.nb-collapse-btn:hover { color: var(--text); }

/* ── Notebook page ────────────────────────────────────────── */
.notebook-page-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

.notebook-page-title {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text);
}

.notebook-page-actions {
  display: flex;
  gap: 0.5rem;
  flex-shrink: 0;
}

/* ── Notebook forms ───────────────────────────────────────── */
.notebook-form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  max-width: 480px;
  padding: 1rem 0;
}

.notebook-select {
  padding: 0.45rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
  font-size: 0.875rem;
  outline: none;
  cursor: pointer;
  width: 100%;
}
.notebook-select:focus { border-color: var(--brand); }

.form-actions {
  display: flex;
  gap: 0.75rem;
  padding-top: 0.25rem;
}

.notebook-delete-btn { margin-top: 2rem; }
.notebook-delete-note { font-size: 0.8rem; color: var(--text-very-muted); margin-top: 2rem; display: block; }
