:root {
  color-scheme: light;
  font-family: "Segoe UI", "PingFang SC", sans-serif;
  --bg: #f6f8fb;
  --panel: #ffffff;
  --line: #e3e8ef;
  --brand: #0c7d63;
  --brand-hover: #086d56;
  --text: #172b4d;
  --muted: #6b778c;
  --warn: #e67e22;
}

* { box-sizing: border-box; }
html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}

.app {
  height: 100vh;
  display: grid;
  grid-template-columns: 380px 1fr;
  overflow: hidden;
}

.sidebar,
.chat-panel {
  background: var(--panel);
  padding: 1rem;
  min-height: 0;
  overflow: hidden;
}

.sidebar {
  border-right: 1px solid var(--line);
  display: grid;
  grid-template-rows: auto auto auto minmax(0, 1fr);
  gap: 0.75rem;
}

.sidebar-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

h1, h2, h3, p { margin: 0; }

.auth-panel {
  border: 1px solid var(--line);
  border-radius: 0.7rem;
  padding: 0.7rem;
  display: grid;
  gap: 0.5rem;
}

.auth-panel h2 { font-size: 1rem; }

.auth-form {
  display: grid;
  gap: 0.45rem;
}

.auth-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.45rem;
}

.settings-bar {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.45rem;
}

input,
textarea,
button {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 0.6rem;
  padding: 0.65rem 0.75rem;
  font: inherit;
}

button {
  background: var(--brand);
  color: #fff;
  border: 0;
  cursor: pointer;
}
button:hover:not(:disabled) { background: var(--brand-hover); }
button:disabled { cursor: not-allowed; opacity: 0.55; }

.ghost-btn {
  background: transparent;
  color: var(--brand);
  border: 1px solid var(--line);
}

.muted { color: var(--muted); font-size: 0.88rem; }
.warning { color: var(--warn); }

.customer-list {
  list-style: none;
  margin: 0;
  padding: 0;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.customer-item {
  border: 1px solid var(--line);
  border-radius: 0.7rem;
  padding: 0.62rem;
  cursor: pointer;
}
.customer-item:hover { border-color: #c9d3df; }
.customer-item.active { border-color: var(--brand); background: #e1f6ef; box-shadow: inset 0 0 0 1px #0c7d63; }
.customer-item.over-24h {
  background: #f4f4f4;
  border-color: #d9d9d9;
}
.customer-item.over-24h .name,
.customer-item.over-24h .preview,
.customer-item.over-24h .time {
  color: #8d8d8d;
}

.customer-item.readonly {
  background: #f6f6f6;
  border-color: #d7d7d7;
}
.customer-item.readonly .name,
.customer-item.readonly .preview,
.customer-item.readonly .time {
  color: #888;
}

.customer-item .line-1,
.customer-item .line-2 {
  display: flex;
  justify-content: space-between;
  gap: 0.6rem;
  align-items: center;
}

.customer-item .name { font-weight: 600; }
.customer-item .preview {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 220px;
}

.badge {
  min-width: 1.4rem;
  text-align: center;
  border-radius: 999px;
  font-size: 0.72rem;
  padding: 0.05rem 0.35rem;
  color: #fff;
  background: var(--brand);
  display: none;
}
.badge.show { display: inline-block; }
.badge.ws-unread {
  min-width: 0.65rem;
  width: 0.65rem;
  height: 0.65rem;
  padding: 0;
  border: 2px solid #fff;
  background: #ff2d2d;
  box-shadow: 0 0 0 1px #ff2d2d;
}

.chat-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 1rem;
}

.message-list {
  list-style: none;
  margin: 0;
  padding: 0;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.message-item {
  max-width: min(78%, 560px);
  border-radius: 0.75rem;
  padding: 0.7rem 0.85rem;
  background: #f2f5f8;
}
.message-item.outbound { margin-left: auto; background: #d9f7ec; }
.message-item.auto-reply { border: 1px dashed #73c8a9; }

.message-item .meta {
  font-size: 0.73rem;
  color: var(--muted);
  margin: 0 0 0.35rem;
}
.message-item .content {
  margin: 0;
  white-space: pre-wrap;
  line-height: 1.4;
}

.message-form {
  border-top: 1px solid var(--line);
  padding-top: 0.9rem;
}

.media-form {
  border-top: 1px dashed var(--line);
  padding-top: 0.75rem;
  display: grid;
  gap: 0.5rem;
}

.media-grid {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 0.6rem;
}

.media-grid label {
  font-size: 0.85rem;
  color: var(--muted);
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.34);
  display: grid;
  place-items: center;
  z-index: 999;
}
.hidden { display: none; }

.modal-content {
  width: min(92vw, 460px);
  background: #fff;
  border-radius: 0.9rem;
  padding: 1rem;
  display: grid;
  gap: 0.7rem;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.6rem;
}

@media (max-width: 900px) {
  body { overflow: auto; }
  .app {
    height: auto;
    min-height: 100vh;
    grid-template-columns: 1fr;
  }
  .sidebar {
    border-right: none;
    border-bottom: 1px solid var(--line);
    max-height: 52vh;
  }
}
