/* Wheelder Notes — self-hosted, no external fonts or CDNs (strict CSP). */

:root {
  --bg: #ffffff;
  --surface: #ffffff;
  --text: #1f1f1f;
  --muted: #5f6368;
  --line: #e0e0e0;
  --hover: #f1f3f4;
  --accent: #1a73e8;
  --danger: #c5221f;
  --shadow: 0 1px 2px rgba(60,64,67,.3), 0 2px 6px 2px rgba(60,64,67,.15);
  --radius: 12px;

  --c-default: #ffffff;
  --c-red:     #f28b82;
  --c-orange:  #fbbc04;
  --c-yellow:  #fff475;
  --c-green:   #ccff90;
  --c-teal:    #a7ffeb;
  --c-blue:    #aecbfa;
  --c-purple:  #d7aefb;
  --c-pink:    #fdcfe8;
  --c-gray:    #e8eaed;
}

html[data-theme="dark"] {
  --bg: #202124;
  --surface: #202124;
  --text: #e8eaed;
  --muted: #9aa0a6;
  --line: #5f6368;
  --hover: #303134;
  --accent: #8ab4f8;
  --danger: #f28b82;
  --shadow: 0 1px 2px rgba(0,0,0,.5), 0 2px 6px 2px rgba(0,0,0,.35);

  --c-default: #202124;
  --c-red:     #5c2b29;
  --c-orange:  #614a19;
  --c-yellow:  #635d19;
  --c-green:   #345920;
  --c-teal:    #16504b;
  --c-blue:    #2d555e;
  --c-purple:  #42275e;
  --c-pink:    #5b2245;
  --c-gray:    #3c3f43;
}

@media (prefers-color-scheme: dark) {
  html:not([data-theme="light"]) {
    --bg: #202124; --surface: #202124; --text: #e8eaed; --muted: #9aa0a6;
    --line: #5f6368; --hover: #303134; --accent: #8ab4f8; --danger: #f28b82;
    --shadow: 0 1px 2px rgba(0,0,0,.5), 0 2px 6px 2px rgba(0,0,0,.35);
    --c-default: #202124; --c-red: #5c2b29; --c-orange: #614a19; --c-yellow: #635d19;
    --c-green: #345920; --c-teal: #16504b; --c-blue: #2d555e; --c-purple: #42275e;
    --c-pink: #5b2245; --c-gray: #3c3f43;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
}

svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2;
      stroke-linecap: round; stroke-linejoin: round; }

/* ------------------------------------------------------------------ topbar */

.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 8px;
  padding: 8px 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  padding-top: max(8px, env(safe-area-inset-top));
}

.icon-btn {
  display: grid; place-items: center;
  width: 40px; height: 40px; flex: 0 0 auto;
  border: 0; border-radius: 50%;
  background: transparent; color: var(--muted); cursor: pointer;
}
.icon-btn:hover { background: var(--hover); }

.brand { display: flex; align-items: center; gap: 8px; font-size: 20px; color: var(--muted); }
.brand-mark { width: 26px; height: 26px; stroke: var(--accent); }
.brand-mark .fold { fill: none; }
.brand-name { font-weight: 500; }
@media (max-width: 640px) { .brand-name { display: none; } }

.search {
  flex: 1 1 auto; max-width: 720px; margin: 0 8px;
  display: flex; align-items: center; gap: 8px;
  background: var(--hover); border-radius: 8px; padding: 0 12px;
}
.search svg { width: 20px; height: 20px; color: var(--muted); flex: 0 0 auto; }
.search input {
  flex: 1; border: 0; outline: 0; background: transparent; color: var(--text);
  font: inherit; padding: 10px 0; min-width: 0;
}

.account { position: relative; }
.account summary { list-style: none; cursor: pointer; }
.account summary::-webkit-details-marker { display: none; }
.avatar {
  display: grid; place-items: center; width: 34px; height: 34px;
  border-radius: 50%; background: var(--accent); color: #fff; font-weight: 600;
}
.account .menu {
  position: absolute; right: 0; top: 44px; min-width: 220px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 8px; z-index: 40;
}
.menu-email { margin: 4px 8px 8px; color: var(--muted); font-size: 13px; word-break: break-all; }
.menu-item {
  display: block; width: 100%; text-align: left; padding: 10px 12px;
  border: 0; border-radius: 8px; background: transparent; color: var(--text);
  font: inherit; cursor: pointer;
}
.menu-item:hover { background: var(--hover); }
.menu-item.danger { color: var(--danger); }

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

.shell { display: flex; align-items: flex-start; }

.sidebar {
  position: sticky; top: 57px;
  width: 240px; flex: 0 0 240px; padding: 8px;
  display: flex; flex-direction: column; gap: 2px;
}
.nav-item {
  display: flex; align-items: center; gap: 16px;
  padding: 12px 16px; border: 0; border-radius: 0 25px 25px 0;
  background: transparent; color: var(--text); font: inherit; cursor: pointer;
  text-align: left;
}
.nav-item:hover { background: var(--hover); }
.nav-item.is-active { background: var(--c-yellow); color: #202124; font-weight: 500; }
html[data-theme="dark"] .nav-item.is-active { color: var(--text); }
.nav-item.ghost { border-radius: 8px; color: var(--danger); font-size: 14px; }

@media (max-width: 900px) {
  .sidebar {
    position: fixed; inset: 57px auto 0 0; z-index: 25;
    background: var(--surface); border-right: 1px solid var(--line);
    transform: translateX(-100%); transition: transform .18s ease;
    height: calc(100dvh - 57px);
  }
  .sidebar.is-open { transform: none; }
}

.content { flex: 1 1 auto; min-width: 0; padding: 16px; padding-bottom: 96px; }

/* ----------------------------------------------------------------- composer */

.composer { max-width: 600px; margin: 8px auto 28px; }
.composer-collapsed {
  width: 100%; text-align: left; padding: 14px 16px;
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--surface); color: var(--muted); font: inherit;
  box-shadow: var(--shadow); cursor: text;
}
.composer-open {
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--surface); box-shadow: var(--shadow); padding: 12px 16px;
}
.c-title, .c-body {
  width: 100%; border: 0; outline: 0; background: transparent;
  color: var(--text); font: inherit; padding: 6px 0; resize: none;
}
.c-title { font-size: 16px; font-weight: 500; }
.c-body { line-height: 1.6; }

.composer-actions { display: flex; align-items: center; gap: 8px; margin-top: 8px; }
.composer-actions.end { justify-content: flex-end; }
.text-btn {
  margin-left: auto; padding: 8px 14px; border: 0; border-radius: 6px;
  background: transparent; color: var(--text); font: inherit; cursor: pointer;
}
.text-btn:hover { background: var(--hover); }

.palette { display: flex; flex-wrap: wrap; gap: 6px; }
.swatch {
  width: 24px; height: 24px; border-radius: 50%;
  border: 1px solid rgba(0,0,0,.2); cursor: pointer; padding: 0;
}
html[data-theme="dark"] .swatch { border-color: rgba(255,255,255,.25); }
.swatch[aria-pressed="true"] { outline: 2px solid var(--accent); outline-offset: 2px; }

/* -------------------------------------------------------------------- grid */

.section-label {
  max-width: 1100px; margin: 4px auto 8px; padding: 0 4px;
  font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted);
}

/* CSS columns give the staggered Keep look without a layout library. */
.grid { max-width: 1100px; margin: 0 auto 24px; columns: 240px; column-gap: 16px; }
.grid:empty { margin: 0 auto; }

.card {
  break-inside: avoid; margin: 0 0 16px;
  background: var(--card, var(--c-default));
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px 8px; cursor: pointer;
  transition: box-shadow .15s ease;
}
.card:hover { box-shadow: var(--shadow); }
.card:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.card h3 { margin: 0 0 6px; font-size: 15px; font-weight: 600; overflow-wrap: anywhere; }
.card p  { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.card .clip { display: -webkit-box; -webkit-line-clamp: 12; -webkit-box-orient: vertical; overflow: hidden; }
.card .bad { color: var(--danger); font-size: 13px; }

.card-actions { display: flex; gap: 2px; margin-top: 8px; opacity: 0; transition: opacity .15s; }
.card:hover .card-actions, .card:focus-within .card-actions { opacity: 1; }
@media (hover: none) { .card-actions { opacity: 1; } }
.card-actions button {
  display: grid; place-items: center; width: 32px; height: 32px;
  border: 0; border-radius: 50%; background: transparent; color: var(--muted); cursor: pointer;
}
.card-actions button:hover { background: rgba(0,0,0,.08); }
html[data-theme="dark"] .card-actions button:hover { background: rgba(255,255,255,.12); }
.card-actions svg { width: 18px; height: 18px; }
.pin-on { color: var(--text); fill: currentColor; }

.empty { text-align: center; color: var(--muted); padding: 48px 16px; }

/* ------------------------------------------------------------------- modal */

.modal {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(0,0,0,.5);
  display: grid; place-items: start center; padding: 8vh 16px 16px;
  overflow: auto;
}
.modal-card {
  width: 100%; max-width: 600px;
  background: var(--card, var(--surface));
  border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px;
}
.modal-card.narrow { max-width: 400px; background: var(--surface); }
.modal-card h2 { margin: 0 0 4px; font-size: 18px; }
.modal-card .c-body { min-height: 40vh; }
.modal-card label { display: block; margin: 12px 0 4px; font-size: 13px; color: var(--muted); }
.modal-card input[type="password"] {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line);
  border-radius: 8px; background: var(--bg); color: var(--text); font: inherit;
}

/* -------------------------------------------------------------------- auth */

.auth-body { display: grid; place-items: center; min-height: 100dvh; padding: 24px; }
.auth-card {
  width: 100%; max-width: 400px; padding: 32px 28px;
  border: 1px solid var(--line); border-radius: 16px; background: var(--surface);
  box-shadow: var(--shadow);
}
.auth-card .brand { justify-content: center; margin-bottom: 20px; }
.auth-card h1 { margin: 0 0 4px; font-size: 22px; font-weight: 500; text-align: center; }
.auth-card .sub { margin: 0 0 20px; text-align: center; color: var(--muted); font-size: 14px; }
.auth-card label { display: block; margin: 14px 0 4px; font-size: 13px; color: var(--muted); }
.auth-card input {
  width: 100%; padding: 12px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--bg); color: var(--text); font: inherit;
}
.auth-card input:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
.hint { margin: 8px 0 0; font-size: 12px; color: var(--muted); }
.switch { margin: 20px 0 0; text-align: center; font-size: 14px; color: var(--muted); }
a { color: var(--accent); }

.primary {
  width: 100%; margin-top: 20px; padding: 12px;
  border: 0; border-radius: 8px; background: var(--accent); color: #fff;
  font: inherit; font-weight: 500; cursor: pointer;
}
.primary:hover { filter: brightness(1.08); }
.primary.small { width: auto; margin: 0; padding: 9px 18px; }

.alert {
  margin: 0 0 4px; padding: 10px 12px; border-radius: 8px;
  background: rgba(197,34,31,.1); color: var(--danger); font-size: 14px;
}

/* ------------------------------------------------------------------- toast */

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  z-index: 60; padding: 12px 18px; border-radius: 8px;
  background: #323232; color: #fff; font-size: 14px; box-shadow: var(--shadow);
  max-width: calc(100vw - 32px);
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
