:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --panel: #ffffff;
  --panel-2: #eef2f5;
  --text: #172026;
  --muted: #66727d;
  --line: #d8e0e7;
  --accent: #16735f;
  --accent-2: #0f5b4b;
  --danger: #b42318;
  --warning: #a15c00;
  --shadow: 0 18px 50px rgba(17, 30, 40, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.4 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

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

button {
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  padding: 10px 14px;
  cursor: pointer;
  font-weight: 700;
}

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

button.secondary {
  background: var(--panel-2);
  color: var(--text);
}

button.secondary:hover {
  background: #dde6ed;
}

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

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

textarea {
  resize: none;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.shell {
  display: grid;
  grid-template-columns: 360px 1fr;
  min-height: 100vh;
}

.sidebar {
  border-right: 1px solid var(--line);
  background: var(--panel);
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.brand {
  min-height: 72px;
  padding: 16px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.brand strong,
.brand span {
  display: block;
}

.brand span {
  color: var(--muted);
  font-size: 13px;
  margin-top: 2px;
}

.icon-button {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  padding: 0;
  background: var(--panel-2);
  color: var(--text);
}

.panel,
.auth-panel {
  padding: 16px;
}

.auth-panel {
  display: grid;
  gap: 14px;
}

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

.inbox-panel {
  min-height: 0;
  display: flex;
  flex: 1;
  flex-direction: column;
}

.filters {
  padding: 14px;
  border-bottom: 1px solid var(--line);
  display: grid;
  grid-template-columns: 1fr 118px;
  gap: 10px;
}

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

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

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

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

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

.conversation-time,
.conversation-preview,
.conversation-phone {
  color: var(--muted);
  font-size: 13px;
}

.conversation-preview {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.workspace {
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.empty-state {
  margin: auto;
  max-width: 460px;
  text-align: center;
  color: var(--muted);
  padding: 32px;
}

.empty-state h1 {
  color: var(--text);
  margin-bottom: 8px;
}

.chat-panel {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr auto;
}

.chat-header {
  min-height: 72px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
}

.chat-header h1 {
  margin: 0;
  font-size: 19px;
}

.chat-header p {
  margin: 3px 0 0;
  color: var(--muted);
}

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

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  border-radius: 999px;
  padding: 6px 10px;
  background: #e9f7f3;
  color: var(--accent-2);
  font-weight: 800;
  font-size: 13px;
}

.badge.human {
  background: #fff3df;
  color: var(--warning);
}

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

.message {
  max-width: min(680px, 78%);
  display: grid;
  gap: 5px;
}

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

.message.outbound {
  align-self: flex-end;
}

.bubble {
  border-radius: 8px;
  padding: 10px 12px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  box-shadow: 0 1px 0 rgba(17, 30, 40, 0.04);
}

.inbound .bubble {
  background: #fff;
  border: 1px solid var(--line);
}

.outbound .bubble {
  background: #dff4ec;
  border: 1px solid #bbe5d6;
}

.message-meta {
  color: var(--muted);
  font-size: 12px;
  padding: 0 3px;
}

.outbound .message-meta {
  text-align: right;
}

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

dialog {
  border: 0;
  border-radius: 8px;
  box-shadow: var(--shadow);
  width: min(560px, calc(100vw - 28px));
}

dialog::backdrop {
  background: rgba(12, 22, 30, 0.36);
}

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

.settings h2 {
  margin: 0 0 4px;
}

.settings menu {
  padding: 0;
  margin: 4px 0 0;
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%);
  background: #172026;
  color: #fff;
  padding: 10px 14px;
  border-radius: 8px;
  box-shadow: var(--shadow);
  z-index: 10;
}

.hidden {
  display: none !important;
}

@media (max-width: 820px) {
  .shell {
    grid-template-columns: 1fr;
  }

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

  .chat-panel {
    min-height: 58vh;
  }

  .message {
    max-width: 92%;
  }

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