/* ─────────────────────────────────────────────────────────────────────────────
   電子員工 — the customer-facing face of a tenant's DSH process.

   Design tokens come straight from the business plan's 「溫暖專業風」direction:
   cream paper, warm grey panels, one amber accent, deep green for done states,
   large radii and soft shadows. The intent is a colleague sitting beside you,
   not a control panel: every colour that could read as "system status" is warm.
   ───────────────────────────────────────────────────────────────────────────── */

:root {
  --bg: #faf7f2;
  --panel: #f2ede4;
  --panel-2: #fffdfa;
  --ink: #2b2723;
  --ink-2: #8a8078;
  --amber: #d97706;
  --amber-soft: #fdf1e0;
  --green: #0f766e;
  --red: #b91c1c;
  --line: #e6ded1;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(43, 39, 35, .05), 0 8px 24px rgba(43, 39, 35, .06);
  --font: "Inter", "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}

button { font: inherit; cursor: pointer; }
input, textarea { font: inherit; color: inherit; }

/* ── shared bits ───────────────────────────────────────────────────────────── */

.muted { color: var(--ink-2); }
.small { font-size: 13px; }
.hidden { display: none !important; }

.card {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  background: var(--panel);
  color: var(--ink-2);
}
.badge.working { background: var(--amber-soft); color: var(--amber); }
.badge.done { background: #e6f2ef; color: var(--green); }

.dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.badge.working .dot { animation: pulse 1.1s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { opacity: 1 } 50% { opacity: .25 } }

button.primary {
  background: var(--amber);
  color: #fff;
  border: 0;
  border-radius: var(--radius-sm);
  padding: 10px 18px;
  font-weight: 600;
}
button.primary:disabled { opacity: .45; cursor: default; }
button.ghost {
  background: transparent;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 8px 14px;
  color: var(--ink-2);
}
button.ghost:hover { background: var(--panel); color: var(--ink); }

.avatar {
  width: 34px; height: 34px;
  border-radius: 11px;
  display: grid; place-items: center;
  background: var(--amber-soft);
  color: var(--amber);
  font-weight: 700;
  flex: none;
}

/* ── login (platform host only) ────────────────────────────────────────────── */

.gate {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 24px;
}
.gate .card { width: 100%; max-width: 420px; padding: 34px; }
.gate h1 { margin: 0 0 6px; font-size: 25px; letter-spacing: -.01em; }
.gate p.lede { margin: 0 0 24px; color: var(--ink-2); }
.gate label { display: block; margin: 14px 0 6px; font-size: 13px; font-weight: 600; }
.gate input {
  width: 100%;
  padding: 11px 13px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: #fff;
}
.gate input:focus { outline: 2px solid var(--amber-soft); border-color: var(--amber); }
.gate button.primary { width: 100%; margin-top: 22px; }
.gate .error { margin-top: 14px; color: var(--red); font-size: 13px; }

.gate .workspaces { margin-top: 8px; }
.gate .workspaces a {
  display: flex; align-items: center; gap: 11px;
  padding: 11px 13px; margin-bottom: 8px;
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--panel-2); color: inherit; text-decoration: none;
}
.gate .workspaces a:hover { border-color: var(--amber); }
.gate .workspaces .who { flex: 1; min-width: 0; }
.gate .workspaces .who b { display: block; font-weight: 600; }
.gate .signout { margin-top: 18px; width: 100%; }

/* ── the workspace shell ───────────────────────────────────────────────────── */

.shell {
  height: 100%;
  display: grid;
  grid-template-columns: 264px minmax(0, 1fr) 268px;
}

.rail {
  background: var(--panel);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.rail header { padding: 20px 18px 12px; }
.rail h2 { margin: 0; font-size: 13px; text-transform: uppercase; letter-spacing: .09em; color: var(--ink-2); }
.rail .list { overflow-y: auto; padding: 0 10px 10px; flex: 1; min-height: 0; }
.rail .new { margin: 12px 18px 16px; }

.employee {
  display: flex;
  gap: 11px;
  align-items: center;
  width: 100%;
  text-align: left;
  padding: 10px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: inherit;
}
.employee:hover { background: #eae3d6; }
.employee[aria-current="true"] { background: var(--panel-2); box-shadow: var(--shadow); }
.employee .meta { min-width: 0; flex: 1; }
.employee .name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.employee .sub { font-size: 12px; color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ── conversation ──────────────────────────────────────────────────────────── */

.thread { display: flex; flex-direction: column; min-height: 0; background: var(--bg); }
.thread > header {
  display: flex; align-items: center; gap: 12px;
  padding: 16px 26px;
  border-bottom: 1px solid var(--line);
  background: rgba(250, 247, 242, .9);
  backdrop-filter: blur(6px);
}
.thread > header .title { font-weight: 650; font-size: 16px; }
.thread > header .spacer { flex: 1; }

.messages { flex: 1; overflow-y: auto; padding: 26px; min-height: 0; }
.messages .empty { max-width: 460px; margin: 12vh auto; text-align: center; color: var(--ink-2); }
.messages .empty h3 { color: var(--ink); font-size: 19px; margin: 0 0 8px; }

.msg { display: flex; gap: 12px; margin-bottom: 22px; max-width: 760px; }
.msg .who { flex: none; padding-top: 2px; }
.msg .body {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 4px var(--radius) var(--radius) var(--radius);
  padding: 13px 16px;
  box-shadow: var(--shadow);
  word-break: break-word;
}
.msg.me { margin-left: auto; flex-direction: row-reverse; }
.msg.me .body {
  background: var(--amber-soft);
  border-color: #f0dcc0;
  border-radius: var(--radius) 4px var(--radius) var(--radius);
}
.msg .stamp { font-size: 11px; color: var(--ink-2); margin-top: 6px; }
.msg.system .body { background: transparent; border: 0; box-shadow: none; color: var(--ink-2); font-size: 13px; padding: 0 4px; }

/* ── Markdown 內容（由 markdown.js 產生；見該檔嘅安全說明）────────────────────
   The employee answers in Markdown, so the bubble has to hold real block-level
   content. Spacing is tightened to reading rhythm rather than prose: a report
   with a table and a code block should not turn into a tall column of gaps. */
.msg .body > :first-child { margin-top: 0; }
.msg .body > :last-child { margin-bottom: 0; }
.msg .body p { margin: 0 0 10px; }
.msg .body h1, .msg .body h2, .msg .body h3,
.msg .body h4, .msg .body h5, .msg .body h6 {
  margin: 16px 0 8px;
  line-height: 1.35;
  font-weight: 650;
}
.msg .body h1 { font-size: 19px; }
.msg .body h2 { font-size: 17px; }
.msg .body h3 { font-size: 15.5px; }
.msg .body h4, .msg .body h5, .msg .body h6 { font-size: 14.5px; color: var(--ink-2); }
.msg .body ul, .msg .body ol { margin: 0 0 10px; padding-left: 22px; }
.msg .body li { margin: 3px 0; }
.msg .body li > ul, .msg .body li > ol { margin: 3px 0 0; }
.msg .body a { color: var(--amber); text-underline-offset: 2px; }
.msg .body strong { font-weight: 650; }
.msg .body del { color: var(--ink-2); }
.msg .body hr { border: 0; border-top: 1px solid var(--line); margin: 14px 0; }
.msg .body blockquote {
  margin: 0 0 10px;
  padding: 2px 0 2px 12px;
  border-left: 3px solid var(--line);
  color: var(--ink-2);
}
.msg .body code {
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  font-size: 12.5px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 1px 5px;
}
.msg .body pre {
  margin: 0 0 10px;
  padding: 11px 13px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  overflow-x: auto;
}
.msg .body pre code { background: none; border: 0; padding: 0; font-size: 12.5px; line-height: 1.55; }
.msg .body table {
  border-collapse: collapse;
  margin: 0 0 10px;
  font-size: 13px;
  display: block;
  overflow-x: auto;
  max-width: 100%;
}
.msg .body th, .msg .body td { border: 1px solid var(--line); padding: 5px 10px; text-align: left; }
.msg .body th { background: var(--panel); font-weight: 600; white-space: nowrap; }
/* ── 即時串流中嘅回覆 ───────────────────────────────────────────────────────
   A reply being typed out: the caret is what tells a viewer the text is still
   arriving (without it, a half sentence looks like a finished thought). */
.msg .body.streaming::after {
  content: "▍";
  margin-left: 2px;
  color: var(--amber);
  animation: caret 1s steps(1, end) infinite;
}
@keyframes caret { 50% { opacity: 0 } }
@media (prefers-reduced-motion: reduce) {
  .msg .body.streaming::after { animation: none; }
}
.msg .body.thinking { color: var(--ink-2); font-style: italic; }

/* ── 員工問問題（ask_user_question）───────────────────────────────────────────
   Modelled on DSH's own question card: a checkbox marks multi-select, a dot marks
   single-select, options carry an optional description, and a free-text row is
   always available. Rendered in this product's warm palette rather than copied
   wholesale, because it has to sit inside our thread. */
/* The employee's side is the default; `me` is the exception, and the question
   card is a `them` row too — so the rule is stated rather than implied. */
.msg.them { margin-right: auto; }
.msg .body.question-card { padding: 14px 16px 12px; max-width: 620px; }
.msg .body.question-card.failed { border-style: dashed; color: var(--ink-2); }
/* Answered: the card stays as a record, recessed so it stops competing with the
   conversation that continued after it. */
.msg .body.question-card.settled { background: var(--panel); box-shadow: none; }
.q-head { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.q-eyebrow { color: var(--amber); font-size: 12px; font-weight: 650; letter-spacing: .02em; }
.q-progress { color: var(--ink-2); font-size: 12px; }
.q-summary { margin: 0; font-weight: 600; }
.q-block + .q-block { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--line); }
.q-header { color: var(--ink-2); font-size: 12px; margin-bottom: 3px; }
.q-title { margin: 0 0 8px; font-weight: 600; }
.q-options { display: flex; flex-direction: column; gap: 2px; }
.q-option {
  display: flex; align-items: flex-start; gap: 9px; width: 100%; text-align: left;
  background: none; border: 1px solid transparent; border-radius: var(--radius-sm);
  padding: 8px 10px; cursor: pointer; font: inherit; color: inherit;
  transition: background-color .12s, border-color .12s;
}
.q-option:hover { background: var(--panel); }
.q-option.selected { background: var(--amber-soft); border-color: #f0dcc0; }
.q-check, .q-radio {
  flex: none; width: 18px; height: 18px; margin-top: 2px; display: grid; place-items: center;
  border: 1.5px solid var(--line); background: var(--panel-2); font-size: 11px; line-height: 1;
  color: var(--amber);
}
.q-check { border-radius: 5px; }
.q-radio { border-radius: 999px; }
.q-option.selected .q-check, .q-option.selected .q-radio { border-color: var(--amber); }
.q-copy { min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.q-label { font-weight: 550; }
.q-badge {
  background: var(--amber-soft); color: var(--amber); border-radius: 6px;
  padding: 0 5px; font-size: 11px; font-weight: 600; vertical-align: 1px;
}
.q-desc { color: var(--ink-2); font-size: 13px; line-height: 1.45; }
.q-custom {
  display: flex; align-items: flex-start; gap: 9px; margin-top: 4px;
  border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 8px 10px;
  color: var(--ink-2);
}
.q-custom:focus-within, .q-custom.has-text { border-color: var(--amber); background: var(--panel-2); }
.q-pen { flex: none; width: 18px; text-align: center; margin-top: 2px; }
.q-custom textarea {
  flex: 1; border: 0; outline: none; background: none; resize: none; font: inherit;
  color: var(--ink); padding: 0; min-height: 22px; max-height: 140px;
}
.q-footer { display: flex; align-items: center; gap: 12px; margin-top: 12px; }
.q-hint { flex: 1; color: var(--ink-2); font-size: 12px; }
.q-footer .primary { padding: 8px 16px; }

/* Task items in a reply or a document: a real box, not literal brackets. */
.msg .body li.task-item { list-style: none; margin-left: -18px; }
.msg .body .task {
  display: inline-block; width: 13px; height: 13px; margin-right: 7px; vertical-align: -1px;
  border: 1.5px solid var(--line); border-radius: 4px; background: var(--panel-2); position: relative;
}
.msg .body .task.done { border-color: var(--green); background: var(--green); }
.msg .body .task.done::after {
  content: ""; position: absolute; left: 3.5px; top: 0.5px; width: 3px; height: 7px;
  border: solid #fff; border-width: 0 1.5px 1.5px 0; transform: rotate(45deg);
}

/* A file the employee named in its reply: opens the workspace preview in place. */
.msg .body a.file-link {
  color: var(--green);
  border-bottom: 1px dashed currentColor;
  text-decoration: none;
  cursor: pointer;
}

.composer { border-top: 1px solid var(--line); padding: 16px 26px 20px; background: var(--panel-2); }
.composer .row { display: flex; gap: 12px; align-items: flex-end; }
.composer textarea {
  flex: 1;
  min-height: 54px;
  max-height: 190px;
  resize: none;
  padding: 13px 15px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
}
.composer textarea:focus { outline: 2px solid var(--amber-soft); border-color: var(--amber); }
.composer .hint { margin-top: 8px; font-size: 12px; color: var(--ink-2); }

/* ── workspace side panel ──────────────────────────────────────────────────── */

.side {
  background: var(--panel);
  border-left: 1px solid var(--line);
  padding: 20px 18px;
  overflow-y: auto;
  min-height: 0;
}
.side h3 { margin: 0 0 12px; font-size: 13px; text-transform: uppercase; letter-spacing: .09em; color: var(--ink-2); }
.side dl { margin: 0 0 22px; display: grid; grid-template-columns: 1fr auto; gap: 8px 12px; }
.side dt { color: var(--ink-2); font-size: 13px; }
.side dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
.side .workcard {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 11px 13px;
  margin-bottom: 10px;
  font-size: 13px;
}
.side .bar { height: 6px; border-radius: 999px; background: var(--line); overflow: hidden; margin-top: 8px; }
.side .bar > i { display: block; height: 100%; background: var(--amber); }

/* ── workspace files ───────────────────────────────────────────────────────── */

.dropzone.dragging { outline: 2px dashed var(--amber); outline-offset: 4px; border-radius: var(--radius-sm); }

.files { margin-bottom: 12px; }
.file {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 9px;
  border-radius: var(--radius-sm);
  background: var(--panel-2);
  border: 1px solid var(--line);
  margin-bottom: 6px;
  font-size: 13px;
}
.file:hover { border-color: #ddcfb8; }
.file .icon { flex: none; width: 18px; text-align: center; }
.file .name {
  flex: 1; min-width: 0;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  background: none; border: 0; padding: 0; text-align: left; color: inherit; font: inherit;
  cursor: pointer;
}
.file .name:hover { color: var(--amber); text-decoration: underline; }
.file .size { color: var(--ink-2); font-size: 11px; font-variant-numeric: tabular-nums; flex: none; }
.file .acts { display: none; gap: 2px; flex: none; }
.file:hover .acts { display: flex; }
.file .acts button {
  border: 0; background: transparent; color: var(--ink-2);
  padding: 2px 5px; border-radius: 6px; font-size: 13px; line-height: 1;
}
.file .acts button:hover { background: var(--panel); color: var(--ink); }
.file .acts button.danger:hover { color: var(--red); }
.files .empty-file { color: var(--ink-2); font-size: 13px; padding: 6px 2px 12px; }
/* A folder the customer can open: the chevron is in the icon slot, and the row
   is indented by depth (set inline), so the tree reads as a tree. */
.files .file.is-dir { cursor: default; }
.files .file.is-dir .icon { color: var(--amber); font-size: 11px; }
.files .file.is-dir .name { font-weight: 600; }
.files .file-loading { color: var(--ink-2); font-size: 12px; padding: 3px 2px 5px; }
.files .files-hint {
  display: flex; align-items: center; gap: 8px; margin-top: 8px; padding-top: 8px;
  border-top: 1px dashed var(--line); color: var(--ink-2); font-size: 12px;
}
.files .files-hint button { padding: 3px 9px; font-size: 12px; }

.overlay {
  position: fixed; inset: 0; z-index: 40;
  background: rgba(43, 39, 35, .45);
  display: grid; place-items: center; padding: 28px;
}
/* A Markdown deliverable opens as a finished document in a sandboxed frame, so
   the preview and the downloadable file are the same artefact. */
.preview .doc-frame { flex: 1; width: 100%; min-height: 60vh; border: 1px solid var(--line); border-radius: var(--radius-sm); background: #fbfbfd; }
.preview header #preview-download { white-space: nowrap; }
.preview { max-width: min(880px, 100%); max-height: 100%; display: flex; flex-direction: column; overflow: hidden; }
.preview header { display: flex; align-items: center; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.preview header span { flex: 1; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
/* An icon-only button carries its meaning in the accessible name instead of the
   glyph, so the hit area is square and the × is optically centred rather than
   sitting on a text baseline. */
.preview header .icon-button {
  flex: none; width: 30px; height: 30px; padding: 0; display: grid; place-items: center;
  font-size: 19px; line-height: 1; color: var(--ink-2); border-radius: 999px;
}
.preview header .icon-button:hover { background: var(--panel); color: var(--ink); }
.preview #preview-body { overflow: auto; padding: 18px; }
.preview img { max-width: 100%; height: auto; border-radius: var(--radius-sm); }
.preview pre { margin: 0; white-space: pre-wrap; word-break: break-word; font-size: 13px; }

@media (max-width: 1080px) {
  .shell { grid-template-columns: 232px minmax(0, 1fr); }
  .side { display: none; }
}
@media (max-width: 720px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .rail { display: none; }
}
