:root {
  color-scheme: light;
  --ink: #182022;
  --muted: #667174;
  --line: #d9e0df;
  --panel: #ffffff;
  --soft: #f5f7f4;
  --mint: #dff3ea;
  --green: #13795b;
  --blue: #2455a6;
  --coral: #c84f3a;
  --gold: #9b6a1b;
  --shadow: 0 10px 30px rgba(22, 32, 34, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: #f3f6f1;
  color: var(--ink);
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

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

button {
  border: 0;
  cursor: pointer;
}

button:disabled {
  cursor: wait;
  opacity: 0.65;
}

.app-shell {
  width: min(1180px, 100%);
  margin: 0 auto;
  padding: 18px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

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

.avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--mint);
  display: grid;
  place-items: center;
  color: var(--green);
  font-weight: 800;
  overflow: hidden;
  flex: 0 0 auto;
}

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

.brand h1,
.brand h2 {
  margin: 0;
  font-size: 22px;
  line-height: 1.15;
}

.brand p,
.muted {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 28px;
  padding: 5px 9px;
  border-radius: 999px;
  background: var(--mint);
  color: var(--green);
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.pill.warn {
  background: #fff0dc;
  color: var(--gold);
}

.pill.danger {
  background: #ffe7e1;
  color: var(--coral);
}

.grid {
  display: grid;
  grid-template-columns: 1.1fr 0.9fr;
  gap: 16px;
}

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

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

.panel h2,
.panel h3 {
  margin: 0 0 12px;
  font-size: 17px;
}

.panel h3 {
  font-size: 15px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.field {
  display: grid;
  gap: 6px;
}

.field.full {
  grid-column: 1 / -1;
}

label {
  color: #415053;
  font-size: 12px;
  font-weight: 700;
}

input,
textarea,
select {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfb;
  color: var(--ink);
  padding: 9px 10px;
  outline: none;
}

textarea {
  min-height: 86px;
  resize: vertical;
  line-height: 1.5;
}

input:focus,
textarea:focus,
select:focus {
  border-color: #7fb4a2;
  box-shadow: 0 0 0 3px rgba(19, 121, 91, 0.12);
}

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

.button {
  min-height: 38px;
  border-radius: 8px;
  padding: 9px 12px;
  background: var(--ink);
  color: white;
  font-weight: 750;
}

.button.secondary {
  background: #e7ece9;
  color: var(--ink);
}

.button.ghost {
  background: transparent;
  color: var(--blue);
  padding-inline: 4px;
}

.button.danger {
  background: var(--coral);
}

.memory-list,
.tier-list,
.session-list {
  display: grid;
  gap: 10px;
}

.memory-card,
.tier-card,
.session-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fbfcfb;
}

.memory-card textarea {
  min-height: 72px;
}

.card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.inline-fields {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.toggle-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-top: 10px;
}

.check {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--ink);
  font-size: 13px;
  font-weight: 600;
}

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

.share-box {
  display: grid;
  grid-template-columns: 160px 1fr;
  gap: 14px;
  align-items: center;
}

.qr {
  width: 160px;
  height: 160px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  padding: 8px;
}

.qr img {
  width: 100%;
  height: 100%;
  display: block;
}

.link-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.link-row input {
  font-size: 13px;
}

.invite-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.82), rgba(244, 246, 242, 0.92)),
    #f4f6f2;
}

.invite-card {
  width: min(420px, 100%);
  min-height: 520px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 34px 24px;
  border: 1px solid rgba(24, 32, 34, 0.09);
  border-radius: 28px;
  background: rgba(255, 255, 255, 0.72);
  box-shadow: 0 24px 80px rgba(24, 32, 34, 0.1);
  backdrop-filter: blur(22px);
  text-align: center;
}

.invite-avatar {
  width: 104px;
  height: 104px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background:
    linear-gradient(145deg, rgba(255, 255, 255, 0.92), rgba(223, 243, 234, 0.88));
  border: 1px solid rgba(19, 121, 91, 0.12);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.9), 0 18px 42px rgba(19, 121, 91, 0.12);
  color: var(--green);
  font-size: 44px;
  font-weight: 760;
  overflow: hidden;
}

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

.invite-kicker {
  margin: 10px 0 0;
  color: #75807d;
  font-size: 12px;
  font-weight: 760;
  letter-spacing: 0;
  text-transform: uppercase;
}

.invite-card h1 {
  margin: 0;
  max-width: 100%;
  color: #161d1f;
  font-size: 28px;
  line-height: 1.18;
  font-weight: 780;
  letter-spacing: 0;
  overflow-wrap: anywhere;
}

.invite-copy,
.invite-footnote {
  margin: 0;
  max-width: 300px;
  color: #667174;
  font-size: 14px;
  line-height: 1.55;
}

.invite-footnote {
  color: #87908d;
  font-size: 12px;
}

.invite-form {
  width: 100%;
  margin-top: 10px;
}

.invite-input-wrap {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 8px;
  min-height: 56px;
  padding: 7px;
  border: 1px solid rgba(24, 32, 34, 0.12);
  border-radius: 18px;
  background: rgba(247, 249, 247, 0.92);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.86);
}

.invite-input-wrap:focus-within {
  border-color: rgba(19, 121, 91, 0.34);
  box-shadow: 0 0 0 4px rgba(19, 121, 91, 0.09), inset 0 1px 0 rgba(255, 255, 255, 0.86);
}

.invite-input-wrap input {
  min-width: 0;
  min-height: 40px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  padding: 0 8px;
  color: var(--ink);
  font-size: 16px;
}

.invite-input-wrap input:focus {
  box-shadow: none;
}

.invite-submit {
  min-width: 72px;
  min-height: 42px;
  border-radius: 12px;
  background: #171d1f;
  color: #fff;
  font-size: 14px;
  font-weight: 760;
}

.invite-loader {
  color: #75807d;
  font-size: 14px;
}

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

.chat-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 12px;
}

.phone {
  width: min(480px, 100%);
  height: min(820px, calc(100vh - 24px));
  min-height: 620px;
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  display: grid;
  grid-template-rows: auto 1fr auto;
  overflow: hidden;
}

.visitor-phone {
  grid-template-rows: 1fr auto;
}

.chat-header {
  padding: 14px;
  border-bottom: 1px solid var(--line);
  background: #fbfcfb;
}

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

.notice {
  margin-top: 12px;
  padding: 10px;
  border-radius: 8px;
  background: #eef5ff;
  color: #29405f;
  font-size: 13px;
  line-height: 1.5;
}

.onboarding {
  padding: 16px;
  overflow: auto;
}

.chat-log {
  padding: 14px;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: #f8faf7;
}

.message-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  max-width: 92%;
}

.message-row.assistant {
  align-self: flex-start;
}

.chat-avatar {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  flex: 0 0 34px;
  overflow: hidden;
  border-radius: 50%;
  background: #dfeee8;
  color: var(--green);
  font-size: 15px;
  font-weight: 760;
  box-shadow: 0 1px 2px rgba(24, 32, 34, 0.08);
}

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

.bubble {
  max-width: 86%;
  padding: 10px 12px;
  border-radius: 8px;
  line-height: 1.5;
  font-size: 15px;
  white-space: pre-wrap;
}

.message-row .bubble {
  max-width: 100%;
}

.bubble.assistant {
  align-self: flex-start;
  background: white;
  border: 1px solid var(--line);
}

.bubble.user {
  align-self: flex-end;
  background: var(--green);
  color: white;
}

.composer {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid var(--line);
  background: white;
}

.composer input {
  min-height: 42px;
}

.session-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 8px;
}

.messages-mini {
  display: grid;
  gap: 6px;
  margin-top: 10px;
  max-height: 260px;
  overflow: auto;
  border-top: 1px solid var(--line);
  padding-top: 10px;
}

.mini-message {
  font-size: 13px;
  line-height: 1.45;
  color: #334044;
}

.mini-message strong {
  color: var(--blue);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
  background: var(--ink);
  color: white;
  padding: 10px 14px;
  border-radius: 8px;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity 160ms ease;
  z-index: 20;
}

.toast.show {
  opacity: 1;
}

.empty {
  padding: 16px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  text-align: center;
}

.error {
  color: var(--coral);
  font-size: 13px;
  margin-top: 8px;
}

@media (max-width: 860px) {
  .grid,
  .form-grid,
  .share-box {
    grid-template-columns: 1fr;
  }

  .inline-fields,
  .toggle-grid {
    grid-template-columns: 1fr;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .phone {
    height: calc(100vh - 24px);
    min-height: 560px;
  }

  .app-shell {
    padding: 12px;
  }
}

@media (max-width: 520px) {
  .invite-page {
    padding: 14px;
  }

  .invite-card {
    min-height: calc(100vh - 28px);
    border-radius: 24px;
    padding: 28px 18px;
  }

  .invite-avatar {
    width: 96px;
    height: 96px;
    font-size: 40px;
  }

  .invite-card h1 {
    font-size: 25px;
  }
}
