/* Self-hosted (the page CSP is default-src 'self'). Both are variable fonts covering 300 to 800. */
@font-face {
  font-family: "Merriweather Sans";
  src: url("/fonts/merriweather-sans-latin.woff2") format("woff2");
  font-weight: 300 800;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Open Sans";
  src: url("/fonts/open-sans-latin.woff2") format("woff2");
  font-weight: 300 800;
  font-style: normal;
  font-display: swap;
}

/* Tokens mirror the desktop Workspace app (spike/ui.html). */
:root {
  --blue: #3979DA;
  --blue-deep: #2F68C2;
  --navy: #2E4D6E;
  --sky: #D6E4F0;
  --ice: #EBF1F8;
  --canvas: #F3F6FA;
  --card: #FFFFFF;
  --ink: #2D3436;
  --ink-2: #4B5563;
  --mid: #6B7280;
  --faint: #9AA3AF;
  --line: #DEE6EF;
  --line-soft: #EDF1F6;
  --ring: #D5DEE8;
  --focus: rgba(57,121,218,.18);
  --ok: #2F7D5B;
  --ok-soft: #E6F3EC;
  --warn: #B4690E;
  --warn-soft: #FBF1E3;
  --warn-rail: #F0B860;
  --crit: #B3261E;
  --you-bubble: #E3EDF9;
  --you-ink: #1F3651;
  --shadow-1: 0 0 0 1px #DEE6EF, 0 1px 2px rgba(46,77,110,.06), 0 2px 8px rgba(46,77,110,.04);
  --shadow-primary: 0 1px 2px rgba(57,121,218,.3);
  --r-sm: 6px;
  --r-ctl: 8px;
  --r-card: 12px;
  --r-bubble: 14px;
  --r-pill: 999px;
  --font-head: "Merriweather Sans", system-ui, -apple-system, sans-serif;
  --font-body: "Open Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-mono: ui-monospace, Menlo, monospace;
  --warn-bg: #FBF1E3;
  --crit-bg: #FBE9E7;
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
  --sar: env(safe-area-inset-right, 0px);
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.45;
  color: var(--ink);
  background: var(--canvas);
  -webkit-text-size-adjust: 100%;
  display: flex;
  flex-direction: column;
  padding-top: var(--sat);
}
[hidden] { display: none !important; }
button, input, textarea { font: inherit; font-size: 16px; }
h1 { font-family: var(--font-head); font-size: 18px; margin: 0; font-weight: 700; color: var(--navy); }

#banners { flex: 0 0 auto; }
.banner {
  padding: 10px calc(14px + var(--sar)) 10px calc(14px + var(--sal));
  font-weight: 600;
  font-size: 15px;
  border-bottom: 1px solid var(--line);
}
.banner.warn { color: var(--warn); background: var(--warn-bg); border-bottom-color: #EBCB9F; }
.banner.crit { color: var(--crit); background: var(--crit-bg); border-bottom-color: #F0B8B3; }

.screen { flex: 1 1 auto; display: flex; flex-direction: column; min-height: 0; }
.scroll { flex: 1 1 auto; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 12px calc(12px + var(--sar)) calc(16px + var(--sab)) calc(12px + var(--sal)); }

.bar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 52px;
  padding: 8px calc(14px + var(--sar)) 8px calc(14px + var(--sal));
  background: var(--navy);
  color: #fff;
}
.bar h1 { flex: 1 1 auto; min-width: 0; color: #fff; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-mark { flex: none; display: block; width: 28px; height: 28px; }
.back { flex: none; background: none; border: 0; color: #fff; padding: 6px 4px 6px 0; min-height: 36px; font-weight: 600; cursor: pointer; }
.bar .tile { width: 26px; height: 26px; font-size: 10.5px; }
.bar .pill { flex: none; }

/* One control scale, as on the desktop; sized up for a thumb. */
.btn {
  border: 1px solid var(--ring); background: #fff; border-radius: var(--r-ctl);
  min-height: 36px; padding: 7px 14px; font-size: 14px; font-weight: 600; color: var(--navy);
  white-space: nowrap; cursor: pointer;
  transition: border-color .12s, background .12s, color .12s, box-shadow .12s;
}
.btn:active { border-color: var(--blue); color: var(--blue); }
.btn:disabled { opacity: .45; cursor: default; }
.btn.primary { background: var(--blue); border-color: var(--blue-deep); color: #fff; box-shadow: var(--shadow-primary); }
.btn.primary:active { background: var(--blue-deep); color: #fff; }
.btn.quiet { border-color: transparent; background: transparent; color: var(--mid); font-weight: 500; }
.btn.quiet:active { background: var(--ice); color: var(--navy); }
@media (hover: hover) {
  .btn:hover { border-color: var(--blue); color: var(--blue); }
  .btn.primary:hover { background: var(--blue-deep); color: #fff; }
  .btn.quiet:hover { background: var(--ice); color: var(--navy); border-color: transparent; }
}

.pill {
  display: inline-block; font-size: 12px; font-weight: 600; padding: 2px 10px; border-radius: var(--r-pill);
  background: var(--ice); color: var(--navy); line-height: 1.5; white-space: nowrap;
}
.pill:empty { display: none; }
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.busy { background: var(--you-bubble); color: var(--blue); }
.pill.ended { background: #F0F2F5; color: var(--mid); }

.tile {
  display: inline-grid; place-items: center; flex: none; border-radius: var(--r-sm);
  color: #fff; font-family: var(--font-body); font-weight: 700; background: var(--navy); letter-spacing: .02em;
}

.muted { color: var(--mid); font-size: 14px; }
.center { text-align: center; }
.inline-error { color: var(--crit); font-size: 14px; margin: 6px 0; }

/* Pairing */
#pair { justify-content: center; align-items: center; padding: 24px; }
.pair-card {
  background: var(--card); border-radius: var(--r-card); box-shadow: var(--shadow-1);
  padding: 28px 24px 24px; max-width: 380px; width: 100%; text-align: center;
}
.pair-card p { color: var(--ink-2); font-size: 15px; margin: 0; }
.pair-card .inline-error { color: var(--crit); font-size: 14px; margin-top: 10px; }
.pair-logo { display: block; margin: 0 auto 10px; border-radius: 16px; }
.pair-card h1 { font-size: 22px; margin-bottom: 8px; }
#pair-form { display: flex; gap: 8px; margin-top: 18px; }
#pair-code {
  flex: 1 1 auto; min-width: 0; font-size: 22px; letter-spacing: 6px; text-align: center;
  padding: 10px; border: 1px solid var(--ring); border-radius: 10px; background: #fff; color: var(--ink);
  outline: none; transition: border-color .12s, box-shadow .12s;
}
#pair-btn { min-height: 48px; padding: 0 20px; font-size: 16px; }

/* Window list */
.window-list { list-style: none; margin: 0; padding: 2px 0 0; }
.window-list li { margin-bottom: 10px; }
.wl-row {
  width: 100%; text-align: left; display: flex; align-items: center; gap: 12px;
  background: var(--card); border: 0; border-radius: var(--r-card); box-shadow: var(--shadow-1);
  padding: 12px 14px; cursor: pointer; color: var(--ink);
}
.wl-row:active { background: #F8FAFD; }
.wl-row .tile { width: 36px; height: 36px; font-size: 12px; }
.wl-row .tile.long { font-size: 10px; letter-spacing: 0; }
.bar .tile.long { font-size: 8px; letter-spacing: 0; }
.wl-main { flex: 1 1 auto; min-width: 0; display: block; }
.wl-name {
  display: block; font-family: var(--font-head); font-weight: 600; font-size: 16px; color: var(--navy);
  line-height: 1.3; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.wl-role { display: block; font-size: 13px; color: var(--mid); line-height: 1.35; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.wl-ctx { display: block; font-size: 12px; color: var(--mid); margin-top: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.wl-ctx.hot, .wl-ctx.soon { color: var(--warn); font-weight: 600; }
.wl-tasks + .wl-ctx { margin-top: 0; }
.wl-row .pill { flex: none; }
/* Swipe a row left for Close and Hand off. The actions sit under the row and are painted only while
   it is dragged or open, so a closed row looks as before. */
.wl-item { position: relative; }
.wl-row { position: relative; z-index: 1; touch-action: pan-y; -webkit-user-select: none; user-select: none; transition: transform .2s ease; }
.wl-row.dragging { transition: none; }
.wl-actions {
  position: absolute; top: 0; right: 0; bottom: 0; display: flex; align-items: center; gap: 8px;
  padding: 0 2px 0 10px; visibility: hidden;
}
.wl-item.reveal .wl-actions { visibility: visible; }
.wl-actions .btn { min-height: 44px; }
.list-error { margin: 0 2px 10px; }
.notify { margin-top: 20px; display: flex; flex-direction: column; align-items: flex-start; gap: 8px; }

/* Window: context meter and session actions, a white strip under the navy bar */
.win-tools { flex: 0 0 auto; background: var(--card); border-bottom: 1px solid var(--line); }
.meter { padding: 10px calc(16px + var(--sar)) 0 calc(16px + var(--sal)); font-size: 13px; color: var(--mid); }
.meter:last-child { padding-bottom: 10px; }
.meter-row { display: flex; align-items: center; gap: 10px; }
.meter-label { flex: none; font-weight: 600; color: var(--navy); }
.meter-bar { flex: 1 1 auto; position: relative; height: 4px; background: var(--line); border-radius: 2px; }
.meter-bar i { display: block; height: 100%; background: var(--blue); border-radius: 2px; }
.meter-bar b { position: absolute; top: -2px; bottom: -2px; width: 2px; margin-left: -1px; background: var(--faint); opacity: .6; border-radius: 1px; }
.meter-detail { font-size: 12px; margin-top: 4px; }
.meter.hot, .meter.hot .meter-label { color: var(--warn); }
.meter.hot .meter-bar i { background: var(--warn); }
.meter.soon, .meter.soon .meter-label { color: var(--warn); }
.meter.soon .meter-bar i { background: var(--warn-rail); }
.win-actions { display: flex; gap: 8px; padding: 10px calc(16px + var(--sar)) 10px calc(16px + var(--sal)); }
.win-actions .btn { flex: 1 1 0; min-width: 0; min-height: 40px; }
.actions-note { margin: 0; font-size: 13px; color: var(--mid); }

/* Thread: Clawd writes on the page, you write in a bubble (desktop .m) */
.thread {
  display: flex; flex-direction: column; gap: 12px;
  padding-left: calc(16px + var(--sal)); padding-right: calc(16px + var(--sar));
  background: radial-gradient(120% 60% at 50% 0%, #FFFFFF 0%, var(--canvas) 70%);
}
#win.ended .thread { background: radial-gradient(120% 60% at 50% 0%, #F3F7FC 0%, var(--sky) 70%); }
#win.ended .composer { background: var(--ice); }
.msg { max-width: 88%; font-size: 15px; line-height: 1.55; overflow-wrap: anywhere; }
.msg.you {
  align-self: flex-end; background: var(--you-bubble); color: var(--you-ink);
  border-radius: var(--r-bubble) var(--r-bubble) 4px var(--r-bubble); padding: 9px 13px; white-space: pre-wrap;
}
.msg.clawd { align-self: flex-start; position: relative; padding-left: 28px; max-width: 100%; color: var(--ink); }
.msg.clawd.first::before {
  content: "C"; position: absolute; left: 0; top: 2px; width: 20px; height: 20px; border-radius: var(--r-sm);
  background: var(--blue); color: #fff; font-size: 10px; font-weight: 700; display: grid; place-items: center;
  font-family: var(--font-body);
}
.msg .label { display: block; font-size: 11.5px; font-weight: 600; color: var(--mid); margin-bottom: 1px; white-space: normal; }
.msg .status { display: block; font-size: 12px; color: var(--mid); margin-top: 3px; white-space: normal; }
.msg .status.err { color: var(--crit); }
.line {
  align-self: flex-start; font-size: 12.5px; color: var(--faint); padding-left: 28px;
  white-space: pre-wrap; overflow-wrap: anywhere; margin: -4px 0;
}
.line.err, .msg.err { color: var(--crit); }
.partial-note { display: block; font-size: 12px; color: var(--faint); margin-top: 4px; }
.md p { margin: 0 0 8px; }
.md p:last-child { margin-bottom: 0; }
.md ul, .md ol { margin: 0 0 8px; padding-left: 20px; }
.md ul:last-child, .md ol:last-child { margin-bottom: 0; }
.md code { font-family: var(--font-mono); font-size: 13px; background: var(--ice); border-radius: 4px; padding: 1px 4px; }
.md pre { background: #fff; box-shadow: 0 0 0 1px var(--line-soft); border-radius: var(--r-ctl); padding: 8px 10px; overflow-x: auto; margin: 0 0 8px; }
.md pre code { background: none; padding: 0; white-space: pre; }
.md a { color: var(--blue); }
.thread-empty { color: var(--faint); text-align: center; margin-top: 24px; font-size: 15px; }

/* Composer */
.composer {
  flex: 0 0 auto;
  background: var(--card);
  border-top: 1px solid var(--line-soft);
  padding: 10px calc(12px + var(--sar)) calc(10px + var(--sab)) calc(12px + var(--sal));
}
.composer-row { display: flex; gap: 8px; align-items: flex-end; }
#msg {
  flex: 1 1 auto; min-width: 0; resize: none; max-height: 40vh; min-height: 44px; line-height: 1.45;
  border: 1px solid var(--ring); border-radius: 10px; padding: 10px 12px; color: var(--ink); background: #fff;
  outline: none; transition: border-color .12s, box-shadow .12s;
}
#send { min-height: 44px; padding: 0 18px; font-size: 15px; }
#msg:focus, #pair-code:focus { border-color: var(--blue); box-shadow: 0 0 0 3px var(--focus); }
