/* RoboChat — login screen, chat layout, sealed message capsules, phone mode */

/* ---------- Login ---------- */
.login {
  position: fixed; inset: 0; z-index: 2; display: grid; place-items: center; padding: 20px;
  overflow-y: auto;
}
.login-card {
  width: min(400px, 100%); padding: 34px 30px 28px; border-radius: 28px;
  box-shadow: 0 40px 120px -30px rgba(0, 0, 0, 0.8), inset 0 1px 0 rgba(255, 255, 255, 0.06);
  animation: rise 0.5s cubic-bezier(0.2, 0.9, 0.3, 1.1);
}
.login-hero { display: grid; justify-items: center; gap: 14px; margin-bottom: 26px; text-align: center; }
.login-hero .robot { width: 84px; height: 84px; filter: drop-shadow(0 10px 30px rgba(127, 231, 255, 0.35)); animation: float 5s ease-in-out infinite; }
@keyframes float { 50% { transform: translateY(-6px); } }
.login-hero h1 { margin: 0; font: 700 32px/1.05 var(--font-d); letter-spacing: -0.035em; }
.login-hero p { margin: 0; color: var(--muted); font-size: 14px; max-width: 30ch; }
.login form { display: grid; gap: 14px; }
.login .btn-primary { margin-top: 6px; min-height: 50px; font-size: 16px; }
.shake { animation: shake 0.4s; }
@keyframes shake { 20%, 60% { transform: translateX(-8px); } 40%, 80% { transform: translateX(8px); } }

/* ---------- Device wrapper (normal mode: invisible; phone mode: a phone) ---------- */
.device, .device-frame { display: contents; }
.device-screen {
  position: fixed; inset: 0; z-index: 2;
  container-type: inline-size; container-name: screen;
}
.status-bar { display: none; }

body.phone-mode .device {
  display: grid; place-items: center; position: fixed; inset: 0; z-index: 2;
  background: radial-gradient(ellipse at center, transparent 30%, rgba(3, 5, 12, 0.55));
}
body.phone-mode .device-frame { display: block; position: relative; animation: rise 0.35s ease-out; }
body.phone-mode .device-screen {
  position: relative; inset: auto;
  height: min(860px, calc(100dvh - 56px)); aspect-ratio: 9 / 19.5;
  border-radius: 52px; overflow: hidden;
  box-shadow:
    0 0 0 11px #0b0d16,
    0 0 0 12.5px #3a4060,
    0 0 0 14px #11131d,
    0 50px 140px -20px rgba(0, 0, 0, 0.85),
    0 0 120px -30px rgba(127, 231, 255, 0.25);
}
body.phone-mode .device-screen::before {
  content: ""; position: absolute; top: 11px; left: 50%; z-index: 60; transform: translateX(-50%);
  width: 108px; height: 31px; border-radius: 20px; background: #000;
}
body.phone-mode .device-frame::before,
body.phone-mode .device-frame::after {
  content: ""; position: absolute; width: 4px; border-radius: 2px; background: #2a2f45;
}
body.phone-mode .device-frame::before { right: -18px; top: 180px; height: 86px; }
body.phone-mode .device-frame::after { left: -18px; top: 150px; height: 120px; box-shadow: 0 -60px 0 0 #2a2f45; }
body.phone-mode .status-bar {
  display: flex; justify-content: space-between; align-items: center;
  position: absolute; top: 0; left: 0; right: 0; z-index: 55; height: 52px; padding: 6px 34px 0;
  font: 600 14px/1 var(--font-d); pointer-events: none;
}
body.phone-mode .status-bar svg { width: 46px; height: 12px; }
body.phone-mode .side-head, body.phone-mode .chat-head { padding-top: 54px; }

/* ---------- App layout ---------- */
.app {
  position: relative; display: grid; grid-template-columns: 300px 1fr; height: 100%;
}
.side {
  display: flex; flex-direction: column; min-height: 0;
  border-right: 1px solid var(--line);
  background: rgba(8, 11, 24, 0.55);
  -webkit-backdrop-filter: blur(22px) saturate(140%); backdrop-filter: blur(22px) saturate(140%);
}
.side-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 16px 12px 20px; }
.side-close { display: none; }
.side-list { flex: 1; overflow-y: auto; padding: 6px 10px 12px; scrollbar-width: thin; }
.side-label { margin: 16px 10px 6px; font-size: 12.5px; color: var(--muted); }

.chat-item, .member {
  width: 100%; display: flex; align-items: center; gap: 12px; padding: 9px 10px;
  border-radius: var(--r-m); border: 1px solid transparent; background: transparent; text-align: left;
  transition: background 0.15s, border-color 0.15s;
}
.chat-item:hover, .member-row:hover .member { background: rgba(127, 140, 200, 0.08); }
.chat-item.active, .member-row.active .member { background: rgba(127, 231, 255, 0.08); border-color: rgba(127, 231, 255, 0.22); }
.item-text { flex: 1; min-width: 0; display: grid; }
.item-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item-sub { font-size: 12.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.badge {
  min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px; display: grid; place-items: center;
  font-size: 11.5px; font-weight: 700; color: #041018; background: var(--ice);
}
.stack { display: flex; flex: none; }
.stack .robot + .robot { margin-left: -14px; }
.member-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.member-row { border-radius: var(--r-m); }
.member-row.selected { background: rgba(127, 140, 200, 0.06); }
.open-chat {
  display: none; margin: 2px 10px 10px 62px; min-height: 36px; font-size: 13.5px; padding: 0 14px;
}
.member-row.selected .open-chat { display: inline-flex; }

.side-foot {
  display: flex; align-items: center; gap: 10px; padding: 12px 14px;
  border-top: 1px solid var(--line);
}
.side-foot .item-text { font-size: 14px; }

/* Chat column */
.chat { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.chat-head {
  display: flex; align-items: center; gap: 12px; padding: 14px 16px; min-height: 68px;
  border-bottom: 1px solid var(--line);
  background: rgba(8, 11, 24, 0.35);
  -webkit-backdrop-filter: blur(18px); backdrop-filter: blur(18px);
}
.chat-title { flex: 1; min-width: 0; display: grid; }
.chat-title strong { font: 650 16.5px/1.25 var(--font-d); letter-spacing: -0.015em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-title span { font-size: 12.5px; color: var(--muted); }
.menu-btn { display: none; position: relative; }
.menu-btn .pip { position: absolute; top: 8px; right: 8px; width: 8px; height: 8px; border-radius: 50%; background: var(--ice); box-shadow: 0 0 6px var(--ice); }
.phone-btn { display: none; }
@media (min-width: 900px) and (pointer: fine) {
  .phone-btn { display: inline-grid; }
}
body.phone-mode .phone-btn { color: var(--ice); background: rgba(127, 231, 255, 0.1); }

.conn {
  margin: 8px auto 0; padding: 4px 12px; border-radius: 999px; font-size: 12.5px;
  color: #ffd9a8; background: rgba(255, 197, 107, 0.12); border: 1px solid rgba(255, 197, 107, 0.3);
}

.messages {
  flex: 1; overflow-y: auto; overscroll-behavior: contain; padding: 18px 16px 8px;
  display: flex; flex-direction: column; scrollbar-width: thin;
}
.messages > * { width: 100%; max-width: 760px; margin-left: auto; margin-right: auto; }
.empty { margin: auto; text-align: center; color: var(--muted); display: grid; justify-items: center; gap: 12px; max-width: 30ch; }
.empty .robot { width: 64px; height: 64px; opacity: 0.85; }
.more { align-self: center; width: auto; margin-bottom: 12px; min-height: 34px; font-size: 13px; }
.day { text-align: center; font-size: 12px; color: var(--muted); margin: 14px auto 10px; }

.msg { display: flex; gap: 10px; align-items: flex-end; margin-top: 14px; }
.msg.cont { margin-top: 6px; }
.msg.cont .msg-ava { visibility: hidden; }
.msg.cont .msg-meta { display: none; }
.msg-ava { width: 36px; flex: none; }
.msg-main { min-width: 0; display: grid; justify-items: start; gap: 4px; }
.msg-meta { display: flex; gap: 8px; align-items: baseline; font-size: 12.5px; color: var(--muted); padding: 0 6px; }
.msg-name { color: var(--text); font-weight: 600; }
.msg.mine { flex-direction: row-reverse; }
.msg.mine .msg-main { justify-items: end; }
.msg.mine .msg-meta { flex-direction: row-reverse; }

/* ---------- The sealed capsule ---------- */
.capsule {
  --tint: 127, 231, 255;
  position: relative; overflow: hidden;
  display: flex; align-items: center; gap: 12px;
  width: 248px; min-height: 58px; padding: 10px 16px 10px 10px;
  border-radius: 20px 20px 20px 6px;
  border: 1px solid rgba(var(--tint), 0.28);
  background:
    linear-gradient(135deg, rgba(var(--tint), 0.14), rgba(var(--tint), 0.03) 60%),
    rgba(10, 14, 30, 0.72);
  -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
  text-align: left;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.05), 0 10px 30px -18px rgba(var(--tint), 0.6);
  transition: border-color 0.2s, box-shadow 0.2s, transform 0.12s;
}
.msg.mine .capsule { --tint: 197, 155, 255; border-radius: 20px 20px 6px 20px; }
.capsule:hover { border-color: rgba(var(--tint), 0.5); box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06), 0 10px 34px -14px rgba(var(--tint), 0.7); }
.capsule:active { transform: scale(0.985); }
/* subtle diagonal texture that says "sealed" */
.capsule::before {
  content: ""; position: absolute; inset: 0; pointer-events: none; opacity: 0.5;
  background: repeating-linear-gradient(135deg, rgba(var(--tint), 0.06) 0 2px, transparent 2px 9px);
}
.cap-seal {
  position: relative; width: 38px; height: 38px; flex: none; border-radius: 12px; display: grid; place-items: center;
  color: rgb(var(--tint)); background: rgba(var(--tint), 0.12); border: 1px solid rgba(var(--tint), 0.3);
}
.cap-seal svg { width: 18px; height: 18px; }
.cap-words { position: relative; display: grid; }
.cap-label { font-weight: 600; font-size: 14.5px; }
.cap-hint { font-size: 12.5px; color: var(--muted); }
/* Not opened yet: a soft breathing glow. Each tap makes it flash brighter. */
.capsule.sealed { animation: cap-glow 2.8s ease-in-out infinite; }
.capsule.sealed.tap { animation: cap-tap 0.6s ease-out, cap-glow 2.8s ease-in-out 0.6s infinite; }
@keyframes cap-glow {
  50% {
    border-color: rgba(var(--tint), 0.6);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06), 0 0 24px -4px rgba(var(--tint), 0.55);
  }
}
@keyframes cap-tap {
  30% {
    border-color: rgba(var(--tint), 0.95);
    box-shadow: inset 0 0 18px rgba(var(--tint), 0.25), 0 0 36px 2px rgba(var(--tint), 0.75);
    transform: scale(1.02);
  }
}
/* Read once and locked for good */
.capsule.read, .msg.mine .capsule.read {
  --tint: 140, 147, 179;
  cursor: default; opacity: 0.62; box-shadow: none;
  background: rgba(10, 13, 26, 0.6);
}
.capsule.read::before { display: none; }
.capsule.read:hover { border-color: rgba(var(--tint), 0.28); box-shadow: none; }
.capsule.read.tap { animation: shake 0.35s; }

/* Open state */
.capsule.open {
  width: auto; max-width: min(560px, 100%); min-width: 120px; display: block;
  padding: 12px 16px; cursor: pointer;
  border-color: rgba(var(--tint), 0.55);
  background: linear-gradient(135deg, rgba(var(--tint), 0.2), rgba(var(--tint), 0.06)), rgba(12, 16, 34, 0.85);
}
.capsule.open::before { display: none; }
.cap-text {
  position: relative; display: block; white-space: pre-wrap; overflow-wrap: anywhere; font-size: 15px; line-height: 1.5;
  animation: unseal-text 0.45s ease-out both;
}
.capsule.open::after {
  content: ""; position: absolute; inset: -2px; pointer-events: none;
  background: linear-gradient(105deg, transparent 30%, rgba(255, 255, 255, 0.55) 48%, rgba(var(--tint), 0.4) 52%, transparent 70%);
  transform: translateX(-120%);
  animation: unseal-sweep 0.7s cubic-bezier(0.3, 0.6, 0.3, 1) forwards;
}
@keyframes unseal-sweep { to { transform: translateX(120%); } }
@keyframes unseal-text { from { opacity: 0; filter: blur(8px); letter-spacing: 0.06em; } }

.typing { min-height: 22px; padding: 0 24px; font-size: 12.5px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.typing .dots { display: inline-flex; gap: 3px; }
.typing .dots i { width: 4px; height: 4px; border-radius: 50%; background: var(--ice); animation: tdot 1.2s infinite; }
.typing .dots i:nth-child(2) { animation-delay: 0.15s; }
.typing .dots i:nth-child(3) { animation-delay: 0.3s; }
@keyframes tdot { 0%, 60%, 100% { opacity: 0.25; transform: translateY(0); } 30% { opacity: 1; transform: translateY(-3px); } }

.composer {
  display: flex; align-items: flex-end; gap: 10px;
  margin: 0 16px 16px; padding: 8px 8px 8px 16px;
  border-radius: 26px; border: 1px solid var(--line-2);
  background: rgba(10, 13, 28, 0.72);
  -webkit-backdrop-filter: blur(18px); backdrop-filter: blur(18px);
  width: auto; max-width: 760px; align-self: stretch;
}
@container screen (min-width: 1100px) { .composer { margin-left: auto; margin-right: auto; width: calc(100% - 32px); } }
.composer:focus-within { border-color: rgba(127, 231, 255, 0.45); }
.composer textarea {
  flex: 1; min-height: 40px; max-height: 140px; resize: none; border: 0; outline: none; background: transparent;
  padding: 9px 0; line-height: 1.45; font-size: 16px;
}
.composer textarea::placeholder { color: #5f6688; }
.send-btn {
  width: 42px; height: 42px; flex: none; border-radius: 50%; border: 0; display: grid; place-items: center; color: #041018;
  background: linear-gradient(135deg, #9af0ff, #7fb2ff 55%, #c59bff);
  transition: transform 0.12s, opacity 0.15s;
}
.send-btn:disabled { opacity: 0.35; cursor: default; }
.send-btn:not(:disabled):active { transform: scale(0.92); }
.send-btn svg { width: 20px; height: 20px; }
.scrim { display: none; }

/* Code dialog */
.code-dialog .who { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }
.code-input {
  width: 100%; min-height: 58px; text-align: center; font: 700 26px/1 var(--font-d); letter-spacing: 0.4em;
  padding-left: 0.4em;
}

/* ---------- Narrow screens (and phone mode) ---------- */
@container screen (max-width: 760px) {
  .app { grid-template-columns: 1fr; }
  .side {
    position: absolute; inset: 0 auto 0 0; z-index: 40; width: min(320px, 86%);
    background: rgba(9, 12, 26, 0.92);
    transform: translateX(-104%); transition: transform 0.28s cubic-bezier(0.3, 0.8, 0.3, 1);
    box-shadow: 30px 0 80px -30px rgba(0, 0, 0, 0.8);
  }
  .app.drawer-open .side { transform: none; }
  .side-close { display: inline-grid; }
  .menu-btn { display: inline-grid; }
  .scrim { display: block; position: absolute; inset: 0; z-index: 30; background: rgba(3, 5, 12, 0.5); opacity: 0; pointer-events: none; transition: opacity 0.25s; }
  .app.drawer-open .scrim { opacity: 1; pointer-events: auto; }
  .chat-head { padding: 10px 10px 10px 8px; min-height: 60px; gap: 8px; }
  .messages { padding: 12px 10px 6px; }
  .msg-ava { width: 30px; }
  .msg-ava .robot { width: 30px; height: 30px; }
  .capsule { width: 220px; }
  .composer { margin: 0 10px 10px; }
  .typing { padding: 0 16px; }
}
@supports (padding: env(safe-area-inset-bottom)) {
  body:not(.phone-mode) .composer { margin-bottom: max(10px, env(safe-area-inset-bottom)); }
}
