@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600&family=Playfair+Display:ital,wght@0,600;0,700;1,600&display=swap');

:root {
    --bg: #faf7f2;
    --surface: #ffffff;
    --accent: #c26e3a;
    --accent-hover: #a85a2d;
    --text: #2c2420;
    --text-light: #6b5e56;
    --text-muted: #a09890;
    --border: #e8e2da;
    --shadow: 0 2px 12px rgba(44, 36, 32, 0.08);
    --shadow-lg: 0 8px 32px rgba(44, 36, 32, 0.12);
    --radius: 12px;
    --radius-sm: 8px;
    --font-body: 'Inter', system-ui, sans-serif;
    --font-heading: 'Playfair Display', Georgia, serif;
}

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

html { scroll-behavior: smooth; }

body {
    font-family: var(--font-body);
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100dvh;
    -webkit-font-smoothing: antialiased;
}

/* Header */
.header {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 1rem 1.5rem;
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-inner {
    max-width: 1200px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.logo {
    font-family: var(--font-heading);
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--accent);
    text-decoration: none;
    letter-spacing: -0.02em;
}

.logo i {
    font-style: italic;
    font-weight: 600;
}

.header-actions {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.6rem 1.2rem;
    border-radius: var(--radius-sm);
    font-family: var(--font-body);
    font-size: 0.875rem;
    font-weight: 500;
    text-decoration: none;
    border: none;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-primary {
    background: var(--accent);
    color: white;
}

.btn-primary:hover {
    background: var(--accent-hover);
    transform: translateY(-1px);
    box-shadow: var(--shadow);
}

.btn-secondary {
    background: transparent;
    color: var(--text);
    border: 1px solid var(--border);
}

.btn-secondary:hover {
    background: var(--bg);
    border-color: var(--text-muted);
}

.btn-danger {
    background: transparent;
    color: #c0392b;
    border: 1px solid #e8c4c0;
}

.btn-danger:hover {
    background: #fdf0ef;
}

.btn-icon {
    padding: 0.6rem;
    aspect-ratio: 1;
    justify-content: center;
}

/* Search & Filters */
.toolbar {
    max-width: 1200px;
    margin: 1.5rem auto;
    padding: 0 1.5rem;
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    align-items: center;
}

.search-box {
    flex: 1;
    min-width: 200px;
    position: relative;
}

.search-box--narrow {
    flex: 0 1 220px;
    min-width: 140px;
}

.quick-add {
    flex: 1;
    display: flex;
    gap: 0.5rem;
    min-width: 200px;
}

.quick-add input {
    flex: 1;
    padding: 0.7rem 1rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: var(--font-body);
    font-size: 0.9rem;
    background: var(--surface);
    color: var(--text);
    transition: border-color 0.2s;
}

.quick-add input:focus {
    outline: none;
    border-color: var(--accent);
}

.search-box input {
    width: 100%;
    padding: 0.7rem 1rem 0.7rem 2.5rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: var(--font-body);
    font-size: 0.9rem;
    background: var(--surface);
    color: var(--text);
    transition: border-color 0.2s;
}

.search-box input:focus {
    outline: none;
    border-color: var(--accent);
}

.search-box svg {
    position: absolute;
    left: 0.75rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    width: 18px;
    height: 18px;
}

.tag-filters {
    display: flex;
    flex-wrap: wrap;
    gap: 0.375rem;
}

.tag-pill {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.35rem 0.75rem;
    border-radius: 100px;
    font-size: 0.8rem;
    font-weight: 500;
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text);
    cursor: pointer;
    transition: all 0.2s;
}

.tag-pill:hover, .tag-pill.active {
    background: var(--accent);
    border-color: var(--accent);
    color: white;
}

.tag-pill .count {
    font-size: 0.7rem;
    opacity: 0.7;
}

/* Recipe Grid */
.recipe-grid {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 1.5rem 3rem;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 1.25rem;
}

.recipe-card {
    border-radius: 18px;
    overflow: hidden;
    cursor: pointer;
    transition: all 0.35s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    text-decoration: none;
    color: inherit;
    display: flex;
    flex-direction: column;
    position: relative;
    background: var(--surface);
    box-shadow: 0 2px 12px rgba(44, 36, 32, 0.08), 0 0 0 1px rgba(44, 36, 32, 0.04);
}

.recipe-card:hover {
    transform: translateY(-8px) scale(1.01);
    box-shadow: 0 20px 40px rgba(44, 36, 32, 0.18), 0 0 0 1px rgba(194, 110, 58, 0.15);
}

/* -- Thumbnail area with overlay title -- */
.recipe-card .thumb {
    aspect-ratio: 16/9;
    overflow: hidden;
    position: relative;
}

.recipe-card .thumb::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(
        to top,
        rgba(20, 15, 12, 0.75) 0%,
        rgba(20, 15, 12, 0.3) 40%,
        rgba(20, 15, 12, 0) 65%
    );
    pointer-events: none;
    transition: opacity 0.35s;
}

.recipe-card:hover .thumb::after {
    opacity: 0.85;
}

.recipe-card .thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.5s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

.recipe-card:hover .thumb img {
    transform: scale(1.1);
}

.recipe-card .thumb .no-thumb {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 4.5rem;
    background: linear-gradient(145deg, #f7ebe0 0%, #e8d5c0 40%, #d4b896 100%);
}

/* -- Title overlay on image -- */
.recipe-card .card-overlay {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 1rem 1.15rem;
    z-index: 2;
    pointer-events: none;
}

.recipe-card .card-overlay .card-title {
    font-family: var(--font-heading);
    font-size: 1.15rem;
    font-weight: 700;
    line-height: 1.25;
    color: #fff;
    text-shadow: 0 1px 4px rgba(0,0,0,0.3);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    margin: 0;
}

/* -- Card body below image -- */
.recipe-card .card-body {
    padding: 0.75rem 1.15rem 1rem;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

.recipe-card .card-source {
    font-size: 0.75rem;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 0.3rem;
    font-weight: 500;
}

.recipe-card .card-source::before {
    content: '👨‍🍳';
    font-size: 0.75rem;
}

.recipe-card .card-desc {
    font-size: 0.8rem;
    color: var(--text-light);
    line-height: 1.4;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.recipe-card .card-tags {
    margin-top: auto;
    display: flex;
    flex-wrap: wrap;
    gap: 0.3rem;
    padding-top: 0.4rem;
}

.recipe-card .card-tags .tag {
    font-size: 0.68rem;
    padding: 0.2rem 0.6rem;
    border-radius: 100px;
    background: var(--accent);
    color: white;
    font-weight: 500;
}

/* Version tag */
.version-tag {
    position: fixed;
    bottom: 0.5rem;
    right: 0.5rem;
    font-size: 0.6rem;
    color: var(--text-muted);
    opacity: 0.4;
    font-family: var(--font-body);
    pointer-events: none;
    z-index: 50;
}

/* Detail View */
.recipe-detail {
    max-width: 800px;
    margin: 0 auto;
    padding: 0 1.5rem 3rem;
    animation: fadeIn 0.3s ease;
}

.recipe-detail .hero-image {
    width: calc(100% + 3rem);
    margin-left: -1.5rem;
    margin-top: -1px;
    aspect-ratio: 16/9;
    overflow: hidden;
    background: var(--border);
    margin-bottom: 0;
    max-height: 400px;
}

.recipe-detail .hero-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.recipe-detail .detail-header-actions {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.75rem;
    flex-wrap: wrap;
}

.recipe-detail .btn-source {
    font-size: 0.8rem;
}

.recipe-detail .detail-header {
    background: var(--surface);
    border-radius: 18px;
    padding: 1.75rem 2rem;
    margin-top: -3rem;
    position: relative;
    z-index: 2;
    box-shadow: 0 4px 24px rgba(44, 36, 32, 0.1);
}

.recipe-detail h1 {
    font-family: var(--font-heading);
    font-size: 2rem;
    font-weight: 700;
    line-height: 1.2;
    margin-bottom: 0.75rem;
}

.recipe-detail .meta {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    align-items: center;
    color: var(--text-muted);
    font-size: 0.85rem;
    margin-bottom: 0.75rem;
}

.recipe-detail .meta-source,
.recipe-detail .meta-date {
    display: flex;
    align-items: center;
    gap: 0.3rem;
}

.recipe-detail .detail-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
}

.recipe-detail .detail-tags .tag-pill {
    font-size: 0.78rem;
    padding: 0.3rem 0.75rem;
}

/* Recipe content (AI-formatted description) */
.recipe-content {
    background: var(--surface);
    border-radius: 18px;
    padding: 1.75rem 2rem;
    margin-top: 1rem;
    box-shadow: 0 2px 12px rgba(44, 36, 32, 0.06);
}

.recipe-content h3.recipe-section-title {
    font-family: var(--font-heading);
    font-size: 1.15rem;
    font-weight: 600;
    color: var(--accent);
    margin: 1.25rem 0 0.6rem;
    padding-bottom: 0.4rem;
    border-bottom: 2px solid var(--border);
}

.recipe-content h3.recipe-section-title:first-child {
    margin-top: 0;
}

.recipe-content p {
    font-size: 0.95rem;
    line-height: 1.7;
    color: var(--text);
    margin: 0.4rem 0;
}

.recipe-content ul.recipe-list {
    list-style: none;
    padding: 0;
    margin: 0.4rem 0;
}

.recipe-content ul.recipe-list li {
    font-size: 0.95rem;
    line-height: 1.6;
    color: var(--text);
    padding: 0.3rem 0 0.3rem 1.5rem;
    position: relative;
    border-bottom: 1px solid rgba(232, 226, 218, 0.5);
}

.recipe-content ul.recipe-list li:last-child {
    border-bottom: none;
}

.recipe-content ul.recipe-list li::before {
    content: '•';
    position: absolute;
    left: 0.4rem;
    color: var(--accent);
    font-weight: 700;
    font-size: 1.1rem;
}

.recipe-detail .actions {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
    margin-top: 1.25rem;
    padding: 1.25rem 2rem;
    background: var(--surface);
    border-radius: 18px;
    box-shadow: 0 2px 12px rgba(44, 36, 32, 0.06);
}

/* Forms */
.form-view {
    max-width: 640px;
    margin: 2rem auto;
    padding: 0 1.5rem;
    animation: fadeIn 0.3s ease;
}

.form-view h1 {
    font-family: var(--font-heading);
    font-size: 1.75rem;
    font-weight: 700;
    margin-bottom: 1.5rem;
}

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

.form-group label {
    display: block;
    font-size: 0.85rem;
    font-weight: 500;
    margin-bottom: 0.375rem;
    color: var(--text-light);
}

.form-group input,
.form-group textarea {
    width: 100%;
    padding: 0.7rem 1rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: var(--font-body);
    font-size: 0.9rem;
    color: var(--text);
    background: var(--surface);
    transition: border-color 0.2s;
}

.form-group input:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--accent);
}

.form-group textarea {
    min-height: 120px;
    resize: vertical;
}

.form-actions {
    display: flex;
    gap: 0.75rem;
    margin-top: 1.5rem;
}

/* URL input with extract button */
.url-input-group {
    display: flex;
    gap: 0.5rem;
}

.url-input-group input {
    flex: 1;
}

/* Preview card in add form */
.scrape-preview {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
    margin-bottom: 1.5rem;
    animation: fadeIn 0.3s ease;
}

.scrape-preview .preview-thumb {
    width: 100%;
    aspect-ratio: 16/9;
    border-radius: var(--radius-sm);
    overflow: hidden;
    background: var(--border);
    margin-bottom: 1rem;
}

.scrape-preview .preview-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.scrape-preview h3 {
    font-family: var(--font-heading);
    font-size: 1.1rem;
    margin-bottom: 0.5rem;
}

.scrape-preview .preview-source {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
}

.scrape-preview .preview-desc {
    font-size: 0.85rem;
    color: var(--text-light);
    max-height: 4.5em;
    overflow: hidden;
}

/* Tag input */
.tag-input-wrapper {
    display: flex;
    flex-wrap: wrap;
    gap: 0.375rem;
    padding: 0.5rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    cursor: text;
    min-height: 44px;
    align-items: center;
}

.tag-input-wrapper:focus-within {
    border-color: var(--accent);
}

.tag-input-wrapper .tag-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.25rem 0.5rem;
    border-radius: 100px;
    background: var(--accent);
    color: white;
    font-size: 0.8rem;
    font-weight: 500;
}

.tag-input-wrapper .tag-chip button {
    background: none;
    border: none;
    color: white;
    cursor: pointer;
    font-size: 1rem;
    line-height: 1;
    opacity: 0.7;
    padding: 0;
}

.tag-input-wrapper .tag-chip button:hover {
    opacity: 1;
}

.tag-input-wrapper input {
    border: none;
    outline: none;
    font-family: var(--font-body);
    font-size: 0.85rem;
    min-width: 100px;
    flex: 1;
    padding: 0.25rem;
    background: transparent;
    color: var(--text);
}

/* Loading spinner */
.spinner {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 2px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

.loading-overlay {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 4rem;
    gap: 0.75rem;
    color: var(--text-muted);
}

/* Empty state */
.empty-state {
    text-align: center;
    padding: 4rem 2rem;
    color: var(--text-muted);
}

.empty-state .icon {
    font-size: 3rem;
    margin-bottom: 1rem;
}

.empty-state h2 {
    font-family: var(--font-heading);
    font-size: 1.5rem;
    color: var(--text-light);
    margin-bottom: 0.5rem;
}

.empty-state p {
    margin-bottom: 1.5rem;
}

/* Toast notifications */
.toast {
    position: fixed;
    bottom: 1.5rem;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: var(--text);
    color: white;
    padding: 0.75rem 1.5rem;
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    z-index: 1000;
    transition: transform 0.3s ease;
    box-shadow: var(--shadow-lg);
}

.toast.show {
    transform: translateX(-50%) translateY(0);
}

/* Animations */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Pull to refresh */
#pull-indicator {
    height: 0;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    font-size: 0.8rem;
    transition: height 0.2s ease, opacity 0.2s ease;
}

/* Responsive */
@media (max-width: 640px) {
    .header { padding: 0.75rem 1rem; }
    .toolbar { padding: 0 1rem; margin: 1rem auto; }
    .recipe-grid { padding: 0 0.75rem 2rem; gap: 0.75rem; grid-template-columns: repeat(2, 1fr); }
    .recipe-card .card-overlay .card-title { font-size: 0.95rem; }
    .recipe-card .card-body { padding: 0.5rem 0.75rem 0.75rem; }
    .recipe-card .card-desc { font-size: 0.72rem; -webkit-line-clamp: 1; }
    .search-box--narrow { flex: 0 1 160px; min-width: 120px; }
    .quick-add { min-width: 160px; }
    .recipe-detail { padding: 0 0.75rem 2rem; }
    .recipe-detail .hero-image { width: calc(100% + 1.5rem); margin-left: -0.75rem; }
    .recipe-detail .detail-header { padding: 1.25rem 1.25rem; margin-top: -2rem; border-radius: 14px; }
    .recipe-detail h1 { font-size: 1.5rem; }
    .recipe-content { padding: 1.25rem 1.25rem; border-radius: 14px; }
    .recipe-detail .actions { padding: 1rem 1.25rem; border-radius: 14px; }
    .form-view { padding: 0 1rem; margin: 1rem auto; }
}

/* Confirm dialog */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(44, 36, 32, 0.4);
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.2s ease;
}

.modal {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 2rem;
    max-width: 400px;
    width: 90%;
    box-shadow: var(--shadow-lg);
}

.modal h3 {
    font-family: var(--font-heading);
    margin-bottom: 0.75rem;
}

.modal p {
    color: var(--text-light);
    margin-bottom: 1.5rem;
    font-size: 0.9rem;
}

.modal .modal-actions {
    display: flex;
    gap: 0.75rem;
    justify-content: flex-end;
}
