:root {
  --bg-app: #0b141a;
  --bg-panel: #111b21;
  --bg-header: #202c33;
  --bg-search: #202c33;
  --bg-hover: #2a3942;
  --bg-active: #2a3942;
  --bg-chat: #0b141a;
  --inbound: #202c33;
  --outbound: #005c4b;
  --text: #e9edef;
  --muted: #8696a0;
  --accent: #00a884;
  --border: #222d34;
  --shadow: 0 1px 0.5px rgba(0, 0, 0, 0.13);
  --radius-bubble: 8px;
  font-family: "Segoe UI", "Helvetica Neue", Helvetica, Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  background: #0a1014;
  color: var(--text);
}

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

.app {
  display: grid;
  grid-template-columns: 30% 70%;
  height: 100%;
  max-width: 1600px;
  margin: 0 auto;
  background: var(--bg-app);
  box-shadow: 0 0 0 1px #000;
}

.sidebar {
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--bg-panel);
  border-right: 1px solid var(--border);
}

.sidebar-header,
.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  background: var(--bg-header);
  min-height: 60px;
}

.brand,
.chat-title {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand strong,
.chat-title strong {
  display: block;
  font-size: 16px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: #6a7175;
  display: grid;
  place-items: center;
  font-weight: 600;
  font-size: 15px;
  flex: 0 0 auto;
  color: #fff;
  text-transform: uppercase;
}

.brand-avatar {
  background: linear-gradient(145deg, #25d366, #128c7e);
  color: #062018;
}

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

.small {
  font-size: 13px;
  line-height: 1.3;
}

.icon-btn {
  border: 0;
  background: transparent;
  color: var(--muted);
  width: 40px;
  height: 40px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 18px;
}

.icon-btn:hover {
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
}

.sidebar-actions {
  display: flex;
  gap: 2px;
}

.search-wrap {
  padding: 8px 12px;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
}

.search-wrap input {
  width: 100%;
  border: 0;
  border-radius: 8px;
  background: var(--bg-search);
  padding: 9px 14px 9px 40px;
  outline: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='%238696a0' viewBox='0 0 16 16'%3E%3Cpath d='M11.742 10.344a6.5 6.5 0 1 0-1.397 1.398h-.001l3.85 3.85a1 1 0 0 0 1.415-1.414l-3.85-3.85zm-5.242.656a5 5 0 1 1 0-10 5 5 0 0 1 0 10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: 14px center;
}

.thread-list {
  overflow: auto;
  flex: 1;
}

.thread {
  display: grid;
  grid-template-columns: 49px 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 12px 14px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
}

.thread:hover {
  background: rgba(255, 255, 255, 0.03);
}

.thread.active {
  background: var(--bg-active);
}

.thread .name {
  font-weight: 500;
  font-size: 16px;
  margin-bottom: 3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.thread .snippet {
  color: var(--muted);
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.thread .meta {
  text-align: right;
  font-size: 12px;
  color: var(--muted);
  align-self: start;
  padding-top: 2px;
}

.badge {
  display: inline-grid;
  place-items: center;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--accent);
  color: #111b21;
  font-size: 12px;
  font-weight: 700;
  margin-top: 8px;
}

.chat {
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--bg-chat);
}

.messages {
  flex: 1;
  overflow: auto;
  padding: 12px 7% 20px;
  background-color: #0b141a;
  background-image: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23ffffff' fill-opacity='0.025'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
}

.empty-state {
  margin: 18vh auto 0;
  text-align: center;
  color: var(--muted);
  max-width: 360px;
  line-height: 1.5;
}

.day-sep {
  display: flex;
  justify-content: center;
  margin: 12px 0 10px;
}

.day-sep span {
  background: #182229;
  color: var(--muted);
  font-size: 12.5px;
  padding: 5px 12px 6px;
  border-radius: 7px;
  box-shadow: var(--shadow);
  text-transform: capitalize;
}

.bubble-row {
  display: flex;
  margin: 2px 0;
  align-items: flex-end;
}

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

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

.bubble {
  display: inline-block;
  width: fit-content;
  max-width: min(65%, 560px);
  padding: 6px 7px 4px 9px;
  border-radius: var(--radius-bubble);
  box-shadow: var(--shadow);
  position: relative;
  vertical-align: top;
}

.inbound .bubble {
  background: var(--inbound);
  border-top-left-radius: 0;
}

.outbound .bubble {
  background: var(--outbound);
  border-top-right-radius: 0;
}

.bubble-body {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 0 8px;
}

.bubble .caption {
  margin: 0;
  font-size: 14.5px;
  line-height: 1.35;
  white-space: pre-wrap;
  word-break: break-word;
  max-width: 100%;
}

.bubble .time {
  margin-left: auto;
  padding: 4px 0 0 8px;
  font-size: 11px;
  line-height: 1;
  color: rgba(233, 237, 239, 0.65);
  white-space: nowrap;
  align-self: flex-end;
}

.bubble img.media {
  display: block;
  max-width: min(280px, 62vw);
  max-height: 320px;
  border-radius: 6px;
  margin-bottom: 4px;
}

.bubble audio {
  width: min(260px, 62vw);
  margin-bottom: 2px;
}

.bubble video {
  display: block;
  max-width: min(280px, 62vw);
  border-radius: 6px;
  margin-bottom: 4px;
}

.composer {
  display: grid;
  grid-template-columns: 1fr 48px;
  gap: 10px;
  align-items: center;
  padding: 10px 16px;
  background: var(--bg-header);
}

.composer textarea {
  resize: none;
  border: 0;
  border-radius: 8px;
  background: #2a3942;
  padding: 11px 14px;
  min-height: 44px;
  max-height: 120px;
  outline: none;
  line-height: 1.35;
}

.composer textarea:disabled {
  opacity: 0.55;
}

.send-btn {
  width: 48px;
  height: 48px;
  border: 0;
  border-radius: 50%;
  background: var(--accent);
  color: #111b21;
  font-weight: 700;
  font-size: 13px;
  cursor: pointer;
  padding: 0;
}

.send-btn:disabled {
  opacity: 0.4;
  cursor: default;
}

@media (max-width: 900px) {
  .app {
    grid-template-columns: 1fr;
  }
  .sidebar {
    display: none;
  }
  .app.show-list .sidebar {
    display: flex;
  }
  .app.show-list .chat {
    display: none;
  }
  .bubble {
    max-width: 85%;
  }
}

.login-body {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(circle at top, rgba(0, 168, 132, 0.16), transparent 42%),
    #0a1014;
}

.login-card {
  width: min(420px, 100%);
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 28px 24px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.35);
}

.login-brand {
  margin-bottom: 22px;
}

.login-label {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 13px;
}

.login-card input[type='password'] {
  width: 100%;
  border: 0;
  border-radius: 8px;
  background: var(--bg-header);
  padding: 12px 14px;
  outline: none;
  margin-bottom: 14px;
}

.login-submit {
  width: 100%;
  height: 44px;
  border-radius: 8px !important;
}

.login-error {
  color: #ff8a80;
  margin: 12px 0 0;
  font-size: 13px;
}

.login-note {
  margin: 14px 0 0;
}

.hidden {
  display: none !important;
}

.nav-tabs {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-panel);
}

.nav-tab {
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 8px 4px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
}

.nav-tab:hover {
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
}

.nav-tab.active {
  background: rgba(0, 168, 132, 0.16);
  color: var(--accent);
}

.side-view {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

.panel-toolbar {
  display: flex;
  gap: 8px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  align-items: center;
}

.panel-toolbar select {
  flex: 1;
  border: 0;
  border-radius: 8px;
  background: var(--bg-search);
  padding: 8px 10px;
  outline: none;
}

.pill-btn,
.primary-btn,
.ghost-btn {
  border: 0;
  border-radius: 8px;
  cursor: pointer;
  padding: 8px 12px;
  font-weight: 600;
  font-size: 13px;
}

.pill-btn,
.primary-btn {
  background: var(--accent);
  color: #111b21;
  white-space: nowrap;
}

.ghost-btn {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
}

.ghost-btn.danger {
  color: #ff8a80;
  border-color: rgba(255, 138, 128, 0.35);
}

.side-form {
  padding: 14px 16px;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.side-form label,
.modal-form label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
}

.side-form input,
.side-form textarea,
.side-form select,
.modal-form input,
.modal-form textarea,
.modal-form select {
  border: 0;
  border-radius: 8px;
  background: var(--bg-search);
  padding: 10px 12px;
  outline: none;
  color: var(--text);
}

.check-row {
  flex-direction: row !important;
  align-items: center;
  gap: 8px !important;
  color: var(--text) !important;
  font-size: 13px !important;
}

.section-label {
  padding: 10px 16px 4px;
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.detail-panel {
  flex: 1;
  overflow: auto;
  padding: 24px 7%;
}

.detail-card {
  max-width: 560px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
}

.detail-card h2 {
  margin: 0 0 4px;
  font-size: 22px;
  font-weight: 600;
}

.detail-grid {
  display: grid;
  grid-template-columns: 120px 1fr;
  gap: 8px 12px;
  margin: 18px 0;
}

.detail-grid dt {
  color: var(--muted);
  font-size: 13px;
}

.detail-grid dd {
  margin: 0;
  font-size: 14px;
}

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

.template-body {
  white-space: pre-wrap;
  background: #0b141a;
  border-radius: 8px;
  padding: 12px;
  font-family: inherit;
  font-size: 14px;
  line-height: 1.4;
  color: var(--text);
}

.modal {
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg-panel);
  color: var(--text);
  padding: 0;
  width: min(480px, calc(100vw - 32px));
}

.modal::backdrop {
  background: rgba(0, 0, 0, 0.55);
}

.modal-form {
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.modal-form h3 {
  margin: 0;
}

.modal-form fieldset {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
}

.modal-form legend {
  padding: 0 6px;
  color: var(--muted);
  font-size: 12px;
}

.chip-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid color-mix(in srgb, var(--chip, #8696a0) 45%, transparent);
  background: transparent;
  font-size: 12px;
  cursor: pointer;
}

.chip.on {
  background: color-mix(in srgb, var(--chip, #00a884) 22%, transparent);
  color: var(--text);
}

.chip input {
  accent-color: var(--accent);
}

.modal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  flex-wrap: wrap;
  margin-top: 4px;
}
