﻿@import url("https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@300;400;500;600;700&display=swap");

:root {
  --z-bg: #f6f7fb;
  --z-surface: #ffffff;
  --z-surface-2: #f1f5f9;
  --z-border: #e5e7eb;
  --z-text: #0f172a;
  --z-muted: #64748b;
  --z-brand: #4f46e5;
  --z-brand-weak: #eef2ff;
  --z-brand-accent: #38bdf8;
  --z-brand-text: #ffffff;
  --z-sidebar-w: 18rem;
  --z-topbar-h: 3.75rem;
  --shadow-soft: 0 1px 2px rgba(15, 23, 42, 0.08);
  --shadow-hard: 0 12px 24px rgba(15, 23, 42, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Plus Jakarta Sans", ui-sans-serif, system-ui, sans-serif;
  color: var(--z-text);
  background: var(--z-bg);
}

.hidden {
  display: none !important;
}

.auth-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background: #f8fafc;
}

.auth-card {
  width: min(420px, 90vw);
  background: var(--z-surface);
  border: 1px solid var(--z-border);
  border-radius: 20px;
  padding: 2rem;
  box-shadow: var(--shadow-hard);
  display: grid;
  gap: 1.25rem;
}

.auth-brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.auth-logo {
  width: 48px;
  height: 48px;
  border-radius: 14px;
  border: 1px solid transparent;
  background: transparent;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.auth-logo img {
  width: 70%;
  height: 70%;
  object-fit: contain;
}

.auth-title {
  font-size: 1rem;
  font-weight: 700;
}

.auth-sub {
  font-size: 0.75rem;
  color: var(--z-muted);
}

.auth-heading-title {
  font-size: 1.1rem;
  font-weight: 700;
}

.auth-heading-sub {
  font-size: 0.85rem;
  color: var(--z-muted);
}

.auth-form {
  display: grid;
  gap: 0.9rem;
}

.auth-form label {
  display: grid;
  gap: 0.4rem;
  font-size: 0.8rem;
  color: var(--z-muted);
}

.auth-form input {
  border: 1px solid var(--z-border);
  border-radius: 12px;
  padding: 0.65rem 0.8rem;
  font-size: 0.9rem;
  color: var(--z-text);
  background: var(--z-surface);
}

.auth-msg {
  font-size: 0.8rem;
  padding: 0.5rem 0.7rem;
  border-radius: 10px;
  display: none;
}

.auth-msg.error {
  background: #fee2e2;
  color: #991b1b;
  border: 1px solid #fecaca;
}

.auth-msg.success {
  background: #dcfce7;
  color: #166534;
  border: 1px solid #bbf7d0;
}

.auth-msg.show {
  display: block;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: var(--z-sidebar-w) 1fr;
}

.sidebar {
  background: var(--z-surface);
  color: var(--z-text);
  padding: 1.5rem 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  border-right: 1px solid var(--z-border);
}

.sidebar-backdrop {
  display: none;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--z-border);
}

.brand-mark {
  width: 36px;
  height: 36px;
  border-radius: 12px;
  background: transparent;
  border: 1px solid transparent;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

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

.brand-title {
  font-weight: 600;
  letter-spacing: 0.01em;
  color: var(--z-text);
  font-size: 0.875rem;
}

.brand-sub {
  font-size: 0.6875rem;
  color: var(--z-muted);
}

.nav {
  display: grid;
  gap: 0.5rem;
  padding-top: 0.75rem;
}

.nav-item {
  background: transparent;
  color: var(--z-text);
  border: 1px solid transparent;
  padding: 0.45rem 0.7rem;
  border-radius: 10px;
  text-align: left;
  font-weight: 500;
  font-size: 0.875rem;
  cursor: pointer;
  transition: all 0.2s ease;
}

.nav-item:hover {
  border-color: var(--z-border);
  background: var(--z-surface-2);
}

.nav-item.active {
  background: var(--z-brand-weak);
  border-color: rgba(79, 70, 229, 0.3);
  color: #4338ca;
}

.sidebar-foot {
  margin-top: auto;
  display: grid;
  gap: 0.75rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--z-border);
}

.user-block {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.user-initials {
  width: 36px;
  height: 36px;
  border-radius: 999px;
  background: var(--z-surface-2);
  border: 1px solid var(--z-border);
  color: var(--z-text);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  font-weight: 600;
}

.user-info {
  min-width: 0;
}

.user-name {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--z-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-email {
  font-size: 0.62rem;
  color: var(--z-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.btn-signout {
  width: 100%;
  font-size: 0.7rem;
  color: var(--z-text);
  padding: 0.45rem 0.7rem;
  border-radius: 10px;
  background: var(--z-surface-2);
  border: 1px solid var(--z-border);
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-signout:hover {
  border-color: #f43f5e;
  color: #f43f5e;
}

.footer-brand {
  font-size: 0.62rem;
  color: var(--z-muted);
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.brand-mini {
  font-weight: 600;
  color: var(--z-brand);
}

.flag-dr {
  width: 18px;
  height: 12px;
  border-radius: 2px;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.2);
  object-fit: cover;
}

.main {
  display: grid;
  grid-template-rows: var(--z-topbar-h) 1fr;
  height: 100vh;
  min-height: 0;
  overflow: hidden;
}

#view-host {
  min-height: 0;
  overflow: auto;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.5rem;
  background: var(--z-surface);
  border-bottom: 1px solid var(--z-border);
  box-shadow: 0 1px 0 rgba(15, 23, 42, 0.03);
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.menu-toggle {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  border: 1px solid var(--z-border);
  background: var(--z-surface);
  display: none;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 4px;
  cursor: pointer;
}

.menu-toggle span {
  width: 16px;
  height: 2px;
  background: var(--z-text);
  border-radius: 999px;
}

.page-title {
  font-size: 1.1rem;
  font-weight: 600;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.search input {
  border: 1px solid var(--z-border);
  padding: 0.5rem 0.8rem;
  border-radius: 12px;
  min-width: 280px;
  background: var(--z-surface);
  font-size: 0.8rem;
}

.content {
  display: grid;
  grid-template-columns: 1.1fr 2fr 1fr;
  gap: 1.25rem;
  padding: 1.5rem;
  min-height: 0;
}

.view {
  display: none;
}

.view.active {
  display: grid;
}

.inbox-view {
  grid-template-columns: 1.1fr 2fr 1fr;
}

.single-view {
  grid-template-columns: 1fr;
}

.grid-2 {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.grid-3 {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.span-3 {
  grid-column: span 3;
}

.panel {
  background: var(--z-surface);
  border: 1px solid var(--z-border);
  border-radius: 16px;
  box-shadow: var(--shadow-soft);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.panel-body {
  padding: 1rem 1.2rem 1.2rem;
  display: grid;
  gap: 0.75rem;
}

.muted {
  color: var(--z-muted);
  font-size: 0.85rem;
}

.channel-actions {
  display: flex;
  gap: 0.6rem;
}

.stack {
  display: grid;
  gap: 0.5rem;
}

.channel-soon {
  padding: 0.65rem 0.8rem;
  border-radius: 12px;
  background: var(--z-surface-2);
  border: 1px solid var(--z-border);
  color: var(--z-muted);
  font-size: 0.8rem;
}

.channel-row {
  padding: 0.7rem 0.9rem;
  border-radius: 12px;
  background: var(--z-surface-2);
  border: 1px solid var(--z-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.channel-row-actions {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-shrink: 0;
}

.channel-row .channel-actions {
  gap: 0.4rem;
}

.channel-color {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.35rem 0.5rem;
  border-radius: 999px;
  border: 1px solid var(--z-border);
  background: var(--z-surface);
  font-size: 0.7rem;
  color: var(--z-muted);
}

.channel-color-input {
  width: 26px;
  height: 20px;
  padding: 0;
  border: none;
  background: transparent;
  cursor: pointer;
}

.channel-color-input::-webkit-color-swatch-wrapper {
  padding: 0;
}

.channel-color-input::-webkit-color-swatch {
  border: 1px solid var(--z-border);
  border-radius: 6px;
}

.channel-color-input::-moz-color-swatch {
  border: 1px solid var(--z-border);
  border-radius: 6px;
}

@media (max-width: 1100px) {
  .channel-row {
    flex-direction: column;
    align-items: flex-start;
  }

  .channel-row-actions {
    width: 100%;
    justify-content: space-between;
  }
}

.channel-name {
  font-size: 0.85rem;
  font-weight: 600;
}

.channel-sub {
  font-size: 0.7rem;
  color: var(--z-muted);
}

.empty {
  min-height: 320px;
}

.empty-body {
  padding: 2rem;
  display: grid;
  gap: 0.6rem;
  justify-items: center;
  text-align: center;
}

.empty-title {
  font-size: 1rem;
  font-weight: 600;
}

.empty-sub {
  font-size: 0.85rem;
  color: var(--z-muted);
  max-width: 360px;
}

.modal {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  z-index: 50;
}

.modal.hidden {
  display: none;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  backdrop-filter: blur(4px);
}

.modal-card {
  position: relative;
  width: min(540px, 100%);
  background: var(--z-surface);
  border: 1px solid var(--z-border);
  border-radius: 20px;
  box-shadow: 0 30px 80px rgba(15, 23, 42, 0.25);
  z-index: 1;
  display: grid;
  overflow: hidden;
}

.modal-head {
  padding: 1.2rem 1.4rem;
  border-bottom: 1px solid var(--z-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.modal-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.modal-title {
  font-size: 1.05rem;
  font-weight: 700;
}

.modal-sub {
  font-size: 0.85rem;
  color: var(--z-muted);
}

.modal-body {
  padding: 1.2rem 1.4rem 1.6rem;
  display: grid;
  gap: 1.2rem;
}

.new-chat-card {
  width: min(560px, 100%);
}

.new-chat-body {
  gap: 0.75rem;
}

.new-chat-search {
  width: 100%;
  border: 1px solid var(--z-border);
  border-radius: 12px;
  padding: 0.62rem 0.78rem;
  font-size: 0.9rem;
  outline: none;
  background: var(--z-surface);
}

.new-chat-search:focus {
  border-color: var(--z-brand);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.12);
}

.new-chat-error {
  border: 1px solid #fecaca;
  background: #fff1f2;
  color: #991b1b;
  font-size: 0.8rem;
  border-radius: 10px;
  padding: 0.55rem 0.65rem;
}

.new-chat-list {
  display: grid;
  gap: 0.35rem;
  max-height: min(52vh, 420px);
  overflow: auto;
  padding-right: 0.15rem;
}

.new-chat-item {
  width: 100%;
  border: 1px solid var(--z-border);
  background: var(--z-surface);
  border-radius: 12px;
  padding: 0.55rem 0.65rem;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  text-align: left;
  color: inherit;
  cursor: pointer;
}

.new-chat-item:hover {
  border-color: #c7d2fe;
  background: #f8faff;
}

.new-chat-item:disabled {
  opacity: 0.65;
  cursor: wait;
}

.new-chat-copy {
  min-width: 0;
  display: grid;
}

.new-chat-name {
  font-size: 0.9rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.new-chat-phone {
  font-size: 0.78rem;
  color: var(--z-muted);
}

.new-chat-empty {
  padding: 0.55rem;
}

.qr-box {
  display: grid;
  justify-items: center;
  gap: 0.5rem;
  padding: 1.2rem;
  border-radius: 16px;
  background: var(--z-surface-2);
  border: 1px dashed var(--z-border);
}

.qr-placeholder {
  width: 220px;
  height: 220px;
  border-radius: 14px;
  background: repeating-linear-gradient(
    45deg,
    rgba(99, 102, 241, 0.18),
    rgba(99, 102, 241, 0.18) 10px,
    rgba(255, 255, 255, 0.9) 10px,
    rgba(255, 255, 255, 0.9) 20px
  );
  display: grid;
  place-items: center;
  font-weight: 700;
  color: #4f46e5;
  letter-spacing: 0.2em;
}

.qr-image {
  width: 100%;
  height: 100%;
  object-fit: contain;
  border-radius: 10px;
}

.qr-placeholder.is-loading {
  background: linear-gradient(120deg, rgba(99, 102, 241, 0.15), rgba(99, 102, 241, 0.35), rgba(99, 102, 241, 0.15));
  background-size: 200% 200%;
  animation: qrPulse 1.6s ease infinite;
}

.qr-status {
  font-size: 0.8rem;
  color: var(--z-muted);
}

.qr-steps {
  margin: 0;
  padding-left: 1.1rem;
  display: grid;
  gap: 0.4rem;
  font-size: 0.85rem;
  color: var(--z-muted);
}

@keyframes qrPulse {
  0% {
    background-position: 0% 50%;
  }
  50% {
    background-position: 100% 50%;
  }
  100% {
    background-position: 0% 50%;
  }
}

.metric {
  padding: 0.8rem 1rem 1.2rem;
  gap: 0.2rem;
}

.metric-value {
  font-size: 1.4rem;
  font-weight: 700;
  padding: 0 1rem 0.6rem;
}

.chart {
  min-height: 260px;
}

.chart-placeholder {
  margin: 0 1rem 1.2rem;
  border-radius: 12px;
  border: 1px dashed var(--z-border);
  background: var(--z-surface-2);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--z-muted);
  font-size: 0.85rem;
  min-height: 180px;
}

.table {
  display: grid;
  gap: 0.5rem;
  padding: 0.8rem 1rem 1.2rem;
}

.table-row {
  display: grid;
  grid-template-columns: 1.3fr 0.8fr 0.8fr 0.7fr;
  gap: 0.75rem;
  align-items: center;
  padding: 0.7rem 0.8rem;
  border-radius: 12px;
  border: 1px solid var(--z-border);
  font-size: 0.82rem;
}

.table-row.table-head {
  background: var(--z-surface-2);
  font-weight: 600;
}

.contact-cell {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  min-width: 0;
}

.contact-copy {
  display: grid;
  min-width: 0;
}

.contact-name {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.contact-phone {
  font-size: 0.72rem;
  color: var(--z-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.form-grid {
  display: grid;
  gap: 1rem;
  padding: 1rem 1.2rem 1.5rem;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.form-grid label {
  display: grid;
  gap: 0.35rem;
  font-size: 0.8rem;
  color: var(--z-muted);
}

.form-grid input,
.form-grid select {
  border: 1px solid var(--z-border);
  border-radius: 12px;
  padding: 0.6rem 0.75rem;
  font-size: 0.85rem;
  color: var(--z-text);
  background: var(--z-surface);
}

.panel-head {
  padding: 1.1rem 1.2rem;
  border-bottom: 1px solid var(--z-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.panel-title {
  font-weight: 600;
  font-size: 0.9rem;
}

.panel-sub {
  font-size: 0.78rem;
  color: var(--z-muted);
}

.btn {
  border: none;
  background: var(--z-brand);
  color: var(--z-brand-text);
  padding: 0.5rem 0.9rem;
  border-radius: 10px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 6px 16px rgba(79, 70, 229, 0.2);
  font-size: 0.8rem;
}

.btn.ghost {
  background: transparent;
  color: var(--z-text);
  border: 1px solid var(--z-border);
  box-shadow: none;
}

.chip {
  background: var(--z-brand-weak);
  color: var(--z-brand);
  padding: 0.2rem 0.55rem;
  border-radius: 8px;
  font-size: 0.7rem;
  font-weight: 600;
}

.chip.ghost {
  background: transparent;
  border: 1px solid var(--z-border);
  color: var(--z-muted);
}

.inbox-list {
  display: grid;
  gap: 0.5rem;
  padding: 0.75rem;
  overflow: auto;
}

.inbox-item {
  background: var(--z-surface);
  border: 1px solid var(--z-border);
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  padding: 0.85rem;
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.2s ease;
  width: 100%;
  min-width: 0;
}

.inbox-color-line {
  width: 4px;
  align-self: stretch;
  border-radius: 999px;
  background: var(--channel-color, #cbd5f5);
  box-shadow: inset 0 0 0 1px rgba(15, 23, 42, 0.08);
}

.inbox-item:hover {
  border-color: rgba(79, 70, 229, 0.25);
  background: var(--z-brand-weak);
}

.inbox-item.active {
  border-color: rgba(79, 70, 229, 0.5);
  background: #eef2ff;
  box-shadow: 0 4px 10px rgba(79, 70, 229, 0.12);
}

.inbox-left {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  text-align: left;
  flex: 1;
  min-width: 0;
}

.inbox-left .inbox-text {
  flex: 1;
  min-width: 0;
}

.avatar-wrap {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.channel-badge {
  position: absolute;
  bottom: -2px;
  left: -2px;
  width: 14px;
  height: 14px;
  border-radius: 999px;
  background: #22c55e;
  border: 2px solid var(--z-surface);
  box-shadow: 0 2px 6px rgba(15, 23, 42, 0.15);
}

.inbox-ui .inbox-left .avatar {
  width: 42px;
  height: 42px;
  font-size: 0.82rem;
}

.inbox-name {
  font-weight: 600;
  display: block;
  max-width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.inbox-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.inbox-time {
  font-size: 0.72rem;
  color: var(--z-muted);
  flex-shrink: 0;
}

.inbox-preview-row {
  display: flex;
  align-items: center;
  gap: 0.45rem;
}

.inbox-preview {
  flex: 1;
  min-width: 0;
  font-size: 0.75rem;
  color: var(--z-muted);
  display: -webkit-box;
  max-width: 100%;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
  line-clamp: 1;
  white-space: normal;
  overflow: hidden;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.inbox-meta {
  display: grid;
  gap: 0.35rem;
  text-align: right;
  flex-shrink: 0;
}

.inbox-ui {
  grid-template-columns: 232px 356px minmax(0, 1fr);
  gap: 0;
  min-height: 0;
  height: 100%;
  overflow: clip;
  border: 1px solid var(--z-border);
  border-radius: 14px;
  background: var(--z-surface);
}

.inbox-ui .panel {
  border-radius: 0;
  border: 0;
  box-shadow: none;
  overflow: hidden;
  border-right: 1px solid var(--z-border);
}

.inbox-ui .thread-panel {
  border-right: 0;
}

.inbox-ui .panel-head {
  padding: 0.8rem 0.9rem;
}

.inbox-ui .filters {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
}

.inbox-ui .filters .chip {
  padding: 0.16rem 0.45rem;
  font-size: 0.66rem;
  border-radius: 999px;
}

.inbox-nav-panel {
  min-width: 0;
  min-height: 0;
}

.inbox-nav-body {
  padding: 0.75rem;
  display: grid;
  gap: 0.75rem;
  overflow: auto;
}

.inbox-nav-section {
  display: grid;
  gap: 0.55rem;
}

.inbox-nav-title {
  font-size: 0.72rem;
  color: var(--z-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 600;
}

.inbox-quick {
  border: 1px solid transparent;
  border-radius: 9px;
  background: transparent;
  color: var(--z-text);
  padding: 0.48rem 0.58rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

.inbox-quick:hover {
  border-color: rgba(79, 70, 229, 0.22);
  background: rgba(79, 70, 229, 0.05);
}

.inbox-quick.is-active {
  background: var(--z-brand-weak);
  border-color: rgba(79, 70, 229, 0.22);
  color: #4338ca;
}

.inbox-nav-note {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.78rem;
  color: var(--z-muted);
}

.inbox-nav-detail {
  border: 1px solid var(--z-border);
  border-radius: 9px;
  background: var(--z-surface-2);
  padding: 0.55rem 0.62rem;
}

.inbox-nav-name {
  font-size: 0.85rem;
  font-weight: 600;
}

.inbox-nav-sub {
  font-size: 0.76rem;
  color: var(--z-muted);
}

.inbox-list-panel {
  min-width: 0;
  min-height: 0;
}

.inbox-ui .inbox-list {
  gap: 0;
  padding: 0;
}

.inbox-ui .inbox-item {
  border: none;
  border-bottom: 1px solid var(--z-border);
  border-radius: 0;
  padding: 0.58rem 0.72rem;
  box-shadow: none;
}

.inbox-ui .inbox-item:last-child {
  border-bottom: none;
}

.inbox-ui .inbox-item.active {
  background: var(--z-brand-weak);
}

.inbox-ui .inbox-name {
  font-size: 0.95rem;
  line-height: 1.2;
}

.inbox-ui .inbox-preview {
  margin-top: 0.08rem;
  font-size: 0.82rem;
  line-height: 1.24;
}

.inbox-meta-row {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  margin-top: 0.22rem;
}

.inbox-tag {
  display: inline-flex;
  align-items: center;
  padding: 0.1rem 0.4rem;
  border-radius: 999px;
  font-size: 0.62rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.inbox-tag.new {
  background: #dbeafe;
  color: #1d4ed8;
}

.inbox-tag.progress {
  background: #dcfce7;
  color: #166534;
}

.inbox-tag.closed {
  background: #f1f5f9;
  color: #475569;
}

.inbox-tag.neutral {
  background: #e2e8f0;
  color: #334155;
}

.unread-pill {
  margin-left: auto;
  min-width: 1.1rem;
  height: 1.1rem;
  border-radius: 999px;
  display: inline-grid;
  place-items: center;
  background: var(--z-brand);
  color: #fff;
  font-size: 0.62rem;
  font-weight: 700;
  padding: 0 0.25rem;
}

.lead-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.1rem 0.4rem;
  border-radius: 999px;
  font-size: 0.62rem;
  font-weight: 600;
  color: #9a3412;
  background: #fff7ed;
}

.lead-icon {
  font-size: 0.7rem;
  line-height: 1;
}

.assignee-badge {
  width: 22px;
  height: 22px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.62rem;
  font-weight: 700;
  color: var(--z-text);
  background: var(--z-surface-2);
  border: 1px solid var(--z-border);
  margin-left: auto;
}

.thread-panel {
  display: grid;
  grid-template-rows: auto 1fr auto;
  min-width: 0;
  min-height: 0;
}

.thread-head {
  border-bottom: 1px solid var(--z-border);
  background: #fff;
}

.inbox-ui .chat-actions {
  gap: 0.4rem;
}

.inbox-ui .chat-actions .btn {
  padding: 0.34rem 0.6rem;
  border-radius: 8px;
  font-size: 0.74rem;
}

.thread-panel .chat-body {
  background:
    radial-gradient(1400px 220px at 50% -130px, rgba(79, 70, 229, 0.05), transparent 62%),
    #f8fafc;
}

.thread-empty,
.inbox-empty {
  margin: auto;
}

.thread-footer {
  border-top: 1px solid var(--z-border);
  padding: 0.6rem 0.8rem 0.8rem;
  display: grid;
  gap: 0.45rem;
  background: var(--z-surface);
}

.composer-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.composer-channel {
  font-size: 0.76rem;
  color: var(--z-muted);
}

.composer-status {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--z-brand);
}

.inbox-ui .composer {
  padding: 0;
  border-top: 0;
  gap: 0.5rem;
  align-items: flex-end;
}

.inbox-ui .composer-fields {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 0.45rem;
}

.inbox-ui .composer input {
  border-radius: 9px;
  background: var(--z-surface-2);
  padding: 0.48rem 0.62rem;
}

.composer-send {
  min-width: 86px;
  border-radius: 9px;
  padding: 0.48rem 0.75rem;
}

.time {
  font-size: 0.7rem;
  color: var(--z-muted);
}

.chat {
  min-height: 0;
}

.chat-title {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.chat-back {
  display: none;
  padding: 0.35rem 0.6rem;
  border-radius: 999px;
  font-size: 0.72rem;
}

.chat-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.chat-body {
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  overflow: auto;
  flex: 1;
  background: var(--z-surface-2);
}

.msg {
  display: flex;
  flex-direction: column;
  width: 100%;
  gap: 0.3rem;
}

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

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

.bubble {
  max-width: 65%;
  padding: 0.8rem 1rem;
  border-radius: 14px;
  box-shadow: var(--shadow-soft);
  font-size: 0.8rem;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.msg.inbound .bubble {
  background: #ffffff;
  border: 1px solid var(--z-border);
  margin-right: auto;
}

.msg.outbound .bubble {
  background: var(--z-brand);
  color: #ffffff;
  margin-left: auto;
}

.msg-meta {
  font-size: 0.7rem;
  color: var(--z-muted);
}

.msg.inbound .msg-meta {
  margin-right: auto;
}

.msg.outbound .msg-meta {
  margin-left: auto;
}

.composer {
  display: flex;
  gap: 0.75rem;
  padding: 1rem;
  border-top: 1px solid var(--z-border);
  align-items: center;
}

.composer-fields {
  flex: 1;
  min-width: 0;
  display: grid;
  gap: 0.5rem;
}

.composer input {
  flex: 1;
  border: 1px solid var(--z-border);
  border-radius: 12px;
  padding: 0.55rem 0.9rem;
  font-size: 0.8rem;
}

.side {
  gap: 0.75rem;
}

.side-block {
  padding: 0 1.2rem 1rem;
  display: grid;
  gap: 0.6rem;
}

.side-label {
  font-size: 0.75rem;
  color: var(--z-muted);
  text-transform: uppercase;
  letter-spacing: 0.12em;
}

.tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.channel-card {
  background: var(--z-surface-2);
  border: 1px solid var(--z-border);
  border-radius: 12px;
  padding: 0.9rem;
  display: grid;
  gap: 0.5rem;
}

.channel-title {
  font-weight: 600;
}

.channel-sub {
  font-size: 0.78rem;
  color: var(--z-muted);
}

textarea {
  width: 100%;
  min-height: 100px;
  border: 1px solid var(--z-border);
  border-radius: 12px;
  padding: 0.75rem;
  font-family: inherit;
}

.pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.25rem 0.6rem;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 600;
}

.pill.new {
  background: rgba(34, 197, 94, 0.15);
  color: #15803d;
}

.pill.progress {
  background: rgba(59, 130, 246, 0.15);
  color: #1d4ed8;
}

.pill.closed {
  background: rgba(148, 163, 184, 0.2);
  color: #475569;
}

.pill.connected {
  background: rgba(16, 185, 129, 0.15);
  color: #0f766e;
}

.pill.connecting {
  background: rgba(59, 130, 246, 0.15);
  color: #1d4ed8;
}

.pill.disconnected {
  background: rgba(148, 163, 184, 0.2);
  color: #64748b;
}

.pill.error {
  background: rgba(239, 68, 68, 0.15);
  color: #b91c1c;
}

.avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--z-brand-weak);
  color: var(--z-brand);
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  flex-shrink: 0;
  border: 1px solid rgba(79, 70, 229, 0.15);
  position: relative;
}

.avatar-initials {
  width: 100%;
  height: 100%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

.avatar.has-photo .avatar-initials {
  display: none;
}

.avatar-photo {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  position: absolute;
  inset: 0;
}

.avatar.sm {
  width: 30px;
  height: 30px;
  font-size: 0.75rem;
}

.user {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.35rem 0.65rem;
  border: 1px solid var(--z-border);
  border-radius: 999px;
  background: var(--z-surface);
}

.user-meta {
  display: grid;
}

.user-name {
  font-size: 0.85rem;
  font-weight: 600;
}

.user-role {
  font-size: 0.7rem;
  color: var(--z-muted);
}

.assignee {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.assignee-name {
  font-weight: 600;
}

.assignee-sub {
  font-size: 0.75rem;
  color: var(--z-muted);
}

@media (max-width: 1200px) {
  .content {
    grid-template-columns: 1.2fr 1.8fr;
  }
  .inbox-ui {
    grid-template-columns: 340px minmax(0, 1fr);
  }
  .inbox-ui .inbox-nav-panel {
    display: none;
  }
  .side {
    display: none;
  }
  .grid-3 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .span-3 {
    grid-column: span 2;
  }
}

@media (max-width: 960px) {
  .main {
    height: auto;
    min-height: 100vh;
    overflow: visible;
  }
  #view-host {
    overflow: visible;
  }
  .app-shell {
    grid-template-columns: 1fr;
  }
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(82vw, 320px);
    transform: translateX(-105%);
    transition: transform 0.25s ease;
    z-index: 40;
    border-right: 1px solid var(--z-border);
    box-shadow: 0 18px 40px rgba(15, 23, 42, 0.2);
  }
  .app-shell.menu-open .sidebar {
    transform: translateX(0);
  }
  .sidebar-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.4);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease;
    z-index: 35;
  }
  .app-shell.menu-open .sidebar-backdrop {
    opacity: 1;
    pointer-events: auto;
  }
  .nav {
    grid-auto-flow: row;
    grid-auto-columns: initial;
  }
  .sidebar-foot {
    display: grid;
  }
  .content {
    grid-template-columns: 1fr;
  }
  .grid-2,
  .grid-3,
  .inbox-view {
    grid-template-columns: 1fr;
  }
  .inbox-ui {
    min-height: auto;
    grid-template-columns: 1fr;
    display: block;
  }
  .inbox-ui.has-selection {
    height: calc(100dvh - 140px);
    overflow: hidden;
  }
  .inbox-ui.has-selection .thread-panel {
    height: 100%;
  }
  .inbox-ui.has-selection .chat-body {
    overflow: auto;
  }
  .inbox-ui.no-selection .thread-panel {
    display: none;
  }
  .inbox-ui.has-selection .inbox-list-panel {
    display: none;
  }
  .inbox-ui .panel {
    border: 1px solid var(--z-border);
    border-radius: 14px;
    box-shadow: var(--shadow-soft);
    background: var(--z-surface);
  }
  .inbox-ui .inbox-list {
    max-height: calc(100dvh - 260px);
  }
  .inbox-ui .thread-panel {
    min-height: calc(100dvh - 220px);
  }
  .inbox-ui .composer-fields {
    grid-template-columns: 1fr;
  }
  .inbox-ui .chat-actions {
    width: 100%;
    justify-content: flex-end;
    flex-wrap: wrap;
  }
  .span-3 {
    grid-column: span 1;
  }
  .form-grid {
    grid-template-columns: 1fr;
  }
  .topbar {
    flex-direction: column;
    gap: 0.75rem;
    align-items: flex-start;
    height: auto;
    padding: 1rem;
  }
  .topbar-right {
    flex-wrap: wrap;
  }
  .search input {
    min-width: 200px;
  }
  .menu-toggle {
    display: inline-flex;
  }
  .chat-back {
    display: inline-flex;
  }
}

@media (max-width: 720px) {
  .sidebar {
    padding: 0.5rem 0.75rem;
    gap: 0.6rem;
  }

  .brand {
    display: none;
  }

  .nav-item {
    padding: 0.35rem 0.55rem;
    font-size: 0.78rem;
  }

  .topbar {
    padding: 0.75rem;
  }

  .topbar-right {
    width: 100%;
  }

  .search,
  .search input {
    width: 100%;
    min-width: 0;
  }

  .topbar-right .btn {
    width: 100%;
  }

  .content {
    padding: 0.85rem;
  }

  .panel-head {
    flex-direction: column;
    align-items: flex-start;
  }

  .filters {
    flex-wrap: wrap;
  }

  .inbox-ui .panel {
    border-radius: 14px;
  }

  .inbox-ui .panel-head {
    padding: 0.75rem 0.9rem;
  }

  .inbox-ui .inbox-item {
    padding: 0.6rem 0.65rem;
  }

  .inbox-ui .chat-body {
    padding: 1rem;
  }

  .thread-panel {
    min-height: 52vh;
  }

  .thread-footer .composer {
    flex-direction: column;
    align-items: stretch;
  }

  .composer-send {
    width: 100%;
  }

  .chat-actions {
    flex-wrap: wrap;
    justify-content: flex-start;
  }

  .channel-row-actions,
  .channel-actions {
    flex-wrap: wrap;
  }

  .table {
    padding: 0.5rem 0.7rem 0.9rem;
  }

  .table-row {
    grid-template-columns: 1fr;
    gap: 0.4rem;
  }

  .table-row.table-head {
    display: none;
  }
}

@media (max-width: 520px) {
  .inbox-ui .inbox-item {
    padding: 0.55rem 0.6rem;
  }

  .inbox-left {
    gap: 0.55rem;
  }

  .inbox-ui .inbox-left .avatar {
    width: 36px;
    height: 36px;
  }

  .thread-footer {
    padding: 0.55rem;
  }

  .modal {
    padding: 0.9rem;
  }

  .modal-head {
    flex-direction: column;
    align-items: flex-start;
  }

  .modal-actions {
    width: 100%;
    justify-content: flex-end;
  }
}

/* View helpers */
.chip.is-active {
  background: var(--z-brand-weak);
  border-color: rgba(79, 70, 229, 0.3);
  color: #4338ca;
}

.table-row.is-active {
  background: var(--z-brand-weak);
  border-color: rgba(79, 70, 229, 0.35);
}

.inline-alert {
  display: none;
  margin: 0.8rem 1.2rem 0;
  padding: 0.6rem 0.8rem;
  border-radius: 12px;
  border: 1px solid rgba(79, 70, 229, 0.3);
  background: var(--z-brand-weak);
  color: #4338ca;
  font-size: 0.8rem;
}

.inline-alert.show {
  display: block;
}
