:root {
  --font-sans: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
}

html[data-theme="light"] {
  --bg-page: #ffffff;
  --bg-surface: #f6f7f9;
  --bg-surface-hover: #eceff4;
  --bg-elevated: #ffffff;
  --bg-glass: rgba(255, 255, 255, 0.9);
  --bg-user-bubble: #f3f4f6;
  --bg-backdrop: rgba(17, 24, 39, 0.32);

  --text-primary: #111827;
  --text-secondary: #6b7280;
  --text-muted: #9ca3af;

  --accent: #b48a1e;
  --accent-bright: #c59b27;
  --accent-soft: rgba(197, 155, 39, 0.1);
  --accent-border: rgba(197, 155, 39, 0.38);

  --btn-primary-bg: #111827;
  --btn-primary-text: #ffffff;
  --btn-primary-hover: #1f2937;

  --border-subtle: rgba(17, 24, 39, 0.08);
  --border-medium: rgba(17, 24, 39, 0.14);

  --code-bg: #f6f7f9;
  --code-header-bg: #eef0f4;
  --code-text: #111827;
  --inline-code-bg: rgba(17, 24, 39, 0.06);
  --inline-code-text: #92670c;
  --table-stripe: rgba(17, 24, 39, 0.02);

  --danger: #dc2626;
  --danger-soft: rgba(220, 38, 38, 0.08);
  --success: #059669;
  --success-soft: rgba(5, 150, 105, 0.1);

  --shadow-capsule: 0 4px 20px rgba(17, 24, 39, 0.05), 0 1px 3px rgba(17, 24, 39, 0.04);
  --shadow-sheet: 0 20px 50px rgba(17, 24, 39, 0.16);
}

html[data-theme="dark"] {
  --bg-page: #0f141e;
  --bg-surface: #181f2c;
  --bg-surface-hover: #212a3a;
  --bg-elevated: #151b26;
  --bg-glass: rgba(15, 20, 30, 0.9);
  --bg-user-bubble: #1e2738;
  --bg-backdrop: rgba(0, 0, 0, 0.56);

  --text-primary: #f3f4f6;
  --text-secondary: #9ca3af;
  --text-muted: #6b7280;

  --accent: #d4af37;
  --accent-bright: #e5c453;
  --accent-soft: rgba(212, 175, 55, 0.14);
  --accent-border: rgba(212, 175, 55, 0.36);

  --btn-primary-bg: #f3f4f6;
  --btn-primary-text: #111827;
  --btn-primary-hover: #ffffff;

  --border-subtle: rgba(255, 255, 255, 0.08);
  --border-medium: rgba(255, 255, 255, 0.14);

  --code-bg: #141a26;
  --code-header-bg: #1b2333;
  --code-text: #e5e7eb;
  --inline-code-bg: rgba(255, 255, 255, 0.09);
  --inline-code-text: #e5c453;
  --table-stripe: rgba(255, 255, 255, 0.025);

  --danger: #f87171;
  --danger-soft: rgba(248, 113, 113, 0.12);
  --success: #34d399;
  --success-soft: rgba(52, 211, 153, 0.14);

  --shadow-capsule: 0 6px 24px rgba(0, 0, 0, 0.28);
  --shadow-sheet: 0 24px 60px rgba(0, 0, 0, 0.5);
}

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

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg-page);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

button,
input,
textarea {
  font-family: inherit;
  color: inherit;
}

button {
  cursor: pointer;
}

.hidden {
  display: none !important;
}

/* ==================== Screen A: Employee Login ==================== */
.login-view {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(24px + env(safe-area-inset-top)) 20px calc(28px + env(safe-area-inset-bottom));
  background: var(--bg-page);
}

.login-card {
  width: 100%;
  max-width: 360px;
  display: flex;
  flex-direction: column;
}

.login-brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  margin-bottom: 32px;
}

.login-logo {
  width: 56px;
  height: 56px;
  border-radius: 16px;
  object-fit: cover;
  border: 1px solid var(--border-subtle);
  background: #ffffff;
  box-shadow: 0 4px 16px rgba(17, 24, 39, 0.06);
  margin-bottom: 14px;
}

.login-title {
  margin: 0;
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--text-primary);
}

.login-subtitle {
  margin: 4px 0 0;
  font-size: 13px;
  color: var(--text-secondary);
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.login-input {
  width: 100%;
  height: 46px;
  padding: 0 14px;
  border-radius: 12px;
  border: 1px solid transparent;
  background: var(--bg-surface);
  font-size: 15px;
  color: var(--text-primary);
  outline: none;
  transition: background 0.16s ease, border-color 0.16s ease, box-shadow 0.16s ease;
}

.login-input::placeholder {
  color: var(--text-muted);
}

.login-input:focus {
  background: var(--bg-page);
  border-color: var(--accent-bright);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.login-code-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.login-code-input {
  flex: 1;
  min-width: 0;
  letter-spacing: 0.08em;
}

.code-send-btn {
  flex-shrink: 0;
  height: 46px;
  padding: 0 14px;
  border-radius: 12px;
  border: 1px solid var(--border-subtle);
  background: var(--bg-surface);
  color: var(--text-primary);
  font-size: 13.5px;
  font-weight: 500;
  white-space: nowrap;
  transition: background 0.16s ease, border-color 0.16s ease, color 0.16s ease;
}

.code-send-btn:hover:not(:disabled) {
  background: var(--bg-surface-hover);
  border-color: var(--border-medium);
}

.code-send-btn:disabled {
  color: var(--text-muted);
  cursor: not-allowed;
}

.demo-code-chip {
  align-self: flex-start;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--accent-border);
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 12.5px;
  font-weight: 500;
  transition: opacity 0.15s ease;
}

.demo-code-chip:hover {
  opacity: 0.85;
}

.login-submit-btn {
  margin-top: 4px;
  width: 100%;
  height: 46px;
  border: none;
  border-radius: 12px;
  background: var(--btn-primary-bg);
  color: var(--btn-primary-text);
  font-size: 15px;
  font-weight: 600;
  transition: background 0.16s ease, opacity 0.16s ease, transform 0.1s ease;
}

.login-submit-btn:hover:not(:disabled) {
  background: var(--btn-primary-hover);
}

.login-submit-btn:active:not(:disabled) {
  transform: scale(0.99);
}

.login-submit-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.login-error {
  margin-top: 2px;
  padding: 9px 12px;
  border-radius: 10px;
  background: var(--danger-soft);
  color: var(--danger);
  font-size: 13px;
  line-height: 1.45;
  text-align: center;
}

.login-footer {
  margin-top: 22px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.login-server-prompt {
  margin: 0;
  font-size: 12px;
  color: var(--accent);
}

.text-link-btn {
  border: none;
  background: transparent;
  padding: 6px 10px;
  font-size: 12.5px;
  color: var(--text-secondary);
  border-radius: 8px;
  transition: color 0.15s ease, background 0.15s ease;
}

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

/* ==================== Screen B: Minimalist Chat Workbench ==================== */
.app-shell {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  background: var(--bg-page);
}

.topbar {
  flex-shrink: 0;
  height: calc(52px + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) 12px 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-glass);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-subtle);
  z-index: 20;
}

.top-icon-btn {
  width: 38px;
  height: 38px;
  padding: 0;
  border: none;
  border-radius: 10px;
  background: transparent;
  color: var(--text-primary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease;
}

.top-icon-btn:hover {
  background: var(--bg-surface);
}

.top-icon-btn svg {
  width: 20px;
  height: 20px;
}

.topbar-center {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.topbar-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: -0.01em;
}

.topbar-thinking-badge {
  padding: 2px 7px;
  border-radius: 999px;
  background: var(--accent-soft);
  border: 1px solid var(--accent-border);
  color: var(--accent);
  font-size: 11px;
  font-weight: 500;
  line-height: 1.3;
}

/* Chat Viewport */
.chat-viewport {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior-y: contain;
}

.chat-container {
  width: 100%;
  max-width: 740px;
  min-height: 100%;
  margin: 0 auto;
  padding: 16px 16px 24px;
  display: flex;
  flex-direction: column;
}

/* Empty Chat Home Screen */
.welcome-home {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 28px 12px 36px;
}

.welcome-logo {
  width: 48px;
  height: 48px;
  border-radius: 14px;
  object-fit: cover;
  border: 1px solid var(--border-subtle);
  background: #ffffff;
  box-shadow: 0 3px 12px rgba(17, 24, 39, 0.06);
  margin-bottom: 16px;
}

.welcome-title {
  margin: 0;
  font-size: 20px;
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: -0.01em;
}

.welcome-subtitle {
  margin: 6px 0 24px;
  font-size: 14px;
  color: var(--text-secondary);
}

.suggestion-list {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  width: 100%;
  max-width: 360px;
}

.suggestion-chip {
  width: 100%;
  display: inline-flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 14px;
  border-radius: 12px;
  border: 1px solid var(--border-subtle);
  background: var(--bg-surface);
  color: var(--text-primary);
  font-size: 13.5px;
  text-align: left;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.suggestion-chip:hover {
  background: var(--bg-surface-hover);
  border-color: var(--border-medium);
}

.suggestion-chip-arrow {
  color: var(--text-muted);
  font-size: 14px;
  flex-shrink: 0;
}

/* Conversation Stream */
.message-list {
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.msg-row {
  display: flex;
  flex-direction: column;
}

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

.msg-user-bubble {
  max-width: 84%;
  padding: 10px 15px;
  border-radius: 18px 18px 4px 18px;
  background: var(--bg-user-bubble);
  color: var(--text-primary);
  font-size: 15px;
  line-height: 1.55;
  word-break: break-word;
}

.msg-user-text {
  white-space: pre-wrap;
}

.msg-image-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 8px;
}

.msg-image-grid:last-child {
  margin-bottom: 0;
}

.msg-image-item {
  padding: 0;
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
  overflow: hidden;
  background: var(--bg-page);
  cursor: zoom-in;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.14s ease, opacity 0.14s ease;
}

.msg-image-item:active {
  transform: scale(0.98);
}

.msg-image-thumb {
  display: block;
  max-width: 220px;
  max-height: 220px;
  border-radius: 12px;
  object-fit: cover;
  cursor: zoom-in;
}

.msg-image-grid.multi .msg-image-item {
  width: 92px;
  height: 92px;
}

.msg-image-grid.multi .msg-image-thumb {
  width: 100%;
  height: 100%;
  max-width: none;
  max-height: none;
  border-radius: 0;
}

.msg-image-placeholder {
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px dashed var(--border-medium);
  background: var(--bg-page);
  display: inline-flex;
  flex-direction: column;
  gap: 2px;
  max-width: 200px;
}

.msg-image-placeholder-name {
  font-size: 12px;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.msg-image-placeholder-note {
  font-size: 11px;
  color: var(--text-muted);
}

.msg-attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 8px;
}

.msg-attachments:last-child {
  margin-bottom: 0;
}

.msg-att-pill,
.msg-doc-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 100%;
  padding: 5px 9px;
  border-radius: 10px;
  background: var(--bg-page);
  border: 1px solid var(--border-subtle);
  font-size: 12px;
  color: var(--text-secondary);
}

.msg-att-pill.truncated,
.msg-doc-pill.truncated {
  border-color: var(--accent-border);
  color: var(--accent);
}

.msg-doc-badge {
  flex-shrink: 0;
  padding: 1px 5px;
  border-radius: 5px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: #ffffff;
  text-transform: uppercase;
}

.msg-doc-name {
  max-width: 150px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-primary);
  font-weight: 500;
}

.msg-doc-meta {
  flex-shrink: 0;
  font-size: 11px;
  color: var(--text-secondary);
}

.msg-doc-pill.truncated .msg-doc-meta {
  color: var(--accent);
}

/* Assistant Message — Airy Full-Width Prose (No Boxed Card) */
.msg-row.assistant {
  align-items: flex-start;
}

.msg-assistant-wrap {
  width: 100%;
  min-width: 0;
}

.msg-assistant-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

.msg-avatar {
  width: 22px;
  height: 22px;
  border-radius: 7px;
  object-fit: cover;
  border: 1px solid var(--border-subtle);
  background: #ffffff;
}

.msg-author-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
}

/* Collapsible Reasoning Accordion */
.reasoning-block {
  margin: 4px 0 12px;
  border-radius: 12px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  overflow: hidden;
}

.reasoning-summary {
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 12px;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  user-select: none;
}

.reasoning-summary::-webkit-details-marker {
  display: none;
}

.reasoning-summary-left {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.reasoning-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent-bright);
}

.reasoning-chevron {
  font-size: 11px;
  color: var(--text-muted);
  transition: transform 0.16s ease;
}

.reasoning-block[open] .reasoning-chevron {
  transform: rotate(180deg);
}

.reasoning-body {
  padding: 0 12px 10px 14px;
  margin: 0 0 2px 12px;
  border-left: 2px solid var(--border-medium);
  font-size: 13px;
  line-height: 1.6;
  color: var(--text-secondary);
  white-space: pre-wrap;
  word-break: break-word;
}

/* Markdown Body */
.markdown-body {
  font-size: 15px;
  line-height: 1.68;
  color: var(--text-primary);
  word-break: break-word;
}

.markdown-body > *:first-child {
  margin-top: 0;
}

.markdown-body > *:last-child {
  margin-bottom: 0;
}

.markdown-body h1,
.markdown-body h2,
.markdown-body h3,
.markdown-body h4 {
  margin: 18px 0 8px;
  font-weight: 600;
  line-height: 1.35;
  color: var(--text-primary);
}

.markdown-body h1 { font-size: 1.25em; }
.markdown-body h2 { font-size: 1.15em; }
.markdown-body h3 { font-size: 1.05em; }

.markdown-body p {
  margin: 0 0 10px;
}

.markdown-body ul,
.markdown-body ol {
  margin: 6px 0 12px;
  padding-left: 20px;
}

.markdown-body li {
  margin: 4px 0;
}

.markdown-body blockquote {
  margin: 10px 0;
  padding: 6px 12px;
  border-left: 3px solid var(--accent-bright);
  background: var(--bg-surface);
  border-radius: 0 8px 8px 0;
  color: var(--text-secondary);
}

.markdown-body hr {
  border: none;
  border-top: 1px solid var(--border-subtle);
  margin: 16px 0;
}

.markdown-body a {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.markdown-body code {
  font-family: var(--font-mono);
  font-size: 0.88em;
  padding: 2px 5px;
  border-radius: 5px;
  background: var(--inline-code-bg);
  color: var(--inline-code-text);
}

.code-block {
  margin: 12px 0;
  border-radius: 12px;
  border: 1px solid var(--border-subtle);
  background: var(--code-bg);
  overflow: hidden;
}

.code-block-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 12px;
  background: var(--code-header-bg);
  font-size: 12px;
  color: var(--text-secondary);
}

.code-copy-btn {
  border: none;
  background: transparent;
  padding: 3px 8px;
  border-radius: 6px;
  font-size: 12px;
  color: var(--text-secondary);
  transition: background 0.15s ease, color 0.15s ease;
}

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

.code-block pre {
  margin: 0;
  padding: 12px 14px;
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.55;
  color: var(--code-text);
}

.code-block pre code {
  padding: 0;
  background: transparent;
  color: inherit;
  font-size: inherit;
}

.md-table-wrap {
  margin: 12px 0;
  overflow-x: auto;
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
}

.md-table-wrap table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}

.md-table-wrap th,
.md-table-wrap td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border-subtle);
  text-align: left;
  white-space: nowrap;
}

.md-table-wrap th {
  font-weight: 600;
  background: var(--bg-surface);
}

.md-table-wrap tr:nth-child(even) td {
  background: var(--table-stripe);
}

.md-table-wrap tr:last-child td {
  border-bottom: none;
}

.streaming-indicator {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-top: 6px;
  font-size: 13px;
  color: var(--text-secondary);
}

.pulse-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent-bright);
  animation: pulseDot 1.2s ease-in-out infinite;
}

@keyframes pulseDot {
  0%, 100% { opacity: 0.35; transform: scale(0.85); }
  50% { opacity: 1; transform: scale(1.1); }
}

.msg-error {
  margin-top: 8px;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--danger-soft);
  color: var(--danger);
  font-size: 13px;
  line-height: 1.5;
  white-space: pre-wrap;
}

.msg-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 8px;
}

.msg-action-btn {
  border: none;
  background: transparent;
  padding: 4px 9px;
  border-radius: 7px;
  font-size: 12px;
  color: var(--text-secondary);
  transition: background 0.15s ease, color 0.15s ease;
}

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

/* ==================== Floating Capsule Composer ==================== */
.composer-dock {
  flex-shrink: 0;
  width: 100%;
  max-width: 740px;
  margin: 0 auto;
  padding: 4px 14px calc(12px + env(safe-area-inset-bottom));
  background: var(--bg-page);
}

.attachment-strip {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  padding: 2px 2px 4px;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}

.attachment-strip::-webkit-scrollbar {
  display: none;
}

.att-thumb-card {
  position: relative;
  width: 64px;
  height: 64px;
  flex: 0 0 64px;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--border-subtle);
  background: var(--bg-surface);
  cursor: zoom-in;
  transition: border-color 0.15s ease, transform 0.12s ease;
}

.att-thumb-card:hover {
  border-color: var(--border-medium);
}

.att-thumb-card:active {
  transform: scale(0.97);
}

.att-thumb-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.att-doc-card {
  position: relative;
  height: 64px;
  min-width: 156px;
  max-width: 220px;
  flex: 0 0 auto;
  padding: 8px 26px 8px 10px;
  border-radius: 12px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  gap: 10px;
  transition: border-color 0.15s ease, opacity 0.15s ease;
}

.att-doc-card.truncated,
.att-doc-card.parsing {
  border-color: var(--accent-border);
}

.att-doc-badge {
  width: 34px;
  height: 40px;
  flex: 0 0 34px;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: #ffffff;
}

.att-doc-badge.pdf,
.msg-doc-badge.pdf {
  background: #dc2626;
}

.att-doc-badge.xlsx,
.msg-doc-badge.xlsx {
  background: #059669;
}

.att-doc-badge.docx,
.msg-doc-badge.docx {
  background: #2563eb;
}

.att-doc-badge.pptx,
.msg-doc-badge.pptx {
  background: #ea580c;
}

.att-doc-badge.txt,
.msg-doc-badge.txt {
  background: #475569;
}

.att-doc-meta {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.att-doc-name {
  font-size: 12.5px;
  font-weight: 500;
  line-height: 1.3;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.att-doc-status {
  font-size: 11px;
  line-height: 1.3;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.att-doc-status.parsing {
  color: var(--accent);
  font-weight: 500;
}

.att-doc-status.truncated {
  color: var(--accent);
}

.att-remove-btn {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 20px;
  height: 20px;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.72);
  color: #ffffff;
  font-size: 14px;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(4px);
  transition: background 0.15s ease, transform 0.1s ease;
}

.att-remove-btn:hover {
  background: rgba(15, 23, 42, 0.9);
}

.att-remove-btn:active {
  transform: scale(0.92);
}

.composer-capsule {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 11px 12px 9px;
  border-radius: 22px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  box-shadow: var(--shadow-capsule);
  transition: border-color 0.16s ease, background 0.16s ease;
}

.composer-capsule:focus-within {
  border-color: var(--border-medium);
}

.composer-input {
  width: 100%;
  min-height: 24px;
  max-height: 140px;
  padding: 0 4px;
  border: none;
  background: transparent;
  resize: none;
  outline: none;
  font-size: 15px;
  line-height: 1.5;
  color: var(--text-primary);
}

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

.composer-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.composer-tools-left,
.composer-tools-right {
  display: flex;
  align-items: center;
  gap: 6px;
}

.capsule-pill {
  height: 30px;
  padding: 0 10px;
  border-radius: 999px;
  border: 1px solid var(--border-subtle);
  background: var(--bg-page);
  color: var(--text-secondary);
  font-size: 12.5px;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.capsule-pill svg {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
}

.capsule-pill:hover {
  color: var(--text-primary);
  border-color: var(--border-medium);
}

.capsule-pill.active {
  background: var(--accent-soft);
  border-color: var(--accent-border);
  color: var(--accent);
}

.plugin-count-pill {
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 11px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.composer-attach-btn {
  width: 32px;
  height: 32px;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--text-secondary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease, color 0.15s ease;
}

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

.composer-attach-btn svg {
  width: 18px;
  height: 18px;
}

.composer-send-btn,
.composer-stop-btn {
  width: 32px;
  height: 32px;
  padding: 0;
  border: none;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease, opacity 0.15s ease, transform 0.1s ease;
}

.composer-send-btn {
  background: var(--btn-primary-bg);
  color: var(--btn-primary-text);
}

.composer-send-btn:disabled {
  background: var(--border-medium);
  color: var(--bg-page);
  opacity: 0.6;
  cursor: default;
}

.composer-send-btn:not(:disabled):hover {
  background: var(--btn-primary-hover);
}

.composer-send-btn svg,
.composer-stop-btn svg {
  width: 16px;
  height: 16px;
}

.composer-stop-btn {
  background: var(--btn-primary-bg);
  color: var(--btn-primary-text);
}

/* ==================== Slide-out Drawer ==================== */
.backdrop {
  position: fixed;
  inset: 0;
  background: var(--bg-backdrop);
  z-index: 40;
  animation: fadeIn 0.18s ease;
}

.drawer {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: min(304px, 84vw);
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--bg-elevated);
  border-right: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  z-index: 50;
  box-shadow: var(--shadow-sheet);
  animation: slideRight 0.2s var(--ease-out);
}

.drawer-top {
  padding: 14px 14px 10px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.drawer-new-btn {
  width: 100%;
  height: 40px;
  border-radius: 999px;
  border: 1px solid var(--border-subtle);
  background: var(--bg-surface);
  color: var(--text-primary);
  font-size: 14px;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: background 0.15s ease;
}

.drawer-new-btn:hover {
  background: var(--bg-surface-hover);
}

.drawer-new-btn svg {
  width: 16px;
  height: 16px;
}

.drawer-search-wrap,
.market-search-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.drawer-search-icon {
  position: absolute;
  left: 11px;
  width: 15px;
  height: 15px;
  color: var(--text-muted);
  pointer-events: none;
}

.drawer-search-input,
.market-search-input {
  width: 100%;
  height: 36px;
  padding: 0 12px 0 32px;
  border-radius: 10px;
  border: 1px solid transparent;
  background: var(--bg-surface);
  font-size: 13.5px;
  color: var(--text-primary);
  outline: none;
}

.drawer-search-input:focus,
.market-search-input:focus {
  border-color: var(--accent-border);
  background: var(--bg-page);
}

.session-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 4px 10px 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.session-empty {
  margin: 24px 12px;
  text-align: center;
  font-size: 13px;
  color: var(--text-muted);
}

.session-item {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 2px 4px 2px 10px;
  border-radius: 10px;
  transition: background 0.14s ease;
}

.session-item:hover {
  background: var(--bg-surface);
}

.session-item.active {
  background: var(--bg-surface);
}

.session-item-btn {
  flex: 1;
  min-width: 0;
  border: none;
  background: transparent;
  padding: 8px 4px;
  text-align: left;
}

.session-title {
  font-size: 13.5px;
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.session-item.active .session-title {
  color: var(--accent);
}

.session-delete-btn {
  flex-shrink: 0;
  min-width: 28px;
  height: 28px;
  padding: 0 6px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--text-muted);
  font-size: 15px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease, color 0.15s ease;
}

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

.session-delete-btn.confirm {
  font-size: 11.5px;
  color: var(--danger);
  background: var(--danger-soft);
}

.drawer-menu-section {
  padding: 8px 12px;
  border-top: 1px solid var(--border-subtle);
}

.drawer-market-entry {
  width: 100%;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--border-subtle);
  background: var(--bg-surface);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-primary);
  transition: background 0.15s ease, border-color 0.15s ease;
}

.drawer-market-entry:hover {
  background: var(--bg-surface-hover);
  border-color: var(--border-medium);
}

.drawer-market-left {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.drawer-count-badge {
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 11.5px;
  font-weight: 500;
}

.drawer-footer {
  padding: 12px 14px 14px;
  border-top: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.drawer-user-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.user-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--accent-soft);
  border: 1px solid var(--accent-border);
  color: var(--accent);
  font-size: 14px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.drawer-user-info {
  min-width: 0;
}

.user-name {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-dept {
  font-size: 12px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.drawer-footer-actions {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.drawer-action-btn {
  width: 100%;
  padding: 8px 10px;
  border: none;
  border-radius: 9px;
  background: transparent;
  color: var(--text-secondary);
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 9px;
  text-align: left;
  transition: background 0.15s ease, color 0.15s ease;
}

.drawer-action-btn svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

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

.drawer-action-btn.danger:hover,
.drawer-action-btn.danger.confirm {
  background: var(--danger-soft);
  color: var(--danger);
}

/* ==================== Modals (Plugin Market & Server URL) ==================== */
.modal {
  position: fixed;
  inset: 0;
  background: var(--bg-backdrop);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 60;
  animation: fadeIn 0.16s ease;
}

.modal-sheet {
  width: 100%;
  max-width: 460px;
  max-height: 86vh;
  max-height: 86dvh;
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: 20px;
  box-shadow: var(--shadow-sheet);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: popIn 0.18s var(--ease-out);
}

.modal-sheet.modal-large {
  max-width: 640px;
  height: min(680px, 88dvh);
}

@media (max-width: 640px) {
  .modal {
    align-items: flex-end;
    padding: 0;
  }

  .modal-sheet,
  .modal-sheet.modal-large {
    max-width: 100%;
    height: auto;
    max-height: 90dvh;
    border-radius: 22px 22px 0 0;
    padding-bottom: env(safe-area-inset-bottom);
    animation: slideUp 0.22s var(--ease-out);
  }

  .modal-sheet.modal-large {
    height: 86dvh;
  }
}

.modal-header {
  padding: 18px 18px 12px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--border-subtle);
}

.modal-header h2 {
  margin: 0;
  font-size: 17px;
  font-weight: 600;
  color: var(--text-primary);
}

.modal-subtitle {
  margin: 3px 0 0;
  font-size: 12.5px;
  color: var(--text-secondary);
}

.close-btn {
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 50%;
  background: var(--bg-surface);
  color: var(--text-secondary);
  font-size: 20px;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s ease, color 0.15s ease;
}

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

.modal-body {
  padding: 16px 18px 20px;
  overflow-y: auto;
}

/* Plugin Market Controls & Cards */
.market-controls {
  padding: 12px 18px 10px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  border-bottom: 1px solid var(--border-subtle);
}

.market-categories {
  display: flex;
  align-items: center;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 2px;
  scrollbar-width: none;
}

.market-categories::-webkit-scrollbar {
  display: none;
}

.market-cat-btn {
  flex-shrink: 0;
  padding: 5px 12px;
  border-radius: 999px;
  border: 1px solid var(--border-subtle);
  background: var(--bg-surface);
  color: var(--text-secondary);
  font-size: 12.5px;
  font-weight: 500;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.market-cat-btn.active {
  background: var(--btn-primary-bg);
  border-color: var(--btn-primary-bg);
  color: var(--btn-primary-text);
}

.market-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 12px 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.market-empty,
.market-error-box {
  padding: 32px 16px;
  text-align: center;
  color: var(--text-secondary);
  font-size: 13.5px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.market-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-radius: 14px;
  border: 1px solid var(--border-subtle);
  background: var(--bg-page);
  transition: border-color 0.15s ease, background 0.15s ease;
}

.market-card:hover {
  border-color: var(--border-medium);
}

.market-card-icon {
  width: 40px;
  height: 40px;
  border-radius: 11px;
  background: var(--bg-surface);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  flex-shrink: 0;
}

.market-card-main {
  flex: 1;
  min-width: 0;
}

.market-card-title-row {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.market-card-title {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
}

.market-cat-tag {
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--bg-surface);
  color: var(--text-secondary);
  font-size: 11px;
  font-weight: 500;
}

.market-card-desc {
  margin: 3px 0 0;
  font-size: 12.5px;
  color: var(--text-secondary);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.market-card-action {
  flex-shrink: 0;
}

.market-btn {
  min-width: 68px;
  height: 32px;
  padding: 0 12px;
  border-radius: 999px;
  font-size: 12.5px;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  transition: background 0.15s ease, border-color 0.15s ease, opacity 0.15s ease;
}

.market-btn-install {
  border: none;
  background: var(--btn-primary-bg);
  color: var(--btn-primary-text);
}

.market-btn-install:hover:not(:disabled) {
  background: var(--btn-primary-hover);
}

.market-btn-installed {
  border: 1px solid var(--border-medium);
  background: transparent;
  color: var(--text-secondary);
}

.market-btn-installed:hover:not(:disabled) {
  border-color: var(--danger);
  color: var(--danger);
  background: var(--danger-soft);
}

.market-btn-required {
  border: 1px solid var(--border-subtle);
  background: var(--bg-surface);
  color: var(--text-muted);
  cursor: default;
}

.market-btn:disabled {
  opacity: 0.72;
  cursor: not-allowed;
}

.btn-spinner {
  width: 13px;
  height: 13px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

/* Server URL Modal */
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

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

.field-input {
  width: 100%;
  height: 44px;
  padding: 0 13px;
  border-radius: 11px;
  border: 1px solid var(--border-medium);
  background: var(--bg-surface);
  font-size: 14px;
  color: var(--text-primary);
  outline: none;
}

.field-input:focus {
  background: var(--bg-page);
  border-color: var(--accent-bright);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.server-tip {
  margin: 10px 0 0;
  font-size: 12.5px;
  line-height: 1.5;
  color: var(--text-secondary);
}

.server-test-result {
  margin-top: 12px;
  padding: 9px 12px;
  border-radius: 10px;
  font-size: 12.5px;
  line-height: 1.45;
}

.server-test-result.ok {
  background: var(--success-soft);
  color: var(--success);
}

.server-test-result.err {
  background: var(--danger-soft);
  color: var(--danger);
}

.server-actions {
  margin-top: 16px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

.btn {
  height: 38px;
  padding: 0 14px;
  border-radius: 10px;
  font-size: 13.5px;
  font-weight: 500;
  border: 1px solid transparent;
  transition: background 0.15s ease, opacity 0.15s ease;
}

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

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

.btn-secondary {
  background: var(--bg-surface);
  border-color: var(--border-subtle);
  color: var(--text-primary);
}

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

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
}

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

/* ==================== Fullscreen Image Lightbox ==================== */
.modal.lightbox-modal {
  background: rgba(0, 0, 0, 0.9);
  align-items: center;
  justify-content: center;
  padding: max(20px, env(safe-area-inset-top)) 12px max(20px, env(safe-area-inset-bottom));
  z-index: 80;
}

.lightbox-close-btn {
  position: fixed;
  top: max(16px, env(safe-area-inset-top));
  right: 16px;
  width: 38px;
  height: 38px;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.16);
  color: #ffffff;
  font-size: 24px;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  z-index: 82;
  backdrop-filter: blur(8px);
  transition: background 0.15s ease, transform 0.12s ease;
}

.lightbox-close-btn:hover {
  background: rgba(255, 255, 255, 0.28);
}

.lightbox-close-btn:active {
  transform: scale(0.94);
}

.lightbox-stage {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
}

.lightbox-img {
  max-width: 94vw;
  max-height: 84vh;
  object-fit: contain;
  border-radius: 8px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.55);
  user-select: none;
  -webkit-user-select: none;
}

.lightbox-caption {
  max-width: 90vw;
  padding: 4px 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
  color: rgba(255, 255, 255, 0.92);
  font-size: 12.5px;
  line-height: 1.4;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ==================== Toast ==================== */
.toast-container {
  position: fixed;
  top: calc(16px + env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  z-index: 90;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
  max-width: calc(100vw - 32px);
}

.toast {
  padding: 9px 16px;
  border-radius: 999px;
  background: var(--text-primary);
  color: var(--bg-page);
  font-size: 13px;
  font-weight: 500;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.16);
  animation: fadeInDown 0.18s var(--ease-out);
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes fadeInDown {
  from { opacity: 0; transform: translateY(-6px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes popIn {
  from { opacity: 0; transform: scale(0.97); }
  to { opacity: 1; transform: scale(1); }
}

@keyframes slideRight {
  from { transform: translateX(-100%); }
  to { transform: translateX(0); }
}

@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

@media (max-width: 640px) {
  .login-input,
  .composer-input,
  .field-input,
  .drawer-search-input,
  .market-search-input {
    font-size: 16px;
  }
}

