:root {
  --bg: #fbf6ee;
  --surface: #ffffff;
  --text: #2b2a26;
  --muted: #6b665c;
  --border: #e6dccb;
  --primary: #5c3d2e;
  --primary-hover: #4a3125;
  /* The theme colour for text on the page background */
  --primary-text: #5c3d2e;
  /* Outlines and focus borders on the page background */
  --primary-line: #5c3d2e;
  --on-primary: #ffffff;
  --accent: #9a5631;
  --online: #23894c;
  --online-glow: rgba(35, 137, 76, 0.2);
  --error: #b3261e;
  --on-error: #ffffff;
  --error-focus: rgba(179, 38, 30, 0.2);
  --focus: rgba(92, 61, 46, 0.25);
  --shadow: 0 1px 2px rgba(43, 42, 38, 0.06), 0 8px 24px rgba(43, 42, 38, 0.08);
  --radius: 14px;
  --font-body: "DM Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-heading: "Fraunces", Georgia, "Times New Roman", serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1a17;
    --surface: #26241f;
    --text: #f1ece3;
    --muted: #a8a092;
    --border: #3a362e;
    --primary: #432c1c;
    --primary-hover: #523727;
    --primary-text: #d1a68d;
    --primary-line: #8b5e47;
    --on-primary: #ffffff;
    --accent: #b06a3e;
    --online: #4cc985;
    --online-glow: rgba(76, 201, 133, 0.25);
    --error: #f2948a;
    --on-error: #3a0b07;
    --error-focus: rgba(242, 148, 138, 0.3);
    --focus: rgba(166, 116, 90, 0.4);
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.35);
    color-scheme: dark;
  }
}

[hidden] {
  display: none !important;
}

/* No visible scroll bars anywhere; scrolling still works as normal */
* {
  scrollbar-width: none;
}

*::-webkit-scrollbar {
  display: none;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font-body);
  font-size: 1rem;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  /* Never let the page swipe sideways on phones; clip (unlike hidden) keeps sticky headers working */
  overflow-x: clip;
}

h1,
h2 {
  font-family: var(--font-heading);
  font-weight: 600;
  line-height: 1.15;
  margin: 0;
}

a {
  color: var(--primary-text);
}

/* Layout */

.center {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 32px 16px;
  text-align: center;
}

/* Home */

.hero h1 {
  font-size: clamp(2.4rem, 8vw, 4.5rem);
  letter-spacing: -0.02em;
}

.hero h1::after {
  content: "";
  display: block;
  width: 64px;
  height: 4px;
  margin: 20px auto 0;
  border-radius: 2px;
  background: var(--accent);
}

.hero h2 {
  max-width: 34ch;
  margin-top: 20px;
  font-family: var(--font-body);
  font-size: clamp(1.1rem, 3.5vw, 1.4rem);
  font-weight: 400;
  color: var(--muted);
}

.hero .button,
.hero .options {
  margin-top: 36px;
}

.options {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  justify-content: center;
  animation: fade-in 0.25s ease-out;
}

@keyframes fade-in {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
}

/* Buttons */

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  padding: 12px 28px;
  font: 600 1rem var(--font-body);
  color: var(--on-primary);
  background: var(--primary);
  border: 2px solid var(--primary);
  border-radius: 999px;
  text-decoration: none;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
}

.button:hover {
  background: var(--primary-hover);
  border-color: var(--primary-hover);
}

.button:active {
  transform: translateY(1px);
}

.button:focus-visible,
input:focus-visible,
textarea:focus-visible,
.restaurant summary:focus-visible {
  outline: none;
  box-shadow: 0 0 0 4px var(--focus);
}

.button.secondary {
  color: var(--primary-text);
  background: transparent;
  border-color: var(--primary-line);
}

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

.button.small {
  min-height: 38px;
  padding: 6px 18px;
  font-size: 0.9rem;
}

.button:disabled {
  opacity: 0.6;
  cursor: wait;
}

/* Cards and forms */

.card {
  width: 100%;
  max-width: 400px;
  padding: 32px 28px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  text-align: left;
}

.card h1 {
  font-size: 2rem;
  margin-bottom: 24px;
}

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

label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-weight: 600;
  font-size: 0.9rem;
}

.required {
  color: var(--error);
}

/* A label with its input as siblings, for inputs that carry extras like suggestions */
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

/* A field's label with something on its right, like a count */
.field-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}

.photo-count {
  font-size: 0.85rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

/* Hidden from view, but still there for keyboards and screen readers */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

form .button.add-photos {
  align-self: flex-start;
  width: auto;
  margin-top: 0;
}

.visually-hidden:focus-visible + .add-photos {
  box-shadow: 0 0 0 4px var(--focus);
}

/* All 5 photos added */
.visually-hidden:disabled + .add-photos {
  opacity: 0.45;
  cursor: not-allowed;
  pointer-events: none;
}

.photo-list {
  display: grid;
  /* minmax(0, ...) so big photos can't stretch the columns past the card's edge */
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin: 4px 0 0;
  padding: 0;
  list-style: none;
}

.photo-list li {
  position: relative;
  min-width: 0;
  aspect-ratio: 1;
}

.photo-list img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  border: 1px solid var(--border);
  border-radius: 8px;
}

/* Sits inside the photo's corner, so the row lines up with the card's edges */
.photo-remove {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 26px;
  height: 26px;
  padding: 0;
  font: 600 1rem/1 var(--font-body);
  color: #ffffff;
  background: rgba(43, 42, 38, 0.75);
  border: 1.5px solid rgba(255, 255, 255, 0.9);
  border-radius: 50%;
  cursor: pointer;
}

.photo-remove:focus-visible {
  outline: none;
  box-shadow: 0 0 0 4px var(--focus);
}

/* Suggestions listed under an input as you type */
.combo {
  position: relative;
}

.suggestions {
  position: absolute;
  z-index: 1000;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  max-height: 280px;
  margin: 0;
  padding: 4px;
  overflow-y: auto;
  list-style: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow);
}

.suggestions li {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  padding: 8px 10px;
  border-radius: 6px;
  cursor: pointer;
}

.suggestions li:hover,
.suggestions li[aria-selected="true"] {
  background: var(--focus);
}

.suggestion-main {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.suggestion-detail {
  flex: none;
  font-size: 0.85rem;
  color: var(--muted);
}

.map {
  height: 220px;
  border: 1px solid var(--border);
  border-radius: 10px;
}

.map .leaflet-control-attribution {
  font-size: 0.65rem;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.6);
}

input[aria-invalid="true"],
input[aria-invalid="true"]:focus-visible {
  border-color: var(--error);
}

input[aria-invalid="true"]:focus-visible {
  box-shadow: 0 0 0 4px var(--error-focus);
}

/* Sign in: SWP - [123] - [ABC] */
.swap-code-input {
  display: flex;
  align-items: center;
  gap: 8px;
  font: 600 1.25rem var(--font-body);
  letter-spacing: 0.08em;
}

.swap-code-input input {
  width: 5.5em;
  font: inherit;
  letter-spacing: inherit;
  text-align: center;
}

.swap-code-input input::placeholder {
  color: var(--muted);
  opacity: 0.45;
}

/* After creating a swap: its swap number, big enough to read off a screenshot */
.swap-made {
  display: flex;
  flex-direction: column;
  gap: 12px;
  text-align: center;
}

.swap-made h1 {
  margin-bottom: 0;
}

.swap-made h1:focus {
  outline: none;
}

.swap-made p {
  margin: 0;
}

.swap-made .swap-code {
  margin: 12px 0;
  padding: 18px 12px;
  font: 600 clamp(1.8rem, 9vw, 2.6rem) var(--font-body);
  letter-spacing: 0.1em;
  color: var(--primary-text);
  background: var(--bg);
  border: 2px dashed var(--primary-line);
  border-radius: var(--radius);
  user-select: all;
}

.swap-made .button {
  margin-top: 8px;
}

.field-problem {
  margin: 0;
  font-size: 0.85rem;
  color: var(--error);
}

.field-problem:empty {
  display: none;
}

.field-note {
  margin: 0;
  font-size: 0.85rem;
  color: var(--muted);
}

.field-note:empty {
  display: none;
}

input,
textarea {
  width: 100%;
  padding: 12px 14px;
  font: 1rem var(--font-body);
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  transition: border-color 0.15s, box-shadow 0.15s;
}

input:focus-visible,
textarea:focus-visible {
  border-color: var(--primary-line);
}

textarea {
  resize: vertical;
  min-height: 96px;
}

input[type="file"] {
  padding: 10px;
  font-size: 0.9rem;
  cursor: pointer;
}

input[type="file"]::file-selector-button {
  margin-right: 12px;
  padding: 6px 14px;
  font: 600 0.85rem var(--font-body);
  color: var(--primary-text);
  background: transparent;
  border: 1.5px solid var(--primary-line);
  border-radius: 999px;
  cursor: pointer;
}

form .button {
  width: 100%;
  margin-top: 4px;
}

.error {
  min-height: 1.5em;
  margin: 0;
  font-size: 0.9rem;
  color: var(--error);
}

.form-footer {
  margin: 20px 0 0;
  font-size: 0.9rem;
  color: var(--muted);
  text-align: center;
}

.back {
  max-width: 400px;
  width: 100%;
  margin: 0 auto 16px;
  font-size: 0.9rem;
  color: var(--muted);
  text-align: left;
  text-decoration: none;
}

.back:hover {
  color: var(--text);
}

/* Dashboard */

.dashboard {
  max-width: 720px;
  margin: 0 auto;
  padding: 16px;
}

/* Stays at the top of the screen while the restaurants scroll under it */
.banner {
  position: sticky;
  top: 0;
  z-index: 500;
  /* The page colour around the green card, so the list scrolls out of sight under it */
  padding: 12px 16px;
  background: var(--bg);
}

/* Name on the left, icon buttons on the right, on one line at every width */
.banner-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  /* Same width as the restaurant cards below */
  max-width: 688px;
  margin: 0 auto;
  padding: 14px 16px;
  color: var(--on-primary);
  background: var(--primary);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

/* A long name is cut short with "…" rather than pushing the buttons off the banner */
/* The restaurant's name with its swap number under it */
.banner-title {
  min-width: 0;
}

.banner h1 {
  overflow: hidden;
  font-size: clamp(1.3rem, 4.5vw, 1.7rem);
  white-space: nowrap;
  text-overflow: ellipsis;
}

.banner-code {
  margin: 2px 0 0;
  font-size: 0.85rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  opacity: 0.75;
}

.banner-actions {
  display: flex;
  flex-shrink: 0;
  gap: 8px;
}

/* Round icon buttons on the green banner; the label is in aria-label and the hover tooltip */
.banner-icon {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  padding: 0;
  color: var(--on-primary);
  background: rgba(255, 255, 255, 0.12);
  border: none;
  border-radius: 50%;
  cursor: pointer;
  transition: background 0.15s;
}

.banner-icon:hover {
  background: rgba(255, 255, 255, 0.24);
}

.banner-icon:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--focus);
}

.banner-icon svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.banner-icon .banner-icon-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  /* White with red text, so the count stands out on any banner colour */
  color: var(--accent);
  background: var(--on-primary);
  border: 2px solid var(--primary);
}

.button.danger {
  color: var(--on-error);
  background: var(--error);
  border-color: var(--error);
}

.button.danger:hover {
  background: var(--error);
  border-color: var(--error);
  filter: brightness(0.92);
}

/* "Are you sure?" box */
.confirm {
  max-width: min(400px, calc(100% - 32px));
  color: var(--text);
}

.confirm::backdrop {
  background: rgba(0, 0, 0, 0.45);
}

.confirm h2 {
  font-size: 1.5rem;
}

.confirm p {
  margin: 12px 0 0;
}

.confirm .error:empty {
  display: none;
}

.confirm-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 24px;
}

.confirm-actions .button {
  flex: 1 1 140px;
}

.section-title {
  font-size: 1.5rem;
  margin-bottom: 16px;
}

.restaurant-list {
  display: grid;
  gap: 12px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.card.restaurant {
  max-width: none;
  padding: 0;
  overflow: hidden;
  transition: border-color 0.15s;
}

.restaurant:hover,
.restaurant[open] {
  border-color: var(--primary-line);
}

.restaurant summary {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 16px;
  border-radius: var(--radius);
  list-style: none;
  cursor: pointer;
  outline: none;
}

.restaurant summary::-webkit-details-marker {
  display: none;
}

.restaurant-text {
  flex: 1;
  min-width: 0;
}

.chevron {
  flex: none;
  width: 10px;
  height: 10px;
  margin-right: 6px;
  border-right: 2px solid var(--muted);
  border-bottom: 2px solid var(--muted);
  transform: translateY(-3px) rotate(45deg);
  transition: transform 0.2s;
}

.restaurant[open] .chevron {
  transform: translateY(2px) rotate(-135deg);
}

.restaurant-body {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 16px;
  border-top: 1px solid var(--border);
  animation: fade-in 0.2s ease-out;
}

.restaurant-text h3 {
  margin: 0;
  font-size: 1.05rem;
}

.restaurant-text p {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

/* Online dot: green when the restaurant has the site open */
.presence {
  display: inline-block;
  flex: none;
  width: 9px;
  height: 9px;
  margin-right: 8px;
  vertical-align: 2px;
  border-radius: 50%;
  background: var(--muted);
  opacity: 0.45;
  transition: background 0.2s, box-shadow 0.2s, opacity 0.2s;
}

.presence.online {
  opacity: 1;
  background: var(--online);
  box-shadow: 0 0 0 3px var(--online-glow);
}

/* Restaurant dropdown contents */

.restaurant-body h4 {
  margin: 0 0 -8px;
  font-size: 0.8rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.no-photos {
  margin: 0;
  padding: 20px;
  border: 2px dashed var(--border);
  border-radius: 10px;
  color: var(--muted);
  text-align: center;
}

.description {
  margin: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.muted {
  color: var(--muted);
}

.gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 10px;
}

.gallery a {
  display: block;
  overflow: hidden;
  border-radius: var(--radius);
  background: var(--border);
  aspect-ratio: 4 / 3;
}

.gallery img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.2s;
}

.gallery a:hover img {
  transform: scale(1.04);
}

.empty {
  margin: 0;
  padding: 40px 24px;
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  color: var(--muted);
  text-align: center;
}

/* The map runs to the bottom of the screen */
.dashboard.map-view {
  padding-bottom: 0;
}

.dashboard .section-title:not(:first-child) {
  margin-top: 40px;
}

/* "Restaurants around" with the List | Map switch beside it */
.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.section-head .section-title {
  margin: 0;
  font-size: clamp(1.25rem, 5vw, 1.5rem);
}

.view-switch {
  display: inline-flex;
  flex: none;
  padding: 3px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
}

.view-switch button {
  min-width: 64px;
  padding: 6px 14px;
  font: 600 0.9rem var(--font-body);
  color: var(--muted);
  background: none;
  border: none;
  border-radius: 999px;
  cursor: pointer;
}

.view-switch button[aria-pressed="true"] {
  color: var(--on-primary);
  background: var(--primary);
}

.view-switch button:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--focus);
}

/* The map of restaurants: fills the screen below the banner */
/* Its height is set to fill the screen below it (see fitMapHeight) */
.restaurant-map {
  position: relative;
  height: calc(100vh - 260px);
  min-height: 360px;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.map-canvas {
  width: 100%;
  height: 100%;
}

.map-pin {
  background: var(--primary);
  border: 3px solid #ffffff;
  border-radius: 50%;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.35);
  cursor: pointer;
}

.map-pin.mine {
  background: var(--accent);
  cursor: default;
}

.leaflet-tooltip.pin-label {
  padding: 2px 8px;
  font: 600 0.8rem var(--font-body);
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.15);
}

.leaflet-tooltip.pin-label.mine {
  color: #ffffff;
  background: var(--accent);
  border-color: var(--accent);
}

.leaflet-tooltip-top.pin-label::before {
  display: none;
}

.labels-hidden .pin-label {
  display: none;
}

/* The tapped restaurant's card, over the bottom of the map */
.card.map-card {
  position: absolute;
  right: 10px;
  bottom: 10px;
  left: 10px;
  z-index: 1000;
  width: auto;
  max-width: none;
  max-height: 65%;
  padding: 0;
  overflow-y: auto;
  animation: fade-in 0.15s ease-out;
}

@media (min-width: 640px) {
  .card.map-card {
    right: auto;
    width: 340px;
    max-height: calc(100% - 20px);
  }
}

.map-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 6px 0 16px;
}

.map-card-head h3 {
  margin: 0;
  font-size: 1.1rem;
}

.map-card .restaurant-body {
  border-top: none;
  padding-top: 8px;
}

/* As wide as the dropdown it's in */
.message-button {
  align-self: stretch;
}

/* Chat list on the dashboard */

.card.chat-item {
  display: flex;
  align-items: center;
  gap: 16px;
  max-width: none;
  padding: 14px 16px;
  color: inherit;
  text-decoration: none;
  transition: border-color 0.15s;
}

.chat-item:hover,
.chat-item:focus-visible {
  border-color: var(--primary-line);
  outline: none;
}

.preview {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.chat-meta {
  flex: none;
  align-self: stretch;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  justify-content: space-between;
  gap: 6px;
}

.chat-time {
  font-size: 0.8rem;
  color: var(--muted);
}

.chat-item.unread {
  border-color: var(--accent);
}

.chat-item.unread .preview {
  font-weight: 600;
  color: var(--text);
}

.chat-item.unread .chat-time {
  color: var(--accent);
  font-weight: 600;
}

/* Red notification bubble with a count */
.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 22px;
  height: 22px;
  padding: 0 7px;
  font: 700 0.75rem/1 var(--font-body);
  color: #fff;
  background: var(--accent);
  border-radius: 999px;
  vertical-align: middle;
}

.section-title .badge {
  margin-left: 6px;
  font-size: 0.8rem;
}

/* Chat page */

/* The chats panel: full screen on phones, a floating window on bigger screens */
.chat-panel {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  animation: fade-in 0.15s ease-out;
}

@media (min-width: 640px) {
  .chat-panel {
    inset: auto 24px 24px auto;
    width: 400px;
    height: min(680px, calc(100vh - 48px));
    height: min(680px, calc(100dvh - 48px));
    overflow: hidden;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
  }
}

/* On phones the panel covers the page, so stop the page behind it scrolling */
@media (max-width: 639px) {
  body.chat-open {
    overflow: hidden;
  }
}

.chat-view {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-height: 0;
}

.panel-header {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px;
}

.panel-header h2 {
  flex: 1;
  font-size: 1.5rem;
}

.chat-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 0;
  padding: 8px 16px 16px;
  overflow-y: auto;
  list-style: none;
}

.chat-view > .empty {
  margin: 8px 16px;
}

.link-like {
  padding: 0;
  font: inherit;
  color: var(--primary-text);
  text-decoration: underline;
  background: none;
  border: none;
  cursor: pointer;
}

.chat {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
  padding: 0 16px 12px;
}

.chat-header {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 0 -8px;
  padding: 8px 0;
}

.status {
  flex: none;
  padding: 4px 10px;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 999px;
}

/* Their name in the chat's top bar: tap it for their description and photos */
.chat-title {
  display: flex;
  /* Only as wide as the name; with the dot's auto margin, dot and name sit in the middle */
  flex: 0 1 auto;
  margin-right: auto;
  flex-direction: column;
  align-items: flex-start;
  min-width: 0;
  padding: 5px 16px;
  font: inherit;
  color: var(--primary-text);
  text-align: left;
  background: none;
  border: 2px solid var(--primary-line);
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

/* A capsule like a pill button; filled while their description and photos are open */
.chat-title:hover {
  background: color-mix(in srgb, var(--primary) 10%, transparent);
}

.chat-title[aria-expanded="true"] {
  color: var(--on-primary);
  background: var(--primary);
  border-color: var(--primary);
}

.chat-title:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--focus);
}

/* The name is the dropdown: an arrow right after it; a long name is cut short, never the arrow */
.chat-title-row {
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: 100%;
}

.chat-title-name {
  min-width: 0;
  overflow: hidden;
  font: 600 1.15rem/1.3 var(--font-heading);
  white-space: nowrap;
  text-overflow: ellipsis;
}

.chat-title .chevron {
  width: 8px;
  height: 8px;
  margin: 0;
  border-color: currentColor;
}

.chat-title[aria-expanded="true"] .chevron {
  transform: translateY(2px) rotate(-135deg);
}

/* The online dot before their name, a little bigger than in the chat list */
.chat-header .presence {
  width: 11px;
  height: 11px;
  margin: 0 2px 0 auto;
}

/* Opens under the top bar; scrolls inside itself so the messages and message bar stay on screen */
.card.chat-about {
  flex: none;
  max-width: none;
  max-height: 40vh;
  max-height: 40dvh;
  padding: 0;
  overflow-y: auto;
  animation: fade-in 0.15s ease-out;
}

.chat-about .restaurant-body {
  border-top: none;
  animation: none;
}

.chat-about .gallery {
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
}

.chat > .empty {
  margin-top: 24px;
}

.messages {
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 1;
  min-height: 0;
  margin: 0;
  padding: 16px 0;
  overflow-y: auto;
  list-style: none;
}

.no-messages {
  margin: 0;
  padding: 0 0 16px;
  color: var(--muted);
  text-align: center;
}

.message {
  max-width: min(80%, 520px);
  padding: 10px 14px;
  border-radius: 18px;
}

.message p {
  margin: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.message .meta {
  display: flex;
  gap: 8px;
  margin-top: 2px;
  font-size: 0.75rem;
  opacity: 0.75;
}

.message.mine .meta {
  justify-content: flex-end;
}

.receipt.seen {
  font-weight: 600;
  opacity: 1;
}

.message.mine {
  align-self: flex-end;
  color: var(--on-primary);
  background: var(--primary);
  border-bottom-right-radius: 4px;
}

.message.theirs {
  align-self: flex-start;
  background: var(--surface);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

.composer {
  flex-direction: row;
  align-items: flex-end;
  gap: 8px;
  padding-top: 12px;
}

/* Looks like one rounded input; the textarea inside it has no border of its own */
.message-box {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-width: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 28px;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.message-box:focus-within {
  border-color: var(--primary-line);
  box-shadow: 0 0 0 4px var(--focus);
}

.message-row {
  display: flex;
  align-items: flex-end;
  padding: 4px;
}

.composer textarea,
.composer textarea:focus-visible {
  min-height: 48px;
  max-height: 160px;
  padding: 12px 4px;
  resize: none;
  background: transparent;
  border: none;
  box-shadow: none;
}

.message-box .icon-button {
  width: 48px;
  height: 48px;
}

.message-box .icon-button.primary {
  width: 40px;
  height: 40px;
  margin: 4px;
}

.message-box .icon-button.primary svg {
  width: 22px;
  height: 22px;
}

/* Round buttons with just an icon: photos, microphone, send */
.icon-button {
  display: inline-flex;
  flex: none;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  padding: 0;
  color: var(--muted);
  background: transparent;
  border: none;
  border-radius: 50%;
  cursor: pointer;
}

.icon-button.primary {
  color: var(--on-primary);
  background: var(--primary);
}

.icon-button:disabled {
  opacity: 0.5;
  cursor: default;
}

.icon-button:focus-visible {
  outline: none;
  box-shadow: 0 0 0 4px var(--focus);
}

.icon-button svg {
  width: 24px;
  height: 24px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.composer {
  gap: 4px;
}

/* Shown instead of the message bar while recording a voice note */
.recorder {
  display: flex;
  align-items: center;
  gap: 10px;
  padding-top: 12px;
}

.recording-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--error);
  animation: recording-pulse 1.2s ease-in-out infinite;
}

@keyframes recording-pulse {
  50% {
    opacity: 0.3;
  }
}

.recording-time {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.recording-label {
  flex: 1;
  color: var(--muted);
}

.recorder .icon-button.primary {
  margin-left: auto;
}

/* Photo and voice note messages */
.message-photo {
  padding: 4px;
}

.message-photo img {
  display: block;
  width: 100%;
  max-width: 260px;
  max-height: 320px;
  object-fit: cover;
  border-radius: 14px;
}

.message-photo .caption {
  max-width: 260px;
  padding: 6px 10px 0;
}

.message-photo .meta {
  padding: 0 8px 2px;
}

/* Photos waiting in the message box for the send button */
.staged-photos {
  display: flex;
  gap: 8px;
  margin: 0;
  padding: 10px 10px 0;
  overflow-x: auto;
  list-style: none;
}

.staged-photos li {
  position: relative;
  flex: none;
  width: 64px;
  height: 64px;
}

.staged-photos img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  border: 1px solid var(--border);
  border-radius: 10px;
}

.staged-photos .photo-remove {
  top: 4px;
  right: 4px;
  width: 22px;
  height: 22px;
  font-size: 0.9rem;
}

.message-voice audio {
  display: block;
  width: 240px;
  max-width: 100%;
  height: 40px;
}

.chat > .error:empty {
  display: none;
}

.chat > .error {
  padding-top: 6px;
}

@media (max-width: 480px) {
  .card {
    padding: 24px 20px;
  }
}
