:root {
  color-scheme: light;
  --green: #0a7c66;
  --green-dark: #075e54;
  --green-soft: #dff5ec;
  --ink: #14211e;
  --muted: #667773;
  --line: #dce5e2;
  --surface: #ffffff;
  --page: #f3f7f5;
  --danger: #b42318;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  color: var(--ink);
  background:
    radial-gradient(circle at 12% 8%, #d7f3e8 0, transparent 28rem), var(--page);
  font-family:
    Inter,
    ui-sans-serif,
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    sans-serif;
}

body.panel-active {
  overflow: hidden;
}

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.hidden {
  display: none !important;
}

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

.panel-view:not(.hidden) {
  height: 100vh;
  min-height: 0;
  overflow: hidden;
}

.access-view {
  width: min(1100px, calc(100% - 40px));
  margin: 0 auto;
  padding: 42px 0;
}

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

.brand-mark,
.empty-icon {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border-radius: 13px;
  color: white;
  background: linear-gradient(145deg, #17a982, var(--green-dark));
  box-shadow: 0 8px 22px #08745d35;
  font-weight: 800;
}

.brand strong,
.brand small {
  display: block;
}

.brand small {
  margin-top: 2px;
  color: var(--muted);
}

.access-card {
  display: grid;
  grid-template-columns: 1.1fr 0.9fr;
  min-height: 510px;
  margin-top: 70px;
  overflow: hidden;
  border: 1px solid #ffffff80;
  border-radius: 28px;
  background: var(--surface);
  box-shadow: 0 28px 80px #183d3420;
}

.access-copy {
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 72px;
  color: white;
  background:
    linear-gradient(135deg, #075e54e8, #0b8e73e8),
    repeating-linear-gradient(45deg, transparent 0 22px, #ffffff0b 22px 23px);
}

.eyebrow {
  color: var(--green);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.access-copy .eyebrow {
  color: #aaf1dd;
}

.access-copy h1 {
  max-width: 520px;
  margin: 18px 0;
  font-size: clamp(2.4rem, 5vw, 4.2rem);
  line-height: 1;
  letter-spacing: -0.055em;
}

.access-copy p {
  max-width: 470px;
  color: #d7f3eb;
  font-size: 1.05rem;
  line-height: 1.7;
}

.access-card form {
  align-self: center;
  padding: 70px;
}

.access-card form h2 {
  margin: 10px 0;
}

.otp-description {
  margin: 0 0 24px;
  color: var(--muted);
  line-height: 1.55;
}

.otp-input {
  height: 64px;
  text-align: center;
  font-size: 2rem;
  font-weight: 800;
  letter-spacing: 0.35em;
}

.back-button {
  width: auto !important;
  height: auto !important;
  margin-bottom: 26px;
  padding: 0 !important;
  color: var(--green-dark) !important;
  background: transparent !important;
  font-size: 0.8rem;
}

label {
  display: block;
  margin-bottom: 9px;
  font-size: 0.86rem;
  font-weight: 700;
}

input,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  outline: none;
  background: white;
  transition:
    border 0.2s,
    box-shadow 0.2s;
}

input {
  height: 48px;
  padding: 0 15px;
}

input:focus,
textarea:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 3px #0a7c6618;
}

.access-card form button,
.message-form button {
  width: 100%;
  height: 48px;
  border: 0;
  border-radius: 12px;
  color: white;
  background: var(--green);
  font-weight: 750;
}

.form-error {
  min-height: 22px;
  margin: 8px 0;
  color: var(--danger);
  font-size: 0.84rem;
}

.topbar {
  display: flex;
  height: 72px;
  align-items: center;
  justify-content: space-between;
  padding: 0 28px;
  border-bottom: 1px solid var(--line);
  background: #ffffffeb;
  backdrop-filter: blur(12px);
}

.compact .brand-mark {
  width: 36px;
  height: 36px;
  border-radius: 11px;
}

.topbar-actions,
.status-pill {
  display: flex;
  align-items: center;
}

.topbar-actions {
  gap: 18px;
}

.device-pill {
  padding: 8px 11px;
  border: 1px solid #cfe4dd;
  border-radius: 10px;
  color: var(--muted);
  background: #f4faf8;
  font-size: 0.75rem;
}

.device-pill b {
  color: var(--green-dark);
}

.status-pill {
  gap: 8px;
  color: var(--muted);
  font-size: 0.82rem;
}

.status-pill span {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #e5a000;
  box-shadow: 0 0 0 4px #e5a00018;
}

.status-pill.ready span {
  background: #16a36a;
  box-shadow: 0 0 0 4px #16a36a18;
}

.status-pill.error span {
  background: var(--danger);
  box-shadow: 0 0 0 4px #b4231818;
}

.ghost-button,
.icon-button {
  border: 1px solid var(--line);
  color: var(--ink);
  background: white;
}

.ghost-button {
  padding: 9px 13px;
  border-radius: 10px;
  font-size: 0.8rem;
}

.auth-panel {
  display: grid;
  min-height: calc(100vh - 72px);
  place-items: center;
  padding: 36px;
}

.auth-card {
  display: grid;
  grid-template-columns: 0.85fr 1.15fr;
  width: min(900px, 100%);
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 24px;
  background: var(--surface);
  box-shadow: 0 24px 70px #183d3417;
}

.qr-side {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 48px;
  background: #f5faf8;
}

.qr-side small {
  color: var(--muted);
}

.qr-frame {
  display: grid;
  width: 300px;
  height: 300px;
  place-items: center;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: white;
}

.qr-frame img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.qr-placeholder {
  color: var(--muted);
  text-align: center;
}

.loader {
  display: inline-block;
  width: 28px;
  height: 28px;
  border: 3px solid var(--line);
  border-top-color: var(--green);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.auth-copy {
  padding: 58px;
}

.auth-copy h2,
.sidebar-header h2 {
  margin: 9px 0 22px;
  letter-spacing: -0.035em;
}

.auth-copy h2 {
  font-size: 2rem;
}

.auth-copy ol {
  padding-left: 22px;
  color: #465752;
  line-height: 2;
}

.auth-tabs {
  display: flex;
  gap: 6px;
  margin: 0 0 18px;
  padding: 4px;
  border-radius: 12px;
  background: #edf3f1;
}

.auth-tab {
  flex: 1;
  padding: 9px 12px;
  border: 0;
  border-radius: 9px;
  color: var(--muted);
  background: transparent;
  font-weight: 700;
}

.auth-tab.active {
  color: var(--green-dark);
  background: white;
  box-shadow: 0 2px 8px #183d3412;
}

.pairing-form label {
  margin-top: 13px;
}

.device-name-help {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.45;
}

.device-name-help strong {
  color: var(--green-dark);
}

.device-name-help span {
  float: right;
}

.pairing-form button {
  width: 100%;
  height: 44px;
  margin-top: 16px;
  border: 0;
  border-radius: 11px;
  color: white;
  background: var(--green);
  font-weight: 750;
}

.pairing-result {
  margin-top: 16px;
  padding: 16px;
  border: 1px solid #a9dccc;
  border-radius: 12px;
  text-align: center;
  background: var(--green-soft);
}

.pairing-result small,
.pairing-result strong {
  display: block;
}

.pairing-result strong {
  margin: 8px 0;
  color: var(--green-dark);
  font-size: 2rem;
  letter-spacing: 0.22em;
}

.pairing-result p {
  margin: 0;
  color: var(--muted);
  font-size: 0.76rem;
  line-height: 1.45;
}

.session-note {
  margin-top: 28px;
  padding: 18px;
  border: 1px solid #bfe7da;
  border-radius: 14px;
  background: var(--green-soft);
}

.session-note p {
  margin: 6px 0 0;
  color: #47625a;
  line-height: 1.5;
}

.auth-message {
  color: var(--danger);
}

.workspace {
  display: grid;
  grid-template-columns: 78px minmax(290px, 340px) minmax(0, 1fr);
  height: calc(100vh - 72px);
  min-height: 0;
  overflow: hidden;
}

.main-navigation {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
  padding: 18px 10px;
  border-right: 1px solid var(--line);
  background: #0b695a;
  overflow: hidden;
}

.navigation-brand {
  display: grid;
  width: 44px;
  height: 44px;
  margin: 0 auto 18px;
  place-items: center;
  border-radius: 14px;
  color: var(--green-dark);
  background: white;
  font-weight: 900;
}

.nav-item {
  display: grid;
  gap: 5px;
  justify-items: center;
  padding: 10px 4px;
  border: 0;
  border-radius: 12px;
  color: #d8eee8;
  background: transparent;
  font-size: 1.1rem;
}

.nav-item b {
  font-size: 0.66rem;
}

.nav-item span {
  font-weight: 800;
}

.nav-item:hover,
.nav-item.active {
  color: white;
  background: #ffffff1c;
}

.nav-spacer {
  flex: 1;
}

.session-card {
  display: grid;
  justify-items: center;
  gap: 7px;
  color: #d8eee8;
  text-align: center;
}

.session-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #58e4a8;
  box-shadow: 0 0 0 5px #58e4a824;
}

.session-card small {
  font-size: 0.62rem;
}

.conversation-sidebar {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  overflow: hidden;
  border-right: 1px solid var(--line);
  background: white;
  min-height: 0;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 24px 22px 10px;
}

.sidebar-header h2 {
  margin-bottom: 0;
}

.icon-button {
  width: 38px;
  height: 38px;
  border-radius: 11px;
  font-size: 1.25rem;
}

.search-box {
  position: relative;
  margin: 16px 18px;
}

.search-box span {
  position: absolute;
  top: 12px;
  left: 13px;
  color: var(--muted);
}

.search-box input {
  padding-left: 38px;
  background: #f6f8f7;
}

.conversation-list {
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.conversation-item {
  display: grid;
  grid-template-columns: 46px 1fr auto;
  gap: 12px;
  width: 100%;
  min-height: 68px;
  padding: 11px 16px;
  border: 0;
  border-top: 1px solid #edf1ef;
  text-align: left;
  background: white;
}

.show-more-button {
  width: calc(100% - 28px);
  margin: 10px 14px 14px;
  padding: 10px;
  border: 1px solid #cfe4dd;
  border-radius: 10px;
  color: var(--green-dark);
  background: #f1faf7;
  font-weight: 700;
}

.conversation-item:hover,
.conversation-item.active {
  background: #edf8f4;
}

.avatar {
  display: grid;
  width: 44px;
  height: 44px;
  place-items: center;
  border-radius: 50%;
  color: var(--green-dark);
  background: #d9eee7;
  font-weight: 800;
  overflow: hidden;
}

.avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

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

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

.conversation-main span,
.conversation-time,
.chat-header small {
  color: var(--muted);
  font-size: 0.78rem;
}

.conversation-main span {
  margin-top: 5px;
}

.unread {
  display: inline-grid;
  min-width: 20px;
  height: 20px;
  margin-top: 6px;
  place-items: center;
  border-radius: 10px;
  color: white;
  background: var(--green);
  font-size: 0.7rem;
}

.chat-area {
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background:
    linear-gradient(#f5f8f7e8, #f5f8f7e8),
    radial-gradient(circle, #8aa89e 1px, transparent 1px);
  background-size:
    auto,
    22px 22px;
}

.empty-chat {
  display: grid;
  height: 100%;
  place-content: center;
  justify-items: center;
  color: var(--muted);
  text-align: center;
}

.empty-chat h2 {
  margin: 20px 0 5px;
  color: var(--ink);
}

.active-chat {
  display: grid;
  height: 100%;
  grid-template-rows: 70px 1fr auto;
  min-height: 0;
  overflow: hidden;
}

.chat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 22px;
  border-bottom: 1px solid var(--line);
  background: white;
}

.chat-header strong,
.chat-header small {
  display: block;
}

.message-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow-y: auto;
  min-height: 0;
  overscroll-behavior: contain;
  scroll-behavior: smooth;
  padding: 22px clamp(24px, 5vw, 72px);
}

.history-status {
  align-self: center;
  position: sticky;
  top: 4px;
  z-index: 2;
  margin: 0 auto 10px;
  padding: 8px 12px;
  border: 1px solid #d7e5e0;
  border-radius: 10px;
  color: var(--muted);
  background: #fffffff2;
  box-shadow: 0 3px 12px #183d3414;
  font-size: 0.72rem;
  font-weight: 700;
}

.history-status.loading::before {
  display: inline-block;
  width: 10px;
  height: 10px;
  margin-right: 7px;
  border: 2px solid #b9d8ce;
  border-top-color: var(--green);
  border-radius: 50%;
  content: "";
  animation: spin 0.8s linear infinite;
}

.message-date {
  align-self: center;
  margin: 6px 0;
  padding: 7px 12px;
  border: 1px solid #cfe0e8;
  border-radius: 9px;
  color: #52717e;
  background: #e7f4fae8;
  box-shadow: 0 2px 8px #183d3410;
  font-size: 0.72rem;
  font-weight: 700;
}

.scroll-to-bottom {
  position: absolute;
  right: 24px;
  bottom: 84px;
  z-index: 3;
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border: 1px solid #bcd8cf;
  border-radius: 50%;
  color: var(--green-dark);
  background: white;
  box-shadow: 0 8px 24px #183d3428;
  font-size: 1.25rem;
  font-weight: 800;
}

.message {
  width: fit-content;
  min-width: 120px;
  max-width: min(560px, 72%);
  padding: 9px 12px 6px;
  border-radius: 12px;
  background: white;
  box-shadow: 0 1px 2px #213b3314;
  line-height: 1.45;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.message.mine {
  align-self: flex-end;
  background: #d8f8e9;
}

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

.message-form {
  display: grid;
  grid-template-columns: 1fr 110px;
  gap: 10px;
  padding: 14px 20px;
  border-top: 1px solid var(--line);
  background: white;
}

.message-form textarea {
  min-height: 48px;
  max-height: 130px;
  padding: 13px 15px;
  resize: vertical;
}

.empty-list {
  padding: 36px 22px;
  color: var(--muted);
  text-align: center;
}

.integration-overlay {
  position: fixed;
  z-index: 20;
  inset: 72px 0 0;
  overflow-y: auto;
  padding: 30px;
  background: #edf4f1f2;
  backdrop-filter: blur(6px);
}

.integration-window {
  width: min(1100px, 100%);
  margin: 0 auto;
}

.integration-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 22px;
}

.integration-header h2 {
  margin: 6px 0;
  font-size: 2rem;
}

.integration-header p,
.integration-card p,
.payload-card p {
  margin: 0;
  color: var(--muted);
  line-height: 1.55;
}

.integration-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
}

.integration-card,
.payload-card {
  border: 1px solid var(--line);
  border-radius: 20px;
  background: white;
  box-shadow: 0 12px 35px #183d340e;
}

.integration-card {
  padding: 24px;
}

.integration-card h3,
.payload-card h3 {
  margin: 8px 0;
}

.card-number {
  color: var(--green);
  font-size: 0.72rem;
  font-weight: 900;
  letter-spacing: 0.12em;
}

.endpoint {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 20px 0 10px;
  padding: 10px 12px;
  border-radius: 10px;
  background: #eff6f3;
}

.endpoint b {
  padding: 4px 7px;
  border-radius: 6px;
  color: white;
  background: var(--green);
  font-size: 0.7rem;
}

pre {
  overflow-x: auto;
  margin: 12px 0;
  padding: 16px;
  border-radius: 12px;
  color: #d7f5ea;
  background: #102823;
  font:
    0.78rem/1.65 ui-monospace,
    SFMono-Regular,
    Consolas,
    monospace;
  white-space: pre-wrap;
}

.integration-card label {
  margin-top: 16px;
}

.integration-card small {
  display: block;
  margin-top: 6px;
  color: var(--muted);
  text-align: right;
}

.form-actions {
  display: flex;
  gap: 9px;
  margin-top: 18px;
}

.form-actions button,
.secondary-button {
  min-height: 42px;
  padding: 0 14px;
  border-radius: 10px;
  font-weight: 750;
}

.form-actions button[type="submit"] {
  border: 0;
  color: white;
  background: var(--green);
}

.secondary-button {
  border: 1px solid #bcd8cf;
  color: var(--green-dark);
  background: white;
}

.integration-message {
  min-height: 22px;
  margin-top: 12px !important;
  font-size: 0.82rem;
}

.integration-message.success {
  color: var(--green);
}

.integration-message.error {
  color: var(--danger);
}

.payload-card {
  display: grid;
  grid-template-columns: 0.75fr 1.25fr;
  gap: 22px;
  margin-top: 18px;
  padding: 24px;
}

.payload-card pre {
  margin: 0;
}

.webhook-status {
  grid-column: 1 / -1;
  padding: 11px 13px;
  border-radius: 10px;
  color: var(--muted);
  background: #f2f6f4;
  font-size: 0.8rem;
}

.webhook-status.success {
  color: var(--green-dark);
  background: var(--green-soft);
}

@media (max-width: 760px) {
  .access-card,
  .auth-card {
    grid-template-columns: 1fr;
  }

  .access-copy {
    padding: 46px 34px;
  }

  .access-card form,
  .auth-copy {
    padding: 38px 30px;
  }

  .access-card {
    margin-top: 35px;
  }

  .workspace {
    grid-template-columns: 1fr;
  }

  .main-navigation {
    display: none;
  }

  .conversation-sidebar:has(.conversation-item.active) {
    display: none;
  }

  .topbar {
    padding: 0 14px;
  }

  .status-pill {
    display: none;
  }

  .device-pill {
    display: none;
  }

  .qr-frame {
    width: 250px;
    height: 250px;
  }

  .integration-overlay {
    padding: 18px;
  }

  .integration-grid,
  .payload-card {
    grid-template-columns: 1fr;
  }
}
