:root {
  color-scheme: light;
  --bg: #f4f7f6;
  --panel: #ffffff;
  --ink: #17211d;
  --muted: #5f6f69;
  --line: #d8e4df;
  --green: #168455;
  --teal: #0f6c75;
  --coral: #d85d46;
  --yellow: #d9a92f;
  --dark: #16231f;
  --soft: #edf6f2;
  --shadow: 0 18px 50px rgba(18, 41, 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,
textarea,
select {
  font: inherit;
}

button {
  min-height: 42px;
  border: 0;
  border-radius: 8px;
  background: var(--green);
  color: #fff;
  padding: 0 16px;
  cursor: pointer;
  font-weight: 800;
}

button:hover:not(:disabled) {
  filter: brightness(0.96);
}

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

.hidden {
  display: none !important;
}

.secondary {
  background: #edf4f1;
  color: var(--ink);
  border: 1px solid var(--line);
}

.secondary.dark {
  background: rgba(255, 255, 255, 0.08);
  color: #eef8f3;
  border-color: rgba(255, 255, 255, 0.18);
}

.icon-button {
  width: 42px;
  padding: 0;
}

.login-shell {
  display: grid;
  grid-template-columns: minmax(320px, 480px) minmax(0, 1fr);
  min-height: 100vh;
}

.login-panel {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 26px;
  padding: 48px;
  background: #fff;
}

.login-aside {
  display: grid;
  place-items: center;
  padding: 40px;
  background:
    linear-gradient(135deg, rgba(15, 108, 117, 0.12), transparent 42%),
    #e6f2ee;
}

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

.brand-mark {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 8px;
  background: #cdeee0;
  color: #13211c;
  font-weight: 900;
}

.brand-row span {
  display: block;
  margin-top: 2px;
  color: #b9cbc4;
  font-size: 13px;
}

.login-form,
.simulate-form {
  display: grid;
  gap: 14px;
}

.form-error {
  min-height: 20px;
  margin: 0;
  color: var(--coral);
  font-weight: 800;
}

.app-shell {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 28px;
  padding: 26px;
  background: var(--dark);
  color: #eef8f3;
}

nav {
  display: grid;
  gap: 8px;
}

nav a {
  color: #d7e7df;
  text-decoration: none;
  padding: 12px 14px;
  border-radius: 8px;
}

nav a.active,
nav a:hover {
  background: rgba(205, 238, 224, 0.14);
  color: #fff;
}

.risk-note {
  margin-top: auto;
  padding: 16px;
  border-radius: 8px;
  background: rgba(216, 93, 70, 0.13);
  border: 1px solid rgba(216, 93, 70, 0.24);
}

.risk-note p {
  margin: 8px 0 0;
  color: #ffd8cf;
  line-height: 1.5;
}

.workspace {
  padding: 30px;
  min-width: 0;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 22px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  line-height: 1.08;
}

h1 {
  max-width: 760px;
  font-size: 34px;
}

h2 {
  font-size: 20px;
}

.status-pill {
  flex: 0 0 auto;
  border-radius: 999px;
  background: #fff;
  border: 1px solid var(--line);
  padding: 10px 14px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.04);
  font-weight: 900;
}

.status-pill.ok {
  color: var(--green);
}

.status-pill.bad {
  color: var(--coral);
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.metric-grid article,
.panel {
  border-radius: 8px;
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.metric-grid article {
  min-height: 116px;
  padding: 20px;
}

.metric-grid span {
  color: var(--muted);
  font-weight: 800;
}

.metric-grid strong {
  display: block;
  margin-top: 10px;
  font-size: 30px;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.panel {
  padding: 20px;
}

.panel-head,
.chat-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 18px;
}

label {
  display: grid;
  gap: 8px;
  color: #31403b;
  font-weight: 800;
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdfc;
  color: var(--ink);
  padding: 12px 13px;
  outline: none;
}

input:focus,
textarea:focus,
select:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(15, 108, 117, 0.13);
}

.toolbar,
.chat-actions,
.settings-grid {
  display: grid;
  gap: 10px;
}

.toolbar {
  grid-template-columns: minmax(0, 1fr) 160px;
  margin-bottom: 14px;
}

.conversation-list {
  display: grid;
  gap: 10px;
  max-height: 650px;
  overflow: auto;
  padding-right: 4px;
}

.conversation-item {
  display: grid;
  gap: 8px;
  width: 100%;
  min-height: 112px;
  border: 1px solid var(--line);
  background: #f8fbfa;
  color: var(--ink);
  text-align: left;
  padding: 13px;
}

.conversation-item.selected {
  border-color: var(--teal);
  background: #eef8f4;
}

.conversation-top,
.conversation-meta {
  display: flex;
  justify-content: space-between;
  gap: 10px;
}

.conversation-top small,
.conversation-meta {
  color: var(--muted);
  font-size: 13px;
}

.conversation-last {
  display: -webkit-box;
  overflow: hidden;
  color: #364640;
  font-weight: 600;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.status {
  flex: 0 0 auto;
  border-radius: 999px;
  padding: 2px 8px;
  background: #e8f2ef;
  color: var(--teal);
  font-weight: 900;
}

.status.ai_error,
.status.delivery_failed {
  background: #fdecea;
  color: var(--coral);
}

.status.operator_active {
  background: #fff6d8;
  color: #8a640e;
}

.status.done,
.status.ai_answered {
  background: #e6f5ed;
  color: var(--green);
}

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

.chat-empty {
  display: grid;
  place-content: center;
  min-height: 630px;
  text-align: center;
  color: var(--muted);
}

.chat-detail {
  display: grid;
  grid-template-rows: auto minmax(380px, 1fr) auto auto;
  min-height: 640px;
}

#chatSubtitle {
  color: var(--muted);
  font-weight: 800;
}

.messages {
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow: auto;
  max-height: 470px;
  padding: 16px;
  border-radius: 8px;
  background:
    linear-gradient(135deg, rgba(15, 108, 117, 0.06), transparent 45%),
    #edf6f2;
  border: 1px solid var(--line);
}

.message {
  max-width: 78%;
}

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

.message.ai,
.message.operator {
  align-self: flex-end;
}

.message.system {
  align-self: center;
  max-width: 92%;
}

.message-body {
  border-radius: 8px;
  padding: 11px 13px;
  background: #fff;
  border: 1px solid var(--line);
  line-height: 1.45;
  white-space: pre-wrap;
}

.message.ai .message-body {
  background: var(--green);
  color: #fff;
  border-color: var(--green);
}

.message.operator .message-body {
  background: var(--teal);
  color: #fff;
  border-color: var(--teal);
}

.message.system .message-body {
  background: #fff8df;
  color: #6a5012;
  border-color: #f0d984;
}

.message-media-list {
  display: grid;
  gap: 8px;
  margin-top: 8px;
}

.message-image {
  display: block;
  width: min(280px, 100%);
  max-height: 320px;
  object-fit: contain;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #fff;
}

.message.ai .message-image,
.message.operator .message-image {
  margin-left: auto;
}

.message-file {
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px dashed var(--line);
  background: rgba(255, 255, 255, 0.74);
  color: var(--muted);
  font-weight: 800;
}

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

.reply-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 150px;
  gap: 10px;
  margin-top: 14px;
}

.hint {
  margin: 8px 0 0;
  color: var(--muted);
  font-weight: 700;
}

.settings-panel,
.prompt-panel,
.accounts-panel,
.contacts-panel,
.billing-panel,
.spp-panel {
  margin-top: 0;
}

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

.contact-form,
.billing-form {
  display: grid;
  grid-template-columns: repeat(4, minmax(140px, 1fr)) 130px;
  gap: 10px;
  align-items: end;
}

.account-form {
  display: grid;
  grid-template-columns: repeat(4, minmax(140px, 1fr)) 120px;
  gap: 10px;
  align-items: end;
}

.accounts-list {
  display: grid;
  gap: 10px;
  margin-top: 16px;
}

.contacts-list,
.spp-list,
.contact-picker {
  display: grid;
  gap: 10px;
  margin-top: 16px;
}

.account-item,
.contact-item,
.spp-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fbfa;
  padding: 13px;
}

.contact-main {
  min-width: 0;
}

.contact-status-actions {
  display: grid;
  justify-items: end;
  gap: 8px;
  min-width: 260px;
}

.contact-picker {
  max-height: 240px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #f8fbfa;
}

.picker-row,
.checkbox-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0;
  font-weight: 800;
}

.picker-row input,
.checkbox-row input {
  width: auto;
}

.wide-field {
  grid-column: 1 / -1;
}

.billing-actions {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(2, minmax(110px, 1fr));
  gap: 8px;
}

.segmented button {
  background: #edf4f1;
  color: var(--ink);
  border: 1px solid var(--line);
}

.segmented button.active {
  background: var(--green);
  color: #fff;
  border-color: var(--green);
}

.account-item span,
.contact-item span,
.spp-item span,
.account-item small,
.contact-item small,
.spp-item small {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-weight: 800;
}

.prompt-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.settings-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin-bottom: 18px;
}

code {
  display: block;
  min-height: 45px;
  padding: 13px;
  border-radius: 8px;
  border: 1px dashed var(--teal);
  background: #eef8f4;
  color: #12342a;
  overflow-wrap: anywhere;
  font-weight: 900;
}

.simulate-form {
  grid-template-columns: minmax(180px, 0.6fr) minmax(240px, 1fr) 170px;
  align-items: end;
}

.result-box {
  overflow: auto;
  max-width: 100%;
  border-radius: 8px;
  background: #101a17;
  color: #dcf8eb;
  padding: 14px;
  line-height: 1.5;
  white-space: pre-wrap;
}

.phone-preview {
  width: min(100%, 390px);
  min-height: 360px;
  border-radius: 8px;
  padding: 22px;
  background:
    linear-gradient(135deg, rgba(15, 108, 117, 0.08), transparent 42%),
    #f8fbfa;
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.phone-preview.compact {
  min-height: 300px;
}

.phone-top {
  width: 72px;
  height: 8px;
  border-radius: 99px;
  margin: 0 auto 26px;
  background: #13211c;
  opacity: 0.2;
}

.bubble {
  max-width: 82%;
  margin-bottom: 12px;
  padding: 11px 13px;
  border-radius: 8px;
  line-height: 1.35;
  font-size: 14px;
}

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

.bubble.out {
  margin-left: auto;
  background: var(--green);
  color: #fff;
}

.empty-list {
  padding: 18px;
  border-radius: 8px;
  background: var(--soft);
  color: var(--muted);
  font-weight: 800;
}

@media (max-width: 1080px) {
  .metric-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

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

  .chat-panel {
    min-height: auto;
  }
}

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

  .login-aside {
    display: none;
  }

  .sidebar {
    position: static;
    height: auto;
  }

  nav {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  nav a {
    text-align: center;
  }

  .settings-grid,
  .simulate-form,
  .account-form,
  .contact-form,
  .billing-form,
  .billing-actions,
  .prompt-footer,
  .toolbar,
  .reply-form {
    grid-template-columns: 1fr;
  }

  .contact-item,
  .spp-item {
    display: grid;
  }

  .contact-status-actions {
    justify-items: stretch;
    min-width: 0;
  }

  .prompt-footer {
    display: grid;
  }
}

@media (max-width: 640px) {
  .workspace,
  .login-panel {
    padding: 18px;
  }

  .topbar {
    display: grid;
  }

  h1 {
    font-size: 27px;
  }

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

  .conversation-top,
  .conversation-meta {
    display: grid;
  }

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