/*
 * Warm domestic: cream paper, one deep green for anything actionable, clay
 * reserved for overdue and failures. Type is a system serif for display against
 * the system UI sans for everything else.
 */
:root {
  --paper: #faf7f1;
  --card: #ffffff;
  --card-soft: #fdfbf6;
  --sunk: #f2eee4;
  --ink: #1e2723;
  --ink-muted: #55605a;
  --ink-faint: #8a938d;
  --rule: #e4ded2;
  --rule-soft: #f3efe6;
  --border: #ede7db;
  --green: #2f6a4b;
  --green-deep: #234f39;
  --green-wash: #e7efe8;
  --green-line: #d3e2d7;
  --clay: #9c5731;
  --clay-deep: #7e4525;
  --clay-wash: #f7eae0;

  --serif: Georgia, 'Iowan Old Style', 'Times New Roman', serif;
  --sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif;

  /* Every full-height page measures itself against the header, so the two must
   * stay in step across breakpoints. */
  --header-height: 72px;

  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-synthesis: none;
  text-rendering: optimizeLegibility;
}

* {
  box-sizing: border-box;
}

/* The browser hides [hidden] elements, closed dialogs and closed popovers
 * through its own stylesheet, which ANY author `display` outranks regardless of
 * specificity. Restating them as author rules keeps a component's layout from
 * revealing something the platform is meant to be hiding. Every new
 * platform-hidden element belongs in this block on the day it is introduced. */
[hidden] {
  display: none !important;
}

dialog:not([open]) {
  display: none !important;
}

[popover]:not(:popover-open) {
  display: none !important;
}

html {
  background: var(--paper);
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-width: 320px;
}

h1,
h2,
h3,
h4 {
  font-family: var(--serif);
  font-weight: 400;
  letter-spacing: -0.015em;
}

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

button,
a {
  -webkit-tap-highlight-color: transparent;
}

a {
  color: var(--green);
  text-decoration: none;
}

a:hover {
  color: var(--green-deep);
}

:focus-visible {
  outline: 3px solid var(--green);
  outline-offset: 3px;
}

.eyebrow {
  color: var(--clay);
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.11em;
  margin: 0;
  text-transform: uppercase;
}

.lede {
  color: var(--ink-muted);
  font-size: 16.5px;
  line-height: 1.55;
  margin: 0;
  max-width: 56ch;
}

.sr-only {
  clip-path: inset(50%);
  height: 1px;
  overflow: hidden;
  position: absolute;
  white-space: nowrap;
  width: 1px;
}

/* Header ------------------------------------------------------------------ */

.site-header {
  align-items: center;
  border-bottom: 1px solid var(--border);
  display: flex;
  gap: 24px;
  height: var(--header-height);
  justify-content: space-between;
  padding: 0 40px;
}

.header-left {
  align-items: center;
  align-self: stretch;
  display: flex;
  gap: 44px;
}

.wordmark {
  color: var(--ink);
  font-family: var(--serif);
  font-size: 21px;
  letter-spacing: -0.01em;
}

.wordmark span {
  color: var(--ink-faint);
}

.primary-nav {
  align-items: stretch;
  align-self: stretch;
  display: flex;
  gap: 28px;
}

.primary-nav a {
  align-items: center;
  border-bottom: 2px solid transparent;
  color: var(--ink-faint);
  display: flex;
  font-size: 15px;
  font-weight: 600;
}

.primary-nav a:hover {
  color: var(--ink);
}

.primary-nav a[aria-current='page'] {
  border-bottom-color: var(--green);
  color: var(--ink);
}

.site-header > nav {
  align-items: center;
  display: flex;
  gap: 12px;
}

.language-toggle {
  background: #efeae0;
  border-radius: 999px;
  display: inline-flex;
  padding: 3px;
}

.language-toggle > * {
  align-items: center;
  border-radius: 999px;
  color: var(--ink-muted);
  display: flex;
  font-size: 12.5px;
  font-weight: 600;
  height: 30px;
  letter-spacing: 0.04em;
  padding: 0 13px;
}

.language-toggle [aria-current='true'] {
  background: var(--card);
  color: var(--ink);
  font-weight: 700;
}

.header-action {
  align-items: center;
  background: var(--ink);
  border-radius: 999px;
  color: var(--paper);
  display: flex;
  font-size: 14.5px;
  font-weight: 600;
  height: 40px;
  padding: 0 20px;
}

.header-action:hover {
  color: var(--paper);
}

/* Account menu ------------------------------------------------------------ */

.account-trigger {
  align-items: center;
  background: none;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: inherit;
  cursor: pointer;
  display: flex;
  gap: 9px;
  padding: 5px 14px 5px 5px;
  transition: background-color 150ms ease;
}

.account-trigger:hover,
.account-trigger[aria-expanded='true'] {
  background: var(--sunk);
}

.avatar {
  align-items: center;
  background: var(--green);
  border-radius: 50%;
  color: var(--paper);
  display: flex;
  font-size: 13px;
  font-weight: 700;
  height: 30px;
  justify-content: center;
  width: 30px;
}

.account-name {
  font-size: 14px;
  font-weight: 600;
}

/* A popover lives in the top layer, so it is positioned against the viewport
 * rather than its DOM parent: `placeMenu` in app.js sets top/left on open. The
 * UA centres it by default, which `inset: auto` undoes. */
.menu-popover {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: 0 20px 44px -18px rgb(30 39 35 / 32%);
  inset: auto;
  margin: 0;
  padding: 8px;
  position: fixed;
}

.menu-popover:popover-open {
  animation: menu-in 120ms ease-out;
}

@keyframes menu-in {
  from {
    opacity: 0;
    translate: 0 -4px;
  }
}

.account-panel {
  display: grid;
  gap: 2px;
  width: 262px;
}

.account-identity,
.account-language {
  align-items: center;
  display: flex;
  gap: 10px;
  justify-content: space-between;
  margin: 0;
  padding: 12px;
}

.account-identity {
  display: grid;
  font-size: 14px;
  gap: 3px;
  justify-items: start;
  overflow-wrap: anywhere;
}

.account-identity span,
.account-language span:first-child {
  color: var(--ink-faint);
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.account-language {
  border-top: 1px solid var(--rule-soft);
}

.account-language span:first-child {
  color: var(--ink);
  font-size: 14.5px;
  font-weight: 500;
  letter-spacing: normal;
  text-transform: none;
}

.sign-out {
  background: none;
  border: 0;
  border-top: 1px solid var(--rule-soft);
  color: var(--clay);
  cursor: pointer;
  font-size: 14.5px;
  font-weight: 600;
  padding: 13px 12px;
  text-align: left;
}

/* Buttons ----------------------------------------------------------------- */

.primary-button,
.secondary-button {
  align-items: center;
  border: 0;
  border-radius: 999px;
  cursor: pointer;
  display: inline-flex;
  font-size: 15px;
  font-weight: 600;
  justify-content: center;
  min-height: 48px;
  padding: 0 22px;
  transition: background-color 150ms ease;
}

.primary-button {
  background: var(--green);
  color: var(--paper);
}

.primary-button:hover {
  background: var(--green-deep);
  color: var(--paper);
}

.secondary-button {
  background: var(--card);
  border: 1px solid var(--rule);
  color: var(--ink-muted);
}

.secondary-button:hover {
  background: var(--sunk);
}

.primary-button:disabled,
.secondary-button:disabled {
  cursor: wait;
  opacity: 0.55;
}

/* Landing ----------------------------------------------------------------- */

.landing {
  display: flex;
  flex-direction: column;
  min-height: calc(100svh - var(--header-height));
  padding: 0 40px;
}

.landing-copy {
  display: flex;
  flex-direction: column;
  flex-grow: 1;
  gap: 26px;
  justify-content: center;
  max-width: 900px;
}

.landing-copy h1 {
  font-size: clamp(52px, 8vw, 112px);
  letter-spacing: -0.03em;
  line-height: 0.98;
  margin: 0;
}

.landing-copy .lede {
  font-size: clamp(17px, 1.6vw, 21px);
  max-width: 30ch;
}

.landing-copy .primary-button {
  align-self: flex-start;
  min-height: 56px;
  padding: 0 30px;
}

.landing-footer {
  color: var(--ink-faint);
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  justify-content: space-between;
  padding-bottom: 44px;
}

.landing-footer p {
  font-size: 13.5px;
  margin: 0;
}

/* Sign in ----------------------------------------------------------------- */

.auth-shell {
  align-items: center;
  display: grid;
  gap: 72px;
  grid-template-columns: minmax(0, 1fr) 424px;
  margin: 0 auto;
  max-width: 1200px;
  min-height: calc(100svh - var(--header-height));
  padding: 40px 40px 72px;
}

.auth-intro {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.auth-intro h1 {
  font-size: clamp(44px, 6vw, 72px);
  letter-spacing: -0.025em;
  line-height: 1;
  margin: 0;
}

.auth-intro p:not(.eyebrow) {
  color: var(--ink-muted);
  font-size: 19px;
  line-height: 1.5;
  margin: 0;
  max-width: 42ch;
}

.auth-content {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 22px;
  box-shadow: 0 24px 48px -32px rgb(30 39 35 / 25%);
  padding: 30px;
}

.auth-content form {
  display: grid;
  gap: 16px;
}

.auth-content label {
  display: grid;
  font-size: 13.5px;
  font-weight: 600;
  gap: 9px;
}

.auth-content input {
  background: var(--paper);
  border: 1px solid #e0dace;
  border-radius: 12px;
  color: var(--ink);
  font-size: 16px;
  min-height: 54px;
  outline: none;
  padding: 0 16px;
}

.auth-content input:focus {
  background: var(--card);
  border-color: var(--green);
}

.auth-content .primary-button,
.auth-content .secondary-button {
  width: 100%;
}

.auth-note {
  border-top: 1px solid var(--rule-soft);
  color: var(--ink-muted);
  font-size: 13px;
  line-height: 1.55;
  margin: 20px 0 0;
  padding-top: 18px;
}

.form-error {
  color: #b42318;
  font-size: 14px;
  margin: 2px 0 4px;
}

/* Pages ------------------------------------------------------------------- */

.page {
  display: flex;
  flex-direction: column;
  gap: 26px;
  margin: 0 auto;
  max-width: 1240px;
  padding: 40px 40px 56px;
}

.page-heading {
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-width: 70ch;
}

.page-heading h1 {
  font-size: clamp(34px, 4vw, 46px);
  line-height: 1.06;
  margin: 0;
}

.section-heading {
  align-items: baseline;
  display: flex;
  gap: 14px;
}

.section-heading h2 {
  font-size: 30px;
  margin: 0;
}

.section-heading::after {
  background: var(--rule);
  content: '';
  flex-grow: 1;
  height: 1px;
}

.badge {
  background: var(--green-wash);
  border-radius: 7px;
  color: var(--green-deep);
  display: inline-flex;
  font-size: 12.5px;
  font-weight: 700;
  letter-spacing: 0.04em;
  padding: 5px 10px;
}

.badge-warn {
  background: var(--clay-wash);
  color: var(--clay-deep);
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.connect-panel {
  align-items: center;
  background: var(--green-wash);
  border: 1px solid #cfe0d4;
  border-radius: 20px;
  display: flex;
  flex-wrap: wrap;
  gap: 26px;
  justify-content: space-between;
  padding: 24px 26px;
}

.connect-panel h2 {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  font-size: 24px;
  gap: 11px;
  margin: 0 0 6px;
}

.connect-panel p {
  color: #4b6355;
  font-size: 14.5px;
  line-height: 1.55;
  margin: 0;
  max-width: 64ch;
}

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

.panel {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: 0 1px 2px rgb(30 39 35 / 4%);
  padding: 24px;
}

.panel h2,
.panel h3 {
  font-size: 24px;
  margin: 0 0 18px;
}

.panel dl {
  margin: 0;
}

.panel dl div {
  align-items: baseline;
  border-top: 1px solid var(--rule-soft);
  display: grid;
  gap: 20px;
  grid-template-columns: 130px minmax(0, 1fr);
  padding: 14px 0;
}

.panel dt {
  color: var(--ink-faint);
  font-size: 12.5px;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.panel dd {
  font-size: 15px;
  margin: 0;
  overflow-wrap: anywhere;
}

.panel form {
  display: grid;
  gap: 16px;
  max-width: 420px;
}

.panel label {
  display: grid;
  font-size: 13px;
  font-weight: 600;
  gap: 8px;
}

.panel input,
.panel select {
  background: var(--paper);
  border: 1px solid #e0dace;
  border-radius: 10px;
  min-height: 46px;
  padding: 0 13px;
}

.panel .field-help {
  color: var(--ink-muted);
  font-size: 12.5px;
  line-height: 1.55;
  margin: 16px 0 0;
  max-width: 52ch;
}

.action-status {
  font-size: 14px;
  margin: 0;
  overflow-wrap: anywhere;
}

.action-status a {
  text-decoration: underline;
}

.residents {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.resident-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.resident-list li {
  align-items: center;
  border-top: 1px solid var(--rule-soft);
  display: flex;
  flex-wrap: wrap;
  gap: 10px 16px;
  justify-content: space-between;
  padding: 14px 0;
}

.resident-list li:first-child {
  border-top: 0;
  padding-top: 0;
}

.resident-list li:last-child {
  padding-bottom: 0;
}

.resident-identity {
  align-items: center;
  display: flex;
  gap: 12px;
  min-width: 0;
}

.resident-name {
  display: grid;
  /* A grid item will not shrink past its min-content width on its own, and a
   * name can be a whole email address when nobody set one. */
  grid-template-columns: minmax(0, 1fr);
  min-width: 0;
}

.resident-name strong {
  font-size: 15px;
  font-weight: 600;
  overflow-wrap: anywhere;
}

.resident-you {
  color: var(--ink-muted);
  font-size: 12.5px;
  font-weight: 600;
}

.resident-email {
  color: var(--ink-muted);
  font-size: 13px;
  overflow-wrap: anywhere;
}

.resident-tags {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.row-menu-trigger {
  align-items: center;
  background: none;
  border: 0;
  border-radius: 999px;
  color: var(--ink-faint);
  cursor: pointer;
  display: flex;
  height: 32px;
  justify-content: center;
  padding: 0;
  transition:
    background-color 150ms ease,
    color 150ms ease;
  width: 32px;
}

.row-menu-trigger svg {
  fill: currentcolor;
}

.row-menu-trigger:hover,
.row-menu-trigger[aria-expanded='true'] {
  background: var(--sunk);
  color: var(--ink);
}

.row-menu-panel {
  border-radius: 12px;
  display: grid;
  min-width: 180px;
  padding: 6px;
}

.row-menu-panel button {
  background: none;
  border: 0;
  border-radius: 8px;
  color: var(--ink);
  cursor: pointer;
  font: inherit;
  font-size: 14px;
  padding: 9px 12px;
  text-align: left;
}

.row-menu-panel button:hover {
  background: var(--sunk);
}

.row-menu-danger {
  color: var(--clay-deep);
}

.row-menu-danger:hover {
  background: var(--clay-wash);
}

/* Never set `display` on the dialog element: an author rule outranks the
 * browser's `dialog:not([open])` and the confirmation renders inline, always
 * open. Layout goes on the wrapper inside. */
#remove-resident-dialog {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: 0 30px 70px -30px rgb(30 39 35 / 45%);
  color: var(--ink);
  max-width: min(430px, calc(100% - 24px));
  padding: 26px;
  width: min(430px, calc(100% - 24px));
}

#remove-resident-dialog::backdrop {
  background: rgb(30 39 35 / 34%);
}

.confirm-body {
  display: grid;
  gap: 18px;
}

.confirm-body h2 {
  font-size: 26px;
  margin: 0;
}

.confirm-body p {
  color: var(--ink-muted);
  font-size: 15px;
  line-height: 1.55;
  margin: 0;
}

.dialog-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.dialog-actions .primary-button,
.dialog-actions .danger-button {
  flex-grow: 1;
}

.danger-button {
  background: var(--clay-deep);
  border: 0;
  border-radius: 999px;
  color: var(--paper);
  cursor: pointer;
  font: inherit;
  font-weight: 600;
  min-height: 44px;
  padding: 0 22px;
}

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

/* A signed-in visitor who is not a resident yet --------------------------- */

.state-page {
  align-items: center;
  justify-content: center;
  min-height: calc(100svh - var(--header-height));
}

.state-card {
  display: flex;
  flex-direction: column;
  gap: 16px;
  max-width: 56ch;
  text-align: center;
}

.state-card h1 {
  font-size: clamp(32px, 4vw, 42px);
  letter-spacing: -0.02em;
  margin: 0;
}

.state-card .eyebrow,
.state-card .lede {
  align-self: center;
}

.state-email {
  align-self: center;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--ink-muted);
  font-size: 14.5px;
  margin: 6px 0 0;
  padding: 10px 18px;
}

/* Telegram playground ----------------------------------------------------- */

.playground {
  margin: 0 auto;
  max-width: 1100px;
  padding: 40px 40px 48px;
}

.playground-heading {
  max-width: 80ch;
}

.playground-heading h1 {
  font-size: clamp(34px, 5vw, 52px);
  letter-spacing: -0.025em;
  line-height: 1.04;
  margin: 20px 0 16px;
}

.playground-heading > p:last-child {
  color: var(--ink-muted);
  font-size: 17px;
  line-height: 1.55;
  margin: 0;
}

.playground-controls,
.playground-worker {
  background: var(--sunk);
  border: 1px solid #e7e1d5;
  border-radius: 18px;
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin-top: 24px;
  padding: 20px;
}

.playground-controls label,
.playground-worker label {
  display: grid;
  font-size: 13px;
  font-weight: 600;
  gap: 8px;
}

.playground-controls select,
.playground-worker input,
.playground-message-form input {
  background: var(--card);
  border: 1px solid #e0dace;
  border-radius: 10px;
  min-height: 46px;
  padding: 0 13px;
}

.playground-clock {
  display: flex;
  flex-direction: column;
  font-size: 13px;
  gap: 10px;
  justify-content: center;
}

.playground-clock span {
  color: var(--ink-faint);
  font-weight: 600;
}

.playground-clock strong {
  font-variant-numeric: tabular-nums;
}

.playground-chat {
  border: 1px solid var(--border);
  border-radius: 18px;
  margin-top: 12px;
  padding: 20px;
}

.playground-transcript {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 320px;
  overflow-y: auto;
  padding: 8px 0 20px;
}

.playground-message {
  align-self: flex-start;
  background: var(--sunk);
  border-radius: 16px 16px 16px 4px;
  line-height: 1.45;
  max-width: min(78%, 620px);
  padding: 11px 14px;
  white-space: pre-wrap;
}

.playground-message.user {
  align-self: flex-end;
  background: var(--green);
  border-radius: 16px 16px 4px;
  color: var(--paper);
}

.playground-message.system {
  align-self: center;
  background: transparent;
  color: var(--ink-faint);
  font-size: 13px;
  text-align: center;
}

.playground-examples {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-bottom: 10px;
}

.playground-examples button {
  background: var(--sunk);
  border: 0;
  border-radius: 999px;
  cursor: pointer;
  font-size: 13px;
  padding: 9px 13px;
}

.playground-message-form {
  display: grid;
  gap: 8px;
  grid-template-columns: 1fr auto;
}

.playground-worker {
  grid-template-columns: minmax(180px, 1fr) repeat(3, auto);
  margin-top: 12px;
}

.playground-worker label span {
  align-items: center;
  display: flex;
  gap: 8px;
}

.playground-worker input {
  width: 110px;
}

/* Narrow ------------------------------------------------------------------ */

@media (max-width: 860px) {
  :root {
    --header-height: 64px;
  }

  .site-header {
    gap: 12px;
    padding: 0 20px;
  }

  .header-left {
    gap: 20px;
  }

  .primary-nav {
    gap: 18px;
  }

  .account-name {
    display: none;
  }

  .landing,
  .auth-shell,
  .page,
  .playground {
    min-height: calc(100svh - var(--header-height));
    padding-left: 20px;
    padding-right: 20px;
  }

  .auth-shell {
    align-content: center;
    display: flex;
    flex-direction: column;
    gap: 28px;
    padding-bottom: 40px;
  }

  .auth-content {
    padding: 22px;
  }

  .page {
    padding-top: 28px;
  }

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

  .connect-panel .primary-button {
    width: 100%;
  }

  .playground-controls,
  .playground-worker {
    grid-template-columns: 1fr;
  }

  .playground-message {
    max-width: 90%;
  }
}

/* Phone -------------------------------------------------------------------- */

/* Below this width the wordmark, the navigation and the account menu stop
 * fitting on one line, and the account menu -- with Sign out inside it -- was
 * pushed off the right edge. The header becomes a two-row grid instead: the
 * wordmark and the account menu share the top row, the navigation sits below. */
@media (max-width: 560px) {
  :root {
    --header-height: 86px;
  }

  .site-header {
    align-items: center;
    column-gap: 12px;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    height: auto;
    min-height: var(--header-height);
    padding: 10px 16px;
    row-gap: 2px;
  }

  /* Let the wordmark and the navigation place themselves on the header grid. */
  .header-left {
    display: contents;
  }

  .wordmark {
    font-size: 18px;
  }

  .account-menu {
    grid-column: 2;
    grid-row: 1;
  }

  .primary-nav {
    gap: 22px;
    grid-column: 1 / -1;
  }

  .landing,
  .auth-shell,
  .page,
  .playground {
    padding-left: 16px;
    padding-right: 16px;
  }

  .landing {
    padding-bottom: 8px;
  }

  .landing-footer {
    padding-bottom: 28px;
  }
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  .primary-button,
  .secondary-button {
    transition: none;
  }
}
