.mobile-primary-navigation,
.mobile-pane-bar,
.mobile-pane-back,
.mobile-notes-empty {
  display: none;
}

@media (max-width: 820px), (pointer: coarse) and (max-height: 600px) {
  html.mobile-layout-active {
    height: 100%;
    overflow: hidden;
  }

  body.mobile-layout-active {
    position: fixed;
    inset: 0;
    display: flex;
    flex-direction: column;
    width: 100%;
    height: var(--mobile-viewport-height, 100dvh);
    min-height: 0;
    overflow: hidden;
  }

  .mobile-layout-active .app-header {
    flex: none;
    min-height: 52px;
    padding: calc(4px + env(safe-area-inset-top, 0px)) calc(10px + env(safe-area-inset-right, 0px)) 6px calc(10px + env(safe-area-inset-left, 0px));
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 8px;
  }

  .mobile-layout-active .app-header h1,
  .mobile-layout-active .theme-control > span,
  .mobile-layout-active .workspace-sidebar-controls,
  .mobile-layout-active .assistant-toggle {
    display: none;
  }

  .mobile-layout-active .brand {
    flex-wrap: wrap;
    gap: 2px 6px;
    font-size: 14px;
    font-weight: 600;
    line-height: 1.4;
  }

  .mobile-layout-active .brand > .brand-name {
    max-width: 150px;
    font-size: 14px;
  }

  .mobile-layout-active .brand .local-guest {
    font-size: 13px;
    font-weight: 400;
    line-height: 1.4;
  }

  .mobile-layout-active .header-controls {
    grid-column: 2;
    grid-row: 1;
    gap: 4px;
  }

  .mobile-layout-active #theme-select {
    width: 88px;
    min-height: 44px;
    padding-block: 4px;
  }

  .mobile-layout-active .language-toggle,
  .mobile-layout-active .guest-space-badge {
    min-width: 44px;
    min-height: 44px;
  }

  .mobile-layout-active .app-status {
    flex: none;
    max-height: 30dvh;
    padding: 6px 12px;
    overflow: auto;
    justify-content: flex-start;
  }

  .mobile-layout-active .app-status #status-text {
    flex: 1 1 auto;
    min-width: 0;
    overflow-wrap: anywhere;
    white-space: normal;
  }

  .mobile-layout-active .app-status .status-retry {
    flex: 0 0 auto;
    min-width: 44px;
    min-height: 44px;
    padding: 0 8px;
    white-space: nowrap;
  }

  .mobile-layout-active .workspace-modebar {
    flex: none;
    min-height: 52px;
    padding: 4px 12px;
    flex-wrap: nowrap;
  }

  .mobile-layout-active .workspace-mode-controls {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    width: 100%;
  }

  .mobile-layout-active .workspace-mode-button {
    min-height: 44px;
  }

  .mobile-layout-active .workspace {
    position: relative;
    flex: 1 1 auto;
    display: block;
    width: 100%;
    min-height: 0;
    overflow: hidden;
  }

  .mobile-layout-active .workspace > :is(#documents-panel, #reader-panel, #data-workspace, #notes-panel) {
    position: absolute;
    inset: 0;
    display: none;
    width: 100%;
    max-width: 100%;
    height: 100%;
    min-height: 0;
    border: 0;
  }

  .mobile-layout-active .workspace[data-mobile-pane="library"] > #documents-panel,
  .mobile-layout-active .workspace[data-mobile-pane="notes"] > #notes-panel {
    display: block !important;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
  }

  .mobile-layout-active .workspace[data-mobile-pane="reader"] > #reader-panel:not([hidden]) {
    display: flex;
    overflow: hidden;
  }

  .mobile-layout-active .workspace[data-mobile-pane="data"] > #data-workspace:not([hidden]) {
    display: block;
    padding: 12px;
    overflow: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
  }

  .mobile-primary-navigation {
    z-index: 35;
    flex: none;
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    min-height: calc(60px + env(safe-area-inset-bottom, 0px));
    padding: 4px max(8px, env(safe-area-inset-right, 0px)) calc(4px + env(safe-area-inset-bottom, 0px)) max(8px, env(safe-area-inset-left, 0px));
    border-top: 1px solid var(--ui-border);
    background: var(--ui-surface);
  }

  .mobile-primary-button {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    min-width: 0;
    min-height: 48px;
    padding: 3px 4px;
    border: 0;
    border-radius: 0;
    background: transparent;
    color: var(--ui-text-soft);
    font-size: 12px;
    font-weight: 500;
    line-height: 1.35;
    cursor: pointer;
  }

  .mobile-primary-button::before {
    position: absolute;
    top: -4px;
    left: 30%;
    width: 40%;
    height: 2px;
    background: transparent;
    content: "";
  }

  .mobile-primary-button > svg {
    display: block;
    width: 22px;
    height: 22px;
    flex: none;
  }

  .mobile-primary-label {
    display: block;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .mobile-primary-button[aria-pressed="true"] {
    background: transparent;
    color: var(--ui-primary);
  }

  .mobile-primary-button[aria-pressed="true"]::before {
    background: var(--ui-primary);
  }

  .mobile-layout-active :is(button, .button, summary, select) {
    min-height: 44px;
  }

  .mobile-layout-active :is(input:not([type="checkbox"]):not([type="radio"]), select, textarea, [contenteditable="true"]) {
    font-size: 16px !important;
  }

  .mobile-layout-active :is(input, select, textarea) {
    max-width: 100%;
  }

  .mobile-layout-active :is(.documents-panel, .reader-panel, .notes-panel) {
    font-size: 14px;
    font-weight: 400;
    line-height: 1.55;
  }

  .mobile-layout-active :is(.document-open, .note-open) {
    font-size: 15px;
    font-weight: 400;
    line-height: 1.55;
  }

  .mobile-layout-active .reader-heading-row h2 {
    font-size: 16px;
    font-weight: 600;
    line-height: 1.4;
  }

  .mobile-layout-active :is(.paper-library-summary, .study-library-summary, .notes-section-summary, .saved-notes-heading h3) {
    font-size: 15px;
    font-weight: 600;
    line-height: 1.45;
  }

  .mobile-layout-active :is(.app-status, .reader-loading) {
    font-size: 14px;
    font-weight: 400;
    line-height: 1.55;
  }

  .mobile-layout-active :is(.document-title, .page-count, .library-search-label, .library-trash-help, .note-label, .note-source, .anchor-help, .rich-text-draft-help, .character-count, .notes-count, .notes-empty, .reader-progress-status, .reader-loading-hint, .reader-error-reference) {
    font-size: 13px;
    font-weight: 400;
    line-height: 1.5;
  }

  .mobile-layout-active :is(pre, .analysis-table-scroll, .data-imports-table-scroll, .assistant-answer-table-scroll, #dataset-preview) {
    max-width: 100%;
    overflow: auto;
    overscroll-behavior: contain;
  }

  .mobile-layout-active .mobile-pane-bar {
    position: sticky;
    top: 0;
    z-index: 3;
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 52px;
    padding: 4px 12px;
    border-bottom: 1px solid var(--ui-border);
    background: var(--ui-surface);
  }

  .mobile-layout-active :is(.mobile-pane-bar, .notes-heading) > :is(strong, h2) {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
    line-height: 1.35;
  }

  .mobile-pane-back {
    align-items: center;
    justify-content: center;
    width: 44px;
    min-width: 44px;
    min-height: 44px;
    padding: 0;
    border: 0;
    border-radius: 3px;
    background: transparent;
    color: var(--ui-text-soft);
    cursor: pointer;
  }

  .mobile-pane-back > svg {
    width: 22px;
    height: 22px;
  }

  .mobile-layout-active .mobile-pane-back {
    display: inline-flex;
  }

  .mobile-layout-active #paper-library > .paper-library-summary {
    display: none;
  }

  .mobile-layout-active .library-search {
    padding: 12px;
  }

  .mobile-layout-active .library-search-row .button,
  .mobile-layout-active .paper-library-actions .button {
    min-height: 44px;
  }

  .mobile-layout-active .documents-list {
    display: block;
  }

  .mobile-layout-active #documents-list .document-item,
  .mobile-layout-active #documents-list .document-open {
    height: auto;
    min-height: 64px;
  }

  .mobile-layout-active .document-open,
  .mobile-layout-active .search-result-open {
    min-height: 56px;
    padding-block: 10px;
  }

  .mobile-layout-active #documents-list .document-menu-button,
  .mobile-layout-active .document-menu-button {
    width: 44px;
    height: 44px;
    min-height: 44px;
    margin-right: 8px;
  }

  .mobile-layout-active .reader-heading-row {
    flex: none;
    min-height: 52px;
    padding: 6px 12px;
  }

  .mobile-layout-active .reader-toolbar {
    flex: none;
    flex-flow: row nowrap;
    align-items: center;
    justify-content: flex-start;
    max-width: 100%;
    min-height: 56px;
    padding: 6px 12px;
    gap: 10px;
    overflow-x: auto;
    overflow-y: hidden;
    overscroll-behavior-inline: contain;
    -webkit-overflow-scrolling: touch;
  }

  .mobile-layout-active .reader-toolbar > * {
    flex: 0 0 max-content;
    width: max-content;
    min-width: max-content;
    max-width: none;
    flex-wrap: nowrap;
    white-space: nowrap;
  }

  .mobile-layout-active .reader-toolbar :is(.reader-reading-controls, .reader-view-label, .translation-controls, .text-annotation-toolbar:not([data-contextual="true"]), .reader-shape-tools, .text-annotation-colors, .annotated-pdf-export) {
    flex: none;
    min-width: max-content;
    max-width: none;
    flex-wrap: nowrap;
    white-space: nowrap;
  }

  .mobile-layout-active .reader-toolbar :is(.button, button, select, label, output) {
    flex: none;
    max-width: none;
    white-space: nowrap;
  }

  .mobile-layout-active .reader-toolbar .button,
  .mobile-layout-active .reader-toolbar select,
  .mobile-layout-active #page-input {
    min-height: 44px;
  }

  .mobile-layout-active .reader-toolbar .button-icon {
    width: 44px;
  }

  .mobile-layout-active #zoom-fit {
    display: inline-flex;
  }

  .mobile-layout-active .reader-translation-layout {
    flex: 1 1 auto;
    min-height: 0;
    overflow: hidden;
  }

  .mobile-layout-active .reader-translation-layout[data-translation-open="true"] {
    grid-template-rows: minmax(0, 1fr) minmax(0, 45%);
  }

  .mobile-layout-active .reader-stage {
    flex: 1 1 auto;
    justify-content: flex-start;
    min-height: 0;
    max-height: none;
    padding: 12px;
    overflow: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
  }

  .mobile-layout-active .reader-pages {
    width: max-content;
    min-width: 100%;
  }

  .mobile-layout-active .translation-panel {
    max-height: none;
  }

  .mobile-layout-active .text-annotation-toolbar[data-contextual="true"] {
    max-width: calc(100vw - 16px);
    overflow-x: auto;
    overscroll-behavior-inline: contain;
  }

  .mobile-layout-active #reader-shape-editor {
    gap: 6px;
    width: min(360px, calc(var(--mobile-viewport-width, 100vw) - 16px - env(safe-area-inset-left, 0px) - env(safe-area-inset-right, 0px)));
    max-height: calc(var(--mobile-viewport-height, 100dvh) - 16px - env(safe-area-inset-bottom, 0px));
    padding: 8px;
    overflow-y: auto;
    overscroll-behavior: contain;
    border-radius: 4px;
    -webkit-overflow-scrolling: touch;
  }

  .mobile-layout-active #reader-shape-editor > label {
    gap: 3px;
  }

  .mobile-layout-active #reader-shape-editor[data-kind]:not([data-kind="textbox"]) {
    width: min(320px, calc(var(--mobile-viewport-width, 100vw) - 16px - env(safe-area-inset-left, 0px) - env(safe-area-inset-right, 0px)));
    gap: 8px;
    padding: 12px;
  }

  .mobile-layout-active #reader-shape-description {
    height: 64px;
    min-height: 52px;
    max-height: 112px;
    padding: 6px 8px;
    border-radius: 3px;
    line-height: 1.4;
  }

  .mobile-layout-active #reader-shape-editor .reader-shape-style-row {
    flex-wrap: wrap;
    gap: 8px;
  }

  .mobile-layout-active #reader-shape-editor .reader-shape-color-field {
    flex: none;
    min-width: 0;
  }

  .mobile-layout-active #reader-shape-editor .reader-shape-color-palette {
    flex-wrap: nowrap;
  }

  .mobile-layout-active #reader-shape-editor :is(#reader-shape-width-field, #reader-shape-font-size-field) {
    flex: none;
    gap: 4px;
    white-space: nowrap;
  }

  .mobile-layout-active #reader-shape-editor :is(#reader-shape-width, #reader-shape-font-size) {
    width: 52px;
    height: 44px;
    min-height: 44px;
    padding: 4px 20px 4px 6px;
    border: 1px solid var(--ui-input-border);
    border-radius: 3px;
    background: var(--ui-input-bg);
    color: var(--ui-text);
  }

  .mobile-layout-active #reader-shape-editor .reader-shape-editor-actions {
    gap: 6px;
  }

  .mobile-layout-active #reader-shape-editor .reader-shape-editor-actions .button {
    flex: 0 1 auto;
    width: auto;
    min-width: 0;
    height: 44px;
    min-height: 44px;
    padding: 8px 14px;
    border-radius: 3px;
    font-size: 14px;
    font-weight: 500;
    line-height: 20px;
    white-space: nowrap;
  }

  .mobile-layout-active .notes-panel {
    padding-bottom: calc(20px + env(safe-area-inset-bottom, 0px));
  }

  .mobile-layout-active .notes-heading {
    position: sticky;
    top: 0;
    z-index: 3;
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 52px;
    padding: 4px 12px;
    border-bottom: 1px solid var(--ui-border);
    background: var(--ui-surface);
  }

  .mobile-layout-active .notes-section-summary {
    min-height: 44px;
    padding: 10px 12px;
    list-style-position: inside;
  }

  .mobile-layout-active .notes-section-summary :is(h2, h3) {
    display: inline;
    margin: 0;
    font: inherit;
  }

  .mobile-layout-active .saved-notes-summary .saved-notes-heading {
    display: inline-flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    width: calc(100% - 20px);
    min-height: 24px;
    padding: 0;
    vertical-align: middle;
  }

  .mobile-layout-active .note-editor {
    padding: 12px;
  }

  .mobile-layout-active #note-text,
  .mobile-layout-active #study-note-text {
    min-height: 180px;
  }

  .mobile-layout-active #rich-text-editor .ql-toolbar {
    flex-wrap: wrap;
    gap: 4px;
    max-width: 100%;
    padding: 4px;
    overflow: visible;
    white-space: normal;
  }

  .mobile-layout-active #rich-text-editor .ql-toolbar .ql-formats {
    flex-wrap: nowrap;
    gap: 4px;
    margin-right: 4px;
  }

  .mobile-layout-active #rich-text-editor .ql-toolbar button {
    width: 44px;
    min-width: 44px;
    height: 44px;
    min-height: 44px;
  }

  .mobile-layout-active #rich-text-editor .ql-toolbar button svg {
    width: 18px;
    height: 18px;
    max-width: 18px;
    max-height: 18px;
  }

  .mobile-layout-active #rich-text-editor .ql-toolbar .ql-picker {
    height: 44px;
    min-width: 44px;
    min-height: 44px;
    max-width: 112px;
  }

  .mobile-layout-active #rich-text-editor .ql-toolbar .ql-picker-label {
    max-width: 104px;
    font-size: 14px;
    line-height: 20px;
  }

  .mobile-layout-active #rich-text-editor .ql-toolbar .ql-picker-label > svg {
    width: 14px;
    height: 14px;
  }

  .mobile-layout-active #rich-text-editor .ql-toolbar .ql-picker-item {
    min-height: 44px;
  }

  .mobile-layout-active #rich-text-editor .ql-editor {
    min-height: 180px;
    max-height: none;
    font-size: 16px;
    line-height: 1.6;
  }

  .mobile-layout-active .note-actions .button,
  .mobile-layout-active .note-save-actions .button,
  .mobile-layout-active .notes-filter-actions .button {
    min-height: 44px;
  }

  .mobile-layout-active .workspace[data-mobile-pane="notes"][data-mobile-has-document="false"] #notes-panel > :not(.notes-heading):not(.mobile-notes-empty) {
    display: none;
  }

  .mobile-layout-active .workspace[data-mobile-has-document="false"] .mobile-notes-empty {
    display: block;
    margin: 12px;
    padding: 12px;
    border-left: 3px solid var(--ui-focus);
    background: var(--ui-info-bg);
    color: var(--ui-text-soft);
    line-height: 1.6;
  }

  .mobile-layout-active .mobile-notes-library {
    display: flex;
    margin-top: 12px;
  }

  .mobile-layout-active .workspace[data-mobile-has-document="false"] #notes-empty {
    display: none;
  }

  .mobile-layout-active .data-tool-switch {
    max-width: 100%;
    overflow-x: auto;
  }

  .mobile-layout-active #assistant-panel {
    z-index: 80;
    border: 0;
    border-radius: 0;
    box-shadow: none;
  }

  .mobile-layout-active .assistant-header {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    padding: calc(4px + env(safe-area-inset-top, 0px)) calc(8px + env(safe-area-inset-right, 0px)) 6px calc(12px + env(safe-area-inset-left, 0px));
    cursor: default;
    touch-action: pan-y;
  }

  .mobile-layout-active .assistant-header h2 {
    display: block;
    flex: 1 1 auto;
    align-self: center;
    min-height: 44px;
  }

  .mobile-layout-active .assistant-header-actions {
    display: contents;
  }

  .mobile-layout-active #assistant-history {
    order: 2;
    flex: 1 1 100%;
    width: 100%;
    min-height: 44px;
    font-size: 16px;
  }

  .mobile-layout-active :is(#assistant-new, #assistant-options, #assistant-clear) {
    order: 1;
    width: 44px;
    min-height: 44px;
  }

  .mobile-layout-active #assistant-full-page {
    display: none !important;
  }

  .mobile-layout-active #assistant-close {
    order: 1;
    width: 44px;
    min-height: 44px;
  }

  .mobile-layout-active .assistant-management > summary {
    display: flex;
    align-items: center;
    min-height: 44px;
    white-space: normal;
  }

  .mobile-layout-active .assistant-form {
    padding: 8px 12px calc(8px + env(safe-area-inset-bottom, 0px));
  }

  .mobile-layout-active #assistant-message {
    min-height: 72px;
    max-height: 30dvh;
    resize: none;
  }

  .mobile-layout-active .assistant-send-row .button,
  .mobile-layout-active .assistant-proposal-actions .button {
    min-height: 44px;
  }

  .mobile-layout-active .guest-access-dialog {
    max-height: calc(var(--mobile-viewport-height, 100dvh) - 16px);
    overflow: auto;
  }
}

@media (max-width: 420px) {
  .mobile-layout-active .library-search-row #library-search-input {
    flex-basis: 100%;
  }

  .mobile-layout-active .brand > .brand-name {
    max-width: 118px;
  }
}

@media (min-width: 821px) and (max-width: 1100px) {
  html:not(.mobile-layout-active) .workspace[data-workspace-mode="reading"],
  html:not(.mobile-layout-active) .workspace[data-workspace-mode="reading"][data-notes-visible="true"],
  html:not(.mobile-layout-active) .workspace[data-workspace-mode="data"],
  html:not(.mobile-layout-active) .workspace[data-workspace-mode="data"][data-notes-visible="true"] {
    grid-template-columns: minmax(190px, 220px) minmax(0, 1fr);
  }

  html:not(.mobile-layout-active) .workspace[data-workspace-mode="reading"][data-library-visible="false"],
  html:not(.mobile-layout-active) .workspace[data-workspace-mode="reading"][data-library-visible="false"][data-notes-visible="true"],
  html:not(.mobile-layout-active) .workspace[data-workspace-mode="data"][data-library-visible="false"],
  html:not(.mobile-layout-active) .workspace[data-workspace-mode="data"][data-library-visible="false"][data-notes-visible="true"] {
    grid-template-columns: minmax(0, 1fr);
  }

  html:not(.mobile-layout-active) .workspace > #notes-panel {
    position: fixed;
    inset: 0 0 0 auto;
    z-index: 35;
    width: min(380px, 44vw);
    min-height: 0;
    padding-bottom: calc(20px + env(safe-area-inset-bottom, 0px));
    overflow-y: auto;
    overscroll-behavior: contain;
    border-left: 1px solid var(--ui-border-strong);
    box-shadow: -8px 0 24px rgb(0 0 0 / 16%);
  }

  html:not(.mobile-layout-active) .workspace > #notes-panel .notes-heading {
    position: sticky;
    top: 0;
    z-index: 2;
    padding-top: calc(12px + env(safe-area-inset-top, 0px));
    background: var(--ui-surface);
  }

  html:not(.mobile-layout-active) .workspace > #notes-panel .mobile-pane-back {
    display: inline-flex;
  }
}

@media (pointer: coarse) and (min-width: 821px) {
  :is(.button, button, summary, select) {
    min-height: 44px;
  }

  :is(input:not([type="checkbox"]):not([type="radio"]), select, textarea) {
    font-size: 16px;
  }

  .document-menu-button {
    width: 44px;
    min-height: 44px;
  }
}

@media (pointer: coarse) and (min-width: 600px) and (max-height: 600px) {
  html.mobile-layout-active .workspace #reader-panel > .reader-heading-row {
    display: none;
  }

  body.mobile-layout-active:has(.workspace[data-workspace-mode="reading"][data-mobile-pane="reader"]) .app-header {
    display: none;
  }

  .mobile-layout-active .research-shell-picker {
    grid-template-columns: 20px minmax(0, 1fr);
    gap: 4px;
    padding: 0 max(8px, env(safe-area-inset-right, 0px)) 0 max(8px, env(safe-area-inset-left, 0px));
  }

  .mobile-layout-active .workspace-modebar {
    min-height: 44px;
    padding: 0 8px;
  }

  .mobile-layout-active .workspace-mode-controls {
    padding: 0;
    border: 0;
  }

  .mobile-layout-active .research-shell-picker-caption,
  .mobile-layout-active .mobile-primary-label {
    display: none;
  }

  .mobile-layout-active #mobile-primary-navigation {
    min-height: calc(48px + env(safe-area-inset-bottom, 0px));
    padding-top: 0;
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }

  .mobile-layout-active .mobile-primary-button {
    min-height: 44px;
    padding-block: 0;
  }
}
