/* Shared mobile shell, touch targets and dialog presentation. */
:root {
  --phone-dock: 62px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

.mobile-dock { display: none; }
.more-links { display: grid; }
.more-link {
  display: grid;
  grid-template-columns: 22px minmax(0, 1fr) 16px;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 52px;
  padding: 9px 4px;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: white;
  color: var(--ink);
  text-align: left;
  font-weight: 580;
}
.more-link:last-child { border-bottom: 0; }
.more-link > svg { color: var(--muted); }
.more-link:hover, .more-link[aria-current] { color: var(--blue); background: var(--soft); }

body:has(#dialog[open]) { overflow: hidden; }
#dialog #toast {
  position: sticky;
  width: fit-content;
  margin: 8px 12px 0 auto;
  inset: 60px 12px auto auto;
  display: none;
}
#dialog #toast.visible {
  display: block;
  z-index: 4;
  transform: none;
}

@media (max-width: 768px), (max-width: 920px) and (max-height: 500px) and (orientation: landscape) and (pointer: coarse) {
  html:has(.app-shell.mobile-priority) {
    scroll-padding-bottom: calc(var(--phone-dock) + var(--safe-bottom) + 12px);
  }
  .app-shell.mobile-priority {
    padding-bottom: calc(var(--phone-dock) + var(--safe-bottom) + 1px);
  }
  .mobile-priority .mobile-menu,
  .mobile-priority .sidebar,
  .mobile-priority .menu-dismiss { display: none; }

  .mobile-priority .workspace { display: block; }
  .mobile-priority .topbar {
    position: sticky;
    top: 0;
    z-index: 6;
    min-height: calc(54px + var(--safe-top));
    padding: var(--safe-top) max(13px, var(--safe-right)) 0 max(13px, var(--safe-left));
    gap: 8px;
  }
  .mobile-priority .topbar .mobile-brand { transform: scale(.77); margin: 0; }
  .mobile-priority .topbar .crumb { flex: 1; min-width: 0; }
  .mobile-priority .topbar .crumb > span, .mobile-priority .topbar .crumb > svg { display: none; }
  .mobile-priority .topbar .crumb strong {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 15px;
  }
  .mobile-priority .topbar .account { justify-content: center; min-width: 44px; min-height: 44px; }
  .mobile-priority .topbar .account > span:last-child { display: none; }
  .mobile-priority .top-end { gap: 1px; }
  .mobile-priority .top-end .icon-button { width: 44px; height: 44px; }
  .mobile-priority .main-content {
    padding-inline: max(16px, var(--safe-left)) max(16px, var(--safe-right));
    padding-block: 14px 22px;
  }

  .mobile-dock {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    position: fixed;
    inset: auto 0 0;
    z-index: 7;
    background: #fff;
    border-top: 1px solid #ccdfe9;
    padding: 0 var(--safe-right) var(--safe-bottom) var(--safe-left);
  }
  .dock-link {
    display: flex;
    min-height: var(--phone-dock);
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    min-width: 0;
    padding: 5px 2px;
    border: 0;
    border-radius: 0;
    background: transparent;
    color: #476176;
    font-size: 11px;
    line-height: 1.2;
    font-weight: 630;
  }
  .dock-link > :last-child { white-space: nowrap; }
  .dock-link:focus-visible { outline-offset: -3px; }
  .dock-link[aria-current] {
    color: #05688f;
    background: var(--accent-soft);
    box-shadow: inset 0 2px 0 var(--accent);
  }
  .dock-link:active { background: #e8f4fb; }
  .dock-icon { position: relative; display: inline-flex; }
  .dock-badge {
    position: absolute;
    top: -5px;
    left: 14px;
    min-width: 16px;
    padding: 1px 4px;
    border: 1px solid white;
    border-radius: 999px;
    background: #076784;
    color: white;
    text-align: center;
    font-size: 10px;
    line-height: 14px;
    font-weight: 750;
  }
  body:has(.mobile-priority) > #toast {
    bottom: calc(var(--phone-dock) + var(--safe-bottom) + 10px);
    right: max(12px, var(--safe-right));
  }
}

@media (max-width: 640px), (max-width: 920px) and (max-height: 500px) and (orientation: landscape) and (pointer: coarse) {
  html { scroll-padding-top: calc(62px + var(--safe-top)); }
  .mobile-priority .btn, #dialog .btn, .login-card .btn {
    min-height: 44px;
    padding-block: 10px;
  }
  .login .role-tabs button { min-height: 44px; }
  .login-content {
    padding-top: calc(12px + var(--safe-top));
    padding-left: max(16px, var(--safe-left));
    padding-right: max(16px, var(--safe-right));
    gap: 14px;
  }
  .login-brand .brand-full { width: 73px; height: 54px; }
  .login-card h1 { font-size: 24px; }
  .login-card form { gap: 11px; }
  .login-intro { min-height: 158px; }
  .login-caption .login-slogan { font-size: clamp(26px, 8vw, 35px); }
  .credentials summary, .login-footer .text-button { min-height: 44px; align-content: center; }
  .password-field .text-button { min-height: 44px; padding-inline: 6px; }
  .login :is(input, select, textarea),
  .mobile-priority .main-content :is(input, select, textarea),
  #dialog :is(input, select, textarea) { font-size: 16px; }
  .login :is(input, select, textarea):not([type=checkbox], [type=radio], [type=file]),
  .mobile-priority .main-content :is(input, select, textarea):not([type=checkbox], [type=radio], [type=file]),
  #dialog :is(input, select, textarea):not([type=checkbox], [type=radio], [type=file]) { min-height: 44px; }
  #dialog[open] {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100dvh;
    max-width: none;
    max-height: none;
    margin: 0;
    border: 0;
    border-radius: 0;
    overflow: auto;
    overscroll-behavior: contain;
    scroll-padding: calc(58px + var(--safe-top)) 0 calc(16px + var(--safe-bottom));
  }
  #dialog[data-presentation=sheet][open] {
    inset: auto 0 0;
    height: auto;
    max-height: min(82dvh, calc(100dvh - var(--safe-top) - 18px));
    border: 1px solid var(--line);
    border-radius: 15px 15px 0 0;
  }
  #dialog .dialog-head {
    padding: calc(5px + var(--safe-top)) max(16px, var(--safe-right)) 5px max(16px, var(--safe-left));
  }
  #dialog[data-presentation=sheet] .dialog-head { padding-top: 5px; }
  #dialog #toast { top: calc(57px + var(--safe-top)); }
  #dialog[data-presentation=sheet] #toast { top: 57px; }
  #dialog .dialog-head h2 { font-size: 19px; overflow-wrap: anywhere; }
  #dialog .dialog-head .icon-button { width: 44px; height: 44px; flex: 0 0 44px; }
  #dialog .dialog-body {
    padding: 16px max(16px,var(--safe-right)) calc(20px + var(--safe-bottom)) max(16px,var(--safe-left));
  }
  #dialog .dialog-body .actions > button { min-width: 44px; }
}
@media (max-width: 355px) {
  .login .role-tabs button { font-size: 11px; }
  .login .role-tabs button svg { display: none; }
}


@media (min-width: 921px) and (max-width: 1179px) {
  .app-shell:has(.role-admin) { grid-template-columns: 188px minmax(0,1fr); }
}
