/*
 * Navigation shell — mobile bottom bar (Option A) + desktop collapsible sidebar.
 * See docs/views.md. Mobile-first; sidebar appears at >= 900px.
 */

/* Floating toast notifications — hover above content near the top. */
.toasts {
  position: fixed;
  top: calc(var(--space-4) + env(safe-area-inset-top, 0px));
  left: 50%;
  transform: translateX(-50%);
  z-index: 60;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-2);
  width: max-content;
  max-width: min(440px, calc(100vw - var(--space-8)));
  pointer-events: none;
}

.toast {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: var(--space-3);
  width: 100%;
  padding: var(--space-2) var(--space-2) var(--space-2) var(--space-4);
  background: var(--color-surface);
  border: 1px solid var(--color-line);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-floating);
  animation: toast-in var(--motion-base) var(--ease-out);
}

.toast__icon {
  display: grid;
  place-items: center;
  flex: none;
  width: 26px;
  height: 26px;
  border-radius: var(--radius-pill);
}

.toast__icon svg {
  width: 17px;
  height: 17px;
}

.toast--notice .toast__icon {
  background: var(--color-accent-tint);
  color: var(--color-accent-strong);
}

.toast--error .toast__icon {
  background: var(--color-danger-tint);
  color: var(--color-danger);
}

.toast__message {
  flex: 1;
  font-size: var(--text-small);
  font-weight: var(--weight-label);
  color: var(--color-ink);
}

.toast__close {
  display: grid;
  place-items: center;
  flex: none;
  width: 30px;
  height: 30px;
  border: none;
  border-radius: var(--radius-control);
  background: none;
  color: var(--color-muted);
  cursor: pointer;
}

.toast__close:hover {
  background: var(--color-bg);
  color: var(--color-ink);
}

.toast__close svg {
  width: 16px;
  height: 16px;
}

.toast--leaving {
  opacity: 0;
  transform: translateY(-12px);
  transition: opacity var(--motion-base) var(--ease-out),
    transform var(--motion-base) var(--ease-out);
}

@keyframes toast-in {
  from { opacity: 0; transform: translateY(-12px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (prefers-reduced-motion: reduce) {
  .toast { animation: none; }
  .toast--leaving { transition: none; }
}

/* Layout scaffold */
.app-shell {
  min-height: 100dvh;
}

.app-main {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}

.app-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: var(--space-4);
}

/* Topbar — Vía A app bar: back? + title + contextual actions. */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: var(--space-2);
  height: 60px;
  padding: 0 var(--space-3) 0 var(--space-4);
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-line);
}

/* When a back button leads the bar, tuck the left padding to the button. */
.topbar--detail {
  padding-left: var(--space-2);
}

.topbar__title {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: var(--text-title);
  font-weight: var(--weight-heading);
  letter-spacing: -0.01em;
}

/* Detail screens omit the title; this keeps actions pinned right. */
.topbar__spacer {
  flex: 1;
}

.topbar__btn {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  flex: none;
  border: none;
  border-radius: var(--radius-control);
  background: none;
  color: var(--color-muted);
  cursor: pointer;
  text-decoration: none;
}

.topbar__btn:hover {
  background: var(--color-bg);
  color: var(--color-ink);
}

.topbar__btn svg {
  width: 22px;
  height: 22px;
}

.topbar__btn--add {
  background: var(--color-accent);
  color: #fff;
}

.topbar__btn--add:hover {
  background: var(--color-accent-strong);
  color: #fff;
}

.topbar__btn--danger {
  color: var(--color-danger);
}

.topbar__btn--danger:hover {
  background: var(--color-danger-tint);
  color: var(--color-danger);
}

.topbar__actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex: none;
}

/* button_to renders a <form>; keep it inline within the actions cluster. */
.topbar__actions form {
  display: inline-flex;
  margin: 0;
}

/* ---------- Sidebar (desktop) ---------- */
.sidebar {
  display: none;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3);
  border-radius: var(--radius-control);
  color: var(--color-ink);
  font-weight: var(--weight-label);
  text-decoration: none;
  white-space: nowrap;
}

.nav-link:hover {
  background: var(--color-bg);
  text-decoration: none;
}

.nav-link--active {
  background: var(--color-accent-tint);
  color: var(--color-accent-strong);
}

.nav-link svg {
  width: 22px;
  height: 22px;
  flex: none;
}

/* ---------- Agent dock ---------- */
/* The launcher every section carries. Sticky, not fixed: it lives in the content
   column, so it inherits its width and desktop centering for free. `margin-top:
   auto` floats it to the bottom of a short screen; a long one scrolls beneath it,
   which is why the strip itself is click-through and only the pill is not. */
.agent-dock {
  position: sticky;
  bottom: calc(var(--space-3) + env(safe-area-inset-bottom, 0px));
  z-index: 5;
  display: flex;
  justify-content: center;
  margin-top: auto;
  padding-top: var(--space-5);
  pointer-events: none;
}

.agent-dock__btn {
  pointer-events: auto;
  display: inline-flex;
  align-items: center;
  gap: var(--space-3);
  height: 56px;
  padding: 0 var(--space-6) 0 var(--space-2);
  border-radius: var(--radius-pill);
  background: var(--color-agent-surface);
  box-shadow: var(--shadow-floating);
  color: var(--color-surface);
  font-size: var(--text-body);
  font-weight: var(--weight-label-strong);
  text-decoration: none;
  transition: filter var(--motion-fast) var(--ease-out);
}

.agent-dock__btn:hover {
  filter: brightness(1.4);
  text-decoration: none;
}

.agent-dock__btn:focus-visible {
  outline: none;
  box-shadow: var(--shadow-floating), var(--focus-ring);
}

.agent-dock__icon {
  display: grid;
  place-items: center;
  flex: none;
  width: 40px;
  height: 40px;
  border-radius: var(--radius-pill);
  background: var(--gradient-agent);
  box-shadow: var(--shadow-agent);
}

.agent-dock__icon svg {
  width: 24px;
  height: 24px;
}

/* ---------- Agent surface ---------- */
.agent {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: var(--space-4);
}

.agent-empty {
  display: flex;
  flex: 1;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
  text-align: center;
}

.agent-empty__title {
  font-size: var(--text-h);
}

.agent-empty__hint {
  max-width: 42ch;
  color: var(--color-muted);
}

.composer {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2);
  border: 1px solid var(--color-line);
  border-radius: var(--radius-card);
  background: var(--color-surface);
  box-shadow: var(--shadow-raised);
}

.composer__input {
  flex: 1;
  height: 40px;
  border: none;
  background: none;
  font-size: var(--text-body);
}

.composer__input:focus {
  outline: none;
}

.composer__btn {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border: none;
  border-radius: var(--radius-pill);
  background: none;
  color: var(--color-muted);
  cursor: pointer;
}

.composer__btn:disabled {
  cursor: default;
}

.composer__btn svg {
  width: 22px;
  height: 22px;
}

/* ---------- Desktop (>= 900px) ---------- */
@media (min-width: 900px) {
  .sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 20;
    display: flex;
    flex-direction: column;
    width: 240px;
    padding: var(--space-4);
    background: var(--color-surface);
    border-right: 1px solid var(--color-line);
  }

  .sidebar__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 40px;
  }

  .sidebar__brand {
    font-size: var(--text-title);
    font-weight: var(--weight-heading);
  }

  .sidebar__toggle {
    display: grid;
    place-items: center;
    width: 36px;
    height: 36px;
    border: none;
    border-radius: var(--radius-control);
    background: none;
    color: var(--color-muted);
    cursor: pointer;
  }

  .sidebar__toggle:hover {
    background: var(--color-bg);
  }

  .sidebar__toggle svg {
    width: 22px;
    height: 22px;
  }

  .sidebar__nav {
    display: flex;
    flex: 1;
    flex-direction: column;
    gap: 2px;
    margin-top: var(--space-5);
  }

  .sidebar__user {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding-top: var(--space-3);
    border-top: 1px solid var(--color-line);
  }

  .avatar {
    display: grid;
    place-items: center;
    flex: none;
    width: 32px;
    height: 32px;
    border-radius: var(--radius-pill);
    background: var(--color-accent-tint);
    color: var(--color-accent-strong);
    font-size: var(--text-small);
    font-weight: var(--weight-label-strong);
  }

  .sidebar__email {
    flex: 1;
    overflow: hidden;
    font-size: var(--text-small);
    color: var(--color-muted);
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .sidebar__signout {
    display: grid;
    place-items: center;
    width: 32px;
    height: 32px;
    padding: 0;
    border: none;
    border-radius: var(--radius-control);
    background: none;
    color: var(--color-muted);
    cursor: pointer;
  }

  .sidebar__signout:hover {
    background: var(--color-bg);
    color: var(--color-ink);
  }

  .sidebar__signout svg {
    width: 20px;
    height: 20px;
  }

  .app-main {
    margin-left: 240px;
  }

  /* Centered canvas: the content column sits centered in the space beside the
     sidebar, not hugging its edge (views.md). */
  .app-content {
    max-width: 760px;
    margin-inline: auto;
    padding: var(--space-6);
  }

  /* Collapsed rail */
  .sidebar--collapsed {
    width: 72px;
  }

  .sidebar--collapsed .sidebar__brand,
  .sidebar--collapsed .nav-link__label,
  .sidebar--collapsed .sidebar__email,
  .sidebar--collapsed .sidebar__signout {
    display: none;
  }

  .sidebar--collapsed .nav-link {
    justify-content: center;
  }

  .app-shell:has(.sidebar--collapsed) .app-main {
    margin-left: 72px;
  }
}
