/* client/css/style.css */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #1a1a2e;
  --bg-secondary: #16213e;
  --bg-bubble-self: #6366f1;
  --bg-bubble-other: #2d2d44;
  --text: #eeeeee;
  --text-secondary: #aaaaaa;
  --text-muted: #666666;
  --accent: #6366f1;
  --green: #4ade80;
  --yellow: #f59e0b;
  --border: #333333;
  --radius: 12px;
  --radius-bubble: 18px;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

#app {
  height: 100%;
  display: flex;
  flex-direction: column;
}

/* --- Header bar --- */
.header {
  display: flex;
  align-items: center;
  padding: 14px 20px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  min-height: 60px;
}

.header-title { font-size: 22px; font-weight: 700; flex: 1; }

.header-back {
  font-size: 24px;
  cursor: pointer;
  padding: 8px;
  margin-right: 8px;
  min-width: 44px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* --- Buttons --- */
.btn-round {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: white;
  font-size: 22px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn-large {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 16px;
  background: var(--bg-secondary);
  border-radius: var(--radius);
  cursor: pointer;
  border: none;
  color: var(--text);
  width: 100%;
  text-align: left;
  font-size: 17px;
}

.btn-large .icon {
  width: 48px;
  height: 48px;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
}

/* --- Chat list --- */
.chat-list { flex: 1; overflow-y: auto; padding: 8px 0; }

.chat-item {
  display: flex;
  align-items: center;
  padding: 14px 20px;
  gap: 14px;
  border-bottom: 1px solid #222;
  cursor: pointer;
}

.chat-item:active { background: rgba(255,255,255,0.05); }

.avatar {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  flex-shrink: 0;
}

.chat-info { flex: 1; min-width: 0; }
.chat-name { font-size: 18px; font-weight: 600; }
.chat-preview {
  font-size: 15px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 3px;
}
.chat-time { font-size: 13px; color: var(--text-muted); }
.online-dot {
  width: 8px; height: 8px;
  background: var(--green);
  border-radius: 50%;
  flex-shrink: 0;
}

/* --- Chat view --- */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.msg { max-width: 75%; }
.msg-self { align-self: flex-end; }
.msg-other { align-self: flex-start; }

.msg-bubble {
  padding: 12px 16px;
  font-size: 16px;
  line-height: 1.5;
  word-wrap: break-word;
}

.msg-self .msg-bubble {
  background: var(--bg-bubble-self);
  border-radius: var(--radius-bubble) var(--radius-bubble) 4px var(--radius-bubble);
}

.msg-other .msg-bubble {
  background: var(--bg-bubble-other);
  border-radius: var(--radius-bubble) var(--radius-bubble) var(--radius-bubble) 4px;
}

.msg-sender {
  font-size: 13px;
  font-weight: 600;
  color: var(--accent);
  margin-bottom: 2px;
}

.msg-sender-clickable {
  cursor: pointer;
}

.msg-sender-clickable:hover {
  text-decoration: underline;
}

.msg-time {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
}

.msg-self .msg-time { text-align: right; }

.msg-media {
  max-width: 240px;
  border-radius: var(--radius);
  cursor: pointer;
}

.msg-audio {
  width: 240px;
  max-width: 100%;
  height: 40px;
  filter: invert(1);
}

.msg-video {
  max-width: 280px;
  max-height: 240px;
  border-radius: var(--radius);
}

.msg-file {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  background: rgba(255,255,255,0.1);
  border-radius: var(--radius);
  font-size: 14px;
  cursor: pointer;
  text-decoration: none;
  color: var(--text);
}

.msg-file:hover {
  background: rgba(255,255,255,0.15);
}

.msg-file-icon {
  font-size: 22px;
  flex-shrink: 0;
}

.msg-file-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.msg-file-size {
  color: var(--text-muted);
  font-size: 12px;
  flex-shrink: 0;
}

/* --- Attachment strip --- */
.attach-strip {
  display: none;
  padding: 8px 16px;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
  gap: 8px;
  overflow-x: auto;
  white-space: nowrap;
}

.attach-strip.visible {
  display: flex;
}

.attach-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-bubble-other);
  border-radius: 8px;
  padding: 4px 8px;
  font-size: 13px;
  flex-shrink: 0;
}

.attach-thumb {
  width: 32px;
  height: 32px;
  border-radius: 4px;
  object-fit: cover;
}

.attach-icon {
  font-size: 18px;
}

.attach-name {
  max-width: 80px;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text-secondary);
}

.attach-remove {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 16px;
  cursor: pointer;
  padding: 2px 4px;
  line-height: 1;
}

.attach-remove:hover {
  color: var(--text);
}

/* --- Input bar --- */
.input-bar {
  display: flex;
  align-items: center;
  padding: 12px 16px;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
  gap: 10px;
}

.input-bar textarea {
  flex: 1;
  background: var(--bg-bubble-other);
  border: none;
  border-radius: 24px;
  padding: 12px 18px;
  font-size: 16px;
  color: var(--text);
  outline: none;
  resize: none;
  overflow-y: hidden;
  line-height: 1.5;
  max-height: 120px;
  font-family: inherit;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.input-bar textarea::placeholder { color: var(--text-muted); }

/* --- Voice recording bar --- */
.voice-recording-bar {
  display: none;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--bg-surface);
  border-top: 1px solid var(--border);
}
.voice-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #ef4444;
  animation: voice-pulse 1s ease-in-out infinite;
}
@keyframes voice-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}
#voice-timer {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

/* --- Add menu --- */
.add-menu {
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* --- Typing indicator --- */
.typing-indicator {
  align-self: flex-start;
  display: none;
}

.typing-indicator.visible {
  display: block;
}

.typing-indicator .msg-bubble {
  background: var(--bg-bubble-other);
  border-radius: var(--radius-bubble) var(--radius-bubble) var(--radius-bubble) 4px;
  padding: 12px 16px;
  display: flex;
  gap: 4px;
  align-items: center;
}

.typing-dot {
  width: 8px;
  height: 8px;
  background: var(--text-secondary);
  border-radius: 50%;
  animation: typing-bounce 1.4s infinite ease-in-out;
}

.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes typing-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-6px); opacity: 1; }
}

/* --- Status banner --- */
.status-banner {
  display: none;
  align-items: center;
  padding: 10px 16px;
  font-size: 15px;
  line-height: 1.4;
  gap: 10px;
}

.status-banner.visible {
  display: flex;
}

.status-banner.level-error {
  background: #dc2626;
  color: #ffffff;
}

.status-banner.level-warn {
  background: #f59e0b;
  color: #1a1a2e;
}

.status-banner.level-info {
  background: #3b82f6;
  color: #ffffff;
}

.status-banner-text {
  flex: 1;
}

.status-banner-close {
  background: none;
  border: none;
  color: inherit;
  font-size: 20px;
  cursor: pointer;
  padding: 4px 8px;
  opacity: 0.8;
  min-width: 32px;
  min-height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.status-banner-close:hover {
  opacity: 1;
}

/* --- Utility --- */
.screen { display: none; flex-direction: column; height: 100%; }
.screen.active { display: flex; }
.hidden { display: none !important; }

/* --- Markdown message rendering --- */
.msg-markdown p { margin-bottom: 0.5em; }
.msg-markdown p:last-child { margin-bottom: 0; }

.msg-markdown h1, .msg-markdown h2, .msg-markdown h3,
.msg-markdown h4, .msg-markdown h5, .msg-markdown h6 {
  font-weight: 600;
  margin: 0.6em 0 0.3em;
}
.msg-markdown h1 { font-size: 1.15em; }
.msg-markdown h2 { font-size: 1.1em; }
.msg-markdown h3, .msg-markdown h4,
.msg-markdown h5, .msg-markdown h6 { font-size: 1.0em; }

.msg-markdown strong, .msg-markdown b { font-weight: 600; }
.msg-markdown em, .msg-markdown i { font-style: italic; }

.msg-markdown code {
  background: rgba(255,255,255,0.1);
  padding: 1px 5px;
  border-radius: 4px;
  font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
  font-size: 0.9em;
}

.msg-markdown pre {
  background: rgba(0,0,0,0.3);
  padding: 10px 12px;
  border-radius: 8px;
  overflow-x: auto;
  margin: 0.4em 0;
}
.msg-markdown pre code {
  background: none;
  padding: 0;
  font-size: 0.85em;
  line-height: 1.5;
}

.msg-markdown ul, .msg-markdown ol {
  padding-left: 1.4em;
  margin: 0.3em 0;
}
.msg-markdown li { margin: 0.15em 0; }

.msg-markdown blockquote {
  border-left: 3px solid var(--accent);
  padding-left: 10px;
  margin: 0.4em 0;
  color: var(--text-secondary);
}

.msg-markdown a {
  color: var(--accent);
  text-decoration: underline;
}

.msg-markdown hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 0.6em 0;
}

.msg-markdown table {
  border-collapse: collapse;
  margin: 0.4em 0;
  font-size: 0.9em;
}
.msg-markdown th, .msg-markdown td {
  border: 1px solid var(--border);
  padding: 4px 8px;
}
.msg-markdown th {
  background: rgba(255,255,255,0.05);
  font-weight: 600;
}

.msg-markdown img {
  max-width: 100%;
  border-radius: 8px;
}

/* --- Message avatar (incoming only) --- */
.msg-other {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}

.msg-other .msg-content {
  display: flex;
  flex-direction: column;
}
