/* ===========================================================================
   Phone navigation
   ===========================================================================
   On a desktop the sections are reachable from the sidebar and the
   breadcrumb trail. Neither survives a phone: the sidebar is hidden at that
   width, and the trail wrapped onto two lines of small type that told you
   where you were without letting you go anywhere.

   So below the breakpoint the header becomes three things - a menu button,
   the practice name, the light/dark switch - with the greeting under them,
   and everything else moves into a drawer: the sections, the calendar, the
   dashboard, and the account links that used to crowd the bar.

   Above the breakpoint none of this exists; the header is django's.
   =========================================================================== */

/* The strip that colours an iPhone's status bar (2.14.1; base_site.html,
   at the top of the name's block). Only on a phone, below. */
.bm-status-tint {
  display: none;
}

/* The menu icon. On a desktop (2.8.x) it sits at the left of the name and folds the
   sidebar away and brings it back, in place of django's « strip down the
   side of the page (the owner's call). Only on pages that have a sidebar:
   the home page lists every section itself. mobile-nav.js passes its click
   to django's own toggle, so whether the sidebar is open is remembered as
   before. Below the breakpoint the rules further down restate what the
   phone needs: there it is on every page, and opens the drawer. */
.mnav-open {
  display: none;
  align-items: center;
  justify-content: center;
  flex: none;
  width: 42px;
  height: 42px;
  margin: 0 14px 0 -12px;
  padding: 0;
  border: none;
  border-radius: 10px;
  background: transparent;
  color: var(--header-link-color, #fff);
  cursor: pointer;
}

body:has(#toggle-nav-sidebar) .mnav-open {
  display: flex;
}

/* On the name's middle: django lays the header's left-hand group out as a
   flex row but leaves its items at the top, which put the button above
   the words beside it. */
#branding {
  align-items: center;
}

.mnav-open:hover {
  background: rgba(255, 255, 255, 0.16);
}

/* A squeeze rather than django's 1px nudge, as on the phone below. */
.mnav-open:active {
  transform: scale(0.92);
}

/* Three bars drawn from one element: a middle rule plus two shadows. One
   box to position instead of three, and it inherits the header's colour
   like the theme switch beside it. */
.mnav-bars,
.mnav-bars::before,
.mnav-bars::after {
  display: block;
  width: 22px;
  height: 2.5px;
  border-radius: 2px;
  background: currentColor;
}

.mnav-bars {
  position: relative;
}

.mnav-bars::before,
.mnav-bars::after {
  content: "";
  position: absolute;
  left: 0;
}

.mnav-bars::before {
  top: -7px;
}

.mnav-bars::after {
  top: 7px;
}

/* Alive under the pointer (2.14.0, the owner's call, as the gear and the
   theme switch beside it): the soft round wash fades in, and the top and
   bottom bars draw in from opposite ends - the top one towards the right,
   the bottom one towards the left - round the middle one, which stays
   whole: a balanced zigzag that never leaves the three bars' own box, so
   every bar keeps its distance from the wash's edge (a first try shortened
   the middle bar, which moved the box and pushed the top bar out). Back
   when the pointer leaves. Only where there is a pointer to hover with;
   still where less motion is asked for. */
.mnav-open {
  transition: background-color 0.15s ease;
}

/* The top bar measured from the right end, the bottom one from the left:
   at rest both as long as the middle one, so nothing moves until they
   draw in. */
.mnav-bars::before {
  right: 0;
  left: auto;
}

.mnav-bars::before,
.mnav-bars::after {
  transition: width 0.32s cubic-bezier(0.2, 0.8, 0.2, 1);
}

@media (hover: hover) {
  .mnav-open:hover .mnav-bars::before,
  .mnav-open:hover .mnav-bars::after {
    width: 62%;
  }
}

@media (prefers-reduced-motion: reduce) {
  .mnav-open,
  .mnav-bars::before,
  .mnav-bars::after {
    transition: none;
  }
}

@media (max-width: 767px) {
  /* The phone's icon keeps the size it has always had (2.9.0 made only
     the desktop one bigger). */
  .mnav-bars,
  .mnav-bars::before,
  .mnav-bars::after {
    width: 19px;
    height: 2px;
  }

  .mnav-bars::before {
    top: -6px;
  }

  .mnav-bars::after {
    top: 6px;
  }

  /* --- Header ----------------------------------------------------------- */

  /* Three rows' worth of content in two: the name centred between the two
     buttons, the greeting beneath it. #branding and #user-tools are
     siblings django stacks in a column at this size, so the centring is
     done by leaving symmetrical room for the buttons, which are lifted out
     of the flow. */
  #header {
    position: relative;
    display: block;
    padding: 10px 52px 9px;
    text-align: center;
  }

  #branding {
    display: block;
    padding: 0;
  }

  #branding #site-name {
    display: block;
    margin: 0;
  }

  #branding #site-name a {
    display: inline-block;
    font-size: 1.15rem;
    line-height: 1.25;
  }

  /* The iPhone's status bar - the strip with the clock over the top bar -
     in the top bar's colour (2.14.1, the owner's call; it was white).
     Safari on iOS 26 no longer reads a colour from the page's
     theme-color, nor from an ordinary header: it looks for an element
     pinned (fixed or sticky) at the very top of the screen, nearly as
     wide as it and more than 10px tall, and paints the status bar in that
     element's background-color; with none, in the page's own colour -
     white. The top bar is not pinned (it scrolls away with the page), so
     this strip is: the bar's flat colour (the phone's bar has no picture
     on it, see the palettes), the whole width, its first 12px, stuck at
     the top of the screen. It sits over the bar itself and is invisible
     there, takes no room (the margins give back exactly what it takes)
     and stays with the bar's top part: sticky inside #branding, it goes
     once the bar has been scrolled away, and the status bar then shows
     the page as any iPhone page does. Nothing else reads it - other
     browsers keep their own colour up there. Not on the login pages,
     whose name block is their own (and whose whole page is already the
     bar's colour). The margins are #header's padding, a few rules up. */
  .bm-status-tint {
    display: block;
    position: -webkit-sticky;
    position: sticky;
    top: 0;
    height: 12px;
    margin: -10px -52px -2px;
    background-color: var(--header-bg);
  }

  /* Only the greeting stays in the bar. The links it used to sit with are
     in the drawer's footer instead. */
  #user-tools {
    display: block;
    /* django floats this right. Left floating it shrinks to its own text
       and centring happens inside that shrunken box, so the greeting sat
       against the right edge instead of under the name. */
    float: none;
    margin: 3px 0 0;
    padding: 0;
    font-size: 0.66rem;
    line-height: 1.4;
    text-align: center;
  }

  #user-tools .user-links {
    display: none;
  }

  /* The trail is replaced by the drawer, which is a better answer to the
     same question: it says where everything is, not just where you are. */
  .breadcrumbs {
    display: none;
  }

  /* --- The two header buttons ------------------------------------------- */

  .mnav-open,
  #user-tools .theme-toggle {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    margin: 0;
  }

  #user-tools .theme-toggle {
    right: 10px;
  }

  /* Impostazioni's gear stays in the menu's corner on a phone: the bar
     holds the menu button, the name and the theme switch (2.14.0). */
  #user-tools a.topbar-gear,
  #user-tools a.topbar-gear:link,
  #user-tools a.topbar-gear:visited {
    display: none;
  }

  .mnav-open {
    left: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    padding: 0;
    border: none;
    border-radius: 9px;
    background: transparent;
    color: var(--header-link-color, #fff);
    cursor: pointer;
  }

  .mnav-open:hover,
  .mnav-open[aria-expanded="true"] {
    background: rgba(255, 255, 255, 0.16);
  }

  /* The button is centred in the header by "top: 50%" plus a -50% pull
     UP, and that pull lives in the transform property. brand.css gives
     every <button> a "transform: translateY(1px)" press cue - which
     doesn't add to the pull, it replaces it, so pressing the menu button
     dropped it half its own height (19px) before the drawer opened.

     Restating the pull here keeps it in place, and the press reads as a
     squeeze instead of a nudge - the right cue anyway for a round icon
     button that has nowhere to travel to. */
  .mnav-open:active {
    transform: translateY(-50%) scale(0.9);
  }

}

/* --- The drawer ---------------------------------------------------------- */

/* Rendered on every page but only ever opened below the breakpoint - the
   script does not bind above it. Kept out of the way with [hidden] so it
   costs nothing on a desktop. */
.mnav-backdrop {
  position: fixed;
  inset: 0;
  z-index: 1300;
  background: rgba(0, 0, 0, 0);
  transition: background-color 0.2s ease;
}

.mnav-backdrop.is-open {
  background: rgba(0, 0, 0, 0.42);
}

.mnav-backdrop[hidden] {
  display: none;
}

.mnav {
  position: fixed;
  z-index: 1310;
  top: 0;
  bottom: 0;
  left: 0;
  width: min(310px, 84vw);
  display: flex;
  flex-direction: column;
  background: var(--body-bg);
  border-right: 1px solid var(--border-color);
  box-shadow: 8px 0 34px rgba(0, 0, 0, 0.28);
  transform: translateX(-100%);
  transition: transform 0.24s cubic-bezier(0.32, 0.72, 0, 1);
}

.mnav[hidden] {
  display: none;
}

.mnav.is-open {
  transform: translateX(0);
}

@media (prefers-reduced-motion: reduce) {
  .mnav,
  .mnav-backdrop {
    transition: none;
  }
}

.mnav-head {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 14px 12px 18px;
  /* Carries the header's own colour, so opening the drawer reads as pulling
     the top bar sideways rather than as arriving somewhere else. */
  background: var(--header-bg);
  color: var(--header-color);
}

.mnav-title {
  font-size: 0.95rem;
  font-weight: 600;
  line-height: 1.25;
  color: var(--header-branding-color);
}

/* Focus lands on the drawer itself when it opens (mobile-nav.js), so that
   Tab starts from its first entry. The drawer is not a control: no ring. */
.mnav:focus {
  outline: none;
}

/* Impostazioni (2.9.1): a gear in the corner where the close button was.
   The drawer closes with a tap on the page beside it, which is what a
   thumb did anyway. Drawn on the header's colour like the menu button,
   and brighter on the Impostazioni page itself. */
/* Just the gear at rest (2.14.0, the owner's call: cleaner) - the round
   wash only while it is pressed, or under a mouse, or reached with the
   keyboard. The 36px target stays the same. */
.mnav-gear,
.mnav-gear:link,
.mnav-gear:visited {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 999px;
  background: transparent;
  color: var(--header-link-color, #fff);
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;
  transition: background-color 0.15s ease, transform 0.1s ease;
}

@media (hover: hover) {
  .mnav-gear:hover {
    background: rgba(255, 255, 255, 0.16);
    color: var(--header-link-color, #fff);
  }
}

.mnav-gear:focus-visible {
  background: rgba(255, 255, 255, 0.16);
  outline: 2px solid rgba(255, 255, 255, 0.7);
  outline-offset: 1px;
}

.mnav-gear:active {
  background: rgba(255, 255, 255, 0.24);
  transform: scale(0.92);
}

.mnav-gear svg {
  display: block;
}

/* The gear turns, as the top bar's does on a computer (2.14.0, the
   owner's call): under the pointer where there is one, and while pressed
   - a phone's tap - a quicker, wider turn, so it is seen before
   Impostazioni opens. Still where less motion is asked for. */
.mnav-gear .icon-gear {
  transition: transform 0.45s cubic-bezier(0.2, 0.8, 0.2, 1);
}

@media (hover: hover) {
  .mnav-gear:hover .icon-gear {
    transform: rotate(60deg);
  }
}

.mnav-gear:focus-visible .icon-gear {
  transform: rotate(60deg);
}

.mnav-gear:active .icon-gear {
  transform: rotate(90deg);
  transition-duration: 0.25s;
}

@media (prefers-reduced-motion: reduce) {
  .mnav-gear .icon-gear {
    transition: none;
  }

  .mnav-gear:hover .icon-gear,
  .mnav-gear:focus-visible .icon-gear,
  .mnav-gear:active .icon-gear {
    transform: none;
  }
}

.mnav-body {
  flex: 1 1 auto;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 10px 0 16px;
}

/* A section's name over its links (2.13.0: a little bigger, and in the
   text's own colour rather than the quiet grey, so the sections stand
   apart at a glance). */
.mnav-section {
  margin: 18px 0 4px;
  padding: 0 18px;
  font-size: 0.74rem;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--body-fg);
}

/* Buttons and links share the row shape: in this list they do the same job,
   and a 46px row is what a thumb expects either way. */
.mnav-link,
.mnav-link:link,
.mnav-link:visited {
  display: flex;
  align-items: center;
  width: 100%;
  box-sizing: border-box;
  min-height: 46px;
  padding: 11px 18px;
  border: none;
  background: none;
  color: var(--body-fg);
  font-family: inherit;
  font-size: 0.88rem;
  text-align: left;
  text-decoration: none;
  cursor: pointer;
}

.mnav-link:hover,
.mnav-link:focus-visible {
  background: var(--darkened-bg);
  color: var(--body-fg);
}

.mnav-link.mnav-strong,
.mnav-link.mnav-strong:link,
.mnav-link.mnav-strong:visited {
  font-weight: 600;
  color: var(--link-fg);
}

/* Where you already are. */
.mnav-link.is-current,
.mnav-link.is-current:link,
.mnav-link.is-current:visited {
  background: var(--selected-bg);
  box-shadow: inset 3px 0 0 var(--link-fg);
  font-weight: 600;
}

.mnav-foot {
  flex: none;
  padding: 8px 0;
  padding-bottom: max(8px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--hairline-color);
  background: var(--md-surface-sunken);
}

.mnav-foot .mnav-link {
  font-size: 0.82rem;
  color: var(--body-quiet-color);
}

.mnav-logout {
  color: var(--error-fg);
}

/* --- Form rows ----------------------------------------------------------- */

/* Not strictly navigation, but the same class of problem: django's
   responsive.css sets ".form-row { padding: 15px 0 }" below the breakpoint,
   so every control sat flush against - and a pixel over - the border of the
   card holding it. Inset to match the card's own rhythm. */
@media (max-width: 1024px) {
  fieldset.module .form-row {
    /* border-box is the load-bearing half. The row is width:100% and
       content-box, so padding added to it lands OUTSIDE that 100% - the
       first attempt at this pushed every row 32px wider than the card it
       sits in, which is the same fault one level up. */
    box-sizing: border-box;
    padding-left: 16px;
    padding-right: 16px;
  }

  fieldset.module .form-row > div,
  fieldset.module .form-row .flex-container,
  fieldset.module .form-row .related-widget-wrapper {
    min-width: 0;
    max-width: 100%;
  }
}
