:root {
  --green-900: #075e54;
  --green-700: #128c7e;
  --green-500: #25d366;
  --ink: #17211f;
  --muted: #65706d;
  --line: #dce5e2;
  --panel: #ffffff;
  --panel-soft: #f5f8f7;
  --chat-bg: #e9ede8;
  --incoming: #ffffff;
  --outgoing: #dcf8c6;
  --accent-blue: #3b82f6;
  --accent-coral: #ff7a59;
  --shadow: 0 18px 55px rgba(23, 33, 31, 0.16);
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  font-family: Tahoma, Arial, sans-serif;
  background:
    linear-gradient(180deg, var(--green-900) 0 118px, var(--chat-bg) 118px 100%),
    var(--chat-bg);
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

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

.login-screen {
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: 20px;
  background:
    linear-gradient(180deg, rgba(7, 94, 84, 0.94), rgba(18, 140, 126, 0.82)),
    var(--chat-bg);
}

.app-shell.is-locked {
  display: none;
}

.login-card {
  display: grid;
  width: min(420px, 100%);
  gap: 16px;
  padding: 26px;
  background: var(--panel);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.login-card h1 {
  font-size: 28px;
}

.login-copy {
  color: var(--muted);
  line-height: 1.7;
}

.login-field {
  display: grid;
  gap: 7px;
}

.login-field span {
  color: var(--ink);
  font-size: 13px;
  font-weight: 800;
}

.login-field input {
  min-height: 46px;
  padding: 0 12px;
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  outline: 0;
}

.login-field input:focus {
  border-color: rgba(18, 140, 126, 0.55);
  box-shadow: 0 0 0 3px rgba(18, 140, 126, 0.1);
}

.login-error {
  margin: 0;
  padding: 10px 12px;
  color: #8a1f11;
  background: #fff0ec;
  border: 1px solid #ffd0c4;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 700;
}

.login-error[hidden] {
  display: none;
}

.primary-button {
  min-height: 46px;
  padding: 0 18px;
  color: #063b35;
  background: var(--green-500);
  border: 0;
  border-radius: 8px;
  font-weight: 800;
}

.primary-button:hover,
.primary-button:focus-visible {
  background: #20bf5c;
  outline: 2px solid rgba(37, 211, 102, 0.35);
  outline-offset: 2px;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(300px, 390px) minmax(0, 1fr);
  width: min(1440px, calc(100vw - 32px));
  height: min(880px, calc(100vh - 32px));
  min-height: 620px;
  margin: 16px auto;
  overflow: hidden;
  background: var(--panel);
  border: 1px solid rgba(255, 255, 255, 0.46);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.sidebar {
  display: grid;
  grid-template-rows: auto auto auto auto 1fr;
  min-width: 0;
  border-left: 1px solid var(--line);
  background: var(--panel);
}

.sidebar-header,
.conversation-header,
.composer {
  display: flex;
  align-items: center;
  gap: 12px;
}

.sidebar-header {
  justify-content: space-between;
  min-height: 78px;
  padding: 16px;
  background: var(--panel-soft);
  border-bottom: 1px solid var(--line);
}

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

.eyebrow {
  margin: 0 0 2px;
  color: var(--green-700);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 24px;
  line-height: 1.2;
}

.icon-button,
.quiet-button,
.send-button,
.filter-tab,
.primary-button {
  border: 0;
  border-radius: 8px;
}

.icon-button {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  flex: 0 0 40px;
  color: var(--green-900);
  background: #e2f4ee;
  font-size: 24px;
  line-height: 1;
}

.icon-button:hover,
.icon-button:focus-visible {
  background: #d0ede4;
  outline: 2px solid rgba(18, 140, 126, 0.24);
  outline-offset: 2px;
}

.status-strip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  background: #f9fbfb;
  border-bottom: 1px solid var(--line);
}

.profile-chip {
  display: flex;
  align-items: center;
  min-width: 0;
  gap: 10px;
}

.profile-chip strong,
.profile-chip span,
.conversation-title h2,
.conversation-title p,
.chat-name,
.chat-preview,
.assignee-chip {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.profile-chip strong,
.profile-chip span {
  display: block;
  max-width: 170px;
}

.profile-chip span,
.conversation-title p,
.chat-preview,
.chat-time {
  color: var(--muted);
  font-size: 13px;
}

.avatar {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  flex: 0 0 44px;
  color: #fff;
  background: var(--green-700);
  border-radius: 50%;
  font-weight: 800;
}

.avatar-me {
  background: var(--accent-blue);
}

.quiet-button {
  min-height: 34px;
  padding: 0 12px;
  color: var(--green-900);
  background: #eef7f4;
  font-size: 13px;
  font-weight: 700;
}

.quiet-button:hover,
.quiet-button:focus-visible {
  background: #dff0eb;
  outline: 2px solid rgba(7, 94, 84, 0.18);
}

.search-box {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 12px 14px;
  padding: 0 12px;
  color: var(--muted);
  background: var(--panel-soft);
  border: 1px solid transparent;
  border-radius: 8px;
}

.search-box:focus-within {
  border-color: rgba(18, 140, 126, 0.45);
  background: #fff;
}

.search-box input {
  width: 100%;
  min-width: 0;
  height: 42px;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--ink);
}

.filter-tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  padding: 0 14px 12px;
}

.filter-tab {
  min-height: 34px;
  color: var(--muted);
  background: var(--panel-soft);
  font-size: 13px;
  font-weight: 700;
}

.filter-tab.is-active {
  color: #063b35;
  background: #dff5ec;
}

.chat-list {
  overflow: auto;
  padding-bottom: 8px;
}

.chat-item {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) auto;
  gap: 12px;
  width: 100%;
  min-height: 76px;
  padding: 12px 16px;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: #fff;
  color: inherit;
  text-align: right;
}

.chat-item:hover,
.chat-item:focus-visible {
  background: #f3faf7;
  outline: 0;
}

.chat-item.is-active {
  background: #e9f6f1;
}

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

.chat-name-row,
.chat-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.chat-name {
  display: block;
  font-weight: 800;
}

.chat-preview {
  display: block;
  margin-top: 4px;
}

.assignee-chip {
  display: inline-flex;
  align-items: center;
  max-width: 100%;
  gap: 6px;
  margin-top: 7px;
  padding: 4px 8px;
  color: #18443e;
  background: #f0f7f4;
  border: 1px solid rgba(7, 94, 84, 0.1);
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
}

.assignee-dot {
  width: 8px;
  height: 8px;
  flex: 0 0 8px;
  background: var(--assignee-color, var(--green-700));
  border-radius: 50%;
}

.chat-meta {
  flex-direction: column;
  align-items: flex-end;
}

.unread-badge {
  display: grid;
  place-items: center;
  min-width: 22px;
  height: 22px;
  padding: 0 7px;
  color: #083d35;
  background: var(--green-500);
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
}

.conversation {
  display: grid;
  grid-template-rows: auto 1fr auto;
  min-width: 0;
  background: var(--chat-bg);
}

.conversation-header {
  min-height: 78px;
  padding: 12px 18px;
  background: var(--panel-soft);
  border-bottom: 1px solid var(--line);
}

.back-button {
  display: none;
}

.conversation-title {
  min-width: 0;
  flex: 1;
}

.conversation-title h2 {
  font-size: 19px;
}

.assignment-panel {
  display: grid;
  min-width: 178px;
  gap: 4px;
}

.assignment-panel span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}

.assignment-panel small {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.assignment-panel select {
  width: 100%;
  height: 38px;
  min-width: 0;
  padding: 0 10px;
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  outline: 0;
}

.assignment-panel select:focus {
  border-color: rgba(18, 140, 126, 0.55);
  box-shadow: 0 0 0 3px rgba(18, 140, 126, 0.1);
}

.assignment-panel select:disabled {
  color: var(--muted);
  background: #f2f5f4;
  cursor: not-allowed;
}

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

.message-pane {
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow: auto;
  padding: 24px clamp(16px, 4vw, 56px);
  background:
    linear-gradient(rgba(233, 237, 232, 0.84), rgba(233, 237, 232, 0.84)),
    repeating-linear-gradient(45deg, transparent 0 18px, rgba(7, 94, 84, 0.05) 18px 19px);
}

.day-divider {
  align-self: center;
  padding: 6px 12px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.82);
  border-radius: 8px;
  font-size: 12px;
  font-weight: 700;
}

.message {
  max-width: min(70%, 620px);
  padding: 9px 11px 7px;
  border-radius: 8px;
  box-shadow: 0 1px 1px rgba(23, 33, 31, 0.09);
}

.message.incoming {
  align-self: flex-start;
  background: var(--incoming);
}

.message.outgoing {
  align-self: flex-end;
  background: var(--outgoing);
}

.message p {
  line-height: 1.6;
}

.responder-name {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 4px;
  color: var(--green-900);
  font-size: 12px;
  font-weight: 800;
}

.message time {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 11px;
  text-align: left;
}

.composer {
  min-height: 76px;
  padding: 12px 16px;
  background: var(--panel-soft);
  border-top: 1px solid var(--line);
}

.message-input-wrap {
  flex: 1;
  min-width: 0;
}

.composer-agent {
  display: inline-flex;
  align-items: center;
  min-height: 38px;
  max-width: 150px;
  padding: 0 10px;
  color: #18443e;
  background: #fff;
  border-right: 4px solid var(--assignee-color, var(--green-700));
  border-radius: 8px;
  font-size: 12px;
  font-weight: 800;
}

.composer-agent.is-error {
  color: #8a1f11;
  border-right-color: #d43f25;
}

.message-input-wrap input {
  width: 100%;
  min-height: 46px;
  padding: 0 16px;
  border: 1px solid transparent;
  border-radius: 8px;
  outline: 0;
  color: var(--ink);
  background: #fff;
}

.message-input-wrap input:focus {
  border-color: rgba(18, 140, 126, 0.45);
}

.send-button {
  min-width: 86px;
  min-height: 46px;
  padding: 0 18px;
  color: #063b35;
  background: var(--green-500);
  font-weight: 800;
}

.send-button:hover,
.send-button:focus-visible {
  background: #20bf5c;
  outline: 2px solid rgba(37, 211, 102, 0.35);
  outline-offset: 2px;
}

.empty-state {
  margin: auto;
  max-width: 380px;
  padding: 24px;
  color: var(--muted);
  text-align: center;
}

.admin-panel {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(7, 22, 20, 0.46);
}

.admin-shell {
  display: grid;
  grid-template-rows: auto auto 1fr;
  width: min(1100px, 100%);
  max-height: min(820px, calc(100vh - 48px));
  overflow: hidden;
  background: var(--panel);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.admin-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 20px;
  background: var(--panel-soft);
  border-bottom: 1px solid var(--line);
}

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

.admin-tabs {
  display: flex;
  gap: 8px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--line);
}

.admin-tab {
  min-height: 38px;
  padding: 0 14px;
  color: var(--muted);
  background: var(--panel-soft);
  border: 0;
  border-radius: 8px;
  font-weight: 800;
}

.admin-tab.is-active {
  color: #063b35;
  background: #dff5ec;
}

.admin-view {
  min-height: 0;
  overflow: auto;
  padding: 20px;
}

#adminUsersView,
#adminIntegrationView {
  display: grid;
  grid-template-columns: minmax(280px, 340px) minmax(0, 1fr);
  gap: 18px;
}

.admin-form {
  display: grid;
  align-content: start;
  gap: 12px;
  padding: 16px;
  background: #f9fbfb;
  border: 1px solid var(--line);
  border-radius: 8px;
}

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

.admin-form label span {
  color: var(--ink);
  font-size: 12px;
  font-weight: 800;
}

.admin-form input:not([type="checkbox"]) {
  min-height: 42px;
  padding: 0 11px;
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  outline: 0;
}

.admin-form input:not([type="checkbox"]):focus {
  border-color: rgba(18, 140, 126, 0.55);
  box-shadow: 0 0 0 3px rgba(18, 140, 126, 0.1);
}

.admin-form input[type="color"] {
  padding: 3px;
}

.check-row {
  display: flex !important;
  grid-template-columns: none;
  align-items: center;
  gap: 9px;
}

.check-row input {
  width: 18px;
  height: 18px;
  accent-color: var(--green-700);
}

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

.form-status {
  min-height: 20px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.form-status.is-error {
  color: #8a1f11;
}

.user-list {
  display: grid;
  align-content: start;
  gap: 10px;
}

.user-card {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  padding: 13px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.user-card.is-inactive {
  opacity: 0.62;
}

.user-info {
  min-width: 0;
}

.user-info strong,
.user-info span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-info span {
  margin-top: 3px;
  color: var(--muted);
  font-size: 13px;
}

.user-badges,
.user-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 7px;
}

.user-badge {
  padding: 4px 8px;
  color: #18443e;
  background: #f0f7f4;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
}

.danger-button {
  min-height: 34px;
  padding: 0 12px;
  color: #8a1f11;
  background: #fff0ec;
  border: 0;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 800;
}

.danger-button:hover,
.danger-button:focus-visible {
  background: #ffe2da;
  outline: 2px solid rgba(138, 31, 17, 0.16);
}

.integration-form {
  width: min(620px, 100%);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 780px) {
  body {
    background: var(--panel);
  }

  .app-shell {
    width: 100vw;
    height: 100vh;
    min-height: 100vh;
    margin: 0;
    border: 0;
    border-radius: 0;
  }

  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    border-left: 0;
  }

  .conversation {
    display: none;
  }

  .app-shell.show-conversation .sidebar {
    display: none;
  }

  .app-shell.show-conversation .conversation {
    display: grid;
  }

  .back-button {
    display: grid;
  }

  .conversation-header {
    min-height: 92px;
    flex-wrap: wrap;
  }

  .conversation-title {
    flex: 1 1 calc(100% - 112px);
  }

  .assignment-panel {
    order: 5;
    min-width: 0;
    flex: 1 1 100%;
  }

  .message {
    max-width: 86%;
  }

  .composer {
    flex-wrap: wrap;
  }

  .composer-agent {
    order: -1;
    max-width: none;
    flex: 1 1 100%;
  }

  .conversation-actions .icon-button {
    width: 36px;
    height: 36px;
    flex-basis: 36px;
    font-size: 20px;
  }

  .admin-panel {
    padding: 0;
  }

  .admin-shell {
    width: 100%;
    max-height: 100vh;
    min-height: 100vh;
    border-radius: 0;
  }

  #adminUsersView,
  #adminIntegrationView {
    grid-template-columns: 1fr;
  }

  .user-card {
    grid-template-columns: 44px minmax(0, 1fr);
  }

  .user-actions {
    grid-column: 1 / -1;
    justify-content: flex-start;
  }
}
