/* CSS Custom Properties - Cell Sizing Variables */
:root {
    /* Desktop cell dimensions */
    --cell-padding-desktop: 3px 4px;
    --cell-min-width-desktop: 60px;
    
    /* Mobile cell dimensions (約83%のスケール) */
    --cell-padding-mobile: 2px 3px;
    --cell-min-width-mobile: 50px;
}

/* 基本リセット */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* body要素の統一スタイル */
body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    line-height: 1.6;
    color: #2c3e50;
    background: linear-gradient(135deg, #e8f5e9, #c8e6c9);
    min-height: 100vh;
}

/* ヘッダー */
header {
    background: linear-gradient(to right, #43a047, #66bb6a);
    color: white;
    text-align: center;
    padding: 2rem 0;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}

header h1 {
    font-size: 2.5rem;
    margin-bottom: 0.5rem;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.1);
}

/* ナビゲーション */
nav {
    background: linear-gradient(to right, #66bb6a, #81c784);
    padding: 1rem 0;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}

nav ul {
    list-style: none;
    display: flex;
    justify-content: flex-start;
    gap: 1rem;
    max-width: 1600px;
    margin: 0 auto;
    padding: 0 2rem;
}

nav ul li a {
    color: white;
    text-decoration: none;
    font-weight: bold;
    transition: all 0.3s ease;
    padding: 0.5rem 1rem;
    border-radius: 20px;
}

nav ul li a:hover {
    background-color: rgba(255,255,255,0.2);
    transform: translateY(-2px);
}

/* メッセージコンテナ */
#message-container {
    max-width: 1600px;
    margin: 0 auto;
    padding: 0 2rem;
}

/* メインコンテンツ */
main {
    max-width: 1600px;
    margin: 0 auto;
    padding: 2rem;
}

/* tool-card */
.tool-card {
    background: linear-gradient(135deg, #ffffff, #e8f5e9);
    border-radius: 12px;
    box-shadow: 0 8px 16px rgba(0,0,0,0.1);
    padding: 2rem;
    margin-bottom: 2rem;
    transition: all 0.3s ease;
}

.tool-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 12px 24px rgba(0,0,0,0.15);
}

.tool-card h2 {
    font-size: 1.8rem;
    margin-bottom: 1rem;
    color: #2e7d32;
    border-bottom: 2px solid #4caf50;
    padding-bottom: 0.5rem;
}

.tool-card h3 {
    font-size: 1.4rem;
    margin-top: 1.5rem;
    margin-bottom: 0.5rem;
    color: #388e3c;
}

/* ボタン */
button {
    background: linear-gradient(to right, #4caf50, #45a049);
    color: white;
    padding: 0.7rem 1.5rem;
    border: none;
    border-radius: 25px;
    font-weight: bold;
    text-transform: uppercase;
    letter-spacing: 1px;
    cursor: pointer;
    transition: all 0.3s ease;
    margin-bottom: 1rem;
}

button:hover {
    background: linear-gradient(to right, #45a049, #4caf50);
    box-shadow: 0 4px 8px rgba(0,0,0,0.2);
    transform: translateY(-2px);
}

/* フォーム要素 */
textarea {
    width: 100%;
    height: 50px;
    padding: 0.5rem;
    border: 1px solid #81c784;
    border-radius: 4px;
    resize: vertical;
    margin-bottom: 1rem;
}

/* フッター */
footer {
    background: linear-gradient(to right, #43a047, #66bb6a);
    color: white;
    text-align: center;
    padding: 1rem 0;
    box-shadow: 0 -2px 10px rgba(0,0,0,0.1);
}

@media (max-width: 768px) {
    main {
        padding: 0 1rem;
    }
    .tool-card {
        padding: 1.5rem;
    }
    .radio-group {
        flex-direction: column;
    }
}

/* 表設定セクション */
.table-config {
    margin-bottom: 1.5rem;
}

.config-row {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1rem;
    border: none;
    padding: 0;
}

.config-row legend {
    font-weight: bold;
    color: #2e7d32;
    padding: 0;
    margin-bottom: 0.5rem;
}

.config-row label {
    font-weight: bold;
    color: #2e7d32;
}

.config-row input[type="number"] {
    width: 80px;
    padding: 0.5rem;
    border: 1px solid #81c784;
    border-radius: 4px;
    font-size: 0.9rem;
}

/* グリッドコンテナ */
.grid-container {
    overflow-x: auto;
    overflow-y: auto;
    margin: 1rem 0;
    border: 2px solid #4caf50;
    border-radius: 8px;
    background: white;
}

/* データグリッド */
.data-grid {
    width: 100%;
    border-collapse: collapse;
    min-width: 40px;
}

.data-grid th,
.data-grid td {
    border: 1px solid #c8e6c9;
    padding: 0; /* セル高さをtextareaに合わせる（th側で後から上書き） */
    min-width: var(--cell-min-width-desktop);
    position: relative;
    line-height: 1.2;
}

.data-grid th {
    background: linear-gradient(to bottom, #66bb6a, #4caf50);
    color: white;
    font-weight: bold;
    text-align: center;
    font-size: 0.85rem;
    padding: var(--cell-padding-desktop); /* ヘッダーの余白は維持 */
}

.data-grid td {
    background: white;
    vertical-align: top;
}

.data-grid textarea {
    width: 100%;
    border: none;
    background: transparent;
    padding: 2px; /* 既定値に戻す（入力エリアサイズはそのまま） */
    font-size: 0.85rem;
    line-height: 1.2;
    min-height: 30px;
    resize: vertical;
    outline: none;
    font-family: inherit;
    overflow-y: auto;
}

.data-grid textarea:focus {
    background: #f1f8e9;
    border: 1px solid #4caf50;
    border-radius: 2px;
}

/* 行・列のヘッダー */
.data-grid .row-header {
    background: linear-gradient(to right, #81c784, #66bb6a);
    color: white;
    text-align: center;
    font-weight: bold;
    width: 40px;
    min-width: 40px;
    padding: 3px 2px;
    line-height: 1.2;
    font-size: 0.85rem;
}

.data-grid .col-header {
    background: linear-gradient(to bottom, #81c784, #66bb6a);
    color: white;
    text-align: center;
    font-weight: bold;
    padding: 3px 2px;
    line-height: 1.2;
    font-size: 0.85rem;
}

.data-grid .corner-cell {
    background: linear-gradient(135deg, #66bb6a, #4caf50);
}

/* インポートセクション */
.import-section {
    margin: 1rem 0;
}

.import-section h3 {
    color: #2e7d32;
    margin-bottom: 0.5rem;
}

#import-data {
    height: 150px;
    font-family: 'Courier New', monospace;
    font-size: 0.9rem;
}

/* 出力セクション */
.export-section {
    margin: 1rem 0;
}

.export-section h3 {
    color: #2e7d32;
    margin-bottom: 0.5rem;
    margin-top: 1.5rem;
}

.export-section h3:first-child {
    margin-top: 0;
}

#markdown-output,
#csv-output {
    height: 150px;
    font-family: 'Courier New', monospace;
    font-size: 0.9rem;
    background: #f8f9fa;
    border: 1px solid #c8e6c9;
}

/* ボタングループ */
.button-group {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-top: 1rem;
}

.button-group button {
    margin-bottom: 0.5rem;
    margin-right: 0;
}

/* Radio group styling */
.radio-group {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
}

.radio-group label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* レスポンシブデザイン */
@media (max-width: 768px) {
    .config-row {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
    }
    
    .config-row input[type="number"] {
        width: 100px;
    }
    
    .data-grid th {
        min-width: var(--cell-min-width-mobile);
        padding: var(--cell-padding-mobile);
    }
    .data-grid td {
        min-width: var(--cell-min-width-mobile);
        padding: 0; /* モバイルでもセル高さをtextareaに合わせる */
    }
    
    .button-group {
        flex-direction: column;
    }
    
    .button-group button {
        width: 100%;
        margin-right: 0;
    }
    
    .radio-group {
        flex-direction: column;
        gap: 0.5rem;
    }
}

/* セル選択状態 */
.data-grid td.selected {
    background: #e8f5e9;
    border: 2px solid #4caf50;
}

/* エラー表示 */
.error-message {
    background: #ffebee;
    color: #c62828;
    padding: 0.5rem;
    border-radius: 4px;
    margin: 0.5rem 0;
    border-left: 4px solid #f44336;
    font-size: 0.9rem;
}

/* 成功メッセージ */
.success-message {
    background: #e8f5e9;
    color: #2e7d32;
    padding: 0.5rem;
    border-radius: 4px;
    margin: 0.5rem 0;
    border-left: 4px solid #4caf50;
    font-size: 0.9rem;
}

/* タブUI */
.tabs {
    margin-top: 0.5rem;
}
.tabs input[type="radio"] {
    display: none;
}
.tab-label {
    display: inline-block;
    padding: 0.6rem 1rem;
    margin-right: 0.25rem;
    border-radius: 8px 8px 0 0;
    background: #e8f5e9;
    color: #2e7d32;
    cursor: pointer;
    font-weight: bold;
    border: 1px solid #c8e6c9;
    border-bottom: none;
}
#tab-output:checked + label,
#tab-import:checked + label {
    background: #ffffff;
    color: #2e7d32;
    box-shadow: 0 -2px 6px rgba(0,0,0,0.06);
}
.tabs-content {
    border: 1px solid #c8e6c9;
    border-radius: 0 8px 8px 8px;
    background: #ffffff;
    padding: 1rem;
}
.tab-panel {
    display: none;
}
#tab-output:checked ~ .tabs-content #panel-output {
    display: block;
}
#tab-import:checked ~ .tabs-content #panel-import {
    display: block;
}