﻿*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --bg: #f0ede8;
    --surface: #faf9f7;
    --surface-2: #f0ede8;
    --border: #e2ddd6;
    --text-primary: #1a1814;
    --text-secondary: #6b6560;
    --text-muted: #a09990;
    --accent: #2d6a4f;
    --accent-light: #d8f3dc;
    --accent-hover: #1b4332;
    --danger: #c0392b;
    --danger-light: #fdecea;
    --warning: #e67e22;
    --checked-bg: #f5f5f3;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.06);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
    --radius: 10px;
    --radius-sm: 6px;
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

body {
    font-family: 'DM Sans', sans-serif;
    background-color: var(--bg);
    color: var(--text-primary);
    min-height: 100vh;
    padding: 24px 16px calc(80px + var(--safe-bottom)) 16px;
    display: flex;
    justify-content: center;
    -webkit-text-size-adjust: 100%;
}

.container {
    width: 100%;
    max-width: 640px;
}

.header {
    margin-bottom: 20px;
}

    .header h1 {
        font-family: 'DM Serif Display', serif;
        font-size: 2rem;
        font-weight: 400;
        letter-spacing: -0.02em;
        line-height: 1.1;
    }

        .header h1 span {
            color: var(--accent);
        }

.counter-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 8px;
    flex-wrap: wrap;
}

.counter-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: var(--accent);
    color: white;
    font-size: 0.78rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    padding: 4px 10px;
    border-radius: 20px;
}

    .counter-badge.cost {
        background: var(--text-secondary);
    }

    .counter-badge .dot {
        width: 6px;
        height: 6px;
        background: rgba(255,255,255,0.6);
        border-radius: 50%;
    }

.mode-switcher {
    display: flex;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 4px;
    margin-bottom: 16px;
    gap: 2px;
    width: 100%;
}

    .mode-switcher button {
        flex: 1;
        padding: 10px 18px;
        border: none;
        background: transparent;
        border-radius: calc(var(--radius) - 2px);
        cursor: pointer;
        font-family: 'DM Sans', sans-serif;
        font-size: 0.92rem;
        font-weight: 500;
        color: var(--text-secondary);
        transition: all 0.18s ease;
        min-height: 44px;
        touch-action: manipulation;
    }

        .mode-switcher button:hover {
            color: var(--text-primary);
            background: var(--surface-2);
        }

        .mode-switcher button.active {
            background: var(--accent);
            color: white;
            font-weight: 600;
            box-shadow: 0 2px 6px rgba(45,106,79,0.3);
        }

.search-create-row {
    display: flex;
    gap: 10px;
    margin-bottom: 16px;
    align-items: stretch;
    animation: slideDown 0.25s ease forwards;
}

.search-container {
    position: relative;
    display: flex;
    align-items: center;
    flex: 1;
}

    .search-container input {
        width: 100%;
        padding: 12px 40px 12px 14px;
        font-size: 16px;
        border: 1px solid var(--border);
        border-radius: var(--radius);
        background: var(--surface);
        font-family: 'DM Sans', sans-serif;
        color: var(--text-primary);
        transition: all 0.15s;
        outline: none;
        -webkit-tap-highlight-color: transparent;
        box-shadow: var(--shadow-sm);
    }

        .search-container input::placeholder {
            color: var(--text-muted);
        }

        .search-container input:focus {
            border-color: var(--accent);
            box-shadow: 0 0 0 3px rgba(45,106,79,0.1);
        }

.btn-clear-search {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 18px;
    cursor: pointer;
    padding: 6px;
    transition: color 0.15s;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    min-height: 44px;
    min-width: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
}

    .btn-clear-search:hover,
    .btn-clear-search:active {
        color: var(--text-primary);
    }

.form-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 20px;
    box-shadow: var(--shadow-sm);
    animation: fadeIn 0.25s ease forwards;
}

.form-grid {
    display: grid;
    grid-template-columns: 1fr 90px;
    gap: 8px;
    margin-bottom: 8px;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
    margin-bottom: 8px;
}

.category-input-wrap {
    position: relative;
}

.form-card input {
    width: 100%;
    font-size: 16px;
    padding: 11px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg);
    font-family: 'DM Sans', sans-serif;
    color: var(--text-primary);
    transition: border-color 0.15s, box-shadow 0.15s;
    outline: none;
    -webkit-tap-highlight-color: transparent;
}

    .form-card input::placeholder {
        color: var(--text-muted);
    }

    .form-card input:focus {
        border-color: var(--accent);
        box-shadow: 0 0 0 3px rgba(45,106,79,0.1);
    }

.input-error {
    border-color: var(--danger) !important;
    box-shadow: 0 0 0 3px rgba(192,57,43,0.1) !important;
}

.error-msg {
    font-size: 0.78rem;
    color: var(--danger);
    margin-top: 4px;
}

.category-suggestions {
    display: none;
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-md);
    z-index: 100;
    max-height: 200px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

    .category-suggestions.open {
        display: block;
    }

.suggestion-item {
    padding: 12px 14px;
    font-size: 0.95rem;
    cursor: pointer;
    color: var(--text-primary);
    transition: background 0.1s;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

    .suggestion-item:hover, .suggestion-item.highlighted {
        background: var(--accent-light);
        color: var(--accent-hover);
    }

.form-actions {
    display: flex;
    gap: 8px;
    margin-top: 12px;
}

.btn {
    padding: 12px 20px;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-family: 'DM Sans', sans-serif;
    font-size: 0.95rem;
    font-weight: 600;
    transition: all 0.15s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    min-height: 44px;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.btn-primary {
    background: var(--accent);
    color: white;
    box-shadow: 0 2px 6px rgba(45,106,79,0.25);
}

    .btn-primary:active {
        background: var(--accent-hover);
        transform: scale(0.98);
    }

.btn-small {
    padding: 10px 12px;
    font-size: 0.8rem;
    flex-shrink: 0;
    white-space: nowrap;
}

.btn-block {
    width: 100%;
    flex: none;
}

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border);
    flex: 1;
}

    .btn-ghost:active {
        background: var(--surface-2);
    }

ul {
    list-style: none;
    padding: 0;
    margin: 0;
}

li {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px;
    margin-bottom: 8px;
    box-shadow: var(--shadow-sm);
    animation: fadeIn 0.2s ease forwards;
    position: relative;
}

    li.is-checked {
        background: var(--checked-bg);
        border-color: #d4ccc4;
        opacity: 0.7;
    }

    li.menu-open {
        z-index: 50;
    }

    li.hidden-search {
        display: none;
    }

.category-header {
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text-secondary);
    margin: 12px 0 6px 0;
}

.item-row {
    display: flex;
    align-items: center;
    gap: 12px;
}

.item-checkbox {
    flex-shrink: 0;
    width: 44px;
    height: 44px;
    cursor: pointer;
    position: relative;
}

.item-row input[type="checkbox"] {
    appearance: none;
    -webkit-appearance: none;
    width: 24px;
    height: 24px;
    border: 2px solid var(--border);
    border-radius: 7px;
    cursor: pointer;
    flex-shrink: 0;
    transition: all 0.15s ease;
    position: relative;
    background: white;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

    .item-row input[type="checkbox"]:checked {
        background: var(--accent);
        border-color: var(--accent);
    }

        .item-row input[type="checkbox"]:checked::after {
            content: '';
            position: absolute;
            left: 5px;
            top: 2px;
            width: 9px;
            height: 13px;
            border: 2.5px solid white;
            border-top: none;
            border-left: none;
            transform: rotate(45deg);
        }

.item-main {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
}

.item-name {
    font-size: 1rem;
    font-weight: 500;
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

    .item-name.checked {
        text-decoration: line-through;
        color: var(--text-muted);
    }

.item-qty {
    font-size: 0.78rem;
    color: var(--text-muted);
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 2px 6px;
    font-weight: 500;
    flex-shrink: 0;
}

.item-price {
    font-size: 0.78rem;
    color: var(--accent);
    background: var(--accent-light);
    border-radius: 4px;
    padding: 2px 6px;
    font-weight: 600;
    flex-shrink: 0;
}

.actions {
    display: flex;
    gap: 6px;
    flex-shrink: 0;
}

.btn-icon {
    width: 38px;
    height: 38px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface-2);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s;
    color: var(--text-secondary);
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    flex-shrink: 0;
}

    .btn-icon:active {
        background: var(--border);
    }

    .btn-icon.danger:active {
        background: var(--danger-light);
        border-color: var(--danger);
        color: var(--danger);
    }

/* Menu Dropdown */
.actions-menu {
    position: relative;
    flex-shrink: 0;
    z-index: 10;
}

.btn-menu {
    width: 38px;
    height: 38px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface-2);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s;
    color: var(--text-secondary);
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    font-size: 18px;
}

.menu-dropdown {
    position: absolute;
    bottom: calc(100% + 6px);
    right: 0;
    background: white;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    box-shadow: 0 4px 16px rgba(0,0,0,0.2);
    z-index: 99999;
    min-width: 140px;
}

.menu-item {
    display: block;
    width: 100%;
    padding: 10px 12px;
    border: none;
    background: none;
    cursor: pointer;
    text-align: left;
    font-size: 14px;
    color: var(--text-primary);
    transition: background 0.15s;
}

    .menu-item:hover {
        background: var(--surface-2);
    }

    .menu-item.danger {
        color: var(--danger);
    }

        .menu-item.danger:hover {
            background: var(--danger-light);
        }

@media (hover: hover) {
    .actions {
        opacity: 0;
        transition: opacity 0.15s;
    }

    li:hover .actions {
        opacity: 1;
    }

    .btn-icon {
        background: white;
    }

        .btn-icon:hover {
            background: var(--surface-2);
            color: var(--text-primary);
        }

        .btn-icon.danger:hover {
            background: var(--danger-light);
            border-color: var(--danger);
            color: var(--danger);
        }

    .btn-menu {
        background: white;
    }

        .btn-menu:hover {
            background: var(--surface-2);
            color: var(--text-primary);
        }

    .btn-primary:hover {
        background: var(--accent-hover);
        box-shadow: 0 3px 10px rgba(45,106,79,0.35);
        transform: translateY(-1px);
    }
}

.notes {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-top: 6px;
    margin-left: 36px;
    font-style: italic;
    line-height: 1.4;
}

.empty-state {
    text-align: center;
    padding: 48px 20px;
    color: var(--text-muted);
}

    .empty-state p {
        font-size: 0.95rem;
    }

.form-card.editing {
    border-color: var(--warning);
    box-shadow: 0 0 0 3px rgba(230,126,34,0.1);
}

.editing-label {
    display: none;
    font-size: 0.78rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--warning);
    margin-bottom: 10px;
}

.form-card.editing .editing-label {
    display: block;
}

@media (min-width: 480px) {
    body {
        padding: 32px 20px 60px;
    }

    .form-row {
        grid-template-columns: 1fr 1fr;
    }

    .mode-switcher {
        width: fit-content;
    }

    .form-card input {
        font-size: 0.9rem;
    }
}

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

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-8px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}
