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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: #f5f5f5;
    color: #222;
    min-height: 100dvh;
    display: flex;
    align-items: center;
    justify-content: center;
}

#app {
    width: 100%;
    max-width: 480px;
    padding: 1.5rem;
}

/* ── App mode (authenticated) ─────────────────────────────── */

body.app-mode {
    align-items: flex-start;
    background: #f0f2f0;
}

body.app-mode #app {
    padding: 0;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
}

/* ── Login ────────────────────────────────────────────────── */

.login-card {
    background: #fff;
    border-radius: 12px;
    padding: 2rem;
    box-shadow: 0 2px 12px rgba(0,0,0,0.1);
}

.login-card h1 {
    font-size: 1.75rem;
    color: #2d7d46;
    margin-bottom: 0.25rem;
}

.login-card .subtitle {
    color: #666;
    font-size: 0.9rem;
    margin-bottom: 1.5rem;
}

.form-group { margin-bottom: 1rem; }

.form-group label {
    display: block;
    font-size: 0.85rem;
    font-weight: 600;
    margin-bottom: 0.4rem;
    color: #444;
}

.form-group input {
    width: 100%;
    padding: 0.65rem 0.75rem;
    border: 1.5px solid #ddd;
    border-radius: 8px;
    font-size: 1rem;
    transition: border-color 0.15s;
    outline: none;
}

.form-group input:focus { border-color: #2d7d46; }

.error-msg {
    color: #c0392b;
    font-size: 0.85rem;
    margin-bottom: 0.75rem;
    min-height: 1.2em;
}

.btn {
    width: 100%;
    padding: 0.75rem;
    background: #2d7d46;
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s;
}
.btn:hover    { background: #256039; }
.btn:disabled { background: #aaa; cursor: default; }

/* ── App shell ────────────────────────────────────────────── */

.app-shell {
    display: flex;
    flex-direction: column;
    min-height: 100dvh;
}

/* ── App bar ──────────────────────────────────────────────── */

.app-shell > header,
.picker-header {
    position: sticky;
    top: 0;
    height: 56px;
    background: #2d7d46;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 0.5rem 0 1rem;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
    z-index: 10;
    flex-shrink: 0;
}

.app-shell > header h1,
.picker-header h2 {
    font-size: 1.15rem;
    font-weight: 700;
    flex: 1;
}

.picker-header h2 { margin-left: 0.25rem; }

/* ── Overflow menu ────────────────────────────────────────── */

.menu-container { position: relative; }

.menu-btn {
    background: none;
    border: none;
    color: #fff;
    font-size: 1.4rem;
    line-height: 1;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.15s;
}
.menu-btn:hover { background: rgba(255,255,255,0.15); }

.menu-dropdown {
    position: absolute;
    top: calc(100% + 4px);
    right: 4px;
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.15);
    min-width: 160px;
    overflow: hidden;
    z-index: 100;
}

.menu-user {
    padding: 0.65rem 1rem;
    font-size: 0.8rem;
    font-weight: 600;
    color: #888;
    border-bottom: 1px solid #eee;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.menu-dropdown button {
    display: block;
    width: 100%;
    padding: 0.75rem 1rem;
    text-align: left;
    background: none;
    border: none;
    font-size: 0.95rem;
    color: #c0392b;
    cursor: pointer;
    transition: background 0.15s;
}
.menu-dropdown button:hover { background: #fdf2f2; }

/* ── Main content ─────────────────────────────────────────── */

.app-shell > main {
    flex: 1;
    padding: 0.75rem 0.75rem 5rem; /* bottom padding for FAB */
    overflow-y: auto;
}

.empty-state {
    color: #aaa;
    font-size: 0.9rem;
    text-align: center;
    margin-top: 2.5rem;
    line-height: 1.6;
}

/* ── Tag list ─────────────────────────────────────────────── */

.tag-list {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    align-items: flex-start;
}

/* ── Shopping item tags ───────────────────────────────────── */

.item-tag {
    display: inline-flex;
    align-items: stretch;
    background: #fff;
    border: 1.5px solid #ddd;
    border-radius: 20px;
    overflow: hidden;
    max-width: 100%;
    transition: border-color 0.15s, background 0.15s;
}

.item-tag.completed {
    background: #e8f5e9;
    border-color: #a5d6a7;
}

.item-complete {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 6px 8px 6px 10px;
    background: none;
    border: none;
    cursor: pointer;
    text-align: left;
    min-width: 0;
    max-width: 220px;
}

.item-icon { font-size: 1rem; flex-shrink: 0; }

.item-name {
    font-size: 0.875rem;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.item-tag.completed .item-name {
    text-decoration: line-through;
    color: #777;
}

.item-detail {
    font-size: 0.75rem;
    color: #888;
    margin-left: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 80px;
}

.item-tag.completed .item-detail { color: #aaa; }

.item-actions {
    display: flex;
    border-left: 1px solid #eee;
    flex-shrink: 0;
}

.item-edit, .item-delete {
    width: 30px;
    padding: 0;
    background: none;
    border: none;
    cursor: pointer;
    font-size: 0.8rem;
    color: #aaa;
    transition: color 0.15s, background 0.15s;
    display: flex;
    align-items: center;
    justify-content: center;
}
.item-edit:hover   { color: #2d7d46; background: #f0f9f3; }
.item-delete:hover { color: #c0392b; background: #fdf2f2; }
.item-actions .item-delete { border-left: 1px solid #eee; }

/* ── Divider ──────────────────────────────────────────────── */

.divider {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.7rem;
    font-weight: 700;
    color: #aaa;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin: 10px 0 6px;
}
.divider::before, .divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: #ddd;
}

/* ── FAB ──────────────────────────────────────────────────── */

.fab {
    position: fixed;
    bottom: 1.25rem;
    right: 1.25rem;
    width: 52px;
    height: 52px;
    border-radius: 50%;
    background: #2d7d46;
    color: #fff;
    border: none;
    font-size: 1.6rem;
    line-height: 1;
    cursor: pointer;
    box-shadow: 0 3px 10px rgba(0,0,0,0.25);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, transform 0.1s;
    z-index: 20;
}
.fab:hover   { background: #256039; }
.fab:active  { transform: scale(0.93); }

/* ── Product picker ───────────────────────────────────────── */

.picker-shell {
    background: #f0f2f0;
}

.picker-main {
    flex: 1;
    padding: 0.75rem 0.75rem 5rem;
    overflow-y: auto;
}

.back-btn {
    background: none;
    border: none;
    color: #fff;
    font-size: 1.3rem;
    width: 44px;
    height: 44px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background 0.15s;
    flex-shrink: 0;
}
.back-btn:hover { background: rgba(255,255,255,0.15); }

.icon-btn {
    background: none;
    border: none;
    color: #fff;
    font-size: 1.4rem;
    width: 44px;
    height: 44px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background 0.15s;
    flex-shrink: 0;
}
.icon-btn:hover { background: rgba(255,255,255,0.15); }

/* ── Product tags ─────────────────────────────────────────── */

.product-tag {
    display: inline-flex;
    align-items: center;
    padding: 6px 12px;
    background: #fff;
    border: 1.5px solid #ddd;
    border-radius: 16px;
    font-size: 0.875rem;
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
    transition: background 0.15s, border-color 0.15s, color 0.15s;
    touch-action: none; /* needed for reliable pointerdown on mobile */
}
.product-tag:hover    { border-color: #2d7d46; }
.product-tag.selected { background: #2d7d46; border-color: #2d7d46; color: #fff; }

/* ── New product form ─────────────────────────────────────── */

.new-product-form {
    display: flex;
    gap: 6px;
    align-items: center;
    margin-bottom: 10px;
    background: #fff;
    border: 1.5px solid #2d7d46;
    border-radius: 12px;
    padding: 8px 10px;
}

.np-icon {
    width: 44px;
    font-size: 1.2rem;
    text-align: center;
    border: 1px solid #ddd;
    border-radius: 8px;
    padding: 4px;
    outline: none;
    flex-shrink: 0;
}
.np-icon:focus { border-color: #2d7d46; }

.np-name {
    flex: 1;
    border: 1px solid #ddd;
    border-radius: 8px;
    padding: 6px 8px;
    font-size: 0.9rem;
    outline: none;
    min-width: 0;
}
.np-name:focus { border-color: #2d7d46; }

/* ── Confirm bar (multi-select) ───────────────────────────── */

.confirm-bar {
    position: sticky;
    bottom: 0;
    background: #fff;
    border-top: 1px solid #eee;
    padding: 0.75rem 1rem;
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    z-index: 10;
}

/* ── Shared button styles ─────────────────────────────────── */

.btn-primary {
    background: #2d7d46;
    color: #fff;
    border: none;
    border-radius: 8px;
    padding: 0.55rem 1.1rem;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s;
}
.btn-primary:hover    { background: #256039; }
.btn-primary:disabled { background: #aaa; cursor: default; }

.btn-secondary {
    background: none;
    color: #555;
    border: 1.5px solid #ccc;
    border-radius: 8px;
    padding: 0.55rem 1.1rem;
    font-size: 0.9rem;
    cursor: pointer;
    transition: border-color 0.15s;
}
.btn-secondary:hover { border-color: #888; }

.btn-sm { padding: 0.4rem 0.8rem; font-size: 0.85rem; }

/* ── Edit detail modal ────────────────────────────────────── */

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.35);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
    padding: 1rem;
}

.edit-modal {
    background: #fff;
    border-radius: 12px;
    padding: 1.25rem;
    width: 100%;
    max-width: 320px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.2);
}

.modal-item-name {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 0.75rem;
    color: #333;
}

.detail-input {
    width: 100%;
    padding: 0.6rem 0.75rem;
    border: 1.5px solid #ddd;
    border-radius: 8px;
    font-size: 0.95rem;
    outline: none;
    margin-bottom: 0.75rem;
}
.detail-input:focus { border-color: #2d7d46; }

.modal-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
}

/* ── Undo toast ───────────────────────────────────────────── */

.toast {
    position: fixed;
    bottom: 1rem;
    left: 50%;
    transform: translateX(-50%);
    background: #333;
    color: #fff;
    border-radius: 8px;
    padding: 0.65rem 1rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: 0.875rem;
    box-shadow: 0 4px 16px rgba(0,0,0,0.25);
    z-index: 300;
    white-space: nowrap;
    max-width: calc(100vw - 2rem);
}

.toast button {
    background: none;
    border: 1px solid rgba(255,255,255,0.5);
    color: #fff;
    border-radius: 6px;
    padding: 0.25rem 0.6rem;
    font-size: 0.8rem;
    cursor: pointer;
    white-space: nowrap;
}
.toast button:hover { background: rgba(255,255,255,0.15); }
