/* ── Reset & base ─────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --primary: #4f46e5;
  --primary-dark: #3730a3;
  --bg: #0f0f1a;
  --surface: #1a1a2e;
  --surface2: #252540;
  --text: #e2e8f0;
  --text-muted: #94a3b8;
  --user-bubble: #4f46e5;
  --model-bubble: #1e293b;
  --error: #ef4444;
  --success: #22c55e;
  --border: #334155;
  --radius: 12px;
  --radius-sm: 8px;
  font-size: 16px;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  line-height: 1.5;
}

#app {
  height: 100%;
  display: flex;
  flex-direction: column;
}

/* ── Screens ──────────────────────────────────────────────────────────────── */
.screen { flex: 1; display: flex; flex-direction: column; height: 100%; }
.hidden { display: none !important; }

/* ── Login ────────────────────────────────────────────────────────────────── */
#login-screen {
  align-items: center;
  justify-content: center;
  padding: calc(24px + env(safe-area-inset-top)) 24px calc(24px + env(safe-area-inset-bottom));
  background: var(--bg);
}

.login-card {
  width: 100%;
  max-width: 360px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 36px 28px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  text-align: center;
}

.logo { font-size: 48px; }

.login-card h1 {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text);
}

.subtitle { color: var(--text-muted); font-size: 0.9rem; }

.login-card input {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  color: var(--text);
  font-size: 1rem;
  outline: none;
  transition: border-color 0.2s;
}
.login-card input:focus { border-color: var(--primary); }
.login-card input::placeholder { color: var(--text-muted); }

.login-card button {
  background: var(--primary);
  border: none;
  border-radius: var(--radius-sm);
  padding: 13px;
  color: #fff;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}
.login-card button:hover { background: var(--primary-dark); }
.login-card button:disabled { opacity: 0.5; cursor: not-allowed; }

.error {
  color: var(--error);
  font-size: 0.875rem;
  text-align: center;
}

/* ── Chat header ──────────────────────────────────────────────────────────── */
.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  /* 顶部 safe area：在 standalone PWA 下避免与状态栏重叠 */
  padding: calc(12px + env(safe-area-inset-top)) 16px 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.header-left { display: flex; align-items: center; gap: 10px; }
.header-icon { font-size: 1.25rem; }
.header-title { font-weight: 600; font-size: 1rem; }
.header-right { display: flex; gap: 8px; }

.icon-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  cursor: pointer;
  font-size: 1rem;
  color: var(--text);
  transition: background 0.2s;
}
.icon-btn:hover { background: var(--surface2); }

/* ── Messages ─────────────────────────────────────────────────────────────── */
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: smooth;
}

.message {
  max-width: 78%;
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 0.95rem;
  line-height: 1.6;
  word-break: break-word;
  white-space: pre-wrap;
}

.message.user {
  align-self: flex-end;
  background: var(--user-bubble);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.message.model {
  align-self: flex-start;
  background: var(--model-bubble);
  color: var(--text);
  border-bottom-left-radius: 4px;
  border: 1px solid var(--border);
}

.message b  { font-weight: 700; }
.message i  { font-style: italic; color: var(--text-muted); }
.message code {
  background: rgba(255,255,255,0.1);
  border-radius: 4px;
  padding: 2px 5px;
  font-family: monospace;
  font-size: 0.875em;
}

.message.thinking {
  align-self: flex-start;
  background: var(--model-bubble);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-style: italic;
}

/* ── Input area ───────────────────────────────────────────────────────────── */
.input-area {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 12px 16px;
  padding-bottom: max(12px, env(safe-area-inset-bottom));
  background: var(--surface);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

#message-input {
  flex: 1;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  color: var(--text);
  font-size: 0.95rem;
  font-family: inherit;
  resize: none;
  outline: none;
  max-height: 120px;
  overflow-y: auto;
  line-height: 1.5;
  transition: border-color 0.2s;
}
#message-input:focus { border-color: var(--primary); }
#message-input::placeholder { color: var(--text-muted); }

.send-btn {
  width: 42px;
  height: 42px;
  background: var(--primary);
  border: none;
  border-radius: var(--radius-sm);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.2s;
}
.send-btn:hover { background: var(--primary-dark); }
.send-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.send-btn svg { width: 18px; height: 18px; }

/* ── Transaction modal ────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 100;
  animation: fadeIn 0.15s ease;
}

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

.modal-card {
  width: 100%;
  max-width: 480px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 24px 20px;
  padding-bottom: max(24px, env(safe-area-inset-bottom));
  animation: slideUp 0.2s ease;
}

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

.modal-card h3 {
  font-size: 1.1rem;
  font-weight: 700;
  margin-bottom: 16px;
  color: var(--text);
}

.txn-row {
  display: flex;
  justify-content: space-between;
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}
.txn-row:last-of-type { border-bottom: none; }
.txn-label { color: var(--text-muted); }
.txn-value { color: var(--text); font-weight: 500; }
.txn-amount { color: #f59e0b; font-size: 1.1rem; font-weight: 700; }

.acc-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 14px 0;
}

.acc-btn {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 7px 12px;
  color: var(--text);
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.15s;
}
.acc-btn:hover { border-color: var(--primary); }
.acc-btn.selected {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.action-row {
  display: flex;
  gap: 10px;
  margin-top: 16px;
}

.btn-confirm {
  flex: 1;
  background: var(--primary);
  border: none;
  border-radius: var(--radius-sm);
  padding: 12px;
  color: #fff;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}
.btn-confirm:hover { background: var(--primary-dark); }

.btn-cancel {
  flex: 0 0 auto;
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 20px;
  color: var(--text-muted);
  font-size: 1rem;
  cursor: pointer;
  transition: border-color 0.2s;
}
.btn-cancel:hover { border-color: var(--error); color: var(--error); }

/* ── Scrollbar ────────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
