:root {
  color-scheme: light;
  --bg: #f5f7f8;
  --surface: #ffffff;
  --surface-muted: #eef3f1;
  --text: #17201c;
  --muted: #65726c;
  --line: #dbe3df;
  --accent: #0b6b57;
  --accent-2: #0b5e83;
  --warning: #a95d00;
  --danger: #a33131;
  --shadow: 0 18px 45px rgba(28, 41, 35, 0.1);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background:
    linear-gradient(180deg, rgba(11, 107, 87, 0.07), transparent 340px),
    var(--bg);
  color: var(--text);
}

button,
input,
textarea {
  font: inherit;
}

.app-shell {
  min-height: 100vh;
  padding: 24px;
}

.topbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
  max-width: 1440px;
  margin: 0 auto 20px;
}

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

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

h1 {
  margin-bottom: 0;
  font-size: 32px;
  line-height: 1.15;
}

h2 {
  margin-bottom: 0;
  font-size: 22px;
}

.topbar-actions,
.sms-controls,
.section-actions,
.modal-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.topbar-actions {
  align-items: end;
  flex-wrap: wrap;
}

.api-field {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.api-field input,
.search-input,
.form-field input,
.form-field textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  outline: none;
}

.api-field input {
  width: min(360px, 42vw);
  padding: 10px 12px;
}

.token-field input {
  width: min(220px, 28vw);
}

.search-input {
  min-width: 240px;
  padding: 11px 12px;
}

.api-field input:focus,
.search-input:focus,
.form-field input:focus,
.form-field textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(11, 107, 87, 0.12);
}

.icon-button,
.text-button {
  border: 1px solid transparent;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  font-weight: 700;
}

.icon-button {
  width: 44px;
  height: 44px;
  font-size: 22px;
}

.text-button {
  min-height: 42px;
  padding: 0 16px;
}

.text-button.secondary {
  background: var(--surface-muted);
  color: var(--text);
}

.text-button.danger {
  background: var(--danger);
}

.text-button:disabled,
.icon-button:disabled {
  cursor: wait;
  opacity: 0.7;
}

.dashboard {
  display: grid;
  grid-template-columns: minmax(320px, 430px) minmax(0, 1fr);
  gap: 18px;
  max-width: 1440px;
  margin: 0 auto;
}

.settings-band {
  display: grid;
  grid-template-columns: auto minmax(280px, 1fr) minmax(190px, 260px) 84px auto minmax(120px, auto);
  align-items: center;
  gap: 10px;
  max-width: 1440px;
  margin: 0 auto 18px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.78);
}

.settings-check {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
  font-size: 13px;
  font-weight: 800;
  white-space: nowrap;
}

.settings-input {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  outline: none;
  padding: 10px 12px;
}

.settings-input.small {
  text-align: center;
}

.settings-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(11, 107, 87, 0.12);
}

.settings-status {
  min-width: 0;
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.panel {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.9);
  box-shadow: var(--shadow);
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px;
  border-bottom: 1px solid var(--line);
}

.count-pill {
  min-width: 34px;
  padding: 5px 10px;
  border-radius: 999px;
  background: var(--surface-muted);
  color: var(--accent);
  text-align: center;
  font-weight: 800;
}

.status-strip {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
  background: #fbfcfc;
}

.status-item {
  min-width: 0;
}

.status-label {
  margin-bottom: 3px;
  color: var(--muted);
  font-size: 12px;
}

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

.status-item.wide {
  grid-column: 1 / -1;
}

.status-value.wrap {
  overflow: visible;
  line-height: 1.45;
  text-overflow: clip;
  white-space: normal;
  word-break: break-word;
}

.profiles-list {
  display: grid;
  gap: 10px;
  padding: 14px;
}

.profiles-list .empty-state {
  min-height: 210px;
}

.profile-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 14px;
}

.profile-card.active {
  border-color: rgba(11, 107, 87, 0.45);
  background: #f3faf7;
}

.profile-main {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.profile-name {
  margin-bottom: 4px;
  font-size: 17px;
  font-weight: 850;
}

.profile-meta {
  display: grid;
  gap: 4px;
  margin: 10px 0 14px;
  color: var(--muted);
  font-size: 13px;
}

.state-badge {
  align-self: start;
  flex: 0 0 auto;
  border-radius: 999px;
  padding: 5px 9px;
  background: var(--surface-muted);
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.state-badge.active {
  background: rgba(11, 107, 87, 0.12);
  color: var(--accent);
}

.profile-actions {
  display: flex;
  gap: 8px;
}

.profile-actions .text-button {
  flex: 1;
}

.profile-actions .secondary {
  border-color: var(--line);
}

.sms-panel {
  overflow: hidden;
}

.sms-layout {
  display: grid;
  grid-template-columns: minmax(260px, 330px) minmax(0, 1fr);
  min-height: 640px;
}

.conversation-list {
  border-right: 1px solid var(--line);
  background: #fbfcfc;
}

.conversation-item {
  width: 100%;
  min-height: 78px;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: transparent;
  color: var(--text);
  cursor: pointer;
  padding: 13px 14px;
  text-align: left;
}

.conversation-item.active {
  background: #e8f3ef;
}

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

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

.conversation-time {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 12px;
}

.conversation-preview {
  display: -webkit-box;
  overflow: hidden;
  margin-top: 5px;
  color: var(--muted);
  font-size: 13px;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.message-stream {
  overflow: auto;
  padding: 18px;
  background:
    linear-gradient(180deg, rgba(11, 94, 131, 0.06), transparent 240px),
    var(--surface);
}

.message-day {
  margin: 2px 0 14px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-align: center;
}

.message-bubble {
  width: fit-content;
  max-width: min(720px, 82%);
  margin-bottom: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f7faf9;
  padding: 11px 13px;
}

.message-bubble.sent {
  margin-left: auto;
  border-color: rgba(11, 94, 131, 0.24);
  background: #eef7fa;
}

.message-body {
  margin-bottom: 6px;
  line-height: 1.55;
  white-space: pre-wrap;
}

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

.empty-state {
  display: grid;
  min-height: 260px;
  place-items: center;
  color: var(--muted);
  text-align: center;
}

.modal {
  width: min(480px, calc(100vw - 34px));
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.modal::backdrop {
  background: rgba(23, 32, 28, 0.42);
}

.form-field {
  display: grid;
  gap: 6px;
  margin-bottom: 13px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.form-field input,
.form-field textarea {
  padding: 11px 12px;
  resize: vertical;
}

.modal-actions {
  justify-content: flex-end;
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  min-width: 260px;
  max-width: min(420px, calc(100vw - 40px));
  transform: translateY(18px);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--text);
  color: #fff;
  opacity: 0;
  padding: 12px 14px;
  pointer-events: none;
  transition:
    opacity 160ms ease,
    transform 160ms ease;
}

.toast.visible {
  transform: translateY(0);
  opacity: 1;
}

@media (max-width: 980px) {
  .app-shell {
    padding: 16px;
  }

  .topbar,
  .dashboard,
  .settings-band,
  .sms-layout {
    grid-template-columns: 1fr;
  }

  .topbar {
    display: grid;
    align-items: start;
  }

  .topbar-actions,
  .sms-head,
  .sms-controls {
    align-items: stretch;
    flex-direction: column;
  }

  .api-field input,
  .token-field input,
  .search-input {
    width: 100%;
    min-width: 0;
  }

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

  .sms-layout {
    min-height: 0;
  }

  .message-stream {
    min-height: 460px;
  }
}

@media (max-width: 560px) {
  h1 {
    font-size: 26px;
  }

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

  .status-strip {
    grid-template-columns: 1fr;
  }

  .message-bubble {
    max-width: 100%;
  }
}
