/* ── App shell ── */

/* The signed-in app. Room at the foot for the phone's bottom tab bar, so the
   last of a page scrolls clear of it (0 from 768px up), and the side safe
   areas of a phone held in landscape. */
.app {
  padding-bottom: var(--chrome-bottom);
  padding-left: env(safe-area-inset-left, 0px);
  padding-right: env(safe-area-inset-right, 0px);
}

/* ── Header ── */

/* One bar at every width: the brand (or a detail's back link), the tabs,
   then upload, sync, the bell and the account. Under 768px the tabs leave
   it for a bar fixed to the foot of the screen, in reach of a thumb (the
   tab bar below); from 768px up they sit in the middle of this one. Its
   height is --chrome-top, which the sticky and full-height views read. */
.app-header {
  background: var(--header-bg);
  color: var(--header-text);
  position: sticky;
  top: 0;
  z-index: 100;
  border-bottom: 1px solid var(--hairline);
}

.header-inner {
  max-width: 1200px;
  margin: 0 auto;
  min-height: calc(var(--chrome-top) - 1px);   /* the hairline makes up the rest */
  padding: var(--space-2) var(--space-3);
  display: flex;
  align-items: center;
  justify-content: space-between;
  column-gap: var(--space-3);
}

.brand {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-width: 0;
  overflow: hidden;   /* gives way first on a 320px screen */
}

.brand-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  flex-shrink: 0;
  color: var(--accent);
}

.brand-icon svg {
  width: 100%;
  height: 100%;
}

.brand-name {
  font-family: var(--font-display);
  font-size: var(--fs-heading);
  font-weight: var(--fw-bold);
  letter-spacing: var(--tracking-display);
  line-height: var(--lh-heading);
}

/* A detail's way back (activity.allium: BackLeadsWhereTheReaderCameFrom),
   where the brand sits on every other page: an arrow and the name of where
   it leads. */
.detail-back {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  flex: 0 1 auto;
  min-width: 44px;
  min-height: 44px;
  margin-left: calc(-1 * var(--space-2));
  padding: 0 var(--space-3) 0 var(--space-2);
  border-radius: var(--radius-pill);
  color: var(--ink);
  font-size: var(--fs-body);
  font-weight: var(--fw-semibold);
  text-decoration: none;
}

.detail-back:hover {
  background: var(--surface-alt);
}

.detail-back-icon {
  flex: none;
  width: 20px;
  height: 20px;
}

.detail-back-label {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  flex: none;
}

@media (min-width: 768px) {
  .header-inner {
    padding: var(--space-2) var(--space-4);
  }

  .header-actions {
    gap: var(--space-2);
  }
}

.avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--on-accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.9rem;
  overflow: hidden;
  padding: 0;
  border: none;
  cursor: pointer;
}

.avatar-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* The menu the avatar opens onto the Settings pages. Inside the header
   (z-index 100), so the backdrop that closes it on an outside click covers
   the page below without covering the menu. */
.account-menu-wrapper {
  position: relative;
}

.account-menu-backdrop {
  position: fixed;
  inset: 0;
  z-index: 1;
}

.account-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: 10px;
  box-shadow: var(--shadow-md);
  min-width: 200px;
  z-index: 2;
  padding: 4px 0;
}

.account-menu-item {
  display: block;
  width: 100%;
  background: none;
  border: none;
  padding: 10px 16px;
  font-size: 0.95rem;
  font-family: inherit;
  font-weight: 500;
  text-align: left;
  cursor: pointer;
  color: var(--ink);
}

.account-menu-item:hover,
.account-menu-item:focus-visible {
  background: var(--surface-alt);
}

.account-menu-separator {
  border: none;
  border-top: 1px solid var(--hairline);
  margin: 4px 0;
}

.account-menu-item[aria-current="page"] {
  color: var(--accent);
}

/* The account's own row: its picture and name, then "View profile". */
.account-menu-item.account-menu-me {
  display: flex;
  align-items: center;
  gap: 10px;
}

.account-menu-me-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  object-fit: cover;
  flex: none;
  color: var(--ink-muted);
}

.account-menu-me-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.account-menu-me-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.account-menu-me-sub {
  font-size: 0.8rem;
  font-weight: 400;
  color: var(--ink-muted);
}

/* ── Notification bell (specs/notification.allium) ──
   Sits with the sync indicator: brand-coloured icon on the chrome, a count
   badge over its corner, and a panel that opens like the account menu. */

.notif-wrapper {
  position: relative;
}

.notif-btn {
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  /* Above the backdrop the open panel lays over the page, so a second tap
     on the bell closes the list rather than landing on the backdrop. */
  z-index: 3;
  color: var(--accent);
}

.notif-badge {
  position: absolute;
  top: 2px;
  right: 2px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--accent);
  color: var(--on-accent);
  font-size: 0.6rem;
  font-weight: 700;
  min-width: 16px;
  height: 16px;
  border-radius: 8px;
  padding: 0 4px;
}

.notif-panel {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: 10px;
  box-shadow: var(--shadow-md);
  width: 320px;
  max-width: calc(100vw - 32px);
  max-height: 70vh;
  overflow-y: auto;
  z-index: 2;
  padding: 4px 0;
}

.notif-panel-title {
  padding: 8px 16px 6px;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--ink-muted, var(--ink));
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

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

.notif-item {
  display: block;
  width: 100%;
  background: none;
  border: none;
  padding: 10px 16px;
  font-size: 0.92rem;
  font-family: inherit;
  text-align: left;
  cursor: pointer;
  color: var(--ink);
  overflow-wrap: anywhere;
}

.notif-item:hover,
.notif-item:focus-visible {
  background: var(--surface-alt);
}

/* What was new when the list opened: marked with a dot and set in weight,
   so the history around it reads as already seen. */
.notif-item {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.notif-item-new {
  font-weight: 600;
}

.notif-dot {
  flex: none;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  transform: translateY(-1px);
}

.notif-text {
  min-width: 0;
}

.notif-item:not(.notif-item-new) .notif-text {
  margin-left: 16px;
  color: var(--ink-muted, var(--ink));
}

.notif-empty {
  margin: 0;
  padding: 10px 16px 14px;
  color: var(--ink-muted, var(--ink));
  font-size: 0.92rem;
}

/* ── Sync indicator ── */

.sync-btn {
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px;
  min-width: 44px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

/* Resting arrows: the accent at full strength, so the control is visible
   at rest and the user can learn where it lives. The chrome is
   surface-coloured, so --accent reads directly against it. */
.sync-arrows {
  display: flex;
  align-items: center;
  gap: 1px;
  color: var(--accent);
  position: relative;
}

.sync-arrow {
  display: flex;
  transition: color 120ms ease-out, opacity 120ms ease-out;
}

/* Two 15px arrows sit in roughly the footprint the single 20px cloud had,
   so the header actions row keeps its spacing. */
.sync-arrow .sync-icon {
  width: 15px;
  height: 15px;
}

/* Only the direction actually moving lights up. Colour alone is a weak
   signal at this size, so the lit arrow also gains prominence by dimming
   its partner — otherwise "uploading" can read as *less* emphatic than
   idle. */
.sync-arrow.active {
  color: var(--accent);
  animation: sync-pulse 1.6s ease-in-out infinite;
}

.sync-btn.transferring .sync-arrow:not(.active) {
  opacity: 0.35;
}

/* Parked, not moving: the queue is stuck behind a quota, so a pulse would
   misleadingly suggest progress. */
.sync-btn.quota .sync-arrow.active {
  animation: none;
}

/* Uploads keep failing. Retries are still running, so the arrow keeps
   pulsing — but at half speed and in the one token that reads as trouble
   rather than progress (--warning is the same amber as --accent, so it
   could not carry this on its own). */
.sync-btn.stalled .sync-arrows {
  color: var(--danger);
}

.sync-btn.stalled .sync-arrow.active {
  color: var(--danger);
  animation-duration: 3.2s;
}

.sync-btn.stalled .sync-count {
  background: var(--danger);
}

/* Offline: neither direction can make progress, so the pair drops to a
   neutral gray and nothing pulses regardless of what is queued. Colour
   alone is too weak to read in isolation (the user never sees online and
   offline side by side), so a slash crosses the pair as well. */
.sync-btn.offline .sync-arrows {
  color: var(--ink-subtle);
}

.sync-btn.offline .sync-arrows::after {
  content: "";
  position: absolute;
  left: -2px;
  right: -2px;
  top: 50%;
  height: 1.5px;
  border-radius: 2px;
  background: currentColor;
  transform: rotate(-22deg);
}

/* Shallower than the old cloud's pulse: the arrow must stay clearly
   brighter than its dimmed partner at every point in the cycle. */
@keyframes sync-pulse {
  0%, 100% { opacity: 0.72; }
  50%      { opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
  .sync-arrow.active {
    animation: none;
  }
}

.sync-badge {
  position: relative;
  display: flex;
  align-items: center;
}

/* Quota-parked: the queue is stuck rather than draining. The dot marks it
   without needing a colour that reads as distinct from --accent (the two
   tokens are the same amber). The QuotaBanner carries the explanation. */
.sync-warn-dot {
  position: absolute;
  bottom: -1px;
  left: -6px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--warning);
  box-shadow: 0 0 0 1.5px var(--header-bg);
}

.sync-count {
  position: absolute;
  top: -6px;
  right: -8px;
  background: var(--warning);
  color: var(--surface);   /* light on the dark amber, dark on the light one */
  font-size: 0.6rem;
  font-weight: 700;
  border-radius: 50%;
  min-width: 14px;
  height: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

/* ── Tab bar ── */

/* The app's one <nav>, the same five links at every width.
   Under 768px: a bar fixed to the foot of the screen, each tab an icon over
   its name (LOOK-2), clear of the home indicator (the safe area under it).
   It stays in the header's stacking context, so overlays that cover the
   header (menus, sheets, the lightbox) cover it too. Its height is
   --chrome-bottom, which the shell pads the page by. */
.tab-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  height: var(--chrome-bottom);
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  padding: 0 env(safe-area-inset-right, 0px) env(safe-area-inset-bottom, 0px) env(safe-area-inset-left, 0px);
  background: var(--surface);
  border-top: 1px solid var(--hairline);
}

.tab-btn {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-width: 0;
  min-height: 44px;
  padding: var(--space-1) 2px;
  color: var(--ink-muted);
  font-size: var(--fs-kicker);
  font-weight: var(--fw-medium);
  line-height: var(--lh-snug);
  text-decoration: none;
  cursor: pointer;
  transition: color 0.15s, box-shadow 0.15s;
}

.tab-icon {
  flex: none;
  box-sizing: content-box;
  width: 22px;
  height: 22px;
  padding: 2px var(--space-3);
  border-radius: var(--radius-pill);
  transition: background 0.15s;
}

.tab-label {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tab-btn:hover {
  color: var(--ink);
}

/* The current tab: the accent, and a shape that is not colour (LOOK-2) — a
   pill behind the icon here, an underline in the wide bar. */
.tab-btn.active {
  color: var(--accent);
  font-weight: var(--fw-semibold);
}

.tab-btn.active .tab-icon {
  background: var(--accent-soft);
  color: var(--accent-hover);
}

.tab-badge {
  position: absolute;
  top: 2px;
  left: calc(50% + 8px);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--accent);
  color: var(--on-accent);
  font-size: 0.6rem;
  font-weight: var(--fw-bold);
  min-width: 16px;
  height: 16px;
  border-radius: var(--radius-pill);
  padding: 0 4px;
}

/* From 768px up: the tabs centred in the app bar, names alone. */
@media (min-width: 768px) {
  .tab-bar {
    position: static;
    height: auto;
    flex: 1;
    align-self: stretch;
    margin: calc(-1 * var(--space-2)) 0;   /* stretch tabs to the full bar height */
    display: flex;
    justify-content: center;
    gap: var(--space-1);
    padding: 0;
    background: none;
    border-top: none;
  }

  .tab-btn {
    flex-direction: row;
    padding: 0 var(--space-3);
    font-size: var(--fs-body);
    font-weight: var(--fw-semibold);
  }

  .tab-icon {
    display: none;
  }

  .tab-btn.active {
    box-shadow: inset 0 -2px 0 var(--accent);
  }

  .tab-badge {
    position: static;
    margin-left: var(--space-1);
  }
}

/* ── Upload button ── */

.upload-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  position: relative;
}

.upload-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--accent);
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  cursor: pointer;
  color: var(--on-accent);
  transition: background 0.15s;
}

.upload-btn:hover {
  background: var(--accent-hover);
}

.upload-btn .at-icon {
  width: 20px;
  height: 20px;
  vertical-align: 0;
}

/* ── Passkey re-enrol banner ──
   App-wide, persistent until the user enrols a new passkey (driven by the
   durable passkey_reenrol_pending flag). Amber/accent, not an error. */

.reenrol-banner {
  background: var(--accent-soft);
  border-bottom: 1px solid var(--accent);
  color: var(--ink);
}

.reenrol-banner-inner {
  max-width: 720px;
  margin: 0 auto;
  padding: 0.6rem 1rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.reenrol-banner-icon {
  flex: none;
  color: var(--accent-hover);
}

.reenrol-banner-text {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  min-width: 0;
  flex: 1 1 auto;
}

.reenrol-banner-text strong {
  font-size: 0.9rem;
  font-weight: 600;
}

.reenrol-banner-text span {
  font-size: 0.82rem;
  color: var(--ink-muted);
}

.reenrol-banner-cta {
  flex: none;
  background: var(--accent);
  color: var(--on-accent);
  border: none;
  border-radius: 8px;
  padding: 0.4rem 0.85rem;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}

.reenrol-banner-cta:hover {
  background: var(--accent-hover);
}

/* ── Sync-engine failure banner ──
   Same layout as the re-enrol banner, but this one is an error: the worker
   is dead and nothing persists or syncs until the page is reloaded. */

.sync-failed-banner {
  background: var(--danger-soft);
  border-bottom-color: var(--danger);
}

.sync-failed-banner .reenrol-banner-icon {
  color: var(--danger);
}

.sync-failed-banner .reenrol-banner-cta {
  background: var(--danger);
}

.sync-failed-banner .reenrol-banner-cta:hover {
  background: var(--danger-hover);
}

/* ── Storage-quota banner ──
   Same layout again, warning-tinted: uploads are parked locally until the
   user frees space (or retries after freeing it elsewhere). */

.quota-banner {
  background: var(--warning-soft, var(--accent-soft));
  border-bottom-color: var(--warning);
}

.quota-banner .reenrol-banner-icon {
  color: var(--warning);
}

.quota-banner .reenrol-banner-cta {
  background: var(--warning);
}
