/* Base reset + shared layout primitives. Editorial, calm, content-first
   (PRD §82/§53) -- no gradients, no big shadows, no dashboard chrome. */

*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; overflow-x: hidden; }
/* Disable the browser's native pull-to-refresh gesture on mobile (it
   fought with swipe-based interactions like the timeline's own scrolling). */
@media (max-width: 640px) {
    html { overscroll-behavior-y: contain; }
}
/* Safety net: an <img>/<video> with hardcoded intrinsic width/height
   attributes (e.g. a full-resolution photo) would otherwise be able to
   force the whole page wider than the viewport on mobile before any
   more specific sizing rule applies. */
img, video { max-width: 100%; height: auto; }

/* Global checkbox styling -- every checkbox across the site (admin lists,
   bulk-select, filters, forms) was plain unstyled browser chrome. Using
   the standard `accent-color` property (not a hand-built custom checkbox)
   keeps native semantics/keyboard behavior/accessibility intact while
   matching the theme's accent color, everywhere at once. */
input[type="checkbox"] {
    accent-color: var(--color-accent);
    width: 16px;
    height: 16px;
    cursor: pointer;
    vertical-align: middle;
}

/* Item: text-like inputs already theme their border/background wherever
   they're individually styled, but almost none of them override :focus --
   so focusing any input not wrapped in .field (which has had its own
   focus rule for a while) fell through to the browser's native focus ring,
   clashing with the theme. One global rule for every text-like control,
   everywhere, so this can't be missed again per-component. */
input[type="text"], input[type="search"], input[type="email"], input[type="password"],
input[type="url"], input[type="tel"], input[type="number"], input[type="date"],
input[type="datetime-local"], input[type="month"], input[type="week"], input[type="time"],
input:not([type]), textarea, select {
    accent-color: var(--color-accent);
}
input[type="text"]:focus, input[type="search"]:focus, input[type="email"]:focus, input[type="password"]:focus,
input[type="url"]:focus, input[type="tel"]:focus, input[type="number"]:focus, input[type="date"]:focus,
input[type="datetime-local"]:focus, input[type="month"]:focus, input[type="week"]:focus, input[type="time"]:focus,
input:not([type]):focus, textarea:focus, select:focus {
    outline: 2px solid var(--color-accent);
    outline-offset: -1px;
}
body {
    margin: 0;
    background: var(--color-background);
    color: var(--color-text);
    font-family: var(--font-body);
    font-size: 16px;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.001ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.001ms !important;
    }
}

a { color: var(--color-link); text-decoration: none; }
a:hover { color: var(--color-link-hover); text-decoration: underline; }

::selection { background: var(--color-selection-background); color: var(--color-selection-text); }

h1, h2, h3, h4 { line-height: 1.25; margin: 0 0 0.5em; font-weight: 600; }

.container {
    max-width: 720px;
    margin-inline: auto;
    padding-inline: 20px;
}

.surface {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 18px;
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    background: var(--color-accent);
    color: var(--color-accent-foreground);
    transition: background-color 120ms ease;
}
.btn:hover { background: var(--color-accent-hover); color: var(--color-accent-foreground); text-decoration: none; }
.btn:focus-visible { outline: 2px solid var(--color-accent); outline-offset: 2px; }
.btn.btn-secondary {
    background: transparent;
    color: var(--color-text);
    border-color: var(--color-border);
}
.btn.btn-secondary:hover { background: var(--color-surface-muted); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.btn-danger { background: transparent; color: var(--color-danger); border-color: color-mix(in srgb, var(--color-danger) 40%, transparent); }
.btn.btn-danger:hover { background: color-mix(in srgb, var(--color-danger) 12%, transparent); color: var(--color-danger); }

.field { margin-bottom: 16px; }
.field label {
    display: block;
    margin-bottom: 6px;
    font-size: 14px;
    font-weight: 600;
    color: var(--color-text-secondary);
}
.field input[type="text"],
.field input[type="email"],
.field input[type="password"],
.field input[type="url"],
.field input[type="datetime-local"],
.field textarea,
.field select {
    width: 100%;
    padding: 10px 12px;
    font-size: 15px;
    font-family: inherit;
    color: var(--color-input-text);
    background: var(--color-input-background);
    border: 1px solid var(--color-input-border);
    border-radius: var(--radius-sm);
}
.field input:focus, .field textarea:focus, .field select:focus {
    outline: 2px solid var(--color-accent);
    outline-offset: -1px;
}

.alert {
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    margin-bottom: 16px;
    font-size: 14px;
    border: 1px solid transparent;
}
.alert-error { background: color-mix(in srgb, var(--color-danger) 12%, var(--color-surface)); color: var(--color-danger); border-color: color-mix(in srgb, var(--color-danger) 30%, transparent); }
.alert-success { background: color-mix(in srgb, var(--color-success) 12%, var(--color-surface)); color: var(--color-success); border-color: color-mix(in srgb, var(--color-success) 30%, transparent); }

.muted { color: var(--color-text-muted); }
.text-secondary { color: var(--color-text-secondary); }

.checklist { list-style: none; padding: 0; margin: 0 0 16px; }
.checklist li {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 0;
    font-size: 14px;
    border-bottom: 1px solid var(--color-border-subtle);
}
.checklist .dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.checklist .dot.ok { background: var(--color-success); }
.checklist .dot.fail { background: var(--color-danger); }

/* Persistent /admin sidebar (admin-nav.php). Present on every admin page --
   shift the page over for it wherever it appears, without needing to touch
   each page's own wrapper class. */
.admin-sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    width: 220px;
    background: var(--color-surface);
    border-right: 1px solid var(--color-border);
    padding: 18px 12px 20px;
    overflow-y: auto;
    z-index: 40;
    display: flex;
    flex-direction: column;
}
body:has(.admin-sidebar) { padding-left: 220px; }

.admin-sidebar-brand {
    display: flex;
    align-items: center;
    gap: 8px;
    font-family: var(--font-serif);
    font-weight: 700;
    font-size: 17px;
    color: var(--color-text);
    padding: 6px 10px;
}
.admin-sidebar-logo-img { width: 28px; height: 28px; object-fit: cover; border-radius: var(--radius-sm); }
.admin-sidebar-logo-emoji { font-size: 20px; line-height: 1; }
.admin-sidebar-description { font-size: 12px; color: var(--color-text-muted); padding: 0 10px 6px; margin-top: -4px; }
.admin-sidebar-homepage-link {
    display: block;
    font-size: 12px;
    color: var(--color-text-muted);
    padding: 0 10px 16px;
}
.admin-sidebar-brand-only { padding-bottom: 20px; }
.admin-sidebar-nav { display: flex; flex-direction: column; gap: 1px; }
.admin-sidebar-nav a {
    display: flex; align-items: center; gap: 9px;
    padding: 8px 10px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    color: var(--color-text-secondary);
    background: none; border: none; cursor: pointer; text-align: left; width: 100%; font-family: inherit;
}
.admin-sidebar-nav a:hover { background: var(--color-surface-muted); text-decoration: none; }
.admin-sidebar-nav a.active { background: var(--color-accent); color: var(--color-accent-foreground); }
.admin-sidebar-nav a i { width: 16px; text-align: center; font-size: 13px; flex-shrink: 0; opacity: .85; }

/* Hovering a nav row reveals a quick "New" link on the right (item: sidebar
   quick-create). The row's own <a> keeps its normal width via flex:1 so the
   hover background/highlight still spans the whole row as before. */
.admin-sidebar-nav-item { position: relative; display: flex; align-items: center; }
.admin-sidebar-nav-item > a[data-nav] { flex: 1; min-width: 0; }
/* Item: the generic ".admin-sidebar-nav a" rule (width:100%, display:flex,
   padding:8px 10px) has higher specificity (class+tag beats one class
   alone) than a single ".admin-sidebar-nav-new" selector, so it was
   winning and stretching this into a full-row block that hid the item's
   own label/icon entirely instead of a small pill pinned to the right.
   Re-qualified as ".admin-sidebar-nav a.admin-sidebar-nav-new" to safely
   out-specificity it, plus explicit width/flex overrides. */
.admin-sidebar-nav a.admin-sidebar-nav-new {
    position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
    width: auto; flex: none; display: inline-flex; align-items: center;
    font-size: 11px; font-weight: 600; padding: 3px 8px; border-radius: 999px;
    background: var(--color-accent); color: var(--color-accent-foreground);
    opacity: 0; pointer-events: none; transition: opacity .12s ease;
    text-decoration: none;
}
.admin-sidebar-nav-item:hover .admin-sidebar-nav-new { opacity: 1; pointer-events: auto; }

/* Theme/Profile buttons pinned to the bottom of the sidebar. */
.admin-sidebar-footer { margin-top: auto; padding-top: 10px; border-top: 1px solid var(--color-border); display: flex; flex-direction: column; gap: 1px; }
.admin-sidebar-footer-btn {
    display: flex; align-items: center; gap: 9px;
    padding: 8px 10px; border-radius: var(--radius-sm);
    font-size: 14px; color: var(--color-text-secondary);
    background: none; border: none; cursor: pointer; text-align: left; width: 100%; font-family: inherit; text-decoration: none;
}
.admin-sidebar-footer-btn:hover { background: var(--color-surface-muted); text-decoration: none; }
.admin-sidebar-footer-btn i { width: 16px; text-align: center; font-size: 13px; flex-shrink: 0; opacity: .85; }

/* Theme popover: everything from partials/theme-manager.php, lazily
   AJAX-loaded on first open. */
.theme-popover {
    position: fixed; left: 226px; bottom: 20px; z-index: 60;
    width: min(420px, calc(100vw - 250px));
    max-height: min(640px, calc(100vh - 40px));
    overflow-y: auto;
    background: var(--color-surface-elevated);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    box-shadow: 0 10px 32px rgba(0, 0, 0, .18);
    padding: 16px;
}
.theme-popover-panel .theme-gallery-group { grid-template-columns: repeat(auto-fill, 120px); justify-content: start; }
/* Matches the sidebar's own off-canvas breakpoint (app.css's "Mobile: the
   sidebar becomes a slide-in..." rule) -- below that, the sidebar itself is
   an overlay taking the full width, so the popover can't anchor beside it. */
@media (max-width: 768px) {
    .theme-popover { left: 12px; right: 12px; width: auto; bottom: 70px; }
}

/* Item: a standalone floating theme button on every front-end page (not
   inside a full sidebar) -- same idea/position as the admin sidebar's own
   Theme footer button, just not attached to a sidebar column here. */
.theme-float-btn {
    position: fixed; left: 16px; bottom: 20px; z-index: 50;
    width: 44px; height: 44px; border-radius: 50%;
    background: var(--color-surface-elevated); border: 1px solid var(--color-border);
    color: var(--color-text-secondary); font-size: 16px;
    display: flex; align-items: center; justify-content: center;
    box-shadow: 0 2px 10px rgba(0, 0, 0, .15); cursor: pointer;
}
.theme-float-btn:hover { color: var(--color-text); border-color: var(--color-accent); }
/* /admin and /compose pages already have their own Theme button in their
   own sidebar -- this floating one is for front-end pages only, same
   :has() exclusion pattern as .mobile-bottom-nav above. */
body:has(.admin-sidebar) .theme-float-btn,
body:has(.admin-sidebar) #site-theme-popover,
body:has(> #composer-root) .theme-float-btn,
body:has(> #composer-root) #site-theme-popover {
    display: none;
}
#site-theme-popover { left: 16px; }
/* Item: front-end-only footer, same page-type exclusion as above. */
.site-footer {
    max-width: 1000px; margin: 32px auto 24px; padding: 16px 20px;
    border-top: 1px solid var(--color-border);
    font-size: 13px; color: var(--color-text-muted); text-align: center;
}
.site-footer p { margin: 0; }
.site-footer a { color: inherit; text-decoration: underline; }
body:has(.admin-sidebar) .site-footer,
body:has(> #composer-root) .site-footer {
    display: none;
}
@media (max-width: 768px) {
    #site-theme-popover { left: 12px; right: 12px; width: auto; }
}
@media (max-width: 640px) {
    /* Clear the mobile bottom-nav bar (58px + safe-area) that sits on top
       of this same edge on the pages that have one. */
    .theme-float-btn { bottom: 70px; }
    /* Item: the base .theme-popover's max-height assumes bottom:20px
       (min(640px, 100vh - 40px)) -- moved up to bottom:126px here without
       also shrinking max-height, the panel could still reach that same
       tall height, pushing its *top* edge off the top of a short mobile
       viewport (cropped). Recompute against the real available space. */
    #site-theme-popover { bottom: 126px; max-height: min(640px, calc(100vh - 146px)); }
}
.admin-sidebar-sub { padding-left: 22px !important; font-size: 13px; }

.admin-sidebar-hamburger {
    display: none;
    position: fixed;
    top: 12px; left: 12px;
    z-index: 55;
    width: 40px; height: 40px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    background: var(--color-surface);
    color: var(--color-text);
    font-size: 18px;
    cursor: pointer;
}
.admin-sidebar-backdrop {
    position: fixed; inset: 0;
    background: rgba(0, 0, 0, .35);
    z-index: 50;
    opacity: 0; visibility: hidden; pointer-events: none;
    transition: opacity .18s ease, visibility .18s ease;
}
.admin-sidebar-backdrop.open { opacity: 1; visibility: visible; pointer-events: auto; }

/* Mobile: the sidebar becomes a slide-in off-canvas panel (toggled by the
   hamburger button) instead of a horizontal-wrapping strip that used to eat
   a lot of vertical space at the top of every admin page. */
@media (max-width: 768px) {
    body:has(.admin-sidebar) { padding-left: 0; padding-top: 56px; }
    .admin-sidebar-hamburger { display: block; }
    .admin-sidebar:not(.admin-sidebar-brand-only) {
        width: min(260px, 82vw);
        transform: translateX(-100%);
        transition: transform .2s ease;
        z-index: 56;
        box-shadow: 2px 0 12px rgba(0, 0, 0, .15);
    }
    .admin-sidebar:not(.admin-sidebar-brand-only).open { transform: translateX(0); }
    /* /compose has only the brand link (no nav to collapse) -- keep it as a
       plain top strip on mobile instead, matching the public site header. */
    .admin-sidebar.admin-sidebar-brand-only { position: static; width: auto; border-right: none; border-bottom: 1px solid var(--color-border); }
    body:has(.admin-sidebar.admin-sidebar-brand-only) { padding-top: 0; }
}

/* Mobile app-shell bottom nav (logged-in author only -- base.php only
   renders it then). Hidden on desktop, and on /admin & /compose even on
   mobile since those already have their own hamburger nav / are full-editor
   surfaces where a bottom bar would just eat vertical space. */
.mobile-bottom-nav { display: none; }
@media (max-width: 640px) {
    body:not(:has(.admin-sidebar)):not(:has(> #composer-root)) .mobile-bottom-nav {
        display: flex;
        align-items: center;
        justify-content: space-around;
        position: fixed;
        left: 0; right: 0; bottom: 0;
        height: 58px;
        background: var(--color-surface-elevated);
        border-top: 1px solid var(--color-border);
        z-index: 50;
        padding-bottom: env(safe-area-inset-bottom, 0);
    }
    /* Leave room so page content never sits underneath the fixed bar. */
    body:not(:has(.admin-sidebar)):not(:has(> #composer-root)) { padding-bottom: 58px; }
}
.mobile-bottom-nav a {
    display: flex; flex-direction: column; align-items: center; gap: 2px;
    color: var(--color-text-secondary); font-size: 10px; flex: 1;
    padding: 6px 0;
}
.mobile-bottom-nav a:hover { text-decoration: none; color: var(--color-text); }
.mobile-bottom-nav .mbn-icon { font-size: 19px; line-height: 1; }
.mobile-bottom-nav .mbn-new {
    flex-shrink: 0;
    width: 46px; height: 46px; margin: 0 4px;
    border-radius: 50%;
    background: var(--color-accent); color: var(--color-accent-foreground);
    border: none; font-size: 24px; line-height: 1;
    display: flex; align-items: center; justify-content: center;
    box-shadow: 0 2px 8px rgba(0, 0, 0, .2);
    cursor: pointer;
    transform: translateY(-6px);
}

/* Item: site-wide styled alert/confirm/prompt replacement (dialogs.js) --
   z-index above everything else (composer modal 95, link-insert popup 97)
   since these can be triggered from inside any of those. */
.hotbot-dialog-backdrop {
    position: fixed; inset: 0; background: rgba(0, 0, 0, .45);
    display: flex; align-items: center; justify-content: center; z-index: 200;
    padding: 20px;
    opacity: 0; transition: opacity .15s ease;
}
.hotbot-dialog-backdrop.open { opacity: 1; }
.hotbot-dialog-panel {
    background: var(--color-surface-elevated); color: var(--color-text);
    border-radius: var(--radius-lg); padding: 20px;
    width: min(360px, 100%); box-shadow: 0 8px 28px rgba(0, 0, 0, .2);
    transform: translateY(-10px); transition: transform .15s ease;
}
.hotbot-dialog-backdrop.open .hotbot-dialog-panel { transform: translateY(0); }
.hotbot-dialog-title { margin: 0 0 8px; font-size: 16px; }
.hotbot-dialog-message { margin: 0 0 14px; font-size: 14px; color: var(--color-text-secondary); white-space: pre-wrap; }
.hotbot-dialog-danger .hotbot-dialog-message { color: var(--color-text); }
.hotbot-dialog-input {
    width: 100%; padding: 8px 10px; margin-bottom: 14px; font: inherit;
    border-radius: var(--radius-sm); border: 1px solid var(--color-input-border);
    background: var(--color-input-background); color: var(--color-input-text);
}
.hotbot-dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }
