:root {
  --bg: #f3f5f7;
  --panel: #ffffff;
  --panel-soft: #f8fafb;
  --line: #dfe5ea;
  --line-strong: #cfd8df;
  --text: #202832;
  --muted: #697684;
  --faint: #8c98a5;
  --accent: #178f69;
  --accent-dark: #0d7453;
  --accent-soft: #e8f6f1;
  --blue: #2d6cdf;
  --blue-soft: #eaf1ff;
  --amber: #b56a00;
  --amber-soft: #fff4df;
  --red: #b42318;
  --red-soft: #fff0ee;
  --incoming: #ffffff;
  --outgoing: #e8f6f1;
  --system: #eef2f5;
  --shadow: 0 10px 30px rgba(32, 40, 50, 0.08);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
  overflow: hidden;
}

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

[hidden] {
  display: none !important;
}

button {
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  border-radius: 7px;
  cursor: pointer;
  min-height: 36px;
  padding: 0 12px;
}

button:hover {
  border-color: var(--accent);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--text);
  outline: none;
}

input,
select {
  height: 38px;
  padding: 0 10px;
}

textarea {
  min-height: 78px;
  resize: vertical;
  padding: 11px 12px;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(23, 143, 105, 0.12);
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(280px, 340px) minmax(420px, 1fr) minmax(260px, 320px);
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  min-height: 0;
  overflow: hidden;
  background: var(--bg);
}

.sidebar,
.thread,
.details {
  min-height: 0;
  background: var(--panel);
}

.sidebar {
  display: grid;
  grid-template-rows: auto auto auto minmax(0, 1fr);
  border-right: 1px solid var(--line);
  overflow: hidden;
}

.details {
  border-left: 1px solid var(--line);
  overflow: auto;
  padding: 18px;
  min-width: 0;
}

.sidebar-head,
.thread-head {
  min-height: 76px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 18px;
  background: rgba(255, 255, 255, 0.94);
}

.brand {
  font-size: 19px;
  font-weight: 800;
}

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

.logout {
  color: var(--muted);
  text-decoration: none;
  font-size: 14px;
  padding: 6px 8px;
  border-radius: 6px;
}

.logout:hover {
  background: var(--panel-soft);
  color: var(--text);
}

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

.queue-summary {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  padding: 12px;
  border-bottom: 1px solid var(--line);
  background: var(--panel-soft);
}

.queue-summary div {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 9px 10px;
}

.queue-summary span {
  display: block;
  font-size: 20px;
  font-weight: 800;
  line-height: 1;
}

.queue-summary small {
  display: block;
  margin-top: 5px;
  color: var(--muted);
  font-size: 12px;
}

.filters {
  display: grid;
  grid-template-columns: 1fr 124px 68px;
  gap: 8px;
  padding: 12px;
  border-bottom: 1px solid var(--line);
}

.my-queue-button.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.conversation-list {
  min-height: 0;
  overflow: auto;
}

.conversation {
  display: grid;
  grid-template-columns: 42px 1fr;
  gap: 10px;
  width: 100%;
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  text-align: left;
  padding: 12px;
  background: var(--panel);
  min-height: 92px;
}

.conversation:hover {
  background: #fbfcfd;
}

.conversation.active {
  background: var(--accent-soft);
  box-shadow: inset 3px 0 0 var(--accent);
}

.avatar {
  width: 42px;
  height: 42px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  background: #edf2f5;
  color: #30414f;
  font-weight: 800;
}

.conversation-main {
  min-width: 0;
  display: grid;
  gap: 6px;
}

.conversation-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-weight: 780;
}

.conversation-title span:first-child {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.conversation-preview {
  color: var(--muted);
  line-height: 1.35;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.conversation-meta,
.thread-subtitle {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  border-radius: 999px;
  background: #edf2f5;
  color: var(--muted);
  font-size: 12px;
  line-height: 1;
  padding: 0 8px;
  white-space: nowrap;
}

.pill.unread {
  background: var(--accent);
  color: #fff;
}

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

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

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

.pill.status-delivered {
  background: #edf7e8;
  color: #447713;
}

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

.operator-pill {
  max-width: 110px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.thread {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  min-width: 0;
  background: linear-gradient(#f7f9fa, #f7f9fa);
}

.thread h1 {
  margin: 0 0 5px;
  font-size: 20px;
  line-height: 1.15;
}

.status-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  justify-content: flex-end;
}

.status-actions button {
  min-height: 34px;
  background: #fff;
}

.status-actions button.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.messages {
  overflow: auto;
  padding: 22px 26px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.message-day {
  align-self: center;
  background: rgba(255, 255, 255, 0.88);
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  font-size: 12px;
  padding: 5px 10px;
  margin: 3px 0;
}

.message {
  max-width: min(620px, 72%);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  line-height: 1.43;
  box-shadow: 0 1px 1px rgba(32, 40, 50, 0.04);
}

.message.in {
  align-self: flex-start;
  background: var(--incoming);
  border-bottom-left-radius: 4px;
}

.message.out {
  align-self: flex-end;
  background: var(--outgoing);
  border-color: #c3eadb;
  border-bottom-right-radius: 4px;
}

.message.system {
  align-self: center;
  max-width: 74%;
  border: 0;
  box-shadow: none;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  padding: 2px 0;
}

.message.system .message-text {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  border-radius: 999px;
  background: var(--system);
  padding: 5px 10px;
}

.message-meta {
  display: flex;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 5px;
}

.message-text {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.message-text + .message-media,
.message-text + .message-audio,
.message-text + .file-attachment {
  margin-top: 8px;
}

.message-media {
  display: block;
  max-width: 100%;
  overflow: hidden;
  border-radius: 9px;
}

.message-media.image {
  border: 1px solid rgba(32, 40, 50, 0.08);
  background: #fff;
}

.message-media img {
  display: block;
  max-width: min(420px, 100%);
  max-height: 320px;
  object-fit: contain;
}

.message-media.video {
  width: min(420px, 100%);
  max-height: 320px;
  background: #111820;
}

.message-audio {
  display: block;
  width: min(360px, 100%);
}

.attachment-name {
  display: inline-block;
  margin-top: 6px;
  color: var(--accent-dark);
  font-size: 13px;
  text-decoration: none;
  overflow-wrap: anywhere;
}

.attachment-name:hover {
  text-decoration: underline;
}

.file-attachment {
  display: grid;
  grid-template-columns: 40px 1fr;
  gap: 10px;
  align-items: center;
  min-width: 220px;
  max-width: 100%;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: rgba(255, 255, 255, 0.58);
  color: var(--text);
  text-decoration: none;
}

.file-attachment:hover {
  border-color: var(--accent);
}

.file-icon {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 8px;
  background: var(--panel-soft);
  color: var(--muted);
  font-size: 10px;
  font-weight: 850;
}

.file-attachment strong {
  display: block;
  overflow-wrap: anywhere;
}

.file-attachment small {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.composer {
  display: grid;
  gap: 9px;
  padding: 13px 18px;
  border-top: 1px solid var(--line);
  background: var(--panel);
}

.quick-replies {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 7px;
}

.quick-replies button,
.template-list button {
  min-height: 30px;
  border-color: transparent;
  background: var(--panel-soft);
  color: var(--muted);
  font-size: 13px;
}

.quick-replies button:hover,
.template-list button:hover {
  background: #eef6f3;
  color: var(--accent-dark);
}

.template-add-button {
  width: 30px;
  padding: 0;
  border-radius: 50%;
  font-size: 20px;
  line-height: 1;
}

.template-list {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.template-item {
  display: inline-grid;
  grid-template-columns: minmax(0, auto) 24px;
  align-items: center;
  border-radius: 7px;
  background: var(--blue-soft);
}

.template-item .template-insert {
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  background: transparent;
  color: var(--blue);
}

.template-item .template-delete {
  width: 24px;
  min-height: 30px;
  padding: 0;
  background: transparent;
  color: var(--faint);
}

.template-item .template-delete:hover {
  color: var(--red);
  background: var(--red-soft);
}

.template-form {
  display: grid;
  grid-template-columns: minmax(160px, 220px) 1fr 230px;
  gap: 8px;
  align-items: start;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
}

.template-form textarea {
  min-height: 82px;
}

.template-actions {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}

.template-actions button {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 760;
}

.template-form .tool-status {
  grid-column: 1 / -1;
}

.composer-row {
  display: grid;
  grid-template-columns: 1fr 132px;
  gap: 10px;
}

.composer-actions {
  display: grid;
  grid-template-rows: 36px 1fr;
  gap: 8px;
}

.composer-actions button {
  width: 100%;
}

#sendButton,
.login-panel button {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 760;
}

#sendButton:hover,
.login-panel button:hover {
  background: var(--accent-dark);
  border-color: var(--accent-dark);
}

.attach-button {
  background: var(--panel-soft);
  color: var(--muted);
}

.attachment-preview {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 34px;
  padding: 7px 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
  color: var(--muted);
  font-size: 13px;
}

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

.attachment-preview button {
  min-height: 28px;
  flex: 0 0 auto;
  padding: 0 9px;
}

.details section {
  padding-bottom: 18px;
}

.details section + section {
  border-top: 1px solid var(--line);
  padding-top: 18px;
}

.details h2 {
  margin: 0 0 12px;
  font-size: 12px;
  text-transform: uppercase;
  color: var(--muted);
}

.client-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding-bottom: 18px;
}

.client-card > div:last-child {
  min-width: 0;
}

.client-avatar {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  background: var(--accent-soft);
  color: var(--accent-dark);
  font-weight: 850;
  font-size: 18px;
}

.client-name {
  font-size: 18px;
  font-weight: 800;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

dl {
  margin: 0;
  display: grid;
  grid-template-columns: 92px 1fr;
  gap: 9px 10px;
  font-size: 14px;
}

dt {
  color: var(--muted);
}

dd {
  margin: 0;
  overflow-wrap: anywhere;
}

.copy-value {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
}

.external-link {
  color: var(--accent-dark);
  text-decoration: none;
}

.external-link:hover {
  text-decoration: underline;
}

.operator-panel {
  display: grid;
  gap: 12px;
}

.operator-identity {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
}

.operator-name-row {
  display: grid;
  grid-template-columns: 1fr 48px;
  gap: 8px;
}

.operator-name-row button {
  padding: 0;
}

.assignment-state {
  display: grid;
  gap: 4px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--panel-soft);
  color: var(--muted);
  font-size: 13px;
}

.assignment-state strong {
  color: var(--text);
  font-size: 15px;
  overflow-wrap: anywhere;
}

.assignment-state small {
  line-height: 1.35;
}

.assignment-actions {
  display: grid;
  grid-template-columns: 1fr 88px;
  gap: 8px;
}

#takeButton {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 760;
}

#takeButton:hover {
  background: var(--accent-dark);
  border-color: var(--accent-dark);
}

.payment-panel,
.templates-panel {
  display: grid;
  gap: 10px;
}

.payment-form {
  display: grid;
  gap: 9px;
}

.payment-form label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

.payment-form button {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 760;
}

.payment-form button:hover,
.template-actions button:hover {
  background: var(--accent-dark);
  border-color: var(--accent-dark);
}

.payment-webhook-status {
  display: grid;
  gap: 4px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--panel-soft);
}

.payment-webhook-status span {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  font-weight: 780;
}

.payment-webhook-status strong {
  color: var(--text);
  font-size: 15px;
}

.payment-webhook-status small {
  color: var(--muted);
  line-height: 1.35;
}

.payment-webhook-status.state-waiting {
  border-color: #f0d196;
  background: var(--amber-soft);
}

.payment-webhook-status.state-paid {
  border-color: #a9d8c8;
  background: var(--accent-soft);
}

.payment-webhook-status.state-error {
  border-color: #f0b7b1;
  background: var(--red-soft);
}

.tool-status {
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.request-list {
  display: grid;
  gap: 10px;
}

.request {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 11px;
  background: var(--panel-soft);
}

.request-title {
  font-weight: 800;
  margin-bottom: 6px;
}

.request p {
  margin: 10px 0 0;
  line-height: 1.42;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.empty-state {
  margin: auto;
  color: var(--muted);
  text-align: center;
}

.login-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background: #eef2f5;
  overflow: auto;
}

.login-panel {
  width: min(360px, calc(100vw - 32px));
  display: grid;
  gap: 14px;
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.login-panel h1 {
  margin: 0;
  font-size: 22px;
}

.login-mark {
  color: var(--accent);
  font-weight: 850;
}

.login-panel label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 14px;
}

.login-error {
  color: var(--red);
  font-size: 14px;
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: minmax(280px, 330px) minmax(360px, 1fr);
  }

  .details {
    display: none;
  }
}

@media (max-width: 760px) {
  .app-shell {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(0, 42dvh) minmax(0, 58dvh);
    min-height: 0;
  }

  .sidebar {
    height: auto;
  }

  .conversation-list {
    min-height: 0;
  }

  .thread {
    height: auto;
  }

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

  .message {
    max-width: 88%;
  }

  .composer-row {
    grid-template-columns: 1fr;
  }

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

  .composer-actions {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: auto;
  }
}
