/* =================================================================
   コンポーネント用CSS - GHG Input Tool
   ================================================================= */

/* =================================================================
   モーダル
   ================================================================= */

.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 10000;
    display: none;
    opacity: 0;
    transition: opacity 0.3s ease;
    background: rgba(0, 0, 0, 0.5);
    align-items: center;
    justify-content: center;
}

.modal.show {
    display: flex !important;
    opacity: 1;
}

.modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 1rem;
}

.modal-dialog {
    /* Bootstrap 5の正しい構造: modal-dialogは透明なコンテナ、装飾はmodal-contentに適用 */
    background: transparent;
    border-radius: 0;
    box-shadow: none;
    max-width: 600px;
    width: 100%;
    max-height: 90vh;
    overflow: hidden;
    transform: scale(0.8);
    transition: transform 0.3s ease;
}

.modal.show .modal-dialog {
    transform: scale(1);
}

.modal-content {
    display: flex;
    flex-direction: column;
    height: 100%;
    background: white;
    border-radius: 8px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
    max-width: 600px;
    width: 90%;
    max-height: 90vh;
    overflow: hidden;
    transform: scale(0.8);
    transition: transform 0.3s ease;
}

.modal.show .modal-content {
    transform: scale(1);
}

.modal-header {
    padding: 1rem 1.5rem;
    border-bottom: 1px solid #e9ecef;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #f8f9fa;
}

.modal-title {
    margin: 0;
    font-size: 1.2rem;
    color: #2c3e50;
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: #666;
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background-color 0.3s ease;
}

.modal-close:hover {
    background: #e9ecef;
    color: #333;
}

.modal-body {
    padding: 1.5rem;
    flex: 1;
    overflow-y: auto;
}

.modal-footer {
    padding: 1rem 1.5rem;
    border-top: 1px solid #e9ecef;
    background: #f8f9fa;
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
}

/* =================================================================
   データテーブル拡張
   ================================================================= */

.table-search {
    margin-bottom: 1rem;
    display: flex;
    justify-content: flex-end;
}

.table-search .form-control {
    max-width: 300px;
}

.data-table th[data-sortable] {
    position: relative;
    user-select: none;
}

.data-table th[data-sortable]:hover {
    background: #e9ecef;
}

.data-table th[data-sortable]::after {
    content: '';
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    width: 0;
    height: 0;
    border-left: 4px solid transparent;
    border-right: 4px solid transparent;
    border-bottom: 4px solid #ccc;
    opacity: 0.3;
}

.data-table th.sort-asc::after {
    border-bottom: 4px solid #3498db;
    opacity: 1;
}

.data-table th.sort-desc::after {
    border-bottom: none;
    border-top: 4px solid #3498db;
    opacity: 1;
}

.table-pagination {
    margin-top: 1rem;
    display: flex;
    justify-content: center;
}

.pagination {
    display: flex;
    gap: 0.25rem;
}

.pagination-btn {
    padding: 0.5rem 0.75rem;
    border: 1px solid #ddd;
    background: white;
    color: #666;
    text-decoration: none;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.3s ease;
}

.pagination-btn:hover {
    background: #f8f9fa;
    border-color: #3498db;
    color: #3498db;
}

.pagination-btn.active {
    background: #3498db;
    border-color: #3498db;
    color: white;
}

.pagination-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* =================================================================
   ローディングオーバーレイ
   ================================================================= */

.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.9);
    z-index: 9999;
    display: flex;
    justify-content: center;
    align-items: center;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.loading-overlay.show {
    opacity: 1;
}

.loading-content {
    text-align: center;
    padding: 2rem;
    background: white;
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
}

.loading-content .loading-spinner {
    width: 40px;
    height: 40px;
    border: 4px solid #f3f3f3;
    border-top: 4px solid #3498db;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 1rem;
}

.loading-message {
    margin: 0;
    color: #666;
    font-size: 0.9rem;
}

/* =================================================================
   フォーム拡張コンポーネント
   ================================================================= */

.form-group {
    margin-bottom: 1rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    color: #2c3e50;
}

.form-group .form-control {
    width: 100%;
}

.form-group.required label::after {
    content: ' *';
    color: #e74c3c;
}

.form-group .help-text {
    font-size: 0.85rem;
    color: #666;
    margin-top: 0.25rem;
}

.form-group .error-text {
    font-size: 0.85rem;
    color: #e74c3c;
    margin-top: 0.25rem;
}

.form-group.has-error .form-control {
    border-color: #e74c3c;
    box-shadow: 0 0 0 2px rgba(231, 76, 60, 0.2);
}

.input-group {
    display: flex;
    align-items: stretch;
}

.input-group .form-control {
    border-radius: 4px 0 0 4px;
    border-right: none;
}

.input-group-append {
    display: flex;
}

.input-group-append .btn {
    border-radius: 0 4px 4px 0;
    border-left: none;
}

/* =================================================================
   アラート
   ================================================================= */

.alert {
    padding: 1rem 1.5rem;
    border-radius: 6px;
    margin-bottom: 1rem;
    border: 1px solid transparent;
}

.alert-info {
    background: #e3f2fd;
    border-color: #bbdefb;
    color: #1565c0;
}

.alert-success {
    background: #e8f5e8;
    border-color: #c8e6c8;
    color: #2e7d32;
}

.alert-warning {
    background: #fff3cd;
    border-color: #ffeaa7;
    color: #d1742f;
}

.alert-error,
.alert-danger {
    background: #ffebee;
    border-color: #ffcdd2;
    color: #c62828;
}

.alert-dismissible {
    position: relative;
    padding-right: 3rem;
}

.alert-close {
    position: absolute;
    top: 0.5rem;
    right: 1rem;
    background: none;
    border: none;
    font-size: 1.2rem;
    cursor: pointer;
    opacity: 0.7;
}

.alert-close:hover {
    opacity: 1;
}

/* =================================================================
   バッジ・ラベル
   ================================================================= */

.badge {
    display: inline-block;
    padding: 0.3rem 0.6rem;
    font-size: 0.75rem;
    font-weight: 500;
    border-radius: 12px;
    text-align: center;
    white-space: nowrap;
    vertical-align: baseline;
}

.badge-primary {
    background: #3498db;
    color: white;
}

.badge-secondary {
    background: #95a5a6;
    color: white;
}

.badge-success {
    background: #27ae60;
    color: white;
}

.badge-danger {
    background: #e74c3c;
    color: white;
}

.badge-warning {
    background: #f39c12;
    color: white;
}

.badge-info {
    background: #3498db;
    color: white;
}

.badge-light {
    background: #ecf0f1;
    color: #2c3e50;
}

.badge-dark {
    background: #2c3e50;
    color: white;
}

/* =================================================================
   ファイル一覧画面 - 検索条件
   ================================================================= */

.search-conditions-section {
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    margin-bottom: 1.5rem;
    padding: 1.5rem;
}

.search-conditions-section h3 {
    margin-bottom: 1rem;
    color: #2c3e50;
    font-size: 1.2rem;
    font-weight: 600;
}

.search-form {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.checkbox-group {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
}

.checkbox-group label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: normal;
    cursor: pointer;
}

.checkbox-group input[type="checkbox"] {
    margin: 0;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

.form-row-3cols {
    grid-template-columns: 1fr 1fr 1fr;
}

.form-row-4cols {
    grid-template-columns: 1fr 1fr 1fr 1fr;
}

.form-row-5cols {
    grid-template-columns: 1fr 1fr 1fr 1fr 1fr;
}

.search-buttons {
    display: flex;
    gap: 0.5rem;
    justify-content: flex-end;
    margin-top: 1rem;
}

.search-results-section {
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    padding: 1.5rem;
}

.results-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.results-header h3 {
    margin: 0;
    color: #2c3e50;
    font-size: 1.2rem;
    font-weight: 600;
}

.pagination-container {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 1rem;
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid #e9ecef;
}

/* =================================================================
   入力・確認画面
   ================================================================= */

.file-info-section {
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
}

.file-info-details {
    margin-top: 1rem;
}

.file-info-row {
    display: flex;
    align-items: center;
    gap: 0.8rem 2rem;
    margin-bottom: 0.5rem;
    flex-wrap: wrap;
}

.file-info-row span {
    font-size: 0.95rem;
    color: #666;
}

.status-badge,
.file-info-row .status-badge {
    padding: 0.25rem 0.75rem;
    border-radius: 12px;
    font-size: 0.8rem;
    font-weight: 500;
    background: #3498db;
    color: white;
    text-align: center;
    display: inline-block;
}

.status-badge.status-pending,
.file-info-row .status-badge.status-pending { 
    background: #ffeaa7; 
    color: #2d3436; 
}

.status-badge.status-in_progress,
.file-info-row .status-badge.status-in_progress { 
    background: #74b9ff; 
    color: white; 
}

.status-badge.status-inputted,
.file-info-row .status-badge.status-inputted { 
    background: #fd79a8; 
    color: white; 
}

.status-badge.status-rejected,
.file-info-row .status-badge.status-rejected { 
    background: #e17055; 
    color: white; 
}

.status-badge.status-approved,
.file-info-row .status-badge.status-approved {
    background: #00b894;
    color: white;
}

.status-badge.status-inquiry,
.file-info-row .status-badge.status-inquiry { 
    background: #3c87dc; 
    color: white;
}

.status-badge.status-ecofield_completed,
.file-info-row .status-badge.status-ecofield_completed { 
    background: #27ae60; 
    color: white;
}

.status-badge.status-excluded,
.file-info-row .status-badge.status-excluded { 
    background: #b3bec3; 
    color: white;
}

.status-badge.status-deleted,
.file-info-row .status-badge.status-deleted {
    background: #636e72;
    color: white;
}

.status-badge.status-deleted\(replace\),
.file-info-row .status-badge.status-deleted\(replace\) {
    background: #2d3436;
    color: white;
}

.status-badge.status-active,
.file-info-row .status-badge.status-active { 
    background: #00b894; 
    color: white; 
}

.status-badge.status-inactive,
.file-info-row .status-badge.status-inactive { 
    background: #636e72; 
    color: white; 
}
.status-success { color: #00b894; }
.status-error { color: #e17055; }
.btn-sm { padding: 0.4rem 0.8rem; font-size: 0.8rem; }
.btn-sm-warn { padding: 0.4rem 0.8rem; font-size: 0.8rem; background-color:#fff3cd;color:#e17055;}

.input-confirm-container {
    display: flex;
    flex-direction: column;  /* 追加: 常に縦並び */
    gap: 1.5rem;
    /* min-height: 600px; */
}

.image-section {
    width: 1060px;
    min-width: 1060px;
    max-width: 1060px;
    flex-shrink: 0;
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    padding: 1rem;
    display: flex;
    flex-direction: column;
    margin: 0 auto;
}

/* タブレット以下でのレスポンシブ対応 */
/* @media (max-width: 1200px) {
    .input-confirm-container {
        flex-direction: column;
        overflow-x: auto;
    }
    
    .image-section {
        width: 700px;
        min-width: 700px;
        max-width: 700px;
        flex-shrink: 0;
    }
} */

.image-viewer {
    /* flex: 1; */
    position: relative;
    background: #f8f9fa;
    border: 1px solid #e9ecef;
    border-radius: 4px;
    margin-bottom: 1rem;
    /* ↓マークアップエリアの高さ（大きくするともっと証憑ファイルが拡大される） */
    min-height: 600px;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    width: 100%;  /* 追加: 横幅いっぱいに */
    overflow: auto;  /* 追加: 画像が大きい場合のスクロール対応 */
}

.image-viewer img {
    max-width: 1000px !important;
    /* max-height: 800px !important; */
    width: auto;
    height: auto;
    object-fit: contain;
}

.markup-canvas {
    position: absolute;
    top: 0;
    left: 0;
    pointer-events: none;
}

.markup-tools {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
    justify-content: center;
}

.tool-btn {
    width: 40px;
    height: 40px;
    border: 1px solid #ddd;
    background: white;
    border-radius: 4px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    transition: all 0.3s ease;
}

.tool-btn:hover {
    background: #f8f9fa;
    border-color: #3498db;
}

.tool-btn.active {
    background: #3498db;
    color: white;
    border-color: #3498db;
}

.image-controls {
    display: flex;
    gap: 0.5rem;
    justify-content: center;
}

.data-section {
    flex: 1;
    min-width: 0;
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    padding: 1rem;
    display: flex;
    flex-direction: column;
}

.data-table-controls {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.data-table-container {
    flex: 1;
    overflow: auto;
    max-height: 300px; /* 入力項目のスクロール欄の高さ */
    border: 1px solid #e9ecef;
    border-radius: 4px;
    margin-bottom: 1rem;
}

.data-input-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

.data-input-table th {
    background: #f8f9fa;
    padding: 0.75rem 0.5rem;
    text-align: left;
    font-weight: 600;
    color: #2c3e50;
    border-bottom: none;
    box-shadow: inset 0 -2px 0 #e9ecef;
    white-space: nowrap;
}

.data-input-table td {
    padding: 0.5rem;
    border-bottom: 1px solid #f1f3f4;
    vertical-align: top;
}

.data-input-table .form-control-sm {
    padding: 0.4rem;
    font-size: 0.85rem;
    border: 1px solid #ddd;
    border-radius: 3px;
    width: 100%;
}

.data-input-table .row-checkbox,
.data-input-table #select-all-rows {
    width: auto;
    margin: 0;
    cursor: pointer;
}

.data-input-table tr.selected {
    background-color: #e3f2fd;
}

.data-input-table tr.selected td {
    background-color: #e3f2fd;
}

.handover-section {
    margin-bottom: 1rem;
}

.handover-section label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    color: #2c3e50;
}

/* .approval-actions {
    display: flex;
    gap: 0.5rem;
    justify-content: flex-end;
    flex-wrap: wrap;
} */

.approval-actions .btn {
    min-width: 100px;
}

/* 入力内容を保存ボタン用の行 */
.save-only-row {
    display: flex;
    justify-content: flex-end;
    margin-bottom: 24px;
}

#save-only-btn.btn {
    padding-top: 0.5rem;
    padding-bottom: 0.5rem;
}

/* ステータス変更ボタン用の行 */
.status-buttons-row {
    display: flex;
    gap: 0.5rem;
    justify-content: flex-end;
    flex-wrap: wrap;
}

/* =================================================================
   マスタ管理画面
   ================================================================= */

.master-selection-section {
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
}

.master-management-section {
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    padding: 1.5rem;
}

.master-management-section h3 {
    margin-bottom: 1.5rem;
    color: #2c3e50;
    font-size: 1.2rem;
    font-weight: 600;
}

.master-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.master-column {
    border: 1px solid #e9ecef;
    border-radius: 4px;
    overflow: hidden;
}

.master-column h4 {
    background: #f8f9fa;
    margin: 0;
    padding: 0.75rem 1rem;
    font-size: 0.95rem;
    font-weight: 600;
    color: #2c3e50;
    border-bottom: 1px solid #e9ecef;
}

.master-list {
    padding: 0.75rem;
    max-height: 200px;
    overflow-y: auto;
}

.master-item {
    padding: 0.5rem 0.75rem;
    margin-bottom: 0.5rem;
    background: #f8f9fa;
    border: 1px solid #e9ecef;
    border-radius: 3px;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.3s ease;
}

.master-item:hover {
    background: #e9ecef;
    border-color: #3498db;
}

.master-item:last-child {
    margin-bottom: 0;
}

.master-actions {
    display: flex;
    justify-content: flex-end;
}

/* =================================================================
   ファイル一覧テーブルの列幅調整
   ================================================================= */

#files-table th:nth-child(1) { width: 40px; }   /* No. */
#files-table th:nth-child(2) { width: 120px; }   /* ステータス */
#files-table td:nth-child(2) { white-space: nowrap; }
#files-table th:nth-child(3) { width: 150px; }  /* ファイル名 */
#files-table th:nth-child(4) { width: 200px; }  /* ファイルパス */
#files-table th:nth-child(5) { width: 100px; }  /* 入力完了対応者 */
#files-table th:nth-child(6) { width: 100px; }  /* 最終更新者 */
#files-table th:nth-child(7) { width: 80px; }  /* 申し送り */
#files-table th:nth-child(8) { width: 80px; }  /* 作成日 */
#files-table th:nth-child(9) { width: 110px; }   /* 操作 */

/* =================================================================
   レスポンシブ
   ================================================================= */

@media (max-width: 1024px) {
    .modal-dialog {
        margin: 0.5rem;
        max-width: none;
    }
    
    .modal-body {
        padding: 1rem;
    }
    
    .modal-footer {
        padding: 1rem;
        flex-direction: column;
    }
    
    .modal-footer .btn {
        width: 100%;
        margin-bottom: 0.5rem;
    }
    
    .table-search .form-control {
        max-width: none;
    }
    
    .pagination {
        flex-wrap: wrap;
    }
    
    .pagination-btn {
        min-width: 40px;
    }
    
    .form-row,
    .form-row-3cols,
    .form-row-4cols,
    .form-row-5cols {
        grid-template-columns: 1fr;
        gap: 0.5rem;
    }
    
    .checkbox-group {
        flex-direction: column;
        gap: 0.5rem;
    }
    
    .file-info-row {
        flex-direction: column;
        gap: 0.5rem;
    }
    
    .file-info-row .status-badge {
        /* ステータスバッジは自然な幅を維持 */
        align-self: flex-start;
        width: auto;
    }
    
    /* .input-confirm-container {
        grid-template-columns: 1fr;
        gap: 1rem;
    } */
    
    .data-table-controls {
        /* 行追加・行削除ボタンは横並びを維持 */
        flex-direction: row;
        gap: 0.5rem;
    }
    
    .data-table-controls .btn:not(.full-width) {
        /* 入力完了ボタン以外は横幅固定 */
        flex: none;
        width: auto;
    }
    
    .approval-actions {
        flex-direction: column;
    }
    
    .master-grid {
        grid-template-columns: 1fr;
    }
    
    .search-buttons {
        justify-content: stretch;
    }
    
    .search-buttons .btn {
        flex: 1;
    }
    
    .results-header {
        flex-direction: column;
        gap: 1rem;
        align-items: stretch;
    }
    
    .pagination-container {
        flex-direction: column;
        gap: 0.5rem;
    }
    
    /* モバイルでのテーブル調整 */
    #files-table {
        font-size: 0.75rem;
    }
    
    #files-table th,
    #files-table td {
        padding: 0.3rem 0.2rem;
    }
    
    /* モバイルでは一部列を非表示にして見やすくする */
    #files-table th:nth-child(5),  /* 入力完了対応者 */
    #files-table td:nth-child(5),
    #files-table th:nth-child(6),  /* 最終更新者 */
    #files-table td:nth-child(6),
    #files-table th:nth-child(7),  /* 申し送り */
    #files-table td:nth-child(7),
    #files-table th:nth-child(8),  /* 作成日 */
    #files-table td:nth-child(8) {
        display: none;
    }
}

