/* Agent dashboard and sign-in page. Same theme tokens as the widget. */

:root {
  --chat-accent: #4F46E5;
  --chat-accent-text: #FFFFFF;
  --chat-accent-soft: #EEF0FB;
  --chat-accent-strong: #312E81;
  --chat-bg: #F3F4F8;
  --chat-panel: #F9FAFB;
  --chat-surface: #FFFFFF;
  --chat-text: #111827;
  --chat-text-2: #374151;
  --chat-muted: #6B7280;
  --chat-border: #E5E7EB;
  --chat-field-border: #D1D5DB;
  --chat-radius: 16px;
  --wait-bg: #FFFBEB;
  --wait-line: #D97706;
  --wait-text: #B45309;
  --wait-avatar: #FDE68A;
  --wait-avatar-text: #78350F;
  --active-avatar: #C7D2FE;
  --ok-bg: #DCFCE7;
  --ok-text: #166534;
  --ok-dot: #16A34A;
  --danger-bg: #FEE2E2;
  --danger-text: #991B1B;
  color-scheme: light;
}

/* Dark values: applied by data-theme="dark", or by the OS setting when the
   theme is "auto". */
body[data-theme='dark'] {
  --chat-accent-soft: #25264A;
  --chat-accent-strong: #C7D2FE;
  --chat-bg: #0D0F14;
  --chat-panel: #111318;
  --chat-surface: #1C1F27;
  --chat-text: #F3F4F6;
  --chat-text-2: #D1D5DB;
  --chat-muted: #A1A7B3;
  --chat-border: #2E3340;
  --chat-field-border: #434957;
  --wait-bg: #2B2110;
  --wait-line: #F59E0B;
  --wait-text: #FBBF24;
  --wait-avatar: #78350F;
  --wait-avatar-text: #FDE68A;
  --active-avatar: #3730A3;
  --ok-bg: #12301D;
  --ok-text: #86EFAC;
  --ok-dot: #4ADE80;
  --danger-bg: #3B1518;
  --danger-text: #FCA5A5;
  color-scheme: dark;
}

@media (prefers-color-scheme: dark) {
  body[data-theme='auto'] {
    --chat-accent-soft: #25264A;
    --chat-accent-strong: #C7D2FE;
    --chat-bg: #0D0F14;
    --chat-panel: #111318;
    --chat-surface: #1C1F27;
    --chat-text: #F3F4F6;
    --chat-text-2: #D1D5DB;
    --chat-muted: #A1A7B3;
    --chat-border: #2E3340;
    --chat-field-border: #434957;
    --wait-bg: #2B2110;
    --wait-line: #F59E0B;
    --wait-text: #FBBF24;
    --wait-avatar: #78350F;
    --wait-avatar-text: #FDE68A;
    --active-avatar: #3730A3;
    --ok-bg: #12301D;
    --ok-text: #86EFAC;
    --ok-dot: #4ADE80;
    --danger-bg: #3B1518;
    --danger-text: #FCA5A5;
    color-scheme: dark;
  }
}

*, *::before, *::after {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html, body {
  height: 100%;
}

body {
  display: flex;
  flex-direction: column;
  margin: 0;
  background: var(--chat-bg);
  color: var(--chat-text);
  font: 400 14px/1.45 system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}

button, input, textarea {
  font: inherit;
  color: inherit;
  margin: 0;
}

button {
  cursor: pointer;
}

a {
  color: var(--chat-accent);
}

body[data-theme='dark'] a {
  color: var(--chat-accent-strong);
}

@media (prefers-color-scheme: dark) {
  body[data-theme='auto'] a {
    color: var(--chat-accent-strong);
  }
}

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

.sr {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.muted {
  color: var(--chat-muted);
}

/* Top bar */

.top {
  flex: none;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 16px;
  min-height: 60px;
  padding: 8px 20px;
  border-bottom: 1px solid var(--chat-border);
  background: var(--chat-surface);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 17px;
  font-weight: 700;
}

.brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: var(--chat-accent);
  color: var(--chat-accent-text);
}

.tabs {
  display: flex;
  gap: 4px;
  margin-left: 12px;
  overflow-x: auto;
}

.tabs button {
  flex: none;
  padding: 8px 12px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--chat-text-2);
  font-size: 14px;
}

.tabs button:hover {
  background: var(--chat-panel);
}

.tabs button[aria-current='page'] {
  background: var(--chat-accent-soft);
  color: var(--chat-accent-strong);
  font-weight: 600;
}

.pill {
  display: inline-block;
  min-width: 20px;
  padding: 1px 7px;
  border-radius: 10px;
  background: var(--chat-border);
  color: var(--chat-text);
  font-size: 12px;
  font-weight: 600;
  text-align: center;
}

.pill.accent {
  background: var(--chat-accent);
  color: var(--chat-accent-text);
}

.top-right {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-left: auto;
}

.logout {
  margin: 0;
}

.icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border: 1px solid var(--chat-border);
  border-radius: 10px;
  background: var(--chat-surface);
  color: var(--chat-text-2);
}

.online-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 40px;
  padding: 0 16px;
  border: 0;
  border-radius: 20px;
  background: var(--chat-border);
  color: var(--chat-text-2);
  font-size: 14px;
  font-weight: 600;
}

.online-toggle .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--chat-muted);
}

.online-toggle[aria-pressed='true'] {
  background: var(--ok-bg);
  color: var(--ok-text);
}

.online-toggle[aria-pressed='true'] .dot {
  background: var(--ok-dot);
}

.banner {
  flex: none;
  padding: 8px 20px;
  background: var(--danger-bg);
  color: var(--danger-text);
  font-weight: 600;
}

/* Buttons and fields */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 40px;
  padding: 0 14px;
  border: 1px solid var(--chat-field-border);
  border-radius: 10px;
  background: var(--chat-surface);
  color: var(--chat-text-2);
  font-size: 14px;
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
}

.btn.primary {
  border-color: transparent;
  background: var(--chat-accent);
  color: var(--chat-accent-text);
}

.btn.danger {
  border-color: transparent;
  background: var(--danger-bg);
  color: var(--danger-text);
}

.btn.ghost {
  border-color: transparent;
  background: transparent;
}

.btn.small {
  height: 32px;
  padding: 0 10px;
  font-size: 13px;
}

.btn:disabled {
  opacity: 0.55;
  cursor: default;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  font-weight: 600;
}

.field input,
.field textarea,
.search {
  width: 100%;
  border: 1px solid var(--chat-field-border);
  border-radius: 10px;
  background: var(--chat-surface);
  font-size: 15px;
  font-weight: 400;
}

.field input,
.search {
  height: 44px;
  padding: 0 12px;
}

.field textarea {
  padding: 10px 12px;
  resize: vertical;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.alert {
  margin-bottom: 14px;
  padding: 10px 14px;
  border-radius: 10px;
  background: var(--danger-bg);
  color: var(--danger-text);
  font-weight: 600;
}

/* Sign-in */

body.login {
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
}

.login-card {
  width: 100%;
  max-width: 380px;
  padding: 28px;
  border-radius: var(--chat-radius);
  background: var(--chat-surface);
  box-shadow: 0 10px 30px rgba(17, 24, 39, 0.08);
}

.login-card h1 {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 0 6px;
  font-size: 20px;
}

.login-card .muted {
  margin: 0 0 20px;
}

.login-card .btn {
  height: 46px;
  font-size: 15px;
}

/* Three-column chat layout */

.app {
  flex: 1;
  display: flex;
  min-height: 0;
}

.layout {
  flex: 1;
  display: flex;
  min-width: 0;
  min-height: 0;
}

.list {
  flex: none;
  display: flex;
  flex-direction: column;
  width: 320px;
  border-right: 1px solid var(--chat-border);
  background: var(--chat-surface);
}

.list-search {
  padding: 16px;
  border-bottom: 1px solid var(--chat-border);
}

.search {
  height: 40px;
  border-color: var(--chat-border);
  background: var(--chat-panel);
  font-size: 14px;
}

.list-body {
  flex: 1;
  overflow-y: auto;
}

.group {
  padding: 14px 16px 6px;
  color: var(--chat-muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.group.waiting {
  color: var(--wait-text);
}

.row {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  width: 100%;
  padding: 12px 16px 12px 13px;
  border: 0;
  border-left: 3px solid transparent;
  background: transparent;
  text-align: left;
}

.row:hover {
  background: var(--chat-panel);
}

.row.waiting {
  border-left-color: var(--wait-line);
  background: var(--wait-bg);
}

.row.selected {
  border-left-color: var(--chat-accent);
  background: var(--chat-accent-soft);
}

.row:focus-visible {
  outline-offset: -2px;
}

.avatar {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--chat-border);
  color: var(--chat-text-2);
  font-weight: 700;
}

.avatar img {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
}

.avatar.waiting {
  background: var(--wait-avatar);
  color: var(--wait-avatar-text);
}

.avatar.active {
  background: var(--active-avatar);
  color: var(--chat-accent-strong);
}

.avatar.big {
  width: 56px;
  height: 56px;
  font-size: 19px;
}

.row-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.row-top {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 14px;
}

.row-top b {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.row-time {
  flex: none;
  color: var(--chat-muted);
}

.row.waiting .row-time {
  color: var(--wait-text);
  font-weight: 600;
}

.row-preview {
  overflow: hidden;
  color: var(--chat-text-2);
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.row-page {
  overflow: hidden;
  color: var(--chat-muted);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.empty {
  padding: 28px 20px;
  color: var(--chat-muted);
  text-align: center;
}

/* Conversation */

.conv {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--chat-panel);
}

.conv-empty {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  color: var(--chat-muted);
  text-align: center;
}

.conv-head {
  flex: none;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 12px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--chat-border);
  background: var(--chat-surface);
}

.conv-title {
  flex: 1;
  min-width: 140px;
}

.conv-title h2 {
  margin: 0;
  font-size: 16px;
}

.conv-title div {
  color: var(--chat-text-2);
  font-size: 13px;
}

.back,
.details-toggle {
  display: none;
}

.messages {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-height: 0;
  padding: 20px;
  overflow-y: auto;
}

.msg {
  max-width: 60%;
  padding: 10px 14px;
  border: 1px solid transparent;
  font-size: 14px;
  line-height: 1.45;
  overflow-wrap: anywhere;
  animation: msg-in 180ms ease-out both;
}

.msg.visitor {
  align-self: flex-start;
  border-color: var(--chat-border);
  border-radius: 18px 18px 18px 6px;
  background: var(--chat-surface);
}

.msg.visitor.cont {
  border-radius: 6px 18px 18px 6px;
}

.msg.agent {
  align-self: flex-end;
  border-radius: 18px 18px 6px 18px;
  background: var(--chat-accent);
  color: var(--chat-accent-text);
}

.msg.agent.cont {
  border-radius: 18px 6px 6px 18px;
}

.msg.cont {
  margin-top: -3px;
}

.msg.system {
  align-self: center;
  max-width: 100%;
  margin: 2px 0 6px;
  padding: 0;
  color: var(--chat-muted);
  font-size: 12px;
  text-align: center;
}

.meta {
  margin-bottom: 8px;
  color: var(--chat-muted);
  font-size: 11.5px;
}

.meta.visitor {
  align-self: flex-start;
}

.meta.agent {
  align-self: flex-end;
}

@keyframes msg-in {
  from { transform: translateY(6px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

.typing {
  align-self: flex-start;
  display: flex;
  gap: 5px;
  padding: 12px 16px;
  border: 1px solid var(--chat-border);
  border-radius: 18px;
  background: var(--chat-surface);
}

.typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--chat-muted);
  animation: blink 1.2s infinite;
}

.typing span:nth-child(2) { animation-delay: 0.2s; }
.typing span:nth-child(3) { animation-delay: 0.4s; }

@keyframes blink {
  0%, 80%, 100% { opacity: 0.25; }
  40% { opacity: 1; }
}

/* Composer: stays pinned to the bottom of the conversation. */

.composer {
  position: sticky;
  bottom: 0;
  flex: none;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px 16px;
  border-top: 1px solid var(--chat-border);
  background: var(--chat-surface);
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip {
  height: 32px;
  padding: 0 12px;
  border: 1px solid var(--chat-border);
  border-radius: 16px;
  background: var(--chat-panel);
  color: var(--chat-text-2);
  font-size: 13px;
}

.composer-row {
  position: relative;
  display: flex;
  align-items: flex-end;
  gap: 10px;
}

.composer textarea {
  flex: 1;
  min-width: 0;
  height: 48px;
  max-height: 140px;
  padding: 12px 14px;
  border: 1px solid var(--chat-field-border);
  border-radius: 12px;
  background: var(--chat-surface);
  resize: none;
  font-size: 15px;
  line-height: 22px;
}

.composer .btn {
  height: 48px;
  padding: 0 20px;
  border-radius: 12px;
  font-size: 15px;
}

.composer-note {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  color: var(--chat-text-2);
  font-weight: 600;
}

.canned-menu {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 56px;
  max-height: 240px;
  margin: 0;
  padding: 6px;
  overflow-y: auto;
  border: 1px solid var(--chat-border);
  border-radius: 12px;
  background: var(--chat-surface);
  box-shadow: 0 8px 24px rgba(17, 24, 39, 0.14);
  list-style: none;
}

.canned-menu li {
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
}

.canned-menu li[aria-selected='true'] {
  background: var(--chat-accent-soft);
}

.canned-menu b {
  display: block;
  font-size: 13px;
}

.canned-menu span {
  display: block;
  overflow: hidden;
  color: var(--chat-muted);
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.error-line {
  margin: 0;
  color: var(--danger-text);
  font-size: 13px;
  font-weight: 600;
}

/* Visitor details */

.details {
  flex: none;
  display: flex;
  flex-direction: column;
  gap: 18px;
  width: 280px;
  padding: 20px;
  overflow-y: auto;
  border-left: 1px solid var(--chat-border);
  background: var(--chat-surface);
}

.details-top {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--chat-border);
  text-align: center;
  overflow-wrap: anywhere;
}

.details-top b {
  font-size: 15px;
}

.facts {
  display: grid;
  gap: 12px;
  margin: 0;
  font-size: 13px;
}

.facts dt {
  color: var(--chat-muted);
}

.facts dd {
  margin: 0;
  font-weight: 600;
  overflow-wrap: anywhere;
}

/* Full-width pages: offline inbox, canned replies, agents */

.page {
  flex: 1;
  overflow-y: auto;
  padding: 24px 20px 40px;
}

.page-inner {
  display: flex;
  flex-direction: column;
  gap: 16px;
  max-width: 760px;
  margin: 0 auto;
}

.page h1 {
  margin: 0;
  font-size: 20px;
}

.card {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 16px;
  border: 1px solid var(--chat-border);
  border-radius: 12px;
  background: var(--chat-surface);
}

.card-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 4px 12px;
}

.card-person {
  display: flex;
  align-items: center;
  gap: 12px;
}

.card-person .card-head {
  flex: 1;
  min-width: 0;
}

.card-body {
  margin: 0;
  overflow-wrap: anywhere;
}

.card-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 14px;
}

.tag {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 10px;
  background: var(--ok-bg);
  color: var(--ok-text);
  font-size: 12px;
  font-weight: 600;
}

.tag.off {
  background: var(--chat-border);
  color: var(--chat-text-2);
}

.tag.warn {
  background: var(--danger-bg);
  color: var(--danger-text);
}

/* Narrower screens: details slide under the header on demand; on phones
   the list and the conversation are stacked and shown one at a time. */

@media (max-width: 1100px) {
  .details {
    display: none;
  }

  .layout.show-details .details {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    z-index: 5;
    display: flex;
    box-shadow: -8px 0 24px rgba(17, 24, 39, 0.12);
  }

  .layout {
    position: relative;
  }

  .details-toggle {
    display: inline-flex;
  }
}

@media (max-width: 720px) {
  .top {
    gap: 8px;
    padding: 8px 12px;
  }

  .top-right {
    gap: 6px;
  }

  .top-right .btn.ghost {
    padding: 0 8px;
  }

  .online-toggle {
    padding: 0 12px;
  }

  .tabs {
    order: 3;
    width: 100%;
    margin-left: 0;
  }

  .list {
    width: 100%;
    border-right: 0;
  }

  .layout[data-show='conv'] .list,
  .layout[data-show='list'] .conv {
    display: none;
  }

  .back {
    display: inline-flex;
  }

  .msg {
    max-width: 82%;
  }

  .layout.show-details .details {
    width: 100%;
  }

  .conv-head {
    padding: 10px 12px;
  }

  .messages {
    padding: 14px 12px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation: none !important;
    transition: none !important;
  }

  .typing span {
    opacity: 0.6;
  }
}
