/* --- 1. CORE VARIABLES & RESET --- */
:root {
    --bg-main: #ffffff;
    --bg-alt: #f8f9fa;
    --text-main: #1a1a1a;
    --text-muted: #666;
    --accent-green: #28a745;
    --danger: #d9534f;
    --border: #eeeeee;
    --shadow: 0 4px 12px rgba(0,0,0,0.08);
    --toolbar-height: 73px;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    /* Fixes the "multiple scrollbars" issue */
    height: auto;
    overflow-x: hidden;
    overflow-y: auto; 
    background-color: var(--bg-main);
    font-family: system-ui, sans-serif;
    color: var(--text-main);
}

/* --- 2. FIXED TOOLBAR --- */
.toolbar {
    position: fixed;
    top: 0;
    width: 100%;
    height: var(--toolbar-height);
    background: whitesmoke;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    z-index: 1000;
    border-bottom: 1px solid #eee;
}

.nav-left, .nav-right { display: flex; align-items: center; }

#status {
    color: #888;
    font-size: 0.8rem;
    margin-left: 15px;
}

/* --- 3. BUTTONS & CONTROLS --- */
.btn {
    padding: 8px 16px;
    border-radius: 6px;
    border: none;
    color: white;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    font-size: 0.9rem;

    display: inline-flex;       /* Helps with alignment */
    align-items: center;        /* Centers text/icons vertically */
    justify-content: center;
    font-family: inherit;       /* IMPORTANT: Prevents <button> from using system default font */
    font-size: 1rem;            /* Ensures font size is consistent */
    padding: 10px 20px;         /* Standardizes the footprint */
    cursor: pointer;
    border: none;               /* Removes default button borders */
    text-decoration: none;      /* Removes underlines from <a> tags */
    height: 40px;
}

.btn-secondary { background: #b2babf; }
.btn-save { background: var(--accent-green); margin-left: 10px; }
.btn-delete { background: var(--danger); margin-left: 10px; }

.tool-btn[title="Clear formatting"]:hover {
    background-color: #f8d7da; /* Light red/pink tint */
    color: #721c24;
}

.formatting-controls {
    display: flex;
    gap: 5px;
    margin: 0 20px;
    padding-left: 20px;
}

.tool-btn {
    background: #333;
    color: white;
    border: 1px solid #444;
    padding: 5px 12px;
    border-radius: 4px;
    cursor: pointer;
    font-weight: bold;
}

.draft {
    border: 1px solid #444;
    padding: 5px 12px;
    border-radius: 4px;
    cursor: pointer;
    font-weight: bold;
}

.tool-btn:hover { background: #555; }

/* --- 4. RECIPE GRID (Gallery View) --- */
.recipe-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 30px;
    padding: calc(var(--toolbar-height) + 40px) 20px 40px;
    justify-content: center;
    max-width: 1300px;
    margin: 0 auto;
}

.recipe-card-link {
    text-decoration: none;
    color: inherit;
    transition: transform 0.2s ease;
}

.recipe-card-link:hover { transform: translateY(-5px); }

.recipe-card {
    width: 280px;
    background: white;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    position: relative;
}

.recipe-card img {
    width: 100%;
    height: 180px;
    object-fit: cover;
}

.recipe-info { padding: 15px; }
.recipe-info h3 { margin: 0 0 5px 0; font-size: 1.1rem; }

.recipe-intro {
    color: var(--text-muted);
    font-size: 0.85rem;

    display: -webkit-box;
    -webkit-line-clamp: 3; /* Limit to 3 lines */
    -webkit-box-orient: vertical;  
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.5em; /* Adjust based on your font */
    max-height: 4.5em;  /* line-height * 3 */
}

.recipe-card .tags {
    color: var(--text-muted);
    font-size: 0.85rem;
}

/* --- 5. RICH EDITOR LAYOUT --- */
.editor-main {
    max-width: 800px;
    margin: var(--toolbar-height) auto 0;
    padding: 40px 20px;
}

/* Heading #1 Title Input */
.h1-input {
    width: 100%;
    border: none;
    font-size: 3.5rem;
    font-weight: 800;
    margin-bottom: 20px;
    outline: none;
    letter-spacing: -1px;
}

/* Thumbnail Section */
.thumbnail-section {
    margin-bottom: 40px;
    text-align: center;
}

#thumbnail-preview {
    width: 100%;
    max-height: 450px;
    object-fit: cover;
    border-radius: 12px;
    box-shadow: var(--shadow);
    background: var(--bg-alt);
}

.btn-upload {
    margin-top: 15px;
    background: var(--bg-alt);
    border: 1px solid var(--border);
    padding: 8px 20px;
    border-radius: 20px;
    cursor: pointer;
    font-weight: 500;
}

/* The container for your rich text */
.rich-editor {
    line-height: 1.6;
    font-size: 1.1rem;
    color: #333;
    outline: none;
    white-space: pre-wrap; /* Crucial for keeping your newlines intact */
}

.rich-editor h2 {
    display: block;
    font-size: 1.8rem;
    font-weight: bold;
    color: #222;
    margin: 15px 0 5px 0;
}

.rich-editor h3 {
    display: block;
    font-size: 1.4rem;
    font-weight: bold;
    color: #444;
    margin: 12px 0 4px 0;
}


/* --- 6. UTILITIES --- */
[contenteditable]:empty:before {
    content: attr(placeholder);
    color: #aaa;
}

/* Ensure the editor feels like a text document */
.rich-editor {
    white-space: pre-wrap; /* Keeps newlines */
    min-height: 300px;
    outline: none;
    line-height: 1.6;
}

.rich-editor h2 {
    display: block;
    font-size: 1.8em !important;
    font-weight: bold !important;
    margin: 1em 0 0.5em 0 !important;
    color: #333;
}

.rich-editor h3 {
    display: block;
    font-size: 1.4em !important;
    font-weight: bold !important;
    margin: 1em 0 0.5em 0 !important;
    color: #555;
}

.rich-editor div, .rich-editor p {
    margin-bottom: 10px;
    min-height: 1em;
}

/* Image Preview Styling */
#thumbnail-preview {
    width: 100%;
    max-height: 450px;
    object-fit: cover;
    border-radius: 12px;
    display: block;
}

/* Ensure the editor knows how to display these tags */
#editor-content h2 {
    display: block !important;
    font-size: 24px !important;
    font-weight: bold !important;
    margin: 15px 0 5px 0 !important;
    color: #1a1a1a;
}

#editor-content h3 {
    display: block !important;
    font-size: 20px !important;
    font-weight: bold !important;
    margin: 12px 0 5px 0 !important;
    color: #333;
}

/* Fallback: if the text is stuck in a 'div' or 'p', 
   make sure there is space between lines */
#editor-content div, #editor-content p {
    margin-bottom: 5px;
}

#editor-content p {
    margin: 0 0 10px 0; /* Adds consistent spacing between lines */
    min-height: 1em;    /* Keeps empty lines from collapsing */
}

#editor-content h2, #editor-content h3 {
    margin-top: 1em;
    margin-bottom: 0.5em;
    display: block; /* Ensures they take up the whole line */
}

#editor-content div, #editor-content p {
    min-height: 1.2em; /* Prevents empty lines from collapsing */
}

/* The container for the images */
#image-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 15px;
    padding: 10px;
}

.modal {
    display: none; position: fixed; z-index: 1000; left: 0; top: 0; 
    width: 100%; height: 100%; background: rgba(0,0,0,0.5);
    justify-content: center; align-items: center;
}
.modal-content {
    background: white; padding: 20px; border-radius: 8px; width: 400px; overflow-y: auto;
}

/* The actual images in the modal */
.modal-grid-img {
    width: 100%;
    height: 120px; /* Force a square/fixed height */
    object-fit: cover; /* This crops the image so it doesn't stretch */
    border-radius: 8px;
    cursor: pointer;
    border: 3px solid transparent;
    transition: transform 0.2s, border-color 0.2s;
    background: #eee; /* Shows gray while loading */
}

.modal-grid-img:hover {
    transform: scale(1.05);
    border-color: #007bff;
}

/* Container for each image in the grid */
.img-container {
    position: relative;
    display: inline-block;
    width: 100%;
}

/* The delete "X" button */
.delete-btn {
    position: absolute;
    top: 5px;
    right: 5px;
    background: rgba(255, 0, 0, 0.7);
    color: white;
    border: none;
    border-radius: 50%;
    width: 24px;
    height: 24px;
    cursor: pointer;
    display: none; /* Hidden by default */
    align-items: center;
    justify-content: center;
    font-weight: bold;
    z-index: 10;
}

/* Show button on hover */
.img-container:hover .delete-btn {
    display: flex;
}

.delete-btn:hover {
    background: red;
}

/* Highlight the active block slightly (optional but helpful) */
#editor-content h2:focus, #editor-content h3:focus {
    outline: none;
    background-color: rgba(0,0,0,0.02);
}

/* Ensure the editor always has a minimum height even when empty */
#editor-content:empty::before {
    content: "Start writing your recipe...";
    color: #aaa;
    pointer-events: none;
}

/* Prevent image resizing issues in the editor */
#editor-content img {
    max-width: 100%;
    height: auto;
    border-radius: 8px;
    margin: 10px 0;
}

.save-btn {
    background-color: #28a745; /* A success green color */
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 6px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
    margin-left: 10px;
}

.save-btn:hover {
    background-color: #218838;
}

/* Site header - Public recipies */
.main-header {
    text-align: center;
    width: 100%;
}

.main-header h1 {
    display: inline;
    font-size: 2rem;
    color: #333;
    font-weight: 700;
}

.tagline {
    font-size: 1.1rem;
    color: #666;
    font-style: italic;
    font-weight: 300;
}

.toolbar button.active {
    background-color: #007bff; /* Bright blue */
    color: white;
    border-color: #0056b3;
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.2);
}

.formatting-controls button.active {
    background-color: #007bff !important;
    color: white !important;
    border-color: #0056b3;
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.2);
}


/* Default: Hide the short title, show the full title and tagline */
.title-short {
    display: none;
}

.title-full {
    display: block;
    margin: 0;
}

.tagline {
    display: inline;
}

/* Small Screens (Mobile) */
/* Default state (Desktop) */
.title-short { display: none; } 

@media (max-width: 1000px) {
    /* Hide the bulk */
    .title-full, .tagline { 
        display: none; 
    }
    
    /* Show the compact version */
    .title-short::before {
        font-weight: bold;
        font-size: 1.5rem;
    }
    .title-short {
        display: block;
    }
}
    
    /* Optional: Ensure the header doesn't take up too much vertical space */
    .logo-container {
        display: flex;
        align-items: center;
    }
}

.recipe-intro {
    display: -webkit-box;
    -webkit-line-clamp: 3; /* Show exactly 3 lines */
    -webkit-box-orient: vertical;  
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Search */

/* End of search */

/* Container to sit next to 'Explore' */
.nav-left {
    display: flex;
    align-items: center;
    gap: 15px;
    flex: 1; /* Giver den lov til at fylde den nødvendige plads */
}

.header-search-form {
    display: flex;
    align-items: center;
}

#search-input {
    width: 40px; /* Start small (icon size) */
    height: 35px;
    padding: 8px 8px 8px 35px; /* Extra left padding for the icon */
    border: 1px solid transparent;
    border-radius: 20px;
    outline: none;
    transition: all 0.3s ease;
    cursor: pointer;

    border: none;
    background: transparent;
    outline: none;

    /* Allow the input to take all remaining space inside the 500px wrapper */
    flex-grow: 1; 
    font-size: 0.95rem;

    /* THE ICON LOGIC */
    background-color: #f4f4f4;
    background-image: url('/assets/icons/search.svg');
    background-repeat: no-repeat;
    background-position: 10px center; /* Positions icon on the left */
    background-size: 18px;

            border: 1px solid #ddd;
}

/* Individual styles for Search and Select */
#search-input, 
.header-tag-select {
    padding: 8px 8px 8px 35px; /* Extra left padding for the icon */
    border-radius: 20px;
    border: 1px solid transparent;
    background-color: rgba(255, 255, 255, 0.6); /* Semi-transparent start */
    transition: all 0.3s ease; /* This creates the "fade" effect */
    outline: none;
    max-width: 180px;

}

/* Individual Fade-In on Hover/Focus */
#search-input:hover, 
#search-input:focus,
.header-tag-select:hover,
.header-tag-select:focus {
    background-color: #ffffff; /* Fades to pure white */
    border-color: #ddd;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}


/* Specifically for the dropdown */
.header-tag-select {
    flex: 1;
    cursor: pointer;
    appearance: none; /* Optional: cleaner look */
    text-align: center;
}
    
.search-btn {display: none;}

/* The main container - keeps everything stable */
.search-wrapper {
    display: flex;
    align-items: center;
    gap: 15px;
    padding: 5px;
    width: 320px; /* Fixed width to prevent layout jumping */
}



.header-tag-select {
    border: none;
    background: transparent;
    background-color: white;
    outline: none;
    color: #666;
    font-size: 0.9rem;
    cursor: pointer;
    border-left: 1px solid #ccc;
    padding-left: 10px;
    /* Prevent the dropdown from shrinking */
    flex-shrink: 0; 

        background-color: rgba(255, 255, 255, 0.6); /* Semi-transparent start */
    transition: all 0.3s ease; /* This creates the "fade" effect */
}

}



/* Optional: Make icon slightly transparent when not focused */
#search-input:not(:focus) {
    opacity: 0.8;
    width: 100%;
}

.tag-list-container {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 20px;
    padding: 10px 0;
}

.tag-link {
    padding: 6px 15px;
    background: #f0f0f0;
    border-radius: 20px;
    text-decoration: none;
    color: #333;
    font-size: 0.9em;
    transition: background 0.2s;
}

.tag-link:hover {
    background: #e0e0e0;
}

.tag-link.active {
    background: #007bff;
    color: white;
}


/* Centers the content and adds padding to the sides of the text */
.view-page .content-display {
    max-width: 900px;
    margin: 100px auto;
    padding: 0 20px; /* This creates the text margins */
    line-height: 1.6;
    color: #333;
}

.view-page .content-display .content {
max-width: 500px;
display: block;
margin-top: 50px;
 
}

/* Styles the recipe image */
.view-page .recipe-image-container {
    width: 100%;
    margin: 0 auto 0px auto;
}

.view-page .recipe-image-container img {
    width: 100%;
    height: auto;
    display: block;
    /* Rounded corners and Shadow */
    border-radius: 15px; 
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.15);
}

/* Optional: style the title specifically in view mode */
.view-page .content-display h1 {
    margin-bottom: 20px;
    font-size: 2.5rem;
    text-align: center;
}

/* A reusable container for centering content on the page */
.container-centered {
    max-width: 1000px;
    margin: 40px auto;
    padding: calc(var(--toolbar-height) + 10px) 20px 40px;
}

.settings-grid {
    display: grid;
    gap: 20px;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    margin-bottom: 20px; /* Space between grid and back button */
}

/* On large screens, keep the content from spreading too wide */
@media (min-width: 1200px) {
    .settings-grid {
        max-width: 1000px; /* Adjust this number to your liking */
    }
}

/* Styles for the saved recipes checkbox that looks like a heart next to the categories filter in the header on the public page. */
.heart-filter {
    display: flex;
    align-items: center;
    cursor: pointer;
    padding: 0 15px;
    font-size: 1.5rem;
    border-left: 1px solid #ddd; /* Adskiller det visuelt fra select-menuen */
}

.heart-filter input {
    display: none; /* Hide the actual checkbox */
}

.heart-icon {
    font-size: 1.2rem;
    color: #ccc; /* Gråt når inaktivt */
    transition: transform 0.2s, color 0.2s;
}

/* Styling af hjerte-knappen */
.heart-filter-label {
    cursor: pointer;
    display: flex;
    align-items: center;
    margin: 0 10px;
}

.heart-filter-label input {
    display: none; /* Skjuler selve checkboxen */
}

.heart-icon {
    font-size: 1.2rem;
    transition: color 0.2s, transform 0.2s;
    color: #ccc; /* Gråt som standard */
}

/* Når checkboxen er "checked", gør hjertet lige ved siden af rødt */
.heart-filter-label input:checked + i {
    color: #ff4b2b !important;
}

/* Gør hjertet lidt større når man holder musen over det */
.heart-filter-label:hover i {
    transform: scale(1.1);
    transition: transform 0.2s;
}

/* Selve baggrunden der dækker skærmen */
.modal {
    display: none; 
    position: fixed; 
    z-index: 2000; 
    left: 0;
    top: 0;
    width: 100%; 
    height: 100%; 
    background-color: rgba(0,0,0,0.7); /* Mørk gennemsigtig baggrund */
    backdrop-filter: blur(5px); /* Gør baggrunden sløret for fokus */
}

/* Den hvide boks i midten */
.modal-content {
    background-color: #fff;
    margin: 5% auto; 
    padding: 25px;
    border-radius: 12px;
    width: 80%;
    max-width: 900px;
    max-height: 80vh;
    overflow-y: auto; /* Tillader scroll hvis der er mange billeder */
    position: relative;
    box-shadow: 0 10px 30px rgba(0,0,0,0.3);
}

/* Luk-knappen (X) */
.close {
    color: #aaa;
    float: right;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
    line-height: 1;
}

.close:hover {
    color: #333;
}

.media-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 15px;
    margin-top: 20px;
}

.media-grid img {
    width: 100%;
    height: 150px;
    object-fit: cover; /* Sikrer at billederne ikke bliver strukket */
    border-radius: 8px;
    cursor: pointer;
    transition: transform 0.2s, border-color 0.2s;
    border: 3px solid transparent;
}

.media-grid img:hover {
    transform: scale(1.05);
    border-color: #007bff; /* Blå kant når man holder musen over */
}

.btn-delete-overlay {
    background: rgba(220, 53, 69, 0.9);
    color: white;
    border: none;
    border-radius: 50%;
    width: 30px;
    height: 30px;
    cursor: pointer;
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.btn-delete-overlay:hover {
    background: #c82333;
}


.media-item {
    position: relative;
    transition: transform 0.2s;
}

.media-item img {
    width: 100%;
    height: 150px;
    object-fit: cover;
    border-radius: 8px;
    cursor: pointer;
    display: block;
}

/* Placer slette-krydset øverst til højre på hvert billede i galleriet */
.media-item .btn-delete-overlay {
    position: absolute;
    top: 5px;
    right: 5px;
    background: rgba(220, 53, 69, 0.8);
    color: white;
    border: none;
    border-radius: 50%;
    width: 25px;
    height: 25px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    opacity: 0; /* Skjul indtil musen er over */
    transition: opacity 0.2s;
}

.media-item:hover .btn-delete-overlay {
    opacity: 1; /* Vis kryds ved hover */
}

.media-item:hover img {
    filter: brightness(0.8);
}

.media-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 15px;
    align-items: start; /* Holder rækkerne stabile */
}

.media-item {
    aspect-ratio: 1 / 1; /* Gør alle felter kvadratiske på forhånd */
    background: #f0f0f0; /* Viser en grå boks mens billedet loader */
    border-radius: 8px;
    overflow: hidden;
    position: relative;
}

.media-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.modal-upload-bar {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
}

/* Gør det tydeligt at man kan klikke på billederne for at vælge dem */
.media-item img {
    border: 2px solid transparent;
    transition: border-color 0.2s;
}

.media-item img:hover {
    border-color: #007bff;
}

/* 1. Setup the toolbar as the grid container */
.toolbar {
    display: grid;
    /* 1fr (left) | auto (center logo) | 1fr (right) */
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    width: 100%;
    padding: 0px 20px;
    box-sizing: border-box;
}

/* 2. Target the custom <site_title> tag from header.ejs */
site_title {
    grid-column: 2; /* Forces it to the middle column */
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
}

/* 3. Ensure the side containers stay in their respective zones */
.nav-left {
    grid-column: 1;
    display: flex;
    justify-content: flex-start;
    align-items: center;
}

.nav-right {
    grid-column: 3;
    display: flex;
    justify-content: flex-end;
    align-items: center;
}