/* app.css — the web shell's own styles. External by design: the CSP in index.html
   allows no inline style at all, so there is no <style> element and no style=""
   attribute anywhere in the shell.

   The --ui-* block below stands in for the Hermes Desktop theme: plugin/src/sims.css
   (built to sims.css) reads those variables, exactly as plugin/dev/harness.html
   provides them. Values match the harness so the office looks like the Desktop one. */

:root {
  --ui-base: #1b1d27;
  --ui-bg-editor: #f4f5f8;
  --ui-bg-elevated: #ffffff;
  --ui-bg-tertiary: #eceef3;
  --ui-stroke-secondary: #d9dce5;
  --ui-text-primary: #1b1d27;
  --ui-text-secondary: #5f6476;
  --ui-text-tertiary: #8a8fa0;
  --ui-accent: #b8791c;
  --ui-green: #23925f;
  --ui-blue: #2f74b5;
  --ui-purple: #7d52c7;
  --ui-yellow: #b97510;
  --ui-red: #c93a3a;
  --ui-cyan: #0f8a92;
  --ui-row-hover-background: rgba(0, 0, 0, .06);

  --ro-gap: 10px;
  --ro-radius: 10px;
  --ro-danger: #c93a3a;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --ui-base: #e8eaf1;
    --ui-bg-editor: #111318;
    --ui-bg-elevated: #1a1d25;
    --ui-bg-tertiary: #232733;
    --ui-stroke-secondary: #2d3240;
    --ui-text-primary: #e8eaf1;
    --ui-text-secondary: #9ba1b4;
    --ui-text-tertiary: #737a8e;
    --ui-accent: #e5a948;
    --ui-row-hover-background: rgba(255, 255, 255, .08);
  }
}

html, body {
  height: 100%;
  margin: 0;
  background: var(--ui-bg-editor);
  color: var(--ui-text-primary);
  font-family: system-ui, -apple-system, "PingFang HK", "Noto Sans TC", sans-serif;
  /* M1: no double-tap zoom over the 3D viewport, safe-area aware */
  touch-action: manipulation;
  -webkit-text-size-adjust: 100%;
}

.ro-app {
  display: grid;
  /* three named rows, explicitly assigned below: auto-placement would shift the
     stage into the banner's row whenever the banner is [hidden] (display:none
     items are not placed at all), leaving the 3D view 0 px tall */
  grid-template-rows: auto auto minmax(0, 1fr);
  grid-template-areas: "bar" "banner" "stage";
  height: 100%;
  min-height: 0;
  position: relative; /* .ro-toast 用 absolute 定位喺呢個框入面 */
}
.ro-bar { grid-area: bar; }
.ro-readonly { grid-area: banner; }
.ro-stage { grid-area: stage; }
noscript { display: none; }

.ro-bar {
  display: flex;
  align-items: center;
  gap: var(--ro-gap);
  padding: 8px 12px;
  padding-top: max(8px, env(safe-area-inset-top));
  border-bottom: 1px solid var(--ui-stroke-secondary);
  background: var(--ui-bg-elevated);
  font-size: 13px;
}

.ro-brand { font-weight: 600; }
.ro-brand-sub { font-weight: 400; color: var(--ui-text-tertiary); margin-left: 6px; }

.ro-pill {
  margin-left: auto;
  padding: 3px 9px;
  border-radius: 999px;
  border: 1px solid var(--ui-stroke-secondary);
  color: var(--ui-text-secondary);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 60vw;
}
.ro-pill[data-status="connected"] { color: var(--ui-green); border-color: currentColor; }
.ro-pill[data-status="pairing"] { color: var(--ui-accent); border-color: currentColor; }
.ro-pill[data-status="read-only"],
.ro-pill[data-status="offline"],
.ro-pill[data-status="idle"] { color: var(--ro-danger); border-color: currentColor; }

.ro-kill {
  font: inherit;
  padding: 4px 10px;
  border-radius: 8px;
  border: 1px solid var(--ui-stroke-secondary);
  background: transparent;
  color: var(--ro-danger);
  cursor: pointer;
  min-height: 28px;
}
.ro-kill:hover { background: var(--ui-row-hover-background); }

.ro-readonly {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 12px;
  background: color-mix(in srgb, var(--ro-danger) 14%, var(--ui-bg-elevated));
  border-bottom: 1px solid color-mix(in srgb, var(--ro-danger) 45%, transparent);
  color: var(--ui-text-primary);
  font-size: 13px;
}
.ro-readonly[hidden] { display: none; }
.ro-readonly strong { color: var(--ro-danger); }
.ro-readonly span { flex: 1 1 auto; }
.ro-readonly button {
  font: inherit;
  padding: 4px 10px;
  min-height: 44px; /* M1 touch target */
  border-radius: 8px;
  border: 1px solid var(--ro-danger);
  background: transparent;
  color: var(--ro-danger);
  cursor: pointer;
}

.ro-stage {
  position: relative;
  min-height: 0;
  min-width: 0;
  overflow: hidden;
}
.ro-stage .hs-root { height: 100%; width: 100%; }

/* act-level controls mirrored from the office (status.js sets [disabled] + data-hs-gate) */
[data-hs-gate][disabled] { opacity: .45; cursor: not-allowed; }

/* 「唯讀」提示（main.js installActGuard 閃 1.4 秒） */
.ro-toast {
  position: absolute;
  left: 50%;
  bottom: calc(18px + env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(8px);
  max-width: min(92vw, 420px);
  padding: 8px 14px;
  border-radius: 999px;
  background: var(--ro-danger);
  color: #fff;
  font-size: 13px;
  line-height: 1.3;
  text-align: center;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .28);
  opacity: 0;
  pointer-events: none;
  transition: opacity .18s ease, transform .18s ease;
  z-index: 40;
}
.ro-toast[data-on="1"] { opacity: 1; transform: translateX(-50%) translateY(0); }
@media (prefers-reduced-motion: reduce) {
  .ro-toast { transition: none; }
}

.ro-pair {
  position: absolute;
  inset: auto 0 0 0;
  margin: 0 auto;
  max-width: 520px;
  padding: 14px 16px calc(14px + env(safe-area-inset-bottom));
  border-top-left-radius: var(--ro-radius);
  border-top-right-radius: var(--ro-radius);
  background: var(--ui-bg-elevated);
  border: 1px solid var(--ui-stroke-secondary);
  border-bottom: 0;
  box-shadow: 0 -8px 30px rgba(0, 0, 0, .18);
  z-index: 5;
  font-size: 13px;
}
.ro-pair[hidden] { display: none; }
.ro-pair-title { margin: 0 0 4px; font-size: 15px; }
.ro-pair-lede { margin: 0 0 10px; color: var(--ui-text-secondary); }

.ro-pair-form, .ro-magic-form {
  display: grid;
  gap: 8px;
  margin-bottom: 10px;
}
.ro-field { display: grid; gap: 3px; }
.ro-field-label { color: var(--ui-text-tertiary); font-size: 12px; }
.ro-field input {
  font: inherit;
  padding: 8px 10px;
  min-height: 44px;
  border-radius: 8px;
  border: 1px solid var(--ui-stroke-secondary);
  background: var(--ui-bg-tertiary);
  color: var(--ui-text-primary);
}
.ro-pair-form button, .ro-magic-form button {
  font: inherit;
  padding: 8px 12px;
  min-height: 44px;
  border-radius: 8px;
  border: 1px solid var(--ui-accent);
  background: var(--ui-accent);
  color: #1b1d27;
  font-weight: 600;
  cursor: pointer;
}
.ro-pair-form button[disabled], .ro-magic-form button[disabled] { opacity: .5; cursor: progress; }

.ro-sas-box {
  display: grid;
  gap: 2px;
  justify-items: center;
  padding: 10px;
  margin: 0 0 10px;
  border-radius: var(--ro-radius);
  border: 1px dashed var(--ui-accent);
  background: var(--ui-bg-tertiary);
}
.ro-sas-box[hidden] { display: none; }
.ro-sas-label, .ro-sas-hint { color: var(--ui-text-secondary); font-size: 12px; }
.ro-sas-code { font-size: 28px; letter-spacing: .22em; font-variant-numeric: tabular-nums; }

.ro-note { margin: 0; color: var(--ui-text-secondary); }
.ro-note[data-kind="error"] { color: var(--ro-danger); }

/* 已配對裝置列表（auth.js `GET /devices`）：文字一律 textContent，唔用 HTML */
.ro-devices { margin: 0 0 10px; padding-top: 8px; border-top: 1px solid var(--ui-stroke-secondary); }
.ro-devices-title { margin: 0 0 6px; font-size: 13px; color: var(--ui-text-secondary); }
.ro-devices-list { list-style: none; margin: 0 0 8px; padding: 0; display: grid; gap: 4px; max-height: 132px; overflow: auto; }
.ro-device { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px; padding: 4px 6px; border-radius: 6px; background: var(--ui-bg-tertiary); }
.ro-device-name { font-weight: 600; }
.ro-device-id, .ro-device-fp { font-size: 11px; color: var(--ui-text-tertiary); }
.ro-device-role { margin-left: auto; font-size: 11px; color: var(--ui-text-secondary); }
.ro-devices button {
  font: inherit;
  padding: 6px 10px;
  border-radius: 8px;
  border: 1px solid var(--ui-stroke-secondary);
  background: transparent;
  color: var(--ui-text-primary);
  cursor: pointer;
}
.ro-noscript { padding: 12px; }

/* mobile: the pairing card becomes a bottom sheet (M1), the strip wraps */
@media (max-width: 480px) {
  .ro-bar { flex-wrap: wrap; }
  .ro-pill { max-width: 100%; margin-left: 0; }
  .ro-pair { max-width: 100%; inset: auto 0 0 0; border-radius: 0; }
}

/* ── chat（階段 5）────────────────────────────────────────────────────────────
   Right-hand drawer over the 3D stage; a bottom sheet under 720px. All nodes are
   built by remote/web/src/chat.js with createElement + textContent, so there is no
   HTML sink to style around. Message rows use `min-height` (row height is only an
   estimate used by the virtual window). */
.ro-chat {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(420px, 100%);
  display: grid;
  grid-template-rows: auto auto auto auto auto minmax(0, 1fr) auto auto;
  gap: 6px;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  background: var(--ui-bg-elevated);
  border-left: 1px solid var(--ui-stroke-secondary);
  box-shadow: -8px 0 30px rgba(0, 0, 0, .12);
  z-index: 4;
  font-size: 13px;
}
.ro-chat[hidden] { display: none; }

.ro-chat-head { display: flex; align-items: baseline; gap: 8px; }
.ro-chat-title { font-weight: 600; font-size: 14px; }
.ro-chat-session {
  color: var(--ui-text-tertiary);
  font-size: 11px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ro-chat-pickrow { display: flex; }
.ro-chat-pick {
  font: inherit;
  width: 100%;
  min-height: 36px;
  padding: 4px 8px;
  border-radius: 8px;
  border: 1px solid var(--ui-stroke-secondary);
  background: var(--ui-bg-tertiary);
  color: var(--ui-text-primary);
}

.ro-chat-note {
  margin: 0;
  font-size: 11px;
  line-height: 1.35;
  color: var(--ui-text-tertiary);
}

.ro-chat-tools { display: flex; flex-wrap: wrap; gap: 6px; }
.ro-chat-mate {
  font: inherit;
  flex: 1 1 120px;
  min-height: 36px;
  padding: 4px 8px;
  border-radius: 8px;
  border: 1px solid var(--ui-stroke-secondary);
  background: var(--ui-bg-tertiary);
  color: var(--ui-text-primary);
}
.ro-chat-btn {
  font: inherit;
  min-height: 36px;
  padding: 4px 12px;
  border-radius: 8px;
  border: 1px solid var(--ui-stroke-secondary);
  background: transparent;
  color: var(--ui-text-primary);
  cursor: pointer;
}
.ro-chat-btn:hover:not([disabled]) { background: var(--ui-row-hover-background); }
.ro-chat-btn[disabled] { opacity: .45; cursor: not-allowed; }
.ro-chat-stop { color: var(--ro-danger); }
.ro-chat-send {
  border-color: var(--ui-accent);
  background: var(--ui-accent);
  color: #1b1d27;
  font-weight: 600;
}

.ro-chat-error {
  margin: 0;
  padding: 6px 8px;
  border-radius: 8px;
  border: 1px solid var(--ro-danger);
  color: var(--ro-danger);
  font-size: 12px;
}
.ro-chat-error[hidden] { display: none; }

.ro-chat-list {
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  border: 1px solid var(--ui-stroke-secondary);
  border-radius: var(--ro-radius);
  background: var(--ui-bg-editor);
  padding: 6px 8px;
}
.ro-chat-pad { width: 100%; }
.ro-msg {
  min-height: 28px;
  padding: 6px 8px;
  margin: 0 0 6px;
  border-radius: 8px;
  line-height: 1.45;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}
.ro-msg-user { background: var(--ui-bg-tertiary); }
.ro-msg-assistant { background: var(--ui-bg-elevated); border: 1px solid var(--ui-stroke-secondary); }
.ro-msg-system { color: var(--ui-text-secondary); font-size: 12px; }
.ro-msg-live { border-style: dashed; }
.ro-msg pre {
  margin: 4px 0;
  padding: 6px 8px;
  overflow-x: auto;
  border-radius: 6px;
  background: var(--ui-bg-tertiary);
  font-size: 12px;
  white-space: pre;
}
.ro-msg code { font-size: 12px; }
.ro-msg strong { font-weight: 600; }
.ro-msg .md-h { font-weight: 600; margin: 4px 0 2px; }
.ro-msg .md-h1 { font-size: 15px; }
.ro-msg .md-h2 { font-size: 14px; }
.ro-msg .md-li { padding-left: 6px; }
.ro-msg .md-quote {
  border-left: 2px solid var(--ui-stroke-secondary);
  padding-left: 8px;
  color: var(--ui-text-secondary);
}
.ro-msg hr { border: 0; border-top: 1px solid var(--ui-stroke-secondary); margin: 6px 0; }

.ro-chat-form { display: flex; gap: 6px; align-items: stretch; }
.ro-chat-input {
  font: inherit;
  flex: 1 1 auto;
  min-height: 44px;
  max-height: 120px;
  padding: 8px;
  border-radius: 8px;
  border: 1px solid var(--ui-stroke-secondary);
  background: var(--ui-bg-tertiary);
  color: var(--ui-text-primary);
  resize: none;
}
.ro-chat-input[disabled] { opacity: .6; cursor: not-allowed; }
.ro-chat-lede { margin: 0; font-size: 11px; color: var(--ui-text-tertiary); }
.ro-chat-lede[hidden] { display: none; }

@media (max-width: 720px) {
  .ro-chat {
    top: auto;
    left: 0;
    width: 100%;
    height: min(70vh, 560px);
    border-left: 0;
    border-top: 1px solid var(--ui-stroke-secondary);
    border-top-left-radius: var(--ro-radius);
    border-top-right-radius: var(--ro-radius);
  }
}
