/*
 * App shell — one layout for every signed-in page, Chat included: a sticky
 * left sidebar (brand, navigation, recent chats, account menu) beside the
 * main column. The sidebar collapses to an icon rail; the state lives on
 * <html data-sidebar> (sidebar controller). Narrow screens start on the rail
 * and open the full sidebar over the content.
 * Token variables only (tokens.css); auto-included via propshaft.
 * Used by app/views/layouts/application.html.erb.
 */

.app {
  display: flex;
  min-height: 100vh;
  background: var(--color-surface);
}

.app-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

/* ---------- Sidebar ---------- */

.sidebar {
  position: sticky;
  top: 0;
  z-index: 40;
  flex: none;
  display: flex;
  flex-direction: column;
  width: 268px;
  height: 100vh;
  padding: var(--space-3) var(--space-2);
  background: var(--color-bg);
  border-right: 1px solid var(--color-border);
}

.sidebar__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  padding: 12px var(--space-1) 24px var(--space-3);
}

.sidebar__brand {
  text-decoration: none;
}

.sidebar__brand:hover {
  text-decoration: none;
}

/* Official FeedMob Plus artwork pairs with the primary product name. */
@font-face {
  font-family: "Lato";
  src: url("/assets/lato-regular-ddba395c.ttf") format("truetype");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

.product-brand {
  font-family: "Lato", var(--font-sans);
  display: inline-flex;
  align-items: center;
  gap: 10px;
}

.product-brand__mark {
  display: block;
  flex: none;
}

.product-brand__name {
  color: var(--color-heading);
  font-size: 22px;
  font-weight: 400;
  letter-spacing: -0.015em;
  line-height: 1.25;
  white-space: nowrap;
}

.sidebar__form {
  margin: 0;
}

.sidebar__item,
.sidebar__chat {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  width: 100%;
  min-height: 40px;
  padding: 0 var(--space-3);
  border: 0;
  border-radius: var(--radius-md);
  background: none;
  color: var(--color-heading);
  font: inherit;
  font-size: var(--text-sm);
  text-align: left;
  text-decoration: none;
  cursor: pointer;
}

.sidebar__item svg {
  flex: none;
  color: var(--color-text-muted);
}

.sidebar__item:hover,
.sidebar__chat:hover,
.sidebar__icon-btn:hover {
  background: var(--color-surface-sunken);
  color: var(--color-heading);
  text-decoration: none;
}

.sidebar__item.is-current,
.sidebar__chat.is-current {
  background: var(--color-selected-bg);
}

.sidebar__icon-btn {
  display: flex;
  flex: none;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  /* The global button padding would leave 8px for the icon. */
  padding: 0;
  border: 0;
  border-radius: var(--radius-md);
  background: none;
  color: var(--color-text-muted);
  cursor: pointer;
}

.sidebar__icon-btn svg {
  flex: none;
}

.sidebar__section {
  margin: var(--space-5) var(--space-3) var(--space-2);
  font-size: var(--text-xs);
  color: var(--color-text-muted);
}

/* Tidy up, at the right of the list's first heading. */
.sidebar__tidy {
  position: absolute;
  top: calc(var(--space-5) - 6px);
  right: var(--space-2);
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: var(--radius-md);
  color: var(--color-text-muted);
}

.sidebar__tidy:hover { background: var(--color-surface-sunken); color: var(--color-heading); }
.sidebar__tidy:focus-visible { outline: 2px solid var(--color-focus-ring); outline-offset: 0; }

/* "Older" is a fold in the list, not a card: no box from the global
   details style, and its heading sits like the day headings above it. */
.sidebar__older {
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: none;
}

.sidebar__older > summary,
.sidebar__older[open] > summary {
  margin: var(--space-5) var(--space-3) var(--space-2);
  font-weight: inherit;
}

.sidebar__older > summary { cursor: pointer; list-style: none; }
.sidebar__older > summary::-webkit-details-marker { display: none; }
.sidebar__older > summary::after { content: " \203A"; display: inline-block; margin-left: 2px; transition: transform 120ms ease; }
.sidebar__older[open] > summary::after { transform: rotate(90deg); }
.sidebar__older > summary:hover { color: var(--color-heading); }

.sidebar__list {
  position: relative;
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.sidebar__chat {
  gap: var(--space-2);
  min-height: 36px;
}

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

/* A conversation row: "..." shows on hover, on the open conversation and
   while its menu is open (chat-menu controller). */
.sidebar__row { position: relative; }
.sidebar__row .sidebar__chat { padding-right: 36px; }
.sidebar__row:hover .sidebar__chat { background: var(--color-surface-sunken); }
.sidebar__row.is-current .sidebar__chat { background: var(--color-selected-bg); }

.sidebar__more {
  position: absolute;
  top: 50%;
  right: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  padding: 0;
  border: 0;
  border-radius: var(--radius-md);
  background: none;
  color: var(--color-text-muted);
  cursor: pointer;
  opacity: 0;
  transform: translateY(-50%);
}

.sidebar__more svg { flex: none; }
.sidebar__more:hover { color: var(--color-heading); background: var(--color-border); }
.sidebar__row:hover .sidebar__more,
.sidebar__row.is-current .sidebar__more,
.sidebar__row.is-open .sidebar__more,
.sidebar__more:focus-visible { opacity: 1; }
.sidebar__row:hover .sidebar__dot,
.sidebar__row.is-open .sidebar__dot { display: none; }
.sidebar__row.is-renaming .sidebar__more { display: none; }

/* A spinner where "..." sits, while Spend Lens replies in that conversation;
   the open one shows its own progress, so its row keeps the "...". */
.sidebar__dot {
  position: absolute;
  top: 50%;
  right: 12px;
  display: flex;
  pointer-events: none;
  transform: translateY(-50%);
}
.sidebar__dot:empty,
.sidebar__row.is-current .sidebar__dot,
.sidebar__row:focus-within .sidebar__dot { display: none; }

.sidebar__rename { margin: 0; padding: 2px; }
.sidebar__rename input {
  width: 100%;
  max-width: none;
  min-height: 32px;
  padding: 0 var(--space-2);
  font-size: var(--text-sm);
}

.sidebar__menu {
  position: fixed;
  z-index: 60;
  min-width: 11rem;
  padding: var(--space-1);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  background: var(--color-raised);
  box-shadow: var(--shadow-md);
}

.sidebar__menu[hidden] { display: none !important; }
.sidebar__menu-form { margin: 0; }

.sidebar__menu-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  width: 100%;
  min-height: 34px;
  padding: 0 var(--space-3);
  border: 0;
  border-radius: var(--radius-md);
  background: none;
  color: var(--color-heading);
  font: inherit;
  font-size: var(--text-sm);
  text-align: left;
  cursor: pointer;
}

.sidebar__menu-item svg { flex: none; color: var(--color-text-muted); }
.sidebar__menu-item:hover,
.sidebar__menu-item:focus-visible { background: var(--color-surface-sunken); outline: none; }
.sidebar__menu-sep { margin: var(--space-1) var(--space-2); border: 0; border-top: 1px solid var(--color-border); }

.sidebar__empty {
  margin: 0 var(--space-3);
  font-size: var(--text-sm);
  color: var(--color-text-muted);
}

.sidebar__foot {
  padding-top: var(--space-2);
  border-top: 1px solid var(--color-border);
}

/* The account menu fills the foot and opens upward. */
.sidebar .user-menu__trigger {
  gap: var(--space-3);
  width: 100%;
  padding: var(--space-2);
  border-radius: var(--radius-md);
  color: var(--color-heading);
  font: inherit;
  font-size: var(--text-sm);
  font-weight: var(--font-semibold);
  text-align: left;
}

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

.sidebar .user-menu__dropdown {
  top: auto;
  right: auto;
  bottom: calc(100% + var(--space-2));
  left: 0;
}

.user-menu__theme {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-1) var(--space-3) var(--space-2);
  font-size: var(--text-sm);
  font-weight: var(--font-medium);
  color: var(--color-text);
}

/* Theme preference selector: System follows the OS; Light and Dark pin a palette. */
.theme-toggle {
  padding: var(--space-1) var(--space-3);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-pill);
  background: var(--color-raised);
  color: var(--color-text);
  font: inherit;
  font-size: var(--text-sm);
  cursor: pointer;
}

/* ---------- Collapsed: an icon rail ---------- */

[data-sidebar="collapsed"] .sidebar {
  width: 60px;
  align-items: center;
}

[data-sidebar="collapsed"] .sidebar__brand,
[data-sidebar="collapsed"] .sidebar__label,
[data-sidebar="collapsed"] .sidebar__section,
[data-sidebar="collapsed"] .sidebar__list,
[data-sidebar="collapsed"] .user-menu__who {
  display: none;
}

[data-sidebar="collapsed"] .sidebar__head {
  padding: 0 0 var(--space-3);
}

[data-sidebar="collapsed"] .sidebar__item {
  justify-content: center;
  width: 40px;
  padding: 0;
}

[data-sidebar="collapsed"] .sidebar__foot {
  margin-top: auto;
}

[data-sidebar="collapsed"] .sidebar .user-menu__trigger {
  width: auto;
  padding: var(--space-1);
}

/* ---------- Page content ---------- */

.page {
  flex: 1;
  width: 100%;
  max-width: var(--container-max);
  margin-inline: auto;
  padding: var(--space-6) clamp(var(--space-5), 3vw, var(--space-7)) var(--space-7);
}

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

@media (max-width: 900px) {
  .page {
    padding-inline: var(--space-4);
  }
}

/* The rail is the default; opening the sidebar lays it over the content. */
@media (max-width: 760px) {
  .app {
    padding-left: 60px;
  }

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    box-shadow: var(--shadow-md);
  }
}
