/* TalkBack UI - iPhone-style chat bubbles with a responsive app shell. */

:root {
  color-scheme: light;
  --bg: #eef1f5;
  --surface: #ffffff;
  --surface-soft: #f7f8fa;
  --text: #1f2328;
  --muted: #6b7280;
  --muted-strong: #4b5563;
  --border: #d8dee8;
  --border-soft: #e7ebf2;
  --bubble-in: #ffffff;
  --online: #2fb344;
  --offline: #a8b0bd;
  --accent: #2563eb;
  --accent-soft: #dbeafe;
  --shadow: 0 14px 40px rgba(28, 39, 54, .10);
  --bubble-shadow: 0 1px 2px rgba(28, 39, 54, .12);
  --radius: 18px;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #111418;
    --surface: #1c2026;
    --surface-soft: #15191f;
    --text: #f4f7fb;
    --muted: #a4adba;
    --muted-strong: #c4cbd5;
    --border: #303844;
    --border-soft: #252c36;
    --bubble-in: #2b313b;
    --online: #35c46b;
    --offline: #687282;
    --accent: #6aa3ff;
    --accent-soft: #172b4d;
    --shadow: 0 18px 50px rgba(0, 0, 0, .32);
    --bubble-shadow: 0 1px 2px rgba(0, 0, 0, .35);
  }
}

* { box-sizing: border-box; }

*:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(circle at top left, rgba(37, 99, 235, .10), transparent 34rem),
    linear-gradient(180deg, var(--bg), var(--surface-soft));
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  padding: 18px;
}

.app {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 260px;
  grid-template-rows: auto minmax(0, 1fr);
  grid-template-areas:
    "top top"
    "chat side";
  width: min(1100px, 100%);
  height: calc(100vh - 36px);
  height: calc(100dvh - 36px);
  margin: 0 auto;
  overflow: hidden;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
}

.topbar {
  grid-area: top;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  min-height: 68px;
  padding: 12px 16px;
  background: color-mix(in srgb, var(--surface) 96%, transparent);
  border-bottom: 1px solid var(--border);
}

.title {
  display: flex;
  align-items: center;
  gap: 11px;
  min-width: 0;
}

.brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  flex: none;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  font-weight: 750;
  font-size: 18px;
  box-shadow: 0 8px 18px color-mix(in srgb, var(--accent) 25%, transparent);
}

.title-copy {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.title-main {
  font-weight: 720;
  font-size: 18px;
  line-height: 1.1;
}

.title-sub {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.2;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.roster-summary {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  max-width: 42vw;
  min-height: 32px;
  padding: 0 11px;
  border: 1px solid var(--border-soft);
  border-radius: 999px;
  background: var(--surface-soft);
  color: var(--muted-strong);
  font-size: 13px;
  font-weight: 560;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#ttsToggle {
  display: none;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 1px solid var(--border-soft);
  border-radius: 8px;
  background: var(--surface-soft);
  color: var(--muted-strong);
  cursor: pointer;
  transition: background .15s ease, border-color .15s ease, color .15s ease;
}

#ttsToggle:hover,
#ttsToggle[aria-pressed="true"] {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--offline);
  display: inline-block;
  flex: none;
}

.dot.live {
  background: var(--online);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--online) 18%, transparent);
}

.chat {
  grid-area: chat;
  min-width: 0;
  overflow-y: auto;
  padding: 22px clamp(14px, 3vw, 34px) 28px;
  display: flex;
  flex-direction: column;
  gap: 7px;
  scroll-behavior: smooth;
  background:
    linear-gradient(180deg, transparent, color-mix(in srgb, var(--surface-soft) 60%, transparent)),
    var(--surface-soft);
}

.sidebar {
  grid-area: side;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--surface);
  border-left: 1px solid var(--border);
  padding: 18px 14px;
  overflow-y: auto;
}

.sidebar h2 {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--muted);
  margin: 0 0 10px;
}

.agent-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.agent-row {
  display: grid;
  grid-template-columns: 10px minmax(0, 1fr);
  grid-template-areas:
    "presence name"
    "presence voice";
  column-gap: 10px;
  align-items: center;
  min-height: 46px;
  padding: 9px 10px;
  border: 1px solid var(--border-soft);
  border-radius: 8px;
  background: var(--surface-soft);
  font-size: 14px;
}

.agent-row .presence {
  grid-area: presence;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex: none;
}

.agent-row .presence.on { background: var(--online); }
.agent-row .presence.off { background: var(--offline); }

.agent-row .name {
  grid-area: name;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text);
  font-weight: 620;
}

.agent-row .voice {
  grid-area: voice;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--muted);
  font-size: 12px;
}

.hint {
  margin: auto 0 0;
  padding-top: 14px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.tts-speaking {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--online);
  margin-left: 1px;
  animation: tts-pulse 1s ease-in-out infinite;
  vertical-align: middle;
}

@keyframes tts-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: .3; }
}

/* Bubbles */
.msg {
  display: flex;
  flex-direction: column;
  max-width: min(78%, 620px);
  animation: pop .18s ease-out;
}

.msg.left {
  align-self: flex-start;
  align-items: flex-start;
}

.msg.right {
  align-self: flex-end;
  align-items: flex-end;
}

@keyframes pop {
  from { opacity: 0; transform: translateY(6px) scale(.98); }
  to { opacity: 1; transform: none; }
}

.bubble {
  padding: 9px 13px;
  border-radius: var(--radius);
  background: var(--bubble-in);
  color: var(--text);
  font-size: 15px;
  line-height: 1.38;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
  box-shadow: var(--bubble-shadow);
}

.msg.left .bubble { border-bottom-left-radius: 5px; }
.msg.right .bubble { border-bottom-right-radius: 5px; }

.meta {
  display: flex;
  align-items: center;
  gap: 6px;
  max-width: 100%;
  color: var(--muted);
  font-size: 11px;
  margin: 2px 4px 3px;
}

.meta span:last-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.avatar {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  color: #fff;
  flex: none;
}

.system {
  align-self: center;
  max-width: 420px;
  margin: auto 0;
  padding: 8px 12px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
  text-align: center;
}

@media (max-width: 760px) {
  body {
    padding: 0;
    background: var(--surface-soft);
  }

  .app {
    width: 100%;
    height: 100vh;
    height: 100dvh;
    border: 0;
    border-radius: 0;
    box-shadow: none;
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(0, 1fr) auto;
    grid-template-areas:
      "top"
      "chat"
      "side";
  }

  .topbar {
    min-height: 60px;
    padding: 10px 12px;
  }

  .brand-mark {
    width: 34px;
    height: 34px;
    border-radius: 8px;
  }

  .title-sub { display: none; }

  .roster-summary {
    max-width: 44vw;
    min-height: 30px;
    padding: 0 9px;
    font-size: 12px;
  }

  #ttsToggle {
    width: 34px;
    height: 34px;
  }

  .chat {
    padding: 16px 10px 18px;
  }

  .msg {
    max-width: 86%;
  }

  .sidebar {
    max-height: 34vh;
    border-left: 0;
    border-top: 1px solid var(--border);
    padding: 12px;
  }

  .agent-list {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  }

  .hint {
    margin-top: 10px;
    padding-top: 0;
  }
}

@media (max-width: 420px) {
  .title-main {
    font-size: 17px;
  }

  .roster-summary {
    max-width: 38vw;
  }

  .msg {
    max-width: 92%;
  }
}

@media (prefers-reduced-motion: reduce) {
  .chat {
    scroll-behavior: auto;
  }

  .msg,
  .tts-speaking {
    animation: none;
  }
}
