body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    margin: 0;
    padding: 0;
    background-color: #fffaf0; 
    color: #4A4A4A; 
    display: flex;
    justify-content: center;
    align-items: flex-start;
    min-height: 100vh;
    padding-top: 20px;
    padding-bottom: 40px;
}

.container {
    width: 90%;
    max-width: 800px;
    background-color: #ffffff;
    padding: 25px 35px;
    border-radius: 12px;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.08);
    text-align: center;
}

header {
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 30px;
    border-bottom: 1px solid #eee;
    padding-bottom: 20px;
}

#logo {
    width: 70px; 
    height: 70px;
    margin-right: 20px;
}

header h1 {
    font-size: 2.8em;
    color: #ff6347; 
    margin: 0;
    font-weight: 700;
    font-family: 'Arial Rounded MT Bold', 'Helvetica Rounded', Arial, sans-serif;
}

#search-form {
    display: flex;
    margin-bottom: 30px;
    gap: 12px;
}

#search-input {
    flex-grow: 1;
    padding: 14px 18px;
    font-size: 1.05em;
    border: 1px solid #ddd;
    border-radius: 28px; 
    box-shadow: none;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
}

#search-input::placeholder {
    color: #aaa;
}

#search-input:focus {
    border-color: #ff7f50; 
    box-shadow: 0 0 0 3px rgba(255, 127, 80, 0.2);
}

#search-button {
    padding: 14px 25px;
    font-size: 1.05em;
    font-weight: 600;
    background-color: #ff6347; 
    color: white;
    border: none;
    border-radius: 28px; 
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: background-color 0.2s, transform 0.1s;
}

#search-button svg {
    width: 20px; 
    height: 20px;
}

#search-button:hover {
    background-color: #e5533d; 
}
#search-button:active {
    transform: translateY(1px);
}


#results-container {
    margin-top: 25px;
    text-align: left;
}

.placeholder-initial {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 20px;
    border: 2px dashed #ffdab9; 
    border-radius: 8px;
    background-color: #fffefa;
}

.placeholder-image {
    max-width: 200px; 
    height: auto;
    margin-bottom: 15px;
    opacity: 0.8;
}

.placeholder-text {
    color: #777;
    font-style: italic;
    text-align: center;
    font-size: 1.1em;
    line-height: 1.5;
}

.error-message {
    color: #d9534f; 
    background-color: #f2dede;
    border: 1px solid #ebccd1;
    padding: 15px;
    border-radius: 4px;
    font-style: normal;
}


/* Recipe Item Styling */
.recipe-item {
    background-color: #fff; 
    border: 1px solid #eee;
    border-radius: 10px;
    padding: 20px 25px;
    margin-bottom: 25px;
    box-shadow: 0 4px 8px rgba(0,0,0,0.05);
    animation: fadeIn 0.5s ease-out;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}


.recipe-item h2 { 
    margin-top: 0;
    color: #D2691E; 
    font-size: 1.8em;
    font-weight: 700;
    margin-bottom: 10px;
    text-align: center;
}

.recipe-description {
    font-size: 1.05em;
    line-height: 1.6;
    color: #555;
    margin-bottom: 20px;
    text-align: center;
    font-style: italic;
}

.recipe-details-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 10px;
    background-color: #f9f9f9;
    padding: 15px;
    border-radius: 6px;
    margin-bottom: 20px;
    font-size: 0.95em;
}
.recipe-details-grid div {
    padding: 5px 0;
}
.recipe-details-grid strong {
    color: #333;
}

.recipe-item h3 { 
    color: #ff7f50; 
    font-size: 1.4em;
    font-weight: 600;
    margin-top: 25px;
    margin-bottom: 10px;
    border-bottom: 2px solid #ffdab9; 
    padding-bottom: 5px;
}

.recipe-ingredients, .recipe-instructions, .recipe-tips {
    padding-left: 20px;
    font-size: 1em;
    line-height: 1.7;
    color: #4A4A4A;
}
.recipe-ingredients li, .recipe-tips li {
    margin-bottom: 8px;
}
.recipe-instructions li {
    margin-bottom: 12px;
}

.recipe-image-container {
    width: 100%;
    max-height: 400px; 
    overflow: hidden;
    border-radius: 8px;
    margin: 20px auto;
    background-color: #f0f0f0; 
    display: flex;
    align-items: center;
    justify-content: center;
    aspect-ratio: 16 / 9; 
}

.recipe-image {
    width: 100%;
    height: 100%;
    object-fit: cover; 
    border-radius: 8px;
    display: block;
}
.image-loading-placeholder {
    font-size: 1em;
    color: #888;
    text-align: center;
    padding: 20px;
}


/* Loading Spinner */
.loading-spinner {
    display: flex; 
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 30px;
    gap: 15px;
}

.spinner {
    border: 6px solid #f3f3f3; 
    border-top: 6px solid #ff6347; 
    border-radius: 50%;
    width: 50px;
    height: 50px;
    animation: spin 1s linear infinite;
}

.loading-spinner p {
    font-size: 1.1em;
    color: #555;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Unit Converter Styles */
.unit-converter {
    margin-top: 40px;
    padding: 25px;
    background-color: #fdfdfd; /* Slightly different background for the section */
    border: 1px solid #eee;
    border-radius: 10px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.06);
}

.unit-converter h2 {
    font-size: 1.8em;
    color: #ff7f50; /* Consistent accent color */
    text-align: center;
    margin-top: 0;
    margin-bottom: 25px;
    font-weight: 600;
}

.converter-form-container {
    display: grid;
    grid-template-columns: 1fr; /* Default for smaller screens */
    gap: 18px;
    margin-bottom: 20px;
}

/* Responsive grid for larger screens */
@media (min-width: 600px) {
    .converter-form-container {
        grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
        align-items: end; /* Align items to the bottom for better layout with button */
    }
    .converter-form-container button {
        grid-column: span 1; /* Ensure button takes full width if it's the last item in a row */
        height: 48px; /* Match input height */
    }
}


.unit-converter .form-group {
    display: flex;
    flex-direction: column;
}

.unit-converter .form-group label {
    margin-bottom: 8px;
    font-size: 0.95em;
    color: #555;
    font-weight: 500;
}

.unit-converter input[type="text"],
.unit-converter select {
    padding: 12px 15px;
    font-size: 1em;
    border: 1px solid #ddd;
    border-radius: 24px; /* Rounded like search */
    box-shadow: none;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
    width: 100%;
    box-sizing: border-box; /* Ensure padding doesn't expand width */
}

.unit-converter input[type="text"]:focus,
.unit-converter select:focus {
    border-color: #ff7f50;
    box-shadow: 0 0 0 3px rgba(255, 127, 80, 0.2);
}

.unit-converter button {
    padding: 12px 20px;
    font-size: 1em;
    font-weight: 600;
    background-color: #ff7f50; /* Consistent accent color */
    color: white;
    border: none;
    border-radius: 24px; /* Rounded like search */
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: background-color 0.2s, transform 0.1s;
    width: 100%; /* Full width on small screens */
    box-sizing: border-box;
}


.unit-converter button svg {
    width: 18px;
    height: 18px;
}

.unit-converter button:hover {
    background-color: #e5533d; /* Darker shade on hover */
}
.unit-converter button:active {
    transform: translateY(1px);
}

.conversion-result-display {
    margin-top: 20px;
    padding: 15px;
    background-color: #e8f5e9; /* Light green for success */
    border: 1px solid #c8e6c9;
    border-radius: 6px;
    text-align: center;
    font-size: 1.1em;
    color: #2e7d32; /* Darker green text */
}

.conversion-result-display.error {
    background-color: #ffebee; /* Light red for error */
    border: 1px solid #ffcdd2;
    color: #c62828; /* Darker red text */
}

.conversion-result-display p {
    margin: 0;
    font-weight: 500;
}
.conversion-result-display span {
    display: block;
    font-size: 0.9em;
    color: #555;
    margin-top: 5px;
}

/* Adjust loading spinner margin for converter */
#unit-converter-section .loading-spinner {
    padding: 20px; /* Less padding than main spinner */
    margin-top: 15px;
}
#unit-converter-section .loading-spinner p {
    font-size: 1em; /* Slightly smaller text */
}
#unit-converter-section .spinner {
    width: 40px;
    height: 40px;
    border-width: 5px;
}

/* Saved Recipes */
.saved-recipes {
    margin-top: 30px;
    text-align: left;
}
.saved-recipes h2 {
    font-size: 1.6em;
    color: #D2691E;
    margin-bottom: 12px;
    text-align: center;
}
.saved-list {
    display: grid;
    gap: 12px;
}
.saved-card {
    border: 1px solid #eee;
    padding: 12px;
    border-radius: 8px;
    background: #fff;
    display: flex;
    gap: 12px;
    align-items: center;
    justify-content: space-between;
    box-shadow: 0 3px 8px rgba(0,0,0,0.04);
}
.saved-card .meta {
    flex: 1 1 auto;
}
.saved-card h4 {
    margin: 0 0 6px 0;
    color: #333;
}
.saved-card .meta small {
    color: #666;
    display:block;
}
.saved-card .saved-actions {
    display: flex;
    gap: 8px;
}
.saved-card button {
    padding: 8px 10px;
    border-radius: 8px;
    border: none;
    cursor: pointer;
    font-weight: 600;
}
.saved-card .btn-edit {
    background: #ffebcd;
    color: #8a4b12;
}
.saved-card .btn-delete {
    background: #ffd6d6;
    color: #9b1e1e;
}
.saved-card .btn-load {
    background: #e6fff1;
    color: #116644;
}

/* Modal */
.modal {
    position: fixed;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background: rgba(20,20,20,0.45);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 60;
}
.modal-content {
    width: 92%;
    max-width: 720px;
    background: #fff;
    border-radius: 10px;
    padding: 18px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.2);
    max-height: 90vh; /* keep modal within viewport height */
    overflow: auto; /* allow scrolling inside the modal */
    -webkit-overflow-scrolling: touch; /* smooth scrolling on iOS */
}
.modal-close {
    background: transparent;
    border: none;
    font-size: 1.6em;
    float: right;
    cursor: pointer;
}
#edit-recipe-name, #edit-recipe-json {
    width: 100%;
    box-sizing: border-box;
    padding: 10px 12px;
    border-radius: 8px;
    border: 1px solid #ddd;
    margin-top: 8px;
}
.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 12px;
}
.modal-actions .primary {
    background: #ff7f50;
    color: #fff;
    border: none;
    padding: 8px 14px;
    border-radius: 8px;
    cursor: pointer;
}
.modal-actions button {
    padding: 8px 12px;
    border-radius: 8px;
    border: 1px solid #ddd;
    background: #fff;
    cursor: pointer;
}

/* In-app dialog styles (replaces native alerts/confirms) */
#inapp-dialog-overlay {
    position: fixed;
    inset: 0;
    background: rgba(20,20,20,0.45);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    -webkit-backdrop-filter: blur(2px);
    backdrop-filter: blur(2px);
}
#inapp-dialog {
    width: 92%;
    max-width: 520px;
    background: #fff;
    border-radius: 10px;
    padding: 18px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.25);
    text-align: center;
}
#inapp-dialog-message {
    color: #333;
    font-size: 1rem;
    margin-bottom: 14px;
    line-height: 1.4;
    max-height: 40vh;
    overflow: auto;
}
#inapp-dialog-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
}
#inapp-dialog-actions .primary {
    background: #ff7f50;
    color: #fff;
    border: none;
    padding: 8px 14px;
    border-radius: 8px;
}
#inapp-dialog-actions .secondary {
    background: #f5f5f5;
    color: #444;
    border: 1px solid #e0e0e0;
    padding: 8px 14px;
    border-radius: 8px;
}