/* ── Reset & Base ────────────────────────────────────────────────────────── */

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

:root {
  --bg:           #060d18;
  --surface:      #0b1624;
  --surface-2:    #0e1e30;
  --surface-3:    #132435;
  --border:       rgba(91, 196, 240, 0.12);
  --border-glow:  rgba(91, 196, 240, 0.28);

  --ice:          #5bc4f0;
  --ice-dim:      #3aa0cc;
  --ice-pale:     rgba(91, 196, 240, 0.08);
  --ice-pale2:    rgba(91, 196, 240, 0.15);
  --frost:        rgba(91, 196, 240, 0.04);

  --text:         #d6eef8;
  --text-dim:     #7aaec8;
  --text-muted:   #3d6880;

  --user-bg:      #0e2a40;
  --user-border:  rgba(91, 196, 240, 0.35);
  --zc-bg:        #0b1e2e;
  --zc-border:    rgba(91, 196, 240, 0.18);

  --online:       #4ade80;
  --offline:      #475569;
  --warning:      #fbbf24;

  --radius:       12px;
  --radius-sm:    8px;
  --font:         -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

/* ── App Shell ───────────────────────────────────────────────────────────── */

#app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 860px;
  margin: 0 auto;
  background: var(--surface);
  border-left: 1px solid var(--border);
  border-right: 1px solid var(--border);
}

/* ── Header ──────────────────────────────────────────────────────────────── */

#header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  flex-shrink: 0;
  position: sticky;
  top: 0;
  z-index: 10;
}

#brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

#claw-icon {
  font-size: 22px;
  color: var(--ice);
  filter: drop-shadow(0 0 6px rgba(91, 196, 240, 0.5));
  line-height: 1;
}

#brand-name {
  font-size: 17px;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--text);
}

#status-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.03em;
  color: var(--text-dim);
  text-transform: uppercase;
}

#status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--offline);
  transition: background 0.4s, box-shadow 0.4s;
}

#status-dot.online {
  background: var(--online);
  box-shadow: 0 0 6px rgba(74, 222, 128, 0.6);
  animation: pulse-dot 2.5s ease-in-out infinite;
}

#status-dot.connecting {
  background: var(--warning);
  box-shadow: 0 0 6px rgba(251, 191, 36, 0.5);
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.55; }
}

/* ── Message Area ────────────────────────────────────────────────────────── */

#message-area {
  flex: 1;
  overflow-y: auto;
  padding: 20px 16px;
  scroll-behavior: smooth;
}

#message-area::-webkit-scrollbar { width: 4px; }
#message-area::-webkit-scrollbar-track { background: transparent; }
#message-area::-webkit-scrollbar-thumb {
  background: var(--ice-pale2);
  border-radius: 2px;
}

#messages {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* ── Message Rows ────────────────────────────────────────────────────────── */

.msg-row {
  display: flex;
  flex-direction: column;
  gap: 3px;
  max-width: 72%;
  animation: msg-in 0.18s ease-out both;
}

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

.msg-row.from-user {
  align-self: flex-end;
  align-items: flex-end;
}

.msg-row.from-zc {
  align-self: flex-start;
  align-items: flex-start;
}

.msg-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--text-muted);
  padding: 0 4px;
}

.msg-row.from-user .msg-meta { flex-direction: row-reverse; }

.msg-sender {
  font-weight: 600;
  font-size: 11px;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.from-zc  .msg-sender { color: var(--ice-dim); }
.from-user .msg-sender { color: var(--text-dim); }

/* ── Bubbles ─────────────────────────────────────────────────────────────── */

.bubble {
  padding: 10px 14px;
  border-radius: var(--radius);
  line-height: 1.55;
  word-break: break-word;
  max-width: 100%;
  position: relative;
}

.zc-bubble {
  background: var(--zc-bg);
  border: 1px solid var(--zc-border);
  border-bottom-left-radius: 4px;
  color: var(--text);
}

.user-bubble {
  background: var(--user-bg);
  border: 1px solid var(--user-border);
  border-bottom-right-radius: 4px;
  color: var(--text);
}

/* ── Typing Indicator ────────────────────────────────────────────────────── */

#typing-indicator {
  margin-top: 8px;
}

#typing-indicator.hidden { display: none; }

.typing-bubble {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 10px 16px;
}

.typing-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--ice-dim);
  animation: typing-bounce 1.2s ease-in-out infinite;
}

.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(-5px); opacity: 1; }
}

/* ── System Messages ─────────────────────────────────────────────────────── */

.system-msg {
  align-self: center;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-muted);
  padding: 4px 12px;
  background: var(--frost);
  border: 1px solid var(--border);
  border-radius: 20px;
  animation: msg-in 0.2s ease-out both;
}

/* ── Date Dividers ───────────────────────────────────────────────────────── */

.date-divider {
  align-self: center;
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 500;
  letter-spacing: 0.03em;
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  margin: 8px 0;
}

.date-divider::before,
.date-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

/* ── Input Area ──────────────────────────────────────────────────────────── */

#input-area {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 14px 16px;
  background: var(--surface-2);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

#input {
  flex: 1;
  background: var(--surface-3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  padding: 10px 14px;
  resize: none;
  max-height: 160px;
  overflow-y: auto;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

#input::placeholder { color: var(--text-muted); }

#input:focus {
  border-color: var(--border-glow);
  box-shadow: 0 0 0 3px var(--ice-pale), inset 0 0 20px rgba(91, 196, 240, 0.03);
}

#input::-webkit-scrollbar { width: 3px; }
#input::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

#send-btn {
  flex-shrink: 0;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: none;
  background: var(--ice-dim);
  color: #06111e;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s, transform 0.1s, box-shadow 0.2s;
}

#send-btn:hover:not(:disabled) {
  background: var(--ice);
  box-shadow: 0 0 14px rgba(91, 196, 240, 0.4);
}

#send-btn:active:not(:disabled) { transform: scale(0.93); }

#send-btn:disabled {
  background: var(--surface-3);
  color: var(--text-muted);
  cursor: not-allowed;
}

/* ── Empty State ─────────────────────────────────────────────────────────── */

#empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  height: 100%;
  color: var(--text-muted);
  font-size: 14px;
  text-align: center;
  padding: 40px;
  user-select: none;
}

#empty-state .empty-icon {
  font-size: 40px;
  filter: drop-shadow(0 0 10px rgba(91, 196, 240, 0.3));
  opacity: 0.7;
}

/* ── Frost overlay on body ───────────────────────────────────────────────── */

body::before {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(ellipse 60% 40% at 20% 0%, rgba(91, 196, 240, 0.04) 0%, transparent 70%),
    radial-gradient(ellipse 40% 30% at 80% 100%, rgba(91, 196, 240, 0.03) 0%, transparent 70%);
  z-index: 0;
}

#app { position: relative; z-index: 1; }

/* ── Responsive ──────────────────────────────────────────────────────────── */

@media (max-width: 600px) {
  .msg-row { max-width: 88%; }
  #message-area { padding: 14px 10px; }
  #input-area { padding: 10px 10px; }
}
