:root {
  --bg: #e8eef5;
  --panel: #ffffff;
  --header: #0b3d5c;
  --header-text: #f5f8fb;
  --dean: #dcf8c6;
  --leo: #ffffff;
  --border: #d0d7de;
  --muted: #6b7280;
  --accent: #0b6e4f;
  --danger: #b91c1c;
  --chip-demo: #92400e;
  --chip-demo-bg: #fef3c7;
  --chip-live: #065f46;
  --chip-live-bg: #d1fae5;
  --chip-sync: #1e40af;
  --chip-sync-bg: #dbeafe;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.08);
  --radius: 16px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: #111827; }

.muted { color: var(--muted); }
.error { color: var(--danger); margin-top: 0.75rem; font-size: 0.9rem; }
.fineprint { font-size: 0.75rem; margin-top: 1.25rem; text-align: center; }
code { font-size: 0.85em; background: #f3f4f6; padding: 0.1em 0.35em; border-radius: 4px; }

/* Login */
.login-body {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: calc(1.5rem + var(--safe-top)) calc(1.5rem + var(--safe-right)) calc(1.5rem + var(--safe-bottom)) calc(1.5rem + var(--safe-left));
  background: linear-gradient(160deg, #0b3d5c 0%, #1a5f7a 45%, #e8eef5 45%);
}
.login-card {
  width: min(400px, 100%);
  background: var(--panel);
  border-radius: 20px;
  padding: 1.75rem;
  box-shadow: 0 12px 40px rgba(15, 23, 42, 0.18);
}
.login-brand { text-align: center; margin-bottom: 1.5rem; }
.login-brand h1 { margin: 0.75rem 0 0.25rem; font-size: 1.4rem; }
.login-brand .muted { margin: 0; }
.login-card label { display: block; font-size: 0.85rem; margin-bottom: 0.35rem; font-weight: 600; }
.login-card input[type="password"],
.login-card input[type="text"] {
  width: 100%;
  padding: 0.75rem 0.9rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 1rem;
  margin-bottom: 1rem;
}

.avatar {
  width: 44px; height: 44px; border-radius: 50%;
  display: inline-grid; place-items: center;
  font-weight: 700; color: #fff; background: #334155;
}
.avatar.leo { background: linear-gradient(135deg, #0b3d5c, #1a5f7a); font-size: 1.15rem; }
.login-brand .avatar { width: 64px; height: 64px; font-size: 1.6rem; }

.btn {
  border: none; border-radius: 999px; padding: 0.55rem 1rem;
  font-size: 0.95rem; font-weight: 600; cursor: pointer;
  background: #e5e7eb; color: #111;
}
.btn.primary { background: var(--header); color: #fff; }
.btn.full { width: 100%; padding: 0.8rem; }
.btn.ghost { background: transparent; color: var(--header-text); border: 1px solid rgba(255,255,255,0.35); padding: 0.35rem 0.7rem; font-size: 0.8rem; }
.btn.small { padding: 0.35rem 0.75rem; font-size: 0.8rem; background: #fff; border: 1px solid var(--border); }
.btn.send {
  width: 44px; height: 44px; border-radius: 50%;
  background: var(--accent); color: #fff; font-size: 1.1rem;
  flex-shrink: 0; display: grid; place-items: center;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* Chat shell */
.chat-body { height: 100%; }
.app {
  max-width: 720px;
  margin: 0 auto;
  height: 100%;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  box-shadow: var(--shadow);
}
.chat-header {
  display: flex; align-items: center; justify-content: space-between;
  gap: 0.75rem;
  padding: calc(0.75rem + var(--safe-top)) calc(1rem + var(--safe-right)) 0.75rem calc(1rem + var(--safe-left));
  background: var(--header);
  color: var(--header-text);
  flex-shrink: 0;
}
.header-left { display: flex; align-items: center; gap: 0.75rem; }
.header-right { display: flex; align-items: center; gap: 0.5rem; }
.title { font-weight: 700; font-size: 1.05rem; line-height: 1.2; }
.subtitle { font-size: 0.75rem; color: rgba(245,248,251,0.75); }

.chip {
  font-size: 0.7rem; font-weight: 700; letter-spacing: 0.02em;
  text-transform: uppercase; padding: 0.25rem 0.55rem; border-radius: 999px;
}
.chip.demo { background: var(--chip-demo-bg); color: var(--chip-demo); }
.chip.live { background: var(--chip-live-bg); color: var(--chip-live); }
.chip.syncing { background: var(--chip-sync-bg); color: var(--chip-sync); }

/* [hidden] must win over class display:flex (banner, preview) */
[hidden] {
  display: none !important;
}

.banner {
  background: #fffbeb; color: #78350f; border-bottom: 1px solid #fde68a;
  padding: 0.6rem 1rem; font-size: 0.85rem;
  display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem 0.75rem;
  flex-shrink: 0;
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  background:
    radial-gradient(circle at 20% 20%, rgba(11,61,92,0.04), transparent 40%),
    radial-gradient(circle at 80% 0%, rgba(11,110,79,0.05), transparent 35%),
    #eef2f6;
  display: flex; flex-direction: column; gap: 0.55rem;
}

.day-sep {
  align-self: center; font-size: 0.7rem; color: var(--muted);
  background: rgba(255,255,255,0.85); padding: 0.2rem 0.6rem; border-radius: 999px;
  margin: 0.35rem 0;
}

.bubble-row { display: flex; }
.bubble-row.dean { justify-content: flex-end; }
.bubble-row.leo { justify-content: flex-start; }

.bubble {
  max-width: min(78%, 420px);
  padding: 0.55rem 0.75rem 0.4rem;
  border-radius: 16px;
  box-shadow: var(--shadow);
  position: relative;
  word-wrap: break-word;
  white-space: pre-wrap;
}
.bubble.dean {
  background: var(--dean);
  border-bottom-right-radius: 4px;
}
.bubble.leo {
  background: var(--leo);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}
.bubble .meta {
  display: flex; justify-content: flex-end; gap: 0.4rem;
  font-size: 0.68rem; color: var(--muted); margin-top: 0.25rem;
}
.bubble img.thumb {
  display: block; max-width: 100%; max-height: 240px;
  border-radius: 10px; margin-bottom: 0.35rem; cursor: pointer;
}

.empty {
  margin: auto; text-align: center; color: var(--muted); padding: 2rem 1rem;
}
.empty strong { display: block; color: #374151; margin-bottom: 0.35rem; }

.composer {
  display: flex; align-items: flex-end; gap: 0.5rem;
  padding: 0.65rem calc(0.75rem + var(--safe-right)) calc(0.65rem + var(--safe-bottom)) calc(0.75rem + var(--safe-left));
  border-top: 1px solid var(--border);
  background: #f8fafc;
  flex-shrink: 0;
}
.attach {
  width: 40px; height: 40px; display: grid; place-items: center;
  cursor: pointer; font-size: 1.25rem; flex-shrink: 0;
  border-radius: 50%;
}
.attach:hover { background: #e5e7eb; }
.composer-main { flex: 1; min-width: 0; }
.composer textarea {
  width: 100%; resize: none; border: 1px solid var(--border);
  border-radius: 18px; padding: 0.65rem 0.9rem;
  font: inherit; line-height: 1.35; max-height: 120px;
  background: #fff;
}
.preview {
  display: flex; align-items: center; gap: 0.5rem;
  margin-bottom: 0.35rem; font-size: 0.8rem;
}
.preview img {
  width: 48px; height: 48px; object-fit: cover; border-radius: 8px;
  border: 1px solid var(--border);
}
.preview button {
  border: none; background: #fee2e2; color: #991b1b;
  border-radius: 999px; padding: 0.2rem 0.55rem; cursor: pointer; font-size: 0.75rem;
}

@media (min-width: 760px) {
  .chat-body { padding: 1rem 0; }
  .app { height: calc(100% - 2rem); border-radius: 16px; overflow: hidden; }
}
