:root {
  --bg: #f5f7f6;
  --panel: #ffffff;
  --text: #18211f;
  --muted: #66736f;
  --line: #d9e1de;
  --brand: #117d68;
  --brand-strong: #0b5d4f;
  --danger: #b42318;
  --warning: #946200;
  --ok: #197741;
  --shadow: 0 12px 24px rgba(20, 39, 34, 0.08);
}

* {
  box-sizing: border-box;
}

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

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

button {
  border: 0;
  cursor: pointer;
}

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

textarea {
  min-height: 84px;
  resize: vertical;
}

label {
  display: grid;
  gap: 6px;
  color: #2d3835;
  font-weight: 600;
}

.inline-check {
  display: flex;
  align-items: center;
  gap: 8px;
}

.inline-check input {
  width: auto;
}

.compact-label {
  display: flex;
  align-items: center;
  gap: 8px;
}

.compact-label select {
  width: auto;
  min-width: 76px;
}

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

h1 {
  margin-bottom: 10px;
  font-size: 30px;
  line-height: 1.1;
}

h2 {
  margin-bottom: 16px;
  font-size: 18px;
}

h3 {
  margin-bottom: 8px;
  font-size: 16px;
}

.hidden {
  display: none !important;
}

.muted {
  color: var(--muted);
}

.hint {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.eyebrow {
  margin-bottom: 8px;
  color: var(--brand);
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0;
  font-size: 12px;
}

.login-shell {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 24px;
}

.login-panel {
  display: grid;
  grid-template-columns: 1.1fr 0.9fr;
  gap: 36px;
  width: min(860px, 100%);
  padding: 32px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

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

.row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.primary,
.ghost,
.danger,
.small {
  border-radius: 6px;
  padding: 10px 13px;
  font-weight: 800;
}

.primary {
  background: var(--brand);
  color: #fff;
}

.primary:hover {
  background: var(--brand-strong);
}

.ghost {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
}

.danger {
  background: #fff;
  color: var(--danger);
  border: 1px solid #f0b7b1;
}

.small {
  padding: 7px 9px;
  font-size: 12px;
}

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

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

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 18px;
  align-items: center;
  padding: 12px 18px;
  border-bottom: 1px solid var(--line);
  background: rgba(245, 247, 246, 0.94);
  backdrop-filter: blur(10px);
}

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.tabs button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border-radius: 6px;
  padding: 8px 10px;
  background: transparent;
  color: var(--muted);
  font-weight: 800;
}

.tabs button.active {
  background: #e4f3ef;
  color: var(--brand-strong);
}

.count-badge {
  min-width: 22px;
  border-radius: 999px;
  padding: 2px 7px;
  background: #dfe8e5;
  color: #34423e;
  font-size: 12px;
  line-height: 1.35;
  text-align: center;
}

.tabs button.active .count-badge {
  background: #cce8df;
  color: var(--brand-strong);
}

.badge,
.status {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 3px 8px;
  font-size: 12px;
  font-weight: 800;
}

.badge {
  margin-left: 8px;
  background: #e9eeec;
  color: #34423e;
}

.tab-panel {
  padding: 18px;
}

#inboxTab {
  display: grid;
  grid-template-columns: minmax(260px, 340px) minmax(0, 1fr) 260px;
  gap: 16px;
  align-items: start;
  min-height: calc(100vh - 106px);
}

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

.filters {
  align-self: start;
  display: grid;
  gap: 12px;
  padding: 14px;
  position: sticky;
  top: 72px;
}

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

.conversation-list {
  overflow: auto;
  max-height: calc(100vh - 106px);
}

.conversation-card {
  display: grid;
  gap: 7px;
  width: 100%;
  padding: 13px;
  border-bottom: 1px solid var(--line);
  background: #fff;
  text-align: left;
}

.conversation-card:hover,
.conversation-card.active {
  background: #eff7f4;
}

.load-more {
  width: 100%;
  padding: 12px;
  border-top: 1px solid var(--line);
  background: #f7faf9;
  color: var(--brand-strong);
  font-weight: 900;
}

.load-more:hover {
  background: #e9f5f1;
}

.list-count {
  padding: 12px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}

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

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

.conversation-preview {
  overflow: hidden;
  color: var(--muted);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.meta-line {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
}

.thread {
  display: grid;
  grid-template-rows: auto 1fr auto;
  min-height: 560px;
}

.thread-head {
  display: grid;
  gap: 10px;
  padding: 14px;
  border-bottom: 1px solid var(--line);
}

.thread-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.transfer-wrap {
  position: relative;
  display: inline-flex;
}

.transfer-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  z-index: 8;
  display: grid;
  min-width: 190px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
}

.transfer-title {
  margin: 0;
  padding: 9px 11px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.transfer-option {
  width: 100%;
  padding: 10px 11px;
  border-top: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  text-align: left;
}

.transfer-option:hover {
  background: #eff7f4;
}

.appointment-field {
  min-width: 128px;
}

.messages {
  overflow: auto;
  padding: 16px;
  background: #f8faf9;
}

.message {
  width: min(78%, 620px);
  margin-bottom: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #fff;
}

.message.outbound {
  margin-left: auto;
  border-color: #badfd6;
  background: #e9f7f3;
}

.message.failed {
  border-color: #f0b7b1;
  background: #fff5f3;
}

.audio-message {
  display: grid;
  gap: 6px;
}

.audio-message audio {
  width: 100%;
  max-width: 360px;
}

.message-meta {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 12px;
}

.composer {
  display: grid;
  gap: 10px;
  padding: 14px;
  border-top: 1px solid var(--line);
}

.voice-button {
  user-select: none;
  touch-action: none;
}

.voice-button.recording {
  border-color: #f0b7b1;
  background: #fff0ee;
  color: var(--danger);
}

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

.two-column {
  display: grid;
  grid-template-columns: minmax(280px, 390px) minmax(0, 1fr);
  gap: 16px;
}

.panel {
  padding: 16px;
}

.label-title {
  margin: 0 0 8px;
  font-weight: 800;
}

.check-grid {
  display: grid;
  gap: 8px;
}

.check-grid label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
}

.check-grid input {
  width: auto;
}

.table-wrap {
  overflow: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 760px;
}

th,
td {
  padding: 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

th {
  color: #33413d;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0;
}

.status.active,
.status.sent,
.status.open {
  background: #e4f3ec;
  color: var(--ok);
}

.status.disabled,
.status.failed {
  background: #fff0ee;
  color: var(--danger);
}

.status.queued,
.status.pending,
.status.awaiting_reply,
.status.received {
  background: #fff8e5;
  color: var(--warning);
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.summary-grid div {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #f8faf9;
}

.summary-grid strong,
.summary-grid span {
  display: block;
}

.summary-grid strong {
  font-size: 20px;
}

.mixed-message {
  display: grid;
  gap: 10px;
}

.message-text {
  white-space: normal;
}

.attachment-message {
  display: grid;
  gap: 8px;
}

.attachment-message a {
  color: var(--brand);
  font-weight: 700;
}

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

.pagination-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  justify-content: flex-end;
  margin-top: 12px;
}

.stats-head {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  align-items: end;
  justify-content: space-between;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 20;
  max-width: min(420px, calc(100vw - 36px));
  padding: 12px 14px;
  border-radius: 8px;
  background: #18211f;
  color: #fff;
  box-shadow: var(--shadow);
}

.toast.error {
  background: var(--danger);
}

.legal-page {
  width: min(860px, calc(100vw - 32px));
  margin: 40px auto;
  padding: 28px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
  line-height: 1.6;
}

.legal-page h1,
.legal-page h2 {
  margin-top: 0;
}

.legal-page a {
  color: var(--brand);
  font-weight: 700;
}

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

  #inboxTab,
  .two-column {
    grid-template-columns: 1fr;
  }

  .filters {
    position: static;
  }

  .thread {
    min-height: 520px;
  }
}

@media (max-width: 680px) {
  .login-panel {
    grid-template-columns: 1fr;
    padding: 22px;
  }

  .tab-panel,
  #inboxTab {
    padding: 10px;
  }

  .message {
    width: 100%;
  }
}
