:root {
  color-scheme: light;
  --bg: #f4f2ee;
  --panel: #fffefb;
  --ink: #18201f;
  --muted: #66706d;
  --line: #ddd8cf;
  --accent: #0f766e;
  --accent-dark: #115e59;
  --amber: #b7791f;
  --rose: #be123c;
  --shadow: 0 18px 50px rgba(29, 35, 33, 0.1);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

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

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 22px;
  border-right: 1px solid var(--line);
  background: #e9e4da;
  padding: 24px;
}

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

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

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

.brand span,
.field span,
.snippet span,
.metrics span,
.conversation small,
.chat-header p,
.topbar p {
  color: var(--muted);
  font-size: 0.88rem;
}

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

.field input,
.field select,
.composer input {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  color: var(--ink);
  padding: 0 12px;
  outline: none;
}

.field input:focus,
.field select:focus,
.composer input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.14);
}

.primary,
.composer button,
.snippet button {
  min-height: 42px;
  border-radius: 8px;
  background: var(--accent);
  color: white;
  font-weight: 700;
  padding: 0 14px;
}

.primary:hover,
.composer button:hover,
.snippet button:hover {
  background: var(--accent-dark);
}

.snippet {
  display: grid;
  gap: 10px;
  margin-top: auto;
}

.snippet code {
  display: block;
  overflow: auto;
  min-height: 98px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffefb;
  color: #243230;
  padding: 12px;
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 0.78rem;
  line-height: 1.5;
  white-space: pre-wrap;
}

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

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
  padding: 24px 30px;
}

.topbar h1 {
  margin: 0 0 6px;
  font-size: 1.75rem;
  line-height: 1.1;
}

.topbar p {
  margin: 0;
}

.metrics {
  display: flex;
  gap: 12px;
}

.metrics div {
  min-width: 86px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #faf8f2;
  padding: 10px 12px;
}

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

.inbox {
  display: grid;
  grid-template-columns: minmax(280px, 390px) 1fr;
  min-height: 0;
}

.conversation-list {
  overflow: auto;
  border-right: 1px solid var(--line);
  background: #fbfaf6;
  padding: 14px;
}

.conversation {
  display: grid;
  gap: 8px;
  width: 100%;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  padding: 14px;
  text-align: left;
}

.conversation:hover,
.conversation.active {
  border-color: var(--line);
  background: white;
}

.conversation.active {
  box-shadow: var(--shadow);
}

.conversation strong,
.conversation span,
.conversation small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

.badge {
  min-width: 24px;
  border-radius: 999px;
  background: var(--rose);
  color: white;
  font-size: 0.75rem;
  font-weight: 700;
  padding: 3px 8px;
  text-align: center;
}

.chat-panel {
  display: grid;
  grid-template-rows: auto 1fr auto;
  min-width: 0;
  min-height: 0;
  background: var(--panel);
}

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

.chat-header h2,
.chat-header p {
  margin: 0;
}

.chat-header h2 {
  margin-bottom: 4px;
  font-size: 1.08rem;
}

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

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

.message {
  max-width: min(620px, 78%);
  border-radius: 8px;
  padding: 12px 14px;
  line-height: 1.45;
}

.message.visitor {
  align-self: flex-start;
  background: #ece7dd;
}

.message.agent {
  align-self: flex-end;
  background: #d7efe9;
}

.message time {
  display: block;
  margin-top: 6px;
  color: var(--muted);
  font-size: 0.76rem;
}

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

.composer:has(input:disabled) {
  opacity: 0.56;
}

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

dialog::backdrop {
  background: rgba(24, 32, 31, 0.34);
}

.dialog-card {
  display: grid;
  gap: 16px;
  padding: 22px;
}

.dialog-card h2 {
  margin: 0;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.dialog-actions button:not(.primary) {
  min-height: 42px;
  border-radius: 8px;
  background: #ebe6dc;
  color: var(--ink);
  padding: 0 14px;
}

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

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

  .snippet {
    margin-top: 0;
  }

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

  .conversation-list {
    max-height: 320px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .chat-panel {
    min-height: 560px;
  }
}
