/* 「ファイルをオープン」の画面を、プレビューのぶん広くする（Bootstrap の modal-xl は 1200px 未満の画面では狭いので、画面の幅に合わせる） */
@media (min-width: 576px) {
    .modal-dialog.filepreview-dialog {
        max-width: min(1140px, calc(100vw - 3.5rem));
    }
}

.filepreview-clear {
    clear: both;
}

.filepreview {
    margin-top: 14px;
}

.filepreview-status {
    margin: 8px 0;
    color: var(--bs-secondary-color, #888);
}

/* PDF.js で表示できなかったときの理由（小さく。1.3.1） */
.filepreview-reason {
    margin: 6px 0 0;
    color: var(--bs-secondary-color, #888);
    font-size: 11px;
    overflow-wrap: anywhere;
}

/* PDF（パソコン。ブラウザの PDF ビューア） */
.filepreview-frame {
    display: block;
    width: 100%;
    height: 72vh;
    min-height: 360px;
    border: 1px solid var(--bs-border-color, #ddd);
    border-radius: 6px;
    background: #fff;
}

/* PDF（スマホ・タブレット。PDF.js）（1.3.0）: 上に操作、下に PDF の枠 */
.filepreview-pdf-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    margin-bottom: 6px;
    /* ボタンを続けて押しても、画面全体が拡大されないように */
    touch-action: manipulation;
}

.filepreview-pdf-toolbar .btn {
    min-width: 36px;
}

.filepreview-pdf-zoom {
    min-width: 3.2em;
    text-align: center;
    font-variant-numeric: tabular-nums;
}

.filepreview-pdf-fullbutton {
    margin-left: auto;
}

/* 何ページ目か（PDF の枠の右上に重ねる。押せない） */
.filepreview-pdf-page {
    position: absolute;
    top: 8px;
    right: 10px;
    z-index: 10;
    padding: 1px 8px;
    border-radius: 10px;
    background: rgba(0, 0, 0, .55);
    color: #fff;
    font-size: 12px;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
    pointer-events: none;
}

.filepreview-pdf-wrap {
    position: relative;
    height: 72vh;
    min-height: 360px;
    overflow: hidden;
    border: 1px solid var(--bs-border-color, #ddd);
    border-radius: 6px;
    background: #e8e8ec;
}

[data-bs-theme="dark"] .filepreview-pdf-wrap {
    background: #26262b;
}

.filepreview-pdf-wrap .filepreview-status {
    position: absolute;
    top: 40%;
    right: 0;
    left: 0;
    margin: 0;
    text-align: center;
}

/*
 * スクロールする枠（PDF.js の PDFViewer は position: absolute を求める）。
 * touch-action で、指 2 本の拡大縮小を画面全体ではなく PDF に効かせる（拡大縮小は JS）。
 * 端までスクロールしても、「ファイルをオープン」の画面はスクロールさせない
 */
.filepreview-pdf-container {
    position: absolute;
    inset: 0;
    overflow: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-x pan-y;
}

.filepreview-pdf-container:focus {
    outline: none;
}

.filepreview-pdf-container:focus-visible {
    outline: 2px solid var(--bs-primary, #0d6efd);
    outline-offset: -2px;
}

.filepreview-pdf-container .pdfViewer {
    padding-top: 8px;
}

.filepreview-pdf-container .pdfViewer.removePageBorders .page {
    margin: 0 auto 8px;
    box-shadow: 0 1px 4px rgba(0, 0, 0, .25);
}

/* 全画面 */
.filepreview.filepreview-pdf-full {
    position: fixed;
    inset: 0;
    z-index: 1090;
    display: flex;
    flex-direction: column;
    margin: 0;
    padding: calc(6px + env(safe-area-inset-top, 0px)) calc(6px + env(safe-area-inset-right, 0px)) calc(6px + env(safe-area-inset-bottom, 0px)) calc(6px + env(safe-area-inset-left, 0px));
    background: var(--bs-body-bg, #fff);
}

.filepreview-pdf-full .filepreview-pdf-wrap {
    flex: 1 1 auto;
    height: auto;
    min-height: 0;
}

/* テキスト */
.filepreview-info {
    margin: 0 2px 4px;
    color: var(--bs-secondary-color, #888);
    font-size: 12px;
}

.filepreview-code {
    max-height: 65vh;
    margin: 0;
    padding: 0;
    overflow: auto;
    border: 1px solid var(--bs-border-color, #ddd);
    border-radius: 6px;
    background: var(--hh-background-color-secondary, #f9f9f9);
}

/* highlight.js の標準の見た目（github.css の背景・余白）は使わず、ここで決める */
.filepreview-code code,
.filepreview-code code.hljs {
    display: block;
    padding: 10px 12px;
    overflow: visible;
    background: transparent;
    color: var(--bs-body-color, #333);
    font-size: 12.5px;
    line-height: 1.5;
    white-space: pre;
    word-break: normal;
    overflow-wrap: normal;
    tab-size: 4;
}

/* 文章が中心のファイル（txt・md など）は折り返す */
.filepreview-code.filepreview-wrap code {
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

/* ダークモードの色分け（github.css の色は暗い背景では読めないので、GitHub のダークテーマに近い色にする） */
[data-bs-theme="dark"] .filepreview-code .hljs-comment,
[data-bs-theme="dark"] .filepreview-code .hljs-quote {
    color: #8b949e;
}

[data-bs-theme="dark"] .filepreview-code .hljs-keyword,
[data-bs-theme="dark"] .filepreview-code .hljs-selector-tag,
[data-bs-theme="dark"] .filepreview-code .hljs-subst {
    color: #ff7b72;
}

[data-bs-theme="dark"] .filepreview-code .hljs-number,
[data-bs-theme="dark"] .filepreview-code .hljs-literal,
[data-bs-theme="dark"] .filepreview-code .hljs-variable,
[data-bs-theme="dark"] .filepreview-code .hljs-template-variable,
[data-bs-theme="dark"] .filepreview-code .hljs-tag .hljs-attr,
[data-bs-theme="dark"] .filepreview-code .hljs-meta {
    color: #79c0ff;
}

[data-bs-theme="dark"] .filepreview-code .hljs-string,
[data-bs-theme="dark"] .filepreview-code .hljs-doctag,
[data-bs-theme="dark"] .filepreview-code .hljs-regexp,
[data-bs-theme="dark"] .filepreview-code .hljs-link {
    color: #a5d6ff;
}

[data-bs-theme="dark"] .filepreview-code .hljs-title,
[data-bs-theme="dark"] .filepreview-code .hljs-section,
[data-bs-theme="dark"] .filepreview-code .hljs-selector-id {
    color: #d2a8ff;
}

[data-bs-theme="dark"] .filepreview-code .hljs-type,
[data-bs-theme="dark"] .filepreview-code .hljs-class .hljs-title,
[data-bs-theme="dark"] .filepreview-code .hljs-symbol,
[data-bs-theme="dark"] .filepreview-code .hljs-bullet,
[data-bs-theme="dark"] .filepreview-code .hljs-built_in,
[data-bs-theme="dark"] .filepreview-code .hljs-builtin-name {
    color: #ffa657;
}

[data-bs-theme="dark"] .filepreview-code .hljs-tag,
[data-bs-theme="dark"] .filepreview-code .hljs-name,
[data-bs-theme="dark"] .filepreview-code .hljs-attribute {
    color: #7ee787;
}

[data-bs-theme="dark"] .filepreview-code .hljs-deletion {
    background: rgba(248, 81, 73, .15);
    color: #ffdcd7;
}

[data-bs-theme="dark"] .filepreview-code .hljs-addition {
    background: rgba(46, 160, 67, .15);
    color: #aff5b4;
}

/* ---- ダウンロード（iPhone・iPad のホーム画面のアプリ。取り寄せの進み具合・「保存・共有」） ---- */

/* HumHub の画面（モーダル。1055）より上 */
.filepreview-save-backdrop {
    position: fixed;
    inset: 0;
    z-index: 1100;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: calc(12vh + env(safe-area-inset-top)) 16px 16px;
    background: rgba(0, 0, 0, .45);
}

.filepreview-save {
    width: min(420px, 100%);
    padding: 18px 18px 14px;
    border-radius: 16px;
    background: var(--hh-background-color-main, #fff);
    box-shadow: 0 12px 40px rgba(0, 0, 0, .3);
    color: var(--bs-body-color, #333);
}

.filepreview-save-title {
    margin: 0 0 8px;
    overflow-wrap: anywhere;
    font-size: 1.05rem;
    font-weight: 700;
}

.filepreview-save-message {
    margin: 0 0 12px;
}

.filepreview-save-message:empty {
    display: none;
}

.filepreview-save-progress {
    height: 6px;
    margin-bottom: 14px;
    overflow: hidden;
    border-radius: 3px;
    background: rgba(127, 127, 127, .2);
}

.filepreview-save-progress span {
    display: block;
    width: 0;
    height: 100%;
    background: var(--bs-accent, #21a1b3);
    transition: width .2s;
}

.filepreview-save-buttons {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

/* ---- すべてダウンロード（メッセージの添付が 2 つ以上のとき。1.2.0） ---- */

.filepreview-all-row {
    margin-top: 6px;
}

.filepreview-all,
.filepreview-all:visited {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    max-width: 100%;
    padding: 4px 12px;
    border: 1px solid var(--bs-border-color, #ddd);
    border-radius: 999px;
    background: var(--hh-background-color-main, #fff);
    color: var(--bs-link-color, #21a1b3);
    font-size: 13px;
    line-height: 1.4;
    text-decoration: none;
}

.filepreview-all:hover,
.filepreview-all:focus {
    background: var(--hh-background-color-secondary, #f7f7f7);
    color: var(--bs-link-hover-color, #1a7f8d);
    text-decoration: none;
}
