/**
 * Core Styles
 *
 * Base resets, container system, header chrome,
 * site branding, content area, entry defaults,
 * and shared utility styles.
 *
 * @package Mestariteema
 */

/* =WordPress Core
-------------------------------------------------------------- */
body {
    margin: 0;
    padding: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
    font-size: var(--fontsize-p, 16px);
    line-height: var(--lineheight-p, 1.6);
    color: var(--scheme-1-text);
}

/* Clip horizontal overflow on the page wrapper — not html/body —
   so #wpadminbar stays viewport-fixed and WP's margin-top bump has no white gap. */
.site {
    width: 100%;
    margin: 0;
    padding: 0;
    overflow-x: hidden;
    overflow-x: clip;
}

/* =Bootstrap-style Container System
-------------------------------------------------------------- */
.container {
    width: 100%;
    max-width: 1200px;
    margin-left: auto;
    margin-right: auto;
    padding-left: 20px;
    padding-right: 20px;
    box-sizing: border-box;
}

.container-fluid {
    width: 100%;
    padding-left: 20px;
    padding-right: 20px;
}

.container-narrow {
    width: 100%;
    max-width: 800px;
    margin-left: auto;
    margin-right: auto;
    padding-left: 20px;
    padding-right: 20px;
}

.container-wide {
    width: 100%;
    max-width: 1400px;
    margin-left: auto;
    margin-right: auto;
    padding-left: 20px;
    padding-right: 20px;
}

/* Row and Column basics */
.row {
    display: flex;
    flex-wrap: wrap;
    margin-left: -15px;
    margin-right: -15px;
}

.col {
    flex: 1;
    padding-left: 15px;
    padding-right: 15px;
}

/* Responsive containers */
@media (max-width: 1200px) {
    .container {
        max-width: 960px;
    }
    .container-wide {
        max-width: 1140px;
    }
}

@media (max-width: 992px) {
    .container {
        max-width: 720px;
    }
    .container-wide {
        max-width: 960px;
    }
}

@media (max-width: 768px) {
    .container,
    .container-narrow,
    .container-wide {
        max-width: 100%;
        padding-left: 15px;
        padding-right: 15px;
        width: 100%;
        box-sizing: border-box;
    }
}

/* ============================================
   Header Positioning
   ============================================
   Priority rules:
   - Default:      position: relative (normal document flow)
   - Sticky only:  position: sticky; top: 0
   - Transparent:  position: absolute; overlaps content
   - Both:         starts absolute, transitions to sticky on scroll
   ============================================ */
.site-header {
    position: relative;
    top: 0;
    width: 100%;
    padding: 0;
    border-bottom: none;
    z-index: 1000;
    transition: background-color 0.3s ease;
    box-sizing: border-box;
    display: flex;
    align-items: center;
    justify-content: center;
}

.header-inner {
    flex: 0 1 auto;
    width: 100%;
    max-width: var(--mestari-container-width, 1200px);
    margin-left: auto;
    margin-right: auto;
    padding-left: 20px;
    padding-right: 20px;
    box-sizing: border-box;
}

/* Full Width Header */
.header-full-width {
    background-color: var(--scheme-2-bg);
}

.header-full-width .header-inner {
    max-width: 100%;
}

/* Dynamic offsets for overlay/sticky header behavior */
:root {
    --mestari-topbar-height: 0px;
    --mestari-adminbar-offset: 0px;
    --mestari-header-height: 0px;
    --mestari-header-bottom: calc(var(--mestari-adminbar-offset, 0px) + var(--mestari-topbar-height, 0px) + 64px);
}

/* Prefer WP core's admin-bar height token when present */
.admin-bar {
    --mestari-adminbar-offset: var(--wp-admin--admin-bar--height, 32px);
}

@media screen and (max-width: 782px) {
    .admin-bar {
        --mestari-adminbar-offset: var(--wp-admin--admin-bar--height, 46px);
    }
}

/* Smartphones: WP admin bar is position:absolute and scrolls away.
   Default offset to 0; navigation.js sets the live visible height. */
@media screen and (max-width: 600px) {
    .admin-bar {
        --mestari-adminbar-offset: 0px;
    }
}

/* Sticky header — enabled via body.header-sticky */
.header-sticky .site-header {
    position: sticky;
    top: var(--mestari-adminbar-offset);
}

/* In-page links (#section) stop below a sticky header instead of under it.
   navigation.js keeps --mestari-header-height in sync with the header. */
html:has(> body.header-sticky),
html:has(> body.header-overlay-active) {
    scroll-padding-top: calc(var(--mestari-adminbar-offset, 0px) + var(--mestari-header-height, 0px) + 16px);
}

/* Transparent header — enabled via body.header-overlay-active */
.header-overlay-active .site-header {
    position: sticky;
    width: 100%;
    top: 0;
}

/* Sticky + Transparent combo */
.header-overlay-active.header-sticky .site-header.header-scrolled {
    position: sticky;
    top: 0;
}

/* Header solid background when scrolled */
.site-header.header-scrolled {
    background-color: var(--header-bg);
}

/* When a submenu or mega menu is open, sync header bar with panel colors (desktop only).
   Specificity must beat .header-mode-light / .header-mode-dark in dynamic CSS. */
.site-header.header-mode-light.header-menu-open,
.site-header.header-mode-dark.header-menu-open {
    background-color: var(--submenu-bg);
    --header-bg: var(--submenu-bg);
    --header-text: var(--submenu-text);
    --nav-link-color: var(--submenu-text);
    --nav-hover-color: var(--submenu-hover-text);
    --nav-active-color: var(--submenu-text);
    --logo-text-color: var(--submenu-text);
    --logo-text-hover-color: var(--submenu-hover-text);
}

/* Mobile overlay open: header bar keeps active header mode (not submenu chrome). */
body.nav-overlay-open .site-header.header-mode-light.header-menu-open {
    background-color: var(--header-light-bg);
    --header-bg: var(--header-light-bg);
    --header-text: var(--header-light-text);
    --nav-link-color: var(--header-light-nav);
    --nav-hover-color: var(--header-light-nav-hover);
    --nav-active-color: var(--header-light-nav-active);
    --logo-text-color: var(--header-light-text);
    --logo-text-hover-color: var(--header-light-nav-hover);
}

body.nav-overlay-open .site-header.header-mode-dark.header-menu-open {
    background-color: var(--header-dark-bg);
    --header-bg: var(--header-dark-bg);
    --header-text: var(--header-dark-text);
    --nav-link-color: var(--header-dark-nav);
    --nav-hover-color: var(--header-dark-nav-hover);
    --nav-active-color: var(--header-dark-nav-active);
    --logo-text-color: var(--header-dark-text);
    --logo-text-hover-color: var(--header-dark-nav-hover);
}

/* Dual logos: only one visible at a time.
   Dark logo (.header-logo--for-light-bg) = default on light headers / light theme.
   Light logo (.header-logo--for-dark-bg) = dark headers / dark theme.
   Markup is only output when BOTH logos are set (see mestari_header_branding). */
.site-branding .custom-logo-link .header-logo--for-light-bg {
    display: block !important;
}

.site-branding .custom-logo-link .header-logo--for-dark-bg {
    display: none !important;
}

.site-header.header-mode-dark .site-branding .custom-logo-link .header-logo--for-light-bg {
    display: none !important;
}

.site-header.header-mode-dark .site-branding .custom-logo-link .header-logo--for-dark-bg {
    display: block !important;
}

/* Desktop submenu open: match submenu chrome */
body.submenu-chrome-dark .site-header.header-mode-light.header-menu-open .site-branding .custom-logo-link .header-logo--for-light-bg {
    display: none !important;
}

body.submenu-chrome-dark .site-header.header-mode-light.header-menu-open .site-branding .custom-logo-link .header-logo--for-dark-bg {
    display: block !important;
}

body.submenu-chrome-light .site-header.header-mode-dark.header-menu-open .site-branding .custom-logo-link .header-logo--for-dark-bg {
    display: none !important;
}

body.submenu-chrome-light .site-header.header-mode-dark.header-menu-open .site-branding .custom-logo-link .header-logo--for-light-bg {
    display: block !important;
}

/* Content — no padding adjustments needed with sticky */
.site-content {
    padding-top: 0;
}



/* In overlay mode, pull content under the header */
.header-overlay-active .site-content {
    margin-top: calc(var(--mestari-header-height, 0px) * -1) !important;
}

/* No Header Layout */
.no-header .site-content {
    padding-top: 0;
}

/* Site Branding */
.site-branding {
    flex-shrink: 0;
    display: flex;
    align-items: center;
}

.site-branding .custom-logo-link {
    display: flex;
    align-items: center;
    line-height: 0;
}

.site-branding .custom-logo-link img {
    display: block;
}

.site-title {
    margin: 0;
    font-size: 1.5em;
    font-weight: 700;
    letter-spacing: 1px;
}

.site-title a {
    color: var(--logo-text-color, var(--header-text, #000000));
    text-decoration: none;
    text-transform: var(--logo-text-transform, none);
}

.site-title a:hover {
    color: var(--logo-text-hover-color, var(--nav-hover-color, #333333));
}

.site-description {
    display: none;
}

/* Header Social Icons */
.header-social {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 15px;
}

.header-social .social-icon {
    color: var(--nav-link-color);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.3s ease;
}

.header-social .social-icon:hover {
    color: var(--scheme-1-accent);
}

.header-social svg {
    width: 20px;
    height: 20px;
}

/* Header search */
.header-search {
    position: relative;
    display: flex;
    align-items: center;
}

.header-search-toggle {
    background: none;
    border: none;
    color: var(--nav-link-color);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 6px;
    transition: color 0.2s ease;
}

.header-search-toggle:hover,
.header-search-toggle:focus-visible {
    color: var(--scheme-1-accent);
    outline: none;
}

.header-search-panel {
    position: absolute;
    top: calc(100% + 10px);
    right: 0;
    background: var(--scheme-2-bg);
    border: 1px solid rgba(255, 255, 255, 0.1);
    padding: 12px;
    min-width: 240px;
    border-radius: 6px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
    opacity: 0;
    pointer-events: none;
    transform: translateY(6px);
    transition: opacity 0.2s ease, transform 0.2s ease;
    z-index: 1002;
}

.header-search-panel.is-open {
    opacity: 1;
    pointer-events: auto;
    transform: translateY(0);
}

.header-search-form {
    display: flex;
    gap: 8px;
}

.header-search-input {
    flex: 1;
    padding: 8px 10px;
    border-radius: 4px;
    border: 1px solid rgba(255, 255, 255, 0.15);
    background: rgba(255, 255, 255, 0.08);
    color: var(--scheme-1-bg);
}

.header-search-input::placeholder {
    color: rgba(255, 255, 255, 0.7);
}

.header-search-submit {
    background: var(--scheme-1-accent);
    border: none;
    color: var(--scheme-2-bg);
    padding: 8px 12px;
    border-radius: 4px;
    font-weight: 600;
    cursor: pointer;
}

/* Language switcher — top bar only (header switcher styled in navigation.css) */
.topbar-lang-switcher {
    display: flex;
    align-items: center;
}

.topbar-lang-switcher ul {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 20px;
}

.topbar-lang-switcher li {
    margin: 0;
    padding: 0;
    display: inline-block;
}

.topbar-lang-switcher a {
    display: inline-flex;
    align-items: center;
    gap: 0.35em;
    color: var(--topbar-text, #ffffff);
    text-decoration: none;
    font-size: 0.85rem;
    line-height: 1.2;
    transition: color 0.3s ease;
}

.topbar-lang-switcher a:hover,
.topbar-lang-switcher a:focus-visible {
    color: var(--topbar-link, #e6b54a);
    outline: none;
}

.topbar-lang-switcher .current-lang > a {
    color: var(--topbar-link, #e6b54a);
}

.topbar-lang-switcher img {
    width: 1.25em;
    height: auto;
    display: block;
    border-radius: 2px;
}

/* Hello bar - always static, outside header, never sticky */
.hello-bar {
    background: var(--scheme-2-bg);
    color: var(--scheme-1-bg);
    padding: 8px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    position: static;
    z-index: 1001;
    width: 100%;
}

/* Overlay offset is dynamic (set from JS) to match top bar height.
   Avoid hardcoded values because top bar size is customizable. */

.hello-bar-inner {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
}

.hello-bar-content {
    font-size: 0.9em;
}

.hello-bar-extras {
    display: flex;
    align-items: center;
    gap: 16px;
}

.hello-bar-cta {
    padding: 8px 20px;
    font-size: 0.85em;
}

@media screen and (max-width: 768px) {
    .hello-bar-inner {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }
}

/* Header Extras (Social + CTA) */
.header-extras {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: flex-end;
    gap: 16px;
    margin-left: var(--header-extras-spacing, 20px);
    grid-column: 3;
}

@media screen and (max-width: 1199px) {
    .header-extras {
        margin-left: 0;
    }
}

/* Header CTA Button — uses dedicated CTA variables */
.header-cta {
    display: inline-block;
    padding: var(--header-cta-padding, 12px 32px);
    background: var(--header-cta-bg);
    color: var(--header-cta-color);
    text-decoration: none;
    font-weight: var(--header-cta-font-weight, 600);
    font-size: var(--header-cta-font-size, 14px);
    text-transform: var(--header-cta-text-transform, none);
    letter-spacing: var(--btn-letter-spacing, 0.5px);
    line-height: 1.2;
    transition: all 0.3s ease;
    border-width: var(--header-cta-border-width, 0);
    border-style: solid;
    border-color: var(--header-cta-border-color);
    border-radius: var(--header-cta-border-radius, 4px);
    white-space: nowrap;
    box-sizing: border-box;
    cursor: pointer;
}

.header-cta:hover {
    background: var(--header-cta-hover-bg);
    border-color: var(--header-cta-hover-bg);
    color: var(--header-cta-hover-color);
    transform: translateY(-2px);
    text-decoration: none;
}

/* ============================================
   Content Area
   ============================================ */
.site-content {
    padding: 0;
    margin: 0;
    min-height: 0;
}

.content-area {
    width: 100%;
}

.site-main {
    width: 100%;
}

/* Contained Page Template */
.page-contained {
	padding-top: var(--padding-default-top, 80px);
	padding-bottom: var(--padding-default-bottom, 80px);
}

.page-contained .site-main {
	width: 100%;
}

.page-contained .entry-content > *:first-child {
	margin-top: 0;
}

.page-contained .entry-content > *:last-child {
	margin-bottom: 0;
}

.page-contained article {
	margin-bottom: 0;
}

/* Full Width Page Template */
.page-full-width {
    padding: 0;
}

.page-full-width .site-main {
    padding: 0;
}

.page-full-width .entry-content {
    padding: 0;
}

.page-full-width .entry-content > *:first-child {
    margin-top: 0;
}

.page-full-width .entry-content > *:last-child {
    margin-bottom: 0;
}

/* Full-width aligned blocks */
.alignfull {
    width: 100%;
    max-width: 100%;
    margin-left: 0;
    margin-right: 0;
}

.page-full-width .alignfull {
    margin-top: 0;
    margin-bottom: 0;
}

.page-full-width .wp-block-group.alignfull,
.page-full-width .hero-block,
.page-full-width .split-content-block {
    margin-top: 0;
    margin-bottom: 0;
}

.page-full-width article {
    margin-bottom: 0;
}

.single-post.page-full-width .entry-content > * {
    margin-top: 0;
    margin-bottom: 0;
    max-width: none;
}

article {
    margin-bottom: 40px;
}

/* Ensure no whitespace in content area */
.site-content:empty {
    display: none;
}

.site-main > *:last-child {
    margin-bottom: 0;
}

/* ============================================
   Entry Styles (single/page scope)
   ============================================ */
.single .entry-header,
.page .entry-header {
    margin-bottom: 30px;
}

.single .entry-title,
.page .entry-title {
    margin: 0 0 20px;
    font-size: var(--fontsize-h1, 42px);
    line-height: var(--lineheight-h1, 1.2);
    font-weight: var(--fontweight-h1, 700);
}

.single .entry-title a,
.page .entry-title a {
    color: var(--scheme-1-text);
    text-decoration: none;
}

.single .entry-title a:hover,
.page .entry-title a:hover {
    color: var(--scheme-1-accent);
}

/* ============================================
   Content lists (pages + posts) — editor parity
   ============================================ */
.entry-content ul,
.entry-content ol,
.entry-content .wp-block-list {
    margin-top: 0;
    margin-bottom: 0;
    padding-left: 1.4em;
}

.entry-content li,
.entry-content .wp-block-list-item {
    margin-top: 0;
    margin-bottom: 0.25em;
    line-height: var(--lineheight-p, 1.6);
}

.entry-content .wp-block-list > .wp-block-list-item:last-child,
.entry-content ul > li:last-child,
.entry-content ol > li:last-child {
    margin-bottom: 0;
}

/* ============================================
   Blockquote / Quote block
   ============================================ */
.entry-content blockquote,
.entry-content .wp-block-quote,
.hero-content blockquote,
.hero-content .wp-block-quote,
.comment-content blockquote,
.wp-block-quote {
    position: relative;
    box-sizing: border-box;
    border: none;
    border-left: none;
    margin: 2em 0;
    padding: 20px;
    overflow: hidden;
    background: none;
    color: var(--scheme-text, inherit);
    font-style: italic;
}

.entry-content blockquote::before,
.entry-content .wp-block-quote::before,
.hero-content blockquote::before,
.hero-content .wp-block-quote::before,
.comment-content blockquote::before,
.wp-block-quote::before {
    content: "\201C";
    position: absolute;
    top: 0;
    left: 0;
    z-index: 0;
    font-family: Georgia, "Times New Roman", serif;
    font-size: 8rem;
    font-style: normal;
    font-weight: 700;
    line-height: 1;
    color: currentColor;
    opacity: 0.03;
    pointer-events: none;
    user-select: none;
}

.entry-content blockquote > *,
.entry-content .wp-block-quote > *,
.hero-content blockquote > *,
.hero-content .wp-block-quote > *,
.comment-content blockquote > *,
.wp-block-quote > * {
    position: relative;
    z-index: 1;
}

.entry-content blockquote p,
.entry-content .wp-block-quote p,
.hero-content blockquote p,
.hero-content .wp-block-quote p,
.wp-block-quote p {
    margin-top: 0;
}

.entry-content blockquote p:last-of-type,
.entry-content .wp-block-quote p:last-of-type,
.hero-content blockquote p:last-of-type,
.hero-content .wp-block-quote p:last-of-type,
.wp-block-quote p:last-of-type {
    margin-bottom: 0;
}

.entry-content blockquote cite,
.entry-content .wp-block-quote cite,
.entry-content .wp-block-quote .wp-block-quote__citation,
.hero-content blockquote cite,
.hero-content .wp-block-quote cite,
.wp-block-quote cite,
.wp-block-quote .wp-block-quote__citation {
    display: block;
    margin-top: 0.75em;
    font-size: 0.9em;
    font-style: normal;
    opacity: 0.75;
}

.wp-block-quote.is-style-plain,
.wp-block-quote.is-style-large {
    border: none;
    padding: 20px;
}

/*
 * Columns keep their 20px block/column gap.
 * Pull lists up by 10px so the effective gap above a list is 10px.
 */
.wp-block-column > .wp-block-list,
.wp-block-column > ul.wp-block-list,
.wp-block-column > ol.wp-block-list {
    margin-top: -10px;
}

.single .entry-meta,
.page .entry-meta {
    color: var(--scheme-1-text);
    font-size: 0.9em;
    margin-bottom: 20px;
}

.single .entry-footer,
.page .entry-footer {
    margin-top: 30px;
    padding-top: 0;
}

.single .edit-link a,
.page .edit-link a {
    color: var(--scheme-1-text);
    text-decoration: none;
    font-size: 0.9em;
}

.single .edit-link a:hover,
.page .edit-link a:hover {
    color: var(--scheme-1-accent);
}

.single .post-thumbnail img,
.page .post-thumbnail img {
    display: block;
    width: 100%;
    height: auto;
}

/* Page Links (pagination for multi-page content) */
.page-links {
    clear: both;
    margin: 20px 0;
    font-weight: 600;
}

.page-links a,
.page-links > span {
    display: inline-block;
    margin: 0 5px;
    padding: 5px 10px;
    text-decoration: none;
}

.single .page-links a,
.single .page-links > span {
    border: none;
}

.page-links a:hover {
    background: var(--scheme-1-accent);
    color: var(--scheme-1-accent-text, #fff);
}

/* Category and Tag Links */
.cat-links,
.tags-links {
    display: inline-flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    margin-right: 15px;
    font-size: 0.9em;
}

.cat-links a,
.tags-links a {
    color: var(--scheme-text, var(--scheme-1-text));
    text-decoration: none;
    padding: 6px 12px;
    background: color-mix(in srgb, var(--scheme-text, var(--scheme-1-text)) 5%, transparent);
    border: 1px solid color-mix(in srgb, var(--scheme-text, var(--scheme-1-text)) 14%, transparent);
    border-radius: 999px;
    display: inline-flex;
    align-items: center;
    margin: 0;
    font-weight: 500;
    transition: background 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}

.cat-links a:hover,
.tags-links a:hover {
    background: color-mix(in srgb, var(--scheme-accent, var(--scheme-1-accent)) 12%, transparent);
    border-color: color-mix(in srgb, var(--scheme-accent, var(--scheme-1-accent)) 35%, transparent);
    color: var(--scheme-accent, var(--scheme-1-accent));
}

/* ============================================
   Search Form
   ============================================ */
.mestari-search-form {
    display: flex;
    align-items: stretch;
    width: 100%;
}

.mestari-search-input {
    flex: 1;
    padding: 12px 16px;
    border: 1px solid rgba(0, 0, 0, 0.15);
    border-right: none;
    border-radius: 6px 0 0 6px;
    font-family: inherit;
    /* 16px minimum: iOS Safari zooms the page when a smaller input gets focus */
    font-size: max(16px, 0.95em);
    color: var(--scheme-1-text);
    background: var(--scheme-1-bg);
    transition: border-color 0.2s ease;
    box-sizing: border-box;
    min-width: 0;
}

.mestari-search-input:focus {
    outline: none;
    border-color: var(--scheme-1-accent);
}

.mestari-search-submit {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0 16px;
    background: var(--scheme-1-heading);
    color: var(--scheme-1-bg);
    border: none;
    border-radius: 0 6px 6px 0;
    cursor: pointer;
    transition: background 0.2s ease;
    flex-shrink: 0;
}

.mestari-search-submit:hover {
    background: var(--scheme-1-accent);
}

/* ============================================
   Responsive — Mobile (content area)
   ============================================ */
@media screen and (max-width: 768px) {
    .site-content {
        padding: 0;
    }
}
