/* What every page shares, the planner's pages (base.html, with app.css) and the home page
   (index.html, with home.css): the top bar (templates/partials/topbar.html) and the sewn label.
   The top bar: Colours come from the page's --ink, which
   both pages make light when the sky is dark; at night the text on the sky turns light here too. */
/* The bar sits in exactly the same place on every page: full width up to 1100px, centred, with
   its own font and line height (the home page's body differs from the planner's), and the page's
   scrollbar always keeps its gutter, so a page that scrolls does not shift the bar sideways. */
html { scrollbar-gutter: stable; }
/* wraps rather than squeezing: if a line ever runs out of room, the account moves under it instead of
   the menu folding into a column */
.topbar {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 16px;
  box-sizing: border-box; width: 100%; max-width: 1100px; margin: 0 auto; padding: 18px 16px;
  font-family: Inter, system-ui, -apple-system, "Segoe UI", sans-serif; font-size: 16px; line-height: 1.5;
}
.brand {
  display: inline-flex; align-items: center; gap: 8px;
  font-weight: 600; font-size: 1.15rem; letter-spacing: -0.02em;
  color: var(--ink); text-decoration: none;
}
.brand svg { width: 22px; height: 22px; fill: currentColor; }
.topbar nav { display: flex; flex-wrap: wrap; gap: 4px; min-width: 0; }
.topbar nav a {
  padding: 6px 12px; border-radius: 999px;
  color: var(--ink); text-decoration: none; font-size: .95rem;
}
.topbar nav a:hover { background: rgba(255, 255, 255, .5); }
/* the current tab is a pill with a stroke instead of bold, which would widen it and move the tabs after it */
.topbar nav a[aria-current] { background: var(--card, rgba(255, 255, 255, .88)); -webkit-text-stroke: .4px currentColor; }
/* account: login link, or the user and logout (only when login is configured) */
/* one line, never wrapped: admin, account name, logout. It is a form, and app.css lays every form
   out as a column with a top margin: the direction and margins are set here, not inherited. */
.account { display: flex; flex-direction: row; flex-wrap: nowrap; align-items: center; gap: 8px; margin: 0 0 0 auto; font-size: .9rem; white-space: nowrap; flex: none; }
.account > * { flex: none; }
/* the accent like the admin link (the home page has no link colour of its own) */
.account-name { color: var(--accent, #3f7f86); font-weight: 600; max-width: 14ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
a.login, .link-button {
  padding: 5px 12px; border-radius: 999px; border: 1px solid var(--accent, #3f7f86);
  background: var(--card, rgba(255, 255, 255, .88)); color: var(--accent, #3f7f86); font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
}
a.login:hover, .link-button:hover { background: var(--accent, #3f7f86); color: #fff; filter: none; }
body.night .account-name { color: #eef2f7; }
.account-admin { color: var(--accent, #3f7f86); font-weight: 600; text-decoration: none; }
.account-admin:hover { text-decoration: underline; }
body.night .account-admin { color: #eef2f7; }
body.night .brand, body.night .topbar nav a:not([aria-current]) { color: #eef2f7; }
body.night .topbar nav a:hover { background: rgba(255, 255, 255, .14); }

/* Phones and narrow tablets: brand and account on the first line, the menu under them. One line
   needs about 800px when logged in (an admin with a long name), so the bar has two lines up to there.
   The account takes the rest of the first line and never wraps under the brand: on the narrowest
   phones the name gives way (ellipsis), the admin link and logout stay whole. */
@media (max-width: 800px) {
  .topbar { gap: 8px; }
  /* the menu's first word under the brand: the pill's padding stands out to the left */
  .topbar nav { order: 3; flex-basis: 100%; margin-left: -12px; }
  form.account { flex: 1 1 0; min-width: 0; justify-content: flex-end; gap: 6px; }
  .account > .account-name { flex: 0 1 auto; min-width: 0; }
}
@media (max-width: 560px) {
  /* phone: the whole menu on one line */
  .topbar nav { gap: 2px; margin-left: -8px; }
  .topbar nav a { padding: 6px 8px; }
  .nav-long { display: none; }
}

/* The sewn label (partials/sewn_label.html): a woven cotton tag sewn into the left edge of the
   page, like the one in a shirt's side seam. Cream with a fine weave (two crossing stripe
   gradients), stitches along its edges (a dashed border inside, ::after: iOS Safari draws dashed
   outlines badly), the seam on the left. Always whole on the screen, clear of the notch
   (safe-area-inset-left on the home page's viewport-fit=cover). */
.sewn-label {
  position: fixed; left: env(safe-area-inset-left, 0px); top: 58%; z-index: 5;
  writing-mode: vertical-rl;
  display: flex; align-items: center; justify-content: center; gap: 6px;
  /* pixels, not rem, and no text autosizing on phones: the same size on every page */
  box-sizing: border-box; width: 32px; height: 226px; padding: 0 9px 0 8px;
  font: 600 12px/12px Inter, system-ui, sans-serif; letter-spacing: 1.7px; text-transform: uppercase;
  -webkit-text-size-adjust: none; text-size-adjust: none; white-space: nowrap;
  /* stays in place during the view transition between the planner's pages */
  view-transition-name: sewn-label;
  color: #2f5a3c; text-decoration: none;
  /* the weave, a soft ripple along its length (the cloth is not quite flat), the cream base */
  background:
    repeating-linear-gradient(0deg, rgba(90, 70, 40, .05) 0 1px, transparent 1px 3px),
    repeating-linear-gradient(90deg, rgba(90, 70, 40, .045) 0 1px, transparent 1px 3px),
    linear-gradient(180deg, rgba(255, 255, 255, .28), transparent 22%, rgba(90, 70, 40, .07) 48%,
      rgba(255, 255, 255, .18) 66%, transparent 84%, rgba(90, 70, 40, .06)),
    linear-gradient(270deg, #efe6d4, #f8f2e6 45%, #f3ebdc);
  /* cut by hand: the free corners are not quite the same */
  border-radius: 0 5px 3px 0 / 0 3px 7px 0;
  border-left: 3px solid #d8cbb2;
  /* a close shadow where it lies on the page and a soft one where it lifts off; the free edge rolled
     a little (inset) */
  box-shadow: 1px 1px 1px rgba(20, 30, 40, .16), 3px 4px 10px rgba(20, 30, 40, .18),
    inset -2px 0 2px -1px rgba(90, 70, 40, .14), inset 0 1px 0 rgba(255, 255, 255, .5);
  /* sewn on by hand, not quite straight: turned a little about the seam */
  transform: rotate(-.7deg); transform-origin: 0 50%;
  transition: transform .25s ease, box-shadow .25s ease;
}
.sewn-label::after {
  content: ""; position: absolute; inset: 4px 4px 4px 3px; pointer-events: none;
  border: 1px dashed rgba(120, 95, 60, .45); border-radius: 2px;
}
.sewn-label span { font-weight: 500; letter-spacing: 1.2px; text-transform: none; color: #6b6150; }
.sewn-label strong { font-weight: 700; }
.sewn-label:hover, .sewn-label:focus-visible {
  transform: rotate(-.7deg) translateX(3px);
  box-shadow: 1px 1px 2px rgba(20, 30, 40, .18), 5px 6px 14px rgba(20, 30, 40, .22),
    inset -2px 0 2px -1px rgba(90, 70, 40, .14), inset 0 1px 0 rgba(255, 255, 255, .5);
}
.sewn-label:focus-visible { outline: 2px solid #2f5a3c; outline-offset: 2px; }
/* at night the fabric is in the shade too */
body.night .sewn-label { filter: brightness(.78); }
/* phones: smaller, low on the edge, and whole: nothing slides behind the edge of the screen */
@media (max-width: 700px) {
  .sewn-label {
    top: auto; bottom: calc(18% + env(safe-area-inset-bottom, 0px));
    width: 22px; height: 164px; padding: 0 5px 0 4px; gap: 4px;
    font-size: 9px; line-height: 9px; letter-spacing: 1.2px;
  }
  .sewn-label span { letter-spacing: .8px; }
  .sewn-label::after { inset: 3px 3px 3px 2px; }
}
@media (prefers-reduced-motion: reduce) { .sewn-label { transition: none; } }
