/* base.css - Reddit-like reset, typography, buttons, forms, shared components. */

*,
*::before,
*::after { box-sizing: border-box; }

html { 
    -webkit-text-size-adjust: 100%; 
    /* `clip` keeps the no-horizontal-scroll behaviour WITHOUT creating a
       scroll container - `hidden` on an ancestor breaks position: sticky,
       which is why the sticky header (mobile search button) was scrolling
       away instead of freezing while scrolling. */
    overflow-x: clip;
}

body {
    margin: 0;
    font-family: var(--font);
    font-size: 15px;
    line-height: 1.55;
    color: var(--text-primary);
    background: var(--bg-page);
    overflow-x: clip;
}

h1, h2, h3, h4 { line-height: 1.25; margin: 0 0 .5em; font-weight: 700; }
p { margin: 0 0 1em; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
code { font-family: var(--mono); font-size: .9em; background: var(--bg-soft); padding: .1em .3em; border-radius: var(--radius-sm); }
img { max-width: 100%; border: 0; }

:focus-visible {
    outline: 2px solid var(--brand);
    outline-offset: 2px;
    border-radius: var(--radius-sm);
}

.sr-only {
    position: absolute;
    width: 1px; height: 1px;
    padding: 0; margin: -1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
    border: 0;
}

.skip-link {
    position: absolute;
    left: -9999px;
    top: 0;
    z-index: calc(var(--z-toast) + 1);
    background: var(--brand);
    color: #fff;
    padding: .6rem 1rem;
    border-radius: 0 0 var(--radius-sm) 0;
}
.skip-link:focus { left: 0; }

.site-main {
    max-width: var(--max-page);
    margin: 0 auto;
    padding: 1rem 1rem 3rem;
    min-height: 60vh;
}
.page-feed .site-main,
.page-hr .site-main { max-width: var(--max-feed); }
.page-admin .site-main { max-width: var(--max-page); }

.page-title { font-size: 1.4rem; margin-bottom: 1rem; }

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    font: inherit;
    font-weight: 700;
    font-size: 0.9rem;
    line-height: 1;
    padding: 0.65rem 1rem;
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    cursor: pointer;
    text-decoration: none !important;
    transition: background 0.15s var(--ease), border-color 0.15s var(--ease), transform 0.1s var(--ease), box-shadow 0.15s var(--ease);
    -webkit-tap-highlight-color: transparent;
    background: var(--bg-soft);
    color: var(--text-primary);
    border-color: var(--border);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
    min-height: var(--touch-target);
    min-width: var(--touch-target);
}
.btn:active {
    transform: translateY(1px) scale(0.98);
    box-shadow: none;
}
.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.btn--primary {
    background: var(--brand);
    color: #fff;
    border-color: var(--brand);
    box-shadow: 0 2px 8px rgba(255, 69, 0, 0.25);
}
.btn--primary:hover {
    background: var(--brand-hover);
    border-color: var(--brand-hover);
    box-shadow: 0 4px 16px rgba(255, 69, 0, 0.3);
}
.btn--ghost {
    background: transparent;
    color: var(--text-primary);
    border-color: var(--border);
}
.btn--ghost:hover {
    background: var(--bg-soft);
    border-color: var(--border-strong);
}

/* Secondary - Sign In button - FIXED contrast */
.btn--secondary {
    background: var(--bg-card);
    color: var(--text-primary);
    border: 2px solid var(--border);
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}
.btn--secondary:hover {
    background: var(--bg-soft);
    border-color: var(--brand);
    color: var(--brand);
    box-shadow: 0 4px 12px rgba(255, 69, 0, 0.15);
}
.btn--secondary:active {
    background: var(--bg-soft);
}

.btn--danger {
    background: transparent;
    color: var(--text-primary);
    border-color: var(--border);
}
.btn--danger:hover {
    background: var(--danger-soft);
    color: var(--danger);
}
.btn--wa {
    background: #16a34a;
    color: #fff;
    border-color: #16a34a;
    box-shadow: 0 2px 8px rgba(22, 163, 74, 0.25);
}
.btn--wa:hover {
    background: #15803d;
}

.btn--sm {
    padding: 0.4rem 0.75rem;
    font-size: 0.82rem;
    min-height: var(--touch-target-sm);
    min-width: var(--touch-target-sm);
}
.btn--xs {
    padding: 0.3rem 0.6rem;
    font-size: 0.78rem;
}
.btn--lg {
    padding: 0.8rem 1.6rem;
    font-size: 1.05rem;
}
/* Full-width button (auth pages) - replaces inline style="width:100%". */
.btn--block {
    width: 100%;
}

/* Button that looks like an inline text link (e.g. "Sign out" on the consent gate). */
.btn-link {
    background: none;
    border: none;
    color: var(--brand);
    cursor: pointer;
    text-decoration: underline;
    font: inherit;
    padding: 0;
}
.btn-link:hover {
    color: var(--brand-hover);
}

/* ---------- Forms ---------- */
.field { display: block; margin-bottom: 1rem; }
.field__label { display: block; font-weight: 700; font-size: .88rem; margin-bottom: .35rem; color: var(--text-secondary); }
.field__opt { color: var(--text-muted); font-weight: 400; margin-left: .4rem; }
.field__hint { display: block; color: var(--text-muted); font-size: .82rem; margin-top: .4rem; }

.field__input {
    width: 100%;
    font: inherit;
    font-size: 1rem; /* Prevents zoom on iOS */
    color: var(--text-primary);
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: .7rem .85rem;
    transition: border-color var(--t-fast) var(--ease), box-shadow var(--t-fast) var(--ease);
    min-height: var(--touch-target);
}
.field__input:focus {
    outline: none;
    border-color: var(--brand);
    box-shadow: 0 0 0 3px var(--brand-soft);
}
.field__input--area { resize: vertical; min-height: 120px; }
.field__input--code { font-family: var(--mono); font-size: .88rem; line-height: 1.55; }

.field-row { display: grid; gap: 0 1rem; grid-template-columns: 1fr; }
@media (min-width: 640px) { .field-row { grid-template-columns: 1fr 1fr; } }

.form-error {
    background: #fff2f0;
    color: var(--danger);
    border: 1px solid var(--danger);
    border-radius: var(--radius-sm);
    padding: .75rem 1rem;
    font-size: .9rem;
}
.form-success {
    background: #e6f7ff;
    color: var(--ok);
    border: 1px solid var(--ok);
    border-radius: var(--radius-sm);
    padding: .75rem 1rem;
    font-size: .9rem;
    margin-bottom: 1rem;
}
.notice {
    border-radius: var(--radius-sm);
    padding: .85rem 1rem;
    margin-bottom: 1rem;
    font-size: .92rem;
    background: var(--brand-soft);
    color: var(--brand-active);
    border: 1px solid var(--brand);
}
.notice--warn { background: #fff6e0; color: var(--warn); border: 1px solid var(--warn); }
.notice--ok { background: #e8f4fd; color: var(--ok); border: 1px solid var(--ok); }

/* ---------- Panels & tables ---------- */
.panel {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-1);
    padding: 1.1rem;
    margin-bottom: 1rem;
}
.panel__title { font-size: 1.1rem; margin-bottom: .5rem; }
.panel__lead { color: var(--text-muted); font-size: .88rem; }
.panel__empty { color: var(--text-muted); }

.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table { width: 100%; border-collapse: collapse; font-size: .88rem; }
.table th, .table td { text-align: left; padding: .6rem .75rem; border-bottom: 1px solid var(--border); vertical-align: top; }
.table th { font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; color: var(--text-muted); }
.table__title { font-weight: 700; max-width: 320px; }
.table__actions { display: flex; gap: .4rem; flex-wrap: wrap; }
.table__muted { color: var(--text-muted); }
.inline-form { display: inline; }

.badge {
    display: inline-flex;
    align-items: center;
    font-size: .72rem;
    font-weight: 700;
    padding: .12rem .5rem;
    border-radius: 999px;
    text-transform: uppercase;
    letter-spacing: .02em;
    border: 1px solid var(--border);
    color: var(--text-secondary);
    background: var(--bg-soft);
}
.badge--ok { border-color: var(--ok); color: var(--ok); }
.badge--warn { border-color: var(--warn); color: var(--warn); }
.badge--danger { border-color: var(--danger); color: var(--danger); }
.badge--muted { border-color: var(--border); color: var(--text-muted); }

/* ---------- Misc ---------- */
.spinner {
    width: 24px; height: 24px;
    border: 3px solid var(--border);
    border-top-color: var(--brand);
    border-radius: 50%;
    animation: hp-spin .8s linear infinite;
    margin: 0 auto;
}
@keyframes hp-spin { to { transform: rotate(360deg); } }

.empty-state {
    text-align: center;
    background: var(--bg-card);
    border: 1px dashed var(--border-strong);
    border-radius: var(--radius);
    padding: 2.5rem 1.5rem;
}
.empty-state h2 { margin-bottom: .4rem; }
.empty-state p { color: var(--text-muted); }

.toast {
    position: fixed;
    left: 50%;
    bottom: 1.5rem;
    transform: translateX(-50%);
    z-index: var(--z-toast);
    background: var(--text-primary);
    color: var(--bg-card);
    padding: .7rem 1.2rem;
    border-radius: var(--radius-sm);
    font-size: .88rem;
    box-shadow: var(--shadow-2);
    max-width: 90vw;
}

/* ---------- Mobile-first responsive ---------- */
@media (max-width: 640px) {
    .site-main {
        padding: 0.75rem 0.75rem 3rem;
    }
    .page-title { font-size: 1.3rem; margin-bottom: 0.75rem; }
    .toast {
        font-size: 0.82rem;
        padding: 0.6rem 1rem;
        left: 1rem;
        right: 1rem;
        transform: none;
        max-width: calc(100% - 2rem);
    }
    .btn { font-size: 0.92rem; padding: 0.7rem 1.1rem; }
    .btn--lg { font-size: 1.05rem; padding: 0.85rem 1.5rem; }
    .field__input { font-size: 1rem; padding: 0.75rem 0.9rem; }
    .panel { padding: 1rem; }
    .panel__title { font-size: 1.05rem; }
}

@media (max-width: 420px) {
    html { font-size: 14px; }
    .site-main { padding: 0.5rem 0.5rem 3rem; }
    .page-title { font-size: 1.2rem; }
    .btn { padding: 0.65rem 0.9rem; }
    .field__input { padding: 0.7rem 0.8rem; }
}

/* ============================================================
     SCROLL TO TOP BUTTON
============================================================ */
.scroll-top {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    z-index: 1000;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--brand);
    color: white;
    border: none;
    box-shadow: 0 4px 16px rgba(255, 69, 0, 0.3);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transform: translateY(20px);
    transition: all 0.3s var(--ease);
    -webkit-tap-highlight-color: transparent;
}
.scroll-top.visible {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}
.scroll-top:hover {
    background: var(--brand-hover);
    box-shadow: 0 6px 20px rgba(255, 69, 0, 0.4);
    transform: translateY(-4px);
}
.scroll-top:active {
    transform: translateY(0) scale(0.95);
}
.scroll-top svg {
    width: 22px;
    height: 22px;
}

@media (max-width: 640px) {
    .scroll-top {
        bottom: 5.5rem; /* Raised to clear mobile bottom navigation */
        right: 1.5rem;
        width: 44px;
        height: 44px;
    }
    /* iOS Safari zoom prevention */
    input, select, textarea {
        font-size: 16px !important;
    }
}

@media (max-width: 420px) {
    .scroll-top {
        bottom: 5rem;
        right: 1rem;
        width: 40px;
        height: 40px;
    }
}

/* ============================================================
     IMAGE LIGHTBOX (modal popup for post images)
============================================================ */
.lightbox {
    position: fixed;
    inset: 0;
    z-index: 3000; /* above header (2000), menus, toasts */
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 4vh 4vw;
    background: rgba(8, 10, 16, 0.88);
    cursor: zoom-out;
    animation: hp-lightbox-in 0.18s var(--ease);
}
.lightbox[hidden] {
    display: none;
}
.lightbox__img {
    display: block;
    max-width: 92vw;
    max-height: 88vh;
    width: auto;
    height: auto;
    object-fit: contain; /* whole image always visible - never cropped */
    border-radius: 8px;
    box-shadow: 0 18px 60px rgba(0, 0, 0, 0.55);
    background: transparent;
    cursor: default;
}
.lightbox__close {
    position: absolute;
    top: 14px;
    right: 16px;
    width: 44px;
    height: 44px;
    border: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.14);
    color: #fff;
    font-size: 28px;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s var(--ease);
}
.lightbox__close:hover {
    background: rgba(255, 255, 255, 0.3);
}
.lightbox__close:focus-visible {
    outline: 2px solid #fff;
    outline-offset: 2px;
}
@keyframes hp-lightbox-in {
    from { opacity: 0; }
    to   { opacity: 1; }
}