/* Companion: the clipboard on its hook (every kid page) and the parent office's chats page. Every rule is scoped
   under .co- (registered globally by app/features/companion). Workshop Shadow Board, inherited whole: steel plate,
   1px seams, machinist-blue presses, black label tape; safety yellow only when a work order is hung or a to-do is done.
   Layers: tab bar 30 < hook 35 < laptop panel 45 < phone sheet 50 < toasts 60. */

:root { --co-w: 400px; --co-top: 57px; --co-hook: 52px; }

/* ------------------------------------------------------------------ the hook (closed) */
.co-hook {
  position: fixed; z-index: 35; right: 16px; bottom: calc(var(--tabbar-h) + 16px + env(safe-area-inset-bottom, 0px));
  width: var(--co-hook); height: var(--co-hook); display: grid; place-items: center; padding: 0;
  border-radius: var(--r-lg); border: 1px solid var(--line); background: var(--surface); color: var(--ink-2);
  box-shadow: var(--shadow-hung); cursor: pointer;
  transition: border-color .15s ease, color .15s ease, transform .08s ease;
}
.co-hook .icon { width: 26px; height: 26px; }
.co-hook:hover { border-color: var(--ink-3); color: var(--blue); }
.co-hook:active { transform: translateY(1px); }
.co-hook:focus-visible { outline: 2px solid var(--focus); outline-offset: 3px; }
.co-dot {
  position: absolute; top: -4px; right: -4px; width: 12px; height: 12px; border-radius: 50%;
  background: var(--blue); border: 2px solid var(--ground);
}
.co-dot[hidden] { display: none; }
/* while it's open the close button lives in the panel header */
body.co-open .co-hook { visibility: hidden; }

/* room for the hook: page bottoms, toasts and the pitch editor's sticky bar clear it */
body:has(.co-hook) .main { padding-bottom: calc(112px + var(--co-hook)); }
body:has(.co-hook) .toasts { bottom: calc(86px + var(--co-hook) + 12px + env(safe-area-inset-bottom, 0px)); }
@media (min-width: 900px) {
  body:has(.co-hook) .main { padding-bottom: calc(48px + var(--co-hook) + 16px); }
  body:has(.co-hook) .toasts { bottom: 24px; }
  body:has(.co-hook) .pt-actions { padding-right: calc(var(--co-hook) + 24px); }
}

/* ------------------------------------------------------------------ the panel */
.co-panel {
  position: fixed; z-index: 50; inset: 0; display: flex; flex-direction: column; min-height: 0;
  background: var(--surface); color: var(--ink);
}
.co-panel[hidden] { display: none; }
.co-body, .co-sheet { display: flex; flex-direction: column; flex: 1; min-height: 0; }
body.co-open { overflow: hidden; }
body.co-open .tabbar { display: none; }
@media (min-width: 900px) {
  .co-panel {
    z-index: 45; inset: var(--co-top) 0 0 auto; width: var(--co-w);
    border-left: 1px solid var(--line); box-shadow: var(--shadow);
  }
  body.co-open { overflow: auto; }
  /* the page stays usable to the left when there is room for both */
  body.co-open .toasts { left: calc((100% - var(--co-w)) / 2); }
}
/* 900-1239px: not enough room to share, so the panel is modal: the page dims behind it (a tap there closes it) */
@media (min-width: 900px) and (max-width: 1239px) {
  body.co-open { overflow: hidden; }
  body.co-open .co-dock::before { content: ""; position: fixed; inset: 0; z-index: 44; background: rgba(10, 12, 15, .38); }
}
@media (min-width: 1240px) {
  body.co-open .shell { margin-right: var(--co-w); }
  body.co-open .toasts { left: calc(var(--rail) + (100% - var(--rail) - var(--co-w)) / 2); }
}

.co-head {
  display: flex; align-items: center; gap: 4px; padding: 10px 10px 10px 16px;
  padding-top: calc(10px + env(safe-area-inset-top, 0px)); border-bottom: 1px solid var(--line);
}
/* the clip: a steel bar clamped across the top edge of the clipboard */
.co-head { position: relative; }
.co-head::before {
  content: ""; position: absolute; top: env(safe-area-inset-top, 0px); left: 50%; width: 76px; height: 7px; transform: translateX(-50%);
  border-radius: 0 0 var(--r-sm) var(--r-sm); background: var(--surface-3); box-shadow: inset 0 -1px 0 var(--line);
}
@media (min-width: 900px) { .co-head::before { top: 0; } }
@media (min-width: 900px) { .co-head { padding-top: 10px; } }
.co-title { font: 800 1.44rem/1.1 var(--font-display); letter-spacing: .03em; text-transform: uppercase; min-width: 0; overflow-wrap: anywhere; }
.co-head-gap { flex: 1; }
.co-icon-btn {
  display: inline-grid; place-items: center; width: 40px; height: 40px; flex: none; padding: 0;
  border: 0; border-radius: var(--r); background: transparent; color: var(--ink-2); cursor: pointer;
}
.co-icon-btn:hover { background: var(--surface-2); color: var(--ink); }
.co-icon-btn[aria-expanded="true"] { background: var(--blue-soft); color: var(--blue); }
.co-icon-btn:focus-visible, .co-seg-btn:focus-visible, .co-switch:focus-visible, .co-check:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
@media (pointer: coarse) { .co-icon-btn { width: 44px; height: 44px; } }

.co-rename { display: grid; gap: 6px; padding: 12px 16px; border-bottom: 1px solid var(--line); background: var(--surface-2); }
.co-rename[hidden] { display: none; }
.co-rename label { font-weight: 700; font-size: .95rem; }
.co-rename-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; }
.co-fine { font-size: .8rem; color: var(--ink-3); }

/* Ask / To-do / Notes */
.co-seg { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 3px; margin: 10px 12px 0; padding: 3px; border-radius: var(--r); border: 1px solid var(--line); background: var(--surface-2); }
.co-seg-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 40px; padding: 6px 8px;
  border: 0; border-radius: var(--r-sm); background: transparent; color: var(--ink-2); font: 700 .95rem var(--font-body); cursor: pointer;
}
.co-seg-btn .icon { width: 18px; height: 18px; }
.co-seg-btn:hover { color: var(--ink); }
.co-seg-btn[aria-selected="true"] { background: var(--surface); color: var(--blue); }
.co-count { min-width: 20px; padding: 0 5px; border-radius: var(--r-sm); background: var(--label-tape); color: var(--label-ink); font: 500 .76rem/1.5 var(--font-mono); font-variant-numeric: tabular-nums; }
@media (pointer: coarse) { .co-seg-btn { min-height: 44px; } }

.co-pane { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.co-pane[hidden] { display: none; }

.co-context { display: flex; align-items: center; flex-wrap: wrap; gap: 6px 8px; margin: 10px 16px 0; font-size: .85rem; }
.co-context-link { min-width: 0; font-weight: 700; color: var(--ink); text-decoration-color: var(--line); text-underline-offset: 3px; overflow-wrap: anywhere; }
.co-context-link:hover { color: var(--blue); text-decoration-color: currentColor; }
.co-switch { margin-left: auto; padding: 6px 8px; min-height: 36px; border: 0; border-radius: var(--r); background: transparent; color: var(--blue); font: 700 .85rem var(--font-body); cursor: pointer; }
.co-switch:hover { background: var(--blue-soft); }

/* the log */
.co-log {
  flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; display: flex; flex-direction: column; gap: 10px;
  padding: 14px 16px 18px; scrollbar-width: thin; scrollbar-color: var(--surface-3) transparent;
}
.co-log > :first-child { margin-top: auto; }
/* lines slide out of sight under the control instead of being sliced by it */
.co-log { -webkit-mask-image: linear-gradient(to bottom, transparent 0, #000 16px); mask-image: linear-gradient(to bottom, transparent 0, #000 16px); }
.co-log .msg { max-width: 92%; font-size: 1rem; }
.co-log .msg.me .msg-who { color: var(--blue-ink); }
.co-log .msg.ai { background: var(--ground); }
.co-log .msg-body > * + * { margin-top: .55em; }
.co-log .msg-body ul, .co-log .msg-body ol { padding-left: 1.2em; }
.co-plain { white-space: pre-wrap; overflow-wrap: anywhere; }
.co-turn { display: flex; flex-direction: column; gap: 8px; align-self: flex-start; max-width: 100%; }
.co-turn > .msg { max-width: 100%; }
.co-thinking { color: var(--ink-3); }
.msg.ai.is-offline { background: var(--surface-2); }
.co-retry { margin-top: 10px; }
.co-earlier { align-self: center; }
.co-starters { display: flex; flex-wrap: wrap; gap: 8px; padding: 0 16px 12px; }
.co-starter { min-height: 38px; font-size: .85rem; }

.co-composer {
  display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: end; gap: 8px;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom, 0px)); border-top: 1px solid var(--line); background: var(--surface);
}
@media (min-width: 900px) { .co-composer { padding-bottom: 12px; } }
.co-composer textarea { min-height: 46px; max-height: 32vh; resize: none; line-height: 1.45; padding-block: 11px; }
.co-send { width: 46px; min-height: 46px; padding: 0; }
.co-send .icon { width: 20px; height: 20px; }

/* ------------------------------------------------------------------ work orders */
.co-orders { display: grid; gap: 8px; }
.co-orders.is-loading { opacity: .85; }
.co-orders-wait { display: inline-flex; align-items: center; gap: 8px; font-size: .85rem; color: var(--ink-3); }
.co-orders-wait .icon { width: 16px; height: 16px; animation: co-jot 1.6s ease-in-out infinite; }
@keyframes co-jot { 50% { transform: translate(2px, -1px) rotate(-8deg); } }
.co-order {
  display: grid; gap: 6px; padding: 12px 12px 12px 14px; border-radius: var(--r); border: 1px solid var(--line);
  background: var(--surface);
}
.co-order-tape { display: flex; align-items: center; flex-wrap: wrap; gap: 6px 10px; }
.co-order-tag {
  background-color: var(--label-tape); background-image: linear-gradient(var(--paint), var(--paint));
  background-repeat: no-repeat; background-size: 0% 100%;
}
.co-order-kind { display: inline-flex; align-items: center; gap: 5px; font-size: .85rem; font-weight: 700; color: var(--ink-2); }
.co-order-kind .icon { width: 16px; height: 16px; }
.co-order-title { font-size: 1rem; line-height: 1.35; overflow-wrap: anywhere; }
.co-order-why { font-size: .85rem; color: var(--ink-2); }
.co-order-acts { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 2px; }
.co-order-acts form { display: contents; }
.co-order.is-hung { border-color: color-mix(in srgb, var(--paint) 60%, var(--line)); }
.co-order.is-hung .co-order-tag { background-size: 100% 100%; color: var(--paint-ink); }
/* the one authored moment: hanging it paints the tape yellow, left to right */
.co-order.is-just-hung .co-order-tag { animation: co-paint .5s cubic-bezier(.16, 1, .3, 1) both; }
@keyframes co-paint { from { background-size: 0% 100%; color: var(--label-ink); } 45% { color: var(--label-ink); } to { background-size: 100% 100%; color: var(--paint-ink); } }
.co-hung { display: flex; align-items: center; flex-wrap: wrap; gap: 6px 10px; font-size: .85rem; font-weight: 700; color: var(--good); }
.co-hung .icon { width: 18px; height: 18px; }
.co-hung a { display: inline-flex; align-items: center; gap: 2px; color: var(--blue); text-underline-offset: 3px; }
.co-order-gone { font-size: .85rem; color: var(--ink-3); }
.co-when { font: 500 .76rem/1.5 var(--font-mono); color: var(--ink-3); font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ------------------------------------------------------------------ to-dos and notes */
.co-list { display: flex; flex-direction: column; gap: 10px; flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 14px 16px 20px; scrollbar-width: thin; scrollbar-color: var(--surface-3) transparent; }
.co-add { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; align-items: end; }
.co-add input { min-height: 44px; }
.co-add-btn { min-height: 44px; }
.co-add-note textarea { min-height: 72px; resize: vertical; }
.co-todos, .co-notes, .co-side-list { list-style: none; margin: 0; padding: 0; }
.co-todo { display: grid; grid-template-columns: 36px minmax(0, 1fr) auto auto; align-items: center; gap: 6px; padding: 6px 0; border-bottom: 1px solid var(--line); }
.co-todo:last-child { border-bottom: 0; }
.co-todo form { display: contents; }
.co-check {
  width: 36px; height: 36px; display: grid; place-items: center; padding: 0; border: 0; background: transparent; cursor: pointer;
  position: relative; color: var(--paint-ink);
}
.co-check::before { content: ""; position: absolute; inset: 7px; border: 2px solid var(--field-line); border-radius: var(--r-sm); background: var(--surface); }
.co-check:hover::before { border-color: var(--blue); }
.co-check.is-on::before { background: var(--paint); border-color: var(--paint); }
.co-check .icon { position: relative; width: 16px; height: 16px; stroke-width: 3; }
.co-todo-title { overflow-wrap: anywhere; line-height: 1.35; }
.co-todo.is-due .co-when { color: var(--warn); font-weight: 700; }
.co-todo.is-done .co-todo-title { color: var(--ink-3); text-decoration: line-through; text-decoration-color: var(--paint); text-decoration-thickness: 3px; }
.co-del { width: 36px; height: 36px; color: var(--ink-3); }
.co-del .icon { width: 18px; height: 18px; }
@media (pointer: coarse) { .co-check, .co-del { width: 44px; height: 44px; } .co-todo { grid-template-columns: 44px minmax(0, 1fr) auto auto; } }
.co-done summary { cursor: pointer; padding: 8px 0; font-weight: 700; color: var(--ink-2); font-size: .95rem; }
.co-num { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.co-empty { color: var(--ink-3); font-size: .95rem; line-height: 1.5; padding: 4px 0; max-width: 40ch; }
.co-note { display: grid; gap: 4px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.co-note:last-child { border-bottom: 0; }
.co-note-title { overflow-wrap: anywhere; }
.co-note-body { white-space: pre-wrap; overflow-wrap: anywhere; color: var(--ink-2); font-size: 1rem; line-height: 1.5; }
.co-note-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.co-note-foot form { display: contents; }

.co-loading { display: flex; align-items: center; gap: 8px; margin: auto; color: var(--ink-3); font-weight: 700; }

/* ------------------------------------------------------------------ the parent office */
.co-office-grid { display: grid; gap: var(--gap); align-items: start; }
@media (min-width: 1000px) { .co-office-grid { grid-template-columns: minmax(0, 1fr) 300px; } .co-office-side { position: sticky; top: 78px; } }
.co-ledger { list-style: none; margin: 0; padding: 0; }
.co-ledger-where { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; padding: 14px 0 6px; font-weight: 700; }
.co-line { display: grid; grid-template-columns: 62px minmax(0, 1fr); gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.co-line time { font: 500 .8rem/1.9 var(--font-mono); color: var(--ink-3); text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.co-line-who { display: block; font-size: .8rem; font-weight: 700; color: var(--ink-3); margin-bottom: 2px; }
.co-line.is-kid .co-line-who { color: var(--blue); }
.co-line-text { overflow-wrap: anywhere; line-height: 1.5; }
.co-line-text > * + * { margin-top: .5em; }
.co-line-text ul, .co-line-text ol { padding-left: 1.2em; }
.co-flag { display: flex; gap: 8px; align-items: flex-start; margin-top: 6px; padding: 6px 10px; border-radius: var(--r); background: var(--warn-soft); font-size: .85rem; }
.co-flag .icon { margin-top: 2px; }
.co-guarded { margin-top: 6px; font-size: .85rem; }
.co-guarded summary { cursor: pointer; color: var(--ink-2); font-weight: 700; }
.co-guarded p { margin-top: 6px; padding: 8px 10px; border-radius: var(--r); background: var(--surface-2); }
.co-office-side { display: grid; gap: 8px; }
.co-side-h { margin-top: 8px; font-size: .85rem; font-weight: 700; color: var(--ink-2); }
.co-side-list li { display: flex; justify-content: space-between; gap: 10px; padding: 6px 0; border-bottom: 1px solid var(--line); font-size: 1rem; }
.co-side-list li:last-child { border-bottom: 0; }
.co-toggle { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 12px; align-items: start; cursor: pointer; }
.co-toggle input { width: 22px; height: 22px; margin-top: 2px; accent-color: var(--blue); }
.co-toggle > span { display: grid; gap: 2px; }
.co-latest { overflow-wrap: anywhere; }

@media (prefers-reduced-motion: reduce) {
  .co-order.is-just-hung .co-order-tag { animation: none; }
  .co-orders-wait .icon { animation: none; }
}

/* ------------------------------------------------------------------ round-2 finish fixes */
.co-hint { display: flex; align-items: flex-start; gap: 10px; max-width: 34ch; color: var(--ink-3); font-size: .95rem; line-height: 1.5; }
.co-hint .icon { width: 20px; height: 20px; flex: none; margin-top: 2px; }
.co-undo { display: flex; align-items: center; flex-wrap: wrap; gap: 4px 10px; padding: 6px 10px; border-radius: var(--r); background: var(--surface-2); font-size: .95rem; overflow-wrap: anywhere; }
.co-undo-btn { min-height: 36px; padding: 4px 10px; border: 0; border-radius: var(--r); background: transparent; color: var(--blue); font: 700 .95rem var(--font-body); cursor: pointer; }
.co-undo-btn:hover { background: var(--blue-soft); }
.co-undo-btn:focus-visible, .co-reconnect:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
@media (pointer: coarse) { .co-undo-btn { min-height: 44px; } }
.co-reconnect { margin-top: 8px; }
.co-disclose { display: grid; gap: 8px; margin: 8px 16px 0; font-size: .85rem; }
.co-disclose summary { cursor: pointer; font-weight: 700; color: var(--ink-2); }
.co-disclose[open] { padding-bottom: 4px; }
.co-disclose .btn { justify-self: start; }
