/* Reset & base */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --bg: #f8f9fa;
    --card: #ffffff;
    --border: #dee2e6;
    --text: #212529;
    --text-muted: #6c757d;
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --danger: #dc3545;
    --success: #198754;
    --warning: #e67e22;
    --radius: 6px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
}

/* Nav */
nav {
    background: var(--text);
    color: white;
    padding: 0.5rem 1rem;
}
.nav-inner {
    max-width: 1200px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    gap: 1.5rem;
}
.nav-brand {
    color: white;
    text-decoration: none;
    font-size: 1.25rem;
    font-weight: 700;
}
.nav-links { display: flex; gap: 0.25rem; }
.nav-links .nav-link {
    padding: 0.25rem 0.75rem;
    border-radius: var(--radius);
}
.nav-links .nav-link.active {
    background: rgba(255,255,255,0.15);
    color: white;
}
.nav-right { margin-left: auto; display: flex; align-items: center; gap: 1rem; }
.nav-user { color: #adb5bd; font-size: 0.875rem; }
.nav-link { color: #adb5bd; font-size: 0.875rem; text-decoration: none; }
.nav-link:hover { color: white; }

/* Main */
main {
    max-width: 1200px;
    margin: 0 auto;
    padding: 1rem;
}

/* Utility */
.empty-msg { color: var(--text-muted); font-size: 0.85rem; padding: 0.5rem 0; }

/* Flash */
.flash { background: #fff3cd; border: 1px solid #ffc107; padding: 0.75rem; border-radius: var(--radius); margin-bottom: 1rem; }
.flash p { margin: 0; }

/* Login */
.login-wrap {
    max-width: 360px;
    margin: 4rem auto;
    text-align: center;
}
.login-wrap h1 { font-size: 2rem; margin-bottom: 0.25rem; }
.subtitle { color: var(--text-muted); margin-bottom: 2rem; }
.login-form { display: flex; flex-direction: column; gap: 0.75rem; }
.login-form input {
    padding: 0.6rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 1rem;
}
.login-form button, .btn-primary {
    padding: 0.6rem;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: var(--radius);
    font-size: 1rem;
    cursor: pointer;
}
.login-form button:hover, .btn-primary:hover { background: var(--primary-hover); }
.btn-secondary {
    padding: 0.6rem;
    background: white;
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.875rem;
    cursor: pointer;
}
.btn-secondary:hover { background: var(--bg); }
.btn-danger {
    padding: 0.5rem 1rem;
    background: white;
    color: var(--danger);
    border: 1px solid var(--danger);
    border-radius: var(--radius);
    font-size: 0.85rem;
    cursor: pointer;
}
.btn-danger:hover { background: #fff5f5; }

/* =========================================================================
   Search page
   ========================================================================= */

.search-page {
    max-width: 800px;
    margin: 0 auto;
}

.search-panel {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem;
}
.search-panel h2 { font-size: 1.125rem; margin-bottom: 0.75rem; }

.filter-row { margin-bottom: 0.5rem; }
.filter-row label {
    display: block;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: 0.15rem;
}
.filter-row input, .filter-row select {
    width: 100%;
    padding: 0.4rem 0.5rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.875rem;
}
.filter-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 0.5rem;
    margin-bottom: 0.5rem;
}

#search-btn {
    width: 100%;
    padding: 0.5rem;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: var(--radius);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
}
#search-btn:hover { background: var(--primary-hover); }
#search-btn:disabled { opacity: 0.6; cursor: not-allowed; }

#search-status {
    margin-top: 0.75rem;
    font-size: 0.875rem;
    color: var(--text-muted);
}
.search-warning { color: #856404; }

/* Search results */
#search-results { margin-top: 0.5rem; }
.result-item {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--border);
}
.result-item:last-child { border-bottom: none; }
.result-title {
    color: var(--primary);
    text-decoration: none;
    font-weight: 500;
}
.result-title:hover { text-decoration: underline; }
.result-score {
    font-size: 0.8rem;
    color: var(--text-muted);
    white-space: nowrap;
    margin-left: 0.5rem;
}
.result-missing {
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* =========================================================================
   Pantry page
   ========================================================================= */

.pantry-page {
    max-width: 800px;
    margin: 0 auto;
}

/* Add section */
.pantry-add-section {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem;
    margin-bottom: 1rem;
}
.pantry-add-section h2 { font-size: 1.125rem; margin-bottom: 0.75rem; }
.pantry-add-form input {
    width: 100%;
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.95rem;
    margin-bottom: 0.5rem;
}
.pantry-add-actions {
    display: flex;
    gap: 0.5rem;
}
.pantry-add-actions button {
    padding: 0.45rem 1rem;
    border-radius: var(--radius);
    font-size: 0.875rem;
    cursor: pointer;
}
.pantry-add-actions button:first-child {
    background: var(--success);
    color: white;
    border: none;
}
.pantry-add-actions button:first-child:hover { opacity: 0.9; }

/* Add feedback */
#add-feedback { margin-top: 0.5rem; }
.feedback-item {
    display: flex;
    justify-content: space-between;
    padding: 0.2rem 0.5rem;
    border-radius: 3px;
    font-size: 0.85rem;
    margin-bottom: 0.15rem;
}
.feedback-ok { background: #d4edda; }
.feedback-warn { background: #fff3cd; }
.feedback-status { font-weight: 600; color: var(--warning); }
.feedback-msg { font-size: 0.8rem; color: var(--text-muted); margin-top: 0.35rem; }
.feedback-warn-msg { color: var(--warning); }
.feedback-suggestions {
    padding: 0.3rem 0.5rem;
    margin-bottom: 0.25rem;
    font-size: 0.8rem;
    color: var(--text-muted);
}
.feedback-suggestions .suggestion-btn { margin: 0.1rem 0.15rem; }
.feedback-no-sug { font-style: italic; }

/* Unknown items section */
.pantry-unknown-section {
    background: #fff8e1;
    border: 1px solid #ffe082;
    border-radius: var(--radius);
    padding: 1rem;
    margin-bottom: 1rem;
}
.pantry-unknown-section h2 { font-size: 1.125rem; margin-bottom: 0.25rem; }
.unknown-hint { font-size: 0.8rem; color: var(--text-muted); margin-bottom: 0.75rem; }

.inv-item-right {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    flex-shrink: 0;
}
.suggestion-btn-sm {
    padding: 0.15rem 0.5rem;
    border: 1px solid var(--warning);
    border-radius: var(--radius);
    background: white;
    color: var(--warning);
    font-size: 0.75rem;
    font-weight: 600;
    cursor: pointer;
}
.suggestion-btn-sm:hover { background: #fff3cd; }

/* Inventory section */
.pantry-inventory {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem;
}
.pantry-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.75rem;
}
.pantry-header h2 { font-size: 1.125rem; }
.pantry-total { font-size: 0.85rem; font-weight: 400; color: var(--text-muted); }
.pantry-controls select {
    padding: 0.25rem 0.4rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.85rem;
}

/* Inventory groups & items */
.inv-group { margin-bottom: 0.75rem; }
.inv-group-label {
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    padding-bottom: 0.2rem;
    border-bottom: 1px solid var(--border);
    margin-bottom: 0.15rem;
}
.inv-group-count { font-weight: 400; }

.inv-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.2rem 0;
    font-size: 0.875rem;
}
.inv-item-left { display: flex; align-items: center; gap: 0.35rem; flex: 1; min-width: 0; }
.inv-item-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.inv-canonical { color: var(--text-muted); font-size: 0.75rem; white-space: nowrap; }
.inv-unrecognized { background: #fff8e1; border-radius: 3px; padding: 0.2rem 0.25rem; }
.inv-warn {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 0.9rem;
    color: var(--warning);
    padding: 0;
    line-height: 1;
    flex-shrink: 0;
}
.inv-warn:hover { color: var(--danger); }
.inv-remove {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 1rem;
    padding: 0 0.25rem;
    flex-shrink: 0;
}
.inv-remove:hover { color: var(--danger); }

/* Always-available section */
.always-section {
    margin-top: 0.75rem;
    padding-top: 0.75rem;
    border-top: 1px solid var(--border);
}
.always-section summary {
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    margin-bottom: 0.5rem;
}
.always-section summary span { font-weight: 400; color: var(--text-muted); font-size: 0.8rem; }

/* =========================================================================
   Fix/Rename Modal
   ========================================================================= */

.modal {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 1000;
    align-items: center;
    justify-content: center;
}
.modal.open { display: flex; }
.modal-content {
    background: white;
    border-radius: var(--radius);
    width: 90%;
    max-width: 440px;
    box-shadow: 0 8px 30px rgba(0,0,0,0.2);
}
.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 1rem; }
.modal-close {
    background: none;
    border: none;
    font-size: 1.25rem;
    cursor: pointer;
    color: var(--text-muted);
}
.modal-close:hover { color: var(--text); }
.modal-body { padding: 1rem; }
.modal-body p { font-size: 0.85rem; color: var(--text-muted); margin-bottom: 0.75rem; }

#fix-suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    margin-bottom: 0.75rem;
}
.suggestion-btn {
    padding: 0.3rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: 99px;
    background: white;
    cursor: pointer;
    font-size: 0.8rem;
}
.suggestion-btn:hover { background: var(--bg); border-color: var(--primary); color: var(--primary); }
.suggestion-cat { font-size: 0.7rem; color: var(--text-muted); }

.fix-custom-form {
    display: flex;
    gap: 0.35rem;
    margin-bottom: 0.75rem;
}
.fix-custom-form input {
    flex: 1;
    padding: 0.4rem 0.5rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.85rem;
}
.fix-custom-form button {
    padding: 0.4rem 0.75rem;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: var(--radius);
    font-size: 0.85rem;
    cursor: pointer;
}
.fix-custom-form button:hover { background: var(--primary-hover); }
.fix-actions { text-align: right; }

/* =========================================================================
   Recipe detail
   ========================================================================= */

.recipe-detail {
    max-width: 800px;
    margin: 0 auto;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.5rem;
}
.back-link {
    color: var(--primary);
    text-decoration: none;
    font-size: 0.875rem;
}
.back-link:hover { text-decoration: underline; }
.recipe-detail h1 { margin: 0.75rem 0 0.5rem; }
.recipe-desc { color: var(--text-muted); margin-bottom: 1rem; }
.recipe-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    font-size: 0.875rem;
    color: var(--text-muted);
    margin-bottom: 0.75rem;
}
.recipe-tags { display: flex; flex-wrap: wrap; gap: 0.35rem; margin-bottom: 1rem; }
.tag {
    display: inline-block;
    padding: 0.15rem 0.5rem;
    border-radius: 99px;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}
.tag-meal { background: #dbeafe; color: #1e40af; }
.tag-food { background: #dcfce7; color: #166534; }
.tag-flavor { background: #fef3c7; color: #92400e; }
.tag-fwd { background: #fce7f3; color: #9d174d; }

.recipe-body { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; }
@media (max-width: 600px) { .recipe-body { grid-template-columns: 1fr; } }
.recipe-ingredients h2, .recipe-directions h2 { font-size: 1rem; margin-bottom: 0.5rem; }
.recipe-ingredients ul { list-style: none; }
.recipe-ingredients li { padding: 0.2rem 0; border-bottom: 1px solid #f0f0f0; font-size: 0.9rem; }
.recipe-directions ol { padding-left: 1.25rem; }
.recipe-directions li { padding: 0.3rem 0; font-size: 0.9rem; }
.recipe-credit { margin-top: 1.5rem; font-size: 0.8rem; color: var(--text-muted); }
