:root {
  color-scheme: light;
  --bg: #f5f7fb;
  --app-bg: #e6edf7;
  --surface: #ffffff;
  --surface-soft: #f8faff;
  --surface-sunken: #eef4fb;
  --surface-muted: #f2f6fc;
  --surface-overlay: rgba(248, 250, 255, 0.94);
  --line: #d8e2ef;
  --line-soft: rgba(216, 226, 239, 0.72);
  --line-strong: #afbed2;
  --text: #171c2d;
  --text-soft: #35405c;
  --muted: #66738a;
  --muted-strong: #4f5d76;
  --accent: #1167ff;
  --accent-dark: #0b48c9;
  --accent-soft: #e8f1ff;
  --accent-tint: rgba(17, 103, 255, 0.14);
  --accent-border: rgba(17, 103, 255, 0.36);
  --blue: #009de8;
  --blue-soft: #e5f7ff;
  --amber: #a16207;
  --amber-soft: #fef3c7;
  --red: #b91c1c;
  --red-soft: #fee2e2;
  --purple: #7a20ff;
  --mine: #e2f8f3;
  --incoming: #ffffff;
  --chat-bg: #e8eef8;
  --chat-pattern: rgba(17, 103, 255, 0.035);
  --focus: rgba(17, 103, 255, 0.32);
  --focus-ring: 0 0 0 3px var(--focus);
  --radius-xs: 6px;
  --radius-sm: 8px;
  --radius-md: 10px;
  --radius-lg: 12px;
  --radius-pill: 999px;
  --control-sm: 36px;
  --control-md: 40px;
  --control-lg: 44px;
  --shadow-xs: 0 1px 2px rgba(23, 28, 45, 0.06);
  --shadow-sm: 0 10px 28px rgba(23, 28, 45, 0.08);
  --shadow: 0 22px 60px rgba(23, 28, 45, 0.14);
  --ease: 150ms ease;
  --font-sans: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-size-xs: 11px;
  --font-size-sm: 12px;
  --font-size-md: 13px;
  --font-size-base: 14px;
  --font-size-lg: 17px;
  --font-size-xl: 20px;
  --font-size-2xl: 24px;
}

* {
  box-sizing: border-box;
}

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

body {
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--app-bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: var(--font-size-base);
  letter-spacing: 0;
}

#app {
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

button:disabled,
input:disabled,
select:disabled,
textarea:disabled {
  cursor: not-allowed;
  opacity: 0.58;
}

input::placeholder,
textarea::placeholder {
  color: var(--muted);
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
.file-picker:focus-within {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  border-color: var(--accent);
  box-shadow: var(--focus-ring);
}

.tab:focus-visible,
.conversation-item:focus-visible,
.tag-option:focus-visible {
  outline-offset: -2px;
}

.login-page {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(360px, 440px);
  align-items: stretch;
  gap: 70px;
  position: relative;
  background: linear-gradient(140deg, #f9fbff 0%, #eef5ff 46%, #dff5fb 100%);
  overflow: hidden;
  padding: 48px;
}

.login-page::before,
.login-page::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.login-page::before {
  background:
    linear-gradient(115deg, rgba(119, 36, 255, 0.12), transparent 30%),
    linear-gradient(310deg, rgba(0, 191, 242, 0.14), transparent 38%);
}

.login-page::after {
  background:
    linear-gradient(90deg, rgba(15, 30, 55, 0.035) 1px, transparent 1px),
    linear-gradient(0deg, rgba(15, 30, 55, 0.035) 1px, transparent 1px);
  background-size: 48px 48px;
  -webkit-mask: radial-gradient(circle at 10% 8%, transparent 0 10%, rgba(0, 0, 0, 0.12) 20%, rgba(0, 0, 0, 0.58) 48%, #000 72%);
  mask: radial-gradient(circle at 10% 8%, transparent 0 10%, rgba(0, 0, 0, 0.12) 20%, rgba(0, 0, 0, 0.58) 48%, #000 72%);
}

.login-brand-panel {
  min-width: 0;
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-rows: auto 1fr;
}

.login-brand {
  display: grid;
  justify-items: start;
}

.login-copy h2,
.login-copy p,
.login-form-heading h2,
.login-form-heading p {
  margin: 0;
}

.brand-logo {
  display: block;
  width: 250px;
  height: auto;
}

.login-hero-stack {
  align-self: center;
  display: grid;
  gap: 24px;
}

.login-copy {
  max-width: 600px;
}

.login-copy h2 {
  max-width: 15ch;
  color: var(--text);
  font-size: clamp(50px, 5.3vw, 76px);
  line-height: 0.91;
  letter-spacing: 0;
}

.login-copy p {
  max-width: 560px;
  margin-top: 18px;
  color: #304263;
  font-size: var(--font-size-lg);
  line-height: 1.45;
}

.login-preview {
  width: min(660px, 100%);
  display: grid;
  gap: 14px;
  position: relative;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.26);
  border-radius: 20px;
  background:
    linear-gradient(145deg, rgba(18, 22, 48, 0.96), rgba(35, 28, 82, 0.94) 56%, rgba(0, 104, 190, 0.9));
  box-shadow: 0 28px 80px rgba(40, 59, 91, 0.22);
  color: #fff;
  padding: 18px;
}

.login-preview::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    linear-gradient(105deg, rgba(255, 255, 255, 0.1), transparent 34%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.08), transparent);
  pointer-events: none;
}

.login-preview > * {
  position: relative;
}

.login-preview-topline,
.login-preview-tags {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.login-preview-topline {
  justify-content: space-between;
  color: rgba(255, 255, 255, 0.76);
  font-size: var(--font-size-md);
  font-weight: 780;
}

.login-preview-topline span,
.login-preview-topline strong,
.login-preview-tags span {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  border-radius: var(--radius-pill);
  background: rgba(255, 255, 255, 0.1);
  padding: 0 10px;
}

.login-preview-topline i {
  width: 7px;
  height: 7px;
  margin-right: 7px;
  border-radius: 50%;
  background: #34d399;
  box-shadow: 0 0 0 4px rgba(52, 211, 153, 0.15);
}

.login-preview-header {
  display: grid;
  grid-template-columns: 46px minmax(0, 1fr);
  align-items: center;
  gap: 12px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.08);
  padding: 10px;
}

.login-preview-avatar {
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--purple), var(--blue));
  color: #fff;
  font-size: var(--font-size-sm);
  font-weight: 850;
  line-height: 1;
}

.login-preview-header strong,
.login-preview-meta span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.login-preview-header strong {
  color: #fff;
}

.login-preview-meta span {
  color: rgba(255, 255, 255, 0.7);
  font-size: var(--font-size-md);
  font-weight: 800;
}

.login-preview-tags span {
  min-height: 24px;
  color: rgba(255, 255, 255, 0.82);
  font-size: var(--font-size-xs);
  font-weight: 820;
}

.login-preview-messages {
  display: grid;
  gap: 10px;
}

.login-preview-messages span {
  width: fit-content;
  max-width: 86%;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 14px 14px 14px 5px;
  background: rgba(255, 255, 255, 0.92);
  color: var(--text);
  padding: 10px 12px;
  box-shadow: 0 10px 30px rgba(10, 16, 32, 0.16);
}

.login-preview-messages span:last-child {
  justify-self: end;
  border-color: rgba(125, 249, 255, 0.26);
  border-radius: 14px 14px 5px 14px;
  background: rgba(220, 252, 250, 0.96);
}

.login-panel {
  align-self: center;
  width: min(420px, 100%);
  position: relative;
  overflow: hidden;
  z-index: 1;
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid rgba(255, 255, 255, 0.88);
  border-radius: 18px;
  box-shadow: 0 1px 2px rgba(45, 61, 91, 0.04);
  padding: 34px;
}

.login-panel::before {
  content: none;
}

.login-form-heading {
  margin-bottom: 24px;
}

.login-form-heading h2 {
  font-size: var(--font-size-2xl);
  line-height: 1.1;
}

.login-form-heading p {
  margin-top: 6px;
  color: var(--muted);
  font-size: var(--font-size-base);
}

.login-panel .primary {
  width: 100%;
  min-height: var(--control-lg);
  margin-top: 4px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 26px;
}

.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: var(--radius-sm);
  display: grid;
  place-items: center;
  background: var(--accent);
  color: #fff;
  font-weight: 800;
}

.brand-mark-image {
  overflow: hidden;
  background: transparent;
  box-shadow: 0 10px 22px rgba(17, 103, 255, 0.16);
}

.brand-mark-image img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.brand-wordmark {
  display: block;
  width: 116px;
  height: auto;
}

.brand h1 {
  margin: 0;
  font-size: 26px;
  line-height: 1;
}

.brand p {
  margin: 4px 0 0;
  color: var(--muted);
}

.brand.compact {
  margin-bottom: 0;
}

.platform-brand {
  display: grid;
  align-content: center;
}

.brand.compact h1 {
  font-size: 20px;
}

.brand.compact .brand-mark {
  width: 36px;
  height: 36px;
}

.field {
  display: grid;
  gap: 7px;
  margin-bottom: 14px;
}

.field span {
  color: var(--muted);
  font-size: var(--font-size-md);
  font-weight: 650;
}

.field input,
.field select,
.field textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  padding: 11px 12px;
  outline: none;
  transition: background var(--ease), border-color var(--ease), box-shadow var(--ease);
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  border-color: var(--accent);
  box-shadow: var(--focus-ring);
}

.password-control {
  position: relative;
}

.password-control input {
  padding-right: 46px;
}

.password-toggle {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: var(--radius-xs);
  background: transparent;
  color: var(--muted);
  transition: background var(--ease), color var(--ease);
}

.password-toggle:hover,
.password-toggle:focus-visible {
  background: var(--surface-soft);
  color: var(--accent-dark);
}

.file-picker {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  min-height: 45px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  padding: 6px;
  transition: background var(--ease), border-color var(--ease), box-shadow var(--ease);
}

.file-picker input {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  opacity: 0;
  pointer-events: none;
}

.file-picker-button {
  display: inline-grid !important;
  place-items: center;
  min-height: 32px;
  border-radius: var(--radius-xs);
  background: var(--surface-soft);
  border: 1px solid var(--line);
  color: var(--text) !important;
  padding: 0 10px;
  font-size: var(--font-size-md) !important;
  font-weight: 800 !important;
}

.file-picker-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--muted) !important;
  font-size: var(--font-size-md) !important;
}

.file-picker:focus-within {
  border-color: var(--accent);
  box-shadow: var(--focus-ring);
}

.primary {
  min-height: var(--control-md);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: #fff;
  font-weight: 750;
  padding: 0 14px;
  transition: background var(--ease), box-shadow var(--ease), transform var(--ease);
}

.primary:hover {
  background: var(--accent-dark);
}

.primary:disabled {
  background: var(--muted);
}

.primary:active {
  transform: translateY(1px);
}

.secondary,
.icon-btn {
  min-height: var(--control-sm);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border-radius: var(--radius-sm);
  background: var(--surface-soft);
  border: 1px solid var(--line);
  color: var(--text);
  font-weight: 700;
  padding: 0 12px;
  transition: background var(--ease), border-color var(--ease), color var(--ease), transform var(--ease);
}

.secondary:hover,
.icon-btn:hover {
  border-color: var(--line-strong);
  background: var(--surface);
}

.secondary:active,
.icon-btn:active {
  transform: translateY(1px);
}

.primary:disabled,
.secondary:disabled,
.icon-btn:disabled {
  transform: none;
}

.icon-only {
  width: 40px;
  padding: 0;
  display: inline-grid;
  place-items: center;
}

.sound-toggle.active {
  border-color: var(--accent-border);
  background: var(--accent-soft);
  color: var(--accent-dark);
}

.btn-icon {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.danger {
  color: var(--red);
}

.danger-action {
  background: var(--red);
  color: #fff;
}

.danger-action:hover {
  background: #991b1b;
}

.danger-action:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

.error {
  min-height: 22px;
  color: var(--red);
  font-size: var(--font-size-md);
  margin-top: 10px;
}

.app-shell {
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  min-height: 0;
  margin: 0;
  display: grid;
  grid-template-columns: minmax(360px, 32vw) 1fr;
  background: var(--bg);
  border: 0;
  border-radius: 0;
  box-shadow: none;
  overflow: hidden;
}

.sidebar {
  display: grid;
  grid-template-rows: auto auto auto 1fr;
  height: 100%;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  border-right: 1px solid var(--line);
  background: var(--surface-muted);
}

.topbar,
.chat-header {
  flex: 0 0 auto;
  min-height: 62px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-muted);
}

.topbar {
  height: 62px;
  max-height: 62px;
  overflow: hidden;
  background: var(--surface);
}

.chat-header {
  height: auto;
  align-items: center;
  overflow: visible;
  flex-wrap: wrap;
  background: var(--surface);
  box-shadow: 0 1px 0 var(--line);
}

.profile {
  flex: 1 1 auto;
  min-width: 0;
}

.tenant-identity {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 10px;
}

.tenant-logo {
  flex: 0 0 auto;
  width: 38px;
  height: 38px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--surface);
  object-fit: contain;
  padding: 3px;
}

.chat-contact {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 12px;
}

.chat-contact-mark {
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--blue));
  color: #fff;
  font-weight: 850;
  letter-spacing: 0;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.24);
}

.chat-title {
  flex: 1 1 auto;
  min-width: 0;
}

.profile strong,
.chat-title strong {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-title strong {
  font-size: var(--font-size-lg);
  line-height: 1.2;
}

.profile span,
.chat-title span,
.meta {
  color: var(--muted);
  font-size: var(--font-size-md);
}

.meta.assigned-mine {
  color: var(--accent-dark);
  font-weight: 850;
}

.toolbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 8px;
}

.tabs {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 6px;
  padding: 12px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.tab {
  min-height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--muted);
  font-size: var(--font-size-md);
  font-weight: 750;
  min-width: 0;
  padding: 0 6px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  transition: background var(--ease), color var(--ease);
}

.tab span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tab.active {
  background: var(--accent-soft);
  color: var(--accent-dark);
}

.tab:hover {
  background: var(--surface-sunken);
  color: var(--text-soft);
}

.tab.active:hover {
  background: var(--accent-soft);
  color: var(--accent-dark);
}

.search {
  padding: 12px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-muted);
}

.search input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 10px 12px 10px 14px;
  outline: none;
  background: var(--surface);
  transition: border-color var(--ease), box-shadow var(--ease);
  box-shadow: var(--shadow-xs);
}

.conversation-list {
  min-height: 0;
  max-height: 100%;
  overflow-y: auto;
  display: grid;
  align-content: start;
  gap: 8px;
  padding: 10px;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.conversation-item {
  position: relative;
  width: 100%;
  min-height: 72px;
  display: grid;
  grid-template-columns: 46px 1fr;
  gap: 12px;
  align-items: start;
  padding: 12px;
  background: rgba(255, 255, 255, 0.78);
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  color: var(--text);
  text-align: left;
  box-shadow: none;
  overflow: hidden;
  transition: background var(--ease), border-color var(--ease), box-shadow var(--ease), opacity var(--ease), filter var(--ease);
}

.conversation-item:hover,
.conversation-item.active {
  background: var(--surface);
  border-color: var(--line);
  box-shadow: var(--shadow-xs);
}

.conversation-item.active {
  border-color: var(--accent-border);
}

.conversation-item.active::before {
  content: "";
  position: absolute;
  inset: 10px auto 10px 0;
  width: 3px;
  border-radius: 0 var(--radius-pill) var(--radius-pill) 0;
  background: var(--accent);
}

.conversation-item.is-closed {
  opacity: 0.52;
  filter: grayscale(0.75);
}

.conversation-item.is-closed:hover,
.conversation-item.is-closed.active {
  opacity: 0.72;
  background: var(--surface-muted);
}

.conversation-item.is-closed .avatar {
  background: #8a9692;
}

.avatar {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--blue));
  font-weight: 850;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.22);
}

.conversation-main {
  align-self: center;
  min-width: 0;
  display: grid;
  gap: 4px;
}

.conversation-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  line-height: 1.24;
}

.conversation-name,
.last-message {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.conversation-name {
  font-weight: 820;
}

.conversation-row .meta {
  flex: 0 0 auto;
}

.conversation-time {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: var(--font-size-sm);
  font-variant-numeric: tabular-nums;
}

.conversation-preview-row {
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
}

.last-message {
  color: var(--muted);
  font-size: var(--font-size-md);
}

.conversation-assignment {
  max-width: 118px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  border-radius: var(--radius-pill);
  background: var(--surface-sunken);
  color: var(--muted-strong);
  padding: 3px 8px;
  font-size: var(--font-size-sm);
  font-weight: 800;
}

.conversation-assignment.queue,
.conversation-assignment.assigned-mine {
  background: var(--accent-soft);
  color: var(--accent-dark);
}

.conversation-assignment.assigned {
  background: var(--blue-soft);
  color: var(--blue);
}

.conversation-assignment.closed,
.conversation-assignment.history {
  background: var(--surface-sunken);
  color: var(--muted-strong);
}

.badges {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 6px;
}

.badge {
  max-width: 130px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  border-radius: var(--radius-pill);
  padding: 3px 8px;
  background: var(--surface-sunken);
  color: var(--text);
  font-size: var(--font-size-sm);
  font-weight: 750;
}

.badge.color {
  color: #fff;
}

.empty {
  height: 100%;
  display: grid;
  place-items: center;
  padding: 22px;
  color: var(--muted);
  text-align: center;
  line-height: 1.4;
}

.chat-pane {
  min-width: 0;
  min-height: 0;
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background:
    linear-gradient(rgba(232, 239, 237, 0.84), rgba(232, 239, 237, 0.84)),
    repeating-linear-gradient(45deg, var(--chat-pattern) 0 1px, transparent 1px 18px),
    var(--chat-bg);
}

.chat-pane.is-closed {
  filter: grayscale(0.35);
}

.chat-pane.is-closed .messages {
  opacity: 0.72;
}

.chat-pane > .empty {
  flex: 1 1 auto;
}

.chat-actions {
  flex: 1 1 360px;
  min-width: min(100%, 280px);
  max-width: 100%;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
  align-content: flex-start;
  overflow-x: auto;
  overflow-y: visible;
  scrollbar-gutter: stable;
}

.chat-actions > * {
  flex: 0 0 auto;
}

.chat-actions,
.tag-bar {
  scrollbar-width: thin;
  scrollbar-color: rgba(102, 117, 113, 0.42) transparent;
}

.chat-actions::-webkit-scrollbar,
.tag-bar::-webkit-scrollbar {
  height: 8px;
}

.chat-actions::-webkit-scrollbar-thumb,
.tag-bar::-webkit-scrollbar-thumb {
  background: rgba(102, 117, 113, 0.38);
  border-radius: var(--radius-pill);
  border: 2px solid transparent;
  background-clip: content-box;
}

.status-pill {
  min-height: 30px;
  display: inline-flex;
  align-items: center;
  border: 1px solid transparent;
  border-radius: var(--radius-pill);
  padding: 0 10px;
  font-size: var(--font-size-sm);
  font-weight: 800;
}

.status-pill.closed {
  background: #e5e7eb;
  color: #4b5563;
}

.status-pill.busy {
  background: var(--blue-soft);
  color: var(--blue);
}

.status-pill.active {
  background: var(--accent-soft);
  color: var(--accent-dark);
}

.status-pill.history {
  background: var(--amber-soft);
  color: #92400e;
}

.status-pill.window-open {
  background: #ecfdf5;
  color: #047857;
}

.status-pill.window-closed {
  background: var(--red-soft);
  color: #b91c1c;
}

.tag-bar {
  flex: 0 0 53px;
  height: 53px;
  min-height: 53px;
  max-height: 53px;
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-overlay);
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-gutter: stable;
  overscroll-behavior-x: contain;
  -webkit-overflow-scrolling: touch;
}

.tag-bar.disabled {
  opacity: 0.58;
}

.tag-option {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: var(--radius-pill);
  padding: 6px 10px;
  font-size: var(--font-size-md);
  font-weight: 750;
  transition: background var(--ease), border-color var(--ease), color var(--ease), transform var(--ease);
}

.tag-option.active {
  background: var(--accent-soft);
  border-color: var(--accent-border);
  color: var(--accent-dark);
}

.tag-option:hover:not(:disabled) {
  border-color: var(--line-strong);
  transform: translateY(-1px);
}

.tag-option:disabled {
  cursor: wait;
  opacity: 0.72;
}

.tag-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

.messages {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 9px;
  overflow-y: auto;
  padding: 24px clamp(16px, 3vw, 38px) 56px;
  scrollbar-gutter: stable;
}

.messages::after {
  content: "";
  flex: 0 0 12px;
}

.messages::-webkit-scrollbar,
.conversation-list::-webkit-scrollbar {
  width: 10px;
}

.messages::-webkit-scrollbar-thumb,
.conversation-list::-webkit-scrollbar-thumb {
  background: rgba(102, 117, 113, 0.34);
  border-radius: var(--radius-pill);
  border: 2px solid transparent;
  background-clip: content-box;
}

.message {
  width: fit-content;
  max-width: min(680px, 74%);
  padding: 10px 12px 8px;
  border: 1px solid rgba(23, 28, 45, 0.08);
  border-radius: 14px 14px 14px 5px;
  background: var(--incoming);
  box-shadow: var(--shadow-xs);
}

.message.customer {
  background: var(--incoming);
}

.message.mine {
  align-self: flex-end;
  background: var(--mine);
  border-color: rgba(17, 103, 255, 0.16);
  border-radius: 14px 14px 5px 14px;
}

.message.agent {
  box-shadow: 0 4px 14px rgba(17, 103, 255, 0.08);
}

.message.ai {
  background: #eef6ff;
  border-color: rgba(0, 157, 232, 0.18);
  border-radius: 14px 14px 14px 5px;
}

.message.system {
  align-self: center;
  background: rgba(255, 255, 255, 0.72);
  color: var(--muted);
  font-size: var(--font-size-md);
  border-color: transparent;
  border-radius: var(--radius-pill);
  box-shadow: none;
}

.message-label {
  color: var(--blue);
  font-size: var(--font-size-xs);
  font-weight: 850;
  margin-bottom: 3px;
}

.message-body {
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.42;
}

.message-time {
  color: var(--muted);
  font-size: var(--font-size-xs);
  margin-top: 5px;
  text-align: right;
}

.message.mine .message-time {
  color: var(--muted-strong);
}

.composer {
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
  gap: 10px;
  padding: 12px 16px;
  border-top: 1px solid var(--line);
  background: rgba(248, 250, 249, 0.96);
}

.composer-input {
  min-width: 0;
  display: grid;
}

.readonly-bar {
  flex: 0 0 auto;
  min-height: 50px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 10px 16px;
  border-top: 1px solid var(--line);
  background: var(--surface-muted);
  color: var(--muted);
  font-size: var(--font-size-base);
  font-weight: 750;
}

.composer textarea {
  width: 100%;
  min-height: 44px;
  max-height: 130px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  padding: 11px 12px;
  outline: none;
  transition: border-color var(--ease), box-shadow var(--ease);
}

.composer .primary {
  min-width: 92px;
}

.composer textarea:focus {
  border-color: var(--accent);
}

.notice {
  position: fixed;
  right: 22px;
  top: 76px;
  width: min(360px, calc(100vw - 44px));
  background: var(--accent);
  border: 1px solid rgba(255, 255, 255, 0.18);
  color: #f7fffd;
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  box-shadow: 0 18px 45px rgba(17, 103, 255, 0.24);
  font-weight: 750;
  z-index: 10;
}

.platform-shell {
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  display: grid;
  grid-template-rows: auto 1fr;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.66) 0, rgba(255, 255, 255, 0) 220px),
    var(--bg);
  overflow: hidden;
}

.platform-topbar {
  min-height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 12px 22px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
  box-shadow: var(--shadow-xs);
}

.platform-user {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  min-width: 0;
}

.platform-user div {
  min-width: 0;
  text-align: right;
}

.platform-user strong,
.platform-user span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.platform-user span {
  color: var(--muted);
  font-size: var(--font-size-md);
}

.platform-content {
  width: 100%;
  max-width: none;
  min-height: 0;
  margin: 0;
  overflow-y: auto;
  padding: 24px clamp(18px, 2.6vw, 48px) 36px;
}

.platform-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.platform-heading h2,
.platform-heading p {
  margin: 0;
}

.platform-heading h2 {
  font-size: var(--font-size-2xl);
  line-height: 1.12;
}

.platform-heading p {
  margin-top: 4px;
  color: var(--muted);
  font-size: var(--font-size-base);
}

.platform-overview {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.platform-metric {
  min-width: 0;
  display: grid;
  gap: 4px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--surface);
  box-shadow: var(--shadow-xs);
}

.platform-metric span,
.platform-metric small {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.platform-metric span {
  color: var(--muted);
  font-size: var(--font-size-sm);
  font-weight: 800;
}

.platform-metric strong {
  font-size: var(--font-size-2xl);
  line-height: 1.06;
}

.platform-metric small {
  color: var(--muted-strong);
  font-size: var(--font-size-md);
}

.tenant-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(360px, 1fr));
  gap: 14px;
}

.tenant-card {
  min-width: 0;
  display: grid;
  gap: 16px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--surface);
  box-shadow: var(--shadow-xs);
  transition: border-color var(--ease), box-shadow var(--ease), transform var(--ease);
}

.tenant-card:hover {
  border-color: var(--line-strong);
  box-shadow: var(--shadow-sm);
  transform: translateY(-1px);
}

.tenant-card.inactive {
  background: var(--surface-soft);
}

.tenant-card.inactive .tenant-card-header,
.tenant-card.inactive .tenant-card-body {
  opacity: 0.58;
  filter: grayscale(0.55);
}

.tenant-card.inactive footer .secondary,
.tenant-card.inactive footer .icon-btn {
  background: var(--surface);
  color: var(--text);
  border-color: var(--line-strong);
}

.tenant-card.inactive footer .danger {
  color: var(--red);
}

.tenant-card-header {
  display: grid;
  grid-template-columns: 50px minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
}

.tenant-card-logo {
  width: 50px;
  height: 50px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: linear-gradient(135deg, var(--surface), var(--accent-soft));
  color: var(--accent-dark);
  font-weight: 850;
  overflow: hidden;
}

.tenant-card-logo img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  padding: 4px;
  background: var(--surface);
}

.tenant-card-header strong,
.tenant-card-header span,
.tenant-card-body strong,
.tenant-card-body span {
  display: block;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tenant-card-title {
  min-width: 0;
}

.tenant-card-title > strong {
  font-size: var(--font-size-lg);
}

.tenant-card-title > span {
  color: var(--muted);
  font-size: var(--font-size-md);
}

.tenant-card-body {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.tenant-card-body div {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface-soft);
  padding: 10px;
}

.tenant-card-body span {
  color: var(--muted);
  font-size: var(--font-size-sm);
  font-weight: 750;
}

.tenant-card-body strong {
  margin-top: 3px;
  font-size: var(--font-size-lg);
  line-height: 1.12;
}

.tenant-card footer {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
  padding-top: 2px;
}

.tenant-status {
  align-self: start;
  border-radius: var(--radius-pill);
  padding: 5px 9px;
  font-size: var(--font-size-sm);
  font-weight: 850;
  white-space: nowrap;
}

.tenant-status.active {
  background: var(--accent-soft);
  color: var(--accent-dark);
}

.tenant-status.inactive {
  background: #e5e7eb;
  color: #6b7280;
}

.admin-empty {
  min-height: 260px;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.58);
}

.platform-dialog {
  width: min(720px, 100%);
}

.delete-dialog {
  width: min(460px, 100%);
}

.history-dialog {
  width: min(760px, 100%);
}

.dialog-subtitle {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: var(--font-size-md);
}

.history-modal-messages {
  height: min(68vh, 620px);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: linear-gradient(135deg, #f4ede4 0%, #efe7db 100%);
}

.confirm-text {
  margin: 0;
  color: var(--muted);
  line-height: 1.4;
}

.dialog-backdrop {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(23, 28, 45, 0.38);
  padding: 20px;
  z-index: 20;
}

.dialog {
  width: min(560px, 100%);
  max-height: calc(100vh - 40px);
  overflow-y: auto;
  background: var(--surface);
  border-radius: var(--radius-md);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  padding: 20px;
}

.dialog header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  margin-bottom: 18px;
}

.dialog h2 {
  margin: 0;
  font-size: var(--font-size-xl);
}

.dialog-heading {
  min-width: 0;
}

.dialog-heading p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: var(--font-size-md);
}

.admin-section {
  display: grid;
  gap: 12px;
  padding: 16px 0;
  border-top: 1px solid var(--line);
}

.admin-section h3 {
  margin: 0;
  font-size: var(--font-size-lg);
  line-height: 1.2;
}

.section-hint {
  margin: -4px 0 2px;
  color: var(--muted);
  font-size: var(--font-size-md);
}

.logo-setting {
  display: grid;
  grid-template-columns: 76px 1fr;
  align-items: center;
  gap: 12px;
}

.logo-preview {
  width: 72px;
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--muted);
  font-size: var(--font-size-sm);
  font-weight: 750;
  overflow: hidden;
  text-align: center;
}

.logo-preview img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  padding: 6px;
  background: transparent;
}

.user-list {
  display: grid;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--surface);
}

.user-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.user-row:last-child {
  border-bottom: 0;
}

.user-row div,
.user-row-main {
  min-width: 0;
}

.user-row-main {
  display: grid;
  grid-template-columns: 36px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
}

.user-avatar {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent-dark);
  font-size: var(--font-size-sm);
  font-weight: 850;
}

.user-status {
  justify-self: end;
  border-radius: var(--radius-pill);
  padding: 4px 8px;
  font-size: var(--font-size-sm);
  font-weight: 800;
  white-space: nowrap;
}

.user-status.active {
  background: var(--accent-soft);
  color: var(--accent-dark);
}

.user-status.inactive {
  background: #e5e7eb;
  color: #6b7280;
}

.user-actions {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 8px;
}

.user-row-main strong,
.user-row-main > div > span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-row-main > div > span {
  color: var(--muted);
  font-size: var(--font-size-md);
}

.user-form {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.user-form button {
  align-self: end;
}

.admin-wide-action {
  width: 100%;
}

.user-form .admin-wide-action {
  grid-column: 1 / -1;
}

.tag-admin-list {
  display: grid;
  gap: 8px;
}

.tag-admin-row {
  display: grid;
  grid-template-columns: 22px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
}

.tag-admin-row .tag-dot {
  justify-self: center;
}

.tag-admin-row input[type="text"],
.tag-admin-row input[name="name"] {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 10px 11px;
  outline: none;
  transition: border-color var(--ease), box-shadow var(--ease);
}

.tag-admin-row input[type="text"]:focus,
.tag-admin-row input[name="name"]:focus {
  border-color: var(--accent);
  box-shadow: var(--focus-ring);
}

.compact-empty {
  padding: 12px;
  font-size: var(--font-size-md);
}

.dialog footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 18px;
}

.hidden {
  display: none !important;
}

@media (max-width: 1200px) {
  .platform-overview {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .tenant-card-header {
    grid-template-columns: 48px minmax(0, 1fr) auto;
  }
}

@media (max-width: 900px) {
  .notice {
    top: 12px;
    right: 12px;
    width: min(360px, calc(100vw - 24px));
  }

  .login-page {
    grid-template-columns: 1fr;
    align-content: start;
    gap: 22px;
    overflow-y: auto;
    padding: 18px;
  }

  .login-brand-panel {
    align-content: start;
    gap: 18px;
    padding: 0;
  }

  .brand-logo {
    width: min(260px, 100%);
  }

  .login-copy h2 {
    max-width: 15ch;
    font-size: 36px;
  }

  .login-copy p {
    margin-top: 12px;
    font-size: var(--font-size-base);
  }

  .login-preview {
    display: none;
  }

  .login-panel {
    align-self: start;
    width: 100%;
    padding: 22px;
  }

  .app-shell {
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    margin: 0;
    border: 0;
    border-radius: 0;
    grid-template-columns: 1fr;
  }

  .tabs {
    grid-template-columns: repeat(5, minmax(82px, 1fr));
    overflow-x: auto;
  }

  .conversation-list {
    padding: 8px;
  }

  .conversation-item {
    grid-template-columns: 42px 1fr;
    min-height: 66px;
    gap: 10px;
    padding: 10px;
  }

  .avatar {
    width: 42px;
    height: 42px;
  }

  .app-shell.chat-open .sidebar {
    display: none;
  }

  .app-shell:not(.chat-open) .chat-pane {
    display: none;
  }

  .message {
    max-width: 88%;
  }

  .mobile-back {
    display: inline-grid;
  }

  .chat-header {
    align-items: stretch;
    padding: 10px 12px;
  }

  .chat-contact {
    flex-basis: calc(100% - 96px);
  }

  .chat-contact-mark {
    width: 36px;
    height: 36px;
    font-size: var(--font-size-md);
  }

  .chat-title strong {
    font-size: var(--font-size-base);
  }

  .chat-actions {
    flex-basis: 100%;
    flex-wrap: nowrap;
    justify-content: flex-start;
    padding-bottom: 2px;
  }

  .messages {
    padding: 16px 12px 42px;
  }

  .composer {
    grid-template-columns: 1fr;
    padding: 10px 12px 12px;
  }

  .composer .primary {
    width: 100%;
  }

  .platform-topbar,
  .platform-heading {
    align-items: stretch;
    flex-direction: column;
  }

  .platform-content {
    padding: 16px 12px 28px;
  }

  .platform-user {
    justify-content: space-between;
  }

  .platform-user div {
    text-align: left;
  }

  .platform-overview {
    grid-template-columns: 1fr;
  }

  .tenant-grid {
    grid-template-columns: 1fr;
  }

  .tenant-card-body,
  .user-form {
    grid-template-columns: 1fr;
  }

  .tenant-card footer {
    justify-content: stretch;
  }

  .tenant-card footer .secondary {
    flex: 1 1 auto;
  }

  .user-row {
    grid-template-columns: minmax(0, 1fr) auto;
  }

  .user-status {
    grid-column: 1 / -1;
    justify-self: start;
  }

  .tag-admin-row {
    grid-template-columns: 22px minmax(0, 1fr);
  }

  .tag-admin-row .secondary {
    grid-column: 1 / -1;
  }
}

@media (min-width: 901px) {
  .mobile-back {
    display: none;
  }
}
