/* ============================================================================
   relately v2.3 — ChatGPT 純白極簡對話工作台樣式
   ============================================================================ */

:root {
  --font-sans: 'Inter', 'Noto Sans TC', -apple-system, BlinkMacSystemFont, sans-serif;

  --bg-main: #FFFFFF;
  --bg-sidebar: #F9F9F9;
  --bg-pill: #F4F4F4;
  --bg-fact: #F7F7F8;
  --bg-hover: #EFEFEF;

  --text-primary: #0D0D0D;
  --text-secondary: #5D5D5D;
  --text-muted: #8E8E8E;

  --border-light: #E5E5E5;
  --border-strong: #0D0D0D;

  --btn-dark-bg: #0D0D0D;
  --btn-dark-text: #FFFFFF;
  --danger-text: #DC2626;
}

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  font-family: var(--font-sans);
  background: var(--bg-main);
  color: var(--text-primary);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  height: 100%;
}

.tabular-nums { font-variant-numeric: tabular-nums; }

/* Shell */
.chatgpt-shell {
  display: flex;
  height: 100vh;
  overflow: hidden;
  background: var(--bg-main);
}

.sidebar-backdrop {
  display: none;
}

/* ============================================================================
   左側側邊欄（ChatGPT Sidebar）
   ============================================================================ */
.gpt-sidebar {
  width: 268px;
  flex-shrink: 0;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border-light);
  display: flex;
  flex-direction: column;
  height: 100vh;
  transition: margin-left 0.2s ease, transform 0.2s ease;
}

body.sidebar-collapsed .gpt-sidebar {
  margin-left: -268px;
}

.sidebar-top-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 12px 10px;
}

.sidebar-search-wrap {
  position: relative;
  flex: 1;
  display: flex;
  align-items: center;
}

.search-svg {
  position: absolute;
  left: 12px;
  color: var(--text-muted);
  pointer-events: none;
}

.sidebar-search-input {
  width: 100%;
  height: 38px;
  padding: 6px 12px 6px 34px;
  border-radius: 9999px;
  border: 1px solid transparent;
  background: var(--bg-hover);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 13.5px;
  outline: none;
}

.sidebar-search-input:focus {
  background: var(--bg-main);
  border-color: var(--border-light);
}

.icon-btn {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
}

.icon-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.role-filter-row {
  display: flex;
  gap: 4px;
  padding: 0 12px 10px;
  overflow-x: auto;
}

.filter-chip {
  min-height: 36px;
  padding: 0 13px;
  border-radius: 9999px;
  border: 1px solid var(--border-light);
  background: var(--bg-main);
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  touch-action: manipulation;
  transition: transform 0.12s ease, background 0.16s ease, color 0.16s ease, border-color 0.16s ease;
}

.filter-chip:active {
  transform: scale(0.94);
}

.filter-chip.active {
  background: var(--btn-dark-bg);
  border-color: var(--btn-dark-bg);
  color: var(--btn-dark-text);
}

.sidebar-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 4px 8px 12px;
}

.sidebar-section {
  margin-bottom: 16px;
}

.sidebar-section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 10px;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text-muted);
}

.mini-count {
  font-size: 11px;
  color: var(--text-muted);
}

.sidebar-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.sidebar-item {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 9px 10px;
  border-radius: 10px;
  border: none;
  background: transparent;
  text-align: left;
  font-family: inherit;
  cursor: pointer;
  color: var(--text-primary);
}

.sidebar-item:hover,
.sidebar-item.active {
  background: var(--bg-hover);
}

.sidebar-item-info {
  min-width: 0;
  flex: 1;
}

.sidebar-item-top {
  display: flex;
  align-items: center;
  gap: 6px;
}

.sidebar-item-name {
  font-size: 13.5px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-item-role {
  font-size: 11px;
  color: var(--text-secondary);
  background: var(--bg-main);
  border: 1px solid var(--border-light);
  padding: 1px 6px;
  border-radius: 9999px;
  flex-shrink: 0;
}

.sidebar-item-sub {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
}

.sidebar-del-btn {
  opacity: 0;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 11.5px;
  padding: 4px 6px;
  border-radius: 6px;
  cursor: pointer;
  flex-shrink: 0;
}

.sidebar-item:hover .sidebar-del-btn {
  opacity: 1;
}

.sidebar-del-btn:hover {
  color: var(--danger-text);
  background: rgba(220, 38, 38, 0.08);
}

.sidebar-empty {
  padding: 8px 10px;
  font-size: 12.5px;
  color: var(--text-muted);
}

.sidebar-footer {
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--border-light);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.vault-status-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
  color: var(--text-secondary);
}

.v1-switch-link {
  font-size: 11px;
  color: var(--text-secondary);
  text-decoration: none;
  border: 1px solid var(--border-light);
  border-radius: 9999px;
  padding: 2px 8px;
  background: var(--bg-main);
}

.sidebar-footer-btns {
  display: flex;
  gap: 6px;
}

.btn-subtle {
  flex: 1;
  height: 36px;
  padding: 0 12px;
  border-radius: 10px;
  border: 1px solid var(--border-light);
  background: var(--bg-main);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
}

.btn-subtle:hover {
  background: var(--bg-hover);
}

/* ============================================================================
   右側主對話區（ChatGPT Main Stage）
   ============================================================================ */
.gpt-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  height: 100vh;
  background: var(--bg-main);
}

.gpt-header {
  height: 58px;
  padding: 0 16px;
  border-bottom: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-shrink: 0;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.header-title-wrap {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.header-title {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-almanac {
  font-size: 11.5px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.model-pill {
  height: 34px;
  padding: 0 12px;
  border-radius: 9999px;
  border: 1px solid var(--border-light);
  background: var(--bg-pill);
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
}

.btn-header-outline {
  height: 34px;
  padding: 0 12px;
  border-radius: 9999px;
  border: 1px solid var(--border-light);
  background: var(--bg-main);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 500;
  cursor: pointer;
}

.btn-header-outline:hover {
  background: var(--bg-pill);
}

/* 對話流 */
.chat-stream {
  flex: 1;
  overflow-y: auto;
  padding: 20px 16px 28px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.msg-row {
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
}

.msg-row.msg-enter {
  animation: chatPopIn 0.26s cubic-bezier(0.22, 1, 0.36, 1) both;
}

@keyframes chatPopIn {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.99);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.msg-row.is-user {
  align-items: flex-end;
}

.user-bubble {
  max-width: 82%;
  padding: 11px 16px;
  border-radius: 20px;
  background: var(--bg-pill);
  color: var(--text-primary);
  font-size: 15px;
  line-height: 1.55;
  white-space: pre-wrap;
}

.msg-row.is-assistant {
  align-items: flex-start;
  gap: 10px;
}

.assistant-head {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
}

/* 嚴格區隔區塊 1：【實錄卡】 */
.fact-box {
  width: 100%;
  background: var(--bg-fact);
  border: 1px solid var(--border-light);
  border-radius: 14px;
  padding: 13px 15px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.fact-box-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
}

.fact-lines {
  font-size: 14px;
  color: var(--text-primary);
  line-height: 1.6;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.history-list-mini {
  margin-top: 6px;
  padding-top: 8px;
  border-top: 1px solid var(--border-light);
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.history-mini-item {
  font-size: 13px;
  color: var(--text-secondary);
}

/* 嚴格區隔區塊 2：【微臣進言】 */
.banter-text {
  font-size: 15px;
  line-height: 1.65;
  color: var(--text-primary);
  white-space: pre-wrap;
}

/* 補齊資訊快捷膠囊 */
.followup-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 2px;
}

.action-pill {
  min-height: 38px;
  padding: 6px 14px;
  border-radius: 9999px;
  border: 1px solid var(--border-light);
  background: var(--bg-main);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: transform 0.12s ease, background 0.16s ease, border-color 0.16s ease;
}

.action-pill:active,
.composer-chip:active,
.send-circle-btn:active,
.btn-dark:active,
.btn-outline:active,
.btn-subtle:active,
.icon-btn:active {
  transform: scale(0.94);
}

.action-pill:hover {
  border-color: var(--border-strong);
  background: var(--bg-pill);
}

.action-pill.primary {
  background: var(--btn-dark-bg);
  border-color: var(--btn-dark-bg);
  color: var(--btn-dark-text);
}

/* 內嵌 API Key 快速綁定卡（無 Key 時出現） */
.inline-key-box {
  width: 100%;
  display: flex;
  gap: 8px;
  align-items: center;
  margin-top: 4px;
}

.typing-row {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 4px 0;
}

.typing-orb {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--text-primary);
  animation: gptPulse 1.15s ease-in-out infinite;
}

@keyframes gptPulse {
  0%, 100% { transform: scale(0.72); opacity: 0.45; }
  50% { transform: scale(1.12); opacity: 1; }
}

.typing-dots {
  font-size: 13.5px;
  color: var(--text-muted);
}

/* ============================================================================
   底部 ChatGPT 膠囊輸入列
   ============================================================================ */
.composer-dock {
  padding: 8px 16px calc(14px + env(safe-area-inset-bottom));
  background: var(--bg-main);
  flex-shrink: 0;
}

.composer-pill {
  max-width: 720px;
  margin: 0 auto;
  background: var(--bg-pill);
  border: 1px solid var(--border-light);
  border-radius: 26px;
  padding: 8px 10px 8px 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  transition: border-color 0.18s ease, box-shadow 0.18s ease, background 0.18s ease;
}

.composer-pill:focus-within {
  background: var(--bg-main);
  border-color: #D4D4D4;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.06);
}

.composer-role-bar {
  display: flex;
  align-items: center;
  gap: 6px;
}

.composer-chip {
  min-height: 34px;
  padding: 0 13px;
  border-radius: 9999px;
  border: 1px solid var(--border-light);
  background: var(--bg-main);
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 0.12s ease, background 0.16s ease, color 0.16s ease;
}

.composer-chip.active {
  background: var(--btn-dark-bg);
  border-color: var(--btn-dark-bg);
  color: var(--btn-dark-text);
}

.composer-input-row {
  display: flex;
  align-items: flex-end;
  gap: 6px;
}

.composer-textarea {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 15px;
  line-height: 1.45;
  resize: none;
  min-height: 38px;
  max-height: 140px;
  padding: 8px 4px;
  outline: none;
}

.composer-textarea::placeholder {
  color: var(--text-muted);
}

.voice-btn {
  width: 40px;
  height: 40px;
}

.voice-btn.recording {
  color: var(--danger-text);
  background: rgba(220, 38, 38, 0.1);
}

.send-circle-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: var(--btn-dark-bg);
  color: var(--btn-dark-text);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  touch-action: manipulation;
  transition: transform 0.12s ease;
}

.send-circle-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

/* ============================================================================
   Modals, Inputs & Toast
   ============================================================================ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
  backdrop-filter: blur(3px);
  z-index: 950;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal-overlay.active { display: flex; }

.modal-card {
  width: 100%;
  max-width: 400px;
  background: var(--bg-main);
  border: 1px solid var(--border-light);
  border-radius: 18px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.16);
  overflow: hidden;
  animation: modalPop 0.2s cubic-bezier(0.22, 1, 0.36, 1) both;
}

@keyframes modalPop {
  from { opacity: 0; transform: scale(0.96) translateY(6px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

.modal-card.modal-lg {
  max-width: 520px;
}

.modal-head {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-head .btn-subtle {
  flex: 0 0 auto;
  height: 32px;
}

.modal-body {
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  max-height: 78vh;
  overflow-y: auto;
}

.settings-section {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border-light);
}

.settings-section:last-child {
  padding-bottom: 0;
  border-bottom: none;
}

.settings-heading {
  font-size: 14.5px;
  font-weight: 600;
}

.settings-desc {
  font-size: 13px;
  color: var(--text-secondary);
}

.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.field label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
}

.clean-input {
  width: 100%;
  min-height: 40px;
  padding: 8px 12px;
  border-radius: 10px;
  border: 1px solid var(--border-light);
  background: var(--bg-main);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 14px;
  outline: none;
}

.clean-input:focus {
  border-color: var(--border-strong);
}

.checkbox-row {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-secondary);
  cursor: pointer;
}

.sync-status {
  font-size: 12px;
  color: var(--text-secondary);
}

.btn-row,
.modal-foot {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.modal-foot {
  justify-content: flex-end;
}

.btn-dark,
.btn-outline,
.btn-danger {
  min-height: 38px;
  padding: 6px 14px;
  border-radius: 9999px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
}

.btn-dark {
  background: var(--btn-dark-bg);
  color: var(--btn-dark-text);
  border: 1px solid var(--btn-dark-bg);
}

.btn-outline {
  background: var(--bg-main);
  color: var(--text-primary);
  border: 1px solid var(--border-light);
}

.btn-danger {
  background: var(--bg-main);
  color: var(--danger-text);
  border: 1px solid rgba(220, 38, 38, 0.3);
}

.error-text {
  font-size: 12.5px;
  color: var(--danger-text);
}

.toast-container {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.toast {
  background: var(--btn-dark-bg);
  color: var(--btn-dark-text);
  padding: 8px 16px;
  border-radius: 9999px;
  font-size: 13px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.16);
}

/* ============================================================================
   Mobile Drawer Sidebar (<= 768px)
   ============================================================================ */
@media (max-width: 768px) {
  .gpt-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 82vw;
    max-width: 310px;
    z-index: 800;
    margin-left: 0 !important;
    transform: translateX(-100%);
    padding-top: env(safe-area-inset-top);
  }

  .sidebar-del-btn {
    opacity: 0.72;
    min-height: 32px;
    padding: 4px 10px;
  }

  .gpt-header {
    padding: 0 12px;
  }

  .model-pill {
    padding: 0 10px;
    font-size: 11.5px;
  }

  body.sidebar-mobile-open .gpt-sidebar {
    transform: translateX(0);
  }

  body.sidebar-mobile-open .sidebar-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.35);
    z-index: 790;
  }

  .user-bubble {
    max-width: 90%;
  }
}
