:root {
  --bg-color: #f3f4f6;
  --header-bg: #ffffff;
  --user-bubble: #95ec69;
  --char-bubble: #ffffff;
  --text-main: #1f2937;
  --text-muted: #6b7280;
  --primary-color: #3b82f6;
  --action-pill-bg: #e5e7eb;
  --border-color: #e5e7eb;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.05);
}

* {
  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: #1e1e1e;
  color: var(--text-main);
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
}

.app-container {
  width: 100%;
  max-width: 480px;
  height: 100vh;
  height: 100dvh;
  background-color: var(--bg-color);
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.3);
}

.app-header {
  height: 56px;
  background-color: var(--header-bg);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 14px;
  z-index: 10;
  flex-shrink: 0;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.avatar-badge {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: #e0e7ff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  box-shadow: var(--shadow-sm);
}

.character-info {
  display: flex;
  flex-direction: column;
}

.character-title {
  font-size: 16px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 6px;
}

.routine-status {
  font-size: 11px;
  color: #10b981;
  display: flex;
  align-items: center;
  gap: 4px;
}

.routine-status .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background-color: #10b981;
}

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

.btn-icon {
  background: none;
  border: none;
  font-size: 18px;
  cursor: pointer;
  padding: 6px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #4b5563;
}

.btn-icon:hover {
  background-color: #f3f4f6;
}

.switchers-bar {
  background: #ffffff;
  padding: 6px 14px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  gap: 10px;
  font-size: 12px;
}

.switcher-group {
  display: flex;
  align-items: center;
  gap: 4px;
  flex: 1;
}

.switcher-group select {
  flex: 1;
  font-size: 12px;
  padding: 4px 6px;
  border-radius: 6px;
  border: 1px solid #d1d5db;
  background-color: #fff;
  color: #374151;
  outline: none;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  scroll-behavior: smooth;
}

.message-turn {
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: 100%;
}

.message-turn.user {
  align-items: flex-end;
}

.message-turn.character {
  align-items: flex-start;
}

.micro-action-pill {
  align-self: flex-start;
  background-color: var(--action-pill-bg);
  color: #4b5563;
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 12px;
  margin-bottom: 4px;
  margin-left: 42px;
  font-style: italic;
  max-width: 80%;
  line-height: 1.4;
  box-shadow: 0 1px 2px rgba(0,0,0,0.03);
}

.character-body {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  width: 100%;
}

.character-avatar-small {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: #e0e7ff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
}

.bubbles-container {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-width: 75%;
}

.bubble {
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 14px;
  line-height: 1.5;
  word-break: break-word;
  position: relative;
  box-shadow: var(--shadow-sm);
  animation: fadeInBubble 0.25s ease-out;
}

.message-turn.user .bubble {
  background-color: var(--user-bubble);
  color: #000000;
  border-bottom-right-radius: 4px;
  align-self: flex-end;
}

.message-turn.character .bubble {
  background-color: var(--char-bubble);
  color: var(--text-main);
  border-top-left-radius: 4px;
  align-self: flex-start;
}

.bubble-meta {
  font-size: 10px;
  color: var(--text-muted);
  margin-top: 4px;
  display: flex;
  justify-content: flex-end;
  gap: 6px;
}

.voice-btn {
  cursor: pointer;
  opacity: 0.6;
  font-size: 11px;
}
.voice-btn:hover {
  opacity: 1;
}

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

.typing-box {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: 42px;
  font-size: 12px;
  color: var(--text-muted);
}

.typing-dots {
  display: flex;
  gap: 4px;
}

.typing-dots span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background-color: #9ca3af;
  animation: typingBounce 1.2s infinite ease-in-out;
}

.typing-dots span:nth-child(2) {
  animation-delay: 0.2s;
}

.typing-dots span:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes typingBounce {
  0%, 80%, 100% { transform: translateY(0); }
  40% { transform: translateY(-5px); }
}

.chat-input-bar {
  background-color: #ffffff;
  border-top: 1px solid var(--border-color);
  padding: 8px 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.input-tools {
  display: flex;
  gap: 4px;
}

.input-field {
  flex: 1;
  background-color: #f3f4f6;
  border: 1px solid #e5e7eb;
  border-radius: 20px;
  padding: 8px 14px;
  font-size: 14px;
  outline: none;
  color: var(--text-main);
  transition: border-color 0.2s;
}

.input-field:focus {
  border-color: var(--primary-color);
  background-color: #ffffff;
}

.btn-send {
  background-color: #10b981;
  color: #ffffff;
  border: none;
  border-radius: 20px;
  padding: 8px 16px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background-color 0.2s;
}

.btn-send:hover {
  background-color: #059669;
}

.btn-send:disabled {
  background-color: #d1d5db;
  cursor: not-allowed;
}

.modal-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 100;
  display: none;
  justify-content: center;
  align-items: flex-end;
}

.modal-overlay.active {
  display: flex;
}

.modal-content {
  background: #ffffff;
  width: 100%;
  max-height: 80vh;
  border-top-left-radius: 16px;
  border-top-right-radius: 16px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: slideUp 0.3s ease-out;
}

@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

.modal-header {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 16px;
  font-weight: 600;
}

.modal-body {
  padding: 16px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  font-size: 13px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.form-group label {
  font-weight: 500;
  color: #374151;
}

.form-group input, .form-group select, .form-group textarea {
  padding: 8px;
  border-radius: 6px;
  border: 1px solid #d1d5db;
  font-size: 13px;
  outline: none;
}

.memory-item {
  border: 1px solid #e5e7eb;
  padding: 10px;
  border-radius: 8px;
  background: #f9fafb;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.memory-item-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 11px;
  color: var(--text-muted);
}

.badge {
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 600;
}

.badge.L2 { background: #dbeafe; color: #1e40af; }
.badge.L3 { background: #fef3c7; color: #92400e; }

.memory-item-content {
  font-size: 13px;
  color: #1f2937;
}

.memory-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

.btn-small {
  padding: 4px 8px;
  font-size: 11px;
  border-radius: 4px;
  border: 1px solid #d1d5db;
  background: #fff;
  cursor: pointer;
}

.btn-danger {
  color: #dc2626;
  border-color: #fca5a5;
}

.network-offline-banner {
  background: #fef2f2;
  color: #b91c1c;
  font-size: 11px;
  padding: 4px 10px;
  text-align: center;
  display: none;
}

@media (max-width: 390px) {
  .bubble {
    font-size: 13px;
    padding: 8px 12px;
  }
  .micro-action-pill {
    font-size: 11px;
    margin-left: 36px;
  }
  .character-title {
    font-size: 15px;
  }
}
