:root {
  color-scheme: light;
  --bg: #f6f8f7;
  --surface: #ffffff;
  --surface-2: #f0f4f2;
  --text: #16211d;
  --muted: #64736d;
  --border: #dce5e0;
  --accent: #16745f;
  --accent-2: #0f5e4d;
  --danger: #a33b3b;
  --shadow: 0 14px 40px rgba(25, 42, 35, 0.08);
  font-family: Inter, "Segoe UI", "Microsoft YaHei", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

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

button {
  border: 0;
  cursor: pointer;
}

a {
  color: var(--accent);
  text-decoration: none;
}

.shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-panel {
  width: min(440px, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 28px;
}

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

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

.brand-mark.small {
  width: 34px;
  height: 34px;
  font-size: 16px;
}

.brand h1,
.brand h2 {
  margin: 0;
  font-size: 22px;
  line-height: 1.2;
}

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

.form {
  display: grid;
  gap: 14px;
}

.field {
  display: grid;
  gap: 7px;
}

.field span {
  color: #30423b;
  font-size: 14px;
  font-weight: 650;
}

.input,
.textarea,
.select {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  padding: 11px 12px;
  outline: none;
}

.input:focus,
.textarea:focus,
.select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(22, 116, 95, 0.12);
}

.textarea {
  resize: vertical;
  min-height: 88px;
}

.primary,
.secondary,
.ghost,
.danger {
  min-height: 40px;
  border-radius: 8px;
  padding: 0 14px;
  font-weight: 700;
}

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

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

.secondary {
  background: #e5efe9;
  color: #173f34;
}

.ghost {
  background: transparent;
  color: var(--accent);
}

.danger {
  background: #f5e3e3;
  color: var(--danger);
}

.status-ok {
  color: var(--accent-2);
  font-weight: 750;
}

.status-danger {
  color: var(--danger);
  font-weight: 750;
}

.error {
  margin: 10px 0 0;
  color: var(--danger);
  font-size: 14px;
}

.app-layout {
  height: 100vh;
  height: 100dvh;
  display: grid;
  grid-template-rows: auto 1fr;
}

.topbar {
  height: 62px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  background: rgba(255, 255, 255, 0.92);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(12px);
}

.client-topbar {
  min-height: 68px;
  height: auto;
  gap: 16px;
  padding: 12px 22px;
}

.topbar-brand {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 12px;
}

.topbar-brand > div:last-child {
  min-width: 0;
  display: grid;
  gap: 3px;
}

.topbar-brand strong {
  font-size: 16px;
}

.topbar-brand span {
  color: var(--muted);
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar-presence,
.service-status {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--accent-2);
  font-size: 13px;
  font-weight: 700;
}

.presence-dot {
  width: 8px;
  height: 8px;
  display: inline-block;
  border-radius: 50%;
  background: #16a36a;
  box-shadow: 0 0 0 4px rgba(22, 163, 106, 0.12);
}

.presence-dot.offline {
  background: #9aa5a0;
  box-shadow: 0 0 0 4px rgba(100, 115, 109, 0.12);
}

.client-workspace {
  min-height: 0;
  overflow: hidden;
  display: grid;
  grid-template-columns: 280px minmax(0, 920px);
  justify-content: center;
  gap: 18px;
  padding: 18px;
}

.client-panel {
  min-height: 0;
  display: grid;
  align-content: start;
  gap: 12px;
}

.service-card,
.info-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.service-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px;
}

.service-avatar {
  width: 44px;
  height: 44px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: #dff3ec;
  color: var(--accent-2);
  font-weight: 850;
}

.service-name {
  margin-bottom: 5px;
  font-size: 17px;
  font-weight: 800;
}

.info-panel {
  display: grid;
}

.info-row {
  display: grid;
  gap: 5px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}

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

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

.info-row strong {
  min-width: 0;
  overflow-wrap: anywhere;
  font-size: 14px;
}

.chat {
  min-height: 0;
  display: grid;
  grid-template-rows: 1fr auto;
  width: min(920px, 100%);
  margin: 0 auto;
}

.client-chat {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.62);
  box-shadow: var(--shadow);
  overflow: hidden;
  grid-template-rows: auto 1fr auto;
}

.conversation-head {
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 18px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.conversation-head h2 {
  margin: 0;
  font-size: 18px;
  line-height: 1.25;
}

.conversation-head p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.messages {
  min-height: 0;
  overflow: auto;
  padding: 24px 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.message {
  max-width: min(720px, 84%);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
  background: var(--surface);
}

.message.customer {
  align-self: flex-end;
  background: #e7f5ef;
  border-color: #c7e7dc;
}

.message.admin {
  align-self: flex-start;
}

.message-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 6px;
  font-size: 12px;
  color: var(--muted);
}

.message-meta > span:first-child {
  flex: 0 0 auto;
}

.meta-right {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 7px;
  flex-wrap: wrap;
  flex: 0 0 auto;
}

.read-receipt {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 2px 7px;
  font-size: 11px;
  font-weight: 750;
}

.read-receipt.read {
  background: #e7f5ef;
  color: var(--accent-2);
}

.read-receipt.unread {
  background: #f1f4f2;
  color: var(--muted);
}

.revoke-badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 2px 7px;
  background: #f5e3e3;
  color: var(--danger);
  font-size: 11px;
  font-weight: 750;
}

.message.revoked {
  border-style: dashed;
}

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

.message-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.message-action {
  min-height: 32px;
  padding: 0 11px;
  border: 1px solid #bbdacf;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.82);
  color: var(--accent-2);
  font-size: 13px;
  font-weight: 750;
}

.message-action:hover:not(:disabled) {
  background: #f7fffb;
}

.message-action.danger-action {
  border-color: #edc8c8;
  color: var(--danger);
}

.message-action:disabled {
  cursor: default;
  opacity: 0.78;
}

.attachment {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
  padding: 8px 10px;
  background: rgba(255, 255, 255, 0.75);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-weight: 650;
}

.image-preview {
  display: block;
  width: min(340px, 100%);
  margin-top: 8px;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.7);
}

.image-preview img {
  display: block;
  width: 100%;
  max-height: 280px;
  object-fit: contain;
  background: #fff;
}

.composer {
  border-top: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.96);
  padding: 14px 16px 18px;
}

.composer-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 10px;
  align-items: end;
}

.file-name {
  margin: 8px 0 0;
  font-size: 13px;
  color: var(--muted);
}

.upload-button {
  display: grid;
  place-items: center;
}

.client-empty {
  align-self: center;
  justify-self: center;
  width: min(360px, 100%);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 18px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.client-empty div:last-child {
  display: grid;
  gap: 5px;
}

.client-empty strong {
  font-size: 16px;
}

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

.admin-layout {
  height: 100vh;
  display: grid;
  grid-template-columns: 340px 1fr;
  background: var(--bg);
}

.sidebar {
  min-height: 0;
  border-right: 1px solid var(--border);
  background: var(--surface);
  display: grid;
  grid-template-rows: auto auto 1fr;
}

.sidebar-head {
  padding: 18px;
  border-bottom: 1px solid var(--border);
}

.filters {
  display: grid;
  gap: 10px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}

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

.customer-row {
  width: 100%;
  min-width: 0;
  display: grid;
  gap: 6px;
  padding: 14px 18px;
  text-align: left;
  background: transparent;
  border-bottom: 1px solid var(--border);
}

.customer-row:hover,
.customer-row.active {
  background: var(--surface-2);
}

.row-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-width: 0;
}

.row-top strong {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.row-badges {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 6px;
}

.pill {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 3px 8px;
  background: #edf4f1;
  color: #315248;
  font-size: 12px;
  font-weight: 700;
}

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

.pill.live {
  background: #e7f5ef;
  color: var(--accent-2);
}

.pill.live.offline {
  background: #f1f4f2;
  color: var(--muted);
}

.pill.banned {
  background: #f5e3e3;
  color: var(--danger);
}

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

.admin-head {
  display: grid;
  gap: 12px;
  padding: 18px 22px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.admin-head-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.identity {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}

.admin-tools {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 10px;
}

.row-preview {
  display: -webkit-box;
  overflow: hidden;
  overflow-wrap: anywhere;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  line-height: 1.35;
}

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

.admin-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
}

.ban-reason {
  padding: 10px 12px;
  border: 1px solid #edc8c8;
  border-radius: 8px;
  background: #fff6f6;
  color: var(--danger);
  font-size: 13px;
  line-height: 1.45;
}

.empty-state {
  display: grid;
  place-items: center;
  color: var(--muted);
  padding: 48px;
}

@media (max-width: 860px) {
  .app-layout {
    grid-template-rows: auto minmax(0, 1fr);
  }

  .client-topbar {
    flex-wrap: wrap;
    min-height: 58px;
    padding: 9px 14px;
    row-gap: 6px;
  }

  .brand-mark.small {
    width: 30px;
    height: 30px;
  }

  .topbar-brand {
    flex: 1 1 auto;
  }

  .topbar-brand strong {
    font-size: 15px;
  }

  .topbar-brand span {
    max-width: 230px;
    font-size: 12px;
  }

  .topbar-presence {
    display: none;
  }

  .client-workspace {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(0, 1fr);
    gap: 0;
    padding: 0;
  }

  .client-panel {
    display: block;
    padding: 8px 12px;
    background: rgba(255, 255, 255, 0.86);
    border-bottom: 1px solid var(--border);
  }

  .client-panel .service-card {
    box-shadow: none;
    padding: 10px 12px;
  }

  .client-panel .service-avatar {
    width: 36px;
    height: 36px;
  }

  .service-name {
    font-size: 15px;
    margin-bottom: 3px;
  }

  .client-panel .info-panel {
    display: none;
  }

  .client-chat {
    border-right: 0;
    border-left: 0;
    border-bottom: 0;
    border-radius: 0;
    box-shadow: none;
  }

  .conversation-head {
    align-items: center;
    padding: 12px 14px;
  }

  .conversation-head h2 {
    font-size: 16px;
  }

  .conversation-head p {
    font-size: 12px;
  }

  .messages {
    padding: 14px 12px;
    gap: 10px;
  }

  .client-chat .composer {
    padding: 10px 12px 12px;
  }

  .client-chat .composer-row {
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }

  .client-chat .composer-row .textarea {
    grid-column: 1 / -1;
    min-height: 72px;
  }

  .client-chat .primary,
  .client-chat .secondary {
    min-height: 40px;
  }

  .admin-layout {
    grid-template-columns: 1fr;
    grid-template-rows: 42vh 58vh;
  }

  .admin-tools {
    grid-template-columns: 1fr;
  }

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

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

@media (max-width: 560px) {
  .topbar {
    padding: 9px 14px;
  }

  .topbar-brand {
    max-width: calc(100vw - 82px);
  }

  .conversation-head {
    padding: 11px 12px;
  }

  .message {
    max-width: 90%;
    padding: 10px 12px;
  }
}
