/* pure-space-shell.css — the shell both pages share: the tokens (common base §13.3), the panes, the
 * column headers and buttons (§13.4), a space's files as a list or a grid of tiles, the view panel
 * under its strip (the selected file and what can be done to it), the dialogs of the write path
 * (pure-space-actions.js), and the notice card (the sign-in, a 403, a 404). A document tile is a
 * scaled frame on the document (recipes/pure-document-thumbnail-recipe.html); the view panel is an
 * <iframe> on the file's own URL. What each page adds: pure-space-app.css (the phone),
 * pure-space-admin.css (the spaces column). */

:root {
  --bg:      #f2f1ee;  /* app canvas behind surfaces        */
  --surface: #ffffff;  /* banner, cards, panels             */
  --border:  #d6d4cf;  /* hairlines, ghost-button fill      */
  --text:    #1e1e1e;  /* primary text                      */
  --dim:     #888888;  /* labels, muted meta                */
  --accent:  #4a9eff;  /* app name, links, primary buttons  */
  --ok:      #5cb85c;
  --err:     #c0392b;
  --warn:    #d4860a;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg:      #141414;
    --surface: #1f1f1f;
    --border:  #2e2e2e;
    --text:    #dddddd;
    --dim:     #777777;
    --accent:  #4a9eff;
    --ok:      #5cb85c;
    --err:     #d9534f;
    --warn:    #f0ad4e;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; } /* let the `hidden` attribute win over display rules */
html, body { height: 100%; }
body {
  margin: 0;
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  background: var(--bg);
}

/* ── The panes ──────────────────────────────────────────────────────────────── */
#app { display: flex; height: 100vh; height: 100dvh; overflow: hidden; }
.col {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  overflow: hidden;
}
#files-col { flex: 0 1 auto; width: var(--files-w, 500px); min-width: 300px; }
.divider { flex: 0 0 auto; width: 6px; cursor: col-resize; background: var(--border); }
.divider:hover { filter: brightness(.92); }
#right {
  flex: 1 1 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  overflow: hidden;
  container-type: inline-size;   /* the strip below asks how wide the panel is */
}
/* The strip over the panel: the selected file's title and meta, then its actions. A panel too narrow
   for a title beside the actions keeps the actions — all of them, on a second row if it must: none is
   ever cut off (660px: the seven actions and a title one can still read). */
.doc-head .who  { flex: 0 1 auto; min-width: 0; }
.doc-head .meta { flex: 1 8 auto; min-width: 0; font-size: 11px; color: var(--dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }   /* the meta gives way before the title */
@container (max-width: 660px) {
  .col-head.doc-head { height: auto; min-height: 42px; flex-wrap: wrap; row-gap: 6px; padding-block: 5px; }
  .doc-head .who, .doc-head .meta { display: none; }
}
.stage { flex: 1 1 0; min-height: 0; position: relative; overflow: hidden; }   /* the document scrolls INSIDE the iframe */
.viewer { width: 100%; height: 100%; border: none; background: #fff; display: block; }
.empty {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  color: var(--dim);
}
/* Keep mouse-drag events flowing while resizing over the iframe. */
body.dragging { cursor: col-resize; user-select: none; }
body.dragging .viewer { pointer-events: none; }

/* ── Column headers (equal height so the columns read as one top strip) ────── */
.col-head {
  flex: 0 0 auto;
  height: 42px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.col-head h1 { margin: 0; font-size: 15px; font-weight: 600; color: var(--accent); white-space: nowrap; }
.col-head h1 .sub { color: var(--dim); font-weight: 400; }
.col-head .spacer { flex: 1; }
.col-head .who { font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.col-head form { display: contents; }

/* ── Buttons (common base §13.4) ───────────────────────────────────────────── */
button, .btn {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 5px 12px;
  border-radius: 4px;
  font: inherit;
  line-height: 1.5;
  cursor: pointer;
  white-space: nowrap;
  text-decoration: none;
  display: inline-block;
}
button:hover, .btn:hover { filter: brightness(1.15); }
button:disabled { opacity: .4; cursor: default; filter: none; }
button.ghost, .btn.ghost { background: var(--border); color: var(--text); }

.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 4px; overflow: hidden; }
.seg-btn { background: var(--surface); color: var(--dim); border-radius: 0; padding: 3px 9px; font-size: 15px; line-height: 1.4; }
.seg-btn:hover  { filter: none; background: var(--border); }
.seg-btn.is-on  { background: var(--accent); color: #fff; }

/* ── The list ──────────────────────────────────────────────────────────────── */
.index { flex: 1 1 auto; overflow-y: auto; padding: 6px 0 24px; }
.doc-row {
  display: block; width: 100%; text-align: left;
  background: none; color: var(--text); border: none; border-radius: 0;
  padding: 7px 16px; cursor: pointer; white-space: normal;
}
.doc-row:hover { filter: none; background: var(--bg); }
.doc-row.is-selected { background: color-mix(in srgb, var(--accent) 16%, transparent); box-shadow: inset 3px 0 0 var(--accent); }
.doc-row .title { font-size: 13px; }
.doc-row .meta  { font-size: 11px; color: var(--dim); margin-top: 1px; }
.docs-empty { padding: 12px 16px; font-size: 12px; color: var(--dim); font-style: italic; }

/* ── The grid: a tile per file ─────────────────────────────────────────────── */
.grid {
  flex: 1 1 auto; overflow-y: auto;
  padding: 14px;
  display: grid; align-content: start; gap: 14px;
  grid-template-columns: repeat(auto-fill, minmax(135px, 1fr));
}
.tile {
  display: flex; flex-direction: column; gap: 7px;
  padding: 10px; background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  cursor: pointer; text-align: left; color: var(--text); white-space: normal;
}
.tile:hover { filter: none; border-color: var(--accent); }
.tile.is-selected { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.thumb {
  position: relative; width: 100%;
  aspect-ratio: 210 / 297;        /* A4 portrait, for every tile — an image sits inside it */
  overflow: hidden; background: #fff;
  border: 1px solid var(--border); border-radius: 4px;
}
/* THE RECIPE, 2 and 5: a desk-sized viewport scaled by ONE transform, inert, hidden until fitted. */
.thumb .frame {
  position: absolute; top: 0; left: 0; width: 1200px; height: 1700px; border: 0; background: #fff;
  transform-origin: 0 0; pointer-events: none; visibility: hidden;
}
.thumb img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; background: var(--bg); }
.thumb.is-empty { display: flex; align-items: center; justify-content: center; color: var(--dim); font-size: 11px; background: var(--bg); }
.thumb .badge {
  position: absolute; left: 6px; bottom: 6px; z-index: 2;
  font-size: 9px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase;
  color: #fff; background: color-mix(in srgb, var(--accent) 85%, #000);
  padding: 1px 6px; border-radius: 999px; box-shadow: 0 1px 3px rgba(0,0,0,.25);
}
.thumb .badge.is-other { background: color-mix(in srgb, var(--dim) 80%, #000); text-transform: none; letter-spacing: 0; }
/* a file its space lets anyone read: said at the other corner */
.thumb .badge.is-public { left: auto; right: 6px; background: color-mix(in srgb, var(--warn) 85%, #000); }
.tile .title { font-size: 12.5px; font-weight: 600; line-height: 1.3; }
.tile .meta  { font-size: 11px; color: var(--dim); }

/* View-mode switching (scoped to the files column). */
body.mode-list .grid { display: none; }
body.mode-grid .index { display: none; }

/* ── The keys of a space, on the connect card: what asks, the two answers, each key and its end ── */
.card .ask { margin: 0 0 4px; font-size: 15px; line-height: 1.45; }
.card .answers { display: flex; gap: 8px; }
.card h2 { margin: 20px 0 6px; font-size: 13px; font-weight: 600; color: var(--dim); }
.card .keys { list-style: none; margin: 0; padding: 0; font-size: 13px; }
.card .keys li { display: flex; align-items: center; gap: 8px; padding: 6px 0; border-top: 1px solid var(--border); }
.card .keys .what { flex: 1; min-width: 0; }
.card .keys .end { display: block; color: var(--dim); font-size: 12px; }
.card .keys button { width: auto; margin: 0; padding: 4px 10px; font-size: 12px; }
.card .back { margin: 16px 0 0; }

/* ── A notice: the sign-in, a 403, a 404 ───────────────────────────────────── */
body.notice { display: flex; align-items: center; justify-content: center; padding: 16px; }
.card { width: 100%; max-width: 360px; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 24px; }
.card h1 { margin: 0 0 4px; font-size: 18px; font-weight: 600; color: var(--accent); }
.card .hint { margin: 0 0 16px; color: var(--dim); font-size: 13px; }
.card label { display: block; font-size: 12px; color: var(--dim); margin: 12px 0 4px; }
.card input {
  display: block; width: 100%; font: inherit; font-size: 16px; /* 16px: no zoom-in on a phone */
  padding: 8px 10px; border: 1px solid var(--border); border-radius: 4px; background: var(--bg); color: var(--text);
}
.card input:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
.card button { width: 100%; margin-top: 16px; padding: 9px 12px; font-size: 15px; }
.card .error { color: var(--err); font-size: 13px; margin: 12px 0 0; }
.card a { color: var(--accent); }

/* ── The dialogs of the write path: New · Rename · Versions · Trash · a reply ──────── */
dialog.dlg {
  width: min(440px, calc(100vw - 32px)); padding: 20px 24px; margin: auto;
  background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: 8px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, .25);
}
dialog.dlg::backdrop { background: rgba(0, 0, 0, .35); }
.dlg h2 { margin: 0 0 8px; font-size: 16px; font-weight: 600; color: var(--accent); }
.dlg label, .dlg .field-label { display: block; font-size: 12px; color: var(--dim); margin: 12px 0 0; }
.dlg input, .dlg select {
  display: block; width: 100%; margin-top: 4px; font: inherit; font-size: 14px;
  padding: 6px 10px; border: 1px solid var(--border); border-radius: 4px; background: var(--bg); color: var(--text);
}
.dlg input:focus, .dlg select:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
.dlg .chips { display: flex; gap: 6px; margin-top: 4px; }
.chip { background: var(--bg); color: var(--text); border: 1px solid var(--border); padding: 4px 12px; }
.chip:hover { filter: none; background: var(--border); }
.chip.is-on { background: var(--accent); color: #fff; border-color: var(--accent); }
.chip:disabled { opacity: .4; }
.dlg .hint { margin: 12px 0 0; font-size: 12px; color: var(--dim); }
.dlg .error { margin: 12px 0 0; font-size: 13px; color: var(--err); }
.dlg-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.versions { max-height: 40vh; overflow-y: auto; margin-top: 8px; border: 1px solid var(--border); border-radius: 4px; }
.dlg .version-row {
  display: flex; align-items: center; gap: 10px; margin: 0; padding: 7px 10px;
  font-size: 13px; color: var(--text); cursor: pointer; border-bottom: 1px solid var(--border);
}
.version-row:last-child { border-bottom: none; }
.version-row:hover { background: var(--bg); }
.version-row input { width: auto; margin: 0; }
.version-row .when { flex: 1; }
.version-row .size { font-size: 11px; color: var(--dim); }
