/* ==========================================================================
   KEN UNIFIED STYLESHEET
   ========================================================================== */

/* ==========================================================================
   1. ROOT VARIABLES (from root.css)
   ========================================================================== */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;700&family=VT323&display=swap');

:root {
    --font-main: 'Inter', sans-serif;
    --font-accent: 'VT323', monospace;
    --color-bg-dither-1: #f0f0f0;
    --color-bg-dither-2: #e0e0e0;
    --color-surface: #ffffff;
    --color-text: #222222;
    --color-supplementary-text: rgb(102, 102, 102, 0.5);
    --color-border: #999999;
    --color-shadow: rgba(0, 0, 0, 0.1);
    --color-highlight-teal: rgb(0, 128, 124);
    --color-bg-teal: rgba(0, 128, 124, 0.3);
    --color-highlight-pink: rgb(255, 0, 255);
    --color-bg-pink: rgba(255, 0, 255, 0.3);
    --color-highlight-gold: rgb(255, 191, 0);
    --color-bg-gold: rgba(255, 191, 0, 0.3);
    --color-dark-gold: rgb(204, 153, 0);
    --color-highlight-blue: rgb(0, 68, 170);
    --color-bg-blue: rgba(0, 68, 170, 0.3);
    --font-size-base: 18px;
    --font-size-h1: calc(var(--font-size-base) * 1.6 * 1.25);
    --font-size-h2: calc(var(--font-size-base) * 1.25);
    --font-size-h3: 1rem;
    --spacing-unit: 10px;
    --border-width: 1px;
    --border-radius: 3px;
}

/* ==========================================================================
   2. GLOBAL STYLES & RESETS (from mac_theme.css)
   ========================================================================== */

body {
    font-family: var(--font-main);
    font-size: calc(var(--font-size-base) * 0.8);
    color: var(--color-text);
    line-height: calc(var(--font-size-base) * 1);
    background-color: var(--color-bg-dither-2);
    background-image: linear-gradient(45deg, var(--color-bg-dither-1) 25%, transparent 25%, transparent 75%, var(--color-bg-dither-1) 75%),
                      linear-gradient(45deg, var(--color-bg-dither-1) 25%, transparent 25%, transparent 75%, var(--color-bg-dither-1) 75%);
    background-size: 4px 4px;
    background-position: 0 0, 2px 2px;
}

h1, h2, h3, h4, h5, h6 {
    font-family: var(--font-main);
    font-weight: normal;
    line-height: 1.2;
    margin-bottom: calc(var(--spacing-unit) * 1.6);
}
h1 { font-size: var(--font-size-h1); }
main > h1 { margin-top: 0; }
h2 { font-size: var(--font-size-h2); }
h3 { font-size: var(--font-size-h3); }

a {
    color: var(--color-highlight-blue);
    text-decoration: none;
    border-bottom: 1px dotted var(--color-highlight-pink);
}
a:hover {
    background-color: var(--color-highlight-blue);
    color: var(--color-surface);
}
a.wikilink-new {
    color: var(--color-highlight-teal);
    text-decoration: none;
    border-bottom: 1px dotted var(--color-highlight-gold);
}
/* ==========================================================================
   3. CORE RESPONSIVE LAYOUT
   ========================================================================== */

/* --- Mobile First (Single Column) --- */
header, footer {
    width: 100%;
    box-sizing: border-box;
}
.page-container > aside.dashboard {
    margin-top: 2.5rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--color-border);
}

/* --- Wide Screen (Multi-Column) --- */
@media (min-width: 900px) {
    body {
        display: grid;
        grid-template-columns: 1fr minmax(0, 820px) 1fr;
        grid-template-rows: auto 1fr auto;
        grid-template-areas:
            ". header ."
            ". content ."
            ". footer .";
        gap: var(--spacing-unit);
    }

    header { grid-area: header; }
    .page-container { grid-area: content; }
    footer { grid-area: footer; }

    /* The main content area becomes a nested grid for main + dashboard */
    .page-container {
        display: grid;
        grid-template-columns: 1fr 320px;
        gap: calc(var(--spacing-unit) * 2);
        align-items: start;
    }

    /* Reset mobile-only styles */
    .page-container > aside.dashboard {
        margin-top: 0;
        padding-top: 0;
        border-top: none;
    }
}

/* ==========================================================================
   4. COMPONENTS
   ========================================================================== */

/* --- Main Page Container --- */
.page-container {
    background-color: var(--color-surface);
    border: var(--border-width) solid var(--color-border);
    border-radius: var(--border-radius);
    box-shadow: 0 calc(var(--spacing-unit) / 2) calc(var(--spacing-unit) * 2) var(--color-shadow);
    padding: calc(var(--spacing-unit) * 2);
    margin-top: calc(var(--spacing-unit) * 1);
    margin-bottom: calc(var(--spacing-unit) * 1);
}

/* --- Hamburger Nav & Site Actions (from custom_structure.css) --- */
.nav {
    position: fixed; /* Changed to fixed for better mobile experience */
    top: 10px;
    right: 10px;
    z-index: 1000;
}
.hamburger-button {
    display: block;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius);
    padding: var(--spacing-unit);
    cursor: pointer;
}
.hamburger-button .bar {
    display: block;
    width: 25px;
    height: 3px;
    margin: 5px auto;
    background-color: var(--color-text);
    transition: all 0.3s ease-in-out;
}
.hamburger-button.is-active .bar:nth-child(1) { transform: translateY(8px) rotate(45deg); }
.hamburger-button.is-active .bar:nth-child(2) { opacity: 0; }
.hamburger-button.is-active .bar:nth-child(3) { transform: translateY(-8px) rotate(-45deg); }

.top-nav-links {
    display: none;
    position: absolute;
    top: 100%;
    right: 0;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    box-shadow: 0 4px 8px var(--color-shadow);
    border-radius: var(--border-radius);
    padding: var(--spacing-unit);
    min-width: 250px;
}
.top-nav-links.is-active { display: block; }
.site-actions {
    list-style-type: none;
    padding: 0;
    margin: 0;
}
.site-actions li { margin-bottom: var(--spacing-unit); }

/* --- Flash Messages (from messages.css) --- */
.flash-messages {
    position: fixed;
    bottom: 1rem;
    right: 1rem;
    width: 100%;
    max-width: 350px;
    z-index: 1050;
    list-style-type: none;
    padding: 0;
    margin: 0;
}
.flash-messages li {
    position: relative;
    font-family: var(--font-mono);
    padding: 1rem 2.5rem 1rem 1.5rem;
    margin-bottom: 1rem;
    border: 1px dotted;
    border-radius: 2px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    transition: opacity 0.3s ease-in-out;
}
.flash-messages .success { background-color: var(--color-bg-teal); border-color: var(--color-highlight-teal); color: var(--color-highlight-teal); }
.flash-messages .error   { background-color: var(--color-bg-gold); border-color: var(--color-highlight-gold); color: var(--color-dark-gold); }
.flash-messages .info    { background-color: var(--color-bg-blue); border-color: var(--color-highlight-blue); color: var(--color-highlight-blue); }

.flash-dismiss {
    position: absolute;
    top: 0.5rem;
    right: 0.75rem;
    background: none;
    border: none;
    font-size: 1.5rem;
    line-height: 1;
    font-weight: bold;
    color: inherit;
    opacity: 0.4;
    cursor: pointer;
    padding: 0;
}
.flash-dismiss:hover { opacity: 0.8; }


/* --- Compact Snippet Box (from custom_structure.css) --- */
.snippet-list {
    display: grid;
    grid-template-columns: 1fr; /* Single column snippets by default */
    gap: 0.625em;
}
.snippet-box {
    height: calc(var(--spacing-unit) * 14);
    display: flex;
    position: relative;
    background-color: var(--color-surface);
    background-size: cover;
    background-position: center;
    border: var(--border-width) solid #ddd;
    border-radius: var(--border-radius);
    overflow: hidden;
    transition: box-shadow 0.2s ease-in-out;
}
.snippet-box:hover { box-shadow: 0 4px 15px rgba(0,0,0,0.15); }

.snippet-box-content {
    width: 100%;
    display: flex;
    flex-direction: column;
    padding: 0.625em;
    position: relative;
    z-index: 2;
}
.snippet-box h3, .snippet-box p {
    margin: 0;
    padding: 0;
    line-height: 1.3;
}
.snippet-box h3 a {
    color: var(--color-text);
    text-decoration: none;
    border-bottom: none;
    font-size: 1.05em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.snippet-box h3 a:hover {
    background-color: transparent;
    color: var(--color-highlight-pink);
}
.snippet-box .snippet-text {
    font-size: 0.9em;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.snippet-meta, .snippet-slugline {
    margin-top: auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.8em;
    padding-top: 0.625em;
    border-top: 1px solid #eee;
}
.snippet-slugline {
    justify-content: left;
    border-top: none;
    margin-top: 0;
    margin-bottom: auto;
    padding-top: 0;
    padding-bottom: 0; 
}
.snippet-slugline p:first-child::after { content: " /  "; padding-right: 0.2em; }  
.snippet-slugline p:last-child::after { content: ""; padding-right: 0.2em; }  
                                         
.snippet-box[style*="background-image"] .snippet-meta { border-top: 1px solid rgba(255, 255, 255, 0.2); }

.snippet-box[style*="background-image"]::before {
    content: '';
    position: absolute;
    inset: 0;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 1;
}
.snippet-box[style*="background-image"] h3 a,
.snippet-box[style*="background-image"] p {
    color: #fff;
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.7);
    border-bottom: none;
}
.snippet-box.has-gradient-bg h3 a,
.snippet-box.has-gradient-bg p {
    color: var(--color-text);
    text-shadow: none;
}
.gradient-1 { background: linear-gradient(45deg, var(--color-bg-teal), var(--color-bg-blue)); }
.gradient-2 { background: linear-gradient(135deg, var(--color-bg-pink), var(--color-bg-gold)); }
.gradient-3 { background: linear-gradient(45deg, var(--color-bg-gold), var(--color-bg-teal)); }
.gradient-4 { background: linear-gradient(135deg, var(--color-bg-blue), var(--color-bg-pink)); }

/* --- Other Components --- */
header div.site-name {
    font-size: 2.0rem;
    font-weight: bold;
    text-transform: uppercase;
    color: var(--color-text);
    text-decoration: none;
    padding-top: calc(var(--spacing-unit)/2);
}   
header div.site-name a {
    color: var(--color-text);
    text-decoration: none;
}
.standfirst {
    font-size: 1.1rem;
    color: var(--color-supplementary-text);
    padding-bottom: calc(var(--spacing-unit) * 1.6);
    border-bottom: 1px dotted var(--color-border);
    margin-bottom: 0;
}
.page-metadata, .page-actions {
    color: var(--color-supplementary-text);
    font-size: 0.9rem;
    list-style: none;
    padding: calc(var(--spacing-unit) * 1.6) 0;
    margin: 0;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px dotted var(--color-border);
}
.page-metadata p, .page-actions p { margin: 0; color: var(--color-supplementary-text); }
.page-metadata li, .page-actions li { margin-right: calc(var(--spacing-unit) * 1/1.6); }

button {
    font-family: var(--font-main);
    font-weight: bold;
    background-color: #f0f0f0;
    border: var(--border-width) solid var(--color-border);
    border-radius: var(--border-radius);
    padding: var(--spacing-unit) calc(var(--spacing-unit) * 2);
    font-size: 0.9rem;
    text-decoration: none;
    color: var(--color-text);
    cursor: pointer;
    transition: all 0.1s ease-in-out;
}
button:hover {
    background-color: var(--color-highlight-gold);
    border-color: var(--color-text);
}

.main-image-container {
    width: 100%;
    margin: 1em auto 1.5em auto;
}
.main-image-container img {
    width: 100%;
    height: auto;
    display: block;
}
.main-image-container figcaption {
    font-size: 0.8em;
    color: var(--color-supplementary-text);
}
.main-image-container .caption { 
    display: inline; 
}
.main-image-container .image-credits { list-style-type: none; display: inline; margin: 0; padding: 0;}
.main-image-container .image-credits::before { content: "("}
.main-image-container .image-credits::after { content: ")"}
.main-image-container .image-credits li { display: inline; list-style-type: none; }
.main-image-container .image-credits li:not(:first-child)::before { content: ", "; }

.media-grid {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-bottom: calc(var(--spacing-unit) * 2);
}
.media-item {
    width: 200px;
    max-width: 200px;
    margin-bottom: calc(var(--spacing-unit) * 2);
}
.media-item img {
    width: 100%;
    height: auto;
    border-radius: var(--border-radius);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}
@media (min-width: 768px) {
    .main-image-container.portrait,
    .main-image-container.square {
        width: 48%;
        float: right;
        margin-left: 1.5em;
        margin-top: 0.5em;
    }
    .content::after {
        content: "";
        display: table;
        clear: both;
    }
}

/* ==========================================================================
   KEN ADMIN & FUNCTIONAL PAGE STYLES
   ========================================================================== */

/* ==========================================================================
   1. FORMS (Create Page, Search)
   ========================================================================== */
/* ... existing form styles ... */
form {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-unit);
}
input[type="text"],
input[type="search"] {
    font-family: var(--font-main);
    font-size: 1.2rem;
    padding: var(--spacing-unit);
    border: var(--border-width) solid var(--color-border);
    border-radius: var(--border-radius);
    background-color: var(--color-surface);
    color: var(--color-text);
}
input[type="text"]:focus,
input[type="search"]:focus {
    outline: 2px solid var(--color-highlight-blue);
    border-color: var(--color-highlight-blue);
}
.search-form {
    flex-direction: row;
    align-items: center;
    margin-bottom: calc(var(--spacing-unit) * 2);
}
.search-form .search-input {
    flex-grow: 1;
}
.search-form .search-button {
    padding: var(--spacing-unit);
    background-color: var(--color-highlight-blue);
    color: var(--color-surface);
    border: none;
}
.search-form .search-button:hover {
    background-color: var(--color-text);
}

/* ==========================================================================
   2. LISTS (Search Results, History, Namespace)
   ========================================================================== */
/* ... existing list styles ... */
.results-list,
.revisions,
.namespace-listing ul {
    list-style: none;
    padding: 0;
    margin-top: calc(var(--spacing-unit) * 2);
}
.results-list li,
.revisions li,
.namespace-listing li {
    padding: var(--spacing-unit) 0;
    border-bottom: 1px solid var(--color-bg-dither-1);
}
.results-list .result-title {
    font-size: 1.2em;
    font-weight: bold;
}
.results-list .result-url {
    font-size: 0.9em;
    color: var(--color-supplementary-text);
    margin-bottom: 0.5em;
}
.results-list .result-score {
    font-size: 0.8em;
    font-family: var(--font-accent);
    color: var(--color-highlight-teal);
}
.revisions .revision-byline {
    margin-left: 1.5em;
    font-size: 0.9em;
    color: var(--color-supplementary-text);
}
.namespace-listing {
    margin-top: calc(var(--spacing-unit) * 2);
}
.namespace-listing ul {
    -webkit-columns: 2;
    -moz-columns: 2;
    columns: 2;
    gap: calc(var(--spacing-unit) * 2);
}
.namespace-listing a {
    font-family: var(--font-accent);
    font-size: 1.1rem;
}

/* ==========================================================================
   3. PAGE EDITOR (page_edit.html)
   ========================================================================== */
/* ... existing editor styles ... */
form textarea[name="raw_content"] {
    width: 100%;
    min-height: 60vh;
    font-family: var(--font-accent);
    font-size: 1rem;
    line-height: 1.5;
    color: var(--color-text);
    background-color: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius);
    padding: var(--spacing-unit);
    box-sizing: border-box;
}
.edit-actions {
    display: flex;
    gap: var(--spacing-unit);
    margin-top: var(--spacing-unit);
}
.delete-form {
    margin-top: calc(var(--spacing-unit) * 2);
    padding-top: calc(var(--spacing-unit) * 2);
    border-top: 1px solid var(--color-border);
}
.button-primary { background-color: var(--color-highlight-blue); color: white; }
.button-secondary { background-color: #ccc; color: var(--color-text); }
.button-danger { background-color: #c00; color: white; }

/* ==========================================================================
   4. SYSTEM & ERROR PAGES
   ========================================================================== */
/* ... existing error page styles ... */
.error-container {
    text-align: center;
    padding: calc(var(--spacing-unit) * 4) var(--spacing-unit);
    margin-top: calc(var(--spacing-unit) * 2);
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius);
    background-color: var(--color-surface);
}
.error-container h1 {
    color: #c00;
}
.error-container .actions {
    list-style: none;
    padding: 0;
    margin-top: calc(var(--spacing-unit) * 2);
}
.error-container .error-code {
    margin-top: calc(var(--spacing-unit) * 2);
    font-family: var(--font-accent);
    color: var(--color-supplementary-text);
}


/* ==========================================================================
   5. LAYOUT OVERRIDES FOR ADMIN/FUNCTIONAL PAGES
   ========================================================================== */

/*
  On wide screens, by default, the .page-container has two columns.
  For templates that should be single-column (like the editor),
  this override reverts the container to a simple block layout,
  allowing the <main> element to span the full width.
*/
@media (min-width: 900px) {
  .template-edit .page-container,
  .template-history .page-container {
    display: block; /* Revert from grid to a simple block layout */
  }
}

/* ==========================================================================
   6. HAMBURGER MENU POSITION OVERRIDE
   ========================================================================== */

/*
  This section overrides the default top-right position of the hamburger
  menu, anchoring it to the bottom-left of the viewport instead.
*/
.nav {
    top: auto;    /* Unset the original 'top' property */
    right: auto;  /* Unset the original 'right' property */
    bottom: var(--spacing-unit);
    left: var(--spacing-unit);
}

/*
  This adjusts the dropdown menu's position to open *above* the button
  (since the button is now at the bottom of the screen).
*/
.top-nav-links {
    top: auto;      /* Unset the original 'top' property */
    right: auto;    /* Unset the original 'right' property */
    bottom: 100%;   /* Position the bottom of the menu at the top of the button */
    left: 0;        /* Align the left edge of the menu with the button */
    margin-bottom: 5px; /* Add a small gap between the button and the menu */
