/* Layout and components. Every colour, radius and typeface comes from a variable, and the site's brand.css
   (generated by src/setup.mjs from the site's theme, then tuned by hand) overrides them, so each desk looks
   like the site it manages. */
:root {
  --bg: #F7F2E9; --white: #FFFDF9; --ink: #2B2B2B; --muted: #6E6A63; --line: #E4DCCF;
  --accent: #24595B; --accent-2: #24595B; --soft: #AAB6A3; --clay: #BC7058; --gold: #C49A45; --client: #C49A45;
  --serif: Georgia, serif; --sans: system-ui, Arial, sans-serif;
  --header-bg: var(--white); --header-fg: var(--accent); --header-sub: var(--muted); --header-line: var(--line);
  --wordmark-size: 24px; --wordmark-weight: 400; --wordmark-pre-weight: 400; --wordmark-tracking: 0; --wordmark-accent: var(--clay);
  --pill-bg: transparent; --pill-fg: var(--accent); --pill-active-bg: var(--accent); --pill-active-fg: var(--white); --pill-radius: 4px;
  --btn-bg: var(--accent); --btn-fg: var(--white); --btn-radius: 4px;
  --card-radius: 4px; --field-radius: 4px;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.55 var(--sans); display: flex; flex-direction: column; }

.col { max-width: 980px; margin: 0 auto; padding-inline: clamp(16px, 4vw, 40px); width: 100%; }
.top { background: var(--header-bg); color: var(--header-fg); position: sticky; top: 0; z-index: 2; box-shadow: 0 1px 0 var(--header-line); }
.top-row { display: flex; align-items: center; gap: 14px; }
.top-row.edge { padding-top: 12px; padding-bottom: 10px; }
.top-row.sub { padding-top: 4px; padding-bottom: 12px; flex-wrap: wrap; row-gap: 8px; }
.brand { display: flex; flex-direction: column; text-decoration: none; color: inherit; }
.brand .mark { width: 36px; height: 36px; display: block; margin-bottom: 6px; }
.brand .wordmark { font: var(--wordmark-weight) var(--wordmark-size)/1 var(--serif); letter-spacing: var(--wordmark-tracking); color: var(--header-fg); white-space: nowrap; }
.brand .wordmark .pre { font-weight: var(--wordmark-pre-weight); }
.brand .wordmark .accent { color: var(--wordmark-accent); }
.brand .subbrand { font: 600 11px/1 var(--sans); letter-spacing: .12em; text-transform: uppercase; color: var(--header-sub); margin-top: 6px; }
.sites { display: flex; gap: 7px; flex-wrap: wrap; row-gap: 7px; }
.sites a, .libbtn { white-space: nowrap; font: 600 13px/1.2 var(--sans); color: var(--pill-fg); background: var(--pill-bg); text-decoration: none; border: 0; border-radius: var(--pill-radius); padding: 8px 13px; cursor: pointer; transition: background .15s ease, color .15s ease; }
.sites a:hover, .sites a:focus-visible, .libbtn:hover, .libbtn:focus-visible { background: var(--pill-active-bg); color: var(--pill-active-fg); }
.libbtn.active { background: var(--pill-active-bg); color: var(--pill-active-fg); }
.status { margin-left: auto; font-size: 13px; color: var(--header-sub); display: flex; align-items: center; gap: 8px; }
.status .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--soft); }
.status.busy .dot { background: var(--gold); animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { opacity: .35; } }
.me { font-size: 13px; color: var(--header-sub); white-space: nowrap; margin-left: auto; }

.thread { flex: 1; overflow-y: auto; padding: 24px clamp(16px, 4vw, 40px) 16px; display: flex; flex-direction: column; gap: 14px; max-width: 980px; width: 100%; margin: 0 auto; scrollbar-gutter: stable; }
.msg { display: grid; grid-template-columns: 34px 1fr; gap: 12px; align-items: start; }
.avatar { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; font: 600 15px/1 var(--sans); color: var(--white); background: var(--soft); }
.msg.role-agent .avatar { background: var(--accent); }
.msg.role-owner .avatar { background: var(--clay); }
.msg.role-client .avatar { background: var(--client); }
.msg.role-system .avatar { background: var(--muted); }
.meta { font-size: 12px; color: var(--muted); margin-bottom: 3px; display: flex; gap: 8px; align-items: baseline; }
.meta b { color: var(--ink); font-weight: 600; }
.body { background: var(--white); border: 1px solid var(--line); border-radius: var(--card-radius); padding: 12px 16px; max-width: 72ch; }
.msg.role-agent .body { border-left: 3px solid var(--accent-2); }
.msg.kind-private .body { border: 1px dashed var(--clay); background: color-mix(in srgb, var(--clay) 8%, var(--white)); }
.msg.kind-private .meta::after { content: "private note"; color: var(--clay); font-weight: 600; }
.msg.role-agent.kind-private .meta::after, .msg.role-system.kind-private .meta::after { content: "private reply, only the owner sees this"; }
.msg.kind-aside .body { border: 1px dashed var(--gold); background: color-mix(in srgb, var(--gold) 10%, var(--white)); }
.msg.kind-aside .meta::after { content: "between you two, the studio does not see this"; color: var(--gold); font-weight: 600; }
.msg.kind-question .body { border-left: 3px solid var(--gold); background: color-mix(in srgb, var(--gold) 10%, var(--white)); }
.msg.kind-question .meta::after { content: "question for the owner"; color: var(--gold); font-weight: 600; }
.body p { margin: 0 0 10px; } .body p:last-child { margin: 0; }
.body ul { margin: 0 0 10px; padding-left: 20px; }
.body a { color: var(--accent-2); }
.body code { font-size: 14px; background: var(--bg); padding: 1px 5px; border-radius: 3px; }
.files { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.files a { font-size: 13px; border: 1px solid var(--line); border-radius: 20px; padding: 4px 12px; text-decoration: none; color: var(--accent); background: var(--bg); }
.files img { max-height: 160px; border-radius: 4px; border: 1px solid var(--line); }
.reply { font-size: 12px; color: var(--muted); margin-bottom: 6px; }

.card { background: var(--white); border: 1px solid var(--line); border-radius: var(--card-radius); padding: 10px 14px; max-width: 72ch; }
.card .head { display: flex; align-items: center; gap: 10px; }
.card .state { width: 10px; height: 10px; border-radius: 50%; background: var(--soft); flex: none; }
.card.running .state { background: var(--gold); animation: pulse 1.2s infinite; }
.card.done .state { background: var(--accent-2); }
.card.failed .state { background: var(--clay); }
.card .title { font-weight: 600; flex: 1; }
.card .comment { font-size: 12px; color: var(--accent-2); background: none; border: 0; cursor: pointer; padding: 2px 4px; font-family: inherit; }
.card .comment:hover { text-decoration: underline; }
.card .detail { font-size: 13px; color: var(--muted); white-space: pre-wrap; margin: 6px 0 0 20px; }
.card .shot { display: block; margin: 10px 0 2px 20px; max-width: 100%; max-height: 420px; border: 1px solid var(--line); border-radius: 4px; cursor: zoom-in; object-fit: cover; object-position: top; }

.composer { border-top: 1px solid var(--line); background: var(--white); padding: 10px 0 calc(12px + env(safe-area-inset-bottom, 0px)); position: sticky; bottom: 0; }
.composer .row { display: flex; align-items: flex-end; gap: 10px; }
.composer textarea { flex: 1; resize: none; border: 1px solid var(--line); border-radius: var(--field-radius); padding: 10px 14px; font: 16px/1.45 var(--sans); background: var(--bg); color: var(--ink); max-height: 40vh; }
.composer textarea:focus { outline: 2px solid var(--accent-2); outline-offset: 1px; }
.attach { color: var(--accent); cursor: pointer; padding: 10px 6px; }
.attach input { display: none; }
.send { background: var(--btn-bg); color: var(--btn-fg); border: 0; border-radius: var(--btn-radius); padding: 11px 22px; font: 650 15px var(--sans); cursor: pointer; }
.send:disabled { opacity: .5; cursor: default; }
.chips, .options { display: flex; flex-wrap: wrap; gap: 8px 16px; font-size: 13px; color: var(--muted); }
.chips:not(:empty) { margin-bottom: 8px; }
.chip { background: var(--bg); border: 1px solid var(--line); border-radius: 20px; padding: 3px 10px; display: inline-flex; gap: 6px; align-items: center; }
.chip button { border: 0; background: none; cursor: pointer; color: var(--clay); font-size: 14px; padding: 0; }
.options { margin-top: 8px; }
.opt { display: flex; align-items: center; gap: 6px; }
.opt.link { background: none; border: 0; color: var(--accent-2); cursor: pointer; font: 600 13px var(--sans); padding: 0; }
.opt.link:hover { text-decoration: underline; }
.powered { margin-left: auto; font-size: 12px; color: var(--muted); text-decoration: none; }
.powered b { font-weight: 600; color: var(--accent); }
.powered:hover b { color: var(--accent-2); }
body.signin .powered { display: inline-block; margin: 18px 0 0; }

/* Who sees which controls: the owner, clients, and only when the site has a client at all. */
body:not(.is-owner) .owner-only, body.is-owner .client-only { display: none; }
body.no-client .has-client { display: none; }
.opt span.owner-only, .opt span.client-only { display: inline; }
body:not(.is-owner) .opt span.owner-only, body.is-owner .opt span.client-only { display: none; }
body.mode-site .mode-demo-only, body.mode-demo .mode-site-only { display: none; }

.library[hidden] { display: none; }
.library { flex: 1; overflow-y: auto; background: var(--bg); padding: 22px 0 40px; }
body.lib-open .thread, body.lib-open .composer { display: none; }
.help-body { max-width: 68ch; }
.help-body h3 { font: 700 22px/1.2 var(--serif); color: var(--accent); margin: 26px 0 8px; }
.help-body h3:first-child { margin-top: 4px; }
.help-body p { margin: 0 0 10px; }
.help-body .owner-only { margin-top: 30px; padding: 16px 18px; border: 1px dashed var(--clay); border-radius: var(--card-radius); background: color-mix(in srgb, var(--clay) 8%, var(--white)); }
.help-body .owner-only h3 { margin-top: 0; color: var(--clay); }
.lib-head { position: relative; padding-right: 56px; }
.lib-head h2 { font: 700 30px/1.1 var(--serif); color: var(--accent); margin: 0 0 8px; }
.lib-head p { margin: 0 0 18px; color: var(--muted); max-width: 64ch; }
.lib-close { position: absolute; top: -4px; right: clamp(16px, 4vw, 40px); font-size: 34px; line-height: 1; background: none; border: 0; color: var(--accent); cursor: pointer; }
.lib-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }
.asset { background: var(--white); border: 1px solid var(--line); border-radius: var(--card-radius); padding: 14px 16px; display: flex; flex-direction: column; gap: 10px; }
.asset .thumb { height: 170px; display: grid; place-items: center; background: repeating-conic-gradient(var(--line) 0 25%, var(--white) 0 50%) 0 0 / 20px 20px; border: 1px solid var(--line); border-radius: 4px; overflow: hidden; }
.asset .thumb img { width: 100%; height: 170px; object-fit: contain; cursor: zoom-in; }
.asset .name { font: 600 20px/1.2 var(--serif); color: var(--accent); background: none; border: 0; border-bottom: 1px dashed transparent; padding: 0; text-align: left; cursor: text; width: 100%; }
.asset .name:hover, .asset .name:focus { border-bottom-color: var(--clay); outline: 0; }
.asset input.name { border-bottom: 1px solid var(--accent); }
.asset .orig, .asset .ver { font-size: 13px; color: var(--muted); margin: 0; }
.asset .ver b { color: var(--ink); font-weight: 600; }
.asset .ver a { color: var(--accent-2); }
.asset .used { color: var(--ink); }
.asset .none { color: var(--clay); }
.asset .err { font-size: 13px; color: var(--clay); margin: 0; }

.lightbox[hidden] { display: none; }
.lightbox { position: fixed; inset: 0; background: rgba(20,20,20,.85); display: grid; place-items: center; z-index: 10; }
.lightbox img { max-width: 96vw; max-height: 94vh; background: var(--white); }
.lightbox button { position: absolute; top: 14px; right: 18px; font-size: 32px; background: none; border: 0; color: var(--white); cursor: pointer; }

body.signin { align-items: center; justify-content: center; padding: 16px; background: var(--header-bg); }
body.signin .card { max-width: 440px; padding: 30px 32px; border-radius: var(--card-radius); }
body.signin .brand { margin-bottom: 18px; }
body.signin .brand .wordmark { color: var(--accent); }
body.signin .brand .subbrand { color: var(--muted); }
body.signin h1 { font: 700 24px/1.2 var(--serif); color: var(--accent); margin: 0 0 12px; }
body.signin p { margin: 0; color: var(--muted); }

@media (max-width: 600px) {
  .status { display: none; }
  .lib-grid { grid-template-columns: 1fr; }
  .me { display: none; }
  .brand .wordmark { font-size: calc(var(--wordmark-size) - 4px); }
  .msg { grid-template-columns: 28px 1fr; gap: 8px; }
  .avatar { width: 28px; height: 28px; font-size: 13px; }
}
