@import url("https://fonts.googleapis.com/css2?family=Noto+Sans+SC:wght@400;500;600;700&display=swap");

:root {
  --bg: #e8eef0;
  --panel: #ffffff;
  --ink: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --accent: #0f766e;
  --accent-dark: #115e59;
  --accent-soft: #ccfbf1;
  --danger: #b91c1c;
  --danger-bg: #fef2f2;
  --warn-bg: #fff7ed;
  --warn-ink: #9a3412;
  --inbound: #ffffff;
  --outbound: #d1fae5;
  --shadow: 0 10px 30px rgba(15, 23, 42, 0.08);
  --radius: 16px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: "Noto Sans SC", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", system-ui, sans-serif;
  color: var(--ink);
  background: var(--bg);
}

.hidden { display: none !important; }
button, input, textarea { font: inherit; }
button { cursor: pointer; }

.login-view {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(1200px 400px at 10% -10%, #99f6e4 0%, transparent 50%),
    radial-gradient(800px 300px at 100% 0%, #bae6fd 0%, transparent 45%),
    var(--bg);
}
.login-card {
  width: min(420px, 100%);
  background: var(--panel);
  border-radius: 24px;
  padding: 32px 28px 28px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.brand-mark {
  width: 52px; height: 52px;
  border-radius: 16px;
  background: linear-gradient(135deg, #0f766e, #0e7490);
  color: white;
  display: grid; place-items: center;
  font-weight: 700; letter-spacing: 0.02em;
}
.login-card h1 { margin: 8px 0 0; font-size: 24px; }
.login-sub { margin: 0 0 8px; color: var(--muted); line-height: 1.5; }
.login-card label { font-size: 13px; color: var(--muted); }
.login-card input, .composer textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
  background: #f8fafc;
  outline: none;
}
.login-card input:focus, .composer textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.15);
  background: #fff;
}
.login-card button, .primary-btn {
  border: 0;
  background: var(--accent);
  color: white;
  border-radius: 12px;
  padding: 12px 16px;
  font-weight: 600;
}
.login-card button:hover, .primary-btn:hover { background: var(--accent-dark); }
.login-card button:disabled, .primary-btn:disabled, .secondary-btn:disabled {
  opacity: 0.55; cursor: not-allowed;
}
.form-error { color: var(--danger); margin: 0; font-size: 13px; }

.app-view {
  height: 100%;
  display: grid;
  grid-template-columns: 340px 1fr;
  background: var(--bg);
}

.sidebar {
  background: var(--panel);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.sidebar-header {
  padding: calc(16px + var(--safe-top)) 16px 12px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  border-bottom: 1px solid var(--line);
}
.sidebar-header h1 { margin: 0; font-size: 18px; }
.account-line { margin: 4px 0 0; color: var(--muted); font-size: 12px; }
.ghost-btn, .back-btn, .secondary-btn {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 10px;
  padding: 8px 10px;
  color: var(--ink);
}
.ghost-btn:hover, .back-btn:hover, .secondary-btn:hover { background: #f8fafc; }

.conversation-list { overflow: auto; flex: 1; }
.conversation {
  width: 100%;
  text-align: left;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: transparent;
  padding: 14px 16px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px 12px;
}
.conversation:hover { background: #f8fafc; }
.conversation.active { background: var(--accent-soft); }
.conv-name { font-weight: 600; }
.conv-time { color: var(--muted); font-size: 12px; }
.conv-preview {
  grid-column: 1 / -1;
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin: 0;
}
.badge {
  background: #dc2626;
  color: white;
  border-radius: 999px;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  font-size: 11px;
  font-weight: 700;
  display: inline-grid;
  place-items: center;
}
.empty-hint { padding: 24px 16px; color: var(--muted); line-height: 1.6; }

.chat {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background:
    linear-gradient(180deg, rgba(15, 118, 110, 0.05), transparent 120px),
    #f7faf9;
}
.chat-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: calc(12px + var(--safe-top)) 16px 12px;
  background: rgba(255,255,255,0.9);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.back-btn { display: none; width: 36px; height: 36px; font-size: 22px; line-height: 1; }
.chat-title h2 { margin: 0; font-size: 16px; }
.chat-meta { margin: 2px 0 0; color: var(--muted); font-size: 12px; }

.window-banner {
  margin: 12px 16px 0;
  background: var(--warn-bg);
  color: var(--warn-ink);
  border: 1px solid #fdba74;
  border-radius: 12px;
  padding: 10px 12px;
  font-size: 13px;
  line-height: 1.5;
}

.message-list {
  flex: 1;
  overflow: auto;
  padding: 16px 16px 24px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.empty-chat {
  margin: auto;
  color: var(--muted);
  padding: 24px;
}
.bubble-row { display: flex; }
.bubble-row.inbound { justify-content: flex-start; }
.bubble-row.outbound { justify-content: flex-end; }
.bubble {
  max-width: min(720px, 86%);
  border-radius: 16px;
  padding: 10px 12px;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.06);
}
.bubble-row.inbound .bubble { background: var(--inbound); border: 1px solid var(--line); }
.bubble-row.outbound .bubble { background: var(--outbound); }
.msg-main { margin: 0; line-height: 1.55; white-space: pre-wrap; word-break: break-word; }
.msg-original, .msg-meta {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
}
.msg-meta { margin-top: 8px; display: flex; gap: 8px; justify-content: flex-end; }

.composer {
  border-top: 1px solid var(--line);
  background: var(--panel);
  padding: 12px 16px calc(12px + var(--safe-bottom));
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.preview-box {
  background: #f0fdfa;
  border: 1px solid #99f6e4;
  border-radius: 12px;
  padding: 10px 12px;
}
.preview-label { font-size: 12px; color: var(--accent-dark); font-weight: 600; }
.preview-text { margin-top: 4px; white-space: pre-wrap; }
.composer textarea { resize: vertical; min-height: 72px; }
.composer-actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }

@media (max-width: 800px) {
  .app-view { grid-template-columns: 1fr; }
  .back-btn { display: inline-grid; place-items: center; }
  .app-view.show-chat .sidebar { display: none; }
  .app-view:not(.show-chat) .chat { display: none; }
  .bubble { max-width: 92%; }
}
