/* --- 全体レイアウト --- */
body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; line-height: 1.6; color: #333; max-width: 960px; margin: 20px auto; padding: 0 15px; background-color: #f9f9f9; }
h1, h3 { text-align: center; color: #005bab; }

/* --- コンテナとカード --- */
.form-container, .results-container { background-color: #fff; padding: 25px; border-radius: 8px; box-shadow: 0 2px 8px rgba(0,0,0,0.1); margin-bottom: 30px; }
.form-section { margin-bottom: 25px; }
.form-section > .section-title { font-weight: bold; font-size: 1.1em; display: block; margin-bottom: 15px; border-bottom: 2px solid #005bab; padding-bottom: 5px; }

/* --- フォームグリッド --- */
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 15px 20px; }
.form-group label { font-weight: bold; display: block; margin-bottom: 5px; font-size: 0.9em; }
input[type="text"], input[type="date"], input[type="number"], select { width: 100%; padding: 10px; box-sizing: border-box; border: 1px solid #ccc; border-radius: 4px; }

/* --- ラジオ/チェックボックスのレイアウト --- */
.radio-group label, .checkbox-grid label { font-weight: normal; cursor: pointer; display: inline-flex; align-items: center; gap: 5px;}
.checkbox-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 10px; }
.checkbox-grid.purpose { grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); }

/* --- 郵便番号検索ボタン --- */
.postal-group { display: flex; gap: 10px; align-items: center; }
#postal-search-btn { padding: 10px; flex-shrink: 0; }

/* --- 検索ボタン --- */
#search-btn { width: 100%; padding: 15px; font-size: 1.2em; font-weight: bold; background-color: #ff5722; color: white; border: none; cursor: pointer; border-radius: 5px; margin-top: 20px; transition: background-color 0.2s; }
#search-btn:disabled { background-color: #9e9e9e; cursor: not-allowed; }
#clear-btn { background-color: #6c757d; color: white; margin-top: 10px; padding: 15px; width: 100%; font-size: 1.2em; font-weight: bold; border: none; cursor: pointer; border-radius: 5px; transition: background-color 0.2s;}
#clear-btn:hover { background-color: #5a6268; }

/* --- AI思考プロセスログ --- */
#ai-process-log { background-color: #2d3748; color: #a0aec0; padding: 15px; border-radius: 5px; min-height: 80px; font-family: monospace; white-space: pre-wrap; word-break: break-all; margin-top:10px; }

/* --- ローディングスピナーのスタイル --- */
.loader {
    border: 5px solid #f3f3f3;
    border-top: 5px solid #3498db;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    animation: spin 1s linear infinite;
    margin: 20px auto;
    display: none;
}
@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* --- 結果表示カードのスタイル --- */
.result-card {
    border: 1px solid #ddd;
    border-radius: 8px;
    margin-bottom: 20px;
    overflow: hidden;
}

.result-card table {
    width: 100%;
    border-collapse: collapse;
}

.result-card th, .result-card td {
    padding: 10px;
    border: 1px solid #ddd;
    text-align: left;
    vertical-align: top;
    font-size: 0.9em;
}

.result-card th {
    background-color: #f2f2f2;
    font-weight: bold;
    width: 120px;
}
.result-card thead th {
    width: auto;
}
.result-card thead th:first-child {
    width: 35%; 
}

/* 一番上のヘッダー行 */
.result-card .card-header { background-color: #e9f5ff; font-size: 1.2em; }
.result-card .card-header .no { font-weight: bold; color: #005bab; }
.result-card .card-header .apply-button-area { text-align: right; }
.result-card .card-header .apply-button { background-color: #007bff; color: white; padding: 8px 15px; border-radius: 5px; text-decoration: none; font-size: 0.9em; transition: background-color 0.2s; }
.result-card .card-header .apply-button:hover { background-color: #0056b3; }

/* ファイルリンクのスタイル */
.file-link { display: block; margin-bottom: 5px; color: #005bab; text-decoration: underline; }
.file-link:not(:last-child) { margin-right: 10px; }

/* --- アコーディオン（開閉式メニュー）のスタイル --- */
.accordion-toggle-row th, .accordion-toggle-row td { cursor: pointer; background-color: #f9f9f9; }
.accordion-toggle-row:hover th, .accordion-toggle-row:hover td { background-color: #f0f0f0; }
.accordion-content-row { display: none; }
.accordion-content-row.active { display: table-row; }

/* ページネーション */
.pagination { text-align: center; margin-top: 20px; border-top: 1px solid #eee; padding-top: 15px; }
.pagination button { background-color: #005bab; color: white; padding: 8px 15px; border: none; border-radius: 5px; cursor: pointer; margin: 0 5px; transition: background-color 0.2s; }
.pagination button:hover:not(:disabled) { background-color: #003f8a; }
.pagination button:disabled { background-color: #ccc; cursor: not-allowed; }
.pagination span { font-weight: bold; margin: 0 10px; }

/* ★★★ スマホ対応のためのメディアクエリ (最終修正版) ★★★ */
@media (max-width: 768px) {
    body { 
        padding: 0 5px; 
        -webkit-text-size-adjust: 100%;
    }
    
    /* ★★★ フォームの項目を1列表示に ★★★ */
    .form-grid { 
        grid-template-columns: 1fr; 
        gap: 15px; 
    }
    .checkbox-grid, .checkbox-grid.purpose { 
        grid-template-columns: 1fr; 
    }
    
    /* テーブルを囲むコンテナで横スクロールを許可 */
    .table-wrapper {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* テーブルのレイアウトが崩れないように最小幅を設定 */
    .result-card table {
        min-width: 800px;
    }

    /* テーブルの文字サイズやパディングを微調整 */
    .result-card th, .result-card td {
        font-size: 0.8em;
        padding: 8px;
        white-space: nowrap;
    }
    
    /* 補助金名などは改行を許可 */
    .result-card td[data-label="補助金名"],
    .result-card th[data-label="補助金名"],
    .result-card td[data-label="キャッチコピー"],
    .result-card td[data-label="概要"],
    .result-card td[data-label="必要書類リスト"] {
        white-space: normal;
    }

    .result-card .card-header {
        font-size: 1em;
    }
}

@media (max-width: 480px) {
    h1 { font-size: 1.8em; }
    .form-container, .results-container { padding: 15px; }
    .form-section > .section-title { font-size: 1em; margin-bottom: 10px; }
    #search-btn, #clear-btn { padding: 12px; font-size: 1em; }
    #ai-process-log { font-size: 0.8em; min-height: 60px; }
}