* { box-sizing: border-box; }
:root {
  --yellow: #FFD600;
  --yellow-dark: #E6C000;
  --black: #000000;
  --grey-100: #F7F7F7;
  --grey-200: #EFEFEF;
  --grey-300: #DDDDDD;
  --grey-500: #888;
  --grey-700: #444;
  --user-bg: #FFD600;
  --ai-bg: #F2F2F2;
  --shadow: 0 2px 10px rgba(0,0,0,0.08);
}

html, body {
  height: 100%;
  margin: 0;
  font-family: "Noto Sans TC", "PingFang TC", -apple-system, "Segoe UI", sans-serif;
  background: #FAFAFA;
  color: #111;
  font-size: 15px;
}

body { display: flex; flex-direction: column; }

.topbar {
  background: #000;
  color: #fff;
  padding: 12px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 3px solid var(--yellow);
}

.brand { display: flex; align-items: center; gap: 12px; }
.logo-dot {
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--yellow);
  display: inline-block;
}
.brand-title { font-weight: 700; font-size: 16px; }
.brand-sub { font-size: 11px; color: var(--yellow); letter-spacing: 0.5px; }

.top-right { display: flex; gap: 10px; align-items: center; }
.version {
  background: var(--yellow);
  color: #000;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 4px;
  font-size: 12px;
}

.btn {
  padding: 8px 14px;
  border-radius: 6px;
  border: none;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  transition: all 0.15s;
}
.btn-ghost {
  background: transparent;
  color: #fff;
  border: 1px solid #444;
}
.btn-ghost:hover { background: #222; }
.btn-primary {
  background: var(--yellow);
  color: #000;
}
.btn-primary:hover { background: var(--yellow-dark); }
.btn-send {
  background: var(--yellow);
  color: #000;
  font-weight: 700;
  padding: 12px 24px;
  border-radius: 8px;
  flex-shrink: 0;
}
.btn-send:hover { background: var(--yellow-dark); }
.btn-send:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-suggest {
  background: #fff;
  color: #000;
  border: 1px solid var(--yellow);
  font-weight: 700;
}
.btn-suggest:hover { background: var(--yellow); }

.btn-sos {
  background: #D32F2F;
  color: #fff;
  font-weight: 800;
  border: 1px solid #B71C1C;
}
.btn-sos:hover { background: #B71C1C; }

.tone-select {
  padding: 8px 10px;
  border: 1px solid var(--grey-300);
  border-radius: 8px;
  font-size: 13px;
  font-family: inherit;
  background: #fff;
  cursor: pointer;
  flex-shrink: 0;
}
.tone-select:focus { outline: none; border-color: var(--yellow); box-shadow: 0 0 0 2px rgba(255,214,0,0.3); }

.ai-tools {
  display: flex;
  gap: 6px;
  margin-top: 6px;
  align-items: center;
  flex-wrap: wrap;
}
.tool-btn {
  padding: 5px 10px;
  background: #fff;
  color: var(--grey-700);
  border: 1px solid var(--grey-300);
  border-radius: 14px;
  font-size: 12px;
  cursor: pointer;
  transition: all 0.15s;
}
.tool-btn:hover { background: var(--yellow); color: #000; border-color: var(--yellow); }
.tool-btn:active { transform: scale(0.96); }
.tool-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.tool-status {
  font-size: 12px;
  color: var(--grey-500);
  font-weight: 600;
  min-width: 60px;
}
.tool-status.ok { color: #2E7D32; }
.tool-status.fail { color: #C62828; }

.user-summary {
  margin-top: 6px;
  font-size: 12px;
  color: #555;
  background: #FFFCE8;
  border-left: 3px solid var(--yellow);
  padding: 6px 10px;
  border-radius: 4px;
  max-width: 80%;
  margin-left: auto;
  font-style: italic;
}
.user-summary.hidden { display: none; }
.user-summary.loading { color: #999; }

.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 16px;
  max-width: 1100px;
  margin: 0 auto;
  width: 100%;
  min-height: 0;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 14px;
  overflow-y: auto;
}

.card {
  background: #fff;
  border-radius: 10px;
  padding: 14px;
  box-shadow: var(--shadow);
}

.card-title {
  font-weight: 700;
  font-size: 13px;
  margin-bottom: 10px;
  color: #000;
  border-left: 3px solid var(--yellow);
  padding-left: 8px;
}

.input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--grey-300);
  border-radius: 6px;
  font-size: 14px;
  font-family: inherit;
}
.input:focus {
  outline: none;
  border-color: var(--yellow);
  box-shadow: 0 0 0 2px rgba(255,214,0,0.3);
}

.input-small {
  width: 100%;
  padding: 6px 10px;
  border: 1px solid var(--grey-300);
  border-radius: 6px;
  font-size: 12px;
  font-family: inherit;
}

.hint {
  font-size: 11px;
  color: var(--grey-500);
  margin-top: 6px;
  line-height: 1.5;
}

.quick-list { display: flex; flex-direction: column; gap: 6px; }
.quick-btn {
  text-align: left;
  padding: 8px 10px;
  background: var(--grey-100);
  border: 1px solid var(--grey-200);
  border-radius: 6px;
  cursor: pointer;
  font-size: 12px;
  transition: all 0.15s;
  line-height: 1.4;
}
.quick-btn:hover {
  background: var(--yellow);
  border-color: var(--yellow);
}
.quick-btn .qnum {
  color: var(--grey-500);
  font-weight: 700;
  margin-right: 6px;
}

.score-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 8px;
}
.score-box {
  background: var(--grey-100);
  border-radius: 8px;
  padding: 12px 8px;
  text-align: center;
}
.score-num {
  font-size: 24px;
  font-weight: 800;
  color: #000;
}
.score-label {
  font-size: 11px;
  color: var(--grey-500);
  margin-top: 2px;
}

.tips {
  font-size: 12px;
  line-height: 1.6;
  color: var(--grey-700);
  padding-left: 16px;
  margin: 0;
}
.tips li { margin-bottom: 4px; }

.chat-area {
  display: flex;
  flex-direction: column;
  background: #fff;
  border-radius: 10px;
  box-shadow: var(--shadow);
  min-height: 0;
  overflow: hidden;
}

.chat-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
}

.chat-placeholder {
  text-align: center;
  color: var(--grey-500);
  padding: 40px 20px;
}
.ph-emoji { font-size: 42px; margin-bottom: 12px; }
.ph-title { font-size: 18px; font-weight: 700; color: #000; margin-bottom: 6px; }
.ph-sub { font-size: 13px; }

.msg {
  display: flex;
  margin-bottom: 16px;
  gap: 10px;
}
.msg-user { justify-content: flex-end; }
.msg-ai .msg-body { max-width: 78%; }

.avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: #000;
  color: var(--yellow);
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  flex-shrink: 0;
}

.bubble {
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 14px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-wrap: break-word;
}
.bubble-user {
  background: var(--user-bg);
  color: #000;
  border-bottom-right-radius: 4px;
  max-width: 80%;
}
.bubble-ai {
  background: var(--ai-bg);
  color: #111;
  border-bottom-left-radius: 4px;
}
.bubble-ai.bubble-error {
  background: #FFF4F4;
  color: #A00;
  border: 1px solid #FFCDCD;
}

.rating-row {
  display: flex;
  gap: 8px;
  margin-top: 6px;
  align-items: center;
  flex-wrap: wrap;
}
.stars { display: flex; gap: 2px; }
.star {
  cursor: pointer;
  font-size: 20px;
  color: var(--grey-300);
  transition: color 0.1s;
  user-select: none;
}
.star:hover, .star.active, .star.hover-preview {
  color: var(--yellow);
}
.rate-note { flex: 1; min-width: 200px; }

.btn-rate-send {
  padding: 8px 16px;
  background: var(--yellow);
  color: #000;
  border: none;
  border-radius: 6px;
  font-weight: 700;
  font-size: 12px;
  cursor: pointer;
  flex-shrink: 0;
}
.btn-rate-send:hover { background: var(--yellow-dark); }
.btn-rate-send:active { transform: scale(0.96); }

.save-status {
  font-size: 12px;
  font-weight: 700;
  min-width: 72px;
  text-align: right;
  transition: opacity 0.2s, color 0.2s;
  opacity: 0;
}
.save-status.saving { color: #888; opacity: 1; }
.save-status.saved  { color: #2E7D32; opacity: 1; }
.save-status.fail   { color: #C62828; opacity: 1; }

.composer {
  display: flex;
  gap: 10px;
  padding: 14px;
  border-top: 1px solid var(--grey-200);
  background: #fff;
  align-items: flex-end;
}

.attachments {
  display: flex;
  gap: 8px;
  padding: 10px 14px 0;
  flex-wrap: wrap;
  background: #fff;
}
.attachments.hidden { display: none; }
.attach-thumb {
  position: relative;
  width: 72px;
  height: 72px;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--grey-300);
  background-size: cover;
  background-position: center;
  flex-shrink: 0;
}
.attach-thumb-x {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: rgba(0,0,0,0.7);
  color: #fff;
  border: none;
  cursor: pointer;
  font-size: 12px;
  line-height: 18px;
  text-align: center;
  padding: 0;
}
.attach-thumb-x:hover { background: #D32F2F; }

.btn-paste {
  background: #fff;
  color: #000;
  border: 1px solid var(--grey-300);
  padding: 10px 12px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 16px;
  flex-shrink: 0;
}
.btn-paste:hover { background: var(--yellow); border-color: var(--yellow); }

.user-images {
  display: flex;
  gap: 6px;
  margin-bottom: 6px;
  flex-wrap: wrap;
  justify-content: flex-end;
}
.user-images img {
  max-width: 240px;
  max-height: 240px;
  border-radius: 10px;
  border: 1px solid var(--grey-200);
  cursor: pointer;
}
.user-images img:hover { opacity: 0.85; }
.composer-input {
  flex: 1;
  padding: 10px 14px;
  border: 1px solid var(--grey-300);
  border-radius: 10px;
  font-size: 14px;
  font-family: inherit;
  resize: none;
  outline: none;
  line-height: 1.5;
  max-height: 150px;
}
.composer-input:focus {
  border-color: var(--yellow);
  box-shadow: 0 0 0 2px rgba(255,214,0,0.3);
}

.typing {
  display: inline-flex;
  gap: 4px;
  align-items: center;
}
.typing i {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--grey-500);
  animation: bounce 1.2s infinite;
}
.typing i:nth-child(2) { animation-delay: 0.15s; }
.typing i:nth-child(3) { animation-delay: 0.3s; }
@keyframes bounce {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.4; }
  40% { transform: translateY(-6px); opacity: 1; }
}

.toast {
  position: fixed;
  bottom: 30px;
  left: 50%;
  transform: translateX(-50%);
  background: #000;
  color: var(--yellow);
  padding: 12px 20px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  box-shadow: 0 4px 16px rgba(0,0,0,0.3);
  z-index: 100;
  transition: opacity 0.25s, transform 0.25s;
}
.toast.hidden { opacity: 0; transform: translateX(-50%) translateY(20px); pointer-events: none; }

/* ===== Modal ===== */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 20px;
}
.modal.hidden { display: none; }

.modal-card {
  background: #fff;
  border-radius: 12px;
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 10px 40px rgba(0,0,0,0.3);
  border-top: 4px solid var(--yellow);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 20px 24px 14px;
  border-bottom: 1px solid var(--grey-200);
}
.modal-title { font-weight: 800; font-size: 18px; color: #000; }
.modal-sub { font-size: 12px; color: var(--grey-500); margin-top: 4px; }

.modal-close {
  background: transparent;
  border: none;
  cursor: pointer;
  color: var(--grey-500);
  font-size: 20px;
  padding: 4px 10px;
  border-radius: 6px;
}
.modal-close:hover { background: var(--grey-100); color: #000; }

.modal-body {
  padding: 18px 24px;
  overflow-y: auto;
}

.form-row { margin-bottom: 14px; }
.form-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: #000;
  margin-bottom: 6px;
}
.textarea {
  resize: vertical;
  min-height: 120px;
  font-family: inherit;
  line-height: 1.6;
}
.checkbox-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--grey-700);
  cursor: pointer;
}
.checkbox-label input { width: 16px; height: 16px; cursor: pointer; }

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 14px 24px 20px;
  border-top: 1px solid var(--grey-200);
}

@media (max-width: 880px) {
  .main { grid-template-columns: 1fr; }
  .sidebar { max-height: 280px; }
}
