/* 清辞 Chat UI */

:root {
  --bg: #eef2ef;
  --bg-quiet: #e3e9e7;
  --surface: #ffffff;
  --surface-warm: #fffaf4;
  --text: #1f2d2b;
  --text-secondary: #63706d;
  --text-muted: #8a9692;
  --bubble-user: #1f8f78;
  --bubble-bot: #fffdf9;
  --bubble-system: #dfe8e5;
  --border: #d5dedb;
  --border-strong: #b7c6c1;
  --accent: #1f8f78;
  --accent-strong: #176f60;
  --accent-soft: #d9eee8;
  --warm: #d86b4f;
  --danger: #c65353;
  --danger-soft: #fff0ec;
  --body-sheen: rgba(255, 250, 244, 0.72);
  --app-bg: rgba(255, 255, 255, 0.78);
  --app-border: rgba(213, 222, 219, 0.72);
  --chrome-bg: rgba(255, 253, 249, 0.94);
  --soft-button: #e8efed;
  --focus-overlay-bg: rgba(22, 34, 31, 0.52);
  --focus-card-border: rgba(255, 255, 255, 0.68);
  --focus-progress-bg: #e2e8e5;
  --input-inset-shadow: inset 0 1px 0 rgba(31, 45, 43, 0.03);
  --user-shadow: 0 8px 22px rgba(31, 143, 120, 0.18);
  --shadow: 0 18px 42px rgba(26, 45, 40, 0.14);
  --shadow-soft: 0 1px 2px rgba(26, 45, 40, 0.08);
  --radius: 8px;
}

:root[data-theme="dark"] {
  --bg: #111816;
  --bg-quiet: #0b100f;
  --surface: #182321;
  --surface-warm: #1f2725;
  --text: #eef5f2;
  --text-secondary: #b3c1bc;
  --text-muted: #81908b;
  --bubble-user: #1f8f78;
  --bubble-bot: #17211f;
  --bubble-system: #22302d;
  --border: #2d3b38;
  --border-strong: #40524d;
  --accent: #3fc3a4;
  --accent-strong: #84dac7;
  --accent-soft: #183d36;
  --warm: #f08a69;
  --danger: #ff9b90;
  --danger-soft: #321d1d;
  --body-sheen: rgba(38, 52, 48, 0.42);
  --app-bg: rgba(16, 24, 22, 0.84);
  --app-border: rgba(64, 82, 77, 0.82);
  --chrome-bg: rgba(20, 29, 27, 0.95);
  --soft-button: #22302d;
  --focus-overlay-bg: rgba(3, 7, 6, 0.66);
  --focus-card-border: rgba(255, 255, 255, 0.08);
  --focus-progress-bg: #2d3b38;
  --input-inset-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04);
  --user-shadow: 0 8px 22px rgba(63, 195, 164, 0.16);
  --shadow: 0 18px 42px rgba(0, 0, 0, 0.34);
  --shadow-soft: 0 1px 2px rgba(0, 0, 0, 0.22);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background:
    linear-gradient(135deg, var(--body-sheen) 0 24%, transparent 24% 100%),
    linear-gradient(180deg, var(--bg) 0%, var(--bg-quiet) 100%);
  color: var(--text);
  height: 100dvh;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button,
textarea {
  font: inherit;
}

button {
  -webkit-tap-highlight-color: transparent;
}

#app {
  display: flex;
  flex-direction: column;
  height: min(100dvh, 940px);
  width: min(100%, 840px);
  margin: 0 auto;
  background: var(--app-bg);
  border-inline: 1px solid var(--app-border);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

@supports not (height: 100dvh) {
  body,
  #app {
    height: 100vh;
  }
}

/* ── Header ───────────────────── */

#header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 72px;
  padding: max(16px, env(safe-area-inset-top)) 22px 14px;
  background: var(--chrome-bg);
  border-bottom: 1px solid var(--border);
  z-index: 10;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.status-dot {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: #a6b0ad;
  box-shadow: 0 0 0 4px rgba(166, 176, 173, 0.18);
  flex: 0 0 auto;
}

.status-dot.online {
  background: var(--accent);
  box-shadow: 0 0 0 4px rgba(31, 143, 120, 0.16);
}

.title {
  font-weight: 600;
  font-size: 18px;
  line-height: 1.15;
  letter-spacing: 0;
}

.subtitle {
  margin-top: 3px;
  color: var(--text-muted);
  font-size: 12px;
  line-height: 1.2;
}

.mode-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 54px;
  min-height: 30px;
  padding: 5px 11px;
  border: 1px solid rgba(31, 143, 120, 0.22);
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-size: 13px;
  font-weight: 600;
  line-height: 1;
  white-space: nowrap;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
}

.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease, transform 0.15s ease;
}

.theme-toggle:hover {
  border-color: var(--border-strong);
  color: var(--text);
}

.theme-toggle:active {
  transform: translateY(1px);
}

/* ── Messages ─────────────────── */

#messages {
  flex: 1;
  overflow-y: auto;
  padding: 22px clamp(16px, 4vw, 34px);
  display: flex;
  flex-direction: column;
  gap: 10px;
  scroll-behavior: smooth;
  scrollbar-color: var(--border-strong) transparent;
}

#messages:empty::before {
  content: "今天从哪一句开始？";
  align-self: center;
  margin: auto 0;
  color: var(--text-muted);
  font-size: 14px;
}

#messages::-webkit-scrollbar {
  width: 10px;
}

#messages::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border: 3px solid transparent;
  border-radius: 999px;
  background-clip: content-box;
}

.message {
  max-width: min(74%, 560px);
  padding: 11px 14px;
  border-radius: 16px;
  line-height: 1.55;
  font-size: 15px;
  word-break: break-word;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
  animation: fadeIn 0.2s ease;
  box-shadow: var(--shadow-soft);
}

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

.msg-time {
  display: block;
  font-size: 10px;
  opacity: 0.5;
  margin-top: 4px;
}

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

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

.message.system {
  align-self: center;
  background: var(--bubble-system);
  color: var(--text-secondary);
  box-shadow: none;
  font-size: 12px;
  line-height: 1.45;
  max-width: min(88%, 620px);
  padding: 6px 10px;
  text-align: center;
  border-radius: 999px;
}

.message.alert {
  align-self: center;
  background: var(--danger-soft);
  border: 1px solid rgba(198, 83, 83, 0.32);
  color: var(--danger);
  font-size: 13px;
  border-radius: var(--radius);
  box-shadow: none;
  max-width: min(92%, 620px);
}

.message img {
  display: block;
  max-width: min(260px, 58vw) !important;
  height: auto;
  border-radius: var(--radius) !important;
}

/* ── Focus Overlay ────────────── */

#focusOverlay {
  position: fixed;
  inset: 0;
  background: var(--focus-overlay-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 100;
  backdrop-filter: blur(10px);
}

#focusOverlay.hidden { display: none; }

.focus-card {
  width: min(100%, 420px);
  background: var(--surface-warm);
  border: 1px solid var(--focus-card-border);
  border-radius: var(--radius);
  padding: 28px;
  text-align: center;
  box-shadow: 0 24px 70px rgba(14, 24, 22, 0.28);
}

.focus-label {
  color: var(--warm);
  font-size: 13px;
  font-weight: 700;
  line-height: 1;
  margin-bottom: 12px;
}

.focus-timer {
  font-size: 56px;
  font-weight: 650;
  letter-spacing: 0;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

.focus-task {
  min-height: 22px;
  margin: 14px auto 20px;
  color: var(--text-secondary);
  font-size: 15px;
  line-height: 1.5;
  overflow-wrap: anywhere;
}

.focus-progress {
  height: 8px;
  background: var(--focus-progress-bg);
  border-radius: 999px;
  margin-bottom: 18px;
  overflow: hidden;
}

.focus-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--warm));
  transition: width 1s linear, background 0.3s;
  width: 0%;
}

#focusOverlay.paused .focus-bar {
  background: #e67e22;
}

#focusOverlay.paused .focus-timer {
  color: #e67e22;
}

#focusOverlay.paused .focus-label {
  color: #e67e22;
}

/* ── Input Area ───────────────── */

#inputArea {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 14px clamp(14px, 3vw, 22px);
  padding-bottom: max(14px, env(safe-area-inset-bottom));
  background: var(--chrome-bg);
  border-top: 1px solid var(--border);
}

#chatInput {
  flex: 1;
  min-height: 44px;
  resize: none;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 11px 13px;
  font-size: 15px;
  outline: none;
  max-height: 120px;
  background: var(--surface);
  color: var(--text);
  line-height: 1.45;
  box-shadow: var(--input-inset-shadow);
}

#chatInput::placeholder {
  color: var(--text-muted);
}

#chatInput:focus {
  border-color: rgba(31, 143, 120, 0.54);
  box-shadow: 0 0 0 3px rgba(31, 143, 120, 0.12);
}

.icon-btn {
  width: 44px;
  height: 44px;
  border: none;
  background: var(--soft-button);
  color: var(--text);
  border-radius: var(--radius);
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: transform 0.15s ease, background 0.15s ease;
}

.icon-btn:active {
  background: var(--border);
  transform: translateY(1px);
}

.send-btn {
  width: 44px;
  height: 44px;
  border: none;
  background: var(--accent);
  color: white;
  border-radius: var(--radius);
  font-size: 24px;
  line-height: 1;
  font-weight: 700;
  cursor: pointer;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.15s ease, background 0.15s ease;
}

.send-btn:active {
  background: var(--accent-strong);
  transform: translateY(1px);
}

.send-btn:disabled {
  background: #b8c4c0;
  cursor: default;
}

.btn-secondary {
  min-height: 40px;
  padding: 9px 18px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  border-radius: var(--radius);
  font-size: 14px;
  cursor: pointer;
  color: var(--text);
  transition: background 0.15s ease, border-color 0.15s ease;
}

.btn-secondary:active {
  background: var(--accent-soft);
  border-color: rgba(31, 143, 120, 0.36);
}

#focusStopBtn {
  background: #c0392b;
  border: none;
  color: #fff;
  padding: 10px 28px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  margin-top: 8px;
}

#focusStopBtn:active {
  background: #a93226;
}

/* ── Responsive ───────────────── */

@media (min-width: 900px) {
  body {
    padding: 24px;
    display: grid;
    place-items: center;
  }

  #app {
    height: min(calc(100dvh - 48px), 940px);
    border-radius: var(--radius);
    overflow: hidden;
  }
}

@media (max-width: 899px) {
  #app {
    width: 100%;
    height: 100dvh;
    border: 0;
    box-shadow: none;
  }
}

@media (max-width: 480px) {
  #header {
    min-height: 64px;
    padding-inline: 16px;
  }

  #messages {
    padding: 16px 12px;
    gap: 8px;
  }

  .message {
    max-width: 88%;
    font-size: 14px;
  }

  .message.system {
    max-width: 96%;
  }

  #inputArea {
    gap: 8px;
    padding-inline: 10px;
  }

  .icon-btn,
  .send-btn {
    width: 42px;
    height: 42px;
  }

  #chatInput {
    min-height: 42px;
    font-size: 14px;
  }

  .focus-card {
    padding: 24px 20px;
  }

  .focus-timer {
    font-size: 44px;
  }
}
