:root {
  color-scheme: light;
  --ink: #15191e;
  --muted: #68717c;
  --line: #dce1e6;
  --line-strong: #c6cdd5;
  --paper: #f4f6f7;
  --panel: #ffffff;
  --blue: #1769e0;
  --blue-soft: #edf4ff;
  --green: #16835f;
  --green-soft: #e9f7f1;
  --red: #c03245;
  --red-soft: #fff0f2;
  --note: #f1f3f5;
  --note-line: #d4d9df;
  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(--paper);
  color: var(--ink);
  letter-spacing: 0;
  touch-action: manipulation;
  -webkit-text-size-adjust: 100%;
  -webkit-user-select: none;
  user-select: none;
}

button, input, select { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .65; }

.app-shell {
  width: min(1120px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  background: var(--panel);
  border-inline: 1px solid var(--line);
}

.app-header {
  min-height: 62px;
  display: grid;
  grid-template-columns: auto minmax(180px, 1fr) auto;
  align-items: center;
  gap: 18px;
  padding: 0 22px;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 30;
  background: rgba(255,255,255,.96);
}

.logo-lockup {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--ink);
  font-size: 19px;
  font-weight: 850;
  border: 0;
  background: transparent;
  padding: 0;
}

.brand-mark {
  width: 34px;
  height: 34px;
  display: grid;
  gap: 3px;
  padding: 7px;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  background: #fff;
}
.brand-mark span {
  display: block;
  border-radius: 3px;
  background: var(--green);
}
.brand-mark span:last-child {
  width: 68%;
  background: var(--blue);
}
.brand-word { line-height: 1; }

.language-control {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}
.language-control label { font-weight: 750; }
select {
  height: 38px;
  border: 1px solid var(--line-strong);
  border-radius: 5px;
  background: #fff;
  color: var(--ink);
  padding: 0 34px 0 10px;
}

.account-menu {
  min-width: 0;
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 12px;
  color: var(--muted);
  font-size: 13px;
}
.account-menu span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.workspace { padding: 24px; }

input {
  min-width: 0;
  height: 40px;
  border: 1px solid var(--line-strong);
  border-radius: 5px;
  background: #fff;
  color: var(--ink);
  padding: 0 11px;
  outline: none;
  -webkit-user-select: text;
  user-select: text;
}
input:focus,
select:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(23,105,224,.12);
}

.primary,
.secondary,
.provider-button {
  min-height: 40px;
  border: 1px solid transparent;
  border-radius: 5px;
  padding: 0 14px;
  font-weight: 750;
}
.primary { background: var(--green); color: #fff; }
.secondary { background: #fff; color: var(--ink); border-color: var(--line-strong); }
.primary:hover { background: #106d4e; }
.secondary:hover { background: #f6f8fa; }

.text-button {
  border: 0;
  background: transparent;
  color: var(--blue);
  padding: 0;
  font-weight: 700;
}
.text-button:hover { text-decoration: underline; }

.icon-button {
  display: inline-grid;
  width: 40px;
  height: 40px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: #fff;
  color: var(--blue);
}
.icon-button:hover { background: var(--blue-soft); }
.icon-button svg { width: 17px; height: 17px; }

.alert {
  margin-bottom: 16px;
  padding: 10px 12px;
  border: 1px solid;
  border-radius: 5px;
  font-size: 13px;
}
.alert.error { color: var(--red); border-color: #efbdc5; background: var(--red-soft); }
.alert.success { color: var(--green); border-color: #b8dfd0; background: var(--green-soft); }

.setup-panel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
}
.setup-panel h2 {
  margin: 3px 0 0;
  font-size: 18px;
}
.setup-form {
  display: flex;
  align-items: center;
  gap: 8px;
}

.auth-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: #f4f6f7;
}
.auth-panel {
  width: min(400px, 100%);
  padding: 32px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  box-shadow: 0 18px 55px rgba(24,32,42,.09);
}
.auth-panel h1 { margin: 34px 0 8px; font-size: 28px; }
.auth-panel p { margin: 0 0 24px; color: var(--muted); line-height: 1.55; }
.email-auth-form {
  display: grid;
  gap: 10px;
  margin-bottom: 18px;
}
.email-auth-form label {
  font-size: 13px;
  font-weight: 700;
  color: var(--muted);
}
.email-auth-form input,
.email-auth-form .primary {
  width: 100%;
}
.auth-reset { justify-self: center; }
.auth-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 4px 0 18px;
  color: var(--muted);
  font-size: 12px;
}
.auth-divider::before,
.auth-divider::after {
  content: "";
  height: 1px;
  flex: 1;
  background: var(--line);
}
.auth-actions { display: grid; gap: 10px; }
.provider-button {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  border-color: var(--line-strong);
  background: #fff;
  color: var(--ink);
}
.provider-button:hover { background: #f6f8fa; }
.apple-button {
  border-color: #111;
  background: #111;
  color: #fff;
}
.apple-button:hover { background: #272727; }
.apple-symbol {
  font-size: 13px;
  line-height: 1;
}
.google-g { color: var(--blue); font-weight: 900; }

.chat-layout {
  min-height: calc(100vh - 112px);
  display: block;
  border: 1px solid var(--line);
  border-radius: 7px;
  overflow: hidden;
  background: #fff;
}
.sidebar {
  min-width: 0;
  background: #fbfcfd;
}
.side-head {
  min-height: 76px;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  padding: 16px;
  border-bottom: 1px solid var(--line);
}
.side-head h1 {
  margin: 3px 0 0;
  font-size: 24px;
}
.eyebrow {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}
.add-contact {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  padding: 12px;
  border-bottom: 1px solid var(--line);
}
.contact-list {
  display: grid;
}
.contact-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 4px 12px;
  align-items: center;
  padding: 15px 16px;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: transparent;
  text-align: left;
}
.contact-row:hover,
.contact-row.active {
  background: #fff;
}
.contact-row.active {
  box-shadow: inset 3px 0 0 var(--green);
}
.contact-row span {
  color: var(--ink);
  font-weight: 780;
}
.contact-row small {
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
}
.contact-row svg {
  grid-row: 1 / 3;
  grid-column: 2;
  width: 17px;
  height: 17px;
  color: var(--muted);
}
.empty-list {
  padding: 18px 16px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.conversation {
  min-width: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  background: #fff;
}
.contact-open .conversation { display: none; }
.chat-open .sidebar { display: none; }
.conversation-head {
  min-height: 76px;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 16px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
}
.back-button {
  color: var(--ink);
}
.conversation-head h2 {
  margin: 3px 0 0;
  font-size: 23px;
}
.conversation-head .secondary,
.composer .primary {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.conversation-head svg,
.composer svg {
  width: 16px;
  height: 16px;
}
.message-list {
  min-height: 360px;
  max-height: calc(100vh - 230px);
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 18px;
  background: linear-gradient(#fff, #fbfcfd);
}
.load-older {
  align-self: center;
  min-height: 32px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: #fff;
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
}
.load-older:hover {
  background: #f6f8fa;
  color: var(--ink);
}
.empty-state,
.conversation-empty {
  color: var(--muted);
  text-align: center;
}
.empty-state {
  margin: auto;
  padding: 34px 16px;
  border: 1px dashed var(--line-strong);
  border-radius: 6px;
  width: min(380px, 100%);
}
.conversation-empty {
  align-self: center;
  justify-self: center;
  width: min(420px, 100%);
  padding: 24px;
}
.conversation-empty h2 {
  margin: 0 0 8px;
  color: var(--ink);
  font-size: 24px;
}
.conversation-empty p {
  margin: 0;
  line-height: 1.55;
}
.message {
  width: min(680px, 100%);
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(160px, 42%);
  gap: 10px;
  align-items: start;
}
.message.mine {
  align-self: flex-end;
  grid-template-columns: minmax(160px, 42%) minmax(0, 1fr);
}
.message.mine .bubble {
  grid-column: 2;
  background: var(--green-soft);
  border-color: #c9e6d8;
}
.message.mine .notes {
  grid-column: 1;
  grid-row: 1;
}
.bubble,
.note {
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 10px 12px;
}
.bubble {
  background: #fff;
}
.bubble p,
.note p {
  margin: 0;
  line-height: 1.48;
}
.bubble time,
.note span {
  display: block;
  margin-top: 8px;
  color: var(--muted);
  font-size: 11px;
}
.note {
  background: var(--note);
  border-color: var(--note-line);
}
.notes {
  display: grid;
  gap: 8px;
}
.note span {
  margin: 0 0 6px;
  font-weight: 850;
  text-transform: uppercase;
}
.pending-note {
  color: var(--muted);
  font-style: italic;
}
.composer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  padding: 14px;
  border-top: 1px solid var(--line);
  background: #fff;
}
.composer input {
  height: 44px;
}

@media (max-width: 800px) {
  .app-shell { border: 0; }
  .app-header {
    grid-template-columns: 1fr auto;
    padding: 10px 14px;
  }
  .language-control {
    order: 3;
    grid-column: 1 / -1;
  }
  .account-menu {
    max-width: 48vw;
    gap: 8px;
  }
  .account-menu span {
    display: block;
    max-width: 24vw;
    font-size: 12px;
  }
  .workspace { padding: 14px; }
  .chat-layout {
    min-height: calc(100vh - 126px);
  }
  .sidebar {
    border: 0;
  }
  .contact-row {
    border-right: 0;
  }
  .message-list {
    max-height: none;
  }
  .message,
  .message.mine {
    grid-template-columns: minmax(0, 1fr);
  }
  .message.mine .bubble,
  .message.mine .notes {
    grid-column: auto;
    grid-row: auto;
  }
  .notes {
    margin-left: 20px;
  }
  .composer {
    grid-template-columns: minmax(0, 1fr);
  }
}
