*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --green: #07c160;
  --green-dark: #06ad56;
  --bg: #ededed;
  --bubble-self: #95ec69;
  --bubble-other: #fff;
  --header-bg: #2e3238;
  --header-text: #fff;
  --text: #1a1a1a;
  --text-secondary: #999;
  --border: #d9d9d9;
  --input-bg: #fff;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Noto Sans SC", "PingFang SC", sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  overflow: hidden;
}

.chat-app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  max-width: 100%;
  padding-bottom: constant(safe-area-inset-bottom);
  padding-bottom: env(safe-area-inset-bottom);
}

.chat-header {
  background: var(--header-bg);
  color: var(--header-text);
  text-align: center;
  padding: 12px 16px 10px;
  flex-shrink: 0;
}

.header-title {
  font-size: 17px;
  font-weight: 600;
}

.header-sub {
  font-size: 12px;
  opacity: .65;
  margin-top: 2px;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 12px 14px 6px;
  -webkit-overflow-scrolling: touch;
  scroll-behavior: smooth;
}

.msg-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text-secondary);
  font-size: 14px;
  gap: 10px;
  text-align: center;
  line-height: 1.6;
}

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

.msg-sender {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 4px;
}

.msg-sender .bubble {
  background: var(--bubble-self);
  border-radius: 8px 2px 8px 8px;
  padding: 9px 13px;
  max-width: 80%;
}

.msg-sender .label-tag {
  font-size: 11px;
  color: var(--text-secondary);
  text-align: right;
  margin-bottom: 3px;
}

.msg-receiver {
  display: flex;
  justify-content: flex-start;
  margin-bottom: 4px;
}

.msg-receiver .bubble {
  background: var(--bubble-other);
  border-radius: 2px 8px 8px 8px;
  padding: 9px 13px;
  max-width: 80%;
  box-shadow: 0 1px 1px rgba(0,0,0,.06);
}

.msg-receiver .label-tag {
  font-size: 11px;
  color: var(--text-secondary);
  margin-bottom: 3px;
}

.bubble {
  font-size: 16px;
  line-height: 1.55;
  word-break: break-word;
  position: relative;
}

.msg-time {
  font-size: 10px;
  color: #bbb;
  text-align: center;
  margin: 2px 0 6px;
}

.msg-actions {
  display: flex;
  gap: 12px;
  justify-content: flex-end;
  padding: 2px 4px 0;
}

.msg-actions button {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 12px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
}

.msg-actions button:active { background: rgba(0,0,0,.06); }

.chat-input-bar {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 8px 10px;
  padding-bottom: calc(8px + constant(safe-area-inset-bottom));
  padding-bottom: calc(8px + env(safe-area-inset-bottom));
  background: #f7f7f7;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.input-row {
  flex: 1;
  display: flex;
  align-items: flex-end;
  gap: 6px;
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 4px 6px;
}

.chat-input {
  flex: 1;
  border: none;
  outline: none;
  resize: none;
  font-size: 16px;
  font-family: inherit;
  line-height: 1.5;
  max-height: 100px;
  min-height: 24px;
  background: transparent;
  padding: 2px 0;
}

.mic-btn {
  flex-shrink: 0;
  min-width: 44px;
  min-height: 44px;
  width: 44px;
  height: 44px;
  border: none;
  background: transparent;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--text-secondary);
  transition: all .15s;
  -webkit-tap-highlight-color: transparent;
}

.mic-btn:active { background: rgba(0,0,0,.08); }
.mic-btn.listening { color: #e74c3c; background: #fde8e8; }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: .6; }
}
.mic-btn.listening svg {
  animation: pulse 1s ease-in-out infinite;
}

.send-btn {
  flex-shrink: 0;
  padding: 8px 16px;
  border: none;
  border-radius: 6px;
  background: var(--green);
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: background .12s;
  height: 44px;
}

.send-btn:active { background: var(--green-dark); }
.send-btn:disabled { opacity: .4; }

.toast {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(0,0,0,.75);
  color: #fff;
  padding: 10px 20px;
  border-radius: 8px;
  font-size: 14px;
  z-index: 100;
  pointer-events: none;
  text-align: center;
  max-width: 80%;
  line-height: 1.5;
}

.toast.hidden { display: none; }

.chat-messages::-webkit-scrollbar { width: 4px; }
.chat-messages::-webkit-scrollbar-thumb { background: #ccc; border-radius: 4px; }

@media (max-width: 480px) {
  .chat-header { padding: 10px 12px 8px; }
  .header-title { font-size: 16px; }
  .chat-messages { padding: 10px 10px 6px; }
  .msg-sender .bubble,
  .msg-receiver .bubble { max-width: 88%; padding: 8px 11px; }
  .bubble { font-size: 15px; }
  .chat-input-bar { padding: 6px 8px; padding-bottom: calc(6px + constant(safe-area-inset-bottom)); padding-bottom: calc(6px + env(safe-area-inset-bottom)); }
  .input-row { padding: 2px 4px; }
  .chat-input { font-size: 15px; }
  .send-btn { font-size: 14px; padding: 8px 14px; height: 44px; }
  .toast { font-size: 13px; max-width: 85%; padding: 8px 16px; }
}

@media (min-width: 768px) {
  .chat-app { max-width: 600px; margin: 0 auto; border-left: 1px solid var(--border); border-right: 1px solid var(--border); }
  body { background: #d1d1d1; }
}
