/* Mnemo — typography-first, iA Writer × Linear aesthetic */

:root {
  --bg:         #ffffff;
  --surface:    #f7f7f5;
  --border:     #e4e4e0;
  --text:       #1a1a18;
  --muted:      #6b6b66;
  --accent:     #1f6feb;
  --accent-dim: #d0e6ff;
  --danger:     #cf3240;
  --mark-bg:    #fff176;
  --radius:     6px;
  --mono:       'JetBrains Mono', 'Fira Code', 'Courier New', monospace;
  --sans:       -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  --max-w:      680px;
  --sidebar-w:  200px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg:         #0d1117;
    --surface:    #161b22;
    --border:     #30363d;
    --text:       #e6edf3;
    --muted:      #8b949e;
    --accent:     #58a6ff;
    --accent-dim: #1c3048;
    --danger:     #f85149;
    --mark-bg:    #4a4000;
  }
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 16px; -webkit-text-size-adjust: 100%; }

body {
  font-family: var(--sans);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Layout ── */

.layout {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  grid-template-rows: auto 1fr;
  min-height: 100vh;
}

.topbar {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.5rem;
  height: 3rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar__brand {
  font-weight: 700;
  font-size: 1.1rem;
  letter-spacing: -0.02em;
  color: var(--text);
}

.topbar__actions { display: flex; gap: 0.75rem; align-items: center; }

.sidebar {
  border-right: 1px solid var(--border);
  padding: 1.25rem 1rem;
  background: var(--surface);
  overflow-y: auto;
}

.sidebar__section { margin-bottom: 1.5rem; }
.sidebar__label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin-bottom: 0.5rem;
}
.sidebar__link {
  display: block;
  padding: 0.3rem 0.5rem;
  border-radius: var(--radius);
  color: var(--text);
  font-size: 0.875rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sidebar__link:hover { background: var(--border); text-decoration: none; }
.sidebar__link.active { background: var(--accent-dim); color: var(--accent); }

.main {
  padding: 2rem 2.5rem;
  max-width: calc(var(--max-w) + 5rem);
  overflow-y: auto;
}

/* ── Auth pages (no sidebar) ── */

.auth-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 2rem;
}

.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) * 2);
  padding: 2.5rem;
}

.auth-card h1 {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 0.25rem;
}
.auth-card .subtitle {
  color: var(--muted);
  font-size: 0.875rem;
  margin-bottom: 1.75rem;
}

/* ── Forms ── */

.form-group { margin-bottom: 1.25rem; }

label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 0.35rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="search"],
textarea,
select {
  width: 100%;
  padding: 0.55rem 0.75rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--sans);
  font-size: 0.9rem;
  transition: border-color 0.15s;
  outline: none;
}

input:focus, textarea:focus, select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}

textarea {
  font-family: var(--mono);
  font-size: 0.875rem;
  resize: vertical;
  line-height: 1.7;
}

/* ── Buttons ── */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem 1rem;
  border-radius: var(--radius);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background 0.15s, opacity 0.15s;
  text-decoration: none;
  background: none;
  color: var(--text);
}
.btn:hover { text-decoration: none; }

.btn-primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-primary:hover { opacity: 0.88; }

.btn-secondary { background: var(--surface); border-color: var(--border); }
.btn-secondary:hover { background: var(--border); }

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

.btn-sm { padding: 0.3rem 0.65rem; font-size: 0.8rem; }
.btn-full { width: 100%; justify-content: center; }

/* ── Alerts ── */

.alert {
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  font-size: 0.875rem;
  margin-bottom: 1.25rem;
}
.alert-error { background: #ffeef0; border: 1px solid #ffc1c6; color: #86181d; }
.alert-success { background: #dcffe4; border: 1px solid #acf2bd; color: #186932; }
.alert-info { background: var(--accent-dim); border: 1px solid #79b8ff; color: #032f62; }
@media (prefers-color-scheme: dark) {
  .alert-error { background: #2d0f13; border-color: #6e1c20; color: #f85149; }
  .alert-success { background: #0d2a14; border-color: #1f6535; color: #3fb950; }
  .alert-info { background: #1c3048; border-color: #388bfd; color: #79b8ff; }
}

/* ── Note cards ── */

.notes-grid {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.note-card {
  display: block;
  padding: 0.85rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  transition: border-color 0.15s, box-shadow 0.15s;
  color: var(--text);
}
.note-card:hover {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
  text-decoration: none;
}

.note-card__title {
  font-weight: 600;
  font-size: 0.95rem;
  margin-bottom: 0.2rem;
}

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

.tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  margin-top: 0.4rem;
}

.tag {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 99px;
  font-size: 0.72rem;
  color: var(--muted);
}
.tag:hover { color: var(--accent); border-color: var(--accent); text-decoration: none; }
.tag.active { background: var(--accent-dim); border-color: var(--accent); color: var(--accent); }

/* ── Note detail ── */

.note-header { margin-bottom: 2rem; }
.note-header h1 {
  font-size: 1.75rem;
  font-weight: 700;
  line-height: 1.25;
  letter-spacing: -0.02em;
}
.note-header__meta {
  font-size: 0.78rem;
  color: var(--muted);
  margin-top: 0.35rem;
}

.note-body {
  font-size: 1rem;
  line-height: 1.8;
  max-width: var(--max-w);
}
.note-body h1, .note-body h2, .note-body h3 { margin: 1.5em 0 0.5em; font-weight: 600; }
.note-body p { margin-bottom: 1em; }
.note-body ul, .note-body ol { margin: 0 0 1em 1.5em; }
.note-body li { margin-bottom: 0.25em; }
.note-body blockquote {
  border-left: 3px solid var(--accent);
  padding-left: 1em;
  color: var(--muted);
  margin: 1em 0;
}
.note-body pre {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1em;
  overflow-x: auto;
  font-family: var(--mono);
  font-size: 0.85em;
  margin-bottom: 1em;
}
.note-body code {
  font-family: var(--mono);
  font-size: 0.875em;
  background: var(--surface);
  padding: 0.1em 0.3em;
  border-radius: 3px;
}
.note-body pre code { background: none; padding: 0; }
.note-body table { width: 100%; border-collapse: collapse; margin-bottom: 1em; }
.note-body th, .note-body td {
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  text-align: left;
}
.note-body th { background: var(--surface); font-weight: 600; }

/* ── Wikilinks ── */

.wikilink { color: var(--accent); }
.wikilink.broken { color: var(--muted); text-decoration: dashed underline; cursor: help; }

/* ── Backlinks / outbound panel ── */

.links-panel {
  margin-top: 2.5rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
}
.links-panel h2 {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin-bottom: 0.75rem;
}

/* ── Editor ── */

.editor-layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
  height: calc(100vh - 10rem);
}
.editor-layout__pane { display: flex; flex-direction: column; gap: 0.5rem; }
.editor-pane-label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}
.editor-textarea {
  flex: 1;
  resize: none;
  font-family: var(--mono);
  font-size: 0.9rem;
  line-height: 1.75;
}
.preview-pane {
  flex: 1;
  overflow-y: auto;
  padding: 0.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.editor-title {
  font-size: 1.2rem;
  font-weight: 600;
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  width: 100%;
  margin-bottom: 0.75rem;
}
.editor-title:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
  outline: none;
}

/* ── Search ── */

.search-bar { position: relative; margin-bottom: 1.5rem; }
.search-bar input { padding-left: 2.25rem; }
.search-bar::before {
  content: "⌕";
  position: absolute;
  left: 0.75rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  pointer-events: none;
}

.search-result mark { background: var(--mark-bg); color: var(--text); border-radius: 2px; }
.search-snippet { font-size: 0.82rem; color: var(--muted); margin-top: 0.2rem; }

/* ── QR code ── */

.qr-wrapper { text-align: center; margin: 1.5rem 0; }
.qr-wrapper img { max-width: 200px; border-radius: var(--radius); }

.recovery-codes {
  font-family: var(--mono);
  font-size: 0.85rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  columns: 2;
  margin: 1rem 0;
}
.recovery-codes li { margin-bottom: 0.35rem; list-style: none; }

/* ── Admin table ── */

.data-table { width: 100%; border-collapse: collapse; font-size: 0.875rem; }
.data-table th, .data-table td {
  padding: 0.6rem 0.85rem;
  border-bottom: 1px solid var(--border);
  text-align: left;
}
.data-table th {
  background: var(--surface);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}
.data-table tr:hover td { background: var(--surface); }

.badge {
  display: inline-block;
  padding: 0.15rem 0.45rem;
  border-radius: 99px;
  font-size: 0.7rem;
  font-weight: 600;
}
.badge-green { background: #dcffe4; color: #186932; }
.badge-red   { background: #ffeef0; color: #86181d; }
.badge-blue  { background: var(--accent-dim); color: var(--accent); }
@media (prefers-color-scheme: dark) {
  .badge-green { background: #0d2a14; color: #3fb950; }
  .badge-red   { background: #2d0f13; color: #f85149; }
}

/* ── Page header ── */

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.5rem;
}
.page-header h1 { font-size: 1.35rem; font-weight: 700; }

/* ── Utility ── */

.text-muted { color: var(--muted); }
.text-sm    { font-size: 0.85rem; }
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.flex { display: flex; }
.gap-2 { gap: 0.5rem; }
.gap-3 { gap: 0.75rem; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.w-full { width: 100%; }

/* ── Divider ── */

hr.divider { border: none; border-top: 1px solid var(--border); margin: 1.5rem 0; }

/* ── Responsive ── */

@media (max-width: 640px) {
  .layout {
    grid-template-columns: 1fr;
  }
  .sidebar { display: none; }
  .main { padding: 1.25rem 1rem; }
  .editor-layout { grid-template-columns: 1fr; }
  .editor-layout__pane:last-child { display: none; }
}
