/* Minimal, dependency-free UI. Light/dark via CSS variables; JS resolves the
   "auto" preference to an explicit data-theme so the manual override wins. */

/* Brand palette from static/brand/ (tee-naming.md): slate ink #2F3B4A, copper
   note #C96F3B (light) / #D9803F (dark), warm off-white #F3EFE9. --primary is
   the slate "stream", --accent the copper "note". */

:root {
  --bg: #f7f4ef;
  --panel: #ffffff;
  --text: #2f3b4a;
  --muted: #6e7883;
  --border: #e5e0d7;
  --primary: #2f3b4a;
  --primary-text: #f3efe9;
  --accent: #a8552b;          /* darkened copper for AA text/links on light */
  --accent-soft: #f6e8dc;
  --danger: #b3372e;
  --danger-soft: #f9e9e7;
  --chip: #efe9e0;
  --shadow: 0 8px 30px rgba(47, 59, 74, 0.14);
  --radius: 8px;
}

[data-theme="dark"] {
  --bg: #1b212a;
  --panel: #242c37;
  --text: #f3efe9;
  --muted: #99a3af;
  --border: #37404d;
  --primary: #d9803f;
  --primary-text: #20150c;
  --accent: #d9803f;          /* the mark's dark-mode copper */
  --accent-soft: #3a2c20;
  --danger: #d96c60;
  --danger-soft: #3a2523;
  --chip: #2e3641;
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.5);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
}

.hidden { display: none !important; }
.spacer { flex: 1; }

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

/* ---------- buttons, inputs ---------- */

.btn {
  display: inline-block;
  padding: 7px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--text);
  font-size: 14px;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
}
.btn:hover { border-color: var(--muted); text-decoration: none; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }
.btn-primary:hover { filter: brightness(1.12); border-color: var(--primary); }
.btn-danger { background: var(--danger-soft); border-color: var(--danger); color: var(--danger); }
.btn-small { padding: 3px 9px; font-size: 13px; }
.btn-wide { display: block; text-align: center; }
.btn:disabled { opacity: 0.5; cursor: default; }

.icon-btn {
  border: none;
  background: none;
  color: var(--muted);
  font-size: 16px;
  cursor: pointer;
  padding: 2px 8px;
  border-radius: 6px;
}
.icon-btn:hover { background: var(--chip); color: var(--text); }

input[type="text"], input[type="search"], input[type="email"], select, textarea {
  font: inherit;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 7px 10px;
  outline: none;
  max-width: 100%;
}
input:focus, textarea:focus, select:focus { border-color: var(--accent); }

/* ---------- login ---------- */

.login {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 20px;
}
.login-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 40px 36px;
  width: 360px;
  max-width: 100%;
  text-align: center;
}
.login-logo {
  width: 84px;
  height: 84px;
  margin: 0 auto 14px;
  background-image: url("/static/brand/tee-mark.svg");
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
}
[data-theme="dark"] .login-logo { background-image: url("/static/brand/tee-mark-dark.svg"); }

.login-card h1 { margin: 0 0 6px; font-size: 28px; }
.login-tagline { color: var(--muted); margin: 0 0 24px; }
.login-error {
  background: var(--danger-soft);
  color: var(--danger);
  border-radius: var(--radius);
  padding: 10px 12px;
  font-size: 14px;
}
.login-fineprint { color: var(--muted); font-size: 12.5px; margin: 18px 0 0; }

/* ---------- shell ---------- */

.shell { display: flex; flex-direction: column; height: 100vh; }

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 17px;
  color: var(--text);
}
.brand:hover { text-decoration: none; }
.brand-logo {
  width: 22px;
  height: 22px;
  background-image: url("/static/brand/tee-mark.svg");
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
}
[data-theme="dark"] .brand-logo { background-image: url("/static/brand/tee-mark-dark.svg"); }
.nav-toggle { display: none; }

.layout { display: flex; flex: 1; min-height: 0; position: relative; }

.rail {
  width: 264px;
  flex-shrink: 0;
  border-right: 1px solid var(--border);
  background: var(--panel);
  overflow-y: auto;
  padding: 14px 12px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.rail input[type="search"] { width: 100%; }
.rail-section { display: flex; flex-direction: column; gap: 2px; }
.rail-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  padding: 0 6px 4px;
}
.rail-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: var(--radius);
  color: var(--text);
  font-size: 14px;
}
.rail-item:hover { background: var(--chip); text-decoration: none; }
.rail-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.rail-item .count { margin-left: auto; color: var(--muted); font-size: 12px; }
.rail-empty { color: var(--muted); font-size: 13px; padding: 2px 8px; }
.rail-owner { color: var(--muted); font-size: 12px; }
.rail-foot { margin-top: auto; border-top: 1px solid var(--border); padding-top: 10px; }
.rail-scrim { display: none; }

.main { flex: 1; overflow-y: auto; padding: 22px 28px 60px; min-width: 0; }
.main-inner { max-width: 860px; margin: 0 auto; }

/* ---------- badges & chips ---------- */

.badge-shared {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 11px;
  font-weight: 600;
  padding: 1px 7px;
  border-radius: 99px;
  vertical-align: middle;
}
.badge-role {
  background: var(--chip);
  color: var(--muted);
  font-size: 11px;
  padding: 1px 7px;
  border-radius: 99px;
}
.badge-lock {
  background: var(--danger-soft);
  color: var(--danger);
  font-size: 12px;
  padding: 2px 9px;
  border-radius: 99px;
}

.chips { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: var(--chip);
  border-radius: 99px;
  padding: 2px 10px;
  font-size: 13px;
  cursor: default;
}
.chip a { color: inherit; }
.chip .chip-x {
  border: none; background: none; cursor: pointer;
  color: var(--muted); font-size: 13px; padding: 0 0 0 2px;
}
.chip .chip-x:hover { color: var(--danger); }
.chip-suggest { background: var(--accent-soft); color: var(--accent); cursor: pointer; }
.chip-suggest:hover { filter: brightness(0.95); }

/* tag picker */
.tagpick { position: relative; display: inline-block; }
.tagpick input { width: 150px; padding: 3px 9px; font-size: 13px; border-radius: 99px; }
.tagpick-menu {
  position: absolute;
  top: 110%;
  left: 0;
  z-index: 30;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  min-width: 210px;
  max-height: 240px;
  overflow-y: auto;
  padding: 4px;
}
.tagpick-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  text-align: left;
  border: none;
  background: none;
  color: var(--text);
  padding: 6px 9px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
}
.tagpick-item:hover { background: var(--chip); }
.tagpick-note { color: var(--muted); font-size: 12px; padding: 4px 9px; }

/* ---------- note list ---------- */

.view-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin: 0 0 18px; }
.view-head h2 { margin: 0; font-size: 21px; }
.view-sub { color: var(--muted); font-size: 13px; width: 100%; }

.note-card {
  display: block;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 13px 16px;
  margin-bottom: 10px;
  color: var(--text);
  cursor: pointer;
}
.note-card:hover { border-color: var(--accent); text-decoration: none; }
.note-card-title { font-weight: 600; font-size: 15.5px; }
.note-card-snippet { color: var(--muted); font-size: 13.5px; margin-top: 2px;
  overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.note-card-meta { display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  margin-top: 7px; color: var(--muted); font-size: 12.5px; }
.empty-state { color: var(--muted); text-align: center; padding: 60px 0; }

/* ---------- note view ---------- */

.note-head h1 { margin: 0 0 4px; font-size: 26px; overflow-wrap: anywhere; }
.note-meta { color: var(--muted); font-size: 13px; display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.note-actions { display: flex; gap: 8px; flex-wrap: wrap; margin: 14px 0; }
.note-tags-row { margin: 10px 0 18px; }

.note-content {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 22px 26px;
  overflow-wrap: anywhere;
}
.note-content img { max-width: 100%; border-radius: 6px; }
.note-content pre {
  background: var(--chip);
  padding: 12px 14px;
  border-radius: 8px;
  overflow-x: auto;
}
.note-content code { background: var(--chip); padding: 1px 5px; border-radius: 4px; font-size: 0.92em; }
.note-content pre code { background: none; padding: 0; }
.note-content blockquote {
  margin: 0.6em 0; padding: 2px 14px;
  border-left: 3px solid var(--accent);
  color: var(--muted);
}
.note-content table { border-collapse: collapse; max-width: 100%; display: block; overflow-x: auto; }
.note-content th, .note-content td { border: 1px solid var(--border); padding: 6px 11px; }
.note-content th { background: var(--chip); }
.note-content h1, .note-content h2, .note-content h3 { margin-top: 1.2em; }
.note-content h1:first-child, .note-content p:first-child { margin-top: 0; }

.image-gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 10px;
  margin: 14px 0;
}
.image-gallery img { width: 100%; border-radius: 8px; display: block; }

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px 18px;
  margin: 16px 0;
}
.panel h3 { margin: 0 0 12px; font-size: 15px; }
.panel-row {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 6px 0; border-bottom: 1px solid var(--border);
}
.panel-row:last-child { border-bottom: none; }
.panel-row .grow { flex: 1; min-width: 120px; overflow-wrap: anywhere; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* ---------- editor ---------- */

.editor { display: flex; flex-direction: column; gap: 12px; }
.editor input.title {
  font-size: 21px; font-weight: 600; width: 100%;
  background: transparent; border: none; border-bottom: 1px solid var(--border);
  border-radius: 0; padding: 6px 2px;
}
.editor input.title:focus { border-bottom-color: var(--accent); }
.editor textarea {
  width: 100%;
  min-height: 55vh;
  resize: vertical;
  font-family: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 14px;
  line-height: 1.55;
  tab-size: 2;
}
.editor-toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.editor-preview { min-height: 55vh; }
.suggest-row { align-items: center; }
.suggest-label { color: var(--muted); font-size: 13px; margin-right: 2px; }

.account-legal { text-align: center; margin-top: 22px; }

/* ---------- storage bar ---------- */

.storage-bar { background: var(--chip); border-radius: 99px; height: 10px; overflow: hidden; max-width: 340px; }
.storage-bar-fill { background: var(--accent); height: 100%; border-radius: 99px; }

/* ---------- modal & toasts ---------- */

.modal-overlay {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(0, 0, 0, 0.45);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.modal {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  width: 460px; max-width: 100%;
  max-height: 85vh; overflow-y: auto;
  padding: 22px 24px;
}
.modal h3 { margin: 0 0 10px; font-size: 17px; }
.modal p { color: var(--muted); margin: 0 0 8px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.modal textarea { width: 100%; min-height: 180px; font-family: ui-monospace, Menlo, monospace; font-size: 13px; }
.modal input { width: 100%; }
.modal-vault input + input { margin-top: 8px; }
.modal-vault p { margin: 8px 0 12px; }
.recovery-key {
  font-family: ui-monospace, Menlo, monospace; font-size: 15px; letter-spacing: 0.04em;
  word-break: break-all; padding: 12px; border-radius: 8px; margin: 8px 0;
  background: var(--bg-alt, rgba(127, 127, 127, 0.12)); user-select: all;
}

#toasts {
  position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%);
  z-index: 200; display: flex; flex-direction: column; gap: 8px; align-items: center;
}
.toast {
  background: var(--text); color: var(--bg);
  border-radius: 99px; padding: 9px 18px; font-size: 14px;
  box-shadow: var(--shadow); max-width: 90vw;
}
.toast-error { background: var(--danger); color: #fff; }

/* ---------- admin/account tables ---------- */

.table-wrap { overflow-x: auto; }
table.data { border-collapse: collapse; width: 100%; font-size: 14px; }
table.data th, table.data td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); }
table.data th { color: var(--muted); font-weight: 600; font-size: 12.5px; text-transform: uppercase; letter-spacing: 0.04em; }

[data-theme="sepia"] {
  --bg: #f1e8d7;
  --panel: #faf4e6;
  --text: #46372a;
  --muted: #83705c;
  --border: #ddcfb4;
  --primary: #46372a;
  --primary-text: #f8f1e2;
  --accent: #a8552b;
  --accent-soft: #f0dfc9;
  --danger: #a83a2e;
  --danger-soft: #f3e0d7;
  --chip: #eadfc8;
  --shadow: 0 8px 30px rgba(70, 55, 42, 0.18);
}

/* No-JS pages (terms/privacy) follow the OS directly: this mirrors the
   [data-theme="dark"] block above — keep the two in sync. The app shell always
   sets data-theme via JS, so these rules never fight the manual toggle. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --bg: #1b212a;
    --panel: #242c37;
    --text: #f3efe9;
    --muted: #99a3af;
    --border: #37404d;
    --primary: #d9803f;
    --primary-text: #20150c;
    --accent: #d9803f;
    --accent-soft: #3a2c20;
    --danger: #d96c60;
    --danger-soft: #3a2523;
    --chip: #2e3641;
    --shadow: 0 8px 30px rgba(0, 0, 0, 0.5);
  }
  :root:not([data-theme]) .brand-logo,
  :root:not([data-theme]) .login-logo {
    background-image: url("/static/brand/tee-mark-dark.svg");
  }
}

/* ---------- markdown guide ---------- */

.guide-row { display: flex; gap: 14px; padding: 7px 0; border-bottom: 1px solid var(--border); }
.guide-row:last-child { border-bottom: none; }
.guide-row code {
  background: var(--chip);
  padding: 2px 8px;
  border-radius: 5px;
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: 13px;
  white-space: pre-wrap;
  flex: 0 0 46%;
}
.guide-row span { color: var(--muted); font-size: 13.5px; align-self: center; }

/* ---------- legal pages (terms/privacy) ---------- */

.legal {
  max-width: 720px;
  margin: 0 auto;
  padding: 28px 20px 80px;
  line-height: 1.65;
}
.legal-head { margin-bottom: 28px; }
.legal h1 { font-size: 27px; margin: 0 0 4px; }
.legal h2 { font-size: 17px; margin: 26px 0 8px; }
.legal p { margin: 0 0 12px; }
.legal code { background: var(--chip); padding: 1px 5px; border-radius: 4px; font-size: 0.92em; }
.legal-foot { border-top: 1px solid var(--border); margin-top: 36px; padding-top: 16px; }

/* ---------- responsive ---------- */

/* Phone-only search bar under the topbar (the rail search is hidden behind the
   hamburger there). Lives outside #main so typing survives view re-renders. */
.mobile-search { display: none; }

@media (max-width: 768px) {
  .nav-toggle { display: block; }
  .mobile-search {
    display: block;
    padding: 10px 14px 2px;
    background: var(--panel);
    border-bottom: 1px solid var(--border);
  }
  .mobile-search input { width: 100%; }
  .rail {
    position: fixed;
    top: 0; bottom: 0; left: 0;
    z-index: 60;
    transform: translateX(-105%);
    transition: transform 0.18s ease;
    width: 280px;
    box-shadow: var(--shadow);
  }
  .layout.rail-open .rail { transform: translateX(0); }
  .layout.rail-open .rail-scrim {
    display: block;
    position: fixed; inset: 0; z-index: 50;
    background: rgba(0, 0, 0, 0.35);
  }
  .main { padding: 16px 14px 60px; }
  .note-content { padding: 16px 15px; }
  .topbar { padding: 10px 12px; }
}

/* account: import */
.import-status { margin-top: 8px; }
.import-status details { margin-top: 4px; }
.import-warnings { margin: 6px 0 0 18px; padding: 0; }
.text-danger { color: var(--danger); }

/* login: Sign in with Apple (Apple's guidelines: black on light, white on dark) + invite banner */
.btn-apple {
  margin-top: 10px;
  background: #000;
  border-color: #000;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.btn-apple:hover { border-color: #000; filter: brightness(1.2); }
.btn-apple svg { width: 16px; height: 16px; fill: currentColor; }
[data-theme="dark"] .btn-apple { background: #fff; border-color: #fff; color: #000; }
.login-invite {
  background: var(--accent-soft);
  color: var(--text);
  border-radius: var(--radius);
  padding: 10px 12px;
  font-size: 14px;
  margin: 0 0 14px;
}
.login-error { margin: 0 0 14px; }
