:root {
  --primary: #008069;
  --primary-foreground: #ffffff;
  --bubble-in: #ffffff;
  --bubble-out: #d9fdd3;
  --surface: #f0f2f5;
  --canvas: #efeae2;
  --foreground: #111b21;
  --muted-foreground: #667781;
  --border: #e3e5e8;
  --input: #ffffff;
  --destructive: #d93025;
  --destructive-soft: rgba(217, 48, 37, 0.1);
  --warning: #9a6700;
  --warning-soft: rgba(154, 103, 0, 0.12);
  --radius: 0.6rem;
  --font: "Inter", "Segoe UI Variable Text", "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, "Helvetica Neue", sans-serif;
}

@supports (background: color-mix(in oklch, red 50%, blue)) {
  :root {
    --bubble-out: color-mix(in oklch, var(--primary) 16%, #ffffff);
  }
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  display: flex;
  flex-direction: column;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  color: var(--foreground);
  background: var(--surface);
  -webkit-font-smoothing: antialiased;
}

button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
:focus { outline: none; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
input:focus-visible, textarea:focus-visible { outline: none; }

/* Shell */
.chat {
  position: relative;
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  background: var(--surface);
}

/* Floating users toggle: no top bar, the room owns the whole height */
.users-fab {
  position: absolute;
  top: 14px;
  right: 14px;
  z-index: 40;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 40px;
  padding: 0 15px;
  font-size: 14px;
  font-weight: 700;
  color: var(--foreground);
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: 999px;
  box-shadow: 0 1px 2px rgba(11, 20, 26, 0.14);
  transition: right 0.2s ease, color 0.15s, border-color 0.15s;
}

.users-fab:hover { color: var(--primary); border-color: var(--primary); }

/* Steps aside when the panel opens, so it never covers the list */
.users.is-open ~ .users-fab { right: 238px; }
.users-fab svg { width: 18px; height: 18px; }
.users-fab.is-active { color: var(--primary-foreground); background: var(--primary); border-color: var(--primary); }

/* Buttons follow the shadcn shapes, not the WhatsApp ones */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 42px;
  padding: 0 18px;
  font-size: 15px;
  font-weight: 600;
  color: var(--primary-foreground);
  background: var(--primary);
  border: 1px solid var(--primary);
  border-radius: var(--radius);
  transition: opacity 0.15s;
}

.btn:hover { opacity: 0.9; }
.btn:disabled { pointer-events: none; opacity: 0.5; }
.btn--block { width: 100%; margin-top: 16px; }

.btn--ghost {
  color: var(--foreground);
  background: #ffffff;
  border-color: var(--border);
}

.btn--ghost:hover { background: var(--surface); }

.link {
  color: var(--primary);
  font-weight: 500;
  text-decoration: none;
}

.link:hover { text-decoration: underline; }

/* Doodle wallpaper behind every screen, one tiled SVG so it stays cheap */
.canvas {
  position: absolute;
  inset: 0;
  z-index: 0;
  background-color: var(--canvas);
  background-image: url("../imgs/chat-bg.svg");
  background-size: 372px 434px;
}

/* Login and errors sit over the room as a modal, the chat stays visible behind */
.screen {
  position: absolute;
  inset: 0;
  z-index: 50;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
  overflow-y: auto;
  background: rgba(239, 234, 226, 0.55);
  -webkit-backdrop-filter: blur(5px);
  backdrop-filter: blur(5px);
}

.screen.is-on { display: flex; }

.chat.is-locked .room { pointer-events: none; }

.panel {
  width: 100%;
  max-width: 350px;
  padding: 28px 26px;
  text-align: center;
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: 0 8px 30px rgba(11, 20, 26, 0.14);
}

.panel__icon {
  display: grid;
  place-items: center;
  width: 52px;
  height: 52px;
  margin: 0 auto 16px;
  color: var(--primary-foreground);
  background: var(--primary);
  border-radius: 50%;
}

.panel__icon svg { width: 25px; height: 25px; }
.panel__icon--bad { color: var(--destructive); background: var(--destructive-soft); }

.panel__title {
  margin: 0 0 16px;
  font-size: 19px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.panel__text {
  margin: 0 0 20px;
  font-size: 14px;
  color: var(--muted-foreground);
}

.field { text-align: left; }

.label {
  display: block;
  margin-bottom: 7px;
  font-size: 14px;
  font-weight: 500;
}

.input {
  width: 100%;
  height: 42px;
  padding: 0 13px;
  background: var(--input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: border-color 0.15s;
}

.input::placeholder { color: var(--muted-foreground); }
.input.is-invalid { border-color: var(--destructive); }

.error {
  display: none;
  margin-top: 7px;
  font-size: 14px;
  color: var(--destructive);
}

.error.is-on { display: block; }

.terms {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  margin-top: 14px;
  font-size: 14px;
  color: var(--muted-foreground);
  text-align: left;
}

.terms input {
  width: 17px;
  height: 17px;
  margin: 2px 0 0;
  accent-color: var(--primary);
}

.policy {
  margin: 14px 0 0;
  font-size: 14px;
  color: var(--muted-foreground);
}

.spinner {
  width: 30px;
  height: 30px;
  margin: 0 auto 14px;
  border: 2px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* Room */
.room {
  position: relative;
  display: none;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.room.is-on { display: flex; }

.thread {
  position: relative;
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
}

.msgs {
  position: relative;
  z-index: 1;
  flex: 1;
  overflow-y: auto;
  padding: 18px 16px 8px;
  scrollbar-width: thin;
}

.msgs::-webkit-scrollbar { width: 8px; }
.msgs::-webkit-scrollbar-thumb { background: rgba(17, 27, 33, 0.18); border-radius: 999px; }

/* Bubbles */
/* fit-content keeps a short line from stretching into a wide thin strip */
.msg {
  position: relative;
  width: fit-content;
  min-width: 92px;
  max-width: 74%;
  margin-bottom: 10px;
  padding: 8px 13px 7px;
  background: var(--bubble-in);
  border-radius: 16px 16px 16px 5px;
  box-shadow: 0 1px 0.5px rgba(11, 20, 26, 0.13);
}

.msg::after {
  content: "";
  position: absolute;
  bottom: 0;
  left: -5px;
  width: 12px;
  height: 12px;
  background: var(--bubble-in);
  border-bottom-right-radius: 12px;
  clip-path: polygon(100% 0, 100% 100%, 0 100%);
}

.msg--me {
  margin-left: auto;
  background: var(--bubble-out);
  border-radius: 16px 16px 5px 16px;
}

.msg--me::after {
  left: auto;
  right: -5px;
  background: var(--bubble-out);
  border-bottom-right-radius: 0;
  border-bottom-left-radius: 12px;
  clip-path: polygon(0 0, 100% 100%, 0 100%);
}

/* Names carry their own color, picked from the palette by the script */
.msg__who {
  display: flex;
  align-items: center;
  gap: 5px;
  margin-bottom: 2px;
  font-size: 14px;
  font-weight: 700;
  color: var(--who, var(--primary));
}


.msg__text {
  font-size: 15px;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.msg__time {
  float: right;
  margin: 6px 0 0 10px;
  font-size: 12.5px;
  color: var(--muted-foreground);
  font-variant-numeric: tabular-nums;
}

.star {
  display: inline-flex;
  flex-shrink: 0;
  color: var(--primary);
}

.star svg { width: 13px; height: 13px; }
.user__avatar .star { color: #ffffff; }
.user__avatar .star svg { width: 15px; height: 15px; }

.note {
  width: fit-content;
  max-width: 82%;
  margin: 0 auto 12px;
  padding: 6px 14px;
  font-size: 14px;
  text-align: center;
  color: var(--muted-foreground);
  background: rgba(255, 255, 255, 0.92);
  border-radius: 999px;
  box-shadow: 0 1px 0.5px rgba(11, 20, 26, 0.13);
}

.note--warn { color: var(--warning); background: var(--warning-soft); }

/* Composer */
.flood {
  display: none;
  position: relative;
  z-index: 1;
  margin: 0 16px 8px;
  padding: 9px 13px;
  font-size: 14px;
  color: var(--warning);
  background: var(--warning-soft);
  border-radius: var(--radius);
}

.flood.is-on { display: block; }

/* Faded while the flood timer runs, so the block is visible */
.composer.is-blocked {
  pointer-events: none;
  opacity: 0.5;
}

.composer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  position: relative;
  z-index: 1;
  flex-shrink: 0;
  padding: 10px 14px;
  background: var(--surface);
  border-top: 1px solid var(--border);
}

.composer__box {
  position: relative;
  display: flex;
  align-items: flex-end;
  flex: 1;
  min-width: 0;
  background: var(--input);
  border: 1px solid var(--border);
  border-radius: 999px;
}

.composer textarea {
  flex: 1;
  min-width: 0;
  max-height: 104px;
  padding: 10px 8px 10px 4px;
  background: none;
  border: 0;
  resize: none;
}

.composer textarea:focus { outline: none; }

.icon-btn {
  display: grid;
  place-items: center;
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  color: var(--muted-foreground);
  background: none;
  border: 0;
  border-radius: 50%;
  transition: color 0.15s, background 0.15s;
}

.icon-btn:hover { color: var(--primary); background: rgba(17, 27, 33, 0.05); }
.icon-btn svg { width: 21px; height: 21px; }

.counter {
  flex-shrink: 0;
  align-self: center;
  padding-right: 14px;
  font-size: 13px;
  color: var(--muted-foreground);
  font-variant-numeric: tabular-nums;
}

.send {
  display: grid;
  place-items: center;
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  color: var(--primary-foreground);
  background: var(--primary);
  border: 0;
  border-radius: 50%;
  transition: opacity 0.15s, transform 0.15s;
}

.send:hover { opacity: 0.9; }
.send:active { transform: scale(0.94); }
.send:disabled { pointer-events: none; opacity: 0.4; }
.send svg { width: 20px; height: 20px; }

.emojis {
  display: none;
  position: absolute;
  left: 14px;
  right: 14px;
  bottom: 70px;
  z-index: 20;
  grid-template-columns: repeat(auto-fill, minmax(40px, 1fr));
  gap: 2px;
  max-height: 200px;
  padding: 8px;
  overflow-y: auto;
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: 14px;
}

.emojis.is-on { display: grid; }

.emojis button {
  height: 38px;
  font-size: 22px;
  background: none;
  border: 0;
  border-radius: 8px;
}

.emojis button:hover { background: var(--surface); }

/* Unread jump */
.jump {
  display: none;
  position: absolute;
  right: 18px;
  bottom: 78px;
  z-index: 15;
  align-items: center;
  gap: 7px;
  height: 38px;
  padding: 0 15px;
  font-size: 14px;
  font-weight: 600;
  color: var(--primary-foreground);
  background: var(--primary);
  border: 0;
  border-radius: 999px;
}

.jump.is-on { display: inline-flex; }
.jump svg { width: 15px; height: 15px; }

/* Users: collapsed by default, the floating button slides it in */
.users {
  display: flex;
  flex-shrink: 0;
  width: 0;
  overflow: hidden;
  background: #ffffff;
  transition: width 0.2s ease;
}

.users.is-open { width: 224px; border-left: 1px solid var(--border); }

.users__inner {
  display: flex;
  flex-direction: column;
  width: 224px;
  min-height: 0;
}

.users__head {
  flex-shrink: 0;
  padding: 16px 16px 10px;
  font-size: 14px;
  font-weight: 600;
  color: var(--muted-foreground);
}

.users__list {
  flex: 1;
  padding: 0 10px 10px;
  overflow-y: auto;
}

.user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 10px;
  font-size: 14px;
  border-radius: 8px;
}

.user:hover { background: var(--surface); }

.user__avatar {
  display: grid;
  place-items: center;
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  font-size: 13px;
  font-weight: 700;
  color: #ffffff;
  background: var(--who, var(--primary));
  border-radius: 50%;
}

.user__name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user__me { flex-shrink: 0; font-size: 13px; color: var(--muted-foreground); }

.users__foot {
  flex-shrink: 0;
  padding: 12px 16px;
  font-size: 14px;
  text-align: center;
  border-top: 1px solid var(--border);
}

.leave {
  color: var(--destructive);
  background: none;
  border: 0;
  padding: 0;
  font-weight: 500;
}

.leave:hover { text-decoration: underline; }

/* Narrow screens get the panel as an overlay, so the room is never squeezed */
@media (max-width: 700px) {
  .users {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    z-index: 30;
    width: 224px;
    border-left: 1px solid var(--border);
    transform: translateX(100%);
    transition: transform 0.22s ease;
  }

  .users.is-open { width: 224px; transform: translateX(0); }
  .msg { max-width: 86%; }
}

/* Moderation actions, panel only */
.act {
  display: grid;
  place-items: center;
  flex-shrink: 0;
  width: 26px;
  height: 26px;
  padding: 0;
  color: var(--muted-foreground);
  background: none;
  border: 0;
  border-radius: 50%;
  opacity: 0;
  transition: color 0.15s, background 0.15s, opacity 0.15s;
}

.act svg { width: 15px; height: 15px; }
.act:hover { color: var(--destructive); background: var(--destructive-soft); }

.user:hover .act,
.act:focus-visible { opacity: 1; }

.msg .act {
  position: absolute;
  top: 4px;
  right: 4px;
  background: var(--bubble-in);
}

.msg:hover .act { opacity: 1; }
