/* =====================================================
   ScienceToday — Dark Theme
   ===================================================== */

/* --- Reset & Base --- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --bg:         #0d1117;
    --bg2:        #161b22;
    --bg3:        #1c2330;
    --border:     #30363d;
    --accent:     #58a6ff;
    --accent2:    #3fb950;
    --accent3:    #d29922;
    --text:       #e6edf3;
    --text-muted: #8b949e;
    --danger:     #f85149;
    --radius:     10px;
    --shadow:     0 4px 24px rgba(0,0,0,0.5);
    --transition: 0.2s ease;
    --font:       'Segoe UI', system-ui, -apple-system, sans-serif;
}

html { font-size: 16px; scroll-behavior: smooth; }

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    line-height: 1.7;
    min-height: 100vh;
}

body.consent-open {
    padding-bottom: 210px;
}

body.consent-closed {
    padding-bottom: 68px;
}

a { color: var(--accent); text-decoration: none; transition: color var(--transition); }
a:hover { color: #a5d3ff; text-decoration: underline; }

img { display: block; max-width: 100%; height: auto; }

/* --- Navbar --- */
.navbar {
    background: var(--bg2);
    border-bottom: 1px solid var(--border);
    padding: 0 2rem;
    position: sticky;
    top: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 60px;
    backdrop-filter: blur(8px);
}
.navbar-brand {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text);
    letter-spacing: -0.5px;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.navbar-brand span { color: var(--accent); }
.navbar-links { display: flex; gap: 1.5rem; }
.navbar-links a {
    color: var(--text-muted);
    font-size: 0.9rem;
    font-weight: 500;
    padding: 0.25rem 0;
    border-bottom: 2px solid transparent;
    transition: all var(--transition);
}
.navbar-links a:hover,
.navbar-links a.active { color: var(--text); border-bottom-color: var(--accent); text-decoration: none; }

/* --- Page wrapper --- */
.page { max-width: 1100px; margin: 0 auto; padding: 2.5rem 1.5rem; }
.page-sm { max-width: 720px; margin: 0 auto; padding: 2.5rem 1.5rem; }

/* --- Hero banner --- */
.hero {
    background: linear-gradient(135deg, #0d1f3c 0%, #0d1117 60%);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 3rem 2rem;
    margin-bottom: 2.5rem;
    text-align: center;
    position: relative;
    overflow: hidden;
}
.hero::before {
    content: '';
    position: absolute;
    inset: 0;
    background: radial-gradient(ellipse at 50% 0%, rgba(88,166,255,0.12) 0%, transparent 70%);
    pointer-events: none;
}
.hero h1 { font-size: 2rem; font-weight: 700; margin-bottom: 0.5rem; }
.hero p  { color: var(--text-muted); font-size: 1rem; }

/* --- Card --- */
.card {
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 2rem;
    box-shadow: var(--shadow);
    transition: border-color var(--transition);
}
.card:hover { border-color: #484f58; }

/* --- Form elements --- */
.form-group { margin-bottom: 1.25rem; }
.form-section-title {
    font-size: 0.78rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--accent);
    margin: 0 0 1rem;
}
label {
    display: block;
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 0.4rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}
input[type=text],
input[type=password],
textarea,
select {
    width: 100%;
    padding: 0.65rem 0.85rem;
    background: var(--bg3);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    font-family: var(--font);
    font-size: 0.95rem;
    transition: border-color var(--transition), box-shadow var(--transition);
    outline: none;
}
input[type=text]:focus,
textarea:focus,
select:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(88,166,255,0.15);
}
select option { background: var(--bg3); }
textarea { resize: vertical; min-height: 100px; }
input[type=file] {
    width: 100%;
    padding: 0.8rem;
    background: var(--bg3);
    border: 1px dashed var(--border);
    border-radius: 6px;
    color: var(--text-muted);
}
.field-hint {
    margin-top: 0.45rem;
    color: var(--text-muted);
    font-size: 0.78rem;
}

.ai-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 0.9rem;
    margin-bottom: 1.5rem;
}

.ai-option-card {
    display: block;
    position: relative;
    padding: 1rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: linear-gradient(180deg, rgba(28,35,48,0.9), rgba(22,27,34,0.95));
    cursor: pointer;
    transition: border-color var(--transition), transform var(--transition), box-shadow var(--transition);
}

.ai-option-card:hover {
    border-color: var(--accent);
    transform: translateY(-2px);
}

.ai-option-card input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.ai-option-card:has(input:checked) {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(88,166,255,0.12);
}

.ai-option-label {
    display: block;
    color: var(--text);
    font-weight: 700;
    margin-bottom: 0.35rem;
}

.ai-provider-title {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.ai-provider-icon {
    width: 1.5rem;
    height: 1.5rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: rgba(88,166,255,0.14);
    border: 1px solid rgba(88,166,255,0.25);
    font-size: 0.9rem;
}

.ai-option-description {
    display: block;
    color: var(--text-muted);
    font-size: 0.82rem;
    line-height: 1.5;
}

.image-mode-row {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
    margin-bottom: 1rem;
}

.mode-pill {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.7rem 1rem;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--bg3);
    color: var(--text-muted);
    cursor: pointer;
}

.mode-pill input {
    accent-color: var(--accent);
}

.logo-brand .logo-orb {
    display: inline-flex;
    width: 28px;
    height: 28px;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: rgba(88,166,255,0.15);
}

.home-search {
    margin-bottom: 1rem;
}

.hero-logo {
    padding-top: 2.4rem;
}

.hero-logo-mark {
    width: 64px;
    height: 64px;
    margin: 0 auto 0.9rem;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.7rem;
    background: rgba(88,166,255,0.16);
    border: 1px solid rgba(88,166,255,0.35);
}

.category-menu-wrap {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 1.25rem;
}

.category-chip {
    display: inline-flex;
    align-items: center;
    padding: 0.35rem 0.75rem;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: var(--bg2);
    color: var(--text-muted);
    font-size: 0.78rem;
    font-weight: 600;
    text-decoration: none;
}

.category-chip:hover,
.category-chip.active {
    border-color: var(--accent);
    color: var(--accent);
    text-decoration: none;
}

/* --- Buttons --- */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.6rem 1.4rem;
    border: none;
    border-radius: 6px;
    font-family: var(--font);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
    text-decoration: none;
}
.btn-primary { background: var(--accent); color: #0d1117; }
.btn-primary:hover { background: #a5d3ff; color: #0d1117; text-decoration: none; }
.btn-success { background: var(--accent2); color: #0d1117; }
.btn-success:hover { background: #7ee787; color: #0d1117; text-decoration: none; }
.btn-outline {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-muted);
}
.btn-outline:hover { border-color: var(--accent); color: var(--accent); text-decoration: none; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-sm { padding: 0.35rem 0.85rem; font-size: 0.8rem; }
button[type=submit] { /* alias */ }

/* --- Post Cards Grid (archive) --- */
.posts-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 1.25rem;
    margin-top: 1.5rem;
}
.post-card {
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    transition: transform var(--transition), border-color var(--transition), box-shadow var(--transition);
    text-decoration: none;
    color: var(--text);
}
.post-card:hover {
    transform: translateY(-3px);
    border-color: var(--accent);
    box-shadow: 0 8px 32px rgba(88,166,255,0.12);
    text-decoration: none;
    color: var(--text);
}
.post-card-img {
    width: 100%;
    height: 180px;
    object-fit: cover;
    background: var(--bg3);
}
.post-card-img-placeholder {
    width: 100%;
    height: 180px;
    background: linear-gradient(135deg, var(--bg3), #0d1f3c);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2.5rem;
    color: var(--border);
}
.post-card-body { padding: 1.1rem; flex: 1; display: flex; flex-direction: column; gap: 0.5rem; }
.post-card-category {
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--accent);
}
.post-card-title {
    font-size: 1rem;
    font-weight: 700;
    line-height: 1.4;
    color: var(--text);
}
.post-card-meta { font-size: 0.78rem; color: var(--text-muted); margin-top: auto; }
.post-card-tags { display: flex; flex-wrap: wrap; gap: 0.3rem; }

/* --- Tag pills --- */
.tag {
    display: inline-block;
    padding: 0.2rem 0.6rem;
    background: rgba(88,166,255,0.1);
    border: 1px solid rgba(88,166,255,0.25);
    border-radius: 20px;
    font-size: 0.72rem;
    color: var(--accent);
    font-weight: 500;
    transition: background var(--transition);
}
.tag:hover { background: rgba(88,166,255,0.2); text-decoration: none; }
.tag-green {
    background: rgba(63,185,80,0.1);
    border-color: rgba(63,185,80,0.25);
    color: var(--accent2);
}

/* --- Search bar --- */
.search-bar {
    display: flex;
    gap: 0.6rem;
    margin-bottom: 1.5rem;
}
.search-bar input { flex: 1; }

/* --- Article view --- */
.article-hero {
    width: 100%;
    max-height: 420px;
    object-fit: cover;
    border-radius: var(--radius);
    margin-bottom: 2rem;
    border: 1px solid var(--border);
}
.article-header { margin-bottom: 1.5rem; }
.article-header h1 {
    font-size: 2rem;
    font-weight: 800;
    line-height: 1.3;
    margin-bottom: 0.75rem;
}
.article-meta {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.75rem;
    font-size: 0.85rem;
    color: var(--text-muted);
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border);
    margin-bottom: 1.25rem;
}
.article-meta .badge {
    padding: 0.25rem 0.7rem;
    background: rgba(88,166,255,0.15);
    border-radius: 20px;
    color: var(--accent);
    font-weight: 600;
    font-size: 0.8rem;
}
.article-body {
    font-size: 1.05rem;
    line-height: 1.85;
    color: #cdd9e5;
}
.article-body p  { margin-bottom: 1.1em; }
.article-body h2 {
    font-size: 1.35rem;
    font-weight: 700;
    color: var(--text);
    margin: 2rem 0 0.6rem;
    padding-bottom: 0.35rem;
    border-bottom: 1px solid var(--border);
}
.article-body h3 {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--accent);
    margin: 1.5rem 0 0.4rem;
}
.article-tags { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-top: 2rem; padding-top: 1.25rem; border-top: 1px solid var(--border); }
.article-tags .label { font-size: 0.8rem; color: var(--text-muted); font-weight: 600; margin-right: 0.25rem; align-self: center; }

/* --- Action bar (view_post) --- */
.action-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin-top: 2rem;
    padding-top: 1.25rem;
    border-top: 1px solid var(--border);
    align-items: center;
}
.action-bar-spacer { flex: 1; }

/* --- Spinner / Loading --- */
.spinner {
    display: none;
    width: 20px; height: 20px;
    border: 2px solid rgba(255,255,255,0.2);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* --- Alert --- */
.alert {
    padding: 0.85rem 1rem;
    border-radius: 6px;
    font-size: 0.9rem;
    margin-bottom: 1rem;
}
.alert-info    { background: rgba(88,166,255,0.1); border: 1px solid rgba(88,166,255,0.3); color: var(--accent); }
.alert-danger  { background: rgba(248,81,73,0.1);  border: 1px solid rgba(248,81,73,0.3);  color: var(--danger); }
.alert-success { background: rgba(63,185,80,0.1);  border: 1px solid rgba(63,185,80,0.3);  color: var(--accent2); }

/* --- Pagination --- */
.pagination {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    justify-content: center;
    margin-top: 2rem;
}
.pagination a,
.pagination strong {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px; height: 36px;
    border-radius: 6px;
    border: 1px solid var(--border);
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-muted);
    text-decoration: none;
    transition: all var(--transition);
}
.pagination a:hover   { border-color: var(--accent); color: var(--accent); background: rgba(88,166,255,0.08); }
.pagination strong    { background: var(--accent); border-color: var(--accent); color: #0d1117; }

/* --- Stats row --- */
.stats-row {
    display: flex;
    gap: 1rem;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
}
.stat-box {
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem 1.5rem;
    min-width: 130px;
    text-align: center;
}
.stat-box .num { font-size: 1.75rem; font-weight: 800; color: var(--accent); }
.stat-box .lbl { font-size: 0.75rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.07em; }

/* --- Footer --- */
.footer {
    text-align: center;
    padding: 2rem 1rem;
    color: var(--text-muted);
    font-size: 0.8rem;
    border-top: 1px solid var(--border);
    margin-top: 3rem;
}

/* --- Ad slot (public pages) --- */
.ad-slot {
    margin: 1.5rem 0;
    overflow: hidden;
}

/* --- Ad slot cards (admin_ads settings page) --- */
.ad-slot-block {
    background: var(--bg3);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem 1.1rem;
    margin-bottom: 0.9rem;
}
.ad-slot-block-label {
    font-size: 0.8rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    color: var(--accent);
    margin-bottom: 0.75rem;
}
.ad-slot-block-fields {
    display: flex;
    gap: 0.85rem;
    align-items: flex-end;
    flex-wrap: wrap;
}
.ad-slot-block-fields .form-group { flex-shrink: 0; }

code {
    font-family: 'Consolas', 'Fira Code', monospace;
    font-size: 0.85em;
    background: rgba(88,166,255,0.08);
    border: 1px solid rgba(88,166,255,0.18);
    border-radius: 4px;
    padding: 0.1em 0.38em;
    color: var(--accent);
}

.admin-card,
.legal-card {
    max-width: 100%;
}

.legal-card h2 {
    margin-top: 1.25rem;
    margin-bottom: 0.45rem;
}

.legal-card p {
    color: #cdd9e5;
}

.admin-title,
.section-title {
    margin-bottom: 1rem;
}

.table-wrap {
    overflow-x: auto;
}

.admin-table {
    width: 100%;
    border-collapse: collapse;
    min-width: 760px;
}

.admin-table th,
.admin-table td {
    padding: 0.75rem;
    border-bottom: 1px solid var(--border);
    text-align: left;
    vertical-align: middle;
}

.admin-table th {
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
}

.admin-actions {
    display: flex;
    gap: 0.4rem;
    align-items: center;
}

.admin-actions form {
    margin: 0;
}

.zoomable-image {
    cursor: zoom-in;
}

.zoom-modal {
    position: fixed;
    inset: 0;
    z-index: 9999;
    align-items: center;
    justify-content: center;
}

.zoom-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.82);
}

.zoom-content {
    position: relative;
    z-index: 2;
    max-width: 92vw;
    max-height: 92vh;
    display: flex;
    align-items: center;
    justify-content: center;
}

.zoom-content img {
    max-width: 92vw;
    max-height: 88vh;
    border-radius: 12px;
    border: 1px solid var(--border);
    box-shadow: 0 10px 40px rgba(0,0,0,0.45);
}

.zoom-close {
    position: absolute;
    top: -42px;
    right: 0;
    border: 0;
    background: transparent;
    color: #fff;
    font-size: 2rem;
    cursor: pointer;
}

.zoom-loading {
    color: #fff;
    font-weight: 600;
}

.share-title {
    font-size: 0.78rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
    margin-bottom: 0.55rem;
}

.share-row {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.consent-banner {
    position: fixed;
    left: 1rem;
    right: 1rem;
    bottom: 1rem;
    z-index: 1200;
}

.consent-content {
    max-width: 860px;
    margin: 0 auto;
    background: rgba(22, 27, 34, 0.98);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 1rem 1rem 0.9rem;
    box-shadow: 0 12px 36px rgba(0,0,0,0.45);
}

.consent-title {
    font-weight: 800;
    margin-bottom: 0.35rem;
}

.consent-content p {
    color: #cdd9e5;
    font-size: 0.9rem;
    margin-bottom: 0.6rem;
}

.consent-links {
    display: flex;
    gap: 0.35rem;
    font-size: 0.82rem;
    margin-bottom: 0.75rem;
    color: var(--text-muted);
}

.consent-actions {
    display: flex;
    gap: 0.5rem;
    justify-content: flex-end;
}

.consent-manage-btn {
    position: fixed;
    left: 1rem;
    bottom: 0.85rem;
    z-index: 1190;
    border: 1px solid var(--border);
    background: rgba(22, 27, 34, 0.96);
    color: var(--text-muted);
    border-radius: 999px;
    padding: 0.5rem 0.85rem;
    font-size: 0.78rem;
    font-weight: 600;
    cursor: pointer;
}

.consent-manage-btn:hover {
    color: var(--text);
    border-color: var(--accent);
}

/* --- Responsive --- */
@media (max-width: 640px) {
    .navbar { padding: 0 1rem; }
    .hero h1 { font-size: 1.4rem; }
    .page, .page-sm { padding: 1.5rem 1rem; }
    .posts-grid { grid-template-columns: 1fr; }
    .article-header h1 { font-size: 1.4rem; }
    .stats-row { flex-direction: column; }
    .consent-actions { justify-content: stretch; }
    .consent-actions .btn { flex: 1; justify-content: center; }
    body.consent-open { padding-bottom: 260px; }
}
