:root {
  color-scheme: light;
  --bg: #f4f7f6;
  --panel: #ffffff;
  --panel-soft: #eef5f2;
  --line: #d9e4df;
  --text: #17211d;
  --muted: #61706a;
  --brand: #168a55;
  --brand-strong: #0f6f45;
  --accent: #2563eb;
  --warn: #c27a16;
  --danger: #c2413a;
  --shadow: 0 12px 30px rgba(30, 55, 45, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family:
    "Microsoft YaHei",
    "PingFang SC",
    "Segoe UI",
    Arial,
    sans-serif;
}

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

button {
  border: 0;
  cursor: pointer;
}

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

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

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

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

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 4px;
  font-size: 24px;
}

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

.field {
  display: grid;
  gap: 8px;
  margin-bottom: 16px;
}

.field label {
  color: var(--muted);
  font-size: 14px;
}

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

input:focus,
select:focus,
textarea:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(22, 138, 85, 0.14);
}

.btn {
  min-height: 42px;
  border-radius: 6px;
  padding: 0 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: var(--panel-soft);
  color: var(--text);
  font-weight: 700;
  white-space: nowrap;
}

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

.btn.primary:hover {
  background: var(--brand-strong);
}

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

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

.btn.full {
  width: 100%;
}

.error {
  min-height: 22px;
  color: var(--danger);
  font-size: 14px;
}

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

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

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

.topbar-title h1 {
  font-size: 18px;
  margin: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.main-shell {
  min-height: 0;
  display: grid;
  grid-template-columns: 78px minmax(0, 1fr);
}

.toast {
  position: fixed;
  top: 74px;
  right: 18px;
  max-width: min(420px, calc(100vw - 36px));
  padding: 12px 14px;
  border-radius: 8px;
  background: #17211d;
  color: #fff;
  box-shadow: var(--shadow);
  z-index: 20;
  font-size: 14px;
}

.main-nav {
  min-height: calc(100vh - 64px);
  padding: 12px 8px;
  display: grid;
  align-content: start;
  gap: 8px;
  background: #10241b;
  border-right: 1px solid rgba(255, 255, 255, 0.08);
}

.main-nav-item {
  min-height: 62px;
  padding: 8px 4px;
  display: grid;
  place-items: center;
  gap: 5px;
  border-radius: 8px;
  background: transparent;
  color: rgba(255, 255, 255, 0.7);
}

.main-nav-item:hover,
.main-nav-item.active {
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
}

.main-nav-icon {
  width: 30px;
  height: 30px;
  border-radius: 7px;
  display: grid;
  place-items: center;
  background: rgba(255, 255, 255, 0.1);
  font-weight: 800;
}

.main-nav-label {
  font-size: 12px;
  font-weight: 700;
}

.role-badge,
.status-badge {
  border-radius: 999px;
  padding: 5px 10px;
  background: var(--panel-soft);
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.workspace {
  display: grid;
  grid-template-columns: 330px minmax(0, 1fr) 300px;
  min-height: 0;
}

.page {
  min-height: calc(100vh - 64px);
  overflow: auto;
  padding: 20px;
}

.page-head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.page-head h2 {
  margin-bottom: 6px;
  font-size: 22px;
}

.users-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 16px;
  align-items: start;
}

.users-panel,
.users-summary {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 8px 22px rgba(30, 55, 45, 0.08);
  overflow: hidden;
}

.users-panel {
  padding: 16px;
}

.log-table {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 8px 22px rgba(30, 55, 45, 0.08);
  overflow: auto;
}

.log-row {
  min-width: 860px;
  display: grid;
  grid-template-columns: 170px 180px 130px 150px minmax(220px, 1fr);
  gap: 12px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  align-items: center;
  font-size: 14px;
}

.log-row span {
  overflow-wrap: anywhere;
}

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

.log-head {
  position: sticky;
  top: 0;
  background: var(--panel-soft);
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
  z-index: 1;
}

.settings-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 16px;
  align-items: start;
}

.settings-panel {
  padding: 16px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 8px 22px rgba(30, 55, 45, 0.08);
}

.settings-panel h3 {
  margin-bottom: 12px;
  font-size: 16px;
}

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

.settings-field {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

.webhook-box {
  margin-bottom: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel-soft);
  color: var(--text);
  font-family: Consolas, "Courier New", monospace;
  font-size: 13px;
  overflow-wrap: anywhere;
}

.check-result {
  padding: 10px 12px;
  border-radius: 6px;
  font-weight: 700;
  font-size: 13px;
}

.check-result.ok {
  background: #e8f7ef;
  color: var(--brand-strong);
}

.check-result.warn {
  background: #fff4df;
  color: var(--warn);
}

.sidebar,
.details {
  min-height: calc(100vh - 64px);
  background: var(--panel);
  border-right: 1px solid var(--line);
  overflow: auto;
}

.details {
  border-right: 0;
  border-left: 1px solid var(--line);
}

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

.panel-head h2 {
  margin-bottom: 10px;
  font-size: 18px;
}

.toolbar {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

.toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px;
  border-radius: 8px;
  background: var(--panel-soft);
}

.switch {
  position: relative;
  width: 48px;
  height: 26px;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  inset: 0;
  border-radius: 999px;
  background: #bacac3;
}

.slider:before {
  content: "";
  position: absolute;
  width: 20px;
  height: 20px;
  top: 3px;
  left: 3px;
  border-radius: 50%;
  background: white;
  transition: transform 0.16s ease;
}

.switch input:checked + .slider {
  background: var(--brand);
}

.switch input:checked + .slider:before {
  transform: translateX(22px);
}

.conversation-list {
  display: grid;
}

.conversation-item {
  text-align: left;
  display: grid;
  gap: 7px;
  width: 100%;
  padding: 14px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  color: var(--text);
}

.conversation-item.unread {
  background: #f8fffb;
}

.conversation-item:hover,
.conversation-item.active {
  background: #f2faf6;
}

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

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

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

.unread-badge {
  min-width: 22px;
  height: 22px;
  padding: 0 7px;
  border-radius: 999px;
  display: inline-grid;
  place-items: center;
  background: #dc2626;
  color: #fff;
  font-size: 12px;
  font-weight: 800;
}

.last-message-time {
  color: var(--muted);
  font-size: 12px;
}

.chat {
  min-width: 0;
  min-height: calc(100vh - 64px);
  display: grid;
  grid-template-rows: auto 1fr auto;
}

.chat-head {
  padding: 16px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  background: #fbfdfc;
  border-bottom: 1px solid var(--line);
}

.chat-head h2 {
  margin-bottom: 4px;
  font-size: 20px;
}

.messages {
  overflow: auto;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.message {
  max-width: min(640px, 82%);
  padding: 10px 12px;
  border-radius: 8px;
  line-height: 1.5;
  box-shadow: 0 2px 8px rgba(22, 42, 33, 0.06);
}

.message.customer {
  align-self: flex-start;
  background: #fff;
  border: 1px solid var(--line);
}

.message.agent,
.message.admin {
  align-self: flex-end;
  background: #dcf8e9;
}

.message-meta {
  margin-top: 6px;
  color: var(--muted);
  font-size: 12px;
}

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

.composer-main {
  min-width: 0;
  display: grid;
  gap: 8px;
}

.composer textarea {
  min-height: 48px;
  max-height: 140px;
  resize: vertical;
}

.attachment-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.attachment-bar .btn {
  min-height: 34px;
  padding: 0 12px;
}

.attachment-message {
  display: grid;
  gap: 8px;
}

.attachment-image {
  display: block;
  width: min(320px, 100%);
  max-height: 260px;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid rgba(23, 33, 29, 0.12);
}

.attachment-name {
  color: var(--muted);
  font-size: 13px;
  overflow-wrap: anywhere;
}

.attachment-message audio {
  width: min(320px, 100%);
}

.file-card {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 10px;
  color: inherit;
  text-decoration: none;
}

.file-card strong,
.file-card small {
  display: block;
  overflow-wrap: anywhere;
}

.file-card small {
  margin-top: 2px;
  color: var(--muted);
}

.file-icon {
  width: 42px;
  height: 42px;
  border-radius: 6px;
  display: grid;
  place-items: center;
  background: rgba(37, 99, 235, 0.1);
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
}

.details-section {
  padding: 16px;
  border-bottom: 1px solid var(--line);
}

.details-section h3 {
  margin-bottom: 12px;
  font-size: 16px;
}

.kv {
  display: grid;
  gap: 10px;
}

.kv-row {
  display: grid;
  grid-template-columns: 88px 1fr;
  gap: 10px;
  font-size: 14px;
}

.kv-row span:first-child {
  color: var(--muted);
}

.assign-form {
  display: grid;
  gap: 10px;
}

.sales-account-list {
  display: grid;
  gap: 12px;
}

.sales-account {
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdfc;
}

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

.sales-account-fields {
  display: grid;
  gap: 8px;
}

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

.stats {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

.stat {
  padding: 12px;
  border-radius: 8px;
  background: var(--panel-soft);
}

.stat strong {
  display: block;
  font-size: 22px;
}

.empty {
  min-height: calc(100vh - 64px);
  display: grid;
  place-items: center;
  color: var(--muted);
  text-align: center;
  padding: 24px;
}

@media (max-width: 1100px) {
  .workspace {
    grid-template-columns: 290px minmax(0, 1fr);
  }

  .details {
    display: none;
  }

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

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

@media (max-width: 760px) {
  .app-shell {
    grid-template-rows: auto 1fr;
  }

  .topbar {
    min-height: 64px;
    height: auto;
    align-items: flex-start;
    padding: 12px;
  }

  .main-shell {
    grid-template-columns: 62px minmax(0, 1fr);
  }

  .main-nav {
    min-height: calc(100vh - 64px);
    padding: 8px 6px;
  }

  .main-nav-item {
    min-height: 56px;
  }

  .main-nav-label {
    font-size: 11px;
  }

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

  .page {
    padding: 12px;
  }

  .sidebar {
    min-height: auto;
    max-height: 38vh;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .chat {
    min-height: 62vh;
  }

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

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

  .message {
    max-width: 94%;
  }

  .user-chip {
    flex-direction: column;
    align-items: flex-end;
    gap: 6px;
  }
}
