:root {
  font-family: "Segoe UI", "Microsoft JhengHei", "PingFang TC", "Noto Sans TC", sans-serif;
  color: #292b32;
  background: #f5f4f0;
  font-synthesis: none;
  --ink: #292b32;
  --muted: #626674;
  --line: #e8e7e1;
  --paper: #fffefa;
  --accent: #4542a2;
  --accent-strong: #373484;
  --danger: #a03739;
}

*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; background: #f5f4f0; }
button, select, textarea, input { font: inherit; color: inherit; }
button, select { cursor: pointer; }
button:disabled, select:disabled { cursor: default; opacity: .55; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
svg { display: block; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

input, select, textarea {
  border: 1px solid #dcdad3;
  border-radius: 8px;
  background: var(--paper);
  padding: 7px 9px;
  font-size: 14px;
  min-width: 0;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 36px;
  padding: 7px 13px;
  border: 1px solid transparent;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 650;
  white-space: nowrap;
}
.button.small { min-height: 30px; padding: 4px 10px; font-size: 12px; }
.button-outline { background: var(--paper); border-color: #dfddd5; }
.button-outline:not(:disabled):hover { background: #efede7; }
.button-send { color: #fff; background: var(--accent); }
.button-send:not(:disabled):hover { background: var(--accent-strong); }
.button-stop, .button-danger { color: var(--danger); background: #fff2f2; border-color: #ead2d3; }
.button-stop:not(:disabled):hover, .button-danger:not(:disabled):hover { background: #fbe5e6; }
.icon-button { display: grid; place-items: center; width: 30px; height: 30px; border: 0; border-radius: 8px; background: transparent; color: #5c5c6b; font-size: 16px; }
.icon-button:not(:disabled):hover { background: #efede7; }

.brand-mark { display: grid; place-items: center; width: 40px; height: 40px; border-radius: 13px; background: #2d2b44; color: #fffefa; flex: none; }
.brand-mark svg { width: 30px; height: 30px; }

/* Login */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 20px 16px; }
.login-card { width: min(100%, 380px); padding: 28px; background: var(--paper); border: 1px solid var(--line); border-radius: 19px; }
.login-card h1 { margin: 14px 0 4px; font-size: 24px; }
.login-card > p { margin: 0 0 18px; color: var(--muted); font-size: 14px; line-height: 1.6; }
.login-card form { display: grid; gap: 6px; }
.login-card label { font-size: 12px; color: var(--muted); font-weight: 650; margin-top: 6px; }
.login-card .button { margin-top: 12px; }
.form-error { margin: 6px 0 0; color: var(--danger); font-size: 13px; line-height: 1.5; white-space: pre-line; }

/* App frame */
.app {
  max-width: 1600px;
  min-height: 100dvh;
  margin: 0 auto;
  padding: 0 clamp(16px, 3vw, 48px) 24px;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}
.topbar { min-height: 72px; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.brand { display: flex; align-items: center; gap: 10px; }
.brand strong { font-size: 19px; font-weight: 750; }
.topbar-actions { position: relative; display: flex; align-items: center; gap: 10px; }
.computer-pill {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 6px 11px; border: 1px solid var(--line); border-radius: 20px;
  background: var(--paper); font-size: 12px; white-space: nowrap;
}
.computer-pill em { font-style: normal; }
.computer-pill > span { width: 8px; height: 8px; border-radius: 50%; background: #9a97a6; }
.computer-pill[data-state="online"] > span { background: #43806a; box-shadow: 0 0 0 3px #e3eee6; }
.computer-pill[data-state="warning"] > span { background: #c27d2c; box-shadow: 0 0 0 3px #f6ead8; }
.computer-pill[data-state="offline"] { color: var(--danger); }
.computer-pill[data-state="offline"] > span { background: #bc5557; }
.menu {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 5;
  display: grid; min-width: 150px; padding: 5px;
  background: var(--paper); border: 1px solid var(--line); border-radius: 11px;
  box-shadow: 0 10px 30px rgb(40 38 60 / .12);
}
.menu button { text-align: left; padding: 8px 10px; border: 0; border-radius: 7px; background: transparent; font-size: 13px; }
.menu button:hover { background: #f1efe9; }

.workspace { display: grid; grid-template-columns: minmax(200px, 250px) minmax(0, 1fr); gap: clamp(12px, 2vw, 22px); min-height: 0; }
.sidebar, .conversation { background: var(--paper); border: 1px solid var(--line); border-radius: 19px; min-width: 0; }
.sidebar { padding: 18px 14px; align-self: start; }
.section-heading { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 0 4px 10px; }
.section-heading h2 { margin: 0; font-size: 15px; }
.projects { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.project-link {
  width: 100%; display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 9px 10px; border: 0; border-radius: 9px; background: transparent; text-align: left; font-size: 14px;
}
.project-link:hover { background: #f3f1ec; }
.project-link[aria-current="true"] { background: #eceafb; color: var(--accent-strong); font-weight: 650; }
.project-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.project-active { flex: none; font-size: 11px; color: var(--accent); background: #efedfa; padding: 1px 7px; border-radius: 10px; }
.empty { margin: 8px 4px; color: var(--muted); font-size: 13px; line-height: 1.6; }

/* Project */
.conversation { display: grid; height: max(620px, calc(100dvh - 96px)); overflow: hidden; }
.placeholder { display: grid; place-content: center; text-align: center; padding: 30px; color: var(--muted); }
.placeholder h2 { margin: 0 0 8px; color: var(--ink); font-size: 22px; }
.placeholder p { margin: 0; max-width: 380px; line-height: 1.7; font-size: 14px; }
.project-view { display: grid; grid-template-rows: auto auto minmax(0, 1fr); min-height: 0; }
.conversation-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px clamp(14px, 3vw, 28px) 8px; }
.title-row { display: flex; align-items: center; gap: 4px; min-width: 0; }
.title-row h1 { margin: 0; font-size: 18px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.run-state { display: inline-flex; align-items: center; gap: 7px; padding: 5px 10px; border-radius: 20px; background: #f2f1ee; color: #5c596c; font-size: 12px; white-space: nowrap; }
.run-state > span:first-child { width: 7px; height: 7px; border-radius: 50%; background: #8d8a9c; }
.run-state[data-state="working"] { background: #efedfa; color: var(--accent-strong); }
.run-state[data-state="working"] > span:first-child { background: #7771c7; animation: pulse 1.4s ease-in-out infinite; }
.run-state[data-state="ready"] { background: #e8f1e8; color: #35614e; }
.run-state[data-state="ready"] > span:first-child { background: #42876a; }
.run-state[data-state="error"] { background: #f9ebea; color: var(--danger); }
.run-state[data-state="error"] > span:first-child { background: #bc5557; }
@keyframes pulse { 50% { opacity: .35; } }
@media (prefers-reduced-motion: reduce) { .run-state > span:first-child { animation: none !important; } }

.tabs { display: flex; gap: 2px; padding: 0 clamp(10px, 3vw, 24px); border-bottom: 1px solid var(--line); }
.tabs button { padding: 9px 12px; border: 0; border-bottom: 2px solid transparent; background: transparent; color: var(--muted); font-size: 14px; }
.tabs button[aria-selected="true"] { color: var(--accent-strong); border-bottom-color: var(--accent); font-weight: 650; }
.tab { min-height: 0; }
.chat-tab { display: grid; grid-template-rows: minmax(0, 1fr) auto; }
.panel { overflow: auto; padding: 18px clamp(14px, 3vw, 28px); display: grid; align-content: start; gap: 10px; max-width: 760px; }
.panel-intro, .hint { margin: 0; color: var(--muted); font-size: 13px; line-height: 1.7; }
.panel label { font-size: 12px; color: var(--muted); font-weight: 650; margin-top: 6px; }
.panel-actions { display: flex; justify-content: flex-end; align-items: center; gap: 10px; }
.saved { color: #2e6a50; font-size: 13px; }
.danger-zone { margin-top: 26px; padding-top: 16px; border-top: 1px solid var(--line); display: grid; gap: 6px; justify-items: start; }
.notes { min-height: 360px; resize: vertical; line-height: 1.7; white-space: pre-wrap; }

/* Team editor */
.presets { display: flex; flex-wrap: wrap; gap: 6px; }
.presets button { padding: 5px 10px; border: 1px solid #e1dce3; border-radius: 20px; background: var(--paper); font-size: 12px; color: #5b5368; }
.presets button:hover:not(:disabled) { background: #f3f1fb; border-color: #c9c3e8; }
.team { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.member { padding: 10px; border: 1px solid var(--line); border-radius: 12px; background: #fdfcf8; display: grid; gap: 8px; }
.member[data-role="manager"] { border-color: #d8d4f2; background: #f9f8fe; }
.member-top { display: flex; align-items: center; gap: 8px; }
.member-name { flex: 1; font-weight: 650; }
.member-controls { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); gap: 8px; }

/* Avatars and badges */
.avatar { display: grid; place-items: center; width: 34px; height: 34px; flex: none; border-radius: 10px; font-weight: 750; font-size: 12px; user-select: none; }
.avatar.codex { color: #146b54; background: #def2ea; }
.avatar.claude { color: #985035; background: #f8e6d8; font-size: 18px; }
.avatar.grok { color: #24252b; background: #e7e7ea; }
.avatar.other { color: #4c4a6b; background: #ebeaf3; }
.avatar.user { color: #3e6051; background: #e5eee6; }
.avatar.system { color: #6a6458; background: #ecebe4; }
.role-badge { font-size: 11px; padding: 1px 7px; border-radius: 10px; font-weight: 650; }
.role-manager { color: #3c3a92; background: #e9e8fa; }
.role-worker { color: #2e6a50; background: #e2efe6; }
.role-reviewer { color: #8a5419; background: #f8ebd9; }
.via { color: var(--muted); font-size: 11px; }

/* Transcript */
.chat-scroll { overflow: auto; overscroll-behavior: contain; padding: 18px clamp(14px, 4vw, 44px); scrollbar-width: thin; }
.intro { text-align: center; color: var(--muted); padding: 40px 10px; }
.intro h2 { margin: 0 0 8px; color: var(--ink); font-size: 22px; }
.intro p { margin: 0 auto; max-width: 420px; line-height: 1.7; font-size: 14px; }
.transcript { display: grid; gap: 22px; width: min(100%, 880px); margin: 0 auto; }
.older { text-align: center; color: var(--muted); font-size: 12px; margin: 0; }
.job { display: grid; gap: 11px; }
.job-status { margin: 0 0 0 43px; color: var(--muted); font-size: 12px; }
.phase-marker { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 11px; }
.phase-marker::before, .phase-marker::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.message { display: flex; align-items: flex-start; gap: 9px; min-width: 0; }
.message-body { min-width: 0; max-width: 100%; padding: 9px 12px; border: 1px solid var(--line); border-radius: 4px 12px 12px 12px; background: #faf9f6; }
.message-user { flex-direction: row-reverse; }
.message-user .message-body { background: #f0f5ef; border-color: #e0e9e0; border-radius: 12px 4px 12px 12px; }
.message-manager .message-body { background: #f7f6fd; border-color: #e6e3f6; }
.message-success .message-body { background: #eef6ef; border-color: #d5e6d9; }
.message-success .avatar.system { color: #2e6a50; background: #dcece0; }
.message-error .message-body { background: #fff3f2; border-color: #f1d9d8; }
.message-error .avatar.system { color: var(--danger); background: #fbe9e7; }
.message-header { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; margin-bottom: 4px; font-size: 12px; }
.message-text { font-size: 14px; line-height: 1.7; white-space: pre-wrap; overflow-wrap: anywhere; color: #32323d; }
.message-detail { margin: 3px 0 0; color: var(--muted); font-size: 12px; line-height: 1.5; overflow-wrap: anywhere; }
.message[data-state="working"] .message-detail::before { content: ""; display: inline-block; width: 6px; height: 6px; margin: 0 6px 1px 0; border-radius: 50%; background: #8e84ba; }
.message[data-state="error"] .message-detail { color: var(--danger); }
.assignment { margin: 2px 0 7px; padding: 6px 9px; border-left: 3px solid #c9c4ec; background: #f6f5fc; border-radius: 0 7px 7px 0; }
.assignment span { font-size: 11px; color: var(--accent); font-weight: 650; }
.assignment p { margin: 2px 0 0; font-size: 13px; line-height: 1.6; white-space: pre-wrap; }

/* Composer */
.composer-area { padding: 12px clamp(14px, 4vw, 44px) 16px; border-top: 1px solid var(--line); }
.composer, .composer-notice { width: min(100%, 880px); margin: 0 auto; }
.composer-notice { margin-bottom: 8px; padding: 6px 9px; border-radius: 7px; background: #fbf3e5; color: #785126; font-size: 12px; line-height: 1.5; }
.composer { padding: 8px 10px; border: 1px solid #dcd9e2; border-radius: 13px; background: #fdfcfc; }
.composer:focus-within { border-color: #a9a0d7; }
.composer textarea { display: block; width: 100%; min-height: 56px; max-height: 200px; resize: vertical; border: 0; background: transparent; padding: 4px 5px; line-height: 1.55; }
.composer textarea:focus-visible { outline: none; }
.composer-actions { display: flex; align-items: center; justify-content: flex-end; gap: 8px; margin-top: 4px; }
.composer-actions > span { margin-right: auto; color: var(--muted); font-size: 11px; padding-left: 5px; }

/* Dialogs */
.key-box { margin: 12px 0; padding: 10px 12px; border: 1px solid #e3e0f4; border-radius: 10px; background: #f8f7fd; display: grid; gap: 6px; }
.key-box strong { font-size: 13px; }
.key-row { display: flex; align-items: center; gap: 8px; }
.key-row code { flex: 1; min-width: 0; overflow-wrap: anywhere; font-size: 12px; background: #fff; padding: 5px 7px; border-radius: 6px; border: 1px solid var(--line); }

.dialog { width: min(92vw, 420px); padding: 22px; border: 1px solid var(--line); border-radius: 16px; background: var(--paper); color: var(--ink); }
.dialog.wide { width: min(94vw, 600px); }
.dialog::backdrop { background: rgb(30 28 40 / .35); }
.dialog h2 { margin: 0 0 12px; font-size: 18px; }
.dialog h3 { margin: 18px 0 8px; font-size: 14px; }
.dialog > input { width: 100%; }
.dialog label { display: block; margin: 10px 0 5px; font-size: 12px; color: var(--muted); font-weight: 650; }
.dialog label + input { width: 100%; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.account-list, .users { list-style: none; margin: 10px 0; padding: 0; display: grid; gap: 6px; }
.account-list li { display: flex; align-items: center; gap: 10px; padding: 8px; border: 1px solid var(--line); border-radius: 10px; font-size: 13px; }
.account-list li div { display: grid; }
.account-list li span:not(.avatar) { color: var(--muted); font-size: 12px; }
.account-list li.missing { border-color: #f0dcc0; background: #fffaf2; }
.users li { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 8px 10px; border: 1px solid var(--line); border-radius: 10px; font-size: 14px; }
.user-actions { margin-left: auto; display: flex; gap: 6px; }
.user-form { display: grid; grid-template-columns: 1fr 1fr auto auto; gap: 8px; align-items: center; }
.check { display: flex !important; align-items: center; gap: 5px; margin: 0 !important; white-space: nowrap; }

@media (max-width: 760px) {
  .app { display: block; padding: 0 12px 12px; }
  .topbar { min-height: 60px; }
  .brand strong { display: none; }
  .workspace { grid-template-columns: 1fr; }
  .sidebar { padding: 10px; }
  .section-heading { margin-bottom: 6px; }
  .projects { display: flex; overflow-x: auto; gap: 6px; padding-bottom: 2px; }
  .projects li { flex: none; }
  .project-link { border: 1px solid var(--line); padding: 6px 10px; }
  .conversation { height: calc(100dvh - 190px); min-height: 480px; }
  .user-form { grid-template-columns: 1fr 1fr; }
  .member-controls { grid-template-columns: 1fr 1fr; }
}
