body {
    margin: 0;
    padding: 0;
    min-height: 100vh;
}

#container {
    margin: 0px auto 0 auto;
    width: 100%;
}

nav {
    background-color: #fff;
    position: sticky;
    top: 0;
    border-bottom: black solid 1px;
    z-index: 10;
}

#top {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

#itemList {
    margin-top: 60px;
}

#buttonBox, #textBox {
    display: flex;
    align-items: center;
    font-size: large;
}

#top > * {
    padding: 10px;
}

#allTitle {
    font-size: xxx-large;
    font-weight: bolder;
    color: black;
}

#watchTitle, #getTitle {
    font-size: xx-large;
    font-weight: normal;
    color: grey;
}

#add {
    height: 40px;
    width: 40px;
    font-size: x-large;
    margin-right: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
}

#searchWrap {
    position: relative;
}

#searchBar {
    height: 30px;
    width: 150px;
    font-size: xx-large;
    margin-right: 10px;
    padding-right: 30px;
}

#searchClear {
    position: absolute;
    right: 4px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    font-size: 20px;
    cursor: pointer;
    color: #666;
    width: 28px;
    height: 28px;
    display: none;
    align-items: center;
    justify-content: center;
    line-height: 1;
    padding: 0;
    z-index: 1;
}

#searchClear.visible {
    display: flex;
}

table {
    width: 100%;
    margin: 0px auto 0 auto;
    border-collapse: collapse;
    color: black;
    background-color: white;
    font-size: xx-large;
    table-layout: fixed;
}

td {
    overflow: hidden;
    word-wrap: break-word;
}

table tr:nth-child(odd) {
    background-color: lightgray;
}

.Plenty {
    color: green;
}

.Watch {
    color: goldenrod;
}

.Get {
    color: red;
}

.Remove {
    color: black;
}

.buttonTD {
    display: flex;
    justify-content: flex-end;
    align-items: end;
}

.buttonTD > div {
    margin-right: 30px;
}

input[type='radio'] {
    transform: scale(2) translateY(-0.2rem);
    margin-right: 5px;

}

#submit {
    visibility: hidden;
    margin: 10px;
    font-size: x-large;
}

select {
    height: 30px;
    width: 200px;
    font-size: x-large;
    margin-right: 10px;
}

#saveToast {
    position: fixed;
    bottom: calc(env(safe-area-inset-bottom, 0px) + 24px);
    left: 50%;
    transform: translateX(-50%) translateY(10px);
    padding: 10px 20px;
    border-radius: 8px;
    font-size: large;
    color: white;
    background-color: #333;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease, transform 0.25s ease;
    z-index: 100;
    white-space: nowrap;
}

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

#saveToast.success {
    background-color: green;
}

#saveToast.error {
    background-color: darkred;
}

/* --- Add Item Modal --- */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
}

.modal-overlay.open {
    opacity: 1;
    pointer-events: auto;
}

.modal-card {
    background: #fff;
    border-radius: 12px;
    padding: 24px;
    width: 90%;
    max-width: 360px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
    transform: translateY(12px);
    transition: transform 0.2s ease;
}

.modal-overlay.open .modal-card {
    transform: translateY(0);
}

.modal-card h2 {
    margin: 0 0 16px;
    font-size: x-large;
}

.modal-card input[type="text"] {
    width: 100%;
    box-sizing: border-box;
    padding: 10px 12px;
    font-size: large;
    border: 2px solid #ccc;
    border-radius: 8px;
    outline: none;
}

.modal-card input[type="text"]:focus {
    border-color: #555;
}

.modal-error {
    display: none;
    color: darkred;
    font-size: medium;
    margin: 8px 0 0;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 20px;
}

.modal-actions button {
    padding: 8px 18px;
    font-size: large;
    border-radius: 8px;
    border: none;
    cursor: pointer;
}

#addCancel {
    background: #eee;
    color: #333;
}

#addConfirm {
    background: #333;
    color: #fff;
}

/* --- Mobile adjustments --- */
@media (max-width: 768px) {
    /* Header: wrap onto two rows instead of overflowing the screen */
    #top {
        flex-wrap: wrap;
        row-gap: 4px;
    }

    #top > * {
        padding: 6px 10px;
    }

    /* !important is required: groceries.js applies inline font-sizes on click,
       which would otherwise override these mobile sizes */
    #allTitle {
        font-size: x-large !important;
    }

    #watchTitle, #getTitle {
        font-size: large !important;
    }

    #buttonBox, #textBox {
        font-size: medium;
    }

    #add {
        width: 32px;
        height: 32px;
        font-size: large;
        margin-right: 8px;
    }

    table {
        font-size: medium;
    }

    /* Hide the label text on mobile: the 4 radios become color-coded
       dots side by side, in the same colors as the labels they replace */
    .buttonTD {
        flex-wrap: nowrap;
        justify-content: center;
        align-items: center;
    }

    label.Plenty,
    label.Watch,
    label.Get,
    label.Remove {
        display: none;
    }

    .buttonTD > div {
        margin: 0 6px;
    }

    .buttonTD input[type='radio'] {
        -webkit-appearance: none;
        appearance: none;
        width: 26px;
        height: 26px;
        margin: 0;
        transform: none;
        border-radius: 50%;
        border: 4px solid;
        flex-shrink: 0;
        cursor: pointer;
    }

    /* Selected = same color, just a thicker border */
    .buttonTD input[type='radio']:checked {
        border-width: 8px;
    }

    .buttonTD input[type='radio'][value='Plenty'] {
        border-color: green;
    }

    .buttonTD input[type='radio'][value='Watch'] {
        border-color: goldenrod;
    }

    .buttonTD input[type='radio'][value='Get'] {
        border-color: red;
    }

    .buttonTD input[type='radio'][value='Remove'] {
        border-color: black;
    }

    label {
        font-size: medium;
    }

    select {
        width: 140px;
        font-size: medium;
    }

    #searchBar {
        font-size: 16px;
        width: 100px;
    }
}

/* --- Very small phones (e.g. iPhone SE / 6/7/8, 320-375px) ---
   The store dropdown is still too wide here and clips the radio button.
   Shrink the select and its margins so both fit within one half-column. */
@media (max-width: 400px) {
    select {
        width: 108px;
        font-size: 13px;
        padding: 2px 6px;
        margin-right: 4px;
    }

    .buttonTD > div {
        margin: 0 4px;
    }
}