/* Textbook Exchange (Exchange/Index, New, Mine). */

.ex-hero {
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: 1.5rem 2rem;
  align-items: center;
  margin: 1.5rem 0;
  padding: 2rem 2.25rem;
  border-radius: 1.25rem;
  color: #fff;
  background:
    radial-gradient(circle at 85% 15%, rgba(253, 224, 71, 0.3), transparent 42%),
    radial-gradient(circle at 10% 90%, rgba(255, 255, 255, 0.12), transparent 40%),
    linear-gradient(135deg, #065f46, #0f766e 50%, #1e40af);
  overflow: hidden;
}

.ex-hero-slim {
  grid-template-columns: 1fr auto;
}

.ex-eyebrow {
  display: inline-block;
  padding: 0.25rem 0.8rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.16);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.ex-hero h1 {
  margin: 0.4rem 0 0.5rem;
  color: #fff;
  font-size: clamp(1.8rem, 1.3rem + 2vw, 2.7rem);
  font-weight: 900;
}

.ex-hero p {
  margin: 0;
  color: rgba(255, 255, 255, 0.9);
  font-size: 1.05rem;
}

.ex-hero-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  margin-top: 1.1rem;
}

.ex-hero-slim .ex-hero-actions {
  margin-top: 0;
}

.ex-hero-actions .btn-light {
  color: #065f46;
}

.ex-hero-note {
  margin-top: 0.75rem !important;
  font-size: 0.85rem !important;
}

.ex-stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem;
}

.ex-stat {
  display: grid;
  padding: 1rem;
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 1rem;
  background: rgba(255, 255, 255, 0.1);
  text-align: center;
  backdrop-filter: blur(4px);
}

.ex-stat strong {
  color: #fde68a;
  font-size: 2rem;
  font-weight: 900;
  line-height: 1.1;
}

.ex-stat span {
  font-size: 0.82rem;
  opacity: 0.9;
}

/* City chips. */
.ex-cities {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
  padding-bottom: 0.3rem;
  overflow-x: auto;
  scrollbar-width: thin;
}

.ex-city {
  display: inline-flex;
  flex: none;
  align-items: center;
  gap: 0.35rem;
  padding: 0.4rem 0.85rem;
  border: 1px solid var(--bb-sage-200);
  border-radius: 999px;
  background: #fff;
  color: var(--bb-sage-900);
  font-size: 0.88rem;
  font-weight: 600;
  text-decoration: none;
  transition: border-color 0.15s ease, background-color 0.15s ease;
}

.ex-city span {
  padding: 0 0.45rem;
  border-radius: 999px;
  background: var(--bb-sage-100);
  font-size: 0.75rem;
  font-weight: 800;
}

.ex-city:hover {
  border-color: #0f766e;
}

.ex-city.is-active {
  border-color: #0f766e;
  background: #0f766e;
  color: #fff;
}

.ex-city.is-active span {
  background: rgba(255, 255, 255, 0.25);
}

/* Tabs and search. */
.ex-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 1rem;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.25rem;
}

.ex-tabs {
  display: inline-flex;
  padding: 0.25rem;
  border-radius: 999px;
  background: var(--bb-sage-100);
}

.ex-tab {
  padding: 0.45rem 1.1rem;
  border-radius: 999px;
  color: var(--bb-sage-700);
  font-weight: 700;
  text-decoration: none;
}

.ex-tab.is-active {
  background: #fff;
  color: #065f46;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.ex-search {
  display: flex;
  flex: 1;
  gap: 0.5rem;
  max-width: 36rem;
}

.ex-search .form-control {
  flex: 1.4;
  min-width: 0;
}

.ex-search .form-select {
  flex: 1;
  min-width: 0;
}

/* Post cards. */
.ex-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 17rem), 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.ex-card {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 1rem 1.1rem;
  border: 1px solid var(--bb-sage-200);
  border-top: 4px solid #10b981;
  border-radius: 1rem;
  background: #fff;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.ex-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 24px rgba(15, 118, 110, 0.12);
}

.ex-card-need {
  border-top-color: #f59e0b;
}

.ex-card.is-match {
  box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.15);
}

.ex-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.ex-badge {
  display: inline-block;
  padding: 0.15rem 0.6rem;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 800;
}

.ex-badge-free { background: #dcfce7; color: #166534; }
.ex-badge-swap { background: #dbeafe; color: #1e40af; }
.ex-badge-sell { background: #f3e8ff; color: #6b21a8; }
.ex-badge-need { background: #fef3c7; color: #92400e; }

.ex-when {
  color: #6b7280;
  font-size: 0.78rem;
}

.ex-title {
  margin: 0;
  color: var(--bb-sage-900);
  font-size: 1.05rem;
  font-weight: 800;
  line-height: 1.3;
  overflow-wrap: anywhere;
}

.ex-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem 0.75rem;
  margin: 0;
  padding: 0;
  color: #4b5563;
  font-size: 0.84rem;
  list-style: none;
}

.ex-notes {
  margin: 0;
  padding: 0.5rem 0.65rem;
  border-radius: 0.6rem;
  background: var(--bb-sage-50);
  color: #4b5563;
  font-size: 0.85rem;
  overflow-wrap: anywhere;
}

.ex-card-foot {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-top: auto;
  padding-top: 0.6rem;
  border-top: 1px solid var(--bb-sage-100);
}

.ex-who {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  color: var(--bb-sage-900);
  font-size: 0.88rem;
  font-weight: 600;
}

.ex-avatar {
  display: grid;
  place-items: center;
  width: 1.8rem;
  height: 1.8rem;
  border-radius: 50%;
  background: linear-gradient(135deg, #0f766e, #1e40af);
  color: #fff;
  font-size: 0.8rem;
  font-weight: 800;
  text-transform: uppercase;
}

.ex-contact {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.ex-btn-wa {
  background: #25d366;
  color: #fff;
}

.ex-btn-wa:hover {
  background: #1ebe5a;
  color: #fff;
}

.ex-no-contact {
  color: #6b7280;
  font-size: 0.8rem;
}

/* Empty state and how it works. */
.ex-empty {
  max-width: 36rem;
  margin: 1rem auto 2rem;
  padding: 2rem 1.5rem;
  border: 1px dashed var(--bb-sage-300);
  border-radius: 1.25rem;
  background: #fff;
  text-align: center;
}

.ex-empty > span {
  font-size: 2.5rem;
}

.ex-empty h2 {
  margin: 0.5rem 0;
  color: var(--bb-sage-900);
  font-size: 1.3rem;
  font-weight: 800;
}

.ex-empty-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.5rem;
}

.ex-how {
  margin: 1rem 0 2.5rem;
  padding: 1.5rem;
  border-radius: 1.25rem;
  background: #ecfdf5;
}

.ex-how h2 {
  margin-bottom: 1rem;
  color: #065f46;
  font-size: 1.25rem;
  font-weight: 800;
}

.ex-how ol {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 15rem), 1fr));
  gap: 1rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.ex-how li {
  display: grid;
  gap: 0.25rem;
  padding: 1rem;
  border-radius: 1rem;
  background: #fff;
  color: #374151;
  font-size: 0.92rem;
}

.ex-how li > span {
  font-size: 1.6rem;
}

.ex-how strong {
  color: #065f46;
}

.ex-safety {
  margin: 1rem 0 0;
  color: #047857;
  font-size: 0.85rem;
}

/* The post form. */
.ex-form-wrap {
  max-width: 44rem;
  margin: 1.5rem auto 2.5rem;
}

.ex-form {
  padding: 0 0 1.5rem;
  border: 1px solid var(--bb-sage-200);
  border-radius: 1.25rem;
  background: #fff;
  overflow: hidden;
}

.ex-form > :not(.ex-form-head) {
  margin-inline: 1.5rem;
}

.ex-form-head {
  margin-bottom: 1.25rem;
  padding: 1.5rem;
  color: #fff;
  background: linear-gradient(135deg, #065f46, #0f766e 55%, #1e40af);
}

.ex-form-head h1 {
  margin: 0.4rem 0 0.25rem;
  color: #fff;
  font-size: 1.7rem;
  font-weight: 900;
}

.ex-form-head p {
  margin: 0;
  color: rgba(255, 255, 255, 0.9);
}

.ex-kind {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}

.ex-kind-option {
  position: relative;
  display: grid;
  justify-items: center;
  gap: 0.15rem;
  padding: 0.9rem;
  border: 2px solid var(--bb-sage-200);
  border-radius: 1rem;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s ease, background-color 0.15s ease;
}

.ex-kind-option input,
.ex-offer input {
  position: absolute;
  opacity: 0;
}

.ex-kind-option:has(input:checked) {
  border-color: #0f766e;
  background: #f0fdfa;
}

.ex-kind-option:has(input:focus-visible),
.ex-offer:has(input:focus-visible) {
  outline: 3px solid var(--bb-blue-500);
  outline-offset: 2px;
}

.ex-kind-emoji {
  font-size: 1.8rem;
}

.ex-kind-option span:last-child {
  color: #6b7280;
  font-size: 0.82rem;
}

.ex-offers {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.ex-offer {
  position: relative;
  padding: 0.45rem 1rem;
  border: 2px solid var(--bb-sage-200);
  border-radius: 999px;
  font-weight: 700;
  cursor: pointer;
}

.ex-offer:has(input:checked) {
  border-color: #0f766e;
  background: #0f766e;
  color: #fff;
}

/* My posts. */
.ex-mine {
  display: grid;
  gap: 1rem;
  margin-bottom: 2.5rem;
}

.ex-mine-item {
  padding: 1.1rem 1.25rem;
  border: 1px solid var(--bb-sage-200);
  border-radius: 1rem;
  background: #fff;
}

.ex-mine-item.is-closed {
  opacity: 0.7;
}

.ex-mine-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.ex-mine-head h2 {
  margin: 0.35rem 0 0.15rem;
  color: var(--bb-sage-900);
  font-size: 1.15rem;
  font-weight: 800;
  overflow-wrap: anywhere;
}

.ex-mine-meta {
  color: #6b7280;
  font-size: 0.85rem;
}

.ex-mine-actions {
  display: flex;
  gap: 0.4rem;
}

.ex-mine-sub {
  margin: 1rem 0 0.75rem;
  color: #065f46;
  font-size: 0.95rem;
  font-weight: 800;
}

.ex-new {
  margin-left: 0.4rem;
  padding: 0.1rem 0.55rem;
  border-radius: 999px;
  background: #10b981;
  color: #fff;
  font-size: 0.75rem;
}

.ex-mine-waiting {
  margin: 0.75rem 0 0;
  color: #6b7280;
  font-size: 0.9rem;
}

@media (max-width: 767.98px) {
  .ex-hero,
  .ex-hero-slim {
    grid-template-columns: 1fr;
    padding: 1.5rem 1.25rem;
  }

  .ex-search {
    flex-wrap: wrap;
    max-width: none;
  }

  .ex-search .form-control,
  .ex-search .form-select {
    flex: 1 1 100%;
  }

  .ex-search .btn {
    flex: 1 1 100%;
  }

  .ex-form > :not(.ex-form-head) {
    margin-inline: 1rem;
  }

  .ex-kind {
    grid-template-columns: 1fr;
  }
}

@media (prefers-reduced-motion: reduce) {
  .ex-card {
    transition: none;
  }
}

/* ---- A post's own page (Exchange/Post): the book, and its conversation ---- */
.ex-back {
  display: inline-block;
  margin: 1.25rem 0 0.75rem;
  font-size: 0.9rem;
  text-decoration: none;
}

.ex-title a {
  color: inherit;
  text-decoration: none;
}

.ex-title a:hover {
  text-decoration: underline;
}

.ex-post-page {
  display: grid;
  grid-template-columns: minmax(0, 20rem) minmax(0, 1fr);
  gap: 1.25rem;
  align-items: start;
  margin-bottom: 2rem;
}

.ex-post-book {
  position: sticky;
  top: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 1.1rem 1.2rem;
  border: 1px solid var(--bb-sage-200);
  border-top: 4px solid #10b981;
  border-radius: 1rem;
  background: #fff;
}

.ex-post-book.ex-card-need {
  border-top-color: #f59e0b;
}

.ex-post-title {
  margin: 0.25rem 0;
  font-size: 1.35rem;
  font-weight: 800;
}

.ex-post-who {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.25rem;
  font-size: 0.92rem;
}

.ex-convo {
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
  min-width: 0;
  padding: 1.1rem 1.2rem;
  border: 1px solid var(--bb-sage-200);
  border-radius: 1rem;
  background: #fff;
}

.ex-convo-head h2 {
  margin: 0;
  font-size: 1.2rem;
  font-weight: 800;
}

.ex-convo-head p {
  margin: 0.2rem 0 0;
  color: #6b7280;
  font-size: 0.9rem;
}

.ex-convo-empty {
  padding: 1.5rem 1rem;
  border-radius: 0.8rem;
  background: var(--bb-sage-50);
  text-align: center;
}

.ex-convo-empty > span {
  font-size: 2rem;
}

.ex-convo-empty h2 {
  margin: 0.25rem 0;
  font-size: 1.2rem;
  font-weight: 800;
}

.ex-threads {
  display: flex;
  gap: 0.5rem;
  overflow-x: auto;
  padding-bottom: 0.25rem;
}

.ex-thread {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 0.5rem;
  max-width: 16rem;
  padding: 0.45rem 0.7rem;
  border: 1px solid var(--bb-sage-200);
  border-radius: 0.75rem;
  color: inherit;
  text-decoration: none;
}

.ex-thread.is-active {
  border-color: #10b981;
  background: #ecfdf5;
}

.ex-thread.has-new strong::after {
  content: " •";
  color: #10b981;
}

.ex-thread-text {
  display: grid;
  min-width: 0;
}

.ex-thread-text small {
  overflow: hidden;
  color: #6b7280;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ex-messages {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  max-height: 26rem;
  overflow-y: auto;
  padding: 0.75rem;
  border-radius: 0.8rem;
  background: var(--bb-sage-50);
}

.ex-messages-hint {
  margin: 0;
  color: #4b5563;
  font-size: 0.92rem;
}

.ex-msg {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  max-width: 80%;
}

.ex-msg.is-mine {
  align-self: flex-end;
  align-items: flex-end;
}

.ex-msg-bubble {
  padding: 0.55rem 0.8rem;
  border-radius: 1rem 1rem 1rem 0.25rem;
  background: #fff;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.08);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.ex-msg.is-mine .ex-msg-bubble {
  border-radius: 1rem 1rem 0.25rem 1rem;
  background: #0f766e;
  color: #fff;
}

.ex-msg-time {
  margin-top: 0.15rem;
  color: #6b7280;
  font-size: 0.75rem;
}

.ex-compose {
  display: flex;
  gap: 0.5rem;
  align-items: flex-end;
}

.ex-compose textarea {
  flex: 1;
  min-width: 0;
  resize: vertical;
}

.ex-chat-guide {
  padding: 0.9rem 1rem;
  border: 1px dashed var(--bb-blue-200);
  border-radius: 0.8rem;
  background: var(--bb-blue-50);
}

.ex-chat-guide h3 {
  margin: 0 0 0.25rem;
  font-size: 1rem;
  font-weight: 800;
}

.ex-chat-guide > p {
  margin: 0 0 0.5rem;
  font-size: 0.9rem;
}

.ex-steps {
  margin: 0 0 0.6rem;
  padding-left: 1.25rem;
  font-size: 0.88rem;
}

.ex-steps li.is-done {
  color: #166534;
}

.ex-steps li.is-done::marker {
  content: "✓  ";
}

.ex-chat-state {
  margin: 0 0 0.5rem;
  font-size: 0.9rem;
  font-weight: 600;
}

/* My Exchange Posts: books I asked about */
.ex-asked {
  margin-bottom: 1.25rem;
  padding: 1rem 1.2rem;
  border: 1px solid var(--bb-sage-200);
  border-radius: 1rem;
  background: #fff;
}

.ex-asked h2 {
  margin: 0 0 0.5rem;
  font-size: 1.1rem;
  font-weight: 800;
}

.ex-asked ul {
  display: grid;
  gap: 0.4rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.ex-asked li {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.65rem;
  border-radius: 0.6rem;
  background: var(--bb-sage-50);
}

.ex-asked li.has-new {
  background: #ecfdf5;
}

.ex-asked a {
  display: grid;
  flex: 1;
  min-width: 0;
  color: inherit;
  text-decoration: none;
}

.ex-asked a span {
  color: #6b7280;
  font-size: 0.85rem;
}

@media (max-width: 767.98px) {
  .ex-post-page {
    grid-template-columns: 1fr;
  }

  .ex-post-book {
    position: static;
  }

  .ex-msg {
    max-width: 92%;
  }
}

/* New messages fade in as they arrive (exchange-chat.js). */
.ex-msg.is-arriving {
  animation: ex-arrive 0.35s ease-out;
}

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

.ex-compose-error {
  margin: -0.4rem 0 0;
}
