/* 主布局与对话 - 使用设计令牌 */
@import url('variables.css');

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font-sans);
  background: var(--color-bg);
  height: 100vh;
  overflow: hidden;
  color: var(--color-text);
}

.app-layout {
  display: flex;
  height: 100vh;
}

/* ========== 侧边栏 ========== */
.sidebar {
  width: 272px;
  min-width: 272px;
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--sidebar-border);
  transition: transform var(--transition-smooth), box-shadow var(--transition-smooth);
}

.sidebar-header {
  padding: 18px 14px;
  flex-shrink: 0;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
}

.logo-icon {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-lg);
  background: linear-gradient(135deg, var(--color-primary) 0%, #0f766e 100%);
  color: #fff;
  font-weight: 700;
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-shadow: 0 2px 8px rgba(13, 148, 136, 0.3);
}

.logo-text {
  font-size: var(--text-lg);
  font-weight: 600;
  color: var(--sidebar-text);
}

.btn-new-chat {
  width: 100%;
  padding: 12px 14px;
  background: var(--color-primary);
  color: #fff;
  border: none;
  border-radius: var(--radius-md);
  font-size: var(--text-base);
  font-weight: 500;
  cursor: pointer;
  font-family: inherit;
  text-decoration: none;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: background var(--transition-base), transform 0.1s ease;
}

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

.btn-new-chat:active {
  transform: scale(0.98);
}

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 18px;
  color: var(--sidebar-text);
  text-decoration: none;
  font-size: var(--text-base);
  border-radius: var(--radius-md);
  margin: 0 10px;
  transition: background var(--transition-fast), color var(--transition-fast);
}

.nav-item:hover {
  background: var(--sidebar-hover);
  color: var(--color-text);
}

.nav-item.active {
  background: var(--sidebar-active-bg);
  color: var(--sidebar-active-text);
  font-weight: 500;
}

.nav-icon {
  font-size: 18px;
  opacity: 0.9;
}

.nav-section {
  margin-top: 12px;
}

.nav-section-title {
  display: block;
  padding: 8px 18px 6px;
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.session-list {
  padding: 0 10px 10px;
}

.session-item {
  padding: 10px 14px;
  cursor: pointer;
  font-size: var(--text-base);
  color: var(--color-text);
  border-radius: var(--radius-md);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 2px;
  transition: background var(--transition-fast);
}

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

.session-item.active {
  background: var(--sidebar-active-bg);
  color: var(--sidebar-active-text);
}

.session-item .session-del {
  padding: 4px 8px;
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  border: none;
  background: none;
  cursor: pointer;
  flex-shrink: 0;
  border-radius: var(--radius-sm);
  transition: color var(--transition-fast), background var(--transition-fast);
}

.session-item .session-del:hover {
  color: var(--color-error);
  background: var(--color-error-bg);
}

.sidebar-footer {
  padding: 14px 18px;
  border-top: 1px solid var(--sidebar-border);
  flex-shrink: 0;
}

.footer-row {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  margin-bottom: 8px;
}

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

.footer-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--color-primary-light) 0%, var(--color-accent-light) 100%);
  color: var(--color-primary);
  font-size: var(--text-sm);
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
}

.footer-username {
  font-size: var(--text-sm);
  color: var(--color-text);
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.footer-logout {
  display: block;
  margin-top: 8px;
  font-size: var(--text-sm);
  color: var(--color-primary);
  text-decoration: none;
  transition: color var(--transition-fast);
}

.footer-logout:hover {
  color: var(--color-primary-hover);
  text-decoration: underline;
}

/* ========== 主区域 ========== */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--color-bg);
}

.main-header {
  padding: 14px 22px;
  background: var(--color-bg-elevated);
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  gap: 14px;
  flex-shrink: 0;
}

/* Agent 切换器：自定义下拉，替代原生 select */
.agent-switcher {
  position: relative;
}

.agent-switcher-trigger {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  font-size: var(--text-base);
  font-family: inherit;
  background: var(--color-bg-elevated);
  color: var(--color-text);
  cursor: pointer;
  min-width: 180px;
  max-width: 260px;
  transition: border-color var(--transition-base), box-shadow var(--transition-base), background var(--transition-fast);
}

.agent-switcher-trigger:hover {
  border-color: var(--color-primary-border);
  background: #fff;
  box-shadow: 0 2px 8px rgba(13, 148, 136, 0.1);
}

.agent-switcher-trigger:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: var(--shadow-focus);
}

.agent-switcher-icon {
  width: 28px;
  height: 28px;
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, var(--color-primary-light) 0%, var(--color-accent-light) 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  flex-shrink: 0;
}

.agent-switcher-label {
  flex: 1;
  text-align: left;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.agent-switcher-chevron {
  font-size: 10px;
  color: var(--color-text-muted);
  transition: transform var(--transition-base);
  flex-shrink: 0;
}

.agent-switcher.open .agent-switcher-chevron {
  transform: rotate(180deg);
}

.agent-switcher-dropdown {
  position: absolute;
  left: 0;
  top: calc(100% + 6px);
  min-width: 100%;
  background: var(--color-bg-elevated);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  z-index: 50;
  padding: 6px 0;
  max-height: 280px;
  overflow-y: auto;
  display: none;
}

.agent-switcher.open .agent-switcher-dropdown {
  display: block;
}

.agent-switcher-item {
  padding: 12px 16px;
  font-size: var(--text-base);
  color: var(--color-text);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 10px;
  transition: background var(--transition-fast);
}

.agent-switcher-item:hover {
  background: var(--color-primary-light);
}

.agent-switcher-item.selected {
  background: var(--color-primary-light);
  color: var(--color-primary);
  font-weight: 500;
}

.agent-switcher-item::before {
  content: '🤖';
  font-size: 16px;
}

.header-settings {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  color: var(--color-primary);
  text-decoration: none;
  font-size: 20px;
  border-radius: var(--radius-md);
  margin-left: auto;
  transition: background var(--transition-fast), color var(--transition-fast);
}

.header-settings:hover {
  background: var(--color-primary-light);
}

.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

/* ========== 欢迎视图 ========== */
.welcome-view {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding: 48px 24px 28px;
}

.welcome-greeting {
  font-size: var(--text-hero);
  font-weight: 700;
  color: var(--color-text);
  margin: 0 0 36px;
  text-align: center;
  letter-spacing: -0.02em;
  line-height: 1.3;
}

.input-block {
  width: 100%;
  max-width: 720px;
}

.input-wrapper {
  position: relative;
  display: flex;
  align-items: flex-end;
  background: var(--color-bg-elevated);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-xl);
  padding: 14px 18px;
  min-height: 58px;
  transition: border-color var(--transition-base), box-shadow var(--transition-base);
}

.input-wrapper:focus-within {
  border-color: var(--color-primary);
  box-shadow: var(--shadow-focus);
}

.input-wrapper textarea {
  flex: 1;
  border: none;
  outline: none;
  resize: none;
  font-size: var(--text-md);
  font-family: inherit;
  min-height: 32px;
  max-height: 120px;
  padding: 0;
  margin: 0 10px 0 0;
  color: var(--color-text);
}

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

.input-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-right: 8px;
}

.input-action-btn {
  width: 36px;
  height: 36px;
  border: none;
  background: none;
  color: var(--color-text-muted);
  font-size: 15px;
  cursor: pointer;
  border-radius: var(--radius-md);
  transition: background var(--transition-fast), color var(--transition-fast);
}

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

.input-send {
  width: 40px;
  height: 40px;
  border: none;
  background: var(--color-primary);
  color: #fff;
  border-radius: var(--radius-lg);
  font-size: 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition-base), transform 0.1s ease;
}

.input-send:hover {
  background: var(--color-primary-hover);
}

.input-send:active {
  transform: scale(0.95);
}

.tool-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 14px;
  justify-content: center;
}

.tool-btn {
  padding: 9px 18px;
  border: 1px solid var(--color-border);
  background: var(--color-bg-elevated);
  color: var(--color-text-secondary);
  border-radius: var(--radius-full);
  font-size: var(--text-sm);
  font-family: inherit;
  cursor: pointer;
  transition: background var(--transition-fast), border-color var(--transition-fast), color var(--transition-fast);
}

.tool-btn:hover {
  background: var(--color-surface);
  border-color: var(--color-border-strong);
  color: var(--color-text);
}

.suggestions {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 14px;
  width: 100%;
  max-width: 720px;
  margin-top: 32px;
}

.suggestion-card {
  background: var(--color-bg-elevated);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 18px 18px;
  font-size: var(--text-base);
  color: var(--color-text);
  line-height: 1.45;
  display: flex;
  flex-direction: column;
  gap: 12px;
  transition: border-color var(--transition-base), box-shadow var(--transition-base), transform 0.15s ease;
}

.suggestion-card:hover {
  border-color: var(--color-primary-border);
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}

.suggestion-btn {
  align-self: flex-start;
  padding: 6px 14px;
  font-size: var(--text-sm);
  color: var(--color-primary);
  background: var(--color-primary-light);
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  font-family: inherit;
  font-weight: 500;
  transition: background var(--transition-fast), color var(--transition-fast);
}

.suggestion-btn:hover {
  background: var(--color-primary);
  color: #fff;
}

/* ========== 对话视图 ========== */
.chat-view {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.chat-view .messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.msg {
  max-width: 85%;
  padding: 14px 18px;
  border-radius: var(--radius-lg);
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: var(--text-base);
  transition: box-shadow var(--transition-fast);
}

.msg.user {
  align-self: flex-end;
  background: var(--color-primary);
  color: #fff;
  box-shadow: 0 2px 8px rgba(13, 148, 136, 0.25);
}

.msg.assistant {
  align-self: flex-start;
  background: var(--color-bg-elevated);
  border: 1px solid var(--color-border);
}

.msg.error {
  align-self: flex-start;
  background: var(--color-error-bg);
  border: 1px solid rgba(220, 38, 38, 0.3);
  color: var(--color-error);
}

.msg.thinking {
  color: var(--color-text-muted);
  font-style: italic;
}

.chat-view .input-area {
  padding: 18px 20px;
  background: var(--color-bg-elevated);
  border-top: 1px solid var(--color-border);
}

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

.input-row textarea {
  flex: 1;
  min-height: 48px;
  max-height: 120px;
  padding: 14px 18px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  font-size: var(--text-base);
  font-family: inherit;
  resize: none;
  color: var(--color-text);
  transition: border-color var(--transition-base), box-shadow var(--transition-base);
}

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

.input-row textarea:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: var(--shadow-focus);
}

.input-row button {
  padding: 14px 22px;
  background: var(--color-primary);
  color: #fff;
  border: none;
  border-radius: var(--radius-lg);
  font-size: var(--text-base);
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  white-space: nowrap;
  transition: background var(--transition-base), transform 0.1s ease;
}

.input-row button:hover {
  background: var(--color-primary-hover);
}

.input-row button:active {
  transform: scale(0.98);
}

.input-row button:disabled {
  background: var(--color-text-muted);
  cursor: not-allowed;
  transform: none;
}

.empty-hint {
  color: var(--color-text-muted);
  text-align: center;
  padding: 48px 24px;
  font-size: var(--text-base);
}

/* ========== 移动端 ========== */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.4);
  z-index: 99;
  opacity: 0;
  transition: opacity var(--transition-base);
  backdrop-filter: blur(2px);
}

.sidebar-overlay.show {
  display: block;
  opacity: 1;
}

@media (min-width: 769px) {
  .sidebar-overlay { display: none !important; }
}

.btn-menu {
  display: none;
  padding: 10px 14px;
  margin: -4px 8px -4px -4px;
  background: none;
  border: none;
  font-size: 22px;
  cursor: pointer;
  color: var(--color-text);
  border-radius: var(--radius-md);
  transition: background var(--transition-fast);
}

.btn-menu:hover {
  background: var(--color-surface);
}

@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    z-index: 100;
    width: 280px;
    max-width: 85vw;
    min-width: 0;
    transform: translateX(-100%);
    transition: transform var(--transition-smooth);
    box-shadow: 8px 0 32px rgba(0, 0, 0, 0.12);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .main {
    width: 100%;
  }

  .main-header {
    flex-wrap: wrap;
    padding: 12px 14px;
  }

  .welcome-view {
    padding: 28px 16px 20px;
  }

  .welcome-greeting {
    font-size: var(--text-2xl);
    margin-bottom: 28px;
  }

  .suggestions {
    grid-template-columns: 1fr;
  }

  .chat-view .messages {
    padding: 14px;
  }

  .msg {
    max-width: 92%;
  }

  .chat-view .input-area {
    padding: 14px;
  }

  .btn-menu {
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }
}
