/* ═══════════════════════════════════════════
   AI Chat — 联合文社
   MONO Design: 0圆角 · 1px边框 · 无投影 · 无渐变
   ═══════════════════════════════════════════ */

/* ── AI Page Layout ── */
.ai-layout {
  display: flex;
  height: calc(100vh - var(--nav-height));
  margin-top: var(--nav-height);
  overflow: hidden;
}

/* ── Sidebar ── */
.ai-sidebar {
  width: 280px;
  min-width: 280px;
  background: var(--ui-surface);
  border-right: var(--ui-border) solid var(--ui-line);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: transform .25s cubic-bezier(.16,1,.3,1);
}
.ai-sidebar-header {
  padding: 20px;
  border-bottom: var(--ui-border) solid var(--ui-line);
  font-family: var(--font-mono);
  font-size: .72rem;
  font-weight: 600;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--ui-fg);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.ai-sidebar-header i { font-size: .9rem; }
.ai-sidebar-body {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
}
.ai-new-chat-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 10px 14px;
  background: var(--ui-bg);
  border: var(--ui-border) solid var(--ui-line);
  color: var(--ui-fg);
  font-family: var(--font-mono);
  font-size: .72rem;
  letter-spacing: .06em;
  cursor: pointer;
  transition: all var(--dur-fast) var(--ease-out);
  margin-bottom: 16px;
}
.ai-new-chat-btn:hover {
  border-color: var(--ui-line-hover);
  background: var(--ui-surface-2);
}

/* Sessions List */
.ai-sessions-label {
  font-family: var(--font-mono);
  font-size: .6rem;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--ui-fg-muted);
  padding: 8px 6px;
  margin-bottom: 4px;
  opacity: .5;
}
.ai-session-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  font-size: .78rem;
  color: var(--ui-fg-muted);
  cursor: pointer;
  border: var(--ui-border) solid transparent;
  transition: all var(--dur-fast) var(--ease-out);
  gap: 8px;
}
.ai-session-item:hover {
  background: var(--ui-surface-2);
  border-color: var(--ui-line-strong);
  color: var(--ui-fg);
}
.ai-session-item.active {
  background: var(--ui-surface-2);
  border-color: var(--ui-accent);
  color: var(--ui-accent);
}
.ai-session-info {
  flex: 1;
  min-width: 0;
  overflow: hidden;
}
.ai-session-title {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-weight: 500;
  margin-bottom: 2px;
}
.ai-session-role {
  font-size: .65rem;
  font-family: var(--font-mono);
  letter-spacing: .04em;
  opacity: .6;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ai-session-delete {
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: var(--ui-border) solid transparent;
  color: var(--ui-fg-muted);
  cursor: pointer;
  font-size: .65rem;
  opacity: 0;
  transition: all var(--dur-fast) var(--ease-out);
}
.ai-session-item:hover .ai-session-delete { opacity: .6; }
.ai-session-delete:hover { color: #f87171; border-color: rgba(248,113,113,.3); opacity: 1; }

/* ── Main Chat Area ── */
.ai-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
}

/* Role Selection */
.ai-role-select {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--gap-xl);
  overflow-y: auto;
}
.ai-role-select-label {
  font-family: var(--font-mono);
  font-size: .65rem;
  letter-spacing: .16em;
  text-transform: uppercase;
  color: var(--ui-fg-muted);
  margin-bottom: var(--gap-sm);
}
.ai-role-select-title {
  font-family: var(--font-serif);
  font-size: clamp(1.25rem, 3vw, 1.75rem);
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-bottom: var(--gap-xl);
}
.ai-roles-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: var(--gap-sm);
  max-width: 800px;
  width: 100%;
}
.ai-role-card {
  background: var(--ui-surface);
  border: var(--ui-border) solid var(--ui-line);
  padding: var(--gap-lg);
  cursor: pointer;
  transition: all var(--dur-fast) var(--ease-out);
  transform: translateY(0);
}
.ai-role-card:hover {
  border-color: var(--ui-line-hover);
  transform: translateY(-2px);
}
.ai-role-card-icon {
  font-size: 1.25rem;
  margin-bottom: var(--gap-sm);
  color: var(--ui-fg);
}
.ai-role-card h4 {
  font-size: .9rem;
  font-weight: 600;
  margin-bottom: 4px;
  letter-spacing: -0.01em;
}
.ai-role-card p {
  font-size: .72rem;
  color: var(--ui-fg-muted);
  margin-bottom: 0;
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* Chat Interface */
.ai-chat-interface {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.ai-chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  border-bottom: var(--ui-border) solid var(--ui-line);
  background: var(--ui-surface);
  gap: 12px;
}
.ai-chat-header-left {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}
.ai-chat-header-icon {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: var(--ui-border) solid var(--ui-line);
  font-size: .85rem;
  flex-shrink: 0;
}
.ai-chat-header-name {
  font-size: .88rem;
  font-weight: 600;
  color: var(--ui-fg);
}
.ai-chat-header-desc {
  font-size: .68rem;
  color: var(--ui-fg-muted);
  font-family: var(--font-mono);
  letter-spacing: .04em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Messages */
.ai-messages {
  flex: 1;
  overflow-y: auto;
  padding: var(--gap-lg);
  display: flex;
  flex-direction: column;
  gap: var(--gap-md);
  scroll-behavior: smooth;
}
.ai-message {
  display: flex;
  gap: 10px;
  width: fit-content;
  max-width: 85%;
  min-width: 0;
  align-items: flex-end;
  animation: aiMsgIn .25s cubic-bezier(.16,1,.3,1) both;
}
.ai-message.ai-user {
  margin-left: auto;
  margin-right: 0;
  flex-direction: row-reverse;
}
.ai-message.ai-assistant {
  margin-right: auto;
  margin-left: 0;
}
.ai-msg-avatar {
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: var(--ui-border) solid var(--ui-line);
  font-size: .75rem;
  flex-shrink: 0;
  color: var(--ui-fg-muted);
  align-self: flex-end;
}
.ai-message.ai-user .ai-msg-avatar {
  background: var(--ui-accent);
  color: var(--ui-bg);
  border-color: var(--ui-accent);
}
.ai-msg-content {
  padding: 12px 16px;
  border: var(--ui-border) solid var(--ui-line);
  font-size: .85rem;
  line-height: 1.7;
  word-wrap: break-word;
  overflow-wrap: break-word;
  word-break: break-word;
  white-space: pre-wrap;
  background: var(--ui-surface);
  color: var(--ui-fg);
  min-width: 0;
}
.ai-message.ai-user .ai-msg-content {
  background: var(--ui-accent);
  color: var(--ui-bg);
  border-color: var(--ui-accent);
}

/* ── Breathing Skeleton (等待AI回复时的呼吸条) ── */
.ai-breath-skeleton {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px 16px;
  border: var(--ui-border) solid var(--ui-line);
  background: var(--ui-surface);
  max-width: 85%;
  align-self: flex-start;
}
.ai-breath-bar {
  height: 10px;
  background: var(--ui-surface-2);
  border: var(--ui-border) solid var(--ui-line);
  animation: aiBreathPulse 1.5s ease-in-out infinite;
}
.ai-breath-bar:nth-child(1) { width: 100%; animation-delay: 0s; }
.ai-breath-bar:nth-child(2) { width: 75%; animation-delay: .15s; }
.ai-breath-bar:nth-child(3) { width: 55%; animation-delay: .3s; }
.ai-breath-bar:nth-child(4) { width: 85%; animation-delay: .45s; }

@keyframes aiBreathPulse {
  0%, 100% { opacity: .25; }
  50% { opacity: .7; }
}

/* ── Typewriter Cursor ── */
.ai-typing-cursor {
  display: inline-block;
  width: 1px;
  height: 1.1em;
  background: var(--ui-fg);
  margin-left: 1px;
  vertical-align: text-bottom;
  animation: aiCursorBlink .8s step-end infinite;
}
@keyframes aiCursorBlink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0; }
}

/* Error message */
.ai-msg-error {
  background: rgba(248,113,113,.06) !important;
  border-color: rgba(248,113,113,.3) !important;
  color: #f87171 !important;
}

/* ── Input Area ── */
.ai-chat-input {
  padding: 16px 24px;
  border-top: var(--ui-border) solid var(--ui-line);
  background: var(--ui-surface);
}
.ai-input-wrap {
  display: flex;
  gap: 10px;
  align-items: flex-end;
}
.ai-input-wrap textarea {
  flex: 1;
  padding: 10px 14px;
  background: var(--ui-bg);
  color: var(--ui-fg);
  border: var(--ui-border) solid var(--ui-line);
  font-family: var(--font-sans);
  font-size: .85rem;
  line-height: 1.5;
  resize: none;
  min-height: 44px;
  max-height: 120px;
  transition: border-color var(--dur-fast) var(--ease-out),
              background var(--dur-fast) var(--ease-out);
  cursor: var(--cursor-text);
}
.ai-input-wrap textarea:focus {
  outline: none;
  border-color: var(--ui-fg);
  background: var(--ui-bg);
}
.ai-input-wrap textarea::placeholder {
  color: var(--ui-fg-muted);
}
.ai-send-btn {
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--ui-accent);
  border: var(--ui-border) solid var(--ui-accent);
  color: var(--ui-bg);
  font-size: .95rem;
  cursor: pointer;
  transition: all var(--dur-fast) var(--ease-out);
  flex-shrink: 0;
}
.ai-send-btn:hover {
  background: var(--ui-accent-hover);
  border-color: var(--ui-accent-hover);
}
.ai-send-btn:disabled {
  opacity: .3;
  pointer-events: none;
}

/* ── Welcome State ── */
.ai-welcome {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--gap-xl);
  text-align: center;
}
.ai-welcome-icon {
  width: 64px;
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: var(--ui-border) solid var(--ui-line);
  margin-bottom: var(--gap-lg);
  font-size: 1.5rem;
  position: relative;
}
.ai-welcome-icon::before {
  content: '';
  position: absolute;
  top: -4px; left: -4px;
  width: 12px; height: 12px;
  border-top: 2px solid var(--ui-fg);
  border-left: 2px solid var(--ui-fg);
}
.ai-welcome-icon::after {
  content: '';
  position: absolute;
  bottom: -4px; right: -4px;
  width: 12px; height: 12px;
  border-bottom: 2px solid var(--ui-fg);
  border-right: 2px solid var(--ui-fg);
}
.ai-welcome-label {
  font-family: var(--font-mono);
  font-size: .65rem;
  letter-spacing: .16em;
  text-transform: uppercase;
  color: var(--ui-fg-muted);
  margin-bottom: var(--gap-sm);
}
.ai-welcome-title {
  font-family: var(--font-serif);
  font-size: clamp(1.25rem, 3vw, 1.75rem);
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-bottom: var(--gap-sm);
}
.ai-welcome-desc {
  font-size: .85rem;
  color: var(--ui-fg-muted);
  max-width: 400px;
  line-height: 1.7;
}

/* ── Empty Sessions ── */
.ai-empty-sessions {
  text-align: center;
  padding: var(--gap-lg);
  color: var(--ui-fg-muted);
  font-size: .7rem;
  font-family: var(--font-mono);
  letter-spacing: .06em;
  opacity: .5;
}

/* ── Responsive ── */
@media (max-width: 768px) {
  .ai-layout { flex-direction: column; }
  .ai-sidebar {
    width: 100%;
    min-width: 100%;
    max-height: 40vh;
    border-right: none;
    border-bottom: var(--ui-border) solid var(--ui-line);
    position: relative;
    transition: max-height .25s cubic-bezier(.16,1,.3,1);
  }
  .ai-sidebar.collapsed { max-height: 52px; overflow: hidden; }
  .ai-sidebar-header { cursor: pointer; }
  .ai-main { height: 0; flex: 1; }
  .ai-messages { padding: var(--gap-md); gap: var(--gap-sm); }
  .ai-message { max-width: 90%; }
  .ai-msg-content { padding: 10px 14px; font-size: .8rem; }
  .ai-chat-header { padding: 12px 16px; }
  .ai-chat-input { padding: 12px 16px; }
  .ai-roles-grid { grid-template-columns: 1fr; max-width: 100%; }
  .ai-role-card { padding: var(--gap-md); }
  .ai-breath-skeleton { max-width: 90%; }
}

@media (max-width: 480px) {
  .ai-message { max-width: 95%; }
  .ai-msg-content { padding: 8px 12px; font-size: .78rem; }
  .ai-messages { padding: var(--gap-sm); }
  .ai-chat-input { padding: 10px 12px; }
  .ai-input-wrap textarea { min-height: 38px; font-size: .8rem; }
  .ai-send-btn { width: 38px; height: 38px; }
}
