:root {
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
}

html,
body {
  min-height: 100vh;
  min-height: 100dvh;
}

#mobileNavToggle,
#mobileNavBackdrop {
  display: none;
}

#mobileNavToggle {
  border: 1px solid rgba(236, 240, 248, 0.46);
  background: rgba(236, 240, 248, 0.12);
  color: #e7eaf1;
  border-radius: 8px;
  padding: 0 10px;
  height: 44px;
  min-width: 44px;
  font-size: 22px;
  line-height: 1;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  cursor: pointer;
}

.top-merged .flash-msg {
  white-space: normal;
}

@media (max-width: 900px) {
  html,
  body {
    height: auto;
    overflow-x: hidden;
    overflow-y: auto;
  }

  body.mobile-nav-open {
    overflow: hidden;
  }

  .layout {
    grid-template-columns: 1fr;
    grid-template-rows: var(--topbar-h) 1fr;
    height: auto;
    min-height: 100vh;
    min-height: 100dvh;
    overflow: visible;
  }

  .top-merged {
    position: sticky;
    top: 0;
    z-index: 1000;
    padding-left: var(--safe-left);
    padding-right: var(--safe-right);
  }

  .top-merged-table {
    table-layout: auto;
  }

  .top-merged-left {
    width: auto;
    max-width: 40vw;
    padding-left: 6px;
    padding-right: 6px;
  }

  .top-merged-right {
    padding: max(8px, var(--safe-top)) 8px 8px;
  }

  .top-merged-right-inner {
    gap: 8px;
  }

  #viewTitle {
    font-size: 15px;
    line-height: 1.25;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 58vw;
  }

  #viewSubtitle {
    display: none;
  }

  .top-merged-title-row {
    min-height: 0;
    align-items: center;
    gap: 8px;
  }

  .top-audio-toggle {
    width: 44px;
    height: 44px;
  }

  #mobileNavToggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
  }

  aside {
    position: fixed;
    top: var(--topbar-h);
    left: 0;
    bottom: 0;
    width: min(88vw, 360px);
    height: auto;
    max-height: calc(100dvh - var(--topbar-h));
    border-right: 1px solid var(--border);
    border-bottom: none;
    background: var(--surface);
    transform: translateX(-105%);
    transition: transform 180ms ease;
    z-index: 1060;
    overflow-y: auto;
    padding-bottom: calc(12px + var(--safe-bottom));
    padding-left: var(--safe-left);
  }

  #mobileNavBackdrop {
    position: fixed;
    inset: var(--topbar-h) 0 0 0;
    background: rgba(0, 0, 0, 0.36);
    z-index: 1050;
  }

  body.mobile-nav-open aside {
    transform: translateX(0);
  }

  body.mobile-nav-open #mobileNavBackdrop {
    display: block;
  }

  main {
    grid-column: 1;
    grid-row: 2;
    min-width: 0;
    min-height: 0;
  }

  .content {
    overflow-x: hidden;
    overflow-y: auto;
    padding: 8px;
  }

  .content .view {
    padding: 0;
  }

  .content .panel {
    padding: 12px;
    margin-bottom: 10px;
  }

  .split,
  .grid-2,
  .grid-3,
  .two-col,
  .media-shell {
    grid-template-columns: 1fr !important;
  }

  .toolbar {
    flex-wrap: wrap;
    gap: 8px;
  }

  .toolbar > button,
  .toolbar > .ghost,
  .toolbar > .bad {
    min-height: 44px;
  }

  .flash-msg {
    white-space: normal;
    max-width: min(56vw, 320px);
  }

  .modal {
    align-items: flex-start;
    justify-content: center;
    padding: max(8px, var(--safe-top)) max(8px, var(--safe-right)) calc(8px + var(--safe-bottom)) max(8px, var(--safe-left));
  }

  #bugTipModal {
    inset: 0 !important;
    width: 100vw !important;
    height: 100dvh !important;
    align-items: flex-start !important;
    justify-content: center !important;
    z-index: 1700;
    padding: max(10px, var(--safe-top)) max(10px, var(--safe-right)) calc(12px + var(--safe-bottom)) max(10px, var(--safe-left));
  }

  #bugTipModal .dialog.small {
    width: min(680px, 100%);
    max-height: calc(100dvh - var(--safe-top) - var(--safe-bottom) - 22px);
    margin: 0 auto;
  }

  #bugTipModal .dialog-body {
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  #bugTipMessage {
    min-height: clamp(180px, 34dvh, 320px);
  }

  .dialog,
  .dialog.small {
    width: 100%;
    max-width: 100%;
    max-height: calc(100dvh - var(--safe-top) - var(--safe-bottom) - 16px);
    border-radius: 10px;
  }

  .dialog-body {
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 14px;
  }

  .dialog-footer {
    flex-wrap: wrap;
    gap: 8px;
  }

  .dialog-footer button,
  .dialog-footer .ghost,
  .btn-close {
    min-height: 44px;
  }

  .view.view-modal.show-modal {
    inset: 0;
    padding: 8px;
  }

  section[data-view="underlag"] .toolbar > h2,
  section[data-view="kollegor"] .toolbar > h2,
  section[data-view="filer"] .toolbar > h2,
  section[data-view="uppdrag"] .toolbar > h2,
  section[data-view="admin"] .toolbar > h2,
  section[data-view="settings"] .toolbar > h2 {
    width: 100%;
    margin-bottom: 2px;
  }

  section[data-view="underlag"] .toolbar > button,
  section[data-view="kollegor"] .toolbar > button,
  section[data-view="uppdrag"] .toolbar > button,
  section[data-view="admin"] .toolbar > button,
  section[data-view="settings"] .toolbar > button {
    flex: 1 1 calc(50% - 8px);
  }

  section[data-view="profil"] #profileInfoCard > div {
    grid-template-columns: 1fr !important;
    gap: 8px !important;
  }

  section[data-view="generera"] [style*="grid-template-columns:1fr 1fr 1fr"],
  section[data-view="generera"] [style*="grid-template-columns:1fr 1fr"] {
    grid-template-columns: 1fr !important;
    grid-auto-flow: row !important;
    gap: 10px !important;
  }

  section[data-view="generera"] #genExperienceSelectionList,
  section[data-view="generera"] #genEducationSelectionList,
  #bundleList,
  #assignmentList,
  #fileList,
  #colleagueDraftList,
  #colleagueFileList,
  #adminUserList,
  #adminInviteList {
    max-height: none !important;
  }

  section[data-view="matcha"] #matchResultActions,
  section[data-view="generera"] .toolbar[style*="justify-content:flex-end"] {
    position: sticky;
    bottom: calc(var(--safe-bottom) + 8px);
    background: linear-gradient(to top, rgba(243, 242, 241, 0.98), rgba(243, 242, 241, 0.84));
    padding-top: 8px;
    z-index: 2;
  }

  section[data-view="filer"] [style*="grid-template-columns:auto 1fr"],
  section[data-view="filer"] [style*="grid-template-columns:auto 1fr 28px"],
  section[data-view="kollegor-filer"] [style*="grid-template-columns:auto 1fr"],
  section[data-view="kollegor-filer"] [style*="grid-template-columns:auto 1fr 28px"] {
    grid-template-columns: 1fr !important;
    gap: 8px !important;
  }

  section[data-view="filer"] #btnUploadFiles,
  section[data-view="kollegor-filer"] #btnUploadColleagueFiles,
  section[data-view="generera"] #btnGenerateCV,
  section[data-view="matcha"] #btnMatchDraft,
  section[data-view="matcha"] #btnMatchCreateBundleForAssignment {
    width: 100%;
  }

  section[data-view="matrix"] .matrix-source-content,
  section[data-view="matrix"] #matrixInternalRow {
    grid-template-columns: 1fr !important;
  }

  .nav-link,
  .nav-item,
  button,
  .ghost,
  .bad {
    min-height: 44px;
  }

  input,
  select,
  textarea,
  button {
    font-size: 16px;
  }
}

@media (prefers-reduced-motion: reduce) {
  body.lava-bg-test .lava-bubble {
    animation: none !important;
  }

  aside,
  #mobileNavBackdrop,
  .modal,
  .dialog,
  .flash-msg {
    transition: none !important;
  }
}
