/* ========================================
   お買い物リスト スタイル（スマホ最適化）
======================================== */

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Sans",
                 "Hiragino Kaku Gothic ProN", Meiryo, sans-serif;
    background: linear-gradient(135deg, #fef9f3 0%, #f3f9ff 100%);
    color: #333;
    line-height: 1.6;
    min-height: 100vh;
    /* iOS Safe Area + 下部固定フォーム分の余白 */
    padding:
        max(env(safe-area-inset-top), 16px)
        max(env(safe-area-inset-right), 12px)
        calc(env(safe-area-inset-bottom) + 96px)
        max(env(safe-area-inset-left), 12px);
}

.container {
    max-width: 720px;
    margin: 0 auto;
    background: #fff;
    border-radius: 18px;
    box-shadow: 0 4px 20px rgba(0, 135, 212, 0.08);
    padding: 20px;
}

/* ============ ヘッダー ============ */
header {
    text-align: center;
    margin-bottom: 16px;
    padding-bottom: 14px;
    border-bottom: 3px dashed #ffd984;
}

h1 {
    color: #0087d4;
    font-size: 1.5rem;
}

/* ============ モード切替 ============ */
.mode-switch {
    display: flex;
    background: #f0f4f8;
    border-radius: 12px;
    padding: 4px;
    margin-bottom: 14px;
    gap: 4px;
}

.mode-btn {
    flex: 1;
    padding: 12px;
    border: none;
    background: transparent;
    color: #678;
    font-size: 1rem;
    font-weight: 600;
    border-radius: 9px;
    cursor: pointer;
    transition: all 0.2s;
    min-height: 44px;
}

.mode-btn.active {
    background: #fff;
    color: #0087d4;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
}

/* ============ ツールバー ============ */
.toolbar {
    display: flex;
    gap: 8px;
    align-items: center;
    margin-bottom: 12px;
    flex-wrap: wrap;
}

.counter {
    margin-left: auto;
    color: #678;
    font-size: 0.9rem;
    font-weight: 500;
}

/* ============ ボタン共通 ============ */
.btn {
    padding: 10px 16px;
    border: none;
    border-radius: 10px;
    font-size: 0.95rem;
    cursor: pointer;
    transition: transform 0.1s, box-shadow 0.2s, background 0.2s;
    font-weight: 600;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.btn:active {
    transform: scale(0.97);
}

.btn-primary {
    background: #ffb84d;
    color: #fff;
}

.btn-primary:hover {
    background: #ffa726;
}

.btn-ghost {
    background: #fff;
    color: #0087d4;
    border: 2px solid #cce6f5;
}

.btn-ghost:hover {
    background: #e8f4fc;
}

.btn-danger {
    background: transparent;
    color: #d43f3f;
    border: none;
    font-size: 1.1rem;
}

/* ============ フィルタバー ============ */
.filter-bar {
    display: flex;
    gap: 8px;
    margin-bottom: 12px;
    flex-wrap: wrap;
}

.filter-btn {
    padding: 8px 14px;
    border: 2px solid #cce6f5;
    background: #fff;
    color: #0087d4;
    border-radius: 20px;
    cursor: pointer;
    font-size: 0.9rem;
    transition: all 0.2s;
    min-height: 36px;
}

.filter-btn.active {
    background: #0087d4;
    color: #fff;
    border-color: #0087d4;
}

/* ============ モード説明 ============ */
.mode-hint {
    color: #678;
    font-size: 0.85rem;
    margin-bottom: 10px;
    padding: 8px 12px;
    background: #f0f8ff;
    border-radius: 8px;
    border-left: 3px solid #0087d4;
}

/* ============ リスト本体 ============ */
.item-list {
    list-style: none;
}

.item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 14px;
    background: #fafafa;
    border-radius: 12px;
    margin-bottom: 8px;
    transition: background 0.2s;
    animation: fadeIn 0.25s;
    min-height: 56px;
}

.item:hover {
    background: #f3f3f3;
}

/* 在庫確認モードでチェック済（在庫あり） */
.item.in-stock {
    background: #f0f0f0;
    opacity: 0.55;
}
.item.in-stock .item-name {
    text-decoration: line-through;
}

/* 買い物モードでチェック済（カゴ済） */
.item.purchased {
    background: #f0f8e8;
}
.item.purchased .item-name {
    text-decoration: line-through;
    color: #888;
}

/* 臨時追加マーカー */
.item.temp .item-name::before {
    content: "✨ ";
    font-size: 0.8em;
}

.item-checkbox {
    width: 28px;
    height: 28px;
    cursor: pointer;
    accent-color: #0087d4;
    flex-shrink: 0;
}

.mode-shop .item-checkbox {
    accent-color: #2a9d2a;
}

.item-content {
    flex: 1;
    min-width: 0;
}

.item-name {
    font-size: 1.05rem;
    font-weight: 500;
    word-break: break-word;
}

.item-note {
    font-size: 0.85rem;
    color: #888;
    margin-top: 2px;
    word-break: break-word;
}

.item-delete {
    background: transparent;
    border: none;
    color: #c44;
    font-size: 1.4rem;
    cursor: pointer;
    padding: 8px 10px;
    border-radius: 8px;
    transition: background 0.2s;
    flex-shrink: 0;
    min-width: 44px;
    min-height: 44px;
}

.item-delete:hover {
    background: #ffe8e8;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(-4px); }
    to { opacity: 1; transform: translateY(0); }
}

.empty-message {
    text-align: center;
    color: #aaa;
    padding: 40px 20px;
    font-size: 1rem;
}

/* ============ フッター ============ */
footer {
    margin-top: 20px;
    padding-top: 16px;
    border-top: 1px solid #eee;
    text-align: center;
    color: #aaa;
    font-size: 0.8rem;
}

/* ============ 下部固定: 臨時追加 ============ */
.add-bar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border-top: 1px solid #e8e8e8;
    padding: 10px 12px calc(env(safe-area-inset-bottom) + 10px);
    z-index: 100;
}

.add-form-row {
    display: flex;
    gap: 6px;
    max-width: 720px;
    margin: 0 auto;
}

.add-form-row input[type="text"] {
    flex: 1;
    min-width: 0;
    padding: 10px 12px;
    border: 2px solid #ffd984;
    border-radius: 10px;
    /* iOSでズームされない最低 16px */
    font-size: 16px;
    background: #fff;
    transition: border-color 0.2s;
}

.add-form-row input[type="text"]:focus {
    outline: none;
    border-color: #ffb84d;
}

.add-form-row #itemName {
    flex: 2;
}

.add-form-row .btn-primary {
    padding: 10px 16px;
    font-size: 1.3rem;
    flex-shrink: 0;
    min-width: 56px;
}

/* ============ モーダル ============ */
.modal {
    position: fixed;
    inset: 0;
    z-index: 200;
    display: none;
}

.modal.open {
    display: block;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    animation: fadeIn 0.2s;
}

.modal-panel {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    width: calc(100% - 24px);
    max-width: 600px;
    max-height: calc(100vh - 40px);
    background: #fff;
    border-radius: 18px;
    padding: 18px;
    overflow-y: auto;
    animation: slideUp 0.25s;
    display: flex;
    flex-direction: column;
}

@keyframes slideUp {
    from { opacity: 0; transform: translate(-50%, -45%); }
    to   { opacity: 1; transform: translate(-50%, -50%); }
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
    padding-bottom: 10px;
    border-bottom: 2px dashed #ffd984;
}

.modal-header h2 {
    font-size: 1.25rem;
    color: #0087d4;
}

.modal-close {
    background: transparent;
    border: none;
    font-size: 1.8rem;
    color: #888;
    cursor: pointer;
    padding: 0 8px;
    min-width: 44px;
    min-height: 44px;
    border-radius: 8px;
}

.modal-close:hover {
    background: #f0f0f0;
}

.modal-hint {
    color: #678;
    font-size: 0.82rem;
    margin-bottom: 10px;
}

.master-list {
    list-style: none;
    flex: 1;
    overflow-y: auto;
    padding: 2px;
    margin-bottom: 12px;
}

.master-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px;
    background: #fafafa;
    border-radius: 10px;
    margin-bottom: 6px;
    min-height: 52px;
}

.master-item.dragging {
    opacity: 0.6;
    background: #fff8e7;
}

.drag-handle {
    color: #aaa;
    font-size: 1.2rem;
    cursor: grab;
    padding: 4px 8px;
    user-select: none;
    touch-action: none;
    min-width: 36px;
    text-align: center;
}

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

.master-fields {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 0;
}

.master-fields input[type="text"] {
    padding: 6px 8px;
    border: 1px solid #e0e0e0;
    border-radius: 6px;
    font-size: 16px;
    background: #fff;
    width: 100%;
}

.master-fields input[type="text"]:focus {
    outline: none;
    border-color: #ffb84d;
}

.master-fields .master-name-input {
    font-weight: 600;
}

.master-fields .master-note-input {
    font-size: 14px;
    color: #666;
}

.master-add {
    display: flex;
    gap: 6px;
    border-top: 1px solid #eee;
    padding-top: 12px;
    flex-wrap: wrap;
}

.master-add input[type="text"] {
    flex: 1;
    min-width: 120px;
    padding: 10px 12px;
    border: 2px solid #ffd984;
    border-radius: 10px;
    font-size: 16px;
}

.master-add input[type="text"]:focus {
    outline: none;
    border-color: #ffb84d;
}

/* ============ トースト ============ */
.toast {
    position: fixed;
    bottom: calc(env(safe-area-inset-bottom) + 90px);
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: #333;
    color: #fff;
    padding: 12px 22px;
    border-radius: 24px;
    font-size: 0.9rem;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    opacity: 0;
    transition: all 0.3s;
    pointer-events: none;
    z-index: 1000;
    max-width: 90%;
    text-align: center;
}

.toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

.toast.error { background: #d43f3f; }
.toast.success { background: #2a9d2a; }

/* ============ レスポンシブ調整 ============ */
@media (min-width: 600px) {
    .container { padding: 28px; }
    h1 { font-size: 1.8rem; }
}

@media (max-width: 380px) {
    .toolbar .btn-ghost {
        padding: 10px 12px;
        font-size: 0.85rem;
    }
    .filter-btn {
        padding: 6px 10px;
        font-size: 0.82rem;
    }
}
