/* Follows the approved screens: navy side menu, white top bar, white bordered cards on a
   pale blue-grey page, green chips, blue for the open tab and the selected member. */
:root {
  --side: #13283f;
  --side-active: #1f4560;
  --side-text: #c3ceda;
  --side-muted: #9aabbd;
  --page: #f1f5f9;
  --surface: #ffffff;
  --line: #e1e7ee;
  --ink: #17212b;
  --text: #25303b;
  --muted: #6f7c8a;
  --green: #0f7f68;
  --green-soft: #e1f3ed;
  --blue: #1b62c4;
  --blue-soft: #e9f1fc;
  --amber: #b7621b;
  --amber-soft: #fcefdc;
  --red: #c23b3b;
  --grey-soft: #eef2f6;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: 14px/1.55 "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", system-ui, sans-serif;
  color: var(--text);
  background: var(--page);
}
a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 20px; font-weight: 700; color: var(--ink); margin: 0; }
h2 { font-size: 22px; font-weight: 700; color: var(--ink); margin: 0; }
h3 { font-size: 17px; font-weight: 700; color: var(--ink); margin: 0; }
p { margin: 6px 0; }

/* Frame */
.shell { display: flex; min-height: 100vh; }
.side {
  flex: 0 0 172px;
  display: flex;
  flex-direction: column;
  padding: 22px 12px 14px;
  background: var(--side);
  color: var(--side-text);
}
.brand { padding: 0 10px 26px; }
.brand strong { display: block; font-size: 19px; font-weight: 700; color: #fff; letter-spacing: 0.02em; }
.brand span { font-size: 13px; color: var(--side-muted); }
.side nav { display: flex; flex-direction: column; gap: 14px; }
.side nav a {
  padding: 8px 14px;
  border-radius: 6px;
  font-size: 16px;
  color: var(--side-text);
}
.side nav a:hover { background: rgb(255 255 255 / 0.06); text-decoration: none; }
.side nav a.active { background: var(--side-active); color: #fff; font-weight: 700; }
.side-foot { margin: auto 0 0; padding: 24px 8px 0; font-size: 12.5px; line-height: 1.9; color: var(--side-text); }
.body { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  min-height: 62px;
  padding: 10px 26px;
  background: var(--surface);
}
.topbar .chip { margin-left: auto; }
.user { display: flex; align-items: center; gap: 10px; font-size: 15px; color: var(--ink); }
main { flex: 1; padding: 14px 24px 36px; }
.crumbs { margin: 0 0 12px; color: var(--muted); font-size: 14px; }
.crumbs a { color: var(--muted); }
.plain { max-width: 440px; margin: 0 auto; padding: 36px 16px; }
.plain .brand { padding: 0 0 18px; }
.plain .brand strong { color: var(--ink); font-size: 22px; }
.plain .brand span { color: var(--muted); }
.context { margin: 0 0 10px; color: var(--muted); font-size: 12.5px; }
.context .local { color: var(--red); font-weight: 700; margin-left: 6px; }

/* Cards and layout pieces */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 16px 18px;
}
.stack { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.split { display: grid; grid-template-columns: 300px minmax(0, 1fr); gap: 16px; align-items: start; }
.cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 12px; }
.head { display: flex; align-items: baseline; gap: 14px; flex-wrap: wrap; }
.head .grow { flex: 1; }
.section-head { display: flex; align-items: baseline; gap: 16px; flex-wrap: wrap; margin: 6px 2px 0; }
.section-head .right { margin-left: auto; }
.table-card { padding: 4px 16px 6px; overflow-x: auto; }
.note { color: var(--muted); font-size: 13px; }
.info { background: var(--blue-soft); border-radius: 6px; padding: 12px 18px; }
.info strong { display: block; color: var(--blue); font-size: 15px; }

/* Chips */
.chip, select.chip {
  display: inline-flex;
  align-items: center;
  padding: 2px 10px;
  border: 0;
  border-radius: 4px;
  background: var(--green-soft);
  color: var(--green);
  font: inherit;
  font-size: 13.5px;
  font-weight: 700;
  white-space: nowrap;
}
select.chip { padding: 3px 6px; cursor: pointer; }
.chip.blue { background: var(--blue-soft); color: var(--blue); }
.chip.amber { background: var(--amber-soft); color: var(--amber); }
.chip.grey { background: var(--grey-soft); color: var(--muted); }
.ok { color: var(--green); }
.warn { color: var(--amber); }
.bad { color: var(--red); }
.quiet { color: var(--muted); }

/* Member list */
.list-card { padding: 14px 10px 10px; }
.list-card .head { padding: 0 8px 8px; align-items: center; }
.list-card .head h3 { flex: 1; }
.search { display: block; width: calc(100% - 16px); margin: 0 8px 10px; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; padding: 0 8px 12px; }
.list-labels, .member-row {
  display: grid;
  grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr);
  gap: 0 8px;
}
.list-labels { padding: 0 8px 4px; color: var(--muted); font-weight: 700; font-size: 13.5px; }
.member-row {
  width: 100%;
  padding: 7px 10px;
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  background: transparent;
  text-align: left;
  font-weight: 400;
  cursor: pointer;
}
.member-row:hover:not(:disabled) { background: #f6f9fc; }
.member-row.active { background: var(--blue-soft); border-radius: 4px; }
.member-row strong { display: block; font-size: 15.5px; color: var(--ink); }
.member-row span { display: block; font-size: 13px; }
.member-row .tier { color: var(--muted); }
.list-foot { display: flex; justify-content: space-between; padding: 12px 10px 2px; color: var(--muted); }

/* Profile */
.profile-head { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 4px 14px; align-items: center; }
.avatar {
  grid-row: 1 / span 2;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--blue-soft);
  color: var(--blue);
  font-size: 20px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}
.who-line { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.who-line strong { font-size: 22px; color: var(--ink); }
.who-line .id { font-size: 16px; color: var(--muted); }
.profile-head .sub { grid-column: 2; color: var(--muted); font-size: 14px; }
.profile-head .source { grid-column: 1 / -1; display: flex; gap: 12px; margin-top: 10px; align-items: baseline; }
.profile-head .source strong { color: var(--green); font-size: 15px; }
.profile-head .source span { margin-left: auto; color: var(--muted); font-size: 13px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: 6px; padding: 12px 14px; }
.stat span { display: block; color: var(--muted); font-size: 13.5px; }
.stat strong { display: block; font-size: 22px; color: var(--ink); margin-top: 6px; }
.stat em { display: block; font-style: normal; font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.facts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 24px; margin-top: 10px; }
.facts div span { display: block; color: var(--muted); font-size: 12.5px; }
.facts div strong { font-weight: 400; font-size: 15px; color: var(--ink); overflow-wrap: anywhere; }

/* Tabs */
.tabs { display: flex; gap: 8px 40px; flex-wrap: wrap; padding: 0 18px; }
.tabs button {
  border: 0;
  border-bottom: 3px solid transparent;
  border-radius: 0;
  background: transparent;
  color: var(--muted);
  font-size: 16px;
  font-weight: 400;
  padding: 12px 2px 9px;
}
.tabs button:hover:not(:disabled) { background: transparent; color: var(--ink); }
.tabs button.active { color: var(--blue); font-weight: 700; border-bottom-color: var(--blue); }

/* Filter bar */
.filterbar { display: flex; align-items: center; gap: 12px 18px; flex-wrap: wrap; padding: 10px 16px; }
.filterbar .grow { flex: 1; }

/* Forms */
.field { display: flex; flex-direction: column; gap: 4px; margin: 10px 0; }
.field span { font-size: 13px; color: var(--muted); }
input, select, textarea {
  font: inherit;
  color: var(--text);
  background: #f3f5f8;
  padding: 7px 10px;
  border: 1px solid transparent;
  border-radius: 4px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--blue); outline-offset: 0; }
input[type="checkbox"] { width: 15px; height: 15px; padding: 0; accent-color: var(--green); }
.field input, .field select, .field textarea { width: 100%; }
button {
  font: inherit;
  font-weight: 700;
  padding: 6px 14px;
  border-radius: 4px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
}
button:hover:not(:disabled) { background: #f5f8fb; }
button[type="submit"] { background: var(--side); border-color: var(--side); color: #fff; }
button[type="submit"]:hover:not(:disabled) { background: var(--side-active); }
button.danger { color: var(--red); }
button:disabled, textarea:disabled, input:disabled { opacity: 0.55; cursor: not-allowed; }
button:focus-visible, a:focus-visible, tr:focus-visible { outline: 2px solid var(--blue); outline-offset: 1px; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin: 10px 0 0; }
.toolbar .field { margin: 0; }
.check {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 10px;
  border-radius: 4px;
  background: var(--grey-soft);
  color: var(--muted);
  font-size: 13.5px;
  font-weight: 700;
  cursor: pointer;
}
.check:has(input:checked) { background: var(--green-soft); color: var(--green); }
.limits { max-width: 360px; }
.broadcast textarea { width: 100%; max-width: 560px; min-height: 96px; resize: vertical; }

/* Tables */
table { border-collapse: collapse; width: 100%; }
th {
  text-align: left;
  font-size: 13.5px;
  font-weight: 700;
  color: var(--muted);
  padding: 9px 8px;
  white-space: nowrap;
}
td { padding: 10px 8px; border-top: 1px solid var(--line); vertical-align: top; font-size: 14.5px; color: var(--ink); }
tbody tr:first-child td { border-top: 0; }
thead + tbody tr:first-child td { border-top: 1px solid var(--line); }
tr.total td { font-weight: 700; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: #f6f9fc; }
dl { display: grid; grid-template-columns: max-content 1fr; gap: 4px 16px; margin: 0; }
dt { color: var(--muted); }
dd { margin: 0; min-width: 0; color: var(--ink); }
.wrap, dd { overflow-wrap: anywhere; white-space: pre-wrap; }

/* Task progress */
.task { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.2fr) auto auto; gap: 2px 14px; align-items: baseline; margin-top: 10px; }
.task strong { color: var(--ink); }
.bar { grid-column: 2 / -1; height: 5px; border-radius: 3px; background: var(--grey-soft); overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--green); border-radius: 3px; }
.w0 { width: 0; } .w10 { width: 10%; } .w20 { width: 20%; } .w30 { width: 30%; } .w40 { width: 40%; }
.w50 { width: 50%; } .w60 { width: 60%; } .w70 { width: 70%; } .w80 { width: 80%; } .w90 { width: 90%; }
.w100 { width: 100%; }

/* Messages to the reader */
.notice { margin: 6px 0; }
.notice:empty { display: none; }
.notice.error { color: var(--red); }
.meta { color: var(--muted); font-size: 13px; }
.empty { color: var(--muted); padding: 12px 0; }
.secret { border-radius: 6px; padding: 8px 12px; background: var(--green-soft); }

/* Agent workspace */
.workspace { display: grid; grid-template-columns: 280px minmax(0, 1fr) 300px; gap: 12px; align-items: start; }
.pane { background: var(--surface); border: 1px solid var(--line); border-radius: 6px; padding: 14px 16px; min-width: 0; }
.pane ul, .events { list-style: none; margin: 0; padding: 0; }
.pane.list ul { display: flex; flex-direction: column; gap: 6px; margin-top: 10px; }
.row { width: 100%; display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 0 8px; align-items: center; text-align: left; padding: 7px 10px; font-weight: 400; }
.row-title { font-weight: 700; color: var(--ink); }
.row-sub { grid-column: 1; font-size: 12.5px; color: var(--muted); }
.row .badge { grid-column: 2; grid-row: 1 / span 2; }
.row.active { background: var(--blue-soft); border-color: var(--blue-soft); }
.badge { font-size: 12.5px; font-weight: 700; padding: 1px 8px; border-radius: 4px; background: var(--grey-soft); color: var(--muted); white-space: nowrap; }
.events { display: flex; flex-direction: column; gap: 8px; max-height: 60vh; overflow-y: auto; margin-top: 10px; }
.event { padding: 8px 12px; border: 1px solid var(--line); border-radius: 6px; }
.event .meta { display: block; }
.event p { margin: 0; color: var(--ink); }
.event.ai_reply, .event.agent_reply { background: var(--green-soft); border-color: var(--green-soft); }
.event.system, .event.transition { border-style: dashed; color: var(--muted); }
.composer { display: flex; gap: 8px; margin-top: 12px; align-items: flex-end; }
.composer textarea { flex: 1; min-height: 40px; resize: vertical; }

/* Dialog */
dialog { border: 1px solid var(--line); border-radius: 6px; padding: 18px 20px; width: calc(100% - 32px); max-width: 360px; color: var(--text); }
dialog::backdrop { background: rgb(19 40 63 / 0.5); }
dialog form > button { margin: 8px 8px 0 0; }

@media (max-width: 980px) {
  .shell { flex-direction: column; }
  .side { flex: none; flex-direction: row; align-items: center; flex-wrap: wrap; gap: 6px 10px; padding: 10px 12px; }
  .brand { padding: 0 6px 0 4px; }
  .brand span, .side-foot { display: none; }
  .side nav { flex-direction: row; flex-wrap: wrap; gap: 4px; }
  .side nav a { padding: 5px 10px; font-size: 14px; }
  .topbar { min-height: 48px; padding: 8px 14px; }
  main { padding: 12px 12px 28px; }
  .split, .workspace { grid-template-columns: 1fr; }
  .facts { grid-template-columns: 1fr; }
  .tabs { gap: 4px 20px; }
  dl { grid-template-columns: 1fr; }
}

/* Fine points of the approved screens */
.stat strong.bad { color: var(--red); }
.stat strong.warn { color: var(--amber); }
.filterbar button[type="submit"] { background: var(--surface); border-color: var(--line); color: var(--ink); }
.filterbar button[type="submit"]:hover:not(:disabled) { background: #f5f8fb; }
.plain .card { margin-top: 4px; }
.plain .user { justify-content: flex-end; margin-bottom: 8px; font-size: 13.5px; }
.card > h2 { font-size: 19px; margin-bottom: 6px; }
.card > h3 + .facts { margin-top: 12px; }
.pane > h2, .pane > h3 { margin-bottom: 8px; }
.pane h3 { font-size: 15px; margin-top: 14px; }
.pane h3:first-child { margin-top: 0; }
.pane .meta button { margin-left: 8px; }
.plain .context { margin-top: 14px; }

/* The member's own area: the same cards without the staff menu */
.member-shell .topbar { gap: 22px; border-bottom: 1px solid var(--line); }
.member-shell .topbar .brand strong { display: inline; font-size: 18px; color: var(--ink); }
.member-shell .topbar .brand span { margin-left: 8px; color: var(--muted); font-size: 13px; }
.member-shell .topbar nav { display: flex; gap: 6px; flex: 1; }
.member-shell .topbar nav a { padding: 6px 12px; border-radius: 6px; color: var(--muted); font-size: 15px; }
.member-shell .topbar nav a:hover { background: var(--grey-soft); text-decoration: none; }
.member-shell .topbar nav a.active { background: var(--blue-soft); color: var(--blue); font-weight: 700; }
.member-shell main { max-width: 1040px; margin: 0 auto; padding: 18px 20px 36px; }

/* Agent workspace: case list, conversation, member summary */
.workspace { display: grid; grid-template-columns: 300px minmax(0, 1fr) 300px; gap: 16px; align-items: start; }
.workspace .list-foot { align-items: center; gap: 8px; flex-wrap: wrap; border-top: 1px solid var(--line); margin-top: 0; padding-top: 10px; }
.workspace .list-foot + .list-foot { border-top: 0; padding-top: 6px; }
.workspace .filters button.chip { cursor: pointer; }
button.chip { cursor: pointer; }
button.primary { background: var(--side); border-color: var(--side); color: #fff; }
button.primary:hover:not(:disabled) { background: var(--side-active); }
.blank { padding: 48px 24px; text-align: center; }
.blank h3 { margin-bottom: 6px; }
.case-head { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 16px; }
.case-head .who-line { flex: 1; min-width: 240px; }
.case-head .toolbar { margin: 0; }
.thread { display: flex; flex-direction: column; }
.thread .events { display: flex; flex-direction: column; gap: 10px; max-height: 56vh; overflow-y: auto; margin: 0 0 4px; padding: 2px; }
.thread .event { max-width: 76%; padding: 8px 12px; border: 0; border-radius: 10px; background: #f3f5f8; align-self: flex-start; }
.thread .event .meta { display: block; font-size: 12px; }
.thread .event.ai_reply { align-self: flex-end; background: var(--green-soft); }
.thread .event.agent_reply { align-self: flex-end; background: var(--blue-soft); }
.thread .event.system, .thread .event.transition {
  align-self: center;
  max-width: 90%;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
  padding: 2px 8px;
}
.thread .event.system p, .thread .event.transition p { color: var(--muted); }
.thread .composer { border-top: 1px solid var(--line); padding-top: 12px; }
.stats.compact { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin-top: 12px; }
.stats.compact .stat { padding: 8px 10px; }
.stats.compact .stat strong { font-size: 17px; margin-top: 2px; }
.deliveries { list-style: none; margin: 8px 0 0; padding: 0; }
.deliveries li { padding: 8px 0; border-top: 1px solid var(--line); }
.deliveries li:first-child { border-top: 0; }
.deliveries p { margin: 2px 0 0; color: var(--ink); }
@media (max-width: 1100px) {
  .workspace { grid-template-columns: 280px minmax(0, 1fr); }
  .workspace > .stack:last-child { grid-column: 1 / -1; }
}
@media (max-width: 980px) {
  .workspace { grid-template-columns: 1fr; }
  .member-shell .topbar { flex-wrap: wrap; gap: 8px 12px; }
  .member-shell main { padding: 12px; }
  .thread .event { max-width: 92%; }
}
