/* yegge-docs — app-layer styles on top of yegge-design.css */

/* ── App shell ─────────────────────────────────────────── */
.app-shell {
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: 100vh;
}
.app-sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 1.5rem 1rem calc(1.5rem + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}
.app-sidebar .nav-brand { display: block; margin-bottom: 1.25rem; padding: 0 0.5rem; }
.side-link {
  display: block;
  padding: 0.45rem 0.6rem;
  border-radius: 2px;
  font-size: 0.82rem;
  color: var(--text);
  text-decoration: none;
  letter-spacing: 0.02em;
}
.side-link:hover { background: var(--surface2); color: var(--text-bright); }
.side-link.active { background: var(--surface2); color: var(--text-bright); }
.side-section { margin-top: 1.25rem; }
.app-main { padding: 2rem clamp(1.25rem, 3vw, 3rem); min-width: 0; }

/* ── Doc list ──────────────────────────────────────────── */
.doc-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.8rem 0.9rem;
  border: 1px solid var(--border);
  border-radius: 3px;
  background: var(--surface);
  margin-bottom: 0.5rem;
  cursor: pointer;
  transition: border-color 0.15s;
}
.doc-row:hover { border-color: var(--accent); }
.doc-row .doc-title { color: var(--text-bright); font-size: 0.95rem; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.doc-row .doc-date { font-size: 0.7rem; color: var(--text-muted); white-space: nowrap; }

/* ── Editor ────────────────────────────────────────────── */
.editor-toolbar {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  flex-wrap: wrap;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1rem;
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 30;
}
.editor-toolbar .tb-sep { width: 1px; height: 18px; background: var(--border2); margin: 0 0.3rem; }

/* Toolbar select — .btn can't be reused here: yegge-design.css's bare
   `select` rule loads after `.btn` and would win the width:100% cascade. */
.tb-select {
  width: auto;
  background: var(--surface2);
  border: 1px solid var(--border2);
  border-radius: 2px;
  color: var(--text);
  font-size: 0.72rem;
  font-family: inherit;
  padding: 0.25em 0.5em;
  cursor: pointer;
}
.tb-select:hover { border-color: var(--accent); }
.editor-surface {
  width: 100%;
  min-height: 55vh;
  background: var(--input-bg);
  border: 1px solid var(--border2);
  border-radius: 3px;
  color: var(--text-bright);
  font-family: 'SFMono-Regular', 'Fira Code', Consolas, monospace;
  font-size: 0.88rem;
  line-height: 1.7;
  padding: 1.25rem;
  outline: none;
  resize: vertical;
}
.editor-surface:focus { border-color: var(--accent); }
.editor-surface.richtext {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Helvetica Neue', Arial, sans-serif;
}
.editor-meta { display: flex; gap: 0.75rem; flex-wrap: wrap; align-items: center; margin: 0.75rem 0 1rem; }
.editor-meta input[type="text"] { width: auto; flex: 1; min-width: 140px; }
.editor-meta-field { display: flex; align-items: center; gap: 0.45rem; margin: 0; }
.editor-meta-field .label { margin: 0; white-space: nowrap; }
.editor-date-field input { width: auto; }

@media (max-width: 640px) {
  .editor-date-field { width: 100%; align-items: stretch; flex-direction: column; gap: 0.25rem; }
  .editor-date-field input { width: 100%; }
}
.dictating { border-color: var(--danger-hover) !important; color: #c07070 !important; }

/* preview pane */
.preview-pane {
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 1.5rem 2rem;
  background: var(--surface);
  min-height: 55vh;
}

/* code render iframe */
.code-render-frame {
  width: 100%;
  min-height: 260px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: #fff;
  margin: 1.5rem 0;
}
.code-render-toggle { right: 4.2rem; }

/* ── AI drawer ─────────────────────────────────────────── */
.ai-drawer {
  position: fixed;
  top: 0; right: 0; bottom: 0;
  width: min(420px, 92vw);
  background: var(--surface);
  border-left: 1px solid var(--border2);
  z-index: 150;
  display: flex;
  flex-direction: column;
  transform: translateX(102%);
  transition: transform 0.2s ease;
}
.ai-drawer.open { transform: none; }
.ai-drawer-body { flex: 1; overflow-y: auto; padding: 1.25rem 1.25rem calc(1.25rem + env(safe-area-inset-bottom)); }
.ai-output {
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 1rem;
  font-size: 0.82rem;
  white-space: pre-wrap;
  max-height: 40vh;
  overflow-y: auto;
  margin-top: 1rem;
}

/* ── Databases (Notion/Airtable-style grid) ──────────────── */
.db-grid-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: 3px; max-height: 70vh; }
.db-grid { margin: 0; min-width: 640px; }
.db-grid thead th { position: sticky; top: 0; z-index: 1; }
.db-grid td input, .db-grid td select {
  background: transparent; border: none; padding: 0.2em 0.3em; width: 100%;
  color: var(--text-bright); font-size: 0.85rem;
}
.db-grid td input:focus { background: var(--input-bg); }
.db-grid .row-del { opacity: 0; }
.db-grid tr:hover .row-del { opacity: 1; }

/* Field-type glyph before each column name, e.g. "# Amount" for a number field */
.db-field-icon { display: inline-block; width: 1.1em; opacity: 0.6; font-size: 0.9em; margin-right: 0.15em; }

/* Select cells render as a colored pill (pillStyle() sets the actual hue
   inline per value) rather than a plain dropdown, matching how Notion and
   Airtable show single-select values. */
.db-grid select.db-select {
  border-radius: 3px;
  font-weight: 500;
  padding: 0.2em 0.5em;
}
.db-grid select.db-select:not([style*="background"]) { color: var(--text-muted); }

/* Multiselect keeps the plain text input for editing (comma-separated) but
   previews the current values as colored chips underneath, read-only. */
.db-pills { display: flex; flex-wrap: wrap; gap: 0.25rem; padding: 0.1rem 0.3rem 0.3rem; }
.db-pill { font-size: 0.72rem; font-weight: 500; padding: 0.1em 0.55em; border-radius: 3px; white-space: nowrap; }

/* Inline "+ New" row instead of a separate button below the table — subtle
   until hovered, consistent with Notion's bottom-of-table add affordance. */
.db-add-row td {
  color: var(--text-muted);
  cursor: pointer;
  padding: 0.55rem 0.75rem;
  letter-spacing: 0.02em;
}
.db-add-row:hover td { background: var(--surface2); color: var(--text-bright); }

/* ── Login ─────────────────────────────────────────────── */
.login-wrap[hidden], .app-shell[hidden] { display: none !important; }

.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 1.25rem;
  padding: 2rem;
  text-align: center;
}

/* ── Public cards ──────────────────────────────────────── */
/* #docs spans the full device width (container--full on index.html) —
   auto-fill turns that width into 1 column on phones and multiple on
   wider screens, instead of one card stretched edge-to-edge. */
#docs, #lib-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 1rem;
}
#docs .empty-state, #lib-grid .empty-state { grid-column: 1 / -1; }

.pub-card {
  display: block;
  background: var(--surface);
  border: 1px solid var(--border2);
  border-radius: 3px;
  padding: 1.25rem 1.5rem;
  text-decoration: none;
  transition: border-color 0.15s;
}
.pub-card:hover { border-color: var(--accent); }
.pub-card h3 { margin-bottom: 0.3rem; font-size: 1.1rem; }

/* locked public redactions — solid, not clickable */
.redacted--locked { cursor: default; }

/* attachments list */
.att-row { display: flex; align-items: center; gap: 0.6rem; padding: 0.4rem 0; font-size: 0.82rem; border-bottom: 1px solid var(--border); }

/* search results — attachment row grows a snippet line below the filename,
   so unlike the plain single-line .att-row it aligns to the top and lets
   .att-search-info stack its children instead of squeezing them inline */
.att-row--search { align-items: flex-start; padding: 0.6rem 0; }
.att-search-info { flex: 1; min-width: 0; }
.att-search-info p { margin: 0.2rem 0 0; }

/* ── Text size controls ───────────────────────────────────
   A-/A+ buttons that adjust --font-scale (see yegge-design.css §html),
   which the whole site's rem-based sizing scales from. Shared markup:
     <div class="text-size-controls" role="group" aria-label="Text size">
       <button class="btn btn--icon btn--sm" onclick="adjustTextScale(-0.1)"
               data-textsize="dec" title="Decrease text size">A−</button>
       <button class="btn btn--icon btn--sm" onclick="adjustTextScale(0.1)"
               data-textsize="inc" title="Increase text size">A+</button>
     </div>
   JS lives in theme.js (loaded on every page already). */
.text-size-controls {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  flex-shrink: 0;
}
.text-size-controls .btn { font-weight: 600; }
.text-size-controls .btn:disabled { opacity: 0.35; }

/* Tag cloud — yegge-design.css only styles hover on <a class="tag">;
   the tag cloud uses <button> (no navigation target, JS-driven filter),
   so hover needs restating here. Sizes vary per-tag via inline style
   (frequency-based), so no fixed font-size here. */
#tag-cloud { row-gap: 0.5rem; }
#tag-cloud .tag { border: none; background: var(--tag-bg); cursor: pointer; line-height: 1.6; }
#tag-cloud .tag:hover, #tag-cloud .tag--active { color: var(--text-bright); background: var(--surface2); }
#tag-cloud .tag .hint { font-size: 0.8em; margin-left: 0.15em; }

/* ── Site footer ───────────────────────────────────────────
   On the public pages (index.html, doc.html), <body class="has-footer">
   pins this to the bottom of the viewport on short pages and pushes
   below content on long ones, without touching yegge-design.css's global
   body rule (which the app shell also depends on and shouldn't inherit
   this — the app's full-height editor layout manages its own sizing). */
body.has-footer { display: flex; flex-direction: column; min-height: 100vh; }
body.has-footer > main { flex: 1; }

.site-footer {
  padding: 1.5rem 2rem;
  text-align: center;
  font-size: 0.72rem;
  letter-spacing: 0.02em;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
.site-footer a { color: var(--text-muted); text-decoration: none; }
.site-footer a:hover { color: var(--text); text-decoration: underline; }
.site-footer .footer-sep { opacity: 0.5; margin: 0 0.4em; }

/* mobile */
@media (max-width: 800px) {
  .app-shell { grid-template-columns: 1fr; }
  .app-sidebar {
    /* align-self: start — without it, .app-shell's min-height:100vh (needed
       so the desktop sticky sidebar fills the viewport) makes CSS Grid's
       default item stretch inflate this row far past its own content once
       it's no longer that fixed-height column, and align-content then
       spreads the wrapped nav lines apart to fill the extra space. */
    position: static; height: auto; flex-direction: row; flex-wrap: wrap;
    border-right: none; border-bottom: 1px solid var(--border);
    align-items: center; align-self: start;
  }
  .app-sidebar .nav-brand { margin: 0 0.75rem 0 0; }
  .side-section { margin-top: 0; }
}

/* Public-site reading text on phones — yegge-design.css drops the root
   font-size to 14px at this breakpoint for the app's compact toolbar UI,
   which also shrinks .prose since it inherits from the same rem scale.
   Long-form reading wants the opposite of a dense UI: override back up
   to a comfortable size here rather than touching the shared root (which
   would also resize the app's buttons/toolbar). */
@media (max-width: 600px) {
  .prose { font-size: 1.15rem; line-height: 1.75; }
  .prose h1 { font-size: 1.55rem; }
  .prose h2 { font-size: 1.25rem; }
  .prose h3 { font-size: 1.1rem; }
  .prose h4 { font-size: 1rem; }
  .prose pre code { font-size: 0.85rem; }

  .pub-card { padding: 1.1rem 1.25rem; }
  .pub-card h3 { font-size: 1.15rem; }

  #tag-cloud .tag { padding: 0.35em 0.7em; }
}
