body {
    font-family: 'Roboto', 'Noto Sans JP', sans-serif;
    background-color: #e0e5ec; /* Neumorphism base background */
    color: #333;
    margin: 0;
    padding: 0;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

.wrapper {
    display: flex;
}

.container {
    flex-grow: 1;
    padding: 30px;
    display: flex;
    flex-direction: column;
    gap: 30px;
}

header {
    text-align: center;
    padding-bottom: 20px;
    border-bottom: 1px solid #d1d9e6;
}

h1, h2 {
    color: #0056b3;
    text-shadow: 1px 1px 2px rgba(163,177,198,0.6), -1px -1px 2px rgba(255,255,255, 0.5);
}

/* フォームのスタイル */
#input-form form {
    display: grid;
    grid-template-columns: 1fr 2fr;
    gap: 15px;
    align-items: center;
}

#input-form label {
    font-weight: bold;
}

#input-form button,
.content-card button { /* Apply to all buttons inside cards */
    padding: 12px;
    border: none;
    border-radius: 18px;
    font-size: 1em;
    background-color: #e0e5ec;
    box-shadow: 6px 6px 12px rgba(163,177,198,0.6), -6px -6px 12px rgba(255,255,255, 0.5);
    transition: all 0.3s ease;
    cursor: pointer;
    color: #007bff;
    font-weight: 600;
}

.content-card button:hover {
    box-shadow: inset 4px 4px 8px rgba(163,177,198,0.6), inset -4px -4px 8px rgba(255,255,255, 0.5);
    color: #0056b3;
}

/* 各セクションの区切り */
section, .content-card {
    margin-bottom: 30px;
    background-color: #e0e5ec;
    padding: 40px;
    border-radius: 25px;
    box-shadow: 9px 9px 18px rgba(163,177,198,0.6), -9px -9px 18px rgba(255,255,255, 0.5);
}

/* --- Chart Container --- */
.chart-container {
    position: relative;
    height: 400px;
}

/* --- メイン操作ボタン --- */
.main-actions {
    display: flex;
    flex-direction: column; /* 縦並びに変更 */
    align-items: flex-start; /* ボタンを左揃えにし、幅を内容に合わせる */
    gap: 20px;
    margin-bottom: 30px;
}

.main-action-btn {
    /* flex-grow: 1; */ /* 横幅いっぱいに広がるのをやめる */
    padding: 20px;
    font-size: 1.2em;
    font-weight: bold;
    color: #007bff;
    background-color: #e0e5ec;
    border: none;
    border-radius: 20px;
    cursor: pointer;
    box-shadow: 9px 9px 18px rgba(163,177,198,0.6), -9px -9px 18px rgba(255,255,255, 0.5);
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}

.main-action-btn:hover {
    box-shadow: inset 4px 4px 8px rgba(163,177,198,0.6), inset -4px -4px 8px rgba(255,255,255, 0.5);
    color: #0056b3;
}

/* --- 履歴表示パネル --- */
.history-container {
    display: flex;
    flex-direction: column;
    gap: 40px; /* パネル間のスペースを少し広げる */
}

.history-panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
}

.print-btn {
    padding: 5px 15px;
    font-size: 0.9em;
}

.history-panel h3 {
    margin-top: 0;
}

.history-scroll-area {
    max-height: 600px; /* 10件程度が表示される高さに調整 */
    overflow-y: auto;
    padding-right: 10px; /* スクロールバーのためのスペース */
}

/* 食事記録フォームのスタイル */
#meal-log-form {
    display: flex;
    flex-direction: column;
    gap: 15px;
    margin-bottom: 20px;
}

.form-group-inline {
    display: flex;
    align-items: center;
    gap: 10px;
}

#meal-log-form label {
    font-weight: bold;
}

#meal-log-form input,
#meal-log-form select,
#daily-log-form input, #daily-log-form select,
#meal-log-form textarea,
#meal-log-form input[type="time"],
.dish-entry input[type="text"] { /* 動的に追加される料理・材料の入力欄にも適用 */
    padding: 12px;
    border: none;
    border-radius: 18px;
    font-size: 1em;
    background-color: #e0e5ec;
    box-shadow: inset 4px 4px 8px rgba(163,177,198,0.6), inset -4px -4px 8px rgba(255,255,255, 0.5);
    transition: all 0.3s ease;
}

/* 時刻入力セレクトボックスのスタイル */
.time-select-wrapper {
    display: flex;
    align-items: center;
    gap: 5px;
}
.time-select-wrapper select {
    /* 他のinput, selectと共通のスタイルを継承 */
    border: none;
    min-width: 60px; /* 最小幅を確保 */
}

#meal-log-form input:focus,
#meal-log-form select:focus,
#daily-log-form input:focus, #daily-log-form select:focus,
#meal-log-form textarea:focus {
    outline: none;
    box-shadow: inset 6px 6px 12px rgba(163,177,198,0.6), inset -6px -6px 12px rgba(255,255,255, 0.5);
}

#daily-log-form {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 15px;
    align-items: center;
}
#daily-log-form label {
    font-weight: bold;
}

#meal-log-form button,
#daily-log-form button[type="submit"] {
    padding: 12px;
    border: none;
    border-radius: 18px;
    font-size: 1em;
    background-color: #e0e5ec;
    box-shadow: 6px 6px 12px rgba(163,177,198,0.6), -6px -6px 12px rgba(255,255,255, 0.5);
    transition: all 0.3s ease;
    cursor: pointer;
    color: #007bff;
    font-weight: 600;
}

#meal-log-form button:hover,
#daily-log-form button[type="submit"]:hover {
    box-shadow: inset 4px 4px 8px rgba(163,177,198,0.6), inset -4px -4px 8px rgba(255,255,255, 0.5);
    color: #0056b3;
}

/* --- 動的追加フォームのスタイル --- */
.dish-entry {
    border: 1px solid #d1d9e6;
    border-radius: 15px;
    padding: 15px;
    margin-bottom: 15px;
    background-color: #e0e5ec;
    box-shadow: inset 4px 4px 8px rgba(163,177,198,0.6), inset -4px -4px 8px rgba(255,255,255, 0.5);
    position: relative;
}

.ingredient-entry {
    display: flex;
    gap: 10px;
    align-items: center;
    margin-bottom: 10px;
}

.ingredient-entry input {
    flex-grow: 1;
}

/* 材料入力欄のレイアウト調整 (Safariのはみ出し対策) */
.meal-ingredient-name {
    width: 100px; /* 幅を100pxに設定 */
}

.meal-ingredient-amount {
    /* 利用可能な幅から、材料名の入力欄(100px)と削除ボタン(約30px)とgap(10px)を引いた幅を計算 */
    width: calc(100% - 100px - 30px - 10px);
}

.editable-na {
    cursor: pointer;
    color: #007bff;
    text-decoration: underline;
    font-weight: bold;
}

.editable-na:hover {
    color: #0056b3;
}

.highlight-input {
    border: 2px solid #dc3545 !important; /* 赤い枠線で強調 */
}

.meal-entry td {
    vertical-align: top; /* セルの内容を上揃えにする */
}

.remove-btn {
    background: none;
    border: none;
    color: #dc3545;
    cursor: pointer;
    font-size: 1.2em;
    padding: 0 5px;
}

.remove-dish-btn {
    position: absolute;
    top: 10px;
    right: 10px;
}

.add-item-btn {
    background-color: transparent;
    border: 1px dashed #007bff;
    color: #007bff;
    padding: 8px 12px;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.3s ease;
    margin-top: 5px;
}
.add-item-btn:hover {
    background-color: #e0e5ec;
    border-style: solid;
}

/* サイドバーのスタイル */
.sidebar {
    width: 300px;
    max-width: 300px;
    flex-shrink: 0;
    background-color: #e0e5ec;
    padding: 30px 20px;
    height: 100vh;
    position: sticky;
    top: 0;
    box-shadow: 9px 9px 18px rgba(163,177,198,0.6), -9px -9px 18px rgba(255,255,255, 0.5);
    border-radius: 25px;
    margin: 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.sidebar-header h2 {
    text-align: center;
    margin-bottom: 30px;
}

.sidebar-nav ul {
    list-style: none;
    padding: 0;
    margin: 0;
}

.sidebar-nav li {
    margin-bottom: 10px;
}

.sidebar-nav a {
    display: block;
    padding: 12px 15px;
    color: #555;
    text-decoration: none;
    font-size: 18px;
    font-weight: 500;
    border-radius: 18px;
    transition: all 0.3s ease;
    background-color: #e0e5ec; /* 背景色を明示 */
    box-shadow: 9px 9px 18px rgba(163,177,198,0.6), -9px -9px 18px rgba(255,255,255, 0.5);
    text-align: center;
}

.sidebar-nav-group {
    background-color: #e0e5ec;
    border-radius: 20px;
    padding: 20px;
    box-shadow: 9px 9px 18px rgba(163,177,198,0.6), -9px -9px 18px rgba(255,255,255, 0.5);
    width: 100%;
    box-sizing: border-box;
}

.sidebar-nav a:hover {
    box-shadow: inset 4px 4px 8px rgba(163,177,198,0.6), inset -4px -4px 8px rgba(255,255,255, 0.5);
    color: #0056b3;
}

/* サイドバーのデータ操作グループ */
.sidebar-group {
    margin-top: 15px;
    width: 100%;
    box-sizing: border-box;
    /* --- ここから追加 --- */
    background-color: #e0e5ec;
    border-radius: 20px;
    padding: 20px;
    box-shadow: 9px 9px 18px rgba(163,177,198,0.6), -9px -9px 18px rgba(255,255,255, 0.5);
}

.sidebar-group-title {
    font-size: 24px; /* 少し大きめに調整 */
    font-weight: bold;
}

.sidebar-group-title {
    font-size: 24px; /* 少し大きめに調整 */
    font-weight: bold;
    color: #333; /* 文字色を黒にして目立たせる */
    text-align: left;
    margin-bottom: 15px;
    text-shadow: 2px 2px 4px #a3b1c6, -2px -2px 4px #ffffff;
}

.sidebar-button {
    width: 100%;
    padding: 12px 15px;
    border: none;
    border-radius: 18px;
    background-color: #e0e5ec; /* 背景色を明示 */
    box-shadow: 9px 9px 18px rgba(163,177,198,0.6), -9px -9px 18px rgba(255,255,255, 0.5);
    color: #333;
    font-size: 16px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s ease;
}

.sidebar-button:hover {
    box-shadow: inset 4px 4px 8px rgba(163,177,198,0.6), inset -4px -4px 8px rgba(255,255,255, 0.5);
    color: #0056b3;
}

.sidebar-version-info {
    padding-bottom: 15px;
    margin-bottom: 15px;
    border-bottom: 1px solid #d1d9e6;
    text-align: center;
}

.sidebar-version-info p {
    margin: 5px 0;
    color: #6c757d;
    text-shadow: 1px 1px 2px rgba(255,255,255, 0.5);
}



.sidebar-button.danger {
    color: #dc3545;
}

.sidebar-buttons-group {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

/* --- データ操作モーダル --- */
.modal-content.small-modal {
    max-width: 400px; /* 小さめのモーダル */
}

.modal-content.small-modal h2 {
    text-align: center;
    margin-bottom: 30px;
}

.data-modal-buttons {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.modal-button {
    width: 100%;
    padding: 15px 20px;
    border: none;
    border-radius: 18px;
    background-color: #e0e5ec;
    box-shadow: 6px 6px 12px rgba(163,177,198,0.6), -6px -6px 12px rgba(255,255,255, 0.5);
    color: #333;
    font-size: 18px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}

.modal-button:hover {
    box-shadow: inset 4px 4px 8px rgba(163,177,198,0.6), inset -4px -4px 8px rgba(255,255,255, 0.5);
}

.modal-button.danger {
    color: #dc3545;
}

/* モーダルのスタイル */
.modal {
    display: none; /* 初期状態では非表示 */
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(0,0,0,0.5);
}

.modal-content {
    background-color: #e0e5ec;
    margin: 5% auto;
    padding: 40px;
    border: none;
    width: 90%;
    max-width: 1400px;
    border-radius: 25px;
    position: relative;
    box-shadow: 9px 9px 18px rgba(163,177,198,0.6), -9px -9px 18px rgba(255,255,255, 0.5);
}

.close-button {
    color: #aaa;
    position: absolute;
    top: 10px;
    right: 25px;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
}

.close-button:hover,
.close-button:focus {
    color: black;
}

#checkup-form h3, #checkup-form h4 {
    color: #0056b3;
    margin-top: 20px;
    margin-bottom: 10px;
    border-bottom: 2px solid #e9ecef;
    padding-bottom: 5px;
}

#checkup-form h4 {
    font-size: 1.1em;
    border-bottom-style: dotted;
}

.form-section {
    margin-bottom: 20px;
}

.form-columns {
    display: flex;
    gap: 40px;
}

.form-column {
    flex: 1;
}

.form-grid {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 8px 15px;
    align-items: center;
}

.form-grid label {
    font-size: 0.9em;
    text-align: right;
}

.form-grid input[type="text"] {
    width: 100%;
    padding: 6px;
    border: none;
    border-radius: 10px;
    background-color: #e0e5ec;
    box-shadow: inset 4px 4px 8px rgba(163,177,198,0.6), inset -4px -4px 8px rgba(255,255,255, 0.5);
    transition: all 0.3s ease;
}

.form-actions {
    margin-top: 30px;
    text-align: center;
}

.form-actions button {
    padding: 10px 20px;
    border: none;
    border-radius: 18px;
    cursor: pointer;
    font-size: 1em;
    margin: 0 10px;
    font-weight: 600;
    background-color: #e0e5ec;
    box-shadow: 6px 6px 12px rgba(163,177,198,0.6), -6px -6px 12px rgba(255,255,255, 0.5);
    transition: all 0.3s ease;
}

.form-actions button:hover {
    box-shadow: inset 4px 4px 8px rgba(163,177,198,0.6), inset -4px -4px 8px rgba(255,255,255, 0.5);
}

.form-actions button[type="submit"] {
    color: #007bff;
}

.form-actions .cancel-button {
    color: #6c757d;
}

/* --- 履歴表示スタイル --- */
.log-entry {
    padding: 20px;
    border-radius: 18px;
    background-color: #e0e5ec; /* Ensure it has a background */
    box-shadow: 6px 6px 12px rgba(163,177,198,0.6), -6px -6px 12px rgba(255,255,255, 0.5);
    margin-bottom: 15px;
}

/* --- 食事履歴スタイル --- */
.meal-entry {
    padding: 20px;
    border-radius: 18px;
    background-color: #e0e5ec; /* Ensure it has a background */
    box-shadow: 6px 6px 12px rgba(163,177,198,0.6), -6px -6px 12px rgba(255,255,255, 0.5);
    margin-bottom: 15px;
}

.meal-entry pre {
    background-color: #d1d9e6; /* 少し濃い背景 */
    padding: 10px;
    border-radius: 10px;
    white-space: pre-wrap; /* 長いテキストを折り返す */
}

.meal-entry .nutritionist-comment-display {
    background-color: #f8f9fa;
    color: #6c757d;
}

/* --- 履歴の折りたたみスタイル --- */
.history-group {
    margin-bottom: 15px;
}

.summary-content {
    padding: 15px 20px;
    border-radius: 18px; /* ヘッダーに角丸を設定 */
    cursor: pointer;
    font-weight: bold;
    font-size: 1.1em;
    color: #333;
    transition: all 0.3s ease;
    position: relative; /* 疑似要素を配置するために追加 */
    background-color: #e0e5ec;
    box-shadow: 9px 9px 18px rgba(163,177,198,0.6), -9px -9px 18px rgba(255,255,255, 0.5);
}

.summary-content:hover {
    box-shadow: inset 4px 4px 8px rgba(163,177,198,0.6), inset -4px -4px 8px rgba(255,255,255, 0.5);
}

.summary-content::after {
    content: '▼';
    position: absolute;
    right: 20px; /* Adjust position based on padding */
    top: 50%;
    transform: translateY(-50%);
    font-size: 0.8em;
    transition: transform 0.3s ease;
}

.history-group.open .summary-content {
    color: #0056b3;
    box-shadow: inset 4px 4px 8px rgba(163,177,198,0.6), inset -4px -4px 8px rgba(255,255,255, 0.5);
    border-bottom-left-radius: 0; /* 開いたときに下の角丸をなくす */
    border-bottom-right-radius: 0;
}

.history-group.open .summary-content::after {
    content: '▶'; /* 開いた状態のアイコン */
}

.history-group .history-content {
    display: none; /* Initially hidden */
    padding: 20px;
    background-color: #e0e5ec;
    box-shadow: inset 6px 6px 12px rgba(163,177,198,0.6), inset -6px -6px 12px rgba(255,255,255, 0.5);
}

/* --- 履歴エントリーの操作ボタン --- */
.entry-actions {
    text-align: right;
    margin-top: 10px;
}

.edit-btn, .delete-btn {
    background-color: transparent;
    border: none;
    cursor: pointer;
    font-size: 0.9em;
    padding: 5px 10px;
    border-radius: 10px;
    transition: all 0.3s ease;
    margin-left: 5px;
}

.edit-btn {
    color: #007bff;
}

.delete-btn {
    color: #dc3545;
}

.edit-btn:hover, .delete-btn:hover {
    background-color: #d1d9e6;
}

/* --- フッター --- */
.main-footer {
    text-align: center;
    padding: 20px;
    margin-top: auto; /* コンテンツが少なくてもフッターを一番下に配置 */
    color: #6c757d;
    background-color: #e0e5ec;
    border-radius: 25px;
    box-shadow: inset 6px 6px 12px rgba(163,177,198,0.6), inset -6px -6px 12px rgba(255,255,255, 0.5);
}

/* --- 印刷用スタイル --- */
@media print {
    body * {
        visibility: hidden; /* まず全ての要素を非表示に */
    }
    .printable, .printable * {
        visibility: visible; /* 印刷したいエリアだけ表示 */
    }
    .printable {
        position: absolute;
        left: 0;
        top: 0;
        width: 100%;
    }
    .entry-actions, .print-btn, .history-group summary::after {
        display: none !important; /* 修正・削除ボタンやアイコンを非表示 */
    }
    .history-group {
        box-shadow: none;
        border: 1px solid #ccc;
    }
    .history-group[open] > summary {
        margin-bottom: 0;
    }
    details {
        page-break-inside: avoid; /* 印刷時にdetailsが途中で改ページされないように */
    }

    /* 日毎のデータブロックの後で改ページを強制 */
    .history-group {
        page-break-inside: avoid; /* 日の途中で改ページされるのを防ぐ */
        page-break-after: always;
    }
}

/* --- レスポンシブデザイン --- */
@media (max-width: 1200px) {
    .wrapper {
        flex-direction: column;
    }
    .sidebar {
        width: auto;
        height: auto;
        position: relative;
        flex-direction: row;
        justify-content: space-between;
        align-items: center;
        padding: 15px;
        margin: 10px;
        border-radius: 20px;
    }
    .sidebar-header {
        margin-bottom: 0;
    }
    .sidebar-header h2 {
        margin: 0;
        font-size: 1.5em;
    }
    .sidebar-nav {
        flex-grow: 1;
        margin: 0 20px;
    }
    .sidebar-nav ul {
        display: flex;
        justify-content: center;
        gap: 15px;
    }
    .sidebar-nav li {
        margin-bottom: 0;
    }
    .sidebar-group-title {
        display: none; /* スマホでは非表示 */
    }
    .sidebar-group {
        margin-top: 0;
        padding: 0;
        background: none;
        box-shadow: none;
    }
    .container {
        padding: 15px;
    }
}

@media (max-width: 768px) {
    .sidebar {
        flex-direction: column;
        gap: 20px;
    }
    .sidebar-nav {
        margin: 0;
    }
    .sidebar-nav ul {
        flex-direction: column;
        width: 100%;
    }
    .history-container {
        grid-template-columns: 1fr;
    }
    .form-columns {
        flex-direction: column;
    }
    .modal-content {
        padding: 20px;
        margin: 10% auto;
    }
    h1 {
        font-size: 1.8em;
    }
    h2 {
        font-size: 1.4em;
    }
    .content-card {
        padding: 20px;
    }
    .main-action-btn {
        font-size: 1em;
        padding: 15px;
    }
}

@media (max-width: 480px) {
    .sidebar-nav a {
        font-size: 16px;
        padding: 10px 12px;
    }
    .modal-content {
        width: 95%;
        margin: 5% auto;
    }
    .form-grid {
        grid-template-columns: 1fr;
        text-align: left;
    }
    .form-grid label {
        text-align: left;
        margin-bottom: 5px;
    }
}
