* { box-sizing: border-box; }
:root{
  --bg:#f6f4ff;
  --primary:#7c3aed;
  --primary-600:#6a2fd6;
  --accent:#f97316;
  --accent-200:#ffe7d3;
  --muted:#eef2ff;
  --text:#1f2937;
  --border:#e5e7eb;
  --ring: rgba(124,58,237,.28);
  --shadow: 0 10px 30px rgba(18, 16, 45, .08);
}
html,body{ height:100%; }
body { margin:0; font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, sans-serif; background: var(--bg); color:var(--text); }
.app { max-width: 1100px; margin: 0 auto; display: grid; grid-template-rows: auto auto 1fr auto; gap:14px; min-height: 100vh; padding: 14px; }

.brand { display:flex; align-items:center; justify-content: space-between; gap:12px; padding: 10px 6px; }
.brand-left { display:flex; align-items:center; gap:10px; }
.mascot { width:42px; height:42px; border-radius: 50%; box-shadow: var(--shadow); background: #fff; display:grid; place-items:center; }
.titles h1 { margin:0; font-size:20px; color:var(--primary); display:flex; gap:6px; align-items:center; }

.badge-status { display:inline-flex; align-items:center; gap:8px; padding:6px 10px; border-radius: 999px; font-size:12px; border:1px solid var(--border); background:#fff; box-shadow: var(--shadow); }
.badge-status svg { opacity:.9; }
.badge-status.online { border-color:#c4f1be; background:#f0fff4; }
.badge-status.offline { opacity:.9; }

.card{ background:#fff; border:1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow); }
.panel { overflow:hidden; }
.panel-head{ display:flex; align-items:center; justify-content: space-between; gap:10px; padding: 12px 14px; cursor:pointer; }
.panel-title{ display:flex; align-items:center; gap:8px; }
.panel-title svg { transform: rotate(-90deg); transition: transform .18s ease; }
.panel.open .panel-title svg { transform: rotate(0deg); }
.panel-title .muted{ color:#6b7280; margin-left:4px; }
.panel-kpis{ display:flex; gap:12px; }
.kpi{ padding:4px 8px; background: var(--muted); border-radius: 999px; font-size:12px; }

.panel-body{ padding: 10px 14px 14px; display:none; }
.panel.open .panel-body{ display:block; }
.grid{ display:grid; grid-template-columns: repeat(5, minmax(140px,1fr)); gap:10px; }
.field{ display:flex; flex-direction: column; gap:6px; }
.field label{ font-size:12px; opacity:.85; }
.field input, .field select{
  padding:9px 10px; border-radius:10px; border:1px solid var(--border); outline:none;
  transition: box-shadow .2s ease, border-color .2s ease;
}
.field input:focus, .field select:focus{ border-color: var(--primary); box-shadow: 0 0 0 4px var(--ring); }

.stt-row{ display:flex; flex-wrap:wrap; gap:10px; align-items:center; margin-top: 6px; }

.btn{ padding:9px 12px; border-radius: 10px; border:1px solid var(--border); background:#fff; cursor:pointer; transition: transform .06s ease, box-shadow .2s ease, background .2s ease, border-color .2s ease; }
.btn:hover{ transform: translateY(-1px); box-shadow: 0 8px 16px rgba(0,0,0,.06); }
.btn:active{ transform: translateY(0); }
.btn:focus-visible{ outline:none; box-shadow: 0 0 0 4px var(--ring); }
.btn.primary{ background: linear-gradient(135deg, var(--primary), var(--accent)); color:#fff; border-color: transparent; }
.btn.primary:hover{ filter: brightness(0.98); }
.btn.ghost{ color: var(--primary); font-weight: 700; }
.btn.mic{ background:#fff; border-color:var(--accent); color: var(--accent); font-weight:700; }
.btn.mic.mic-on{ background: var(--accent); color:#fff; }

.mic-status{ margin-left:auto; padding:4px 8px; background: var(--muted); border-radius: 8px; font-size:12px; }

main#chat { padding: 14px; overflow-y: auto; display:flex; flex-direction: column; gap:10px; }
.msg { display:flex; gap:10px; align-items: flex-start; }
.msg .bubble { padding:10px 12px; border-radius: 12px; max-width: 72%; box-shadow: 0 1px 2px rgba(0,0,0,0.06); border:1px solid var(--border); }
.msg.child .bubble { background: #fff; border-top-left-radius: 4px; }
.msg.bear .bubble { background: #f3e8ff; border-top-right-radius: 4px; border-color:#ead8ff; }
.msg.sys .bubble { background: #f9fafb; }
.msg .who { font-size: 11px; opacity: 0.6; margin-bottom: 2px; }

/* Audio card + equalizer */
.audio-wrap{ display:flex; align-items:center; gap:10px; margin-top:6px; }
.eq { display:inline-grid; grid-auto-flow: column; gap:3px; height: 18px; align-items:end; }
.eq span{ width:4px; background: var(--primary); border-radius: 2px; height: 4px; opacity:.55; }
.audio-wrap.playing .eq span{ animation: bounce 1s ease-in-out infinite; }
.audio-wrap.playing .eq span:nth-child(2){ animation-delay:.2s; }
.audio-wrap.playing .eq span:nth-child(3){ animation-delay:.4s; }
@keyframes bounce{ 0%,100%{ height:4px; opacity:.55; } 40%{ height:18px; opacity:1; } }

/* Footer + upload progress */
.footer{ position: relative; display:grid; grid-template-columns: 1fr auto auto; gap: 10px; align-items:center; padding: 12px; }
.footer input { width: 100%; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--border); transition: box-shadow .2s ease, border-color .2s ease; }
.footer input:focus{ border-color: var(--primary); box-shadow: 0 0 0 4px var(--ring); }
.footer .btn.primary{ font-weight:800; letter-spacing:.2px; }

.upload-progress{ position:absolute; left:10px; right:10px; top:0; height:4px; border-radius: 999px; background: #f1f5f9; overflow: hidden; }
.upload-progress .bar{ height:100%; background: linear-gradient(90deg, var(--primary), var(--accent)); width:0%; transition: width .15s ease; }

/* Mic icon button */
.btn-icon { position: relative; width: 46px; height: 46px; display:grid; place-items:center; border-radius: 12px; border: 1px solid var(--border); background: #fff; cursor:pointer; transition: transform .06s ease, box-shadow .2s ease; }
.btn-icon:hover{ transform: translateY(-1px); box-shadow: 0 10px 18px rgba(0,0,0,.08); }
.btn-icon:focus-visible{ outline:none; box-shadow: 0 0 0 4px var(--ring); }
.btn-icon svg { display:block; }

#btnRec.rec-idle { border-color: var(--border); }
#btnRec.rec-on   { border-color: var(--accent); background: var(--accent-200); animation: pulse 1.2s infinite; box-shadow: 0 0 0 0 rgba(249,115,22,.45); }
#btnRec.rec-upload { border-color:var(--primary); background:#f2ebff; animation:none; opacity: .96; }

@keyframes pulse { 0%{box-shadow:0 0 0 0 rgba(249,115,22,.45);} 70%{box-shadow:0 0 0 12px rgba(249,115,22,0);} 100%{box-shadow:0 0 0 0 rgba(249,115,22,0);} }

.badge { position:absolute; top:-7px; right:-7px; background: var(--accent); color:#fff; font-size: 11px; line-height: 1; padding: 4px 6px; border-radius: 10px; box-shadow: 0 2px 6px rgba(0,0,0,.2); }

.spinner { position: absolute; bottom: -7px; right: -7px; width: 16px; height: 16px; border: 2px solid #cbd5e0; border-top-color: var(--primary); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Typing indicator + fade-out */
.typing .bubble { background: #f9fafb; }
.typing-dots{
  display: inline-flex;
  gap: 6px;
  align-items: center;
  padding: 2px 0;
}
.typing-dots span{
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--primary);
  opacity: .35;
  animation: dotBlink 1.2s ease-in-out infinite;
}
.typing-dots span:nth-child(2){ animation-delay: .15s; }
.typing-dots span:nth-child(3){ animation-delay: .30s; }

@keyframes dotBlink {
  0%, 80%, 100% { opacity: .25; transform: translateY(0); }
  40% { opacity: 1; transform: translateY(-2px); }
}
.typing-dots.fade-out {
  opacity: 0;
  transition: opacity 0.3s ease-out;
}

@media (max-width: 820px) {
  .grid{ grid-template-columns: repeat(2, minmax(140px,1fr)); }
}
@media (max-width: 520px) {
  .footer { grid-template-columns: 1fr auto; }
}
