/* ═══════════════════════════════════════════
   HARU TALK — Design System
   粉藍配色收斂版 · 2025
═══════════════════════════════════════════ */

@import url('https://fonts.googleapis.com/css2?family=DM+Sans:ital,opsz,wght@0,9..40,300;0,9..40,500;0,9..40,700;1,9..40,300&family=Noto+Sans+TC:wght@300;400;700&display=swap');

:root {
  /* Palette */
  --pink:        #d47fa0;
  --pink-light:  #f0b8ce;
  --pink-dim:    rgba(212, 127, 160, 0.14);
  --blue:        #6aaecb;
  --blue-light:  #a8d4e8;
  --blue-dim:    rgba(106, 174, 203, 0.14);
  --navy:        #1e3248;

  /* Surface */
  --bg:          #f5f0f3;
  --surface:     #ffffff;
  --surface-2:   #f9f5f7;
  --surface-3:   #f0eaf0;

  /* Text */
  --ink:         #1e2a35;
  --ink-2:       #4a5568;
  --muted:       #8a96a8;

  /* Border */
  --line:        rgba(180, 160, 175, 0.28);
  --line-strong: rgba(180, 160, 175, 0.5);

  /* Elevation */
  --shadow-sm:   0 1px 3px rgba(30, 50, 72, 0.06), 0 1px 2px rgba(30, 50, 72, 0.04);
  --shadow-md:   0 4px 16px rgba(30, 50, 72, 0.08), 0 2px 6px rgba(30, 50, 72, 0.05);

  /* Radius */
  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 18px;
  --r-xl: 24px;

  /* Type */
  --font-display: 'DM Sans', 'Noto Sans TC', system-ui, sans-serif;
  --font-body:    'Noto Sans TC', 'DM Sans', system-ui, sans-serif;
  --app-height: 100dvh;
}

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

html {
  height: 100%;
  overflow: hidden;
}

body {
  height: 100%;
  min-height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  width: 100%;
  font-family: var(--font-body);
  font-size: 14px;
  line-height: 1.6;
  color: var(--ink);
  background: var(--bg);
  background-image:
    linear-gradient(135deg, rgba(255,255,255,0.38) 25%, transparent 25%),
    linear-gradient(225deg, rgba(255,255,255,0.32) 25%, transparent 25%),
    linear-gradient(180deg, rgba(106, 174, 203, 0.16), rgba(212, 127, 160, 0.14));
  background-size: 28px 28px, 28px 28px, 100% 100%;
  background-position: 0 0, 14px 14px, 0 0;
  background-attachment: fixed;
}

/* ── Base elements ── */
button, input, select, textarea { font: inherit; color: inherit; }

h2 { font-family: var(--font-display); font-size: 1.25rem; font-weight: 700; letter-spacing: -0.02em; }
h3 { font-family: var(--font-display); font-size: 1.05rem; font-weight: 700; letter-spacing: -0.01em; }

/* ═══════════════════════════════════════════
   APP SHELL
═══════════════════════════════════════════ */
.app {
  position: fixed;
  inset: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  width: min(100%, 1280px);
  height: var(--app-height);
  max-height: var(--app-height);
  min-height: 0;
  box-sizing: border-box;
  max-width: 1280px;
  margin: 0 auto;
  padding: 12px 16px 24px;
  gap: 16px;
  overflow: hidden;
}

/* ═══════════════════════════════════════════
   HEADER
═══════════════════════════════════════════ */
.app-header {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 10px 20px;
  border-radius: var(--r-xl);
  border: 1px solid var(--line-strong);
  background: rgba(255,255,255,0.88);
  backdrop-filter: blur(12px);
  box-shadow: var(--shadow-sm);
}

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

.brand-dot {
  width: 28px;
  height: 28px;
  border-radius: 9px;
  background:
    linear-gradient(135deg, rgba(255,255,255,0.88), rgba(255,255,255,0.1)),
    linear-gradient(135deg, var(--pink), var(--blue));
  box-shadow: 0 0 0 3px rgba(255,255,255,0.7), 0 4px 10px rgba(30, 50, 72, 0.14);
  animation: pulse-dot 2.4s ease-in-out infinite;
}

@keyframes pulse-dot {
  0%, 100% { box-shadow: 0 0 0 3px var(--pink-dim); }
  50%       { box-shadow: 0 0 0 6px var(--pink-dim); }
}

.brand-name {
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--navy);
}

.brand-sub {
  font-size: 0.7rem;
  font-weight: 500;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 2px 7px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
}

.header-nav {
  display: flex;
  gap: 4px;
  flex: 1;
  justify-content: center;
}

.tab {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 36px;
  padding: 0 16px;
  border-radius: var(--r-md);
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 180ms ease;
}

.tab:hover {
  color: var(--ink);
  background: var(--surface-3);
}

.tab.active {
  color: var(--navy);
  background: white;
  border-color: var(--line-strong);
  box-shadow: var(--shadow-sm);
  font-weight: 700;
}

.tab-icon { font-size: 0.7rem; opacity: 0.7; }

.header-status { flex: 0 0 auto; }

.auth-controls {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
}

.tab:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.tab:disabled:hover {
  color: var(--muted);
  background: transparent;
}

/* ═══════════════════════════════════════════
   VIEW SWITCHING
═══════════════════════════════════════════ */
.view {
  display: none;
  min-height: 0;
  overflow: hidden;
}
.view.active {
  display: grid;
  animation: fadeUp 200ms ease-out both;
}

#viewerView {
  grid-template-rows: minmax(0, 1fr);
}

#studioView {
  grid-template-rows: auto minmax(0, 1fr);
}

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

/* ═══════════════════════════════════════════
   VIEWER VIEW
═══════════════════════════════════════════ */
.viewer-layout {
  display: grid;
  grid-template-columns: minmax(0, 860px);
  gap: 16px;
  align-items: stretch;
  justify-content: center;
  min-height: 0;
  height: 100%;
}

/* Chat column */
.chat-col {
  position: relative;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 0;
  border: 1px solid rgba(255,255,255,0.82);
  border-radius: 28px;
  background: var(--surface);
  box-shadow:
    0 18px 42px rgba(30, 50, 72, 0.14),
    inset 0 0 0 1px rgba(30, 50, 72, 0.08);
  overflow: hidden;
  min-height: 0;
  height: 100%;
}

.chat-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  background:
    linear-gradient(180deg, rgba(255,255,255,0.92), rgba(249,245,247,0.94)),
    linear-gradient(90deg, rgba(106,174,203,0.12), rgba(212,127,160,0.1));
}

.chat-toolbar > div {
  display: grid;
  gap: 1px;
  min-width: 0;
}

.chat-toolbar strong {
  color: var(--navy);
  font-family: var(--font-display);
  font-size: 1rem;
}

.chat-toolbar span {
  color: var(--muted);
  font-size: 0.78rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.settings-toggle {
  display: inline-flex;
  margin-left: auto;
  flex: 0 0 auto;
}

.stat-item {
  display: flex;
  align-items: baseline;
  gap: 6px;
}

.stat-item strong {
  font-family: var(--font-display);
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--navy);
}

.stat-item span {
  font-size: 0.75rem;
  color: var(--muted);
  font-weight: 500;
}

.stat-divider {
  width: 1px;
  height: 20px;
  background: var(--line-strong);
}

/* Thread */
.thread {
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 22px;
  display: grid;
  align-content: start;
  gap: 12px;
}

.chat-body {
  background:
    linear-gradient(rgba(255,255,255,0.72), rgba(255,255,255,0.72)),
    linear-gradient(90deg, rgba(106,174,203,0.12) 1px, transparent 1px),
    linear-gradient(180deg, rgba(212,127,160,0.1) 1px, transparent 1px),
    var(--surface);
  background-size: auto, 24px 24px, 24px 24px, auto;
}

.empty-state {
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.8;
  display: grid;
  place-items: center;
  text-align: center;
  padding: 48px 24px;
}

/* Composer */
.composer {
  position: sticky;
  bottom: 0;
  z-index: 2;
  padding: 14px 16px;
  border-top: 1px solid var(--line);
  background: rgba(255,255,255,0.95);
  display: grid;
  gap: 10px;
}

.composer textarea {
  width: 100%;
  min-height: 72px;
  max-height: 140px;
  resize: vertical;
  padding: 10px 12px;
  border: 1px solid var(--line-strong);
  border-radius: var(--r-md);
  background: var(--surface-2);
  outline: none;
  transition: border-color 150ms, box-shadow 150ms;
  line-height: 1.65;
}

.composer textarea:focus {
  border-color: var(--pink);
  box-shadow: 0 0 0 3px var(--pink-dim);
  background: white;
}

.composer-footer {
  display: flex;
  align-items: center;
  gap: 10px;
  justify-content: flex-end;
}

.toggle-line {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.82rem;
  color: var(--ink-2);
  cursor: pointer;
}

.toggle-line input[type="checkbox"] {
  width: 15px;
  height: 15px;
  accent-color: var(--pink);
  cursor: pointer;
}

.char-count {
  font-size: 0.75rem;
  color: var(--muted);
}

/* Settings column */
.settings-col {
  display: grid;
  align-content: start;
  gap: 10px;
  position: fixed;
  left: 50%;
  top: 50%;
  z-index: 30;
  width: min(420px, calc(100vw - 24px));
  max-height: calc(100dvh - 32px);
  padding: 14px;
  overflow-y: auto;
  border: 1px solid var(--line-strong);
  border-radius: var(--r-xl);
  background: rgba(255, 255, 255, 0.98);
  box-shadow: var(--shadow-md);
  transform: translate(-50%, -48%) scale(0.98);
  opacity: 0;
  pointer-events: none;
  transition: transform 180ms ease, opacity 180ms ease;
}

.settings-col.open {
  transform: translate(-50%, -50%) scale(1);
  opacity: 1;
  pointer-events: auto;
}

.settings-drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.settings-backdrop {
  display: block;
  position: fixed;
  inset: 0;
  z-index: 25;
  background: rgba(30, 42, 53, 0.22);
  opacity: 0;
  pointer-events: none;
  transition: opacity 180ms ease;
}

.settings-backdrop.open {
  opacity: 1;
  pointer-events: auto;
}

.settings-form {
  display: grid;
  gap: 12px;
}

.settings-field {
  display: grid;
  gap: 8px;
}

.settings-card {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  display: grid;
  gap: 10px;
}

.login-card .input-row {
  display: flex;
  gap: 8px;
}

.login-card .input-row input { flex: 1; min-width: 0; }

.card-label {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--muted);
}

.daily-card {
  background:
    radial-gradient(circle at 90% 10%, rgba(106, 174, 203, 0.15), transparent 50%),
    var(--surface);
}

.daily-text {
  font-size: 0.88rem;
  color: var(--navy);
  font-weight: 500;
  line-height: 1.5;
}

/* ── Chips ── */
.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chip {
  display: inline-flex;
  align-items: center;
  height: 30px;
  padding: 0 12px;
  border-radius: 999px;
  border: 1px solid var(--line-strong);
  background: white;
  color: var(--ink-2);
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 150ms ease;
}

.chip:hover {
  border-color: var(--pink);
  color: var(--pink);
}

.chip.active {
  background: linear-gradient(135deg, var(--pink), var(--blue));
  border-color: transparent;
  color: white;
  font-weight: 700;
}

/* Route track */
.route-track {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  background: var(--surface);
  display: flex;
  align-items: center;
  gap: 6px;
}

.route-step {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 0 0 auto;
}

.route-node {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 1px solid var(--line-strong);
  background: white;
  font-size: 0.68rem;
  font-weight: 700;
  color: var(--muted);
  font-family: var(--font-display);
  transition: all 200ms;
}

.route-label-text {
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--muted);
  transition: color 200ms;
}

.route-line-seg {
  flex: 1;
  height: 1px;
  background: var(--line-strong);
  min-width: 12px;
}

.route-step.active .route-node {
  background: linear-gradient(135deg, var(--pink), var(--blue));
  border-color: transparent;
  color: white;
  box-shadow: 0 2px 8px var(--pink-dim);
}

.route-step.active .route-label-text { color: var(--navy); font-weight: 700; }

.route-step.done .route-node {
  background: var(--blue-dim);
  border-color: var(--blue);
  color: var(--blue);
}

/* ═══════════════════════════════════════════
   STUDIO VIEW
═══════════════════════════════════════════ */
.studio-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 2px 4px 12px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 12px;
}

.studio-topbar h2 { color: var(--navy); }

.studio-topbar .eyebrow {
  display: block;
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
  margin-bottom: 2px;
}

.studio-topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.badge {
  display: inline-flex;
  align-items: center;
  height: 28px;
  padding: 0 10px;
  border-radius: 999px;
  background: var(--pink-dim);
  color: var(--pink);
  font-size: 0.75rem;
  font-weight: 700;
  border: 1px solid rgba(212, 127, 160, 0.3);
}

.badge-blue {
  background: var(--blue-dim);
  color: var(--blue);
  border-color: rgba(106, 174, 203, 0.3);
}

.studio-layout {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  gap: 18px;
  align-items: stretch;
  min-height: 0;
  height: 100%;
}

/* Viewer column */
.viewer-col {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  gap: 12px;
  padding: 16px;
  border: 1px solid var(--line-strong);
  border-radius: var(--r-xl);
  background: var(--surface);
  box-shadow: var(--shadow-md);
}

.search-wrap input {
  width: 100%;
  height: 38px;
  padding: 0 12px;
  border: 1px solid var(--line-strong);
  border-radius: var(--r-md);
  background: var(--surface-2);
  outline: none;
  font-size: 0.85rem;
  transition: border-color 150ms, box-shadow 150ms;
}

.search-wrap input:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px var(--blue-dim);
  background: white;
}

.viewer-list {
  display: grid;
  gap: 8px;
  min-height: 0;
  overflow-y: auto;
}

.viewer-card {
  display: grid;
  gap: 5px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--surface-2);
  text-align: left;
  cursor: pointer;
  transition: all 150ms ease;
}

.viewer-card:hover {
  border-color: var(--pink-light);
  background: white;
}

.viewer-card.active {
  border-color: var(--pink);
  background: white;
  box-shadow: 0 0 0 3px var(--pink-dim);
}

.viewer-card.unread {
  border-color: rgba(212, 127, 160, 0.42);
  background: linear-gradient(160deg, rgba(212, 127, 160, 0.12), rgba(255, 255, 255, 0.96));
}

.viewer-card.unread strong::after {
  content: "";
  display: inline-block;
  width: 7px;
  height: 7px;
  margin-left: 7px;
  border-radius: 50%;
  background: var(--pink);
  vertical-align: middle;
}

.viewer-card strong {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--navy);
}

.viewer-card span {
  font-size: 0.75rem;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Detail column */
.detail-col {
  border: 1px solid var(--line-strong);
  border-radius: var(--r-xl);
  background: var(--surface);
  box-shadow: var(--shadow-md);
  overflow: hidden;
  min-height: 0;
  height: 100%;
  display: grid;
}

.detail-empty {
  min-height: 400px;
}

.detail-panel {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  min-height: 0;
  height: 100%;
}

.detail-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 22px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-2);
}

.detail-header .eyebrow {
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
  display: block;
  margin-bottom: 2px;
}

/* Tool grid */
.detail-tools {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-2);
}

.tool-card {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: white;
  display: grid;
  gap: 8px;
  font-size: 0.84rem;
}

.live-cue .field-title {
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--muted);
  margin-bottom: 4px;
}

.live-cue strong { color: var(--navy); font-size: 0.84rem; display: block; }
.live-cue p { color: var(--ink-2); font-size: 0.82rem; margin-top: 4px; }
.live-cue .cue-meta { color: var(--muted); font-size: 0.75rem; }

.memory-area {
  width: 100%;
  min-height: 80px;
  resize: vertical;
  padding: 8px 10px;
  border: 1px solid var(--line-strong);
  border-radius: var(--r-sm);
  background: var(--surface-2);
  outline: none;
  font-size: 0.83rem;
  line-height: 1.6;
  transition: border-color 150ms, box-shadow 150ms;
}

.memory-area:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px var(--blue-dim);
  background: white;
}

/* Studio thread */
.studio-thread {
  min-height: 0;
  padding: 20px 22px;
  overflow-y: auto;
  background:
    radial-gradient(circle at 8% 8%, rgba(212, 127, 160, 0.05), transparent 30%),
    radial-gradient(circle at 92% 88%, rgba(106, 174, 203, 0.07), transparent 30%),
    var(--surface);
}

/* Reply area */
.reply-area {
  padding: 16px 18px;
  border-top: 1px solid var(--line);
  background: rgba(255,255,255,0.95);
}

.reply-form { display: grid; gap: 10px; }

.reply-target {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border: 1px solid rgba(106, 174, 203, 0.3);
  border-radius: var(--r-md);
  background: var(--blue-dim);
  animation: fadeUp 150ms ease-out;
}

.reply-target-label {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--muted);
  flex-shrink: 0;
}

.reply-target strong {
  flex: 1;
  min-width: 0;
  font-size: 0.84rem;
  color: var(--navy);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.reply-form textarea {
  width: 100%;
  min-height: 72px;
  max-height: 130px;
  resize: vertical;
  padding: 10px 12px;
  border: 1px solid var(--line-strong);
  border-radius: var(--r-md);
  background: var(--surface-2);
  outline: none;
  line-height: 1.65;
  transition: border-color 150ms, box-shadow 150ms;
}

.reply-form textarea:focus {
  border-color: var(--pink);
  box-shadow: 0 0 0 3px var(--pink-dim);
  background: white;
}

.reply-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: flex-end;
}

/* ═══════════════════════════════════════════
   MESSAGES
═══════════════════════════════════════════ */
.message-row {
  display: flex;
  align-items: end;
  gap: 8px;
  width: 100%;
}

.message-row.from-haru {
  justify-content: start;
}

.message-row.from-viewer {
  justify-content: end;
  flex-direction: row-reverse;
}

.studio-thread .message-row.from-haru {
  justify-content: end;
  flex-direction: row-reverse;
}

.studio-thread .message-row.from-viewer {
  justify-content: start;
  flex-direction: row;
}

.message-avatar {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  border-radius: 12px;
  color: white;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 0.78rem;
  box-shadow: 0 4px 10px rgba(30, 50, 72, 0.14);
  overflow: hidden;
}

.message-avatar.photo {
  background: white;
  padding: 2px;
}

.message-avatar img {
  width: 100%;
  height: 100%;
  border-radius: 10px;
  object-fit: cover;
  display: block;
}

.from-haru .message-avatar {
  background: linear-gradient(135deg, var(--blue), #85c9df);
}

.from-viewer .message-avatar {
  background: linear-gradient(135deg, var(--pink), #e7a6bf);
}

.message-card {
  position: relative;
  max-width: 72%;
  padding: 11px 14px;
  border-radius: var(--r-lg);
  border: 1px solid var(--line);
  background: white;
  font-size: 0.88rem;
  overflow-wrap: anywhere;
  word-break: break-word;
  box-shadow: 0 4px 14px rgba(30, 50, 72, 0.08);
}

/* 觀眾端 viewer messages (right) */
.chat-body .message-card:not(.reply) {
  background: linear-gradient(160deg, rgba(255, 224, 237, 0.98), rgba(255, 247, 251, 0.98));
  border-color: rgba(212, 127, 160, 0.3);
  border-radius: var(--r-lg) var(--r-lg) 4px var(--r-lg);
}

/* 觀眾端 haru replies (left) */
.chat-body .message-card.reply {
  background: linear-gradient(160deg, rgba(255,255,255,0.98), rgba(236, 249, 255, 0.98));
  border-color: rgba(106, 174, 203, 0.3);
  border-radius: var(--r-lg) var(--r-lg) var(--r-lg) 4px;
}

.chat-body .message-card::after,
.studio-thread .message-card::after {
  content: "";
  position: absolute;
  bottom: -1px;
  width: 11px;
  height: 11px;
  background: inherit;
}

.message-card.reply::after {
  left: -5px;
  border-left: 1px solid rgba(106, 174, 203, 0.3);
  border-bottom-left-radius: 9px;
}

.message-card:not(.reply)::after {
  right: -5px;
  border-right: 1px solid rgba(212, 127, 160, 0.3);
  border-bottom-right-radius: 9px;
}

/* 後台端 viewer messages (left) */
.studio-thread .message-card:not(.reply) {
  justify-self: start;
  border-radius: var(--r-lg) var(--r-lg) var(--r-lg) 4px;
}

/* 後台端 haru replies (right) */
.studio-thread .message-card.reply {
  justify-self: end;
  background: linear-gradient(160deg, rgba(212,127,160,0.1), rgba(212,127,160,0.03));
  border-color: rgba(212, 127, 160, 0.3);
  border-radius: var(--r-lg) var(--r-lg) 4px var(--r-lg);
}

.message-card.is-new {
  animation: messageGlow 600ms ease-out both;
}

@keyframes messageGlow {
  0%   { box-shadow: 0 0 0 0 rgba(212, 127, 160, 0); }
  30%  { box-shadow: 0 0 0 4px rgba(212, 127, 160, 0.2); }
  100% { box-shadow: 0 0 0 0 rgba(212, 127, 160, 0); }
}

.message-meta {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
  font-size: 0.68rem;
  font-weight: 700;
  color: var(--muted);
}

.message-card p {
  line-height: 1.65;
  white-space: pre-wrap;
  color: var(--ink);
}

.reply-context {
  margin-bottom: 8px;
  padding: 6px 10px;
  border-left: 2px solid var(--blue);
  border-radius: 6px;
  background: var(--blue-dim);
  font-size: 0.76rem;
  color: var(--muted);
  font-weight: 500;
}

.message-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.inline-reply-button {
  display: inline-flex;
  align-items: center;
  height: 26px;
  padding: 0 10px;
  border-radius: 999px;
  border: 1px solid var(--line-strong);
  background: white;
  color: var(--ink-2);
  font-size: 0.75rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 130ms;
}

.inline-reply-button:hover,
.inline-reply-button.active {
  background: linear-gradient(135deg, var(--pink), var(--blue));
  border-color: transparent;
  color: white;
}

/* ═══════════════════════════════════════════
   BUTTONS
═══════════════════════════════════════════ */
.btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 36px;
  padding: 0 18px;
  border-radius: var(--r-md);
  border: none;
  background: linear-gradient(135deg, var(--pink), var(--blue));
  color: white;
  font-size: 0.84rem;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
  transition: opacity 150ms, box-shadow 150ms;
}

.btn-primary:hover {
  opacity: 0.9;
  box-shadow: 0 2px 12px rgba(212, 127, 160, 0.35);
}

.btn-ghost {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 34px;
  padding: 0 14px;
  border-radius: var(--r-md);
  border: 1px solid var(--line-strong);
  background: white;
  color: var(--ink-2);
  font-size: 0.82rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 150ms;
}

.btn-ghost:hover {
  border-color: var(--pink-light);
  color: var(--navy);
  background: var(--surface-2);
}

.compact {
  height: 26px;
  padding: 0 8px;
  font-size: 0.75rem;
  border-radius: var(--r-sm);
}

/* ═══════════════════════════════════════════
   FORM ELEMENTS
═══════════════════════════════════════════ */
input:not([type="checkbox"]):not([type="search"]),
select {
  width: 100%;
  height: 38px;
  padding: 0 12px;
  border: 1px solid var(--line-strong);
  border-radius: var(--r-md);
  background: var(--surface-2);
  outline: none;
  font-size: 0.85rem;
  transition: border-color 150ms, box-shadow 150ms;
}

input:not([type="checkbox"]):not([type="search"]):focus,
select:focus {
  border-color: var(--pink);
  box-shadow: 0 0 0 3px var(--pink-dim);
  background: white;
}

select { cursor: pointer; }

/* ═══════════════════════════════════════════
   STATUS PILL
═══════════════════════════════════════════ */
.status-pill {
  display: inline-flex;
  align-items: center;
  height: 28px;
  padding: 0 11px;
  border-radius: 999px;
  background: var(--blue-dim);
  border: 1px solid rgba(106, 174, 203, 0.3);
  color: var(--navy);
  font-size: 0.75rem;
  font-weight: 700;
  white-space: nowrap;
}

/* ═══════════════════════════════════════════
   UTILITIES
═══════════════════════════════════════════ */
.hidden { display: none !important; }

/* ═══════════════════════════════════════════
   REDUCED MOTION
═══════════════════════════════════════════ */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 1ms !important;
    transition-duration: 1ms !important;
  }
}

/* ═══════════════════════════════════════════
   RWD
═══════════════════════════════════════════ */
@media (max-width: 960px) {
  .app { padding: 8px 10px 12px; gap: 10px; }

  .app-header {
    flex-wrap: wrap;
    gap: 12px;
    padding: 10px 14px;
    border-radius: var(--r-lg);
  }

  .header-status { order: -1; margin-left: auto; }

  .viewer-layout {
    grid-template-columns: 1fr;
  }

  .studio-layout {
    grid-template-columns: 260px minmax(0, 1fr);
  }

  .detail-tools { grid-template-columns: 1fr; }

  .reply-actions {
    flex-wrap: wrap;
  }

  .reply-actions .btn-ghost { flex: 1; }
  .reply-actions .btn-primary { width: 100%; }
}

@media (max-width: 760px) {
  html,
  body {
    height: 100%;
    min-height: 100%;
    overflow: hidden;
    overscroll-behavior: none;
  }

  .app {
    height: var(--app-height);
    max-height: var(--app-height);
    min-height: 0;
    padding: 8px 8px max(8px, env(safe-area-inset-bottom));
    gap: 8px;
    overflow: hidden;
  }

  .app-header {
    align-content: start;
    gap: 8px;
    padding: 8px 10px;
    border-radius: var(--r-md);
  }

  .header-brand {
    min-width: 0;
  }

  .brand-sub,
  .header-status {
    display: none;
  }

  .auth-controls {
    margin-left: auto;
  }

  .header-nav {
    order: 2;
    flex-basis: 100%;
  }

  .tab {
    flex: 1;
    justify-content: center;
  }

  #viewerView,
  .viewer-layout,
  .chat-col {
    min-height: 0;
    height: 100%;
  }

  .chat-col:focus-within {
    grid-template-rows: auto minmax(96px, 1fr) auto;
  }

  .chat-toolbar {
    padding: 8px 10px;
  }

  .thread {
    min-height: 0;
    padding: 12px;
    overflow-y: auto;
    touch-action: pan-y;
  }

  .chat-body {
    max-height: none;
  }

  .composer {
    padding: 10px;
    gap: 8px;
    flex: 0 0 auto;
  }

  .composer textarea {
    font-size: 16px;
    min-height: 56px;
    max-height: 92px;
  }

  input,
  select,
  textarea {
    font-size: 16px;
  }

  .message-card {
    max-width: 88%;
  }

  .studio-topbar {
    align-items: flex-start;
    gap: 8px;
  }

  .studio-layout {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(120px, 28%) minmax(0, 1fr);
  }

  .viewer-col {
    min-height: 0;
  }
}

@media (max-width: 600px) {
  .composer-footer { flex-wrap: nowrap; }
  .btn-primary { width: 100%; }
  .composer-footer .btn-primary { width: auto; }
  .studio-topbar { flex-wrap: wrap; gap: 10px; }
}
