:root {
  --bg: #f4f6f5;
  --panel: #ffffff;
  --panel-soft: #eef4f1;
  --line: #d9e1dc;
  --text: #17201c;
  --muted: #66756e;
  --green: #128c5a;
  --green-dark: #0c6a43;
  --amber: #b96f00;
  --red: #bb3030;
  --bubble: #dcf8c6;
  --incoming: #ffffff;
  --shadow: 0 18px 48px rgba(17, 32, 25, 0.12);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
}

.is-hidden {
  display: none !important;
}

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

button {
  min-height: 38px;
  border: 0;
  border-radius: 7px;
  background: var(--green);
  color: #fff;
  cursor: pointer;
}

button:hover {
  background: var(--green-dark);
}

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

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

input,
select {
  min-height: 38px;
  padding: 0 10px;
}

textarea {
  resize: none;
  padding: 11px 12px;
  line-height: 1.45;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(18, 140, 90, 0.14);
}

.app-shell {
  display: grid;
  grid-template-columns: 300px minmax(420px, 1fr) 620px;
  height: 100vh;
  overflow: hidden;
}

.login-screen {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(rgba(244, 246, 245, 0.92), rgba(244, 246, 245, 0.92)),
    repeating-linear-gradient(135deg, rgba(18, 140, 90, 0.08) 0 1px, transparent 1px 22px);
}

.login-box {
  display: grid;
  width: min(420px, 100%);
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  padding: 22px;
}

.login-box .brand-row {
  margin-bottom: 8px;
}

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

.sidebar,
.reply-pane,
.chat-pane {
  min-width: 0;
  min-height: 0;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 18px;
  border-right: 1px solid var(--line);
  background: var(--panel);
  padding: 18px;
  overflow: auto;
}

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

.brand-logo {
  width: 92px;
  height: 42px;
  object-fit: contain;
  object-position: left center;
  flex: 0 0 auto;
}

.brand-row h1,
.chat-header h2,
.reply-header h2,
.section-title h2,
.dialog-form h2 {
  margin: 0;
  letter-spacing: 0;
}

.brand-row h1 {
  font-size: 18px;
}

.brand-row span,
.chat-header span,
.reply-header span,
.active-meta {
  color: var(--muted);
  font-size: 13px;
}

.panel-block {
  display: grid;
  gap: 10px;
}

.user-panel {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 58px;
  align-items: center;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--panel-soft);
  padding: 9px;
}

.user-panel strong,
.user-panel span {
  display: block;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-panel span {
  color: var(--muted);
  font-size: 12px;
}

.user-panel button {
  min-height: 32px;
  background: #24342d;
  font-size: 13px;
  padding: 0;
}

.live-panel {
  display: grid;
  gap: 7px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  padding: 9px;
}

.live-panel div {
  display: grid;
  grid-template-columns: 76px minmax(0, 1fr);
  gap: 8px;
  align-items: center;
}

.live-panel span {
  color: var(--muted);
  font-size: 12px;
}

.live-panel strong {
  min-width: 0;
  overflow: hidden;
  color: var(--text);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.view-tabs {
  display: grid;
  grid-template-columns: 1fr;
  gap: 7px;
}

.view-tabs button {
  min-height: 36px;
  background: #e8eeeb;
  color: var(--text);
  text-align: left;
  padding: 0 10px;
}

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

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

.section-title h2 {
  font-size: 13px;
  color: var(--muted);
  text-transform: uppercase;
}

.icon-button {
  display: grid;
  width: 32px;
  min-height: 32px;
  place-items: center;
  padding: 0;
  font-size: 21px;
}

.stack-list,
.contact-list {
  display: grid;
  gap: 6px;
}

.list-button,
.contact-row,
.member-row {
  display: grid;
  align-items: center;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
}

.list-button {
  grid-template-columns: 1fr auto;
  width: 100%;
  padding: 8px 10px;
  color: var(--text);
  text-align: left;
}

.list-button:hover,
.list-button.active {
  border-color: rgba(18, 140, 90, 0.42);
  background: var(--panel-soft);
  color: var(--text);
}

.list-title,
.contact-name {
  overflow: hidden;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.list-count,
.contact-phone {
  color: var(--muted);
  font-size: 12px;
}

.compact-form {
  display: grid;
  grid-template-columns: 1fr;
  gap: 7px;
}

.contact-row {
  grid-template-columns: 1fr 30px;
  gap: 8px;
  padding: 8px 8px 8px 10px;
}

.delete-button {
  display: grid;
  width: 28px;
  min-height: 28px;
  place-items: center;
  padding: 0;
  background: transparent;
  color: var(--red);
}

.delete-button:hover {
  background: rgba(187, 48, 48, 0.1);
}

.chat-pane {
  display: grid;
  grid-template-rows: auto 1fr auto;
  background:
    linear-gradient(rgba(245, 247, 246, 0.85), rgba(245, 247, 246, 0.85)),
    repeating-linear-gradient(135deg, rgba(18, 140, 90, 0.08) 0 1px, transparent 1px 22px);
}

.chat-header,
.reply-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 70px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.92);
  padding: 14px 18px;
}

.chat-header h2,
.reply-header h2 {
  font-size: 18px;
}

.chat-header button {
  width: 82px;
  background: #24342d;
}

.chat-header button:hover {
  background: #17201c;
}

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

.bubble-row {
  display: flex;
}

.bubble-row.out {
  justify-content: flex-end;
}

.bubble-row.in {
  justify-content: flex-start;
}

.bubble {
  max-width: min(620px, 82%);
  border: 1px solid rgba(0, 0, 0, 0.04);
  border-radius: 8px;
  box-shadow: 0 2px 12px rgba(21, 32, 27, 0.06);
  padding: 10px 12px;
}

.bubble.out {
  background: var(--bubble);
}

.bubble.in {
  background: var(--incoming);
}

.bubble strong {
  display: block;
  margin-bottom: 4px;
  font-size: 12px;
  color: var(--green-dark);
}

.bubble p {
  margin: 0;
  overflow-wrap: anywhere;
  line-height: 1.45;
  white-space: pre-wrap;
}

.delivery-line {
  display: block;
  margin-top: 8px;
  border-radius: 7px;
  padding: 7px 8px;
  background: rgba(102, 117, 110, 0.12);
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.delivery-line.sent {
  background: rgba(18, 140, 90, 0.12);
  color: var(--green-dark);
}

.delivery-line.partial {
  background: rgba(185, 111, 0, 0.12);
  color: var(--amber);
}

.delivery-line.failed {
  background: rgba(187, 48, 48, 0.12);
  color: var(--red);
}

.bubble time {
  display: block;
  margin-top: 6px;
  color: var(--muted);
  font-size: 11px;
  text-align: right;
}

.composer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 118px;
  gap: 10px;
  border-top: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.92);
  padding: 14px;
}

.composer button {
  align-self: stretch;
}

.reply-pane {
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  border-left: 1px solid var(--line);
  background: var(--panel);
}

.admin-pane {
  display: grid;
  grid-column: 2 / -1;
  grid-template-rows: auto 1fr;
  min-width: 0;
  min-height: 0;
  background: var(--panel);
}

.admin-header {
  display: flex;
  align-items: center;
  min-height: 70px;
  border-bottom: 1px solid var(--line);
  padding: 14px 18px;
}

.admin-header h2,
.admin-form h3 {
  margin: 0;
  letter-spacing: 0;
}

.admin-header h2 {
  font-size: 18px;
}

.admin-header span {
  color: var(--muted);
  font-size: 13px;
}

.admin-layout {
  display: grid;
  grid-template-columns: 340px minmax(0, 1fr);
  gap: 16px;
  overflow: auto;
  padding: 18px;
}

.admin-card {
  align-self: start;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 14px;
}

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

.admin-form h3 {
  font-size: 17px;
}

.admin-form label {
  display: grid;
  gap: 6px;
}

.admin-form label span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.admin-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.admin-actions button:first-child {
  background: #e8eeeb;
  color: var(--text);
}

.users-card {
  display: grid;
  gap: 12px;
}

.admin-users {
  display: grid;
  gap: 8px;
}

.admin-user-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 92px 140px;
  gap: 10px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 10px;
}

.admin-user-row strong,
.admin-user-row span {
  display: block;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.admin-user-row span {
  color: var(--muted);
  font-size: 12px;
}

.role-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 0 9px;
  background: rgba(18, 140, 90, 0.12);
  color: var(--green-dark);
  font-size: 12px;
  font-weight: 800;
}

.role-pill.user {
  background: rgba(102, 117, 110, 0.14);
  color: #4e5d56;
}

.admin-row-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px;
}

.admin-row-actions button {
  min-height: 32px;
  font-size: 13px;
  padding: 0;
}

.admin-row-actions button:first-child {
  background: #24342d;
}

.admin-row-actions button:last-child {
  background: transparent;
  color: var(--red);
}

.admin-row-actions button:last-child:hover {
  background: rgba(187, 48, 48, 0.1);
}

.reply-header select {
  max-width: 190px;
}

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

.checkbox-grid {
  display: grid;
  max-height: 132px;
  gap: 6px;
  overflow: auto;
}

.member-row {
  grid-template-columns: 18px 1fr;
  gap: 8px;
  padding: 7px 9px;
}

.member-row input {
  width: 16px;
  min-height: 16px;
  accent-color: var(--green);
}

.member-row span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.table-wrap {
  overflow: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 650px;
  table-layout: fixed;
}

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

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #f9fbfa;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

td {
  font-size: 14px;
}

th:nth-child(1),
td:nth-child(1) {
  width: 140px;
}

th:nth-child(2),
td:nth-child(2) {
  width: 180px;
}

th:nth-child(3),
td:nth-child(3) {
  width: 230px;
}

th:nth-child(4),
td:nth-child(4) {
  width: 88px;
}

th:nth-child(5),
td:nth-child(5) {
  width: 105px;
}

.answer-text {
  overflow-wrap: anywhere;
}

.message-cell {
  overflow-wrap: anywhere;
  color: #304139;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 0 9px;
  background: rgba(18, 140, 90, 0.12);
  color: var(--green-dark);
  font-size: 12px;
  font-weight: 700;
}

.status-pill.waiting {
  background: rgba(185, 111, 0, 0.12);
  color: var(--amber);
}

.simulate-form {
  display: grid;
  grid-template-columns: 140px 1fr 92px;
  gap: 8px;
  border-top: 1px solid var(--line);
  padding: 12px;
}

dialog {
  width: min(420px, calc(100vw - 32px));
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

dialog::backdrop {
  background: rgba(18, 32, 26, 0.36);
}

.dialog-form {
  display: grid;
  gap: 14px;
}

.dialog-form h2 {
  font-size: 18px;
}

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

.dialog-actions button:first-child {
  background: #e8eeeb;
  color: var(--text);
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  transform: translateY(20px);
  max-width: 360px;
  border-radius: 8px;
  background: #17201c;
  color: #fff;
  opacity: 0;
  padding: 12px 14px;
  pointer-events: none;
  transition: opacity 160ms ease, transform 160ms ease;
}

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

.empty-state {
  color: var(--muted);
  padding: 14px 0;
}

@media (max-width: 1360px) {
  .app-shell {
    grid-template-columns: 280px minmax(360px, 1fr);
  }

  .reply-pane {
    grid-column: 1 / -1;
    height: 44vh;
    border-top: 1px solid var(--line);
    border-left: 0;
  }

  .admin-pane {
    grid-column: 1 / -1;
  }
}

@media (max-width: 760px) {
  .app-shell {
    display: flex;
    min-height: 100vh;
    height: auto;
    flex-direction: column;
    overflow: visible;
  }

  .sidebar,
  .chat-pane,
  .reply-pane {
    width: 100%;
    height: auto;
    max-height: none;
    border: 0;
  }

  .conversation {
    min-height: 430px;
  }

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

  .chat-header,
  .reply-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .reply-header select {
    max-width: none;
  }

  .admin-layout {
    grid-template-columns: 1fr;
  }

  .admin-user-row {
    grid-template-columns: 1fr;
  }
}
