:root {
  --header: #076e73;
  --header-2: #065e63;
  --bg: #e3f6f4;
  --teal: #0c7f84;
  --ink: #1b3332;
  --muted: #5e7d7a;
  --line: #d5eeea;
  --wa: #2fce6b;
  --white: #ffffff;
  --card: #ffffff;
  --promo: #0caf4a;
  --shadow: 0 8px 28px rgba(4, 50, 54, 0.18);
  --menu: #ffffff;
  --field: #e7f8ef;
  --field-line: #3cb87a;
}

html.dark {
  --bg: #102220;
  --ink: #e7f4f2;
  --muted: #9bb8b4;
  --line: #245552;
  --white: #17302e;
  --card: #17302e;
  --promo: #3dde7a;
  --menu: #17302e;
  --field: #0e2422;
  --field-line: #2f9d78;
  --header: #064e52;
  --header-2: #04383b;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  position: fixed;
  inset: 0;
  width: 100%;
  font-family: "Segoe UI", system-ui, sans-serif;
  background: #054e52;
  color: var(--ink);
  display: flex;
  justify-content: center;
  -webkit-font-smoothing: antialiased;
  touch-action: manipulation;
}

html.dark body { background: #021716; }

button, input { font-family: inherit; }

button { cursor: pointer; }

.sr {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.app {
  position: relative;
  width: min(440px, 100%);
  height: 100dvh;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: var(--shadow);
}

.topbar {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 8px 8px 12px;
  background: linear-gradient(180deg, #087980 0%, var(--header) 55%, var(--header-2) 100%);
  color: #fff;
  min-height: 62px;
  flex: none;
  z-index: 5;
}

.avatar {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  object-fit: cover;
  object-position: center 42%;
  border: 2px solid rgba(255, 255, 255, 0.92);
  background: #064e52;
  flex: none;
}

.who { flex: 1; min-width: 0; }

.topbar h1 {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0.01em;
}

.status {
  margin: 2px 0 0;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: rgba(255, 255, 255, 0.9);
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #3dff8a;
  box-shadow: 0 0 0 0 rgba(61, 255, 138, 0.7);
  animation: pulse 1.8s infinite;
}

@keyframes pulse {
  70% { box-shadow: 0 0 0 6px rgba(61, 255, 138, 0); }
  100% { box-shadow: 0 0 0 0 rgba(61, 255, 138, 0); }
}

.more {
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: #fff;
  display: grid;
  place-items: center;
  flex: none;
}

.more:hover { background: rgba(255, 255, 255, 0.12); }

.menu {
  position: absolute;
  top: 62px;
  right: 10px;
  width: 196px;
  background: var(--menu);
  color: var(--ink);
  border-radius: 14px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.18);
  overflow: hidden;
  z-index: 6;
}

.menu button {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  border: 0;
  background: transparent;
  color: inherit;
  text-align: left;
  padding: 12px 14px;
  font-size: 14px;
  font-weight: 600;
}

.menu button + button { border-top: 1px solid var(--line); }

.menu button:hover { background: rgba(12, 127, 132, 0.08); }

.chat {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 10px 12px 6px;
  scrollbar-width: none;
  -ms-overflow-style: none;
  touch-action: pan-y;
  -webkit-overflow-scrolling: touch;
}

.chat::-webkit-scrollbar { width: 0; height: 0; }

.bubble {
  max-width: 92%;
  background: var(--white);
  color: var(--ink);
  border-radius: 16px;
  padding: 9px 12px;
  line-height: 1.4;
  font-size: 14px;
  box-shadow: 0 1px 2px rgba(7, 70, 74, 0.06);
  margin: 0 0 10px;
  animation: rise 0.28s ease both;
}

.bubble p { margin: 0; white-space: pre-line; }

.bubble strong { font-weight: 700; }

.promo { color: var(--promo); font-weight: 800; }

.bubble.user {
  margin-left: auto;
  background: #0c7c74;
  color: #fff;
  border-radius: 18px 18px 6px 18px;
}

.bubble.user .promo { color: #b8ffd4; }

.bubble.bot { border-radius: 18px 18px 18px 6px; }

.bubble-actions {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 10px;
}

.bubble-actions a {
  display: block;
  text-align: center;
  text-decoration: none;
  background: #e7f7f4;
  color: #076e73;
  font-weight: 700;
  border-radius: 12px;
  padding: 9px 10px;
}

html.dark .bubble-actions a {
  background: #0e3330;
  color: #8ef0c8;
}

.typing {
  display: flex;
  gap: 5px;
  width: fit-content;
  padding: 14px 16px;
}

.typing i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #8ec9c4;
  display: block;
  animation: blink 1s infinite;
}

.typing i:nth-child(2) { animation-delay: 0.15s; }
.typing i:nth-child(3) { animation-delay: 0.3s; }

@keyframes blink {
  0%, 80%, 100% { opacity: 0.35; transform: translateY(0); }
  40% { opacity: 1; transform: translateY(-2px); }
}

@keyframes rise {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

.suggest {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 2px;
}

.suggest button {
  width: 100%;
  background: var(--white);
  color: #0e8f7c;
  border: 1.5px solid #1aa88f;
  border-radius: 16px;
  padding: 9px 12px;
  font-size: 14px;
  font-weight: 600;
  text-align: center;
}

html.dark .suggest button { color: #7ddec8; border-color: #1aa88f; }

.suggest button:hover { background: rgba(26, 168, 143, 0.08); }
.suggest button:active { transform: scale(0.99); }

.dock {
  flex: none;
  background: var(--card);
  box-shadow: 0 -8px 20px rgba(7, 80, 84, 0.05);
}

.panel { padding: 4px 8px 2px; }

.mail-row[hidden] { display: none !important; }

.mail-row {
  display: flex;
  align-items: stretch;
  gap: 8px;
  width: 100%;
  max-width: 100%;
  margin-bottom: 4px;
}

.mail-row input {
  flex: 1;
  min-width: 0;
  width: 100%;
  border: 1.5px solid #7c3aed;
  background: var(--bg);
  color: var(--ink);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 16px;
  line-height: 1.15;
  outline: none;
}

.mail-row input:focus {
  border-color: #6d28d9;
  box-shadow: 0 0 0 3px rgba(124, 58, 237, 0.18);
}

.mail-row button {
  flex: none;
  min-width: 84px;
  border: 0;
  border-radius: 999px;
  background: #0c7c74;
  color: #fff;
  font-size: 14px;
  font-weight: 800;
  padding: 0 14px;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  margin-bottom: 3px;
}

.panel-head h2 {
  margin: 0;
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #12a37a;
  font-weight: 800;
}

.code-chip, .icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  border: 0;
  background: transparent;
  color: #12a37a;
}

.code-chip {
  padding: 2px 0 2px 4px;
  font-size: 12px;
  font-weight: 700;
  flex: none;
}

.code-chip strong { font-weight: 800; letter-spacing: 0.03em; }

.icon-btn {
  width: 22px;
  height: 22px;
  border-radius: 8px;
  border: 1px solid #b7e6da;
  flex: none;
  padding: 0;
}

html.dark .mail-row input {
  border-color: #a78bfa;
  background: #0b2422;
  color: #e8f7f4;
}

html.dark .icon-btn { border-color: #2c675f; }

.code-chip.copied, .icon-btn.copied { color: var(--promo); }

.books {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
}

.book {
  display: flex;
  align-items: center;
  gap: 2px;
  min-width: 0;
  background: var(--card);
  border: 1.5px solid #b7e6da;
  border-radius: 999px;
  padding: 1px 3px 1px 5px;
  min-height: 30px;
}

html.dark .book { border-color: #2c675f; }

.book a {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  flex: 1;
  text-decoration: none;
  color: var(--ink);
}

.logo {
  width: 26px;
  height: 16px;
  object-fit: contain;
  border-radius: 5px;
  flex: none;
  background: #041426;
}

.logo-1x { background: #071a44; }
.logo-mel, .logo-win { background: #000; }

.logo-cold {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  object-fit: cover;
  background: #071525;
}

.bk-text {
  display: flex;
  align-items: baseline;
  gap: 4px;
  min-width: 0;
  line-height: 1;
}

.bk-text strong {
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.01em;
}

.bk-text em {
  font-style: normal;
  font-size: 10px;
  font-weight: 800;
  color: #12a37a;
}

.wa {
  position: relative;
  overflow: hidden;
  margin-top: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 100%;
  min-height: 32px;
  background: var(--wa);
  color: #fff;
  text-decoration: none;
  font-weight: 700;
  font-size: 13px;
  border-radius: 12px;
  animation: wa-blink 1.35s ease-in-out infinite;
}

.wa::after {
  content: "";
  position: absolute;
  top: 0;
  left: -45%;
  width: 32%;
  height: 100%;
  background: linear-gradient(100deg, transparent, rgba(255, 255, 255, 0.72), transparent);
  transform: skewX(-18deg);
  animation: shine 2.1s ease-in-out infinite;
  pointer-events: none;
}

.wa img,
.wa span { position: relative; z-index: 1; }

.wa img {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  object-fit: cover;
  background: #25d366;
}

@keyframes wa-blink {
  0%, 100% { filter: brightness(1); box-shadow: 0 0 0 0 rgba(47, 206, 107, 0.15); }
  50% { filter: brightness(1.16); box-shadow: 0 0 14px 3px rgba(47, 206, 107, 0.55); }
}

@keyframes shine {
  0% { left: -45%; }
  55%, 100% { left: 130%; }
}

.composer {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px calc(6px + env(safe-area-inset-bottom));
}

.photo {
  width: 36px;
  height: 36px;
  flex: none;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: #0a8185;
  display: grid;
  place-items: center;
  padding: 0;
}

.composer input {
  flex: 1;
  min-width: 0;
  border: 0;
  background: var(--bg);
  border-radius: 999px;
  padding: 9px 12px;
  font-size: 16px;
  color: var(--ink);
  outline: none;
  box-shadow: inset 0 0 0 1px var(--line);
}

.composer input::placeholder { color: #93b3af; }

.composer input:focus { box-shadow: inset 0 0 0 1.5px var(--teal); }

.send {
  width: 40px;
  height: 40px;
  flex: none;
  border: 0;
  border-radius: 50%;
  background: #0a8185;
  color: #fff;
  display: grid;
  place-items: center;
}

.send:active { transform: scale(0.97); }

.app.admin-open .topbar,
.app.admin-open .chat,
.app.admin-open .dock { display: none; }

.admin {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 28px 18px;
  background: var(--bg);
}

.admin[hidden],
.admin-card[hidden],
.admin-log[hidden] { display: none !important; }

.admin.log-mode {
  align-items: stretch;
  justify-content: flex-start;
  padding: 0;
}

.admin-card {
  width: min(100%, 340px);
  background: var(--card);
  border-radius: 22px;
  box-shadow: 0 16px 40px rgba(7, 60, 50, 0.12);
  padding: 28px 22px 22px;
}

.admin-card h2,
.admin-log-head h2 {
  margin: 0 0 18px;
  text-align: center;
  color: #14915a;
  font-size: 26px;
  font-weight: 700;
}

.pass-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
  border: 1.5px solid var(--field-line);
  background: var(--field);
  border-radius: 14px;
  padding: 4px 8px 4px 14px;
}

.pass-wrap input {
  flex: 1;
  min-width: 0;
  border: 0;
  background: transparent;
  color: var(--ink);
  font-size: 16px;
  padding: 11px 0;
  outline: none;
}

#toggle-pass {
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: #5f8f86;
  display: grid;
  place-items: center;
}

.admin-error {
  margin: 8px 0 0;
  color: #d34545;
  font-size: 13px;
  text-align: center;
}

.admin-go {
  width: 100%;
  margin-top: 14px;
  border: 0;
  border-radius: 14px;
  padding: 13px 16px;
  color: #fff;
  font-size: 16px;
  font-weight: 700;
  background: linear-gradient(90deg, #5dcfb2 0%, #49a6e4 100%);
}

.admin-log {
  display: flex;
  flex-direction: column;
  min-height: 0;
  flex: 1;
  width: 100%;
}

.admin-log-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 14px 14px 8px;
}

.admin-log-head h2 {
  margin: 0;
  font-size: 20px;
  text-align: left;
}

.admin-actions { display: flex; gap: 8px; }

.admin-actions button {
  border: 0;
  background: transparent;
  color: var(--teal);
  font-weight: 700;
  font-size: 13px;
  padding: 6px;
}

#admin-list,
#thread-list,
#general-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 4px 12px 16px;
  touch-action: pan-y;
  -webkit-overflow-scrolling: touch;
}

.thread {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

.thread[hidden],
#inbox-head[hidden],
#admin-list[hidden],
.lightbox[hidden] { display: none !important; }

.msg-title {
  display: flex;
  align-items: center;
  gap: 8px;
}

.count-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 22px;
  height: 22px;
  padding: 0 6px;
  border-radius: 999px;
  background: #e11d48;
  color: #fff;
  font-size: 12px;
  line-height: 1;
  animation: count-blink 1s ease-in-out infinite;
}

@keyframes count-blink {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.45; transform: scale(0.92); }
}

.back-arrow {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  border: 0;
  background: #e7f6f3;
  color: #0c7c74;
  font-weight: 700;
  border-radius: 999px;
  padding: 6px 10px 6px 8px;
}

html.dark .back-arrow { background: #0e3330; color: #8ef0c8; }

.unread-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #22c55e;
  flex: none;
  box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.7);
  animation: pulse 1.2s infinite;
}

.convo {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  text-align: left;
  border: 0;
  background: var(--card);
  color: var(--ink);
  border-radius: 14px;
  padding: 12px;
  margin-bottom: 8px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}

.convo-text {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
  flex: 1;
}

.convo-id {
  color: #0c7c74;
  font-size: 14px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.convo-preview {
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.convo time {
  flex: none;
  color: var(--muted);
  font-size: 12px;
}

.shot {
  display: block;
  width: min(100%, 200px);
  margin-top: 6px;
  border-radius: 12px;
}

.photo-actions {
  display: flex;
  gap: 12px;
  margin-top: 6px;
}

.photo-actions button,
.photo-actions a {
  border: 0;
  background: transparent;
  color: #0c7c74;
  font-weight: 700;
  font-size: 13px;
  padding: 0;
  text-decoration: none;
}

.lightbox {
  position: absolute;
  inset: 0;
  z-index: 20;
  background: rgba(0, 0, 0, 0.88);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 18px;
}

.lightbox img {
  max-width: 100%;
  max-height: 70%;
  border-radius: 12px;
}

.lightbox a,
.lightbox-close {
  color: #fff;
  background: #0a8185;
  border: 0;
  border-radius: 999px;
  padding: 8px 14px;
  font-weight: 700;
  text-decoration: none;
}

.admin-empty {
  text-align: center;
  color: var(--muted);
  margin-top: 28px;
}

.log-item {
  background: #ffffff;
  border-radius: 14px;
  padding: 10px 12px;
  margin-bottom: 8px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
  max-width: 92%;
}

.log-item.user {
  background: #ffffff;
  margin-right: auto;
  border: 1px solid #e4eeec;
}

.log-item.bot {
  background: #d7ebff;
  margin-left: auto;
  border: 1px solid #c3ddf7;
}

html.dark .log-item.user {
  background: #243836;
  border-color: #345550;
  color: #e7f4f2;
}

html.dark .log-item.bot {
  background: #1d4e89;
  border-color: #2f6cb3;
  color: #f3f8ff;
}

.log-item header {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 4px;
  font-size: 12px;
}

.log-item.user header strong { color: #0c7c74; }
.log-item.bot header strong { color: var(--promo); }

.log-item time { color: var(--muted); }

.log-item p {
  margin: 0;
  white-space: pre-line;
  font-size: 14px;
  line-height: 1.4;
}

.convo-general { border: 1.5px solid #c4b5fd; }

.cast-form {
  flex: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
  background: #e6e8ec;
}

html.dark .cast-form { background: #1c1c1e; }

.cast-form input {
  flex: 1;
  min-width: 0;
  width: auto;
  border: 0;
  background: #fff;
  color: #111;
  border-radius: 999px;
  padding: 9px 14px;
  font-size: 16px;
  outline: none;
}

html.dark .cast-form input {
  background: #2c2c2e;
  color: #f5f5f5;
}

.cast-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.cast-icon,
.cast-mic {
  flex: none;
  border: 0;
  padding: 0;
  display: grid;
  place-items: center;
}

.cast-icon {
  width: 34px;
  height: 34px;
  background: transparent;
  color: #1c1c1e;
}

html.dark .cast-icon { color: #f2f2f2; }

.cast-plus {
  font-size: 34px;
  font-weight: 300;
  line-height: 1;
}

.cast-mic {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: #3a3a3c;
  color: #fff;
}

.cast-remove {
  border: 0;
  border-radius: 999px;
  background: #0c7c74;
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  padding: 8px 12px;
}

#cast-status {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
}

.cast {
  background: var(--card);
  border-radius: 16px;
  padding: 10px;
  margin: 8px 0;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.cast p {
  margin: 0 0 8px;
  font-weight: 700;
  font-size: 14px;
}

.cast audio,
.cast video,
.cast img {
  display: block;
  width: 100%;
  border-radius: 12px;
}

.cast video,
.cast img { max-height: 240px; object-fit: contain; background: #04181a; }

.cast-admin {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 12px;
}

.to-top {
  position: absolute;
  right: 14px;
  bottom: 18px;
  z-index: 4;
  border: 0;
  border-radius: 999px;
  background: #0c7c74;
  color: #fff;
  font-size: 12px;
  font-weight: 800;
  padding: 8px 12px;
  box-shadow: 0 6px 16px rgba(7, 60, 50, 0.25);
}

.admin { position: relative; }

.login-back {
  position: absolute;
  top: calc(12px + env(safe-area-inset-top));
  left: 12px;
  z-index: 3;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  border: 0;
  background: #e7f6f3;
  color: #0c7c74;
  font-weight: 700;
  border-radius: 999px;
  padding: 8px 12px 8px 8px;
}

.admin.log-mode .login-back { display: none; }

html.dark .login-back { background: #0e3330; color: #8ef0c8; }

.rec-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  background: #fff1f2;
  border-radius: 14px;
  padding: 8px;
}

#cast-tools[hidden],
.rec-bar[hidden] { display: none !important; }

.rec-live {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: #be123c;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.rec-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #e11d48;
  animation: count-blink 1s ease-in-out infinite;
}

#rec-cancel,
#rec-send {
  border: 0;
  border-radius: 999px;
  font-weight: 800;
  padding: 10px 14px;
}

#rec-cancel { background: #e5e7eb; color: #1f2937; }
#rec-send { background: #0c7c74; color: #fff; }

.toast {
  position: absolute;
  left: 50%;
  bottom: 86px;
  transform: translateX(-50%) translateY(8px);
  background: #063f43;
  color: #fff;
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 8;
  white-space: nowrap;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

:focus-visible {
  outline: 2px solid #0a8185;
  outline-offset: 2px;
}

@media (max-width: 360px) {
  .bk-text strong { font-size: 10px; }
  .logo { width: 28px; }
  .topbar h1 { font-size: 17px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation: none !important;
    transition: none !important;
  }
}
