/* Apply border-box sizing to all elements */
*, *::before, *::after {
    box-sizing: border-box;
}

.shopping-page {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    /* Better mobile scrolling */
    -webkit-overflow-scrolling: touch;
}

.container {
    width: 100%;
    padding: 1em;
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    max-height: calc(100vh - 60px);
}

.header {
    margin-bottom: 1em;
    flex-shrink: 0;
}

.header h1 {
    color: white;
    font-size: 2em;
    margin: 0;
}

.main-layout {
    display: flex;
    gap: 1em;
    flex: 1;
    overflow: hidden;
    min-height: 0; /* Important for flex children */
}

.sidebar {
    width: 280px;
    background: white;
    border-radius: 12px;
    padding: 1.5em;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-width: 280px; /* Prevent squishing */
}

.sidebar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1em;
    flex-shrink: 0;
}

.sidebar-header h2 {
    margin: 0;
    font-size: 1.3em;
    color: #2c3e50;
}

.list-menu {
    list-style: none;
    padding: 0;
    margin: 0;
    overflow-y: auto;
    flex: 1;
    -webkit-overflow-scrolling: touch;
}

.list-menu-item {
    padding: 0.75em 1em;
    margin-bottom: 0.5em;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
    border: 2px solid transparent;
    /* Ensure minimum tap target */
    min-height: 44px;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.list-menu-item:hover {
    background: #f8f9fa;
}

.list-menu-item.active {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border-color: #667eea;
}

.list-menu-item-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: 600;
    margin-bottom: 0.25em;
}

.list-menu-item-stats {
    font-size: 0.85em;
    opacity: 0.8;
}

.content {
    flex: 1;
    background: white;
    border-radius: 12px;
    padding: 1.5em;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.mobile-back {
    display: none;
    margin-bottom: 1em;
}

.content-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 1em;
    flex-shrink: 0;
}

.title-section h2 {
    margin: 0 0 0.5em 0;
    color: #2c3e50;
    font-size: 1.5em;
}

.list-stats {
    display: flex;
    gap: 1.5em;
    font-size: 0.9em;
    color: #7f8c8d;
}

.list-stats .stat {
    display: flex;
    align-items: center;
    gap: 0.25em;
}

.content-actions {
    display: flex;
    gap: 0.5em;
}

.content-scroll {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    display: flex;
    flex-direction: column;
}

.toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75em;
    background: #f8f9fa;
    border-radius: 8px;
    margin-bottom: 1em;
    gap: 0.75em;
}

.toolbar-left, .toolbar-right {
    display: flex;
    gap: 0.75em;
    align-items: center;
    flex-wrap: wrap;
}

.btn-icon {
    padding: 0.6em 1em;
    font-size: 0.85em;
    background: white;
    border: 2px solid #ecf0f1;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
    font-weight: 500;
    color: #2c3e50;
}

.btn-icon:hover {
    border-color: #667eea;
    background: #f8f9fa;
}

.view-toggle {
    display: flex;
    align-items: center;
    gap: 0.5em;
    cursor: pointer;
    font-size: 0.85em;
    padding: 0.4em 0.8em;
    background: white;
    border-radius: 6px;
    border: 2px solid #ecf0f1;
    white-space: nowrap;
}

.view-toggle input[type="checkbox"] {
    cursor: pointer;
}

#content-area {
    flex: 1;
    min-height: 0;
}

.items-grid {
    display: grid;
    gap: 0.75em;
    padding-bottom: 1em;
}

.item-card {
    background: white;
    border: 2px solid #ecf0f1;
    border-radius: 8px;
    padding: 0.75em;
    display: flex;
    align-items: center;
    gap: 0.75em;
    transition: all 0.2s;
}

.item-card:hover {
    border-color: #667eea;
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.1);
}

.item-card.checked {
    background: #f8f9fa;
    opacity: 0.7;
}

.item-card.checked .item-name {
    text-decoration: line-through;
}

.item-checkbox {
    width: 24px;
    height: 24px;
    cursor: pointer;
    flex-shrink: 0;
}

.item-details {
    flex: 1;
}

.item-header {
    display: flex;
    justify-content: space-between;
    align-items: start;
    margin-bottom: 0.5em;
}

.item-name {
    font-weight: 600;
    font-size: 1.1em;
    color: #2c3e50;
}

.item-priority {
    display: inline-block;
    padding: 0.25em 0.75em;
    border-radius: 12px;
    font-size: 0.75em;
    font-weight: 600;
    text-transform: uppercase;
}

.item-priority.urgent {
    background: #e74c3c;
    color: white;
}

.item-priority.high {
    background: #e67e22;
    color: white;
}

.item-priority.low {
    background: #95a5a6;
    color: white;
}

.item-priority.optional {
    background: #ecf0f1;
    color: #7f8c8d;
}

.item-meta {
    display: flex;
    gap: 1.5em;
    font-size: 0.9em;
    color: #7f8c8d;
    flex-wrap: wrap;
}

.item-meta span {
    display: flex;
    align-items: center;
    gap: 0.25em;
}

.item-brand {
    font-style: italic;
}

.item-actions {
    display: flex;
    gap: 0.5em;
}

.btn-small-icon {
    padding: 0.5em;
    background: transparent;
    border: none;
    cursor: pointer;
    font-size: 1.2em;
    opacity: 0.5;
    transition: opacity 0.2s;
}

.btn-small-icon:hover {
    opacity: 1;
}

.store-group {
    margin-bottom: 1.5em;
}

.store-group-header {
    display: flex;
    align-items: center;
    gap: 0.75em;
    padding: 0.6em 1em;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border-radius: 8px;
    margin-bottom: 0.75em;
    font-weight: 600;
    font-size: 1em;
}

.empty-state {
    text-align: center;
    padding: 4em 2em;
    color: #95a5a6;
}

.empty-state-icon {
    font-size: 4em;
    margin-bottom: 0.5em;
}

.empty-state-text {
    font-size: 1.2em;
}

.loading {
    text-align: center;
    padding: 2em;
    color: #95a5a6;
}

/* Buttons */
.btn {
    padding: 0.75em 1.5em;
    border: none;
    border-radius: 8px;
    font-size: 1em;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    /* Ensure minimum tap target size */
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.btn-primary {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

.btn-secondary {
    background: #ecf0f1;
    color: #2c3e50;
}

.btn-secondary:hover {
    background: #bdc3c7;
}

.btn-success {
    background: #27ae60;
    color: white;
}

.btn-success:hover {
    background: #229954;
}

.btn-danger {
    background: #e74c3c;
    color: white;
}

.btn-danger:hover {
    background: #c0392b;
}

.btn-small {
    padding: 0.5em 1em;
    font-size: 0.9em;
}

/* Forms */
.form-group {
    margin-bottom: 1em;
}

.form-group label {
    display: block;
    margin-bottom: 0.4em;
    font-weight: 600;
    color: #2c3e50;
    font-size: 0.9em;
}

.form-input {
    width: 100%;
    padding: 0.6em;
    border: 2px solid #ecf0f1;
    border-radius: 8px;
    font-size: 0.95em;
    transition: border-color 0.2s;
}

.form-input:focus {
    outline: none;
    border-color: #667eea;
}

.form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 0.75em;
}

.form-actions {
    display: flex;
    justify-content: flex-end;
    gap: 1em;
    margin-top: 1.5em;
    padding-top: 1em;
    border-top: 1px solid #ecf0f1;
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    align-items: center;
    justify-content: center;
}

.modal.active {
    display: flex;
}

.modal-content {
    background: white;
    border-radius: 12px;
    padding: 1.5em;
    max-width: 600px;
    width: 90%;
    max-height: calc(100vh - 120px);
    overflow-y: auto;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1em;
}

.modal-header h3 {
    margin: 0;
    color: #2c3e50;
    font-size: 1.3em;
}

.modal-close {
    background: none;
    border: none;
    font-size: 2em;
    cursor: pointer;
    color: #95a5a6;
    line-height: 1;
}

.modal-close:hover {
    color: #2c3e50;
}

/* Recipe Selector Styles */
.recipe-card {
    padding: 1em;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    margin-bottom: 0.75em;
    cursor: pointer;
    transition: all 0.2s;
}

.recipe-card:hover {
    border-color: #667eea;
    background: #f8f9fa;
}

.recipe-card.selected {
    border-color: #667eea;
    background: #e8eaf6;
}

.recipe-card h4 {
    margin: 0 0 0.3em 0;
    color: #2c3e50;
    font-size: 1.1em;
}

.recipe-card p {
    margin: 0;
    color: #7f8c8d;
    font-size: 0.9em;
}

.recipe-card-meta {
    display: flex;
    gap: 1em;
    margin-top: 0.5em;
    font-size: 0.85em;
    color: #95a5a6;
}

.recipe-card-meta span {
    display: flex;
    align-items: center;
    gap: 0.3em;
}

#recipe-details h4 {
    font-size: 1.2em;
}

#recipe-details h5 {
    font-size: 1em;
}

.empty-recipes {
    text-align: center;
    padding: 2em;
    color: #95a5a6;
}

/* Mobile */
@media (max-width: 768px) {
    .shopping-page {
        padding: 0;
    }

    .container {
        padding: 0.5em;
    }

    .header {
        margin-bottom: 0.75em;
    }

    .header h1 {
        font-size: 1.5em;
    }

    .main-layout {
        flex-direction: column;
        gap: 0;
    }

    .sidebar {
        width: 100%;
        padding: 1em;
        border-radius: 8px;
    }

    .sidebar-header h2 {
        font-size: 1.1em;
    }

    .list-menu-item {
        padding: 0.6em 0.8em;
        margin-bottom: 0.4em;
    }

    .mobile-back {
        display: block;
        margin-bottom: 0.75em;
    }

    .sidebar.mobile-hidden {
        display: none;
    }

    .content.mobile-hidden {
        display: none;
    }

    .content {
        padding: 1em;
        border-radius: 8px;
    }

    .content-header {
        flex-direction: column;
        gap: 1em;
        margin-bottom: 0.75em;
    }

    .title-section h2 {
        font-size: 1.3em;
        margin: 0 0 0.4em 0;
    }

    .list-stats {
        flex-wrap: wrap;
        gap: 0.75em;
        font-size: 0.85em;
    }

    .content-actions {
        width: 100%;
        flex-wrap: wrap;
        justify-content: flex-start;
    }

    .content-actions .btn-small {
        flex: 1;
        min-width: 120px;
        text-align: center;
        padding: 0.6em 0.75em;
        font-size: 0.85em;
    }

    .toolbar {
        flex-direction: column;
        gap: 0.5em;
        padding: 0.6em;
    }

    .toolbar-left, .toolbar-right {
        width: 100%;
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 0.5em;
    }

    .btn-icon {
        padding: 0.65em 0.5em;
        font-size: 0.8em;
        text-align: center;
        white-space: nowrap;
        min-width: 0;
    }

    .view-toggle {
        justify-content: center;
        padding: 0.6em;
        font-size: 0.85em;
    }

    .btn-success {
        grid-column: 1 / -1;
        padding: 0.75em;
        font-size: 0.95em;
    }

    /* Item cards - optimized for mobile */
    .item-card {
        padding: 0.75em;
        gap: 0.6em;
        flex-wrap: wrap;
    }

    .item-checkbox {
        width: 28px;
        height: 28px;
        flex-shrink: 0;
    }

    .item-details {
        flex: 1;
        min-width: 0;
    }

    .item-header {
        flex-direction: column;
        gap: 0.4em;
        margin-bottom: 0.4em;
        align-items: flex-start;
    }

    .item-name {
        font-size: 1em;
        word-break: break-word;
    }

    .item-priority {
        font-size: 0.7em;
        padding: 0.2em 0.6em;
    }

    .item-meta {
        flex-direction: column;
        gap: 0.4em;
        font-size: 0.85em;
    }

    .item-actions {
        width: 100%;
        justify-content: flex-end;
        gap: 0.4em;
    }

    .btn-small-icon {
        font-size: 1.4em;
        padding: 0.4em;
    }

    .store-group-header {
        padding: 0.5em 0.75em;
        font-size: 0.95em;
        gap: 0.5em;
    }

    .form-row {
        grid-template-columns: 1fr;
    }

    /* Modal adjustments for mobile */
    .modal-content {
        width: 95%;
        max-width: 95%;
        margin: 0.5em;
        border-radius: 8px;
    }

    .modal-header h3 {
        font-size: 1.1em;
    }

    .form-actions {
        flex-direction: column-reverse;
        gap: 0.5em;
    }

    .form-actions .btn {
        width: 100%;
    }

    /* Empty state */
    .empty-state {
        padding: 3em 1em;
    }

    .empty-state-icon {
        font-size: 3em;
    }

    .empty-state-text {
        font-size: 1em;
    }
}

/* Extra small screens (phones in portrait) */
@media (max-width: 480px) {
    .container {
        padding: 0.25em;
    }

    .header h1 {
        font-size: 1.3em;
    }

    .sidebar, .content {
        padding: 0.75em;
    }

    .content-header {
        gap: 0.75em;
    }

    .title-section h2 {
        font-size: 1.1em;
    }

    .list-stats {
        font-size: 0.8em;
        gap: 0.5em;
    }

    .content-actions .btn-small {
        font-size: 0.8em;
        padding: 0.5em 0.6em;
        min-width: 100px;
    }

    .item-card {
        padding: 0.6em;
    }

    .item-name {
        font-size: 0.95em;
    }

    .item-meta {
        font-size: 0.8em;
    }

    .btn-icon {
        font-size: 0.75em;
        padding: 0.6em 0.4em;
    }
}
