/* librenotes — mobile-first responsive styles.
 *
 * Breakpoints (matches Phase 3 issue #18):
 *   - small mobile:   320–479px  (default; no media query)
 *   - large mobile:   480–767px
 *   - tablet:         768–1023px
 *   - desktop:       1024–1439px
 *   - large desktop: 1440–2559px
 *   - ultrawide:    >= 2560px
 *
 * Design goals:
 *   - Never horizontal-scroll at any width.
 *   - Use min(100% - gutter, max-content) sizing so content
 *     adapts without breaking at the extremes.
 *   - Reserve a sidebar layout primitive (.app-shell + .app-sidebar
 *     + .app-content) for the eventual notes UI; on mobile the
 *     sidebar collapses behind a toggle (display: none until
 *     [data-sidebar="open"]).
 */

:root {
  --fg: #1a1a1a;
  --bg: #ffffff;
  --muted: #5b5b5b;
  --accent: #2563eb;
  --accent-fg: #ffffff;
  --border: #e5e5e5;
  --card: #fafafa;
  --error: #b91c1c;
  --success: #047857;
}

[data-theme="dark"] {
  --fg: #e5e5e5;
  --bg: #0b0b0b;
  --muted: #9a9a9a;
  --accent: #3b82f6;
  --accent-fg: #ffffff;
  --border: #262626;
  --card: #141414;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  color: var(--fg);
  background: var(--bg);
  /* Prevent horizontal scroll at narrow widths even if a child
     overflows. Vertical overflow is allowed normally. */
  overflow-x: hidden;
}

img, svg, video, canvas, iframe { max-width: 100%; height: auto; }

/* Fluid typography between mobile and desktop sizes. */
h1 { font-size: clamp(1.5rem, 4vw, 2.5rem); line-height: 1.15; }
h2 { font-size: clamp(1.1rem, 2.5vw, 1.5rem); }

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

.wrap {
  width: 100%;
  max-width: 64rem;
  margin: 0 auto;
  padding: 0 1rem;
}

/* Comfortable reading width that scales up to ultrawide without
   stretching paragraphs into uselessly long lines. */
@media (min-width: 1440px) { .wrap { max-width: 72rem; padding: 0 2rem; } }
@media (min-width: 2560px) { .wrap { max-width: 96rem; padding: 0 3rem; } }

.brand {
  font-weight: 700;
  font-size: 1.15rem;
  color: var(--fg);
}

.muted { color: var(--muted); }

/* Header */
.site-header {
  border-bottom: 1px solid var(--border);
  padding: 1rem 0;
}
.site-header .wrap { display: flex; align-items: center; justify-content: space-between; }
.site-header nav a { margin-left: 1rem; }

/* Hero */
.hero { padding: 4rem 0 3rem; }
.hero h1 { font-size: clamp(1.6rem, 4vw, 2.5rem); margin: 0 0 1rem; line-height: 1.2; }
.hero .lede { font-size: 1.1rem; color: var(--muted); max-width: 36rem; }
.ctas { margin-top: 1.5rem; }
.btn {
  display: inline-block;
  padding: 0.65rem 1.1rem;
  border-radius: 0.4rem;
  border: 1px solid var(--accent);
  margin-right: 0.5rem;
  font-weight: 500;
}
.btn.primary { background: var(--accent); color: var(--accent-fg); }
.btn.primary:hover { text-decoration: none; opacity: 0.9; }
.btn.ghost { color: var(--accent); background: transparent; }
.btn.ghost:hover { background: var(--card); text-decoration: none; }
.cta { color: var(--accent); }

/* Features grid */
.features { padding: 2rem 0 4rem; }
.features .grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(15rem, 1fr));
  gap: 1.5rem;
}
.features article {
  padding: 1.25rem;
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  background: var(--card);
}
.features h2 { margin: 0 0 0.4rem; font-size: 1.05rem; }
.features p { margin: 0; color: var(--muted); }

/* Footer */
.site-footer {
  border-top: 1px solid var(--border);
  padding: 1.5rem 0;
  font-size: 0.9rem;
}
.site-footer p { margin: 0.25rem 0; }

/* Auth pages (login, verify) */
.auth-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 1.5rem; }
.auth-card {
  width: 100%;
  max-width: 24rem;
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  padding: 1.75rem;
  background: var(--card);
}
.auth-card h1 { margin: 0 0 0.25rem; font-size: 1.5rem; }
.auth-card label { display: block; margin: 1rem 0 0.25rem; font-weight: 500; }
.auth-card input[type="email"] {
  width: 100%;
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 0.35rem;
  font-size: 1rem;
  background: var(--bg);
  color: var(--fg);
}
.auth-card input[aria-invalid="true"] { border-color: var(--error); }
.auth-card button {
  width: 100%;
  margin-top: 1rem;
  padding: 0.7rem;
  border: 0;
  border-radius: 0.35rem;
  background: var(--accent);
  color: var(--accent-fg);
  font-size: 1rem;
  font-weight: 500;
  cursor: pointer;
}
.auth-card button:disabled { opacity: 0.6; cursor: not-allowed; }
.auth-card .footer-link { margin-top: 1.25rem; text-align: center; font-size: 0.9rem; }

.error { color: var(--error); margin: 0.5rem 0 0; font-size: 0.9rem; }
.success { color: var(--success); margin-top: 1rem; }

/* App shell */
.app-page .app-header {
  display: flex;
  gap: 1rem;
  align-items: center;
  padding: 0.75rem 1.25rem;
  border-bottom: 1px solid var(--border);
}
.app-page .app-header .who { color: var(--muted); margin-left: auto; }
.app-page .app-header button {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 0.3rem;
  padding: 0.35rem 0.7rem;
  cursor: pointer;
  color: var(--fg);
}
.app-page .app-main { padding: 2rem 1.25rem; max-width: 48rem; margin: 0 auto; }
.app-page pre {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 0.4rem;
  padding: 1rem;
  overflow-x: auto;
}

/* App shell layout primitive — used by the eventual notes UI.
   Mobile-first: sidebar hidden behind a toggle, content fills
   the viewport. Tablet+: sidebar visible, fixed width.
   Desktop+: sidebar wider, content has reading max-width. */
.app-shell {
  display: grid;
  grid-template-columns: 1fr;
  min-height: calc(100vh - 3.25rem); /* minus header */
}
.app-sidebar {
  display: none;
  border-right: 1px solid var(--border);
  background: var(--card);
  padding: 1rem;
  overflow-y: auto;
  /* Pointer / touch friendliness for the eventual resize handle. */
  touch-action: pan-y;
}
.app-shell[data-sidebar="open"] .app-sidebar { display: block; }
.app-content { padding: 1rem; min-width: 0; }

@media (min-width: 768px) {
  .app-shell { grid-template-columns: 16rem 1fr; }
  .app-sidebar { display: block; }
  .app-content { padding: 1.25rem 1.5rem; }
}
@media (min-width: 1024px) {
  .app-shell { grid-template-columns: 18rem 1fr; }
}
@media (min-width: 1440px) {
  .app-shell { grid-template-columns: 20rem minmax(0, 1fr); }
  .app-content { max-width: 56rem; padding: 2rem; }
}
@media (min-width: 2560px) {
  /* On ultrawide, reserve a third column for backlinks/preview
     so the editor doesn't stretch into illegibility. */
  .app-shell { grid-template-columns: 22rem minmax(0, 1fr) 22rem; }
}

/* Sidebar resize handle: pointer events + capture for drag.
   Disabled by default; the eventual JS controller will toggle
   .resizing on the shell. */
.app-resize-handle {
  width: 0.4rem;
  cursor: col-resize;
  background: transparent;
  touch-action: none;
}
.app-resize-handle:hover, .app-shell.resizing .app-resize-handle {
  background: var(--accent);
}

/* Ensure inputs in the auth card fit comfortably on 320px. */
@media (max-width: 360px) {
  .auth-card { padding: 1.25rem; }
  .auth-card h1 { font-size: 1.25rem; }
}

/* Sync state badge in the app header. */
.sync-state {
  margin-left: auto;
  font-size: 0.85rem;
  padding: 0.2rem 0.6rem;
  border-radius: 1rem;
  background: var(--card);
  color: var(--muted);
  border: 1px solid var(--border);
}
.sync-state[data-state="syncing"] { color: var(--accent); }
.sync-state[data-state="synced"]  { color: var(--success); }
.sync-state[data-state="offline"] { color: var(--muted); }
.sync-state[data-state="error"]   { color: var(--error); }
.app-page .app-header .who { margin-left: 0; }

/* Conflict dialog. */
#conflict-dialog::backdrop { background: rgba(0,0,0,0.4); }
#conflict-dialog {
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  background: var(--bg);
  color: var(--fg);
  padding: 1.5rem;
  max-width: min(48rem, 90vw);
  width: 100%;
}
.conflict-cols {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}
@media (max-width: 600px) { .conflict-cols { grid-template-columns: 1fr; } }
.conflict-cols pre {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 0.4rem;
  padding: 0.75rem;
  max-height: 30vh;
  overflow: auto;
  white-space: pre-wrap;
}
#conflict-form menu {
  display: flex;
  gap: 0.5rem;
  margin: 1rem 0 0;
  padding: 0;
}
#conflict-form button {
  padding: 0.5rem 1rem;
  border-radius: 0.35rem;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: var(--accent-fg);
  cursor: pointer;
}
#conflict-form button[value="remote"] {
  background: transparent;
  color: var(--accent);
}

/* Onboarding dialog reuses the conflict dialog visuals but
   needs a slightly different size and list styling. */
#onboarding-dialog::backdrop { background: rgba(0,0,0,0.4); }
#onboarding-dialog {
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  background: var(--bg);
  color: var(--fg);
  padding: 1.75rem;
  max-width: min(36rem, 90vw);
  width: 100%;
}
#onboarding-dialog h2 { margin-top: 0; }
#onboarding-dialog ul { padding-left: 1.25rem; }
#onboarding-dialog li { margin: 0.4rem 0; }
#onboarding-dialog menu { padding: 0; margin: 1rem 0 0; }
#onboarding-dialog button {
  padding: 0.55rem 1.1rem;
  border-radius: 0.35rem;
  border: 0;
  background: var(--accent);
  color: var(--accent-fg);
  cursor: pointer;
  font-weight: 500;
}
