:root {
  --primary: #00808a;
  --accent: #15a9a0;
  --soft: #ecf4f5;
  --ink: #2d3034;
  --muted: #5c6066;
  --line: #cdd6d9;
  --warning: #a8741a;
}
* {
  box-sizing: border-box;
}
body {
  margin: 0;
  color: var(--ink);
  font:
    16px/1.65 "Microsoft JhengHei",
    system-ui,
    sans-serif;
  background: #f5f8f8;
}
button,
input,
textarea,
select {
  font: inherit;
}
button,
a {
  touch-action: manipulation;
}
button {
  cursor: pointer;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: white;
  color: var(--ink);
  padding: 8px 14px;
}
button:hover {
  border-color: var(--primary);
  color: var(--primary);
}
button:disabled {
  opacity: 0.55;
  cursor: wait;
}
.primary {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}
.primary:hover {
  background: #006a72;
  color: white;
}
a {
  color: var(--primary);
  text-decoration: none;
}
a:hover {
  text-decoration: underline;
}
:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 3px;
}
[hidden] {
  display: none !important;
}
.login {
  display: grid;
  grid-template-columns: 1fr 1fr;
  min-height: 100vh;
  max-width: 1400px;
  margin: auto;
  background: white;
}
.login-intro {
  padding: 12vh 9%;
  background: var(--soft);
  display: flex;
  flex-direction: column;
  justify-content: center;
}
.wordmark {
  color: var(--primary);
  font-weight: 700;
  letter-spacing: 0.12em;
}
.login h1 {
  font-size: clamp(30px, 3.4vw, 48px);
  line-height: 1.5;
  margin: 32px 0 16px;
}
.login p {
  color: var(--muted);
}
.rule {
  width: 64px;
  height: 4px;
  background: var(--primary);
  margin-top: 36px;
}
.login form {
  align-self: center;
  padding: 50px 12%;
  max-width: 640px;
  width: 100%;
}
.login h2 {
  font-size: 25px;
}
.login label {
  display: block;
  margin-top: 20px;
}
.login input {
  display: block;
  width: 100%;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 5px;
  margin-top: 6px;
}
.login button {
  width: 100%;
  margin-top: 28px;
}
.login small {
  display: block;
  color: var(--muted);
  margin-top: 20px;
}
.eyebrow {
  font-size: 13px;
  color: var(--primary);
  font-weight: 700;
}
#login-error {
  color: #a23d36;
}
header {
  height: 76px;
  background: white;
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 0 24px;
  border-bottom: 1px solid var(--line);
}
.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 12px;
  line-height: 1.4;
  white-space: nowrap;
}
.brand strong {
  display: block;
  font-size: 18px;
}
.brand-logo {
  width: 40px;
  height: 40px;
  object-fit: contain;
  flex-shrink: 0;
  display: block;
}
.mark {
  font-size: 16px;
  color: white;
  background: var(--primary);
  padding: 10px 8px;
  border-radius: 6px;
  font-weight: 700;
}
nav {
  align-self: stretch;
  display: flex;
  gap: 8px;
  flex: 1;
}
nav button {
  border: 0;
  border-radius: 0;
  border-bottom: 3px solid transparent;
  padding: 0 14px;
}
nav button.active {
  border-bottom-color: var(--primary);
  color: var(--primary);
  font-weight: 700;
}
#username {
  font-size: 14px;
}
.layout {
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr) 300px;
  height: calc(100vh - 76px);
}
aside {
  padding: 24px 18px;
  background: white;
  overflow: auto;
}
#sidebar {
  border-right: 1px solid var(--line);
}
#sources {
  border-left: 1px solid var(--line);
}
aside h2 {
  font-size: 13px;
  color: var(--muted);
  font-weight: 500;
  margin: 28px 0 12px;
}
aside h2:first-child {
  margin-top: 0;
}
#new-chat {
  width: 100%;
}
#questions button {
  text-align: left;
  width: 100%;
  font-size: 14px;
  padding: 9px 8px;
  margin-bottom: 4px;
  border: 0;
  background: transparent;
}
#questions button:hover {
  background: var(--soft);
}
.text-button {
  border: 0;
  padding: 0;
  font-size: 13px;
  color: var(--primary);
}
main {
  min-width: 0;
  min-height: 0;
}
.view {
  height: 100%;
  display: flex;
  flex-direction: column;
}
.view-heading {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 10px 24px;
  min-height: 48px;
  background: white;
  border-bottom: 1px solid #e2e9eb;
}
.view-heading h1 {
  font-size: 17px;
  font-weight: 600;
  margin: 0;
  line-height: 1.4;
}
.view-heading-left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
.mobile-history-btn {
  display: none;
}
.badge {
  font-size: 12px;
  background: var(--soft);
  color: var(--primary);
  padding: 5px 10px;
  border-radius: 12px;
  white-space: nowrap;
}
#thread {
  flex: 1;
  overflow: auto;
  padding: 28px 30px;
}
#welcome {
  max-width: 600px;
  margin: 12vh auto 0;
}
#welcome h2 {
  font-size: 26px;
}
#welcome p {
  color: var(--muted);
}
.message {
  margin: 0 0 24px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  max-width: 850px;
}
.message.user {
  margin-left: auto;
  background: var(--primary);
  color: white;
  padding: 12px 16px;
  border-radius: 10px 10px 2px 10px;
  width: fit-content;
  max-width: 85%;
}
.message.assistant {
  background: white;
  border: 1px solid var(--line);
  border-radius: 2px 10px 10px 10px;
  padding: 18px;
  white-space: normal;
}
.message-content {
  white-space: normal;
  line-height: 1.6;
}
.message-content p {
  margin: 0.35em 0;
  line-height: 1.6;
}
.message-content p:first-child {
  margin-top: 0;
}
.message-content p:last-child {
  margin-bottom: 0;
}
.message-content ul,
.message-content ol {
  margin: 0.35em 0;
  padding-left: 20px;
}
.message-content li {
  margin: 0.2em 0;
}
.message-content table {
  width: 100%;
  border-collapse: collapse;
  margin: 12px 0;
  font-size: 13.5px;
  border: 1px solid var(--line);
}
.message-content th,
.message-content td {
  border: 1px solid var(--line);
  padding: 8px 12px;
  text-align: left;
}
.message-content th {
  background: #f8fafc;
  font-weight: 600;
  color: #1e293b;
}
.message-content tr:nth-child(even) {
  background: #fbfcfe;
}
.citations {
  display: grid;
  gap: 8px;
  margin-top: 16px;
}
.citation {
  text-align: left;
  background: var(--soft);
  font-size: 14px;
}
.message small {
  color: var(--muted);
}
#composer {
  padding: 12px 24px;
  border-top: 1px solid var(--line);
  background: white;
}
.composer-row {
  display: flex;
  flex-direction: row;
  gap: 10px;
  align-items: stretch;
  width: 100%;
}
#composer textarea {
  flex: 1;
  min-height: 48px;
  height: 48px;
  max-height: 140px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px 14px;
  background: white;
  font-family: inherit;
  font-size: 14px;
  line-height: 1.5;
  resize: vertical;
  box-sizing: border-box;
}
.composer-btn {
  align-self: stretch;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: auto;
  min-height: 100%;
  padding: 0 20px;
  font-size: 14px;
  font-weight: 600;
  border-radius: 8px;
  white-space: nowrap;
  box-sizing: border-box;
  cursor: pointer;
  flex-shrink: 0;
}
.composer-kb-btn {
  display: none;
  position: relative;
}
.kb-badge {
  position: absolute;
  right: -3px;
  bottom: -3px;
  min-width: 17px;
  height: 17px;
  padding: 0 4px;
  font-size: 10.5px;
  font-weight: 700;
  line-height: 14px;
  color: #ffffff;
  background: var(--primary);
  border: 1.5px solid #ffffff;
  border-radius: 999px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  box-sizing: border-box;
  z-index: 2;
  transition: transform 0.15s ease, background-color 0.15s ease;
}
.kb-badge.zero {
  background: #94a3b8;
}
.kb-header-badge {
  font-size: 14px;
  color: var(--primary);
  font-weight: 600;
  margin-left: 4px;
}
.sr-status {
  display: none;
}
.mobile-nav-container {
  display: none;
}
.source-file {
  padding: 12px 0;
  border-bottom: 1px solid #e2e9eb;
  font-size: 14px;
  overflow-wrap: anywhere;
}
.source-file small {
  display: block;
  color: var(--muted);
}
.subtle {
  font-size: 13px;
  color: var(--muted);
  margin: 20px 0;
}
#notice {
  padding: 10px 24px;
  background: #fbf1de;
  color: #79500c;
}
.filters {
  display: flex;
  gap: 16px;
  align-items: end;
  flex-wrap: wrap;
  padding: 20px 30px;
}
.filters label {
  font-size: 13px;
  color: var(--muted);
}
select {
  display: block;
  padding: 8px;
  max-width: 100%;
  border: 1px solid var(--line);
  background: white;
  border-radius: 4px;
}
.caution {
  font-size: 13px;
  color: #79500c;
  margin: 0 30px 18px;
}
#knowledge-content {
  overflow: auto;
  padding: 0 30px 30px;
}
.knowledge-item {
  padding: 18px 0;
  border-top: 1px solid var(--line);
}
.knowledge-item h3 {
  font-size: 18px;
  margin: 0 0 8px;
}
.knowledge-item p {
  margin: 8px 0;
}
.knowledge-item small {
  color: var(--muted);
  display: block;
}
.knowledge-item button {
  font-size: 13px;
  margin: 10px 8px 0 0;
}
iframe {
  width: 100%;
  height: 100%;
  border: 0;
}
dialog {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 24px;
  width: min(850px, 94vw);
  max-height: 85vh;
  overflow: auto;
}
dialog::backdrop {
  background: #172e3655;
}
.dialog-heading {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.dialog-heading h2 {
  font-size: 20px;
}
#source-content {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
}
.mobile-tools {
  display: none;
}
@media (max-width: 1200px) {
  .layout {
    grid-template-columns: 210px minmax(0, 1fr);
  }
  #sources:not(.open) {
    display: none !important;
  }
  .composer-kb-btn {
    display: inline-flex !important;
  }
}
@media (max-width: 750px) {
  .login {
    grid-template-columns: 1fr;
  }
  .login-intro {
    padding: 32px 24px;
  }
  .login h1 {
    font-size: 28px;
    margin: 16px 0;
  }
  .login-intro .rule,
  .login-intro > p:last-child {
    display: none;
  }
  .login form {
    padding: 30px 24px;
  }
  .login h2 {
    font-size: 22px;
  }
  header {
    height: 56px;
    min-height: 56px;
    padding: 0 14px;
    gap: 8px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: nowrap;
  }
  header nav,
  header #username,
  header #logout {
    display: none !important;
  }
  .brand {
    gap: 8px;
    font-size: 11px;
    flex: initial;
  }
  .brand strong {
    font-size: 15px;
  }
  .brand-logo {
    width: 32px;
    height: 32px;
  }
  .mobile-nav-container {
    display: block;
    position: relative;
  }
  .mobile-menu-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    font-size: 13px;
    font-weight: 600;
    color: var(--primary);
    background: var(--soft);
    border: 1px solid #ccebe6;
    border-radius: 6px;
    cursor: pointer;
    white-space: nowrap;
  }
  .mobile-menu-btn:hover {
    background: #dcf1ee;
  }
  .mobile-nav-dropdown {
    position: absolute;
    right: 0;
    top: calc(100% + 6px);
    background: white;
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
    min-width: 150px;
    z-index: 250;
    padding: 6px;
    display: flex;
    flex-direction: column;
    gap: 2px;
  }
  .mobile-nav-dropdown[hidden] {
    display: none !important;
  }
  .mobile-nav-dropdown button {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    text-align: left;
    padding: 9px 12px;
    font-size: 14px;
    border: 0;
    background: transparent;
    border-radius: 6px;
    color: var(--ink);
    cursor: pointer;
  }
  .mobile-nav-dropdown button:hover,
  .mobile-nav-dropdown button.active {
    background: var(--soft);
    color: var(--primary);
    font-weight: 600;
  }
  .mobile-nav-dropdown .menu-divider {
    margin: 4px 0;
    border: 0;
    border-top: 1px solid var(--line);
  }
  #mobile-logout {
    color: #a23d36;
  }
  .layout {
    display: block;
    height: calc(100dvh - 56px);
  }
  #sidebar:not(.open),
  #sources:not(.open) {
    display: none !important;
  }
  main {
    height: 100%;
  }
  .view {
    height: 100%;
  }
  .view-heading {
    padding: 8px 12px;
    min-height: 42px;
  }
  .view-heading h1 {
    font-size: 15px;
    font-weight: 600;
    margin: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: calc(100vw - 72px);
  }
  .mobile-history-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: white;
    color: var(--primary);
    font-size: 14px;
    cursor: pointer;
    flex-shrink: 0;
  }
  .badge {
    display: none;
  }
  #thread {
    padding: 16px 12px;
  }
  #welcome {
    margin: 4vh 0;
  }
  #welcome h2 {
    font-size: 20px;
  }
  #composer {
    padding: 8px 12px;
  }
  .composer-row {
    display: flex;
    flex-direction: row;
    gap: 8px;
    align-items: stretch;
    width: 100%;
  }
  #composer textarea {
    flex: 1;
    height: 40px;
    min-height: 40px;
    max-height: 40px;
    padding: 9px 12px;
    font-size: 14px;
    line-height: 20px;
    resize: none;
    overflow-y: auto;
    border-radius: 8px;
  }
  .composer-kb-btn {
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    position: relative;
    width: 40px;
    height: 40px;
    min-height: 40px;
    padding: 0;
    font-size: 15px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: white;
    color: var(--primary);
    flex-shrink: 0;
    cursor: pointer;
  }
  .composer-btn {
    height: 40px;
    min-height: 40px;
    padding: 0 12px;
    font-size: 14px;
    border-radius: 8px;
  }
  .filters {
    padding: 14px 12px;
    gap: 10px;
  }
  .filters label {
    max-width: 100%;
  }
  .caution {
    margin: 0 12px 12px;
  }
  #knowledge-content {
    padding: 0 12px 20px;
  }
  #knowledge-view .view-heading {
    display: none !important;
  }
  #sidebar.open {
    display: block !important;
    position: fixed;
    left: 0;
    top: 56px;
    bottom: 0;
    width: 280px;
    max-width: 85vw;
    height: calc(100dvh - 56px);
    max-height: none;
    z-index: 200;
    box-shadow: 2px 0 16px rgba(0, 0, 0, 0.18);
    border-right: 1px solid var(--line);
    border-bottom: 0;
    padding-top: 16px;
  }
  #sources.open {
    display: flex !important;
    flex-direction: column !important;
    position: fixed;
    right: 0;
    top: 56px;
    bottom: 0;
    width: 300px;
    max-width: 85vw;
    height: calc(100dvh - 56px);
    max-height: none;
    z-index: 200;
    box-shadow: -2px 0 16px rgba(0, 0, 0, 0.18);
    border-left: 1px solid var(--line);
    border-bottom: 0;
    padding: 16px !important;
    background: white;
  }
  .message.user {
    max-width: 95%;
  }
}
@media (prefers-reduced-motion: reduce) {
  * {
    scroll-behavior: auto !important;
    transition: none !important;
  }
}

.answer-content {
  white-space: normal;
}
.answer-content p {
  margin: 0 0 12px;
}
.answer-content h2,
.answer-content h3 {
  font-size: 18px;
  margin: 20px 0 8px;
}
.answer-content ul,
.answer-content ol {
  padding-left: 24px;
}
.answer-content table {
  border-collapse: collapse;
  display: block;
  overflow: auto;
  max-width: 100%;
}
.answer-content th,
.answer-content td {
  border: 1px solid var(--line);
  padding: 6px 10px;
}
.answer-content pre {
  white-space: pre-wrap;
}
.query-rules {
  font-size: 12px;
  margin-top: 10px;
}
.message.user .query-rules small {
  color: white;
  white-space: pre-wrap;
}
.mobile-tools {
  position: relative;
  z-index: 5;
  background: #f5f8f8;
}

@media (min-width: 751px) and (max-width: 1200px) {
  .mobile-tools {
    display: flex;
    padding: 8px 16px;
  }
  #toggle-history {
    display: none;
  }
  .view {
    height: calc(100% - 54px);
  }
  #sources.open {
    display: block;
    position: fixed;
    right: 0;
    top: 130px;
    width: 300px;
    max-height: 70vh;
    z-index: 6;
    border-bottom: 2px solid var(--primary);
  }
}

.knowledge-subject {
  margin-bottom: 28px;
}
.knowledge-subject > h2 {
  font-size: 21px;
  border-bottom: 2px solid var(--primary);
  padding-bottom: 12px;
  margin: 10px 0 0;
}
.knowledge-item h3 {
  color: var(--primary);
  font-size: 16px;
}
.knowledge-item:first-of-type {
  border-top: 0;
}

#manage,#line-manage{display:block;margin-top:12px}
#line-manage[hidden]{display:none}

.turn-progress{white-space:normal;margin-bottom:16px;padding-bottom:12px;border-bottom:1px solid var(--line);font-size:14px}
.turn-progress summary{cursor:pointer;display:flex;align-items:center;gap:10px;flex-wrap:wrap;color:var(--primary)}
.turn-progress summary:before{content:"＋";width:14px;flex-shrink:0}
.turn-progress[open] summary:before{content:"−"}
.turn-progress.running summary:before{content:"";height:14px;border:2px solid var(--line);border-top-color:var(--primary);border-radius:50%;animation:turn-spin 1s linear infinite}
.turn-progress summary small{margin-left:auto;font-variant-numeric:tabular-nums}
.progress-steps{padding-left:22px;margin:12px 0;max-height:180px;overflow:auto}
.progress-steps li{padding:3px 0;color:var(--muted)}
.progress-steps li[data-status=active]{color:var(--primary)}
.progress-steps li[data-status=failed],.turn-progress.interrupted summary{color:var(--warning)}
.progress-steps li[data-status=done]:after{content:" ✓";color:var(--primary)}
.progress-hint{font-size:12px;color:var(--muted);margin:8px 0 0}
@keyframes turn-spin{to{transform:rotate(360deg)}}
@media(prefers-reduced-motion:reduce){.turn-progress.running summary:before{animation:none}}
/* Keep the composer visible when an error notice occupies vertical space. */
#workspace{height:100dvh;display:flex;flex-direction:column}
#workspace>header,#notice{flex-shrink:0}
.layout{flex:1;min-height:0}

/* --- Turu C10 Modern Styling Extensions --- */

.sidebar-header, .sources-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 16px 0 10px;
}

.panel-divider {
  border: 0;
  border-top: 1px solid var(--line);
  margin: 18px 0;
}

/* History Room List */
.room-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 10px;
  margin-bottom: 4px;
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s ease;
  border: 1px solid transparent;
}
.room-item:hover {
  background: var(--soft);
}
.room-item.active {
  background: #e0f2f1;
  border-color: var(--accent);
  color: var(--primary);
  font-weight: 600;
}
.room-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}
.room-delete-btn {
  opacity: 0.4;
  border: 0;
  background: transparent;
  padding: 2px 6px;
  font-size: 11px;
}
.room-delete-btn:hover {
  opacity: 1;
  color: #dc2626;
}

/* Knowledge Base Checklist */
.kb-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 240px;
  overflow-y: auto;
  padding-right: 4px;
}
.kb-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
  background: #fafcfc;
  transition: all 0.15s;
}
.kb-item:hover {
  border-color: var(--primary);
}
.kb-item.selected {
  background: #e6fffa;
  border-color: var(--accent);
}
.kb-item label {
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  margin: 0;
}
.kb-item .kb-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.kb-item .kb-preview-link {
  font-size: 11px;
  color: var(--primary);
  text-decoration: underline;
  padding-left: 4px;
}

.kb-preview {
  font-size: 12px;
  overflow-y: auto;
  background: transparent;
  border: none;
  padding: 0;
}
.kb-file-list {
  list-style: none;
  padding: 0;
  margin: 0;
}
.kb-file-item {
  padding: 4px 0;
  border-bottom: 1px dashed var(--line);
  display: flex;
  align-items: center;
  gap: 6px;
}
.kb-file-item:last-child {
  border-bottom: none;
}

/* Header Badges */
.header-badges {
  display: flex;
  align-items: center;
  gap: 8px;
}
.badge {
  background: #e0f2fe;
  color: #0369a1;
  border: 1px solid #bae6fd;
  border-radius: 12px;
  padding: 2px 10px;
  font-size: 12px;
  font-weight: 500;
}

/* Quick questions */
.quick-questions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 16px;
}
.quick-question-btn {
  text-align: left;
  background: white;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 14px;
  font-size: 14px;
  color: var(--ink);
  transition: all 0.2s;
}
.quick-question-btn:hover {
  border-color: var(--primary);
  color: var(--primary);
  background: var(--soft);
}

/* Message Content Components */
.message {
  margin-bottom: 20px;
}
.message-bubble {
  position: relative;
}

/* Collapsible Details: Thinking, Agent, Memory */
details.thinking-block,
details.agent-activity-block,
details.memory-block {
  border-radius: 8px;
  margin: 10px 0;
  font-size: 13.5px;
  transition: all 0.2s;
}
details.thinking-block summary,
details.agent-activity-block summary,
details.memory-block summary {
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 14px;
  font-weight: 600;
  user-select: none;
  list-style: none;
}
details.thinking-block summary::-webkit-details-marker,
details.agent-activity-block summary::-webkit-details-marker,
details.memory-block summary::-webkit-details-marker {
  display: none;
}

/* Thinking block styles */
details.thinking-block {
  background: #f0f7ff;
  border: 1px solid #bfdbfe;
  color: #1e40af;
}
details.thinking-block .thinking-content {
  padding: 10px 14px;
  border-top: 1px solid #dbeafe;
  color: #334155;
  font-size: 13px;
  line-height: 1.6;
}

/* Agent block styles */
details.agent-activity-block {
  background: #f0fdf4;
  border: 1px solid #bbf7d0;
  color: #166534;
}
details.agent-activity-block .agent-steps {
  padding: 10px 14px;
  border-top: 1px solid #dcfce7;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.agent-step {
  border-left: 3px solid #22c55e;
  padding-left: 10px;
}
.agent-step.explain {
  border-left-color: #3b82f6;
}
.agent-step-title {
  font-weight: 600;
  font-size: 13px;
}
.agent-step-body {
  font-size: 12.5px;
  color: #475569;
  margin-top: 2px;
}

/* Memory block styles */
details.memory-block {
  background: #faf5ff;
  border: 1px solid #e9d5ff;
  color: #6b21a8;
}
details.memory-block .memory-content {
  padding: 10px 14px;
  border-top: 1px solid #f3e8ff;
  color: #4c1d95;
  font-size: 13px;
}

/* Quote badges */
.quote-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 8px 0;
}
.quote-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: #f1f5f9;
  border: 1px solid #cbd5e1;
  border-radius: 12px;
  padding: 2px 10px;
  font-size: 12px;
  color: #334155;
}

/* Info and Warning Alerts */
.info-box {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  background: #eff6ff;
  border-left: 4px solid #3b82f6;
  color: #1e40af;
  padding: 10px 14px;
  border-radius: 4px;
  margin: 10px 0;
  font-size: 13.5px;
}
.warning-box {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  background: #fffbeb;
  border-left: 4px solid #f59e0b;
  color: #b45309;
  padding: 10px 14px;
  border-radius: 4px;
  margin: 10px 0;
  font-size: 13.5px;
}

/* Dynamic Progress Bar */
.progress-bar-container {
  margin: 10px 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.progress-bar-item {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  padding: 8px 12px;
}
.progress-bar-label {
  display: flex;
  justify-content: space-between;
  font-size: 12.5px;
  font-weight: 500;
  color: #334155;
  margin-bottom: 6px;
}
.progress-track {
  width: 100%;
  height: 8px;
  background: #e2e8f0;
  border-radius: 4px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: var(--primary);
  border-radius: 4px;
  transition: width 0.3s ease;
}
.progress-fill.indeterminate {
  width: 40%;
  animation: indeterminate-slide 1.5s infinite ease-in-out;
}
@keyframes indeterminate-slide {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(250%); }
}

/* Attachment Pill & Thumbnails */
.attachment-container {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 8px 0;
}
.attachment-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: #f1f5f9;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  padding: 4px 10px;
  font-size: 12.5px;
  color: #1e293b;
  text-decoration: none;
  max-width: 280px;
}
.attachment-pill:hover {
  background: #e2e8f0;
  text-decoration: none;
}
.attachment-image {
  width: 88px;
  height: 88px;
  border-radius: 6px;
  border: 1px solid #cbd5e1;
  object-fit: cover;
  cursor: pointer;
  transition: transform 0.2s;
}
.attachment-image:hover {
  transform: scale(1.03);
}

/* Mermaid Container */
.mermaid-container {
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 16px;
  margin: 12px 0;
  overflow-x: auto;
  text-align: center;
}
.mermaid-container svg {
  max-width: 100%;
  height: auto;
}

/* Code Block Wrapper with Copy Button */
.code-block-wrapper {
  background: #1e293b;
  border-radius: 6px;
  margin: 12px 0;
  overflow: hidden;
}
.code-block-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: #0f172a;
  padding: 6px 12px;
  font-size: 12px;
  color: #94a3b8;
}
.copy-code-btn {
  border: 0;
  background: transparent;
  color: #94a3b8;
  cursor: pointer;
  padding: 2px 6px;
  font-size: 12px;
}
.copy-code-btn:hover {
  color: white;
}
.code-block-wrapper pre {
  margin: 0;
  padding: 12px;
  color: #f8fafc;
  overflow-x: auto;
  font-family: Consolas, Monaco, "Courier New", monospace;
  font-size: 13px;
  line-height: 1.5;
}

/* Message Actions (Feedback & Copy) */
.message-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px solid #e2e8f0;
}
.action-btn {
  border: 1px solid var(--line);
  background: white;
  border-radius: 4px;
  padding: 4px 10px;
  font-size: 12px;
  color: var(--muted);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  transition: all 0.15s;
}
.action-btn:hover {
  border-color: var(--primary);
  color: var(--primary);
}
.action-btn.active-like {
  background: #ecfdf5;
  border-color: #10b981;
  color: #059669;
  font-weight: 600;
}
.action-btn.active-dislike {
  background: #fef2f2;
  border-color: #ef4444;
  color: #dc2626;
  font-weight: 600;
}

/* KB Selection & Preview Styling */
.kb-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 6px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.15s;
}
.kb-item:hover {
  background: var(--soft);
}
.kb-item.preview-active {
  background: var(--soft);
  border-color: var(--primary);
}
.kb-item.kb-select-all {
  border-bottom: 1px solid var(--line);
  padding-bottom: 10px;
  margin-bottom: 8px;
}
.kb-name {
  flex: 1;
  font-size: 13.5px;
  cursor: pointer;
  user-select: none;
}
.kb-preview-btn {
  background: transparent;
  border: none;
  color: var(--muted);
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 4px;
}
.kb-preview-btn:hover {
  color: var(--primary);
  background: white;
}
.kb-preview-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--line);
  font-size: 13.5px;
}
.kb-stage-files {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.kb-stage-file-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 8px 10px;
  background: white;
  border: 1px solid var(--line);
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.15s;
}
.kb-stage-file-item:hover {
  border-color: var(--primary);
  background: var(--soft);
}
.kb-stage-file-name {
  font-size: 13px;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 6px;
  word-break: break-all;
}
.kb-stage-file-meta {
  display: flex;
  justify-content: space-between;
  font-size: 11.5px;
  color: var(--muted);
}
/* History Item Single Row without Line Break */
.history-item {
  display: flex !important;
  flex-direction: row !important;
  align-items: center !important;
  justify-content: space-between !important;
  padding: 7px 10px !important;
  margin-bottom: 4px !important;
  border-radius: 6px !important;
  font-size: 13px !important;
  cursor: pointer !important;
  transition: background 0.15s ease !important;
  border: 1px solid transparent !important;
  width: 100% !important;
  box-sizing: border-box !important;
}
.history-item:hover {
  background: var(--soft) !important;
}
.history-item.active {
  background: #e0f2f1 !important;
  border-color: var(--accent) !important;
  color: var(--primary) !important;
  font-weight: 600 !important;
}
.history-item .title {
  flex: 1 1 auto !important;
  min-width: 0 !important;
  overflow: hidden !important;
  text-overflow: ellipsis !important;
  white-space: nowrap !important;
  margin-right: 6px !important;
  text-align: left !important;
  display: block !important;
}
.history-item .delete-button {
  width: auto !important;
  flex: 0 0 auto !important;
  padding: 4px 6px !important;
  margin: 0 !important;
  border: 0 !important;
  background: transparent !important;
  opacity: 0.45 !important;
  cursor: pointer !important;
  color: inherit !important;
  font-size: 12px !important;
  line-height: 1 !important;
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  border-radius: 4px !important;
}
.history-item .delete-button:hover {
  opacity: 1 !important;
  color: #dc2626 !important;
  background: #fee2e2 !important;
}

/* Feedback Actions: Small buttons with proper gap */
.feedback-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 8px;
  padding-top: 4px;
}
.feedback-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 8px;
  font-size: 12px;
  line-height: 1.4;
  border: 1px solid var(--line);
  background: #ffffff;
  color: var(--muted);
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.15s ease;
}
.feedback-btn:hover {
  background: var(--soft);
  color: var(--text);
  border-color: #cbd5e1;
}
.feedback-btn.active.like-btn {
  background: #ecfdf5;
  border-color: #10b981;
  color: #059669;
  font-weight: 600;
}
.feedback-btn.active.dislike-btn {
  background: #fef2f2;
  border-color: #ef4444;
  color: #dc2626;
  font-weight: 600;
}

/* Right Sidebar: Enlarged Knowledge Base Preview & Compact Indented List */
#sources {
  display: flex;
  flex-direction: column;
  height: 100%;
  box-sizing: border-box;
  padding: 20px 16px;
  overflow: hidden;
}
#sources .sources-header {
  flex-shrink: 0;
  margin: 0 0 6px;
}
#sources > p.subtle {
  flex-shrink: 0;
  margin-bottom: 8px;
}
#kb-list {
  flex: 0 0 auto;
  max-height: 180px;
  overflow-y: auto;
  padding-right: 2px;
}
#sources .panel-divider {
  flex-shrink: 0;
  margin: 12px 0 10px;
}
#sources h2:last-of-type {
  flex-shrink: 0;
  margin: 0 0 8px;
}
#kb-preview {
  flex: 1 1 0 !important;
  min-height: 0 !important;
  max-height: none !important;
  overflow-y: auto !important;
  background: transparent !important;
  border: none !important;
  padding: 0 !important;
}

/* Indented Compact KB Stage Files Preview */
.kb-preview-group {
  margin-bottom: 12px;
}
.kb-preview-group:last-child {
  margin-bottom: 0;
}
.kb-preview-group-header {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--primary);
  padding: 3px 0;
}
.kb-group-count {
  font-size: 11px;
  color: var(--muted);
  font-weight: normal;
}
.kb-preview-group-files {
  margin-left: 10px;
  padding-left: 8px;
  border-left: 2px solid #e2e8f0;
  display: flex;
  flex-direction: column;
  gap: 3px;
  margin-top: 4px;
}
.kb-stage-file-compact {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 4px 6px;
  background: white;
  border: 1px solid var(--line);
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.15s ease;
  font-size: 12px;
}
.kb-stage-file-compact:hover {
  background: var(--soft);
  border-color: var(--primary);
  color: var(--primary);
}
.kb-stage-file-compact .file-left {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  flex: 1;
}
.kb-stage-file-compact .file-left i {
  color: #64748b;
  font-size: 11px;
  flex-shrink: 0;
}
.kb-stage-file-compact .file-left .file-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.kb-stage-file-compact .file-right {
  font-size: 11px;
  color: var(--muted);
  margin-left: 6px;
  flex-shrink: 0;
}
.kb-preview-empty-hint {
  font-size: 11.5px;
  color: var(--muted);
  padding: 2px 4px;
}

.source-meta {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  padding: 10px 14px;
  margin: 12px 0;
  font-size: 13px;
  display: grid;
  grid-template-columns: 1fr;
  gap: 6px;
  color: #334155;
}
.source-meta code {
  background: #e2e8f0;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 12px;
}
.file-content-pre {
  margin: 0;
  padding: 16px;
  background: #f8fafc;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 13px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 60vh;
  overflow-y: auto;
  font-family: Consolas, Monaco, "Courier New", monospace;
}

/* Hide sidebars on Knowledge and Monthly views */
.layout.hide-sidebars {
  grid-template-columns: minmax(0, 1fr) !important;
}
.layout.hide-sidebars #sidebar,
.layout.hide-sidebars #sources {
  display: none !important;
}
.layout.hide-sidebars .mobile-tools {
  display: none !important;
}

#monthly-view {
  height: 100%;
  width: 100%;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
}
#monthly-frame {
  width: 100%;
  height: 100%;
  border: 0;
  flex: 1;
}

/* SSE 檢索相關知識中 等待畫面 */
.retrieval-waiting {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  background: var(--soft);
  color: var(--primary);
  border: 1px solid #ccebe6;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  margin: 4px 0;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
}
.retrieval-waiting i {
  font-size: 15px;
  color: var(--primary);
  animation: fa-spin 1.2s infinite linear;
}
.retrieval-waiting span {
  letter-spacing: 0.5px;
}
