:root {
  color-scheme: light;
  --bg: #f3f5f2;
  --panel: #ffffff;
  --panel-soft: #f8faf7;
  --ink: #1b2420;
  --muted: #66736d;
  --line: #dce3de;
  --green: #157158;
  --green-soft: #e5f3ed;
  --blue: #2469a7;
  --blue-soft: #e8f1fb;
  --red: #ab3d4d;
  --red-soft: #fae8eb;
  --yellow: #966c18;
  --yellow-soft: #fbf2db;
  --violet: #6754a6;
  --violet-soft: #eeeafa;
  --shadow: 0 18px 48px rgba(28, 39, 33, 0.11);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body.modal-open {
  overflow: hidden;
}

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

button,
select {
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 24px;
  padding: 22px 16px;
  background: #16231f;
  color: #f8fbf8;
}

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

.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 8px;
  background: #edf8f2;
  color: var(--green);
  font-weight: 850;
}

.brand strong,
.brand span {
  display: block;
}

.brand span {
  margin-top: 3px;
  color: #b9c6c0;
  font-size: 13px;
}

.user-panel {
  display: grid;
  gap: 8px;
  padding: 12px;
  border: 1px solid rgba(255, 255, 255, 0.10);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.06);
}

.user-panel label {
  color: #b9c6c0;
  font-size: 12px;
  font-weight: 750;
}

.user-panel select {
  width: 100%;
  min-height: 36px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 8px;
  background: #20322c;
  color: #ffffff;
  padding: 7px 9px;
}

.ghost-button {
  min-height: 34px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 8px;
  background: transparent;
  color: #dce6e1;
  font-weight: 750;
}

.ghost-button.active {
  background: #fff4d7;
  color: #5d420f;
}

.nav-tabs,
.channel-filter {
  display: grid;
  gap: 8px;
}

.nav-tab,
.filter-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 42px;
  border: 1px solid rgba(255, 255, 255, 0.10);
  border-radius: 8px;
  background: transparent;
  color: #dce6e1;
  padding: 9px 10px;
  text-align: left;
  font-weight: 720;
}

.nav-tab:hover,
.nav-tab.active,
.filter-chip:hover,
.filter-chip.active {
  background: rgba(255, 255, 255, 0.10);
  color: #ffffff;
}

.channel-filter {
  margin-top: auto;
}

.filter-chip {
  min-height: 36px;
  font-size: 13px;
}

.filter-chip::before,
.channel-badge::before {
  content: "";
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--muted);
}

.whatsapp::before,
.channel-badge.whatsapp::before {
  background: #1aa668;
}

.telegram::before,
.channel-badge.telegram::before {
  background: #229ed9;
}

.vk::before,
.channel-badge.vk::before {
  background: #2878d9;
}

.avito::before,
.channel-badge.avito::before {
  background: #82bd2a;
}

.max::before,
.channel-badge.max::before {
  background: #725cff;
}

.instagram::before,
.channel-badge.instagram::before {
  background: #c14f8d;
}

.sidebar-footer {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #b9c6c0;
  font-size: 12px;
  line-height: 1.35;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #6bd096;
  flex: 0 0 auto;
}

.workspace {
  display: grid;
  grid-template-rows: auto auto auto minmax(0, 1fr);
  gap: 16px;
  min-width: 0;
  padding: 22px;
}

.topbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 20px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--green);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 34px;
  line-height: 1.05;
  letter-spacing: 0;
}

h2 {
  font-size: 18px;
  letter-spacing: 0;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.search {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: min(380px, 42vw);
  height: 42px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.search input {
  width: 100%;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--ink);
}

.primary-button,
.reply-actions button,
.conversation-actions button,
.segment,
.list-toolbar button {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  padding: 8px 12px;
  font-weight: 750;
}

.primary-button {
  border-color: var(--green);
  background: var(--green);
  color: #ffffff;
}

.primary-button:hover {
  background: #0f604a;
}

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

.stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.stats article {
  min-height: 86px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.stats span {
  display: block;
  font-size: 26px;
  font-weight: 850;
}

.stats p {
  margin-top: 6px;
  color: var(--muted);
  font-size: 13px;
}

.work-queue {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.work-queue div {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
  padding: 10px 12px;
}

.queue-label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
}

.work-queue strong {
  font-size: 16px;
  text-align: right;
}

.view-panel {
  display: none;
  min-height: 0;
}

.view-panel.active {
  display: block;
}

.inbox-layout {
  display: grid;
  grid-template-columns: 340px minmax(420px, 1fr) 300px;
  gap: 14px;
  min-height: calc(100vh - 267px);
}

.thread-list,
.conversation,
.customer-card {
  min-height: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 8px 28px rgba(28, 39, 33, 0.05);
}

.thread-list {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  overflow: hidden;
}

.list-toolbar {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding: 12px;
  border-bottom: 1px solid var(--line);
}

.segment {
  min-height: 34px;
  white-space: nowrap;
  font-size: 12px;
}

.segment.active {
  border-color: var(--green);
  background: var(--green-soft);
  color: var(--green);
}

.threads {
  overflow: auto;
}

.thread {
  display: grid;
  gap: 8px;
  width: 100%;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: transparent;
  padding: 14px;
  color: var(--ink);
  text-align: left;
}

.thread:hover,
.thread.active {
  background: var(--panel-soft);
}

.thread.active {
  box-shadow: inset 3px 0 0 var(--green);
}

.thread-top,
.thread-bottom {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

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

.thread-meta-row {
  display: flex;
  gap: 6px;
  min-width: 0;
  overflow: hidden;
}

.thread strong,
.thread span,
.thread p {
  min-width: 0;
}

.thread strong,
.thread p {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.thread p {
  color: var(--muted);
  font-size: 13px;
}

.time-pill,
.value-pill,
.priority-pill,
.sla-pill {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 12px;
}

.priority-pill,
.sla-pill {
  border-radius: 999px;
  border: 1px solid var(--line);
  background: #ffffff;
  padding: 3px 7px;
  font-weight: 750;
}

.priority-pill.high {
  border-color: #efd78d;
  background: var(--yellow-soft);
  color: var(--yellow);
}

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

.sla-pill.overdue {
  border-color: #efc5cc;
  background: var(--red-soft);
  color: var(--red);
}

.status-pill {
  border-radius: 999px;
  padding: 3px 8px;
  background: var(--blue-soft);
  color: var(--blue);
  font-size: 12px;
  font-weight: 750;
}

.status-pill.waiting {
  background: var(--red-soft);
  color: var(--red);
}

.status-pill.hot {
  background: var(--yellow-soft);
  color: var(--yellow);
}

.status-pill.closed {
  background: #eef1ef;
  color: var(--muted);
}

.conversation {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  overflow: hidden;
}

.conversation-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 16px;
  border-bottom: 1px solid var(--line);
}

.client-line {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.channel-badge {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  border-radius: 999px;
  background: var(--panel-soft);
  border: 1px solid var(--line);
  padding: 4px 9px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
}

#client-meta {
  margin-top: 5px;
  color: var(--muted);
  font-size: 13px;
}

.conversation-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.conversation-actions button {
  min-width: 84px;
  padding: 8px 10px;
  font-size: 12px;
}

.messages {
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow: auto;
  padding: 16px;
  background: linear-gradient(180deg, #fbfcfb, #f4f7f4);
}

.message {
  max-width: min(74%, 620px);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  padding: 10px 12px;
}

.message.out {
  align-self: flex-end;
  border-color: #bcd9cc;
  background: var(--green-soft);
}

.message.note {
  align-self: center;
  max-width: 88%;
  border-style: dashed;
  background: var(--yellow-soft);
}

.message p {
  line-height: 1.42;
}

.message small {
  display: block;
  margin-top: 7px;
  color: var(--muted);
  font-size: 11px;
}

.reply-box {
  display: grid;
  gap: 10px;
  padding: 12px;
  border-top: 1px solid var(--line);
  background: var(--panel);
}

.reply-toolbar,
.reply-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

.reply-toolbar select,
.quick-fields select {
  min-height: 36px;
  max-width: 260px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  padding: 7px 9px;
}

#reply-hint {
  color: var(--muted);
  font-size: 12px;
}

textarea {
  width: 100%;
  min-height: 96px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  outline: 0;
}

textarea:focus,
input:focus,
select:focus {
  border-color: var(--green);
}

.customer-card {
  padding: 16px;
  overflow: auto;
}

.customer-card dl {
  display: grid;
  gap: 12px;
  margin: 16px 0;
}

.customer-card dt {
  color: var(--muted);
  font-size: 12px;
}

.customer-card dd {
  margin: 4px 0 0;
  font-weight: 720;
  line-height: 1.35;
}

.quick-fields {
  display: grid;
  gap: 12px;
}

.quick-fields label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
}

.quick-fields select {
  max-width: none;
  color: var(--ink);
}

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

.accounts-layout,
.crm-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(280px, 0.8fr);
  gap: 14px;
}

.accounts-layout > section,
.research-panel,
.crm-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 16px;
}

.section-note {
  margin-top: 8px;
  color: var(--muted);
  line-height: 1.45;
  font-size: 14px;
}

.account-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 12px;
  margin-top: 14px;
}

.account-card {
  display: grid;
  gap: 12px;
  min-height: 250px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
  padding: 14px;
}

.account-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.account-card h3 {
  margin: 0;
  font-size: 18px;
  line-height: 1.15;
}

.account-card p {
  color: var(--muted);
  font-size: 14px;
}

.account-card dl {
  display: grid;
  gap: 8px;
  margin: 0;
}

.account-card dt {
  color: var(--muted);
  font-size: 12px;
}

.account-card dd {
  margin: 2px 0 0;
  line-height: 1.35;
  font-size: 13px;
}

.account-state {
  border-radius: 999px;
  padding: 4px 8px;
  background: #eef1ef;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.account-state.connected {
  background: var(--green-soft);
  color: var(--green);
}

.account-state.ready {
  background: var(--blue-soft);
  color: var(--blue);
}

.account-state.research {
  background: var(--yellow-soft);
  color: var(--yellow);
}

.account-action {
  align-self: end;
  min-height: 38px;
  border: 1px solid var(--green);
  border-radius: 8px;
  background: #ffffff;
  color: var(--green);
  font-weight: 800;
}

.research-panel p,
.crm-panel p {
  margin-top: 12px;
  color: var(--muted);
  line-height: 1.5;
}

.priority-list,
.crm-flow {
  display: grid;
  gap: 8px;
  margin-top: 16px;
}

.priority-list span,
.crm-flow span {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
  padding: 10px 12px;
  font-weight: 720;
}

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

.plain-list {
  display: grid;
  gap: 10px;
  margin: 14px 0 0;
  padding: 0;
  list-style: none;
}

.plain-list li {
  border-bottom: 1px solid var(--line);
  padding-bottom: 10px;
}

.integration-card,
.team-card {
  min-height: 190px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 16px;
}

.integration-card h2,
.team-card h2 {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.integration-card p,
.team-card p {
  color: var(--muted);
  line-height: 1.45;
  font-size: 14px;
}

.integration-card ul {
  display: grid;
  gap: 7px;
  margin: 14px 0 0;
  padding: 0;
  list-style: none;
}

.integration-card li {
  color: var(--ink);
  font-size: 13px;
}

.integration-state {
  border-radius: 999px;
  padding: 4px 8px;
  background: var(--yellow-soft);
  color: var(--yellow);
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.integration-state.ready {
  background: var(--green-soft);
  color: var(--green);
}

.team-metrics {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 16px;
}

.team-metrics div {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: var(--panel-soft);
}

.team-metrics strong {
  display: block;
  font-size: 20px;
}

.team-metrics span {
  color: var(--muted);
  font-size: 12px;
}

.empty-state {
  padding: 24px;
  color: var(--muted);
  text-align: center;
}

.connect-modal[hidden] {
  display: none;
}

.connect-modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 22px;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(12, 20, 17, 0.58);
}

.modal-panel {
  position: relative;
  z-index: 1;
  width: min(840px, 100%);
  max-height: min(720px, calc(100vh - 44px));
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.modal-head,
.modal-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 16px;
}

.modal-head {
  border-bottom: 1px solid var(--line);
}

.modal-actions {
  border-top: 1px solid var(--line);
  background: var(--panel-soft);
}

.modal-actions button,
.icon-button {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  color: var(--ink);
  padding: 8px 12px;
  font-weight: 750;
}

.icon-button {
  display: grid;
  place-items: center;
  width: 38px;
  padding: 0;
  font-size: 22px;
  line-height: 1;
}

.connect-layout {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  gap: 16px;
  padding: 16px;
}

.qr-box {
  display: grid;
  place-items: center;
  align-content: center;
  gap: 8px;
  min-height: 300px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  text-align: center;
}

.qr-grid {
  width: 162px;
  height: 162px;
  border: 10px solid #ffffff;
  border-radius: 8px;
  background:
    linear-gradient(90deg, var(--ink) 12px, transparent 12px) 0 0 / 28px 28px,
    linear-gradient(var(--ink) 12px, transparent 12px) 0 0 / 28px 28px,
    linear-gradient(90deg, transparent 8px, #ffffff 8px 20px, transparent 20px) 0 0 / 56px 56px,
    linear-gradient(transparent 8px, #ffffff 8px 20px, transparent 20px) 0 0 / 56px 56px,
    #dfe7e2;
}

.qr-box strong {
  font-size: 18px;
}

.qr-box span {
  color: var(--muted);
  font-size: 13px;
}

.connect-details {
  display: grid;
  gap: 16px;
}

.connect-details dl {
  display: grid;
  gap: 10px;
  margin: 0;
}

.connect-details dl div {
  display: grid;
  grid-template-columns: 120px minmax(0, 1fr);
  gap: 10px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 9px;
}

.connect-details dt {
  color: var(--muted);
  font-size: 12px;
}

.connect-details dd {
  margin: 0;
  font-weight: 750;
}

.connect-steps {
  display: grid;
  gap: 8px;
  margin: 0;
  padding-left: 20px;
  color: var(--muted);
  line-height: 1.45;
}

.session-status {
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--green-soft);
  color: var(--green);
  padding: 10px 12px;
  font-weight: 800;
}

@media (max-width: 1180px) {
  .app-shell {
    grid-template-columns: 220px minmax(0, 1fr);
  }

  .inbox-layout {
    grid-template-columns: 310px minmax(0, 1fr);
  }

  .accounts-layout,
  .crm-layout {
    grid-template-columns: 1fr;
  }

  .customer-card {
    display: none;
  }
}

@media (max-width: 860px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    gap: 14px;
  }

  .nav-tabs,
  .channel-filter {
    display: flex;
    overflow-x: auto;
  }

  .nav-tab,
  .filter-chip {
    width: auto;
    flex: 0 0 auto;
  }

  .workspace {
    padding: 16px;
  }

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

  .top-actions {
    justify-content: stretch;
  }

  .search {
    min-width: 100%;
  }

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

  .work-queue {
    grid-template-columns: 1fr;
  }

  .crm-flow {
    grid-template-columns: 1fr;
  }

  .inbox-layout {
    grid-template-columns: 1fr;
    min-height: auto;
  }

  .thread-list,
  .conversation {
    min-height: 420px;
  }

  .connect-layout {
    grid-template-columns: 1fr;
  }

  .qr-box {
    min-height: 240px;
  }
}

@media (max-width: 540px) {
  h1 {
    font-size: 28px;
  }

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

  .reply-toolbar,
  .reply-actions,
  .conversation-header {
    align-items: stretch;
    flex-direction: column;
  }

  .reply-toolbar select {
    max-width: none;
  }

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