/* App shell: a left rail on desktop, a bottom tab bar on phones. Auth pages use a centred card. */
@layer layout {
  .brand {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    font-family: var(--display);
    font-weight: 700;
    font-size: 21px;
    letter-spacing: -.03em;
    color: var(--ink);
    text-decoration: none;

    & svg { width: 30px; height: 30px; flex: none; }
  }

  .shell {
    display: grid;
    grid-template-columns: 232px minmax(0, 1fr);
    min-height: 100dvh;
  }

  .rail {
    position: sticky;
    top: 0;
    height: 100dvh;
    display: flex;
    flex-direction: column;
    gap: 28px;
    padding: 22px 16px;
    border-right: 1px solid var(--line);
    background: var(--panel);
  }

  .nav {
    display: flex;
    flex-direction: column;
    gap: 2px;

    & a {
      display: flex;
      align-items: center;
      gap: 12px;
      padding: 9px 12px;
      border-radius: var(--r-ctl);
      color: var(--muted);
      font-weight: 500;
      text-decoration: none;
    }
    & a:hover { color: var(--ink); background: var(--bg); }
    & a[aria-current="page"] { color: var(--ink); background: var(--accent-wash); }
    & a[aria-current="page"] svg { color: var(--accent-text); }
    & svg { width: 20px; height: 20px; flex: none; }
    & .soon { margin-left: auto; font-family: var(--mono); font-size: 10px; letter-spacing: .06em; text-transform: uppercase; }
    & .short { display: none; }
  }

  .rail-foot {
    margin-top: auto;
    display: flex;
    flex-direction: column;
    gap: 8px;
    font-size: 14px;

    & .who { color: var(--muted); overflow-wrap: anywhere; }
    & .foot-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
    & .btn[aria-current="page"] { border-color: var(--accent-text); color: var(--accent-text); }
  }

  .main {
    min-width: 0;
    padding: clamp(20px, 4vw, 40px) clamp(16px, 4vw, 48px) 96px;
    display: flex;
    flex-direction: column;
    gap: 24px;
  }

  .page-head {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    justify-content: space-between;
    gap: 12px 24px;

    & h1 { font-size: clamp(30px, 4.4vw, 44px); line-height: 1; }
  }

  .flash { max-width: 720px; }

  /* Phone: rail becomes a top bar plus a bottom tab bar. */
  @media (max-width: 760px) {
    .shell { grid-template-columns: minmax(0, 1fr); }

    .rail {
      position: sticky;
      height: auto;
      flex-direction: row;
      align-items: center;
      justify-content: space-between;
      padding: 12px 16px;
      border-right: 0;
      border-bottom: 1px solid var(--line);
      z-index: 5;
    }

    .rail .nav {
      position: fixed;
      inset: auto 0 0 0;
      flex-direction: row;
      justify-content: space-around;
      padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
      background: var(--panel);
      border-top: 1px solid var(--line);
      z-index: 5;

      & a { flex-direction: column; gap: 2px; padding: 6px 8px; font-size: 11.5px; }
      & .soon { display: none; }
      & .long { display: none; }
      & .short { display: inline; }
    }

    .rail-foot { margin-top: 0; flex-direction: row; align-items: center; }
    .rail-foot .who { display: none; }
    .rail-foot { min-width: 0; }
    .rail-foot .foot-actions { flex-wrap: nowrap; gap: 4px; overflow-x: auto; scrollbar-width: none; }
    .rail-foot .btn.sm { padding: 6px 9px; font-size: 13px; }
  }

  /* Auth */
  .auth {
    min-height: 100dvh;
    display: grid;
    place-items: center;
    padding: 32px 16px;
  }

  .auth-card {
    width: min(420px, 100%);
    padding: clamp(24px, 5vw, 36px);
    display: flex;
    flex-direction: column;
    gap: 22px;

    & h1 { font-size: 32px; }
    & form { display: flex; flex-direction: column; gap: 16px; }
    & .alt { font-size: 14.5px; color: var(--muted); }
  }

  .errors {
    padding: 12px 14px;
    border-radius: var(--r-inner);
    background: var(--accent-wash);
    color: var(--accent-ink);
    font-size: 14px;

    & ul { margin: 6px 0 0; padding-left: 18px; }
  }
}

/* The way back to an import in progress, under the menu on desktop and floating above the tab bar on phones. */
@layer layout {
  .import-pill-slot:empty { display: none; }

  .import-pill {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 12px;
    border: 1px solid var(--line);
    border-radius: var(--r-inner);
    background: var(--bg);
    color: var(--ink);
    text-decoration: none;
    font-size: 13.5px;
    transition: border-color .2s, transform .2s;

    &:hover { border-color: var(--accent-text); transform: translateY(-1px); }
    & .pill-ring { width: 26px; height: 26px; flex: none; transform: rotate(-90deg); }
    & .pill-ring circle { fill: none; stroke-width: 3; }
    & .pill-ring .t { stroke: var(--line); }
    & .pill-ring .f { stroke: var(--actual); stroke-linecap: round; transition: stroke-dashoffset .5s; }
    & .pill-ring .k { fill: none; stroke: var(--good); stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; transform: rotate(90deg); transform-origin: center; }
    & .pill-copy { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; }
    & .pill-copy b { font-weight: 600; }
    & .pill-copy small { color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

    &.pending .pill-ring, &.running .pill-ring { animation: pill-breathe 1.6s ease-in-out infinite; }
    &.done .pill-ring .f { stroke: var(--good); }
    &.failed .pill-ring .f { stroke: var(--fatigue); }
  }

  @keyframes pill-breathe { 50% { filter: drop-shadow(0 0 4px color-mix(in srgb, var(--actual) 55%, transparent)); } }

  @media (prefers-reduced-motion: reduce) {
    .import-pill .pill-ring { animation: none; }
  }

  @media (max-width: 760px) {
    .import-pill-slot {
      position: fixed;
      right: 12px;
      bottom: calc(76px + env(safe-area-inset-bottom));
      z-index: 6;
    }
    .import-pill { background: var(--panel); box-shadow: 0 6px 22px color-mix(in srgb, var(--ink) 18%, transparent); padding: 8px 14px 8px 10px; border-radius: var(--r-pill); }
  }
}

@layer layout {
  /* The import page shows the import itself. */
  body:has(.live) .import-pill-slot { display: none; }
}
