:root {
  --bg-color: #09090b;
  --card-bg: #18181b;
  --card-border: #27272a;
  --text-main: #f4f4f5;
  --text-muted: #a1a1aa;
  --primary: #6366f1;
  --primary-hover: #4f46e5;
  --accent-green: #10b981;
  --accent-amber: #f59e0b;
  --accent-purple: #a855f7;
  --radius: 16px;
  --safe-top: env(safe-area-inset-top, 20px);
  --safe-bottom: env(safe-area-inset-bottom, 20px);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background-color: var(--bg-color);
  color: var(--text-main);
  min-height: 100dvh;
  height: 100dvh;
  overflow: hidden;
  padding-top: var(--safe-top);
}

.app-container {
  display: flex;
  flex-direction: column;
  height: 100%;
  max-width: 680px;
  margin: 0 auto;
  position: relative;
}

/* Header */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  border-bottom: 1px solid var(--card-border);
  background: var(--bg-color);
  z-index: 10;
}

.logo-area {
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo-icon {
  font-size: 22px;
  background: rgba(99, 102, 241, 0.15);
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  border: 1px solid rgba(99, 102, 241, 0.3);
}

.logo-title h1 {
  font-size: 16px;
  font-weight: 600;
}

.logo-sub {
  font-size: 11px;
  color: var(--text-muted);
}

.header-actions {
  display: flex;
  gap: 8px;
}

.icon-btn {
  background: #27272a;
  border: none;
  color: var(--text-main);
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  cursor: pointer;
}

.icon-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

/* Status Banner */
.status-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  background: rgba(24, 24, 27, 0.7);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid rgba(39, 39, 42, 0.6);
  z-index: 9;
}

.status-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 12px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.3s;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.status-idle {
  background: rgba(161, 161, 170, 0.12);
  color: var(--text-muted);
}
.status-idle .status-dot { background: #71717a; }

.status-listening {
  background: rgba(16, 185, 129, 0.15);
  color: var(--accent-green);
  border: 1px solid rgba(16, 185, 129, 0.3);
}
.status-listening .status-dot {
  background: var(--accent-green);
  box-shadow: 0 0 10px var(--accent-green);
  animation: pulse-green 1.5s infinite;
}

.status-woken {
  background: rgba(245, 158, 11, 0.18);
  color: var(--accent-amber);
  border: 1px solid rgba(245, 158, 11, 0.4);
}
.status-woken .status-dot {
  background: var(--accent-amber);
  animation: pulse-amber 0.8s infinite;
}

.status-thinking {
  background: rgba(168, 85, 247, 0.18);
  color: var(--accent-purple);
  border: 1px solid rgba(168, 85, 247, 0.4);
}
.status-thinking .status-dot {
  background: var(--accent-purple);
  animation: pulse-purple 1s infinite;
}

.status-answering {
  background: rgba(99, 102, 241, 0.18);
  color: #818cf8;
  border: 1px solid rgba(99, 102, 241, 0.4);
}
.status-answering .status-dot {
  background: #818cf8;
}

@keyframes pulse-green {
  0% { opacity: 0.4; transform: scale(0.9); }
  50% { opacity: 1; transform: scale(1.2); }
  100% { opacity: 0.4; transform: scale(0.9); }
}

@keyframes pulse-amber {
  0% { opacity: 0.5; transform: scale(0.85); }
  50% { opacity: 1; transform: scale(1.3); }
  100% { opacity: 0.5; transform: scale(0.85); }
}

@keyframes pulse-purple {
  0% { opacity: 0.5; }
  50% { opacity: 1; }
  100% { opacity: 0.5; }
}

.tts-switch-pill {
  display: flex;
  align-items: center;
}

.switch-label {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  color: var(--text-muted);
  cursor: pointer;
}

.switch-label input {
  accent-color: var(--primary);
  width: 14px;
  height: 14px;
}

.btn-subtle {
  background: transparent;
  border: 1px solid #3f3f46;
  color: var(--text-muted);
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 12px;
  cursor: pointer;
}

/* Chat Timeline Container */
.chat-container {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
}

.chat-welcome {
  text-align: center;
  padding: 24px 16px;
  color: #71717a;
  font-size: 13px;
  line-height: 1.6;
}

.welcome-badge {
  display: inline-block;
  background: rgba(99, 102, 241, 0.12);
  color: #a5b4fc;
  font-size: 12px;
  padding: 4px 12px;
  border-radius: 20px;
  margin-bottom: 8px;
}

.chat-messages {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* Chat Message Bubbles */
.chat-msg {
  display: flex;
  flex-direction: column;
  border-radius: var(--radius);
  padding: 14px 16px;
  animation: fadeIn 0.25s ease;
  position: relative;
}

.user-msg {
  background: #18181b;
  border: 1px solid var(--card-border);
  align-self: stretch;
}

.assistant-msg {
  background: rgba(99, 102, 241, 0.08);
  border: 1px solid rgba(99, 102, 241, 0.25);
  align-self: stretch;
}

.msg-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
  font-weight: 600;
  margin-bottom: 8px;
}

.user-msg .msg-header { color: #a1a1aa; }
.assistant-msg .msg-header { color: #818cf8; }

.msg-time {
  font-size: 11px;
  color: #71717a;
  font-weight: normal;
}

.msg-body-full {
  font-size: 14px;
  line-height: 1.6;
  color: #e4e4e7;
  white-space: pre-wrap;
  word-break: break-word;
  user-select: text;
}

.intent-pill {
  margin-top: 10px;
  padding: 8px 12px;
  background: rgba(245, 158, 11, 0.12);
  border: 1px dashed rgba(245, 158, 11, 0.4);
  border-radius: 8px;
  font-size: 13px;
  color: #fde68a;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.intent-label {
  font-size: 11px;
  color: var(--accent-amber);
  font-weight: 600;
}

/* Collapsible Content for Long Assistant Answers */
.collapsible-wrapper {
  position: relative;
  overflow: hidden;
  font-size: 14px;
  line-height: 1.6;
  color: #e4e4e7;
  white-space: pre-wrap;
  word-break: break-word;
  user-select: text;
  transition: max-height 0.3s ease;
}

.collapsible-wrapper.collapsed {
  max-height: 160px;
}

.collapsible-wrapper.collapsed::after {
  content: '';
  position: absolute;
  bottom: 0; left: 0; right: 0;
  height: 50px;
  background: linear-gradient(180deg, transparent 0%, #141426 100%);
  pointer-events: none;
}

.collapse-toggle-btn {
  background: none;
  border: none;
  color: var(--primary);
  font-size: 12px;
  font-weight: 500;
  padding: 6px 0 0 0;
  cursor: pointer;
  align-self: flex-start;
}

/* Standard Chat Bottom Input Bar */
.chat-input-bar {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 8px 12px max(12px, env(safe-area-inset-bottom)) 12px;
  background: #121214;
  border-top: 1px solid var(--card-border);
  z-index: 10;
}

.mic-toggle-btn {
  position: relative;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: #27272a;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-bottom: 2px;
  transition: all 0.2s;
}

.mic-icon {
  font-size: 18px;
  z-index: 2;
}

.mic-toggle-btn.active {
  background: var(--accent-green);
  box-shadow: 0 0 16px rgba(16, 185, 129, 0.5);
}

.mic-wave-ring {
  position: absolute;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgba(16, 185, 129, 0.4);
  z-index: 1;
  opacity: 0;
}

.mic-toggle-btn.active .mic-wave-ring {
  opacity: 1;
  animation: pulse-ring 1.8s infinite;
}

@keyframes pulse-ring {
  0% { transform: scale(1); opacity: 0.8; }
  100% { transform: scale(1.6); opacity: 0; }
}

.input-box-wrapper {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: #18181b;
  border: 1px solid #27272a;
  border-radius: 20px;
  padding: 8px 14px;
  min-height: 40px;
  transition: border-color 0.2s;
}

.input-box-wrapper:focus-within {
  border-color: var(--primary);
}

.chat-input {
  width: 100%;
  background: transparent;
  border: none;
  color: var(--text-main);
  font-size: 15px;
  line-height: 1.5;
  resize: none;
  outline: none;
  font-family: inherit;
  box-sizing: border-box;
  max-height: 200px;
  min-height: 24px;
  overflow-y: auto;
}

.chat-input::placeholder {
  color: #52525b;
  font-size: 13px;
}

.intent-tag-indicator {
  font-size: 11px;
  color: var(--accent-amber);
  background: rgba(245, 158, 11, 0.12);
  padding: 3px 8px;
  border-radius: 6px;
  margin-bottom: 6px;
  animation: fadeIn 0.2s ease;
}

.send-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: var(--primary);
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-bottom: 2px;
  transition: all 0.2s;
}

.send-btn:active {
  transform: scale(0.92);
}

.send-icon {
  font-size: 16px;
  transform: rotate(-30deg) translate(1px, -1px);
}

/* Scroll to bottom floating button */
.scroll-bottom-btn {
  position: absolute;
  bottom: 75px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(39, 39, 42, 0.92);
  backdrop-filter: blur(8px);
  border: 1px solid #52525b;
  color: var(--text-main);
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 12px;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(0,0,0,0.5);
  z-index: 20;
  animation: fadeIn 0.2s ease;
}

/* Pocket Mode Overlay */
.pocket-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: #000000;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
}

.pocket-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  text-align: center;
  padding: 24px;
}

.pocket-pulse-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #10b981;
  box-shadow: 0 0 16px #10b981;
  animation: pulse-green 2s infinite;
}

.pocket-status-text {
  font-size: 15px;
  color: #71717a;
}

.pocket-hint {
  font-size: 12px;
  color: #3f3f46;
}

.unlock-btn {
  background: #18181b;
  color: #a1a1aa;
  border: 1px solid #27272a;
  padding: 12px 28px;
  border-radius: 30px;
  font-size: 14px;
  cursor: pointer;
  margin-top: 20px;
}

/* Modal */
.modal {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(8px);
  z-index: 1000;
  display: flex;
  align-items: flex-end;
}

.modal-card {
  background: var(--card-bg);
  border-top-left-radius: 24px;
  border-top-right-radius: 24px;
  border: 1px solid var(--card-border);
  width: 100%;
  max-width: 680px;
  margin: 0 auto;
  padding: 20px 24px calc(24px + var(--safe-bottom)) 24px;
  animation: slideUp 0.3s ease;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.close-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 24px;
  cursor: pointer;
}

.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  font-size: 13px;
  color: var(--text-main);
  margin-bottom: 8px;
}

.form-group input, .form-group select {
  width: 100%;
  padding: 12px 14px;
  background: #121214;
  border: 1px solid var(--card-border);
  border-radius: 10px;
  color: var(--text-main);
  font-size: 14px;
  outline: none;
}

.form-hint {
  font-size: 11px;
  color: #71717a;
  display: block;
  margin-top: 5px;
}

.btn-primary {
  background: var(--primary);
  border: none;
  color: white;
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 13px;
  cursor: pointer;
}

.full-width {
  width: 100%;
  padding: 12px;
  font-size: 15px;
}

.hidden {
  display: none !important;
}

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

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}
