/* AETHET - Clean Responsive CSS - fix trace inside bubble */
:root {
  --bg: #0e0e10;
  --bg2: #151517;
  --sidebar: #111113;
  --border: #262629;
  --border-hover: #3a3a3f;
  --text: #ececec;
  --muted: #8a8a90;
  --muted2: #55555c;
  --accent: #fff;
  --bubble-user: #1e1e20;
  --bubble-assistant: #17171a;
  --trace-bg: #1a1a1e;
  --radius: 14px;
  --sidebar-w: 280px;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}
.mobile-header {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 56px;
  background: var(--sidebar);
  border-bottom: 1px solid var(--border);
  z-index: 50;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
}
.menu-btn {
  background: none; border: none; color: var(--text); font-size: 20px; cursor: pointer;
  width: 36px; height: 36px; border-radius: 8px;
}
.menu-btn:hover { background: var(--bg2); }
.mobile-logo { font-weight: 800; letter-spacing: 1px; }
.mobile-mode { font-size: 11px; color: var(--muted); border: 1px solid var(--border); padding: 4px 8px; border-radius: 20px; }
.sidebar {
  width: var(--sidebar-w);
  background: var(--sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 24px 16px;
  flex-shrink: 0;
  z-index: 40;
  transition: transform .25s ease;
}
.sidebar-top { flex: 1; }
.logo { margin-bottom: 28px; }
.logo-title { display: block; font-size: 26px; font-weight: 900; letter-spacing: 2px; line-height: 1; }
.logo-sub { display: block; font-size: 12px; color: var(--muted); margin-top: 6px; letter-spacing: .3px; }
.mode-group { margin-bottom: 20px; }
.mode-label { font-size: 11px; text-transform: uppercase; letter-spacing: 1.2px; color: var(--muted2); margin-bottom: 10px; font-weight: 600; }
.mode-buttons { display: flex; flex-direction: column; gap: 8px; }
.mode-btn {
  text-align: left;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  color: var(--muted);
  cursor: pointer;
  transition: all .15s;
}
.mode-btn:hover { border-color: var(--border-hover); color: var(--text); }
.mode-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #000;
}
.mode-name { display: block; font-size: 13px; font-weight: 700; line-height: 1.2; }
.mode-desc { display: block; font-size: 11px; opacity: .7; margin-top: 3px; font-weight: 400; }
.mode-btn.active .mode-desc { opacity: .6; color: #000; }
.info-box {
  font-size: 11px; color: var(--muted2); line-height: 1.5;
  background: var(--bg2); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px;
}
.info-box code { color: var(--muted); background: #000; padding: 2px 5px; border-radius: 4px; }
.sidebar-bottom { padding-top: 20px; border-top: 1px solid var(--border); margin-top: 20px; }
.clear-btn {
  width: 100%; background: transparent; border: 1px solid var(--border); color: var(--muted);
  padding: 10px; border-radius: 10px; cursor: pointer; font-size: 12px;
}
.clear-btn:hover { border-color: #444; color: var(--text); }
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--bg);
}
.chat-area {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  scroll-behavior: smooth;
}
.message {
  display: flex; gap: 12px; max-width: 860px; width: 100%; margin: 0 auto;
  animation: fadeIn .2s ease;
}
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }
.avatar {
  width: 32px; height: 32px; border-radius: 50%; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 800;
}
.avatar.user { background: #fff; color: #000; }
.avatar.assistant { background: #222; color: #fff; border: 1px solid var(--border); }
.bubble {
  flex: 1;
  background: var(--bubble-assistant);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  min-width: 0;
}
.message:has(.avatar.user) .bubble { background: var(--bubble-user); }
.role {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .6px;
  color: var(--muted);
  margin-bottom: 6px;
  text-transform: uppercase;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.tts-btn {
  background: var(--bg2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  padding: 4px 8px;
  font-size: 10px;
  cursor: pointer;
  transition: all 0.2s;
  text-transform: none;
  letter-spacing: normal;
}
.tts-btn:hover { background: var(--border-hover); }
.tts-btn:disabled { opacity: 0.5; cursor: not-allowed; }

.content { font-size: 14.5px; line-height: 1.6; white-space: pre-wrap; word-break: break-word; }
.content.it { margin-top: 12px; padding-top: 12px; border-top: 1px dashed var(--border); color: #cfcfd6; }
.content.it b { color: var(--muted); }

/* TRACE */
.trace {
  width: 100%;
  margin: 0 0 12px 0;
  background: var(--trace-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
}
.trace-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 10px;
  cursor: pointer;
  background: #151518;
  user-select: none;
}
.trace-header:hover { background: #1a1a1e; }
.trace-title { font-size: 10px; color: var(--muted2); text-transform: uppercase; letter-spacing: .8px; font-weight: 700; }
.trace-toggle { font-size: 10px; color: var(--muted2); }
.trace-body {
  padding: 10px;
  display: flex; flex-direction: column; gap: 8px;
  max-height: 260px; overflow-y: auto;
}
.trace.collapsed .trace-body { display: none; }
.trace.collapsed .trace-toggle { transform: rotate(-90deg); }
.trace-item {
  font-size: 11.5px; background: #0f0f11; border: 1px solid var(--border); border-radius: 8px; padding: 7px 9px;
  color: #a0a0a8; word-break: break-word; white-space: pre-wrap;
}
.trace-item b { color: var(--text); font-size: 10.5px; text-transform: uppercase; letter-spacing: .5px; }
.trace-item.updated { border-color: #444; background: #1c1c1f; }

.source-card { margin-top: 4px; background: #141416; border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; }
.source-card b { color: var(--text); }
.source-card small { color: var(--muted); }
.typing { font-size: 11px; color: var(--muted2); margin: 0 auto; max-width: 860px; width: 100%; padding: 8px 24px 8px 68px; }

.input-area {
  border-top: 1px solid var(--border);
  padding: 16px 24px 12px;
  background: linear-gradient(to top, var(--bg) 60%, transparent);
}
.input-wrap {
  max-width: 860px; margin: 0 auto;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 10px 12px;
  display: flex; align-items: flex-end; gap: 10px;
  transition: border-color .15s;
}
.input-wrap:focus-within { border-color: var(--border-hover); }

/* STT Microphone Button */
.mic-btn {
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 18px;
  cursor: pointer;
  padding: 8px;
  flex-shrink: 0;
  transition: all 0.2s ease;
  border-radius: 50%;
}
.mic-btn:hover { color: var(--text); background: var(--bg); }
.mic-btn.recording {
  color: #ff4444;
  animation: pulse-record 1.5s infinite;
}
@keyframes pulse-record {
  0% { transform: scale(1); box-shadow: 0 0 0 0 rgba(255, 68, 68, 0.4); }
  70% { transform: scale(1.1); box-shadow: 0 0 0 6px rgba(255, 68, 68, 0); }
  100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(255, 68, 68, 0); }
}

textarea {
  flex: 1; background: transparent; border: none; outline: none; color: var(--text);
  resize: none; max-height: 160px; min-height: 24px; font-size: 15px; line-height: 1.5; font-family: inherit;
}
.send-btn {
  background: var(--accent); color: #000; border: none; border-radius: 10px;
  padding: 10px 18px; font-weight: 700; cursor: pointer; font-size: 13px; flex-shrink: 0;
  transition: opacity .15s, transform .1s;
}
.send-btn:active { transform: scale(.97); }
.send-btn:disabled { opacity: .4; cursor: not-allowed; }
.input-hint { max-width: 860px; margin: 8px auto 0; font-size: 11px; color: var(--muted2); text-align: center; }
.overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.6); z-index: 30; }

@media (max-width: 900px) {
  body { flex-direction: column; }
  .mobile-header { display: flex; }
  .sidebar {
    position: fixed; top: 56px; left: 0; bottom: 0;
    width: 85%; max-width: 320px;
    transform: translateX(-100%);
    border-right: 1px solid var(--border);
    padding: 20px 16px;
  }
  .sidebar.open { transform: translateX(0); }
  .overlay.show { display: block; }
  .main { padding-top: 56px; height: 100vh; }
  .chat-area { padding: 16px 14px; }
  .message { max-width: 100%; }
  .input-area { padding: 12px 14px calc(12px + env(safe-area-inset-bottom)); }
  .typing { padding-left: 14px; padding-right: 14px; }
}
@media (max-width: 480px) {
  .bubble { padding: 12px 14px; }
  .content { font-size: 15px; }
  textarea { font-size: 16px; }
  .input-wrap { border-radius: 14px; padding: 8px 10px; }
}

/* PATCH V3: fix TRACE hidden + THINKING + MD */
.trace.hidden { display: none !important; }
.thinking {
  display: block;
  background: #121214;
  border: 1px dashed #2a2a2e;
  border-left: 2px solid #555;
  border-radius: 8px;
  padding: 10px 12px;
  margin: 0 0 12px 0;
  font-size: 12px;
  line-height: 1.5;
  color: #999;
  white-space: pre-wrap;
  max-height: 200px;
  overflow-y: auto;
}
.thinking-label { font-size: 10px; letter-spacing: 1px; color: #666; font-weight: 700; margin-bottom: 6px; }
.content.md p { margin: 8px 0; }
.content.md strong { color: #fff; }
.content.md em { color: #ccc; }
.content.md code { background: #000; padding: 2px 5px; border-radius: 4px; font-size: 13px; }
.content.md pre { background: #000; border: 1px solid var(--border); padding: 12px; border-radius: 8px; overflow-x: auto; margin: 10px 0; }
.content.md ul, .content.md ol { margin: 8px 0 8px 18px; }
.content.md h1, .content.md h2, .content.md h3 { margin: 14px 0 6px; color: #fff; }
.pulse { animation: pulse 1s infinite; color: #666; }
@keyframes pulse { 0% { opacity: 1; } 50% { opacity: 0.3; } 100% { opacity: 1; } }
.it-label { font-size: 10px; font-weight: 700; color: var(--muted); margin-bottom: 4px; letter-spacing: .5px; }