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

:root {
  --bg: #FFFAF5;
  --surface: #ffffff;
  --surface-alt: #FFF8F0;
  --text: #2D1B0E;
  --text-secondary: #7A6552;
  --text-muted: #A89585;
  --accent: #FF8C42;
  --accent-light: #FFF3E0;
  --accent-dark: #E67332;
  --success: #22c55e;
  --success-light: #dcfce7;
  --warning: #f59e0b;
  --warning-light: #fef3c7;
  --danger: #ef4444;
  --danger-light: #fee2e2;
  --border: #F0E6DC;
  --border-light: #F8F0E8;
  --shadow-sm: 0 1px 3px rgba(180,120,60,0.06);
  --shadow: 0 4px 12px rgba(180,120,60,0.08);
  --shadow-lg: 0 8px 32px rgba(180,120,60,0.10);
  --radius: 16px;
  --radius-sm: 10px;
  --radius-lg: 20px;
  --radius-full: 9999px;
  --font: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: "SF Mono", "Consolas", "Courier New", monospace;
  --transition: 0.2s ease;
}

html { font-size: 15px; scroll-behavior: smooth; }
body {
  font-family: var(--font);
  background: linear-gradient(180deg, #FFF8F0 0%, #FFF3E0 100%);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* ── Animations ── */
@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}
.animate-in { animation: fadeInUp 0.25s ease both; }

/* ── Layout ── */
.page-shell {
  max-width: 1400px;
  margin: 0 auto;
  padding: 12px 16px 40px;
}

/* ── Header ── */
.page-header {
  text-align: center;
  padding: 20px 20px 16px;
}
.page-header h1 {
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 4px;
}
.page-header .subtitle {
  font-size: 0.9rem;
  color: var(--text-secondary);
}
.variant-badge {
  display: inline-block;
  padding: 4px 14px;
  border-radius: var(--radius-full);
  font-size: 0.75rem;
  font-weight: 600;
  margin-bottom: 8px;
}
.variant-badge.exp {
  background: var(--accent-light);
  color: var(--accent);
}

/* ── Cards ── */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 20px;
  box-shadow: var(--shadow-sm);
  transition: box-shadow var(--transition);
}
.card:hover { box-shadow: var(--shadow); }
.card-title {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
  letter-spacing: 0.5px;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 6px;
}

/* ── Entry Form ── */
.entry-card {
  margin-bottom: 20px;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
}
.entry-form {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
  align-items: end;
}
.field label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 5px;
}
.field input,
.field select,
.field textarea {
  width: 100%;
  padding: 14px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 1rem;
  font-family: var(--font);
  color: var(--text);
  background: var(--surface);
  transition: border-color var(--transition), box-shadow var(--transition);
  outline: none;
}
.field input:focus,
.field select:focus,
.field textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(255, 140, 66, 0.15);
}
.field input::placeholder,
.field textarea::placeholder { color: var(--text-muted); }
.field textarea { resize: vertical; min-height: 80px; }

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 20px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 600;
  font-family: var(--font);
  cursor: pointer;
  transition: all var(--transition);
  text-decoration: none;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn:hover:not(:disabled) {
  transform: translateY(-2px);
}
.btn-primary { background: var(--accent); color: #fff; border-radius: 24px; height: 52px; font-size: 1.1rem; }
.btn-primary:hover:not(:disabled) { background: var(--accent-dark); box-shadow: var(--shadow-lg); }
.btn-secondary { background: var(--surface-alt); color: var(--text); border: 1.5px solid var(--border); }
.btn-secondary:hover:not(:disabled) { background: var(--border-light); }
.btn-ghost { background: transparent; color: var(--accent); padding: 6px 12px; }
.btn-ghost:hover { background: var(--accent-light); }
.btn-sm { padding: 6px 14px; font-size: 0.8rem; height: auto; border-radius: var(--radius-sm); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { background: #dc2626; }

/* ── Privacy Notice ── */
.privacy-bar {
  background: var(--warning-light);
  border: 1px solid #fde68a;
  border-radius: var(--radius-sm);
  padding: 8px 14px;
  font-size: 0.8rem;
  color: #92400e;
  text-align: center;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

/* ── Status Bar ── */
.status-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 16px;
  background: #FFF3E0;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: 12px;
  flex-wrap: wrap;
}
.status-item {
  font-size: 0.8rem;
  color: var(--text-secondary);
}
.status-item strong {
  color: var(--text);
  font-weight: 600;
}
.status-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  display: inline-block;
}
.status-dot.live { background: var(--success); }
.status-dot.mock { background: var(--warning); }

/* ══════════════════════════════════════
   Chat Layout
   ══════════════════════════════════════ */

.split-layout {
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-height: 0;
}

.split-layout .chat-panel {
  flex: 0 0 auto;
}

/* ── Chat Panel ── */
.chat-panel {
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  height: clamp(500px, calc(100vh - 230px), 720px);
  min-height: 0;
}

.chat-panel-header {
  padding: 14px 16px 10px;
  border-bottom: 1px solid var(--border-light);
}
.chat-panel-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
}

.chat-disclaimer {
  padding: 6px 16px 10px;
  font-size: 0.75rem;
  color: #92400e;
  background: var(--warning-light);
  text-align: center;
}

/* ── Chat Box ── */
.chat-box {
  flex: 1;
  padding: 16px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 0;
  scroll-padding-bottom: 16px;
}
.chat-box::-webkit-scrollbar { width: 6px; }
.chat-box::-webkit-scrollbar-track { background: transparent; }
.chat-box::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

.chat-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 0.85rem;
  text-align: center;
}

/* ── Chat Bubbles ── */
.bubble {
  max-width: 88%;
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 0.95rem;
  line-height: 1.7;
  word-break: break-word;
  white-space: pre-wrap;
}
.bubble.user {
  align-self: flex-end;
  background: var(--accent);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.bubble.ai {
  align-self: flex-start;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  color: var(--text);
  border-bottom-left-radius: 4px;
}
.bubble .bubble-label {
  font-size: 0.7rem;
  font-weight: 600;
  opacity: 0.7;
  margin-bottom: 4px;
}
.bubble.user .bubble-label { color: rgba(255,255,255,0.8); }

/* ── Bubble Image ── */
.bubble-image { margin: 4px 0 6px; max-width: 280px; }
.bubble-image img {
  max-width: 100%;
  max-height: 200px;
  border-radius: var(--radius-sm);
  object-fit: contain;
  cursor: pointer;
  transition: transform var(--transition);
  border: 1px solid rgba(0,0,0,0.1);
}
.bubble-image img:hover { transform: scale(1.02); }
.bubble.user .bubble-image img { border-color: rgba(255,255,255,0.2); }

.system-msg {
  text-align: center;
  font-size: 0.75rem;
  color: var(--text-muted);
  padding: 6px 0;
}
.system-msg::before { content: "— "; }
.system-msg::after { content: " —"; }

.typing .dots { animation: blink 1.2s infinite; }
@keyframes blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

/* ── Image Preview ── */
.image-preview { display: flex; padding: 8px 16px 4px; }
.image-preview-inner { position: relative; display: inline-block; max-width: 120px; }
.image-preview-inner img {
  max-width: 120px;
  max-height: 90px;
  border-radius: var(--radius-sm);
  border: 2px solid var(--accent);
  object-fit: cover;
}
.image-preview-close {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--danger);
  color: #fff;
  border: 2px solid var(--surface);
  font-size: 0.7rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

/* ── Chat Input ── */
.chat-input-bar {
  display: flex;
  gap: 8px;
  padding: 10px 16px;
  align-items: flex-end;
  border-top: 1px solid var(--border-light);
  background: linear-gradient(180deg, rgba(255,255,255,0.92), rgba(255,247,240,0.98));
  flex-shrink: 0;
}
.chat-input-bar textarea {
  flex: 1;
  padding: 12px 16px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  font-family: var(--font);
  color: var(--text);
  resize: none;
  outline: none;
  line-height: 1.5;
  max-height: 120px;
  transition: border-color var(--transition);
}
.chat-input-bar textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(255, 140, 66, 0.15);
}
.chat-input-bar textarea::placeholder { color: var(--text-muted); }

.chat-input-bar textarea.voice-interim { color: var(--text-muted); }

/* ── Send Button (orange capsule) ── */
.chat-input-bar .btn-primary {
  padding: 10px 24px;
  border-radius: 24px;
  height: auto;
}

/* ── Attach Button ── */
.btn-attach {
  width: 44px;
  height: 44px;
  padding: 0;
  border: 1.5px solid var(--border);
  border-radius: 50%;
  background: var(--surface);
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all var(--transition);
  flex-shrink: 0;
}
.btn-attach:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-light);
}

/* ── Mic Button ── */
.btn-mic {
  width: 44px;
  height: 44px;
  padding: 0;
  border: 1.5px solid var(--border);
  border-radius: 50%;
  background: var(--surface);
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all var(--transition);
  flex-shrink: 0;
}
.btn-mic:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-light);
}
.btn-mic.recording {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-light);
  animation: mic-pulse 1s ease-in-out infinite;
}
@keyframes mic-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255, 140, 66, 0.3); }
  50% { box-shadow: 0 0 0 6px rgba(255, 140, 66, 0); }
}
.btn-mic.unsupported { opacity: 0.3; cursor: not-allowed; }

/* ── Mic Wrap + Volume Meter ── */
.mic-wrap { position: relative; display: flex; align-items: flex-end; flex-shrink: 0; }
.volume-meter {
  position: absolute;
  bottom: 48px;
  left: 50%;
  transform: translateX(-50%);
  width: 6px;
  height: 40px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
}
.volume-bar {
  position: absolute;
  bottom: 0;
  width: 100%;
  height: 0%;
  border-radius: 3px;
  background: var(--success);
  transition: height 0.08s linear, background 0.15s ease;
}

/* ── Streaming Cursor ── */
.bubble-text.streaming::after {
  content: "\25CE";
  animation: cursor-blink 0.6s step-end infinite;
  color: var(--accent);
  font-weight: 300;
}
@keyframes cursor-blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0; }
}

/* ── Chips ── */
.chip-group { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-block;
  padding: 5px 12px;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  font-size: 0.78rem;
  font-family: var(--font);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition);
  text-align: left;
  line-height: 1.4;
}
.chip:hover {
  background: var(--accent-light);
  color: var(--accent);
  border-color: var(--accent);
}

/* ── Error Message ── */
.error-msg {
  color: var(--danger);
  font-size: 0.82rem;
  margin-top: 10px;
  text-align: center;
}

/* ── Success Message ── */
.success-msg {
  color: var(--success);
  font-size: 0.82rem;
  margin-top: 10px;
  text-align: center;
}

/* ══════════════════════════════════════
   ADMIN STYLES
   ══════════════════════════════════════ */

.admin-tabs {
  display: flex;
  gap: 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 4px;
  margin-bottom: 20px;
}
.admin-tab {
  flex: 1;
  padding: 10px 16px;
  border: none;
  border-radius: 6px;
  background: transparent;
  font-size: 0.85rem;
  font-weight: 500;
  font-family: var(--font);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition);
  text-align: center;
}
.admin-tab:hover { background: var(--surface-alt); }
.admin-tab.active {
  background: var(--accent);
  color: #fff;
  font-weight: 600;
}

.tab-panel { display: none; }
.tab-panel.active { display: block; }

.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 14px;
}
.stat-card { text-align: center; padding: 20px 14px; }
.stat-card .stat-value { font-size: 1.8rem; font-weight: 700; color: var(--accent); }
.stat-card .stat-label { font-size: 0.8rem; color: var(--text-muted); margin-top: 4px; }

.filter-bar { display: flex; flex-wrap: wrap; gap: 10px; align-items: end; }
.filter-bar .field { min-width: 120px; }
.filter-bar .field input,
.filter-bar .field select { padding: 8px 10px; font-size: 0.82rem; }

.table-wrap { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: 0.8rem; }
.data-table th {
  background: var(--surface-alt);
  font-weight: 600;
  color: var(--text-secondary);
  padding: 10px 12px;
  text-align: left;
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
}
.data-table td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border-light);
  color: var(--text);
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.data-table tr:hover td { background: #FFF8F0; }

.session-list { display: flex; flex-direction: column; gap: 6px; max-height: 300px; overflow-y: auto; }
.session-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px;
  background: var(--surface-alt);
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  cursor: pointer;
  transition: background var(--transition);
}
.session-item:hover { background: var(--accent-light); }

.transcript-box {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 16px;
  max-height: 400px;
  overflow-y: auto;
  font-size: 0.82rem;
  line-height: 1.7;
}
.transcript-box .t-row { padding: 8px 0; border-bottom: 1px solid var(--border-light); }
.transcript-box .t-row:last-child { border-bottom: none; }
.transcript-box .t-label { font-weight: 600; font-size: 0.75rem; color: var(--text-muted); }
.transcript-box .t-text { margin-top: 2px; white-space: pre-wrap; }

.config-form { display: flex; flex-direction: column; gap: 16px; }

/* ── Config Grid ── */
.config-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.pill { display: inline-block; padding: 3px 10px; border-radius: var(--radius-full); font-size: 0.7rem; font-weight: 600; }
.pill-chat { background: #dbeafe; color: #1d4ed8; }
.pill-reflect { background: #fce7f3; color: #be185d; }
.pill-event { background: var(--surface-alt); color: var(--text-muted); }

.info-list { list-style: none; counter-reset: info; }
.info-list li {
  counter-increment: info;
  padding: 6px 0 6px 28px;
  position: relative;
  font-size: 0.85rem;
  color: var(--text-secondary);
}
.info-list li::before {
  content: counter(info);
  position: absolute;
  left: 0;
  width: 20px; height: 20px;
  background: var(--accent-light);
  color: var(--accent);
  border-radius: 50%;
  font-size: 0.7rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ── Markdown Rendering ── */
.bubble-text strong { font-weight: 700; }
.bubble-text em { font-style: italic; }
.md-h1 { font-size: 1.1rem; font-weight: 700; margin: 8px 0 4px; }
.md-h2 { font-size: 1rem; font-weight: 700; margin: 6px 0 3px; }
.md-h3 { font-size: 0.95rem; font-weight: 600; margin: 4px 0 2px; }
.md-li { padding-left: 8px; margin: 2px 0; }
.md-code-block {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  margin: 6px 0;
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: 0.82rem;
  line-height: 1.5;
  white-space: pre-wrap;
}
.md-inline-code {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 5px;
  font-family: var(--font-mono);
  font-size: 0.85em;
}

/* ── Responsive ── */
@media (max-width: 900px) {
  .split-layout {
    min-height: auto;
  }
  .chat-panel {
    height: clamp(420px, calc(100vh - 210px), 620px);
  }
  .config-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 480px) {
  .entry-form { grid-template-columns: 1fr; }
  .page-header { padding: 12px 8px 10px; }
  .page-header h1 { font-size: 1.2rem; }
  .split-layout { gap: 10px; }
  .chat-panel { height: clamp(360px, calc(100vh - 200px), 540px); }
  .bubble { max-width: 92%; }
  .config-grid { grid-template-columns: 1fr; }
}
