:root {
  color-scheme: light;
  --bg: #eef3f6;
  --panel: #ffffff;
  --panel-soft: #f7fafb;
  --line: #cfd9df;
  --line-strong: #aebdc7;
  --text: #16202a;
  --muted: #5c6a75;
  --brand: #187a74;
  --brand-dark: #0e5d58;
  --brand-soft: #dff3ef;
  --blue: #255fd5;
  --danger: #c43d4b;
  --warning: #a76611;
  --shadow: 0 18px 48px rgba(22, 32, 42, 0.14);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Arial, Helvetica, sans-serif;
  overflow: hidden;
}

button,
input,
textarea {
  font: inherit;
}

.app-shell {
  height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr;
  min-height: 0;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 64px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

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

.brand-mark {
  display: inline-grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 8px;
  background: var(--brand);
  color: #ffffff;
  font-weight: 900;
}

.brand h1,
.brand p,
.chat-detail-head h2,
.chat-detail-head p,
.sidebar-head h2,
.qr-panel h2,
.qr-panel p {
  margin: 0;
}

.brand h1 {
  font-size: 1.24rem;
  line-height: 1.1;
}

.brand p,
.chat-detail-head p,
.qr-panel p {
  color: var(--muted);
  font-size: 0.9rem;
}

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

.user-chip {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel-soft);
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 700;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  padding: 0 12px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: var(--brand);
  color: #ffffff;
  cursor: pointer;
  font-weight: 800;
}

.button:hover {
  background: var(--brand-dark);
}

.button:disabled {
  cursor: not-allowed;
  opacity: 0.58;
}

.button.primary {
  min-height: 44px;
  padding: 0 18px;
  background: var(--blue);
}

.button.primary:hover {
  background: #1d4db2;
}

.button.ghost {
  background: #edf5f7;
  border-color: var(--line);
  color: var(--brand-dark);
}

.button.ghost:hover {
  background: #e2eef1;
}

.button.quiet {
  background: #f5f7f8;
  border-color: var(--line);
  color: var(--text);
}

.button.quiet:hover {
  background: #e9eef1;
}

.button.danger {
  background: #fff1f2;
  border-color: rgba(196, 61, 75, 0.28);
  color: var(--danger);
}

.button.danger:hover {
  background: #ffe4e6;
}

.workspace {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  gap: 12px;
  min-height: 0;
  overflow: hidden;
  padding: 14px;
}

.status-panel,
.qr-panel,
.chat-sidebar,
.chat-detail {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 8px 22px rgba(22, 32, 42, 0.05);
}

.status-panel {
  display: grid;
  grid-template-columns: minmax(320px, 620px) auto;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 58px;
  padding: 8px 12px;
}

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

.profile-grid div {
  min-width: 0;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
}

.profile-grid span {
  display: block;
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 800;
  text-transform: uppercase;
}

.profile-grid strong {
  display: block;
  margin-top: 3px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

.qr-panel {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 16px;
  min-height: 84px;
  padding: 14px 18px;
}

.qr-panel img {
  width: 230px;
  max-width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.chat-layout {
  display: grid;
  grid-template-columns: minmax(270px, 360px) minmax(0, 1fr);
  gap: 12px;
  min-height: 0;
  height: auto;
}

.chat-sidebar,
.chat-detail {
  min-height: 0;
}

.chat-sidebar {
  display: grid;
  grid-template-rows: auto auto 1fr;
  gap: 9px;
  padding: 11px;
}

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

.sidebar-head h2,
.chat-detail-head h2,
.qr-panel h2 {
  font-size: 1.02rem;
}

.sidebar-head span {
  min-width: 32px;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--brand-soft);
  color: var(--brand-dark);
  text-align: center;
  font-size: 0.8rem;
  font-weight: 900;
}

.search-input {
  width: 100%;
  min-height: 36px;
  padding: 0 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  outline: none;
}

.search-input:focus,
.composer textarea:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(24, 122, 116, 0.13);
}

.chat-list {
  min-height: 0;
  overflow-y: auto;
  display: grid;
  align-content: start;
  gap: 7px;
  padding-right: 2px;
}

.chat-item {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
  color: var(--text);
  cursor: pointer;
  padding: 9px 10px;
  text-align: left;
}

.chat-item:hover {
  border-color: var(--line-strong);
  background: #eef6f6;
}

.chat-item.active {
  border-color: var(--brand);
  background: var(--brand-soft);
}

.chat-item.unread {
  border-color: #7aa7e8;
  box-shadow: inset 3px 0 0 #255fd5;
}

.chat-row-title {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-weight: 900;
}

.chat-row-title span {
  overflow-wrap: anywhere;
}

.chat-row-title small {
  color: var(--blue);
  white-space: nowrap;
}

.chat-row-meta,
.chat-row-preview {
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.82rem;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-box-orient: vertical;
}

.chat-row-preview {
  -webkit-line-clamp: 2;
}

.chat-row-meta {
  -webkit-line-clamp: 1;
}

.chat-detail {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
}

.chat-detail-head {
  min-height: 48px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--line);
}

.message-list {
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 5px;
  padding: 10px 12px;
  background:
    linear-gradient(rgba(255, 255, 255, 0.9), rgba(255, 255, 255, 0.9)),
    repeating-linear-gradient(135deg, #e3eaee 0 1px, transparent 1px 18px);
}

.message-row {
  display: flex;
  justify-content: flex-start;
}

.message-row.me {
  justify-content: flex-end;
}

.message-bubble {
  display: grid;
  gap: 3px;
  max-width: min(54%, 560px);
  padding: 6px 9px;
  border: 1px solid rgba(24, 122, 116, 0.22);
  border-radius: 8px;
  background: #dff3e6;
  box-shadow: 0 2px 8px rgba(22, 32, 42, 0.04);
  color: #081c17;
  font-size: 0.86rem;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  line-height: 1.28;
}

.message-ticket {
  font-weight: 900;
}

.message-reply-button {
  justify-self: start;
  min-height: 28px;
  margin-top: 4px;
  padding: 0 10px;
  border: 1px solid rgba(24, 122, 116, 0.34);
  border-radius: 7px;
  background: #ffffff;
  color: var(--brand-dark);
  cursor: pointer;
  font-size: 0.78rem;
  font-weight: 900;
}

.message-reply-button:hover {
  background: #eef8f5;
  border-color: rgba(24, 122, 116, 0.55);
}

.message-bubble--media {
  max-width: 180px;
  min-width: 110px;
  padding: 6px 9px;
  color: var(--muted);
  font-style: italic;
  text-align: center;
}

.message-row.me .message-bubble {
  border-color: rgba(37, 95, 213, 0.28);
  background: #dce8ff;
  color: #071a3d;
}

.message-time {
  display: block;
  margin-top: 2px;
  color: rgba(22, 32, 42, 0.62);
  font-size: 0.68rem;
  font-weight: 700;
}

.message-row.me .message-time {
  color: rgba(7, 26, 61, 0.62);
}

.composer {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  padding: 8px 10px 10px;
  border-top: 1px solid var(--line);
  background: var(--panel);
}

.composer textarea {
  width: 100%;
  resize: none;
  min-height: 42px;
  max-height: 96px;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  outline: none;
}

.composer-status {
  display: none;
  margin: 0;
  padding: 0 12px 10px;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 700;
}

.composer-status.error {
  display: block;
  color: var(--danger);
}

.empty-text {
  margin: 0;
  color: var(--muted);
}

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

.login-shell {
  width: min(420px, calc(100vw - 32px));
}

.login-panel {
  display: grid;
  gap: 12px;
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  box-shadow: var(--shadow);
}

.login-panel h1,
.login-panel p {
  margin: 0;
}

.login-panel p {
  color: var(--muted);
}

.login-form {
  display: grid;
  gap: 12px;
}

.login-form label {
  display: grid;
  gap: 6px;
  color: var(--text);
  font-weight: 800;
}

.login-form input {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 11px;
}

.login-form button {
  min-height: 42px;
  border: 0;
  border-radius: 8px;
  background: var(--brand);
  color: #ffffff;
  cursor: pointer;
  font-weight: 900;
}

.login-error {
  padding: 10px 12px;
  border: 1px solid rgba(196, 61, 75, 0.25);
  border-radius: 8px;
  background: #fff1f2;
  color: var(--danger);
  font-weight: 800;
}

@media (max-width: 1050px) {
  body {
    overflow: auto;
  }

  .app-shell {
    height: auto;
    min-height: 100vh;
  }

  .workspace {
    overflow: visible;
  }

  .status-panel {
    grid-template-columns: 1fr;
  }

  .status-actions {
    justify-content: flex-start;
  }

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

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

  .chat-sidebar {
    max-height: 360px;
  }
}

@media (max-width: 640px) {
  .topbar,
  .topbar-actions,
  .status-actions,
  .qr-panel,
  .composer {
    display: grid;
    grid-template-columns: 1fr;
  }

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