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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: #f5f5f5;
    color: #333;
    line-height: 1.5;
}

header {
    background: #1a1a2e;
    color: #fff;
    padding: 1.2rem 0;
    text-align: center;
}

header h1 {
    font-size: 1.4rem;
    font-weight: 600;
    letter-spacing: 0.5px;
}

header p {
    font-size: 0.85rem;
    opacity: 0.7;
    margin-top: 0.2rem;
}

.header-nav {
    margin-top: 0.7rem;
    display: flex;
    justify-content: center;
    gap: 0.6rem;
}

.nav-btn {
    display: inline-block;
    padding: 0.4rem 1.1rem;
    border: 1px solid rgba(255,255,255,0.4);
    border-radius: 5px;
    color: #fff;
    font-size: 0.82rem;
    text-decoration: none;
    transition: all 0.15s;
}

.nav-btn:hover {
    background: rgba(255,255,255,0.15);
    border-color: rgba(255,255,255,0.7);
}

.nav-btn.active {
    background: rgba(255,255,255,0.2);
    border-color: rgba(255,255,255,0.8);
    font-weight: 600;
}

.nav-btn.backup {
    border-color: rgba(46,204,113,0.5);
    color: #a0f0c0;
}

.nav-btn.backup:hover {
    background: rgba(46,204,113,0.2);
    border-color: rgba(46,204,113,0.7);
}

.nav-btn.logout {
    border-color: rgba(231,76,60,0.5);
    color: #f8a0a0;
}

.nav-btn.logout:hover {
    background: rgba(231,76,60,0.2);
    border-color: rgba(231,76,60,0.7);
}

.nav-user {
    align-self: center;
    font-size: 0.8rem;
    color: rgba(255,255,255,0.7);
    white-space: nowrap;
    margin-right: 0.2rem;
}

.backup-reminder {
    display: none;
    background: #fff3cd;
    border-bottom: 1px solid #ffc107;
    padding: 0.6rem 1rem;
    text-align: center;
    font-size: 0.85rem;
    color: #664d03;
}

.backup-reminder.active { display: block; }

.backup-reminder a {
    color: #664d03;
    font-weight: 600;
    text-decoration: underline;
    margin: 0 0.3rem;
}

.backup-reminder .dismiss-btn {
    background: none;
    border: none;
    color: #997a00;
    cursor: pointer;
    font-size: 1rem;
    margin-left: 0.8rem;
    vertical-align: middle;
}

main {
    max-width: 720px;
    margin: 2rem auto;
    padding: 0 1rem;
}

.card {
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.08);
    padding: 2rem;
}

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

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

.form-row {
    display: flex;
    gap: 1rem;
}

.form-row .form-group {
    flex: 1;
}

input[type="text"],
input[type="number"] {
    width: 100%;
    padding: 0.55rem 0.75rem;
    border: 1px solid #ccc;
    border-radius: 5px;
    font-size: 0.95rem;
    font-family: inherit;
    transition: border-color 0.15s;
}

input:focus {
    outline: none;
    border-color: #4a6cf7;
    box-shadow: 0 0 0 2px rgba(74, 108, 247, 0.15);
}

/* Inline validation errors */
.field-error {
    font-size: 0.8rem;
    color: #dc3545;
    margin-top: 0.25rem;
    display: none;
}

.field-error.active {
    display: block;
}

input.input-error {
    border-color: #dc3545 !important;
    box-shadow: 0 0 0 2px rgba(220, 53, 69, 0.15) !important;
}

/* Per-row material error (sits under the material input, inside .item-row-wrapper) */
.item-row-wrapper { margin-bottom: 0.6rem; }
.item-row-wrapper .item-row { margin-bottom: 0.25rem; }
.material-error {
    margin-top: 0;
    padding-left: 0.1rem;
}

/* Flash animation for when user ignores the error and tries + Add Item */
@keyframes errorFlash {
    0%, 100% { opacity: 1; transform: translateX(0); }
    20%, 60% { opacity: 1; transform: translateX(-4px); }
    40%, 80% { opacity: 1; transform: translateX(4px); }
}
.material-error.flashing {
    animation: errorFlash 0.6s ease-in-out;
    font-weight: 600;
}

/* Disabled add button */
.add-item-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    border-color: #ccc;
    color: #999;
}
.add-item-btn:disabled:hover {
    border-color: #ccc;
    color: #999;
}

/* Autocomplete */
.autocomplete-wrapper {
    position: relative;
}

.autocomplete-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    z-index: 1000;
    background: #fff;
    border: 1px solid #ccc;
    border-top: none;
    border-radius: 0 0 5px 5px;
    max-height: 200px;
    overflow-y: auto;
    display: none;
    box-shadow: 0 4px 8px rgba(0,0,0,0.1);
}

.autocomplete-dropdown.active {
    display: block;
}

.autocomplete-item {
    padding: 0.5rem 0.75rem;
    cursor: pointer;
    font-size: 0.9rem;
    border-bottom: 1px solid #f0f0f0;
}

.autocomplete-item:last-child {
    border-bottom: none;
}

.autocomplete-item:hover,
.autocomplete-item.selected {
    background: #e8efff;
}

.autocomplete-item .sub {
    font-size: 0.78rem;
    color: #888;
}

/* Items list */
.items-section h3 {
    font-size: 0.95rem;
    font-weight: 600;
    color: #444;
    margin-bottom: 0.5rem;
}

.item-row {
    display: flex;
    gap: 0.6rem;
    align-items: flex-start;
    margin-bottom: 0.5rem;
}

.item-row .autocomplete-wrapper {
    flex: 1;
}

.item-row .rate-input {
    width: 110px;
    flex-shrink: 0;
}

.item-row .dilution-input {
    width: 75px;
    flex-shrink: 0;
}

#addressSelect {
    width: 100%;
    padding: 0.55rem 0.75rem;
    border: 1px solid #ccc;
    border-radius: 5px;
    font-size: 0.95rem;
    font-family: inherit;
    background: #fff;
    transition: border-color 0.15s;
}

#addressSelect:focus {
    outline: none;
    border-color: #4a6cf7;
    box-shadow: 0 0 0 2px rgba(74, 108, 247, 0.15);
}

.address-display-box {
    font-size: 0.88rem;
    color: #555;
    margin-top: 0.4rem;
}

.remove-btn {
    background: none;
    border: 1px solid #ddd;
    border-radius: 5px;
    padding: 0.55rem 0.65rem;
    cursor: pointer;
    font-size: 0.85rem;
    color: #999;
    transition: all 0.15s;
    flex-shrink: 0;
}

.remove-btn:hover {
    border-color: #e74c3c;
    color: #e74c3c;
    background: #fdf0ef;
}

.add-item-btn {
    background: none;
    border: 1px dashed #aaa;
    border-radius: 5px;
    padding: 0.45rem 1rem;
    cursor: pointer;
    font-size: 0.85rem;
    color: #666;
    margin-top: 0.3rem;
    transition: all 0.15s;
}

.add-item-btn:hover {
    border-color: #4a6cf7;
    color: #4a6cf7;
}

/* Generate button */
.generate-btn {
    display: block;
    width: 100%;
    padding: 0.75rem;
    background: #1a1a2e;
    color: #fff;
    border: none;
    border-radius: 6px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    margin-top: 1.5rem;
    transition: background 0.15s;
}

.generate-btn:hover {
    background: #2d2d4e;
}

.generate-btn:disabled {
    background: #999;
    cursor: not-allowed;
}

/* Toast notifications */
.toast-container {
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.toast {
    background: #fff;
    border: 1px solid #ddd;
    border-left: 4px solid #4a6cf7;
    border-radius: 6px;
    padding: 0.8rem 1rem;
    box-shadow: 0 4px 12px rgba(0,0,0,0.12);
    font-size: 0.85rem;
    max-width: 360px;
    animation: slideIn 0.25s ease-out;
}

.toast p {
    margin-bottom: 0.5rem;
}

.toast-actions {
    display: flex;
    gap: 0.5rem;
}

.toast-actions button {
    padding: 0.3rem 0.8rem;
    border-radius: 4px;
    border: 1px solid #ccc;
    background: #fff;
    cursor: pointer;
    font-size: 0.8rem;
}

.toast-actions .btn-yes {
    background: #4a6cf7;
    color: #fff;
    border-color: #4a6cf7;
}

@keyframes slideIn {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

/* Success toast */
.toast.success-toast {
    border-left-color: #27ae60;
}

.toast.success-toast p {
    margin-bottom: 0;
    color: #27ae60;
    font-weight: 600;
}

/* ── Confirm modal ─────────────────────────────────────────────── */
.confirm-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.35);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: 5000;
    justify-content: center;
    align-items: center;
}

.confirm-overlay.active {
    display: flex;
}

.confirm-box {
    background: #fff;
    border-radius: 10px;
    padding: 1.5rem 2rem;
    max-width: 400px;
    width: 90%;
    box-shadow: 0 8px 30px rgba(0,0,0,0.2);
    animation: confirmIn 0.15s ease-out;
    text-align: center;
}

@keyframes confirmIn {
    from { transform: scale(0.95); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

.confirm-box p {
    font-size: 0.95rem;
    color: #333;
    margin-bottom: 1.2rem;
    line-height: 1.5;
}

.confirm-actions {
    display: flex;
    gap: 0.6rem;
    justify-content: center;
}

.confirm-actions button {
    padding: 0.5rem 1.5rem;
    border-radius: 6px;
    border: 1px solid #ccc;
    font-size: 0.88rem;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.15s;
}

.confirm-actions .confirm-yes {
    background: #e74c3c;
    color: #fff;
    border-color: #e74c3c;
}

.confirm-actions .confirm-yes:hover {
    background: #c0392b;
}

.confirm-actions .confirm-no {
    background: #fff;
    color: #333;
}

.confirm-actions .confirm-no:hover {
    background: #f5f5f5;
    border-color: #999;
}

/* ── Mobile responsiveness ─────────────────────────────────────── */
@media (max-width: 768px) {
    .header-nav {
        flex-wrap: wrap;
        gap: 0.4rem;
        padding: 0 0.8rem;
    }

    .nav-btn {
        font-size: 0.75rem;
        padding: 0.35rem 0.7rem;
    }

    main {
        margin: 1rem auto;
        padding: 0 0.5rem;
    }

    .card {
        padding: 1.2rem;
    }

    .form-row {
        flex-direction: column;
        gap: 0;
    }

    .item-row {
        flex-wrap: wrap;
    }

    .item-row .rate-input {
        width: 80px;
    }

    .toast-container {
        bottom: auto;
        top: 0.5rem;
        right: 0.5rem;
        left: 0.5rem;
    }

    .toast {
        max-width: 100%;
    }
}

@media (max-width: 480px) {
    header h1 { font-size: 1.1rem; }
    header p { font-size: 0.75rem; }

    .nav-btn {
        font-size: 0.7rem;
        padding: 0.3rem 0.5rem;
    }

    .card {
        padding: 0.8rem;
    }
}
