.mobile-tab-bar { display: none; }
.modal-form input.sr-only { width: 1px; padding: 0; border: 0; }
.mobile-sheet {
  width: min(36rem, calc(100% - 2rem));
  max-height: calc(100dvh - 2rem);
  padding: 0;
  border: 1px solid #e2e8f0;
  border-radius: 1.5rem;
  background: #fff;
  color: #0f172a;
  box-shadow: 0 16px 60px #0f172a40;
}
.mobile-sheet::backdrop { background: #0f172a99; }
.mobile-sheet-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid #e2e8f0;
}
.mobile-sheet-heading h2 { font-size: 1.125rem; font-weight: 700; }
.mobile-sheet-heading button, .mobile-menu-logout button {
  min-height: 44px;
  padding: .5rem .75rem;
  border-radius: .75rem;
  background: #f1f5f9;
  font-weight: 600;
}
.mobile-menu-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: .75rem;
  padding: 1.25rem;
}
.mobile-menu-tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: .75rem;
  min-height: 90px;
  padding: .75rem .25rem;
  border: 1px solid #e2e8f0;
  border-radius: 1rem;
  color: #334155;
  font-size: .75rem;
  font-weight: 600;
  text-align: center;
}
.mobile-menu-tile svg { color: #4f46e5; }
.mobile-menu-tile:hover { background: #eef2ff; }
.mobile-menu-logout { padding: 0 1.25rem 1.25rem; }
.mobile-menu-logout button { width: 100%; color: #b91c1c; }
.pwa-install-content { padding: 1.25rem; font-size: .9375rem; line-height: 1.6; }
.pwa-install-content h3 { margin-top: 1rem; font-weight: 700; }
.pwa-install-content p { margin-bottom: .75rem; }
.pwa-install-note { color: #64748b; font-size: .8125rem; }
#pwa-install-prompt[hidden] { display: none; }

@media (max-width: 1023px) {
  .app-topbar { padding-top: max(.75rem, env(safe-area-inset-top)); }
  #app-sidebar { padding-top: env(safe-area-inset-top); padding-bottom: env(safe-area-inset-bottom); }
  #app-content {
    padding-left: max(.75rem, env(safe-area-inset-left));
    padding-right: max(.75rem, env(safe-area-inset-right));
    overscroll-behavior-y: contain;
  }
  .mobile-tab-bar {
    display: flex;
    flex-shrink: 0;
    justify-content: space-around;
    gap: .25rem;
    border-top: 1px solid #e2e8f0;
    background: #fff;
    padding: .4rem max(.5rem, env(safe-area-inset-right)) max(.4rem, env(safe-area-inset-bottom)) max(.5rem, env(safe-area-inset-left));
  }
  .mobile-tab {
    display: flex;
    flex: 1;
    min-width: 0;
    min-height: 52px;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: .3rem;
    border-radius: .75rem;
    color: #64748b;
    font-size: .6875rem;
    font-weight: 700;
  }
  .mobile-tab--dashboard { --tab-accent: #1d4ed8; --tab-tint: #dbeafe; }
  .mobile-tab--matters { --tab-accent: #0f766e; --tab-tint: #ccfbf1; }
  .mobile-tab--calendar_app { --tab-accent: #b45309; --tab-tint: #fef3c7; }
  .mobile-tab--time_entries { --tab-accent: #7e22ce; --tab-tint: #f3e8ff; }
  .mobile-tab--more { --tab-accent: #be185d; --tab-tint: #fce7f3; }
  .mobile-tab-icon {
    display: flex;
    flex: 0 0 32px;
    width: 36px;
    height: 32px;
    align-items: center;
    justify-content: center;
    border-radius: 10px;
    background: var(--tab-tint, #e0e7ff);
    color: var(--tab-accent, #4338ca);
  }
  .mobile-tab-icon svg { width: 22px; height: 22px; stroke-width: 2; }
  .mobile-tab[aria-current="page"] { background: var(--tab-tint, #eef2ff); color: var(--tab-accent, #4338ca); }
  .mobile-tab[aria-current="page"] .mobile-tab-icon { background: var(--tab-accent, #4338ca); color: #fff; }
  .mobile-tab:focus-visible { outline: 2px solid var(--tab-accent, #4338ca); outline-offset: -2px; }
  .mobile-tab:hover { background: #f1f5f9; }
}

@media (max-width: 639px) {
  .mobile-sheet {
    width: 100%;
    max-width: none;
    max-height: calc(100dvh - max(1rem, env(safe-area-inset-top)));
    margin: auto 0 0;
    border-radius: 1.5rem 1.5rem 0 0;
    padding-bottom: env(safe-area-inset-bottom);
  }
  .app-topbar { gap: .5rem; }
  .app-topbar [x-show="openCreate"],
  .app-topbar [x-show="openNotifications"] {
    position: fixed;
    top: calc(8rem + env(safe-area-inset-top));
    left: .75rem;
    right: .75rem;
    width: auto;
    max-height: calc(100dvh - 13rem);
    overflow-y: auto;
  }
  #app-content form .grid-cols-2 { grid-template-columns: minmax(0, 1fr); }
  #app-content form .grid-cols-2 > .col-span-2 { grid-column: auto / span 1; }
  #app-content input:not([type="checkbox"]):not([type="radio"]),
  #app-content select,
  #app-content textarea,
  body input[name="username"],
  body input[name="password"],
  .app-topbar input:not([type="checkbox"]):not([type="radio"]),
  .app-topbar select,
  .app-topbar textarea { font-size: 16px; max-width: 100%; }
  #app-content .btn-primary,
  #app-content .btn-secondary,
  #app-content .btn-danger,
  #app-content .matter-icon-btn,
  #app-content .bill-icon-btn,
  #app-content .matter-btn-lite,
  #app-content .contacts-btn,
  #app-content .bill-btn { min-height: 44px; }
  #app-content .matter-icon-btn,
  #app-content .bill-icon-btn { min-width: 44px; }
  .mobile-segments { max-width: 100%; overflow-x: auto; }
  .mobile-segments > a { flex-shrink: 0; white-space: nowrap; }
  .mobile-record-table { display: block; width: 100%; min-width: 0; }
  .mobile-record-table thead {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }
  .mobile-record-table tbody { display: block; padding: .75rem; }
  .mobile-record-table tbody > tr {
    display: block;
    margin-bottom: .75rem;
    padding: .5rem .75rem;
    border: 1px solid #e2e8f0;
    border-radius: 1rem;
    background: white;
  }
  .mobile-record-table tbody > tr:last-child { margin-bottom: 0; }
  .mobile-record-table tbody > tr > td {
    display: block;
    width: auto;
    min-width: 0;
    padding: .5rem 0;
    border: 0;
    white-space: normal;
    overflow-wrap: anywhere;
    text-align: left;
  }
  .mobile-record-table td[data-label]::before {
    content: attr(data-label);
    display: block;
    margin-bottom: .2rem;
    color: #64748b;
    font-size: .6875rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .04em;
  }
  #calendar { min-height: 0; }
  #calendar .fc-toolbar { flex-wrap: wrap; gap: .75rem; }
  #calendar .fc-toolbar-title { font-size: 1.125rem; }
  #calendar .fc-button { min-height: 44px; }
  .calendar-modal { max-height: calc(100dvh - 2rem); overflow-y: auto; }
}

@media print {
  .mobile-tab-bar, .mobile-sheet, [data-install-app] { display: none !important; }
}
