/* spreadsheet.css - Excelライクなスプレッドシートスタイル */

/* ============================================================
   iOS auto-zoom prevention baseline
   iOSではfont-size 16px未満のinput/select/textareaにフォーカスすると
   ブラウザが自動ズームする。全入力要素のデフォルトを16pxに設定。
   個別クラスで16px以上の値に上書きは可能。
   ============================================================ */
input, select, textarea {
    font-size: 16px;
}

/* Prevent page-level scrolling; keep all scroll inside #spreadsheet-container */
body:has(#nutrition-sheet-app) {
    overflow: hidden;
}
body:has(#nutrition-sheet-app) footer {
    display: none;
}

/* === Container === */
#nutrition-sheet-app {
    padding: 0;
    margin-top: 0;
    height: calc(100vh - 64px);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: #f8f9fa;
}

/* === Ribbon Menu === */
#ribbon {
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    z-index: 20;
    border-bottom: 1px solid #d1d5db;
    background: #fff;
    position: relative;
}

.ribbon-tab-bar {
    display: flex;
    align-items: center;
    height: 32px;
    padding: 0 12px;
    background: #f3f4f6;
    border-bottom: 1px solid #e5e7eb;
    gap: 0;
    flex-shrink: 0;
}

.ribbon-tab-bar h2 {
    font-size: 14px;
    font-weight: 600;
    color: #1f2937;
    margin: 0;
    white-space: nowrap;
    margin-right: 8px;
}

.sheet-name-display {
    font-size: 13px;
    color: #6b7280;
    margin-right: 12px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 200px;
}

.ribbon-tabs {
    display: flex;
    align-items: stretch;
    flex: 1;
    gap: 0;
}

.ribbon-tab {
    padding: 6px 16px;
    font-size: 13px;
    font-weight: 500;
    color: #4b5563;
    background: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
    white-space: nowrap;
}

.ribbon-tab:hover {
    background: #e5e7eb;
}

.ribbon-tab.active {
    color: #1f2937;
    font-weight: 600;
    background: #fff;
    border-bottom-color: #16a34a;
}

.ribbon-toggle-btn {
    margin-left: auto;
    padding: 4px 8px;
    background: none;
    border: none;
    cursor: pointer;
    color: #6b7280;
    font-size: 12px;
    transition: color 0.15s;
}

.ribbon-toggle-btn:hover {
    color: #1f2937;
}

.ribbon-toggle-btn i {
    transition: transform 0.2s ease;
}

.ribbon.collapsed .ribbon-toggle-btn i {
    transform: rotate(180deg);
}

/* === Ribbon Panel === */
.ribbon-panel {
    overflow: hidden;
    background: #fff;
    border-bottom: 1px solid #e5e7eb;
    max-height: 80px;
    opacity: 1;
    transition: max-height 0.2s ease, opacity 0.15s ease;
}

.ribbon.collapsed .ribbon-panel {
    max-height: 0;
    opacity: 0;
    border-bottom: none;
}

.ribbon.collapsed .ribbon-panel.ribbon-panel-peek {
    max-height: 80px;
    opacity: 1;
    border-bottom: 1px solid #d1d5db;
    position: absolute;
    left: 0;
    right: 0;
    top: 100%;
    z-index: 25;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
    background: #fff;
}

.ribbon-panel-content {
    display: none;
    flex-direction: row;
    align-items: stretch;
    gap: 0;
    padding: 6px 12px;
}

.ribbon-panel-content.active {
    display: flex;
}

/* === Ribbon Groups === */
.ribbon-group {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 0 10px;
}

.ribbon-group-buttons {
    display: flex;
    align-items: center;
    gap: 4px;
    flex: 1;
}

.ribbon-group-label {
    font-size: 11.5px;
    color: #4b5563;
    margin-top: 2px;
    text-align: center;
    white-space: nowrap;
}

.ribbon-group-separator {
    width: 1px;
    background: #d1d5db;
    margin: 4px 0;
    align-self: stretch;
}

.ribbon-inline-label {
    font-size: 13px;
    color: #6b7280;
    white-space: nowrap;
    margin-right: 4px;
}

.toolbar-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 4px 10px;
    font-size: 13px;
    font-weight: 500;
    color: #374151;
    background: #fff;
    border: 1px solid #d1d5db;
    border-radius: 4px;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
    white-space: nowrap;
}

.toolbar-btn:hover {
    background: #f3f4f6;
    border-color: #9ca3af;
}

.toolbar-btn:active {
    background: #e5e7eb;
}

.toolbar-btn.primary {
    background: #16a34a;
    color: #fff;
    border-color: #16a34a;
}

.toolbar-btn.primary:hover {
    background: #15803d;
}

.toolbar-btn.danger {
    color: #dc2626;
    border-color: #fca5a5;
}

.toolbar-btn.danger:hover {
    background: #fef2f2;
    border-color: #dc2626;
}

.toolbar-select {
    padding: 4px 8px;
    font-size: 16px;
    border: 1px solid #d1d5db;
    border-radius: 4px;
    background: #fff;
    cursor: pointer;
}

/* === Spreadsheet Container === */
#spreadsheet-container {
    flex: 1;
    overflow: auto;
    position: relative;
    min-width: 0;
    width: 100%;
}

/* === Table === */
#nutrition-table {
    border-collapse: collapse;
    width: max-content;
    min-width: 100%;
    font-size: 13px;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

/* === Header === */
#nutrition-table thead {
    position: sticky;
    top: 0;
    z-index: 10;
}

#nutrition-table thead th {
    background: #f0f0f0;
    border: 1px solid #c0c0c0;
    padding: 4px 6px;
    font-weight: 600;
    font-size: 12px;
    text-align: center;
    white-space: nowrap;
    color: #333;
    user-select: none;
    position: relative;
    min-width: 60px;
}

/* Column header for nutrient columns */
#nutrition-table thead th.nutrient-col {
    min-width: 70px;
    max-width: 100px;
}

/* Unit row */
#nutrition-table thead tr.unit-row th {
    background: #e8e8e8;
    font-weight: 400;
    font-size: 11px;
    color: #666;
    padding: 2px 6px;
}

/* Reference row */
#nutrition-table thead tr.reference-row th {
    background: #fff9e6;
    font-weight: 400;
    font-size: 11px;
    color: #92400e;
    padding: 2px 6px;
}

/* === Cells === */
#nutrition-table tbody td {
    border: 1px solid #d1d5db;
    padding: 2px 4px;
    height: 26px;
    vertical-align: middle;
    background: #fff;
    color: #1f2937;
    position: relative;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Row number column */
#nutrition-table tbody td.row-num {
    background: #f0f0f0;
    color: #6b7280;
    text-align: center;
    font-size: 11px;
    width: 30px;
    min-width: 30px;
    cursor: default;
    user-select: none;
}

/* Editable cells */
#nutrition-table tbody td.editable {
    cursor: cell;
}

#nutrition-table tbody td.editable:hover {
    background: #f0f8ff;
}

/* Active/Selected cell */
#nutrition-table tbody td.active {
    outline: 2px solid #2563eb;
    outline-offset: -1px;
    z-index: 2;
}

/* Multi-row selection */
#nutrition-table tbody tr.row-selected {
    background: #dbeafe !important;
}
#nutrition-table tbody tr.row-selected td {
    background: inherit;
}

/* Editing cell */
#nutrition-table tbody td.editing {
    padding: 0;
    overflow: visible;
}

#nutrition-table tbody td.editing input,
#nutrition-table tbody td.editing select {
    width: 100%;
    height: 100%;
    border: none;
    outline: none;
    padding: 2px 4px;
    font-size: 16px;
    font-family: inherit;
    background: #fff;
    box-sizing: border-box;
}

/* Numeric cells */
#nutrition-table tbody td.numeric {
    text-align: right;
    padding-right: 6px;
    font-variant-numeric: tabular-nums;
}

/* Food name column */
#nutrition-table tbody td.food-name {
    min-width: 180px;
    max-width: 250px;
}

/* Weight column */
#nutrition-table tbody td.weight-col {
    min-width: 60px;
    width: 70px;
}

/* Meal type column */
#nutrition-table tbody td.meal-type {
    min-width: 70px;
    width: 80px;
    position: relative;
}

#nutrition-table tbody td.meal-type .meal-type-label {
    overflow: hidden;
    text-overflow: ellipsis;
    vertical-align: middle;
}

#nutrition-table tbody td.meal-type .meal-type-toggle {
    position: absolute;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
    color: #94a3b8;
    cursor: pointer;
    border-radius: 2px;
    line-height: 1;
    padding: 4px 6px;
    font-size: 10px;
}

#nutrition-table tbody td.meal-type .meal-type-toggle:hover {
    color: #3b82f6;
    background: #eff6ff;
}

/* Recipe name column */
#nutrition-table tbody td.recipe-name {
    min-width: 120px;
    max-width: 180px;
}

/* === Aggregation Rows === */
/* Recipe subtotal - light blue */
#nutrition-table tbody tr.subtotal-recipe td {
    background-color: #cce5ff;
    font-weight: 600;
    border-color: #b3d4fc;
}

/* Meal category total - light orange */
#nutrition-table tbody tr.subtotal-meal td {
    background-color: #ffe6cc;
    font-weight: 600;
    border-color: #ffd4a8;
}

/* Grand total - light purple */
#nutrition-table tbody tr.subtotal-grand td {
    background-color: #ffccff;
    font-weight: 700;
    border-color: #e6b3e6;
}

/* PFC ratio row */
#nutrition-table tbody tr.pfc-row td {
    background-color: #e6ffe6;
    font-weight: 600;
    font-size: 12px;
    border-color: #b3e6b3;
}

/* Satisfaction rate row */
#nutrition-table tbody tr.satisfaction-row td {
    background-color: #f0f4ff;
    font-weight: 600;
    font-size: 12px;
    border-color: #c7d2fe;
}

/* === Food Search Dropdown === */
.food-search-dropdown {
    position: absolute;
    z-index: 100;
    background: #fff;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.15);
    max-height: 60vh;
    overflow-y: auto;
    min-width: min(350px, 90vw);
}

.food-search-dropdown .search-input-wrapper {
    position: sticky;
    top: 0;
    background: #fff;
    padding: 8px;
    border-bottom: 1px solid #e5e7eb;
}

.food-search-dropdown .search-input-wrapper input {
    width: 100%;
    padding: 6px 10px;
    border: 1px solid #d1d5db;
    border-radius: 4px;
    font-size: 16px;
    outline: none;
    box-sizing: border-box;
}

.food-search-dropdown .search-input-wrapper input:focus {
    border-color: #2563eb;
    box-shadow: 0 0 0 2px rgba(37,99,235,0.15);
}

.food-search-item {
    padding: 6px 10px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    border-bottom: 1px solid #f3f4f6;
}

.food-search-item:hover,
.food-search-item.highlighted {
    background: #eff6ff;
}

.food-search-item .food-group-badge {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}

.food-search-item .food-number {
    color: #6b7280;
    font-size: 11px;
    flex-shrink: 0;
    width: 50px;
}

.food-search-item .food-name-text {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.food-search-no-results {
    padding: 16px;
    text-align: center;
    color: #9ca3af;
    font-size: 13px;
}

/* === Meal Type Dropdown === */
.meal-type-dropdown {
    position: absolute;
    z-index: 100;
    background: #fff;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.12);
    min-width: 120px;
}

.meal-type-dropdown .dropdown-item {
    padding: 6px 12px;
    cursor: pointer;
    font-size: 13px;
}

.meal-type-dropdown .dropdown-item:hover {
    background: #eff6ff;
}

.meal-type-dropdown .dropdown-item-disabled {
    color: #9ca3af;
    cursor: not-allowed;
    opacity: 0.6;
}

.meal-type-dropdown .dropdown-item-disabled:hover {
    background: transparent;
}

.meal-type-dropdown .dropdown-item-clear {
    color: #6b7280;
    font-style: italic;
    border-bottom: 1px solid #e5e7eb;
}

/* === Tooltip (standard amount) === */
.cell-tooltip {
    position: absolute;
    z-index: 200;
    background: #1f2937;
    color: #fff;
    padding: 6px 10px;
    border-radius: 4px;
    font-size: 12px;
    white-space: nowrap;
    pointer-events: none;
    box-shadow: 0 4px 8px rgba(0,0,0,0.2);
}

.cell-tooltip::before {
    content: '';
    position: absolute;
    top: -5px;
    left: 12px;
    border-left: 5px solid transparent;
    border-right: 5px solid transparent;
    border-bottom: 5px solid #1f2937;
}

/* === Empty State === */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 20px;
    color: #9ca3af;
}

.empty-state i {
    font-size: 48px;
    margin-bottom: 16px;
    color: #d1d5db;
}

.empty-state p {
    font-size: 14px;
    margin: 4px 0;
}

/* === Nutrient Profile Modal === */

.modal-content {
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 20px 40px rgba(0,0,0,0.2);
    max-width: 600px;
    width: 90%;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid #e5e7eb;
}

.modal-header h3 {
    font-size: 16px;
    font-weight: 600;
    margin: 0;
}

.modal-close {
    background: none;
    border: none;
    font-size: 20px;
    cursor: pointer;
    color: #6b7280;
    padding: 4px;
}

.modal-body {
    padding: 20px;
    overflow-y: auto;
    flex: 1;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding: 12px 20px;
    border-top: 1px solid #e5e7eb;
}

/* === Save Sheet Modal === */
.save-modal-row {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 14px;
}

.save-modal-label {
    min-width: 110px;
    font-size: 13px;
    font-weight: 500;
    color: #374151;
    flex-shrink: 0;
}

.save-modal-input {
    flex: 1;
    padding: 6px 10px;
    border: 1px solid #d1d5db;
    border-radius: 4px;
    font-size: 16px;
    outline: none;
}

.save-modal-input:focus {
    border-color: #3b82f6;
    box-shadow: 0 0 0 2px rgba(59,130,246,0.15);
}

.save-modal-date-wrap {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 13px;
    color: #374151;
}

.save-modal-select {
    padding: 5px 6px;
    border: 1px solid #d1d5db;
    border-radius: 4px;
    font-size: 16px;
    min-width: 60px;
    outline: none;
}

.save-modal-select:focus {
    border-color: #3b82f6;
}

.save-modal-combine {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    color: #374151;
    cursor: pointer;
}

.save-modal-example {
    margin-left: 12px;
    font-size: 12px;
    color: #9ca3af;
}

.save-modal-preview {
    font-size: 14px;
    font-weight: 600;
    color: #1d4ed8;
    padding: 4px 0;
}

/* === Column Settings Modal === */
.nutrient-group {
    margin-bottom: 8px;
}

.nutrient-group-header {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 8px;
    background: #f3f4f6;
    border: 1px solid #e5e7eb;
    border-radius: 4px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 600;
    color: #374151;
    user-select: none;
}

.nutrient-group-header:hover {
    background: #e5e7eb;
}

.group-toggle {
    font-size: 10px;
    color: #6b7280;
}

.nutrient-checkbox-list {
    padding: 4px 0 4px 16px;
}

.nutrient-checkbox-item {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 3px 4px;
    font-size: 12px;
    cursor: pointer;
    border-radius: 3px;
    color: #1f2937;
}

.nutrient-checkbox-item:hover {
    background: #eff6ff;
}

.nutrient-checkbox-item input[type="checkbox"] {
    margin: 0;
    cursor: pointer;
}

.selected-columns-list {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.selected-column-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 4px 8px;
    background: #f9fafb;
    border: 1px solid #e5e7eb;
    border-radius: 4px;
    font-size: 12px;
    color: #1f2937;
}

.selected-column-item:hover {
    background: #eff6ff;
    border-color: #bfdbfe;
}

.selected-column-label {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.column-bulk-btn {
    padding: 2px 8px;
    font-size: 11px;
    border: 1px solid #d1d5db;
    border-radius: 3px;
    background: #fff;
    color: #374151;
    cursor: pointer;
    white-space: nowrap;
}

.column-bulk-btn:hover {
    background: #e5e7eb;
    color: #1f2937;
}

.column-drag-handle {
    cursor: grab;
    color: #9ca3af;
    font-size: 14px;
    padding: 0 4px;
    flex-shrink: 0;
    user-select: none;
}

.column-drag-handle:active {
    cursor: grabbing;
}

.selected-column-item.dragging {
    opacity: 0.4;
}

.selected-column-item.drag-over-top {
    border-top: 2px solid #6366f1;
}

.selected-column-item.drag-over-bottom {
    border-bottom: 2px solid #6366f1;
}

/* Dark mode - Column Settings */
.dark .nutrient-group-header {
    background: #374151;
    border-color: #4b5563;
    color: #e5e7eb;
}

.dark .nutrient-group-header:hover {
    background: #4b5563;
}

.dark .nutrient-checkbox-item {
    color: #e5e7eb;
}

.dark .nutrient-checkbox-item:hover {
    background: #374151;
}

.dark .selected-column-item {
    background: #1f2937;
    border-color: #4b5563;
    color: #e5e7eb;
}

.dark .selected-column-item:hover {
    background: #374151;
    border-color: #6366f1;
}

.dark .column-bulk-btn {
    background: #374151;
    border-color: #4b5563;
    color: #d1d5db;
}

.dark .column-bulk-btn:hover {
    background: #4b5563;
    color: #e5e7eb;
}

.dark .column-drag-handle {
    color: #6b7280;
}

.dark .modal-content {
    background: #1f2937;
    color: #e5e7eb;
}

.dark .modal-header {
    border-color: #374151;
}

.dark .modal-header h3 {
    color: #e5e7eb;
}

.dark .modal-close {
    color: #9ca3af;
}

.dark .modal-footer {
    border-color: #374151;
}

/* === PFC Popup === */
.pfc-popup-content {
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.15);
    max-width: 420px;
    width: 90%;
    overflow: hidden;
}

.pfc-popup-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid #e5e7eb;
}

.pfc-popup-header h3 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
    color: #1f2937;
}

.pfc-popup-body {
    padding: 20px;
}

.pfc-bar-container {
    display: flex;
    height: 32px;
    border-radius: 6px;
    overflow: hidden;
    margin-bottom: 20px;
}

.pfc-bar {
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-weight: 700;
    font-size: 13px;
    min-width: 24px;
}

.pfc-bar-p { background: #3b82f6; }
.pfc-bar-f { background: #f59e0b; }
.pfc-bar-c { background: #10b981; }

.pfc-values {
    display: flex;
    gap: 12px;
    margin-bottom: 16px;
}

.pfc-value-item {
    flex: 1;
    text-align: center;
    padding: 10px 8px;
    border-radius: 8px;
    background: #f9fafb;
    border: 1px solid #e5e7eb;
}

.pfc-value-item.pfc-p { border-left: 3px solid #3b82f6; }
.pfc-value-item.pfc-f { border-left: 3px solid #f59e0b; }
.pfc-value-item.pfc-c { border-left: 3px solid #10b981; }

.pfc-value-label {
    font-size: 11px;
    color: #6b7280;
    margin-bottom: 4px;
}

.pfc-value-num {
    font-size: 22px;
    font-weight: 700;
    color: #1f2937;
}

.pfc-ratio-summary {
    text-align: center;
    font-size: 18px;
    font-weight: 600;
    color: #374151;
    padding: 8px;
    background: #f3f4f6;
    border-radius: 6px;
}

/* PFC popup dark mode */
.dark .pfc-popup-content {
    background: #1f2937;
}

.dark .pfc-popup-header {
    border-color: #374151;
}

.dark .pfc-popup-header h3 {
    color: #e5e7eb;
}

.dark .pfc-value-item {
    background: #111827;
    border-color: #374151;
}

.dark .pfc-value-num {
    color: #e5e7eb;
}

.dark .pfc-ratio-summary {
    background: #111827;
    color: #e5e7eb;
}

/* === Scrollbar Styling === */
#spreadsheet-container::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

#spreadsheet-container::-webkit-scrollbar-track {
    background: #f1f1f1;
}

#spreadsheet-container::-webkit-scrollbar-thumb {
    background: #c0c0c0;
    border-radius: 5px;
}

#spreadsheet-container::-webkit-scrollbar-thumb:hover {
    background: #a0a0a0;
}

/* === Loading Indicator === */
.sheet-loading {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    display: flex;
    align-items: center;
    gap: 8px;
    color: #6b7280;
    font-size: 14px;
}

.sheet-loading .spinner {
    width: 20px;
    height: 20px;
    border: 2px solid #e5e7eb;
    border-top-color: #16a34a;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* === Dark mode support === */
.dark #nutrition-sheet-app {
    background: #111827;
}

.dark #ribbon {
    background: #111827;
    border-color: #374151;
}

.dark .ribbon-tab-bar {
    background: #1f2937;
    border-color: #374151;
}

.dark .ribbon-tab-bar h2 {
    color: #f3f4f6;
}

.dark .sheet-name-display {
    color: #9ca3af;
}

.dark .ribbon-tab {
    color: #d1d5db;
}

.dark .ribbon-tab:hover {
    background: #374151;
}

.dark .ribbon-tab.active {
    background: #111827;
    color: #f3f4f6;
    border-bottom-color: #22c55e;
}

.dark .ribbon-toggle-btn {
    color: #9ca3af;
}

.dark .ribbon-toggle-btn:hover {
    color: #e5e7eb;
}

.dark .ribbon-panel {
    background: #1f2937;
    border-color: #374151;
}

.dark .ribbon.collapsed .ribbon-panel.ribbon-panel-peek {
    background: #1f2937;
    border-color: #374151;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}

.dark .ribbon-group-label {
    color: #9ca3af;
}

.dark .ribbon-group-separator {
    background: #374151;
}

.dark .ribbon-inline-label {
    color: #9ca3af;
}

.dark .toolbar-btn {
    background: #374151;
    color: #e5e7eb;
    border-color: #4b5563;
}

.dark .toolbar-btn:hover {
    background: #4b5563;
}

.dark .toolbar-btn.primary {
    background: #16a34a;
    color: #fff;
    border-color: #16a34a;
}

.dark #nutrition-table thead th {
    background: #374151;
    border-color: #4b5563;
    color: #e5e7eb;
}

.dark #nutrition-table thead tr.unit-row th {
    background: #1f2937;
    color: #9ca3af;
}

.dark #nutrition-table thead tr.reference-row th {
    background: #422006;
    color: #fbbf24;
}

.dark #nutrition-table tbody td {
    background: #1f2937;
    border-color: #374151;
    color: #e5e7eb;
}

.dark #nutrition-table tbody td.row-num {
    background: #374151;
    color: #9ca3af;
}

.dark #nutrition-table tbody td.editable:hover {
    background: #1e3a5f;
}

.dark #nutrition-table tbody tr.subtotal-recipe td {
    background-color: #1e3a5f;
    border-color: #2563eb;
}

.dark #nutrition-table tbody tr.subtotal-meal td {
    background-color: #451a03;
    border-color: #92400e;
}

.dark #nutrition-table tbody tr.subtotal-grand td {
    background-color: #4a1d6a;
    border-color: #7c3aed;
}

.dark #nutrition-table tbody tr.satisfaction-row td {
    background-color: #1e1b4b;
    border-color: #4338ca;
}

.dark #nutrition-table tbody tr.pfc-row td {
    background-color: #052e16;
    border-color: #166534;
}

/* Dark mode - Mobile Notice */
.dark .mobile-notice-content {
    background: #1f2937;
}

.dark .mobile-notice-content h3 {
    color: #e5e7eb;
}

.dark .mobile-notice-content p {
    color: #9ca3af;
}

.dark .mobile-notice-content i {
    color: #9ca3af;
}

.dark .food-search-dropdown {
    background: #1f2937;
    border-color: #4b5563;
}

.dark .food-search-dropdown .search-input-wrapper {
    background: #1f2937;
    border-color: #374151;
}

.dark .food-search-dropdown .search-input-wrapper input {
    background: #374151;
    color: #e5e7eb;
    border-color: #4b5563;
}

.dark .food-search-item {
    border-color: #374151;
    color: #e5e7eb;
}

.dark .food-search-item:hover,
.dark .food-search-item.highlighted {
    background: #374151;
}

/* === Mobile Notice Overlay === */
.mobile-only-notice {
    display: none;
}

/* === Responsive: Tablet (max-width: 1024px) === */
@media (max-width: 1024px) {
    .ribbon-tab-bar h2 {
        display: none;
    }

    .sheet-name-display {
        display: none;
    }

    .ribbon-tab {
        padding: 8px 12px;
        font-size: 14px;
    }

    .toolbar-btn {
        padding: 8px 12px;
        font-size: 14px;
    }

    .toolbar-select {
        padding: 8px 10px;
        font-size: 16px;
    }

    .ribbon.collapsed .ribbon-panel.ribbon-panel-peek {
        position: absolute;
        top: 100%;
    }

    /* 既存のテーブルセル/モーダルルールは維持 */
    #nutrition-table tbody td {
        height: 36px;
        padding: 4px 6px;
    }

    #nutrition-table tbody td.meal-type .meal-type-toggle {
        transform: translateY(-50%) scale(1.0);
        opacity: 0.6;
    }

    .modal-content {
        max-height: calc(100vh - 40px);
    }

    .modal-body {
        -webkit-overflow-scrolling: touch;
    }
}

/* === Responsive: Smartphone (max-width: 767px) === */
@media (max-width: 767px) {
    #nutrition-sheet-app {
        width: 0;
        max-width: 0;
        overflow: hidden;
    }
    .mobile-only-notice {
        display: flex;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 1000;
        background: rgba(0,0,0,0.5);
        align-items: center;
        justify-content: center;
        padding: 20px;
    }

    .mobile-notice-content {
        background: #fff;
        border-radius: 12px;
        padding: 32px 24px;
        text-align: center;
        max-width: 360px;
        width: 100%;
        box-shadow: 0 20px 40px rgba(0,0,0,0.2);
    }

    .mobile-notice-content i {
        font-size: 48px;
        color: #6b7280;
        margin-bottom: 16px;
        display: block;
    }

    .mobile-notice-content h3 {
        font-size: 18px;
        font-weight: 600;
        color: #1f2937;
        margin: 0 0 12px;
    }

    .mobile-notice-content p {
        font-size: 14px;
        color: #6b7280;
        margin: 0 0 8px;
        line-height: 1.5;
    }

    .mobile-notice-content .toolbar-btn {
        margin-top: 16px;
        padding: 10px 24px;
        font-size: 15px;
    }

    /* ツールバータイトル省略 */
    .ribbon-tab-bar h2 {
        font-size: 14px;
    }
}

/* === Touch device: hover alternatives === */
@media (hover: none) {
    #nutrition-table tbody td.meal-type .meal-type-toggle {
        opacity: 0.6;
        transform: translateY(-50%) scale(1.0);
    }

    #nutrition-table tbody td.editable {
        background: #fafbff;
    }

    .dark #nutrition-table tbody td.editable {
        background: #1a2332;
    }

    /* 食品検索の項目タッチターゲット拡大 */
    .food-search-item {
        padding: 10px 12px;
    }

    .meal-type-dropdown .dropdown-item {
        padding: 10px 14px;
    }
}

/* === 100dvh fix === */
@supports (height: 100dvh) {
    #nutrition-sheet-app {
        height: calc(100dvh - 64px);
    }
    @media (max-width: 1024px) {
        .modal-content {
            max-height: calc(100dvh - 40px);
        }
    }
}

/* === Print styles === */
@media print {
    #ribbon { display: none; }
    #nutrition-sheet-app {
        height: auto;
        overflow: visible;
    }
    #spreadsheet-container {
        overflow: visible;
    }
    #nutrition-table thead {
        position: static;
    }
    #nutrition-table tbody td,
    #nutrition-table thead th {
        border: 1px solid #000;
    }
}

/* ============================================================
   Meal Category Set Selector & Manager
   ============================================================ */

/* Toolbar selector */
#meal-category-set-selector {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    cursor: pointer;
}
.meal-set-label {
    max-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.meal-set-caret {
    font-size: 0.7em;
    opacity: 0.6;
}

/* Set dropdown */
.meal-set-dropdown {
    background: #fff;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    min-width: 180px;
    max-height: 300px;
    overflow-y: auto;
    padding: 4px 0;
}
.meal-set-dropdown .dropdown-item {
    padding: 8px 16px;
    cursor: pointer;
    font-size: 0.9rem;
}
.meal-set-dropdown .dropdown-item:hover {
    background: #f3f4f6;
}
.meal-set-dropdown .dropdown-item-active {
    background: #e0f2fe;
    font-weight: 600;
}
.meal-set-dropdown .dropdown-item-action {
    color: #6b7280;
}
.meal-set-dropdown .dropdown-separator {
    height: 1px;
    background: #e5e7eb;
    margin: 4px 0;
}

/* Modal overlay */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10001;
}

/* Modal */
.meal-category-modal {
    background: #fff;
    border-radius: 10px;
    box-shadow: 0 8px 30px rgba(0,0,0,0.2);
    width: 680px;
    max-width: 95vw;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid #e5e7eb;
}
.modal-header h3 {
    margin: 0;
    font-size: 1.1rem;
    font-weight: 600;
}
.modal-close-btn {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: #6b7280;
    padding: 0 4px;
    line-height: 1;
}
.modal-close-btn:hover {
    color: #111;
}

/* Content layout */
.meal-category-content {
    display: flex;
    flex: 1;
    overflow: hidden;
    min-height: 350px;
}

/* Left panel */
.meal-category-left {
    width: 200px;
    min-width: 180px;
    border-right: 1px solid #e5e7eb;
    overflow-y: auto;
    padding: 12px;
    background: #f9fafb;
}

.meal-cat-section-title {
    font-size: 0.8rem;
    font-weight: 600;
    color: #6b7280;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 8px;
}

.meal-cat-set-item {
    padding: 8px 10px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.9rem;
    margin-bottom: 2px;
    display: flex;
    align-items: center;
    gap: 4px;
}
.meal-cat-set-item:hover {
    background: #e5e7eb;
}
.meal-cat-set-item.active {
    background: #dbeafe;
    font-weight: 600;
}
.meal-cat-active-marker {
    color: #2563eb;
    font-size: 0.7em;
}
.meal-cat-badge {
    font-size: 0.7rem;
    background: #e5e7eb;
    padding: 1px 6px;
    border-radius: 4px;
    color: #6b7280;
    margin-left: auto;
}

.meal-cat-add-set-btn {
    display: block;
    width: 100%;
    padding: 8px;
    margin-top: 12px;
    border: 1px dashed #d1d5db;
    border-radius: 6px;
    background: transparent;
    color: #6b7280;
    cursor: pointer;
    font-size: 0.85rem;
    text-align: center;
}
.meal-cat-add-set-btn:hover {
    background: #f3f4f6;
    color: #374151;
}

/* Right panel */
.meal-category-right {
    flex: 1;
    overflow-y: auto;
    padding: 16px 20px;
}

.meal-cat-hint {
    color: #9ca3af;
    text-align: center;
    margin-top: 60px;
}

.meal-cat-field-group {
    margin-bottom: 16px;
}
.meal-cat-field-group label {
    display: block;
    font-size: 0.8rem;
    font-weight: 600;
    color: #374151;
    margin-bottom: 4px;
}
.meal-cat-name-input {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font-size: 16px;
    box-sizing: border-box;
}
.meal-cat-name-input:disabled {
    background: #f3f4f6;
    color: #9ca3af;
}

.meal-cat-notice {
    background: #fef3c7;
    border: 1px solid #fbbf24;
    border-radius: 6px;
    padding: 10px 14px;
    font-size: 0.85rem;
    color: #92400e;
    margin-bottom: 16px;
}

/* Category rows */
.meal-cat-list {
    margin-bottom: 8px;
}
.meal-cat-row {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 0;
    border-bottom: 1px solid #f3f4f6;
}
.meal-cat-move {
    display: flex;
    flex-direction: column;
    gap: 1px;
}
.meal-cat-move-btn {
    background: none;
    border: 1px solid #d1d5db;
    border-radius: 3px;
    font-size: 0.6rem;
    padding: 1px 5px;
    cursor: pointer;
    color: #6b7280;
    line-height: 1;
}
.meal-cat-move-btn:hover:not(:disabled) {
    background: #e5e7eb;
}
.meal-cat-move-btn:disabled {
    opacity: 0.3;
    cursor: default;
}
.meal-cat-label-input {
    flex: 1;
    padding: 6px 8px;
    border: 1px solid #d1d5db;
    border-radius: 4px;
    font-size: 16px;
}
.meal-cat-label-input:disabled {
    background: #f3f4f6;
    color: #6b7280;
}
.meal-cat-del-btn {
    background: none;
    border: none;
    font-size: 1.2rem;
    color: #ef4444;
    cursor: pointer;
    padding: 2px 6px;
    line-height: 1;
    opacity: 0.6;
}
.meal-cat-del-btn:hover {
    opacity: 1;
}

.meal-cat-add-btn {
    display: inline-block;
    padding: 6px 14px;
    border: 1px dashed #d1d5db;
    border-radius: 6px;
    background: transparent;
    color: #6b7280;
    cursor: pointer;
    font-size: 0.85rem;
    margin-bottom: 16px;
}
.meal-cat-add-btn:hover {
    background: #f3f4f6;
    color: #374151;
}

.meal-cat-btn-group {
    display: flex;
    gap: 8px;
    padding-top: 12px;
    border-top: 1px solid #e5e7eb;
    flex-wrap: wrap;
}

/* Toast notification */
.toast-notification {
    position: fixed;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: #1f2937;
    color: #fff;
    padding: 10px 24px;
    border-radius: 8px;
    font-size: 0.9rem;
    opacity: 0;
    transition: opacity 0.3s, transform 0.3s;
    z-index: 20000;
    pointer-events: none;
}
.toast-notification.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* ============================================================
   Recipe Save / Metadata / Cooking Modals
   ============================================================ */

/* Status dot (recipe_name cell) */
.recipe-status-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin-right: 4px;
    vertical-align: middle;
}
.recipe-status-dot.saved { background: #22c55e; }
.recipe-status-dot.unsaved { background: #f59e0b; }
.recipe-status-dot.no-metadata { background: #ef4444; }

/* Recipe modal overlay */
.recipe-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Recipe modal */
.recipe-modal {
    background: #fff;
    border-radius: 10px;
    box-shadow: 0 8px 30px rgba(0,0,0,0.2);
    max-width: 500px;
    width: 92%;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.recipe-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid #e5e7eb;
}
.recipe-modal-header h3 {
    margin: 0;
    font-size: 1.05rem;
    font-weight: 600;
    color: #1f2937;
}
.recipe-modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: #6b7280;
    padding: 0 4px;
    line-height: 1;
}
.recipe-modal-close:hover { color: #111; }

.recipe-modal-body {
    padding: 16px 20px;
    overflow-y: auto;
    flex: 1;
}

.recipe-modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding: 12px 20px;
    border-top: 1px solid #e5e7eb;
}

/* Recipe list items */
.recipe-list-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 12px;
    cursor: pointer;
    border-radius: 6px;
    transition: background 0.12s;
    border: 1px solid transparent;
    margin-bottom: 4px;
}
.recipe-list-item:hover {
    background: #f3f4f6;
    border-color: #e5e7eb;
}
.recipe-list-item-name {
    font-size: 0.95rem;
    font-weight: 500;
    color: #1f2937;
    display: flex;
    align-items: center;
    gap: 6px;
}
.recipe-status-badge {
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 500;
    white-space: nowrap;
}
.recipe-status-badge.saved {
    background: #dcfce7;
    color: #166534;
}
.recipe-status-badge.modified {
    background: #fef3c7;
    color: #92400e;
}
.recipe-status-badge.unsaved {
    background: #fee2e2;
    color: #991b1b;
}

/* Metadata form */
.metadata-form-group {
    margin-bottom: 14px;
}
.metadata-form-group label {
    display: block;
    font-size: 0.82rem;
    font-weight: 600;
    color: #374151;
    margin-bottom: 4px;
}
.metadata-select {
    width: 100%;
    padding: 7px 10px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font-size: 16px;
    background: #fff;
    cursor: pointer;
    outline: none;
    box-sizing: border-box;
}
.metadata-select:focus {
    border-color: #3b82f6;
    box-shadow: 0 0 0 2px rgba(59,130,246,0.15);
}
.metadata-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    align-items: center;
}
.metadata-chip {
    display: inline-flex;
    align-items: center;
    padding: 3px 10px;
    background: #e0e7ff;
    border-radius: 16px;
    font-size: 0.85rem;
    color: #3730a3;
}
.metadata-chip-remove {
    cursor: pointer;
    margin-left: 4px;
    color: #6366f1;
    font-weight: 700;
    font-size: 1rem;
    line-height: 1;
}
.metadata-chip-remove:hover {
    color: #ef4444;
}
.metadata-add-btn {
    display: inline-flex;
    align-items: center;
    gap: 2px;
    padding: 3px 10px;
    background: #f3f4f6;
    border: 1px dashed #d1d5db;
    border-radius: 16px;
    font-size: 0.82rem;
    color: #6b7280;
    cursor: pointer;
}
.metadata-add-btn:hover {
    background: #e5e7eb;
    color: #374151;
}

.metadata-link-btn {
    display: inline-block;
    padding: 6px 0;
    font-size: 0.85rem;
    color: #3b82f6;
    cursor: pointer;
    background: none;
    border: none;
}
.metadata-link-btn:hover {
    text-decoration: underline;
}

/* Cooking modal tabs */
.cooking-tabs {
    display: flex;
    border-bottom: 2px solid #e5e7eb;
    margin-bottom: 12px;
}
.cooking-tab {
    padding: 8px 16px;
    cursor: pointer;
    font-size: 0.9rem;
    color: #6b7280;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    background: none;
    border-top: none;
    border-left: none;
    border-right: none;
}
.cooking-tab:hover {
    color: #374151;
}
.cooking-tab.active {
    border-bottom-color: #3b82f6;
    color: #3b82f6;
    font-weight: 600;
}

/* 前日チェックボックス */
.food-prep-prev-day {
    width: 18px;
    height: 18px;
    cursor: pointer;
    accent-color: #3b82f6;
}

/* 3タブ対応 - モバイルでの余白調整 */
@media (max-width: 600px) {
    .cooking-tab {
        padding: 8px 8px;
        font-size: 0.8rem;
    }
}

/* Cooking steps */
.cooking-step {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    padding: 8px 4px;
    border: 1px dashed transparent;
    border-radius: 6px;
    margin-bottom: 4px;
    transition: border-color 0.15s, background 0.15s;
}
.cooking-step.drag-over {
    border-color: #3b82f6;
    background: #f0f4ff;
}
.cooking-step .drag-handle {
    cursor: grab;
    color: #9ca3af;
    font-size: 1.2em;
    padding: 4px 2px;
    user-select: none;
    flex-shrink: 0;
}
.cooking-step .drag-handle:active { cursor: grabbing; }
.cooking-step-number {
    font-size: 0.85rem;
    font-weight: 600;
    color: #6b7280;
    min-width: 24px;
    text-align: right;
    flex-shrink: 0;
    padding-top: 6px;
}
.cooking-step textarea {
    flex: 1;
    resize: vertical;
    padding: 6px 8px;
    border: 1px solid #d1d5db;
    border-radius: 4px;
    font-size: 16px;
    min-height: 36px;
    font-family: inherit;
    box-sizing: border-box;
}
.cooking-step textarea:focus {
    border-color: #3b82f6;
    outline: none;
}
.cooking-step-delete {
    background: none;
    border: none;
    color: #ef4444;
    cursor: pointer;
    font-size: 1.1rem;
    padding: 4px 4px;
    opacity: 0.6;
    flex-shrink: 0;
}
.cooking-step-delete:hover { opacity: 1; }

/* Food processing table */
.food-processing-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}
.food-processing-table th {
    text-align: left;
    font-size: 0.8rem;
    font-weight: 600;
    color: #6b7280;
    padding: 6px 4px;
    border-bottom: 1px solid #e5e7eb;
}
.food-processing-table td {
    padding: 6px 4px;
    border-bottom: 1px solid #f3f4f6;
    vertical-align: middle;
}
.food-processing-input {
    width: 100%;
    padding: 4px 6px;
    border: 1px solid #d1d5db;
    border-radius: 4px;
    font-size: 16px;
    box-sizing: border-box;
}
.food-processing-input:focus {
    border-color: #3b82f6;
    outline: none;
}
.food-processing-select {
    padding: 4px 6px;
    border: 1px solid #d1d5db;
    border-radius: 4px;
    font-size: 16px;
    background: #fff;
    cursor: pointer;
    min-width: 80px;
}

/* Food group management */
.food-group-section {
    margin-top: 16px;
    padding-top: 12px;
    border-top: 1px solid #e5e7eb;
}
.food-group-section-title {
    font-size: 0.82rem;
    font-weight: 600;
    color: #6b7280;
    margin-bottom: 8px;
}
.food-group-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 0;
}
.food-group-item input[type="text"] {
    flex: 1;
    padding: 4px 6px;
    border: 1px solid #d1d5db;
    border-radius: 4px;
    font-size: 16px;
}
.food-group-color-input {
    width: 40px;
    height: 30px;
    border: none;
    cursor: pointer;
    background: transparent;
    padding: 0;
}
.food-group-del-btn {
    background: none;
    border: none;
    color: #ef4444;
    cursor: pointer;
    font-size: 1.1rem;
    opacity: 0.6;
}
.food-group-del-btn:hover { opacity: 1; }

/* Missing metadata modal */
.missing-metadata-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 0;
    border-bottom: 1px solid #f3f4f6;
}
.missing-metadata-item:last-child { border-bottom: none; }
.missing-metadata-name {
    font-weight: 500;
    color: #1f2937;
}
.missing-metadata-actions {
    display: flex;
    gap: 6px;
}
.missing-metadata-actions button {
    padding: 3px 10px;
    border: 1px solid #d1d5db;
    border-radius: 4px;
    background: #fff;
    font-size: 0.8rem;
    cursor: pointer;
    color: #374151;
}
.missing-metadata-actions button:hover {
    background: #f3f4f6;
    border-color: #9ca3af;
}

/* Options editor sub-modal */
.options-editor-category {
    margin-bottom: 16px;
}
.options-editor-category-title {
    font-size: 0.85rem;
    font-weight: 600;
    color: #374151;
    margin-bottom: 6px;
}
.options-editor-item {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 0;
}
.options-editor-item input {
    flex: 1;
    padding: 4px 8px;
    border: 1px solid #d1d5db;
    border-radius: 4px;
    font-size: 16px;
}
.options-editor-item input:disabled {
    background: #f3f4f6;
    color: #9ca3af;
}
.options-editor-item .system-badge {
    font-size: 0.7rem;
    color: #9ca3af;
    white-space: nowrap;
}
.options-editor-delete {
    background: none;
    border: none;
    color: #ef4444;
    cursor: pointer;
    font-size: 1rem;
    opacity: 0.5;
}
.options-editor-delete:hover { opacity: 1; }
.options-editor-delete:disabled {
    color: #d1d5db;
    cursor: default;
    opacity: 0.3;
}

/* Dark mode for recipe modals */
.dark .recipe-modal {
    background: #1f2937;
}
.dark .recipe-modal-header {
    border-color: #374151;
}
.dark .recipe-modal-header h3 { color: #e5e7eb; }
.dark .recipe-modal-close { color: #9ca3af; }
.dark .recipe-modal-body { color: #e5e7eb; }
.dark .recipe-modal-footer { border-color: #374151; }
.dark .recipe-list-item:hover { background: #374151; }
.dark .recipe-list-item-name { color: #e5e7eb; }
.dark .metadata-form-group label { color: #d1d5db; }
.dark .metadata-select {
    background: #374151;
    color: #e5e7eb;
    border-color: #4b5563;
}
.dark .metadata-chip { background: #312e81; color: #c7d2fe; }
.dark .cooking-tab { color: #9ca3af; }
.dark .cooking-tab.active { color: #60a5fa; border-bottom-color: #60a5fa; }
.dark .food-prep-prev-day { accent-color: #60a5fa; }
.dark .cooking-step textarea {
    background: #374151;
    color: #e5e7eb;
    border-color: #4b5563;
}
.dark .food-processing-input {
    background: #374151;
    color: #e5e7eb;
    border-color: #4b5563;
}
.dark .food-processing-select {
    background: #374151;
    color: #e5e7eb;
    border-color: #4b5563;
}

/* ============================================================
   料理検索モーダル
   ============================================================ */
.recipe-search-modal {
    display: flex;
    flex-direction: column;
    max-height: 85vh;
    overflow: visible;
}
.recipe-search-input {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font-size: 16px;
    box-sizing: border-box;
}
.recipe-search-filters {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 4px 16px 8px;
    border-bottom: 1px solid #e5e7eb;
    flex-shrink: 0;
    max-height: 30vh;
    overflow-y: auto;
}
.recipe-search-filter-item {
    display: flex;
    align-items: center;
}
.recipe-search-filter-select {
    font-size: 16px;
    padding: 2px 6px;
    border: 1px solid #d1d5db;
    border-radius: 4px;
    background: #fff;
}
.recipe-search-body {
    display: flex;
    flex: 1;
    min-height: 0;
    overflow: auto;
}
.recipe-search-results {
    flex: 1;
    overflow-y: auto;
    border-right: 1px solid #e5e7eb;
}
.recipe-search-item {
    padding: 10px 12px;
    cursor: pointer;
    border-bottom: 1px solid #f3f4f6;
}
.recipe-search-item:hover {
    background: #eff6ff;
}
.recipe-search-item.selected {
    background: #dbeafe;
}
.recipe-search-item-meta {
    font-size: 0.8rem;
    color: #6b7280;
    margin-top: 2px;
}
.recipe-search-preview {
    flex: 1;
    padding: 16px;
    overflow-y: auto;
}
.recipe-preview-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}
.recipe-preview-table th {
    text-align: left;
    padding: 6px 8px;
    border-bottom: 2px solid #e5e7eb;
    font-weight: 600;
    font-size: 12px;
    color: #6b7280;
}
.recipe-preview-table td {
    padding: 4px 8px;
    border-bottom: 1px solid #e5e7eb;
}

/* 料理名セル内検索ボタン */
.recipe-cell-search-btn {
    background: none;
    border: none;
    color: #6b7280;
    cursor: pointer;
    padding: 2px 4px;
    font-size: 12px;
    flex-shrink: 0;
}
.recipe-cell-search-btn:hover {
    color: #2563eb;
}

/* ダークモード */
.dark .recipe-search-input {
    background: #374151;
    color: #e5e7eb;
    border-color: #4b5563;
}
.dark .recipe-search-filter-select {
    background: #374151;
    color: #e5e7eb;
    border-color: #4b5563;
}
.dark .recipe-search-filters {
    border-bottom-color: #4b5563;
}
.dark .recipe-search-results {
    border-right-color: #4b5563;
}
.dark .recipe-search-item {
    border-bottom-color: #374151;
}
.dark .recipe-search-item:hover {
    background: #1e3a5f;
}
.dark .recipe-search-item.selected {
    background: #1e3a5f;
}
.dark .recipe-search-item-meta {
    color: #9ca3af;
}
.dark .recipe-preview-table th {
    border-bottom-color: #4b5563;
    color: #9ca3af;
}
.dark .recipe-preview-table td {
    border-bottom-color: #4b5563;
}
.dark .recipe-cell-search-btn {
    color: #9ca3af;
}
.dark .recipe-cell-search-btn:hover {
    color: #60a5fa;
}

/* === DRI Settings === */
.dri-label-clickable {
    cursor: pointer;
    text-decoration: underline;
    color: #2563eb;
    font-weight: bold;
}
.dri-label-clickable:hover {
    color: #1d4ed8;
}

#nutrition-table thead tr.dri-add-row th {
    text-align: left;
    padding: 4px 6px;
    background: #dbeafe;
    border-bottom: 2px solid #93c5fd;
    border-top: 1px solid #93c5fd;
}
.dri-add-btn {
    cursor: pointer;
    color: #2563eb;
    font-size: 13px;
    font-weight: bold;
    padding: 2px 12px;
    border: 1px dashed #60a5fa;
    border-radius: 4px;
    display: inline-block;
    position: sticky;
    left: 10px;
}
.dri-add-btn:hover {
    color: #1d4ed8;
    background: #bfdbfe;
    border-color: #3b82f6;
}

#nutrition-table thead tr.satisfaction-header-row th {
    font-weight: bold;
    font-size: 12px;
    background: #fefce8;
    border-bottom: 2px solid #9ca3af;
}

/* === DRI Settings Modal === */
.dri-settings-modal {
    background: white;
    border-radius: 8px;
    padding: 20px;
    min-width: 400px;
    max-width: 500px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}
.dri-settings-modal h3 {
    margin: 0 0 16px 0;
    font-size: 16px;
    color: #1f2937;
}
.dri-settings-modal .form-group {
    margin-bottom: 12px;
}
.dri-settings-modal label {
    display: block;
    font-size: 13px;
    font-weight: bold;
    margin-bottom: 4px;
    color: #374151;
}
.dri-settings-modal select {
    width: 100%;
    padding: 6px 8px;
    border: 1px solid #d1d5db;
    border-radius: 4px;
    font-size: 16px;
}
.dri-settings-modal .radio-group {
    display: flex;
    gap: 16px;
}
.dri-settings-modal .radio-group label {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-weight: normal;
    cursor: pointer;
}
.dri-settings-modal .btn-group {
    display: flex;
    gap: 8px;
    margin-top: 16px;
    justify-content: flex-end;
}
.dri-settings-modal .btn {
    padding: 6px 16px;
    border: 1px solid #d1d5db;
    border-radius: 4px;
    cursor: pointer;
    font-size: 13px;
}
.dri-settings-modal .btn-primary {
    background: #2563eb;
    color: white;
    border-color: #2563eb;
}
.dri-settings-modal .btn-danger {
    background: #dc2626;
    color: white;
    border-color: #dc2626;
}
.dri-settings-modal .btn:hover {
    opacity: 0.9;
}

/* DRI Modal Tabs */
.dri-modal-tabs {
    display: flex;
    border-bottom: 2px solid #e5e7eb;
    margin-bottom: 16px;
}
.dri-modal-tab {
    padding: 8px 16px;
    border: none;
    background: none;
    cursor: pointer;
    font-size: 13px;
    color: #6b7280;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    transition: color 0.15s, border-color 0.15s;
}
.dri-modal-tab:hover {
    color: #374151;
}
.dri-modal-tab.active {
    color: #2563eb;
    border-bottom-color: #2563eb;
    font-weight: 600;
}

/* Custom DRI List */
.custom-dri-list {
    max-height: 200px;
    overflow-y: auto;
    margin-bottom: 12px;
}
.custom-dri-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    margin-bottom: 6px;
}
.custom-dri-item:hover {
    background: #f9fafb;
}
.custom-dri-item-name {
    font-weight: 600;
    font-size: 13px;
}
.custom-dri-item-desc {
    font-size: 11px;
    color: #6b7280;
}
.custom-dri-item-actions {
    display: flex;
    gap: 4px;
    flex-shrink: 0;
}

/* Custom DRI Create Form */
.custom-dri-create-form {
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    padding: 12px;
    margin-bottom: 8px;
    background: #f9fafb;
}

/* Custom DRI Edit Table */
.custom-dri-edit-wrapper {
    max-height: 350px;
    overflow-y: auto;
    margin: 8px 0;
    border: 1px solid #e5e7eb;
    border-radius: 4px;
}
.custom-dri-edit-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
}
.custom-dri-edit-table th {
    background: #f3f4f6;
    padding: 4px 8px;
    text-align: left;
    border-bottom: 1px solid #d1d5db;
    position: sticky;
    top: 0;
    z-index: 1;
}
.custom-dri-edit-table td {
    padding: 4px 8px;
    border-bottom: 1px solid #e5e7eb;
}
.custom-dri-edit-table input {
    width: 80px;
    padding: 2px 4px;
    border: 1px solid #d1d5db;
    border-radius: 3px;
    text-align: right;
    font-size: 16px;
}
.custom-dri-edit-table input:focus {
    outline: none;
    border-color: #2563eb;
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.15);
}

/* レスポンシブ: 小画面では上下分割 */
@media (max-width: 768px) {
    .recipe-search-body {
        flex-direction: column;
    }
    .recipe-search-results {
        border-right: none;
        border-bottom: 1px solid #e5e7eb;
        max-height: 40%;
    }
    .dark .recipe-search-results {
        border-bottom-color: #4b5563;
    }
}

/* ============================================================
   Satisfaction Chart Modal (充足率チャート)
   ============================================================ */
.chart-modal {
    background: #fff;
    border-radius: 10px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.18);
    width: 90vw;
    max-width: 900px;
    min-width: 320px;
    max-height: 90vh;
    overflow-y: auto;
    padding: 20px 24px;
    position: relative;
}

.chart-container {
    display: flex;
    gap: 20px;
    align-items: flex-start;
    flex-wrap: wrap;
}

.chart-box {
    flex: 1;
    min-width: 350px;
    background: #fafafa;
    border-radius: 8px;
    padding: 12px;
    border: 1px solid #e5e7eb;
}

.chart-tabs {
    display: flex;
    gap: 4px;
    margin-bottom: 12px;
    border-bottom: 1px solid #e5e7eb;
    padding-bottom: 8px;
    flex-wrap: wrap;
}

.chart-tab {
    padding: 5px 14px;
    font-size: 12px;
    font-weight: 500;
    color: #6b7280;
    background: #f3f4f6;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.15s;
}
.chart-tab:hover {
    background: #e5e7eb;
    color: #374151;
}
.chart-tab-active {
    background: #2563eb;
    color: #fff;
    border-color: #2563eb;
}
.chart-tab-active:hover {
    background: #1d4ed8;
    color: #fff;
}

@media (max-width: 768px) {
    .chart-modal {
        width: 96vw;
        padding: 14px 12px;
    }
    .chart-container {
        flex-direction: column;
    }
    .chart-box {
        min-width: 0;
        width: 100%;
        max-width: none;
    }
}

/* ============================================================
   Advanced Food Search & Food Usage History
   ============================================================ */

/* Search input wrapper with buttons */
.food-search-dropdown .search-input-wrapper {
    display: flex;
    align-items: center;
    gap: 4px;
}

.food-search-dropdown .search-input-wrapper input {
    flex: 1;
    min-width: 0;
}

/* Small icon buttons in search wrapper */
.search-history-btn,
.search-advanced-btn {
    width: 32px;
    height: 32px;
    flex-shrink: 0;
    border: 1px solid #d1d5db;
    border-radius: 4px;
    background: #f9fafb;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    line-height: 1;
    padding: 0;
    transition: background 0.15s, border-color 0.15s;
}
.search-history-btn:hover,
.search-advanced-btn:hover {
    background: #e5e7eb;
    border-color: #9ca3af;
}

/* Recording indicator - red dot */
.search-history-btn.recording-indicator {
    position: relative;
}
.search-history-btn.recording-indicator::after {
    content: '';
    position: absolute;
    top: 2px;
    right: 2px;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #ef4444;
    border: 1px solid #fff;
}

/* Advanced search modal */
.advanced-search-modal {
    background: #fff;
    border-radius: 10px;
    box-shadow: 0 8px 30px rgba(0,0,0,0.2);
    max-width: 550px;
    width: 92%;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Filter layout */
.adv-search-filters {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 12px;
}

.adv-search-row {
    display: flex;
    align-items: center;
    gap: 10px;
}
.adv-search-row label {
    flex-shrink: 0;
    width: 60px;
    font-size: 13px;
    font-weight: 500;
    color: #374151;
    text-align: right;
}

/* Select elements - 16px minimum for iOS */
.adv-search-select {
    flex: 1;
    padding: 6px 10px;
    border: 1px solid #d1d5db;
    border-radius: 4px;
    font-size: 16px;
    background: #fff;
    color: #1f2937;
    box-sizing: border-box;
    min-width: 0;
}
.adv-search-select:focus {
    border-color: #2563eb;
    box-shadow: 0 0 0 2px rgba(37,99,235,0.15);
    outline: none;
}

/* Sort radio buttons */
.adv-search-sort {
    display: flex;
    align-items: center;
    gap: 16px;
    padding-left: 70px;
    font-size: 13px;
    color: #374151;
}
.adv-search-sort label {
    display: flex;
    align-items: center;
    gap: 4px;
    cursor: pointer;
}
.adv-search-sort input[type="radio"] {
    margin: 0;
}

/* Action buttons */
.adv-search-actions {
    display: flex;
    gap: 8px;
    margin-bottom: 12px;
}

.adv-search-btn-primary {
    padding: 6px 20px;
    background: #2563eb;
    color: #fff;
    border: none;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s;
}
.adv-search-btn-primary:hover {
    background: #1d4ed8;
}

.adv-search-btn-secondary {
    padding: 6px 16px;
    background: #f3f4f6;
    color: #374151;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font-size: 14px;
    cursor: pointer;
    transition: background 0.15s;
}
.adv-search-btn-secondary:hover {
    background: #e5e7eb;
}

/* Result count */
.adv-search-result-count {
    font-size: 12px;
    color: #6b7280;
    margin-bottom: 6px;
}

/* Results container (scrollable) */
.adv-search-results {
    max-height: 40vh;
    overflow-y: auto;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
}

/* Nutrient value badge in results */
.nutrient-value-badge {
    flex-shrink: 0;
    font-size: 12px;
    color: #2563eb;
    font-weight: 600;
    padding: 1px 6px;
    background: #eff6ff;
    border-radius: 4px;
    white-space: nowrap;
    margin-left: auto;
}

/* Usage count badge in history results */
.usage-count-badge {
    flex-shrink: 0;
    font-size: 11px;
    color: #6b7280;
    font-weight: 600;
    padding: 1px 6px;
    background: #f3f4f6;
    border-radius: 4px;
    white-space: nowrap;
    margin-left: auto;
}

/* History panel header */
.history-panel-header {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 10px;
    border-bottom: 1px solid #e5e7eb;
    flex-wrap: wrap;
}

/* Preset dropdown in history */
.preset-select {
    padding: 3px 6px;
    border: 1px solid #d1d5db;
    border-radius: 4px;
    font-size: 16px;
    background: #fff;
    color: #1f2937;
    max-width: 140px;
    min-width: 0;
}

/* History action buttons container */
.history-action-btns {
    display: flex;
    gap: 4px;
    margin-left: auto;
}

/* ============================================================
   Dark mode: Advanced Search & History
   ============================================================ */
.dark .search-history-btn,
.dark .search-advanced-btn {
    background: #374151;
    border-color: #4b5563;
    color: #e5e7eb;
}
.dark .search-history-btn:hover,
.dark .search-advanced-btn:hover {
    background: #4b5563;
}

.dark .advanced-search-modal {
    background: #1f2937;
}

.dark .adv-search-row label {
    color: #d1d5db;
}

.dark .adv-search-select {
    background: #374151;
    color: #e5e7eb;
    border-color: #4b5563;
}
.dark .adv-search-select:focus {
    border-color: #60a5fa;
    box-shadow: 0 0 0 2px rgba(96,165,250,0.2);
}

.dark .adv-search-sort {
    color: #d1d5db;
}

.dark .adv-search-btn-primary {
    background: #3b82f6;
}
.dark .adv-search-btn-primary:hover {
    background: #2563eb;
}

.dark .adv-search-btn-secondary {
    background: #374151;
    color: #e5e7eb;
    border-color: #4b5563;
}
.dark .adv-search-btn-secondary:hover {
    background: #4b5563;
}

.dark .adv-search-result-count {
    color: #9ca3af;
}

.dark .adv-search-results {
    border-color: #374151;
}

.dark .nutrient-value-badge {
    background: #1e3a5f;
    color: #93c5fd;
}

.dark .usage-count-badge {
    background: #374151;
    color: #9ca3af;
}

.dark .history-panel-header {
    border-color: #374151;
}

.dark .preset-select {
    background: #374151;
    color: #e5e7eb;
    border-color: #4b5563;
}

.dark .search-history-btn.recording-indicator::after {
    border-color: #1f2937;
}

/* === カスタム成分表モーダル === */
.food-table-settings-modal {
    max-width: 480px;
}

.food-table-radio-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 12px 0;
}

.food-table-radio-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border-radius: 6px;
    cursor: pointer;
    transition: background-color 0.15s;
}

.food-table-radio-item:hover {
    background-color: #f0f4ff;
}

.food-table-radio-item input[type="radio"] {
    margin: 0;
    accent-color: #16a34a;
}

.food-table-radio-item label {
    cursor: pointer;
    font-size: 14px;
    flex: 1;
}

.food-table-radio-item .entry-count {
    color: #6b7280;
    font-size: 12px;
}

.food-table-actions {
    display: flex;
    gap: 8px;
    padding: 12px 0;
    border-top: 1px solid #e5e7eb;
}

.food-table-actions button {
    padding: 6px 16px;
    border-radius: 6px;
    border: 1px solid #d1d5db;
    background: #fff;
    cursor: pointer;
    font-size: 13px;
    transition: all 0.15s;
}

.food-table-actions button:hover {
    background: #f3f4f6;
}

.food-table-actions button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.food-table-actions button.danger {
    color: #dc2626;
    border-color: #fecaca;
}

.food-table-actions button.danger:hover:not(:disabled) {
    background: #fef2f2;
}

/* === 成分表エディタモーダル === */
.food-table-editor-modal {
    max-width: 900px;
    height: 80vh;
}

.food-table-editor-body {
    display: flex;
    gap: 16px;
    flex: 1;
    overflow: hidden;
    padding: 16px;
}

.food-table-editor-search {
    flex: 1;
    display: flex;
    flex-direction: column;
    border-right: 1px solid #e5e7eb;
    padding-right: 16px;
}

.food-table-editor-selected {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.food-table-editor-search input {
    font-size: 16px;  /* iOS auto-zoom prevention */
    padding: 8px 12px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    margin-bottom: 8px;
}

.food-table-editor-search select {
    font-size: 16px;  /* iOS auto-zoom prevention */
    padding: 6px 8px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    margin-bottom: 8px;
}

.food-table-search-results,
.food-table-selected-list {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.food-table-food-item {
    display: flex;
    align-items: center;
    padding: 6px 8px;
    border-bottom: 1px solid #f3f4f6;
    gap: 8px;
    font-size: 13px;
}

.food-table-food-item:hover {
    background-color: #f9fafb;
}

.food-table-food-item .food-num {
    color: #6b7280;
    font-size: 12px;
    min-width: 60px;
    font-variant-numeric: tabular-nums;
}

.food-table-food-item .food-name {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* 右パネル（選択済み）では食品名を折り返し表示 */
.food-table-editor-selected .food-table-food-item .food-name {
    white-space: normal;
    word-break: break-all;
    line-height: 1.4;
}

.food-table-food-item .btn-add-food,
.food-table-food-item .btn-remove-food {
    padding: 2px 10px;
    border-radius: 4px;
    border: 1px solid;
    cursor: pointer;
    font-size: 12px;
    white-space: nowrap;
    transition: all 0.15s;
}

.food-table-food-item .btn-add-food {
    color: #16a34a;
    border-color: #bbf7d0;
    background: #f0fdf4;
}

.food-table-food-item .btn-add-food:hover {
    background: #dcfce7;
}

.food-table-food-item .btn-add-food.added {
    color: #9ca3af;
    border-color: #e5e7eb;
    background: #f9fafb;
    cursor: default;
}

.food-table-food-item .btn-remove-food {
    color: #dc2626;
    border-color: #fecaca;
    background: #fef2f2;
}

.food-table-food-item .btn-remove-food:hover {
    background: #fee2e2;
}

.food-table-selected-header {
    font-size: 14px;
    font-weight: 600;
    padding: 8px 0;
    color: #374151;
    border-bottom: 1px solid #e5e7eb;
    margin-bottom: 8px;
}

.food-table-empty-state {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 200px;
    color: #9ca3af;
    font-size: 14px;
}

/* Active state for 成分表 button */
#btn-food-table-settings.active {
    background: #dcfce7;
    color: #16a34a;
    border-color: #bbf7d0;
}

/* Responsive: tablet */
@media (max-width: 1024px) {
    .food-table-editor-modal {
        max-width: 95vw;
    }
}

/* ============================================================
   Recipe Detail View (1画面表示)
   ============================================================ */

.recipe-detail-overlay {
    position: fixed;
    inset: 0;
    z-index: 10002;
    background: #f8fafc;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.recipe-detail-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 24px;
    background: #1e293b;
    color: #fff;
    position: sticky;
    top: 0;
    z-index: 10;
}

.recipe-detail-header h2 {
    margin: 0;
    font-size: 18px;
    font-weight: 700;
}

.recipe-detail-close {
    background: none;
    border: none;
    color: #fff;
    font-size: 28px;
    cursor: pointer;
    padding: 0 4px;
    line-height: 1;
}

.recipe-detail-content {
    padding: 16px 24px 40px;
    max-width: 1400px;
    margin: 0 auto;
}

.recipe-detail-grid {
    display: grid;
    grid-template-columns: 300px 1fr;
    gap: 16px;
    margin-bottom: 16px;
}

.recipe-detail-section {
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    margin-bottom: 12px;
}

.recipe-detail-section-title {
    font-size: 15px;
    font-weight: 700;
    color: #1e293b;
    padding: 10px 16px;
    cursor: pointer;
    user-select: none;
    list-style: none;
}

.recipe-detail-section-title::before {
    content: '▶ ';
    font-size: 11px;
    color: #94a3b8;
}

.recipe-detail-section[open] > .recipe-detail-section-title::before {
    content: '▼ ';
}

.recipe-detail-section-body {
    padding: 0 16px 12px;
}

.recipe-detail-meta-row {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 6px 0;
    border-bottom: 1px solid #f1f5f9;
}

.recipe-detail-meta-row:last-child {
    border-bottom: none;
}

.recipe-detail-meta-label {
    font-size: 13px;
    font-weight: 600;
    color: #64748b;
    min-width: 100px;
    flex-shrink: 0;
}

.recipe-detail-meta-value {
    font-size: 13px;
    color: #1e293b;
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}

.recipe-detail-chip {
    display: inline-block;
    background: #e0f2fe;
    color: #0369a1;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 12px;
}

.recipe-detail-comment-text {
    font-size: 14px;
    color: #334155;
    white-space: pre-wrap;
    line-height: 1.6;
}

/* Foods Table */
.recipe-detail-foods-wrapper {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.recipe-detail-foods-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
    white-space: nowrap;
}

.recipe-detail-foods-table th,
.recipe-detail-foods-table td {
    padding: 6px 10px;
    border: 1px solid #e2e8f0;
    text-align: left;
}

.recipe-detail-foods-table th {
    background: #f1f5f9;
    font-weight: 600;
    color: #475569;
    position: sticky;
    top: 0;
    z-index: 2;
}

.recipe-detail-foods-table .sticky-col {
    position: sticky;
    left: 0;
    background: #fff;
    z-index: 1;
    min-width: 120px;
}

.recipe-detail-foods-table th.sticky-col {
    z-index: 3;
    background: #f1f5f9;
}

.recipe-detail-foods-table .sticky-col-2 {
    position: sticky;
    left: 120px;
    background: #fff;
    z-index: 1;
}

.recipe-detail-foods-table th.sticky-col-2 {
    z-index: 3;
    background: #f1f5f9;
}

.recipe-detail-subtotal .sticky-col-2 {
    background: #fefce8;
}

.recipe-detail-foods-table td.numeric {
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.recipe-detail-subtotal td {
    font-weight: 700;
    background: #fefce8;
    border-top: 2px solid #1e293b;
}

/* Cooking instructions */
.recipe-detail-cooking-subtitle {
    font-size: 14px;
    font-weight: 700;
    color: #334155;
    margin: 12px 0 6px;
    padding-bottom: 4px;
    border-bottom: 1px solid #e2e8f0;
}

.recipe-detail-cooking-subtitle:first-child {
    margin-top: 0;
}

.recipe-detail-cooking-list {
    margin: 4px 0 8px;
    padding-left: 20px;
    font-size: 13px;
    color: #334155;
    line-height: 1.7;
}

.recipe-detail-cooking-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
    margin-bottom: 8px;
    table-layout: auto;
}

.recipe-detail-cooking-table th,
.recipe-detail-cooking-table td {
    padding: 6px 10px;
    border: 1px solid #e2e8f0;
    text-align: left;
    vertical-align: top;
}

.recipe-detail-cooking-table th {
    background: #f1f5f9;
    font-weight: 600;
    color: #475569;
    white-space: nowrap;
}

.recipe-detail-cooking-table td:first-child {
    width: 1%;
    white-space: nowrap;
    font-weight: 500;
}

/* Desktop: show table, hide cards */
.recipe-detail-cooking-desktop { display: block; }
.recipe-detail-cooking-mobile { display: none; }

/* Card style (used on mobile) */
.recipe-detail-cooking-card {
    padding: 8px 12px;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    margin-bottom: 6px;
}

.recipe-detail-cooking-card-name {
    font-weight: 600;
    font-size: 13px;
    color: #1e293b;
}

.recipe-detail-cooking-card-content {
    font-size: 13px;
    color: #475569;
    margin-top: 2px;
}

.recipe-detail-badge {
    display: inline-block;
    background: #fef3c7;
    color: #92400e;
    padding: 1px 6px;
    border-radius: 4px;
    font-size: 11px;
    margin-left: 6px;
}

.recipe-detail-food-group {
    border-left: 4px solid #FFF3CD;
    padding: 6px 0 6px 12px;
    margin: 8px 0;
}

.recipe-detail-food-group-label {
    font-weight: 600;
    font-size: 13px;
    color: #475569;
    margin-bottom: 4px;
}

/* ============================================================
   Compare Panel - Split View
   ============================================================ */

/* Workspace: wraps main spreadsheet + compare panel */
#sheet-workspace {
    display: flex;
    flex: 1;
    overflow: hidden;
    min-height: 0;
}

/* Default: single sheet fills workspace */
#sheet-workspace #spreadsheet-container {
    flex: 1;
    min-width: 0;
}

/* Horizontal split (side by side) */
#sheet-workspace.split-horizontal {
    flex-direction: row;
}

#sheet-workspace.split-horizontal #spreadsheet-container {
    flex: 1;
    min-width: 0;
    border-right: 3px solid #e5e7eb;
}

#sheet-workspace.split-horizontal #compare-panel {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

/* Vertical split (stacked) */
#sheet-workspace.split-vertical {
    flex-direction: column;
}

#sheet-workspace.split-vertical #spreadsheet-container {
    flex: 1;
    min-height: 0;
    border-bottom: 3px solid #e5e7eb;
}

#sheet-workspace.split-vertical #compare-panel {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

/* Compare Panel Header */
.compare-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 4px 8px;
    background: #f0f4ff;
    border-bottom: 1px solid #c7d2fe;
    flex-shrink: 0;
    min-height: 32px;
}

.compare-sheet-name {
    font-weight: 600;
    font-size: 13px;
    color: #1e40af;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
}

.compare-panel-actions {
    display: flex;
    gap: 4px;
    flex-shrink: 0;
}

.compare-btn {
    background: none;
    border: 1px solid transparent;
    border-radius: 4px;
    padding: 4px 6px;
    cursor: pointer;
    color: #4b5563;
    font-size: 13px;
    line-height: 1;
}

.compare-btn:hover {
    background: #e0e7ff;
    border-color: #a5b4fc;
    color: #1e40af;
}

.compare-btn.active {
    background: #c7d2fe;
    border-color: #818cf8;
    color: #1e3a8a;
}

/* Compare Table Container */
.compare-table-container {
    flex: 1;
    overflow: auto;
    min-height: 0;
}

/* Compare Table - reuse main table styling */
.compare-table {
    border-collapse: collapse;
    width: max-content;
    min-width: 100%;
    font-size: 13px;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

.compare-table thead {
    position: sticky;
    top: 0;
    z-index: 10;
}

.compare-table thead th {
    background: #f0f0f0;
    border: 1px solid #c0c0c0;
    padding: 4px 6px;
    font-weight: 600;
    font-size: 12px;
    text-align: center;
    white-space: nowrap;
    color: #333;
    user-select: none;
    min-width: 60px;
}

.compare-table thead th.nutrient-col {
    min-width: 70px;
    max-width: 100px;
}

.compare-table thead tr.unit-row th {
    background: #e8e8e8;
    font-weight: 400;
    font-size: 11px;
    color: #666;
    padding: 2px 6px;
}

.compare-table tbody td {
    border: 1px solid #d1d5db;
    padding: 2px 4px;
    height: 26px;
    vertical-align: middle;
    background: #fff;
    color: #1f2937;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.compare-table tbody td.numeric {
    text-align: right;
    padding-right: 6px;
    font-variant-numeric: tabular-nums;
}

.compare-table tbody td.food-name {
    min-width: 180px;
    max-width: 250px;
}

.compare-table tbody td.weight-col {
    min-width: 60px;
    width: 70px;
}

.compare-table tbody td.meal-type {
    min-width: 70px;
    width: 80px;
}

.compare-table tbody td.recipe-name {
    min-width: 120px;
    max-width: 180px;
}

/* Aggregation rows in compare table */
.compare-table tbody tr.subtotal-recipe td {
    background-color: #cce5ff;
    font-weight: 600;
    border-color: #b3d4fc;
}

.compare-table tbody tr.subtotal-meal td {
    background-color: #ffe6cc;
    font-weight: 600;
    border-color: #ffd4a8;
}

.compare-table tbody tr.subtotal-grand td {
    background-color: #ffccff;
    font-weight: 700;
    border-color: #e6b3e6;
}

/* Sheet picker modal */
.compare-sheet-picker-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.compare-sheet-picker {
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.2);
    width: min(400px, 90vw);
    max-height: 70vh;
    display: flex;
    flex-direction: column;
}

.compare-sheet-picker-header {
    padding: 16px 20px 12px;
    border-bottom: 1px solid #e5e7eb;
    font-weight: 600;
    font-size: 15px;
    color: #1f2937;
}

.compare-sheet-picker-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px 0;
}

.compare-sheet-picker-item {
    padding: 10px 20px;
    cursor: pointer;
    border-bottom: 1px solid #f3f4f6;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.compare-sheet-picker-item:hover {
    background: #eff6ff;
}

.compare-sheet-picker-item-name {
    font-size: 14px;
    color: #1f2937;
    font-weight: 500;
}

.compare-sheet-picker-item-date {
    font-size: 11px;
    color: #9ca3af;
}

.compare-sheet-picker-empty {
    padding: 20px;
    text-align: center;
    color: #9ca3af;
    font-size: 14px;
}

.compare-sheet-picker-footer {
    padding: 12px 20px;
    border-top: 1px solid #e5e7eb;
    text-align: right;
}

.compare-sheet-picker-cancel {
    background: #f3f4f6;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    padding: 6px 16px;
    cursor: pointer;
    font-size: 13px;
    color: #374151;
}

.compare-sheet-picker-cancel:hover {
    background: #e5e7eb;
}
