* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html,
body {
    font-family: Arial, sans-serif;
    margin: 0;
    padding: 0;
    height: 100%;
    font-size: 0.85rem;
}

body {
    font-family: Arial, sans-serif;
    line-height: 1.6;
    color: #333;
    background-color: #f4f4f4;
    overflow: hidden;
    /* リサイズ時のスクロールバーを防ぐ */
}

h2 {
    font-size: 1rem;
    margin: 0.25rem 0;
    color: #333;
    margin-bottom: 15px;
    border-bottom: 1px solid #eee;
    padding-bottom: 2px;
    display: flex;
    align-items: center;
}

h2 .help-btn {
    margin-left: 10px;
    margin-right: auto;
}

/* コンテナの初期グリッド設定 - 左右 2:1、上下 1:4 の比率に変更 */
.container {
    display: grid;
    grid-template-columns: 66.67% 33.33%;
    /* 左右 2:1 の比率 */
    grid-template-rows: 20% 80%;
    /* 上下 1:4 の比率 */
    height: 100vh;
    position: relative;
    overflow: hidden;
}

.panel {
    background-color: #fff;
    border: 1px solid #ccc;
    padding: 5px;
    overflow: auto;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    position: relative;
}

.left-top {
    grid-column: 1;
    grid-row: 1;
}

.left-bottom {
    grid-column: 1;
    grid-row: 2;
    display: flex;
    flex-direction: column;
}

.right-top {
    grid-column: 2;
    grid-row: 1;
}

/* 右下パネル内の要素配置を調整 */
.right-bottom {
    grid-column: 2;
    grid-row: 2;
    display: flex;
    flex-direction: column;
}

/* リサイズハンドル */
.resize-handle {
    position: absolute;
    background-color: #ccc;
    z-index: 10;
    touch-action: none;
}

.resize-handle.horizontal {
    height: 6px;
    width: 100%;
    cursor: ns-resize;
    left: 0;
    z-index: 100;
}

.resize-handle.vertical {
    width: 6px;
    height: 100%;
    cursor: ew-resize;
    top: 0;
    z-index: 100;
}

.resize-handle.corner {
    width: 12px;
    height: 12px;
    background-color: #999;
    cursor: nwse-resize;
    border-radius: 50%;
    z-index: 102;
}

.resize-handle:hover {
    background-color: #999;
}

/* タブ関連のスタイル */
.tabs-container {
    margin-top: 5px;
    margin-bottom: 10px;
}

.tabs-header {
    display: flex;
    border-bottom: 1px solid #ccc;
    position: relative;
    overflow-x: auto;
    white-space: nowrap;
    margin-bottom: 10px;
}

.tab {
    padding: 0 10px;
    line-height: 30px;
    background-color: #f0f0f0;
    border: 1px solid #ccc;
    border-bottom: none;
    border-radius: 5px 5px 0 0;
    margin-right: 2px;
    cursor: pointer;
    position: relative;
    width: 120px;
    /* 固定幅 */
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    text-align: center;
    /* テキストを中央揃え */
}

.tab.active {
    background-color: #fff;
    border-bottom: 1px solid #fff;
    z-index: 1;
    margin-bottom: -1px;
}

.tab:hover {
    background-color: #e9e9e9;
}

.tab.active:hover {
    background-color: #fff;
}

.add-tab-btn {
    padding: 0 10px;
    line-height: 30px;
    background-color: #f0f0f0;
    border: 1px solid #ccc;
    border-bottom: none;
    border-radius: 5px 5px 0 0;
    cursor: pointer;
    font-weight: bold;
}

.tab-content {
    display: none;
    height: auto;
    /* タブヘッダーとパスナビゲーターの高さを差し引く */
    overflow: auto;
}

.tab-content.active {
    display: block;
}

.tab .close-tab {
    display: inline-block;
    margin-left: 8px;
    font-size: 14px;
    opacity: 0.6;
}

.tab .close-tab:hover {
    opacity: 1;
    color: #f44336;
}

/* Form controls */
.form-group {
    margin-bottom: 5px;
}

.form-group label {
    display: block;
    margin-bottom: 5px;
    font-weight: bold;
}

.form-group input {
    width: 100%;
    padding: 5px;
    border: 1px solid #ddd;
    border-radius: 4px;
}

/* アップロード先フォームのスタイル修正 */
.upload-controls {
    margin-top: 10px;
}

.upload-path-container {
    display: flex;
    gap: 5px;
    margin-bottom: 5px;
}

.upload-path-container input {
    flex-grow: 1;
    width: 100%;
}

.upload-buttons {
    display: flex;
    gap: 5px;
}

.upload-buttons button {
    flex-grow: 1;
}

/* Buttons */
.btn {
    background-color: #f0f0f0;
    border: 1px solid #ccc;
    border-radius: 4px;
    color: #333;
    cursor: pointer;
    padding: 0.15rem !important;
    text-align: center;
    transition: background-color 0.2s;
    font-size: 0.85rem !important;
    margin-right: 5px;
}

.btn:hover {
    background-color: #e0e0e0;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn.primary {
    background-color: #4CAF50;
    color: white;
    border-color: #45a049;
}

.btn.primary:hover {
    background-color: #45a049;
}

.btn.danger {
    background-color: #f44336;
    color: white;
    border-color: #d32f2f;
}

.btn.danger:hover {
    background-color: #d32f2f;
}

.btn.small {
    font-size: 0.75rem !important;
    padding: 0.1rem !important;
}

.buttons {
    display: flex;
    gap: 10px;
    margin-top: 15px;
}

/* Directory tree */
.path-navigator {
    display: flex;
    align-items: center;
    margin-top: 5px;
    margin-bottom: 5px;
    padding: 3px;
    background-color: #f5f5f5;
    border-radius: 4px;
}

#currentPath {
    flex-grow: 1;
    font-family: monospace;
    margin-right: 10px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    padding: 4px;
    overflow-x: auto;
    background-color: #fff;
    border: 1px solid #ddd;
    border-radius: 4px;
}

.directory-tree {
    background-color: #fff;
    border: 1px solid #ddd;
    border-radius: 4px;
    padding: 10px;
    margin-top: 10px;
    height: 250px;
    min-height: unset;
    overflow: auto;
}

.directory-tree ul {
    list-style-type: none;
    padding-left: 15px;
    margin: 0;
}

.directory-tree li {
    cursor: pointer;
    padding: 5px;
    border-radius: 2px;
    margin: 2px 0;
}

.directory-tree li:hover {
    background-color: #f0f0f0;
}

.directory-tree .directory {
    color: #0066cc;
    font-weight: bold;
}

.directory-tree .directory:before {
    content: "📂 ";
    color: #FFD700 !important;
    /* 重要: スマホでも黄色にする */
}

.directory-tree .file {
    color: #333;
}

.directory-tree .file:before {
    content: "📄 ";
}

directory-tree .selected {
    background-color: #e0e7ff;
}

/* File info and actions */
.file-info {
    background-color: #fff;
    border: 1px solid #ddd;
    border-radius: 4px;
    padding: 5px;
    margin: 4px 0;
    min-height: 50px;
    max-height: 25vh;
    overflow: auto;
}

/* File preview */
.file-preview {
    height: auto;
    /* 固定サイズから可変サイズに変更 */
    min-height: 100px;
    /* 最小高さは確保 */
    flex-grow: 1;
    /* 利用可能なスペースを取得 */
    border: 1px solid #ddd;
    border-radius: 4px;
    padding: 10px;
    overflow: auto;
    background-color: #f9f9f9;
    display: flex;
    flex-direction: column;
    height: calc(100% - 50px);
}

.file-preview img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    margin: 0 auto;
}

.text-content {
    white-space: pre-wrap;
    word-break: break-all;
    font-family: monospace;
    padding: 10px;
    background-color: #fff;
    border: 1px solid #eee;
    border-radius: 4px;
    flex-grow: 1;
    overflow: auto;
    font-size: 14px;
    height: 100%;
}

.binary-content {
    font-family: monospace;
    font-size: 14px;
    padding: 10px;
    background-color: #fff;
    border: 1px solid #eee;
    border-radius: 4px;
    overflow: auto;
}

.hex-view {
    display: grid;
    grid-template-columns: auto 1fr auto;
    gap: 10px;
    font-family: monospace;
    font-size: 0.85rem;
    margin-top: 10px;
    line-height: 1.5;
}

.no-file-selected {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: #999;
    font-style: italic;
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    animation: fadeIn 0.3s;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

.modal-content {
    background-color: #fefefe;
    margin: 15% auto;
    padding: 20px;
    border: 1px solid #888;
    width: 80%;
    max-width: 500px;
    border-radius: 8px;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
}

.modal-content h3 {
    margin-top: 0;
    color: #2c3e50;
}

.file-path {
    background-color: #f5f5f5;
    padding: 8px;
    margin: 15px 0;
    border-radius: 4px;
    word-break: break-all;
    font-family: monospace;
}

.modal-buttons {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 20px;
}

/* Helpボタン */
.help-btn {
    background-color: #2196F3;
    color: white;
    border-radius: 50%;
    width: 1.2rem;
    height: 1.2rem;
    margin-left: 5px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
}

.help-btn:hover {
    background-color: #31b0d5;
}

/* ゴミ箱警告表示 */
.trash-warning {
    display: none;
    background-color: #fff3cd;
    color: #856404;
    padding: 10px;
    border-radius: 4px;
    margin-bottom: 10px;
    border-left: 4px solid #ffeeba;
    align-items: center;
}

.warning-icon {
    font-size: 1.5rem;
    margin-right: 10px;
}

.warning-text {
    flex-grow: 1;
}

/* ゴミ箱フォルダにいる場合の視覚的な表示 */
.tab-content.trash-folder .directory-tree {
    border: 2px solid #ffeeba;
    background-color: #fffdf5;
}

/* ゴミ箱を空にするボタン */
#emptyTrashBtn {
    white-space: nowrap;
    padding: 5px 8px;
    font-size: 12px;
}

/* 長押し時の視覚的フィードバック */
.long-press-active {
    background-color: #d1e8ff !important;
    transform: scale(0.98);
    transition: transform 0.2s;
}

/* ロード表示、成功、エラーメッセージ */
.loading {
    padding: 10px;
    text-align: center;
    color: #555;
}

.success {
    padding: 10px;
    text-align: center;
    color: green;
}

.error {
    padding: 10px;
    text-align: center;
    color: red;
}

/* リサイズ中のオーバーレイ */
.resize-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: transparent;
    z-index: 999;
}

/* モバイル向け調整 */
@media (max-width: 768px) {
    .container {
        grid-template-columns: 1fr;
        grid-template-rows: auto auto auto auto;
        height: auto;
        min-height: 100vh;
    }

    .left-top,
    .right-top,
    .left-bottom,
    .right-bottom {
        grid-column: 1;
    }

    .left-top {
        grid-row: 1;
    }

    .right-top {
        grid-row: 2;
    }

    .left-bottom {
        grid-row: 3;
    }

    .right-bottom {
        grid-row: 4;
    }

    /* モバイルではリサイズハンドルをより大きく */
    .resize-handle {
        width: 24px !important;
        height: 24px !important;
        background-color: rgba(153, 153, 153, 0.7);
        touch-action: none;
    }

    .resize-handle.horizontal {
        height: 24px !important;
    }

    .resize-handle.vertical {
        width: 24px !important;
    }

    .resize-handle.corner {
        width: 30px !important;
        height: 30px !important;
    }

    /* タッチしやすいようにボタン間の間隔を広げる */
    .action-buttons {
        gap: 8px;
    }

    .btn {
        padding: 0.25rem !important;
    }
}

/* メディアクエリを修正 - 明確に小さい画面のみに適用 */
@media (max-width: 600px) {
    .container {
        grid-template-columns: 1fr;
        grid-template-rows: auto auto auto auto;
        height: auto;
        min-height: 100vh;
        overflow: auto;
    }

    .left-top,
    .right-top,
    .left-bottom,
    .right-bottom {
        grid-column: 1;
        width: 100%;
    }

    .left-top {
        grid-row: 1;
        height: auto;
    }

    .right-top {
        grid-row: 2;
        height: auto;
    }

    .left-bottom {
        grid-row: 3;
        height: auto;
    }

    .right-bottom {
        grid-row: 4;
        height: auto;
    }

    /* リサイズハンドルを非表示 */
    .resize-handle {
        display: none;
    }

    /* モバイルでもファイル情報エリアを保持 */
    .file-info {
        max-height: 20vh;
    }

    /* モバイルでのフォーム配置を修正 */
    .form-group {
        margin-bottom: 5px;
    }

    /* タッチ操作向けの調整 */
    .directory-tree li {
        padding: 8px 5px;
    }

    /* アップロード先を横並びにする */
    .upload-path-container {
        display: flex;
        flex-direction: row;
        gap: 5px;
        align-items: center;
    }

    .upload-path-container input {
        flex-grow: 1;
    }

    html,
    body {
        height: auto;
        overflow: auto;
    }

    .container {
        height: auto;
        min-height: 100%;
        overflow: visible;
    }

    .panel {
        overflow: visible;
    }

    /* すべてのパネルを表示 */
    .right-bottom {
        display: block !important;
        min-height: 200px;
    }

    /* パネル間の余白を追加 */
    .left-top,
    .right-top,
    .left-bottom,
    .right-bottom {
        margin-bottom: 10px;
    }

    /* ビューの最小高さを確保 */
    .file-preview {
        min-height: 150px;
        height: 200px;
        min-height: unset;
    }
}

/* PCサイズでのスクロールバー調整 */
@media (min-width: 601px) {
    .panel {
        overflow: auto;
    }
}

/* 操作ボタンのスタイル修正 */
.action-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    margin: 4px 0;
}

/* アップロード関連のスタイル修正 */
.upload-controls {
    margin-top: 10px;
}

.upload-path-container {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    align-items: center;
}

.upload-path-container input {
    flex-grow: 1;
    min-width: 120px;
}

.upload-buttons {
    display: flex;
    gap: 5px;
}

.upload-buttons button {
    flex-grow: 1;
}

/* パスナビゲーターの調整 */
.path-navigator {
    display: flex;
    align-items: center;
    margin-top: 5px;
    margin-bottom: 5px;
    padding: 3px;
    background-color: #f5f5f5;
    border-radius: 4px;
    flex-wrap: wrap;
    gap: 5px;
}

/* ヘルプボタンのスタイル調整 */
.help-btn {
    background-color: #2196F3;
    color: white;
    border-radius: 50%;
    width: 1.5rem;
    height: 1.5rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    margin-left: auto;
}

/* アップロード先とボタンを同じ行に配置 */
.upload-path-wrapper {
    display: flex;
    align-items: center;
    gap: 5px;
    flex-wrap: nowrap;
}

.upload-path-wrapper label {
    white-space: nowrap;
    margin-bottom: 0;
}

.upload-path-wrapper input {
    flex: 1;
    min-width: 0;
}

.upload-path-wrapper button {
    white-space: nowrap;
}

/* スマホモードでの調整 */
@media (max-width: 600px) {

    /* スマホでもプレビューエリアを維持 */
    .right-bottom {
        display: block !important;
        min-height: 200px;
    }

    /* スマホでの操作ボタンレイアウト調整 */
    .action-buttons {
        gap: 8px;
        justify-content: space-around;
    }

    .action-buttons button {
        flex-grow: 1;
        padding: 8px 5px !important;
        min-height: 36px;
        font-size: 0.9rem !important;
    }

    /* アップロード関連のレイアウト調整 */
    .upload-path-container {
        flex-wrap: wrap;
        gap: 8px;
    }

    .upload-path-container button {
        flex-grow: 1;
        padding: 8px 5px !important;
        min-height: 36px;
    }

    /* 必ずプレビューエリアを表示 */
    #rightBottomPanel {
        display: block !important;
        min-height: 180px;
    }

    .file-preview {
        min-height: 100px;
    }

    /* 各パネルの高さを固定にして再描画時の移動を防止 */
    .left-top {
        height: auto;
    }

    .right-top {
        height: auto;
    }

    .left-bottom {
        height: auto;
    }

    .right-bottom {
        height: auto;
    }

    /* ファイル一覧の高さを固定 */
    .directory-tree {
        height: 300px;
    }

    /* プレビューエリアの高さを固定 */
    .file-preview {
        height: 200px;
        min-height: unset;
    }

    /* アップロード先とボタンのレイアウト */
    .upload-path-wrapper {
        flex-wrap: wrap;
    }

    .upload-path-wrapper label {
        width: 100%;
        margin-bottom: 3px;
    }

    .upload-path-wrapper input,
    .upload-path-wrapper button {
        margin-top: 2px;
    }
}