/* style.css — Mobile-first, SEO-optimized */

:root {
    --primary-color: #0284c7;
    --primary-hover: #0369a1;
    --bg-color: #f8fafc;
    --card-bg: #ffffff;
    --text-main: #1e293b;
    --text-muted: #64748b;
    --border-color: #e2e8f0;
    --danger-color: #ef4444;
    --danger-hover: #dc2626;
    --success-color: #10b981;
}

*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-main);
    line-height: 1.6;
    padding-bottom: 40px;
    -webkit-text-size-adjust: 100%;
}

a {
    color: var(--primary-color);
    text-decoration: none;
    transition: color 0.2s;
}

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

/* ---- HEADER ---- */
header {
    background-color: var(--card-bg);
    border-bottom: 1px solid var(--border-color);
    padding: 12px 16px;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.02);
}

.header-container {
    max-width: 600px;
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.logo {
    font-size: 1.3rem;
    font-weight: 800;
    color: var(--text-main);
    letter-spacing: -0.5px;
}

.logo span {
    color: var(--primary-color);
}

.logo:hover {
    text-decoration: none;
}

.nav-links {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* ---- LAYOUT ---- */
.container {
    max-width: 600px;
    margin: 15px auto;
    padding: 0 16px;
}

/* ---- HOMEPAGE HERO ---- */
.hero {
    text-align: center;
    margin: 24px 0 32px;
}

.hero h1 {
    font-size: 1.6rem;
    font-weight: 800;
    letter-spacing: -0.5px;
    margin-bottom: 8px;
    color: var(--text-main);
}

.hero p {
    color: var(--text-muted);
    font-size: 0.95rem;
}

/* ---- POST LIST ---- */
.posts-list {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

/* ---- POST CARD ---- */
.post-card {
    background-color: var(--card-bg);
    border-radius: 14px;
    padding: 18px;
    box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.05), 0 1px 2px -1px rgba(0, 0, 0, 0.05);
    border: 1px solid var(--border-color);
    content-visibility: auto;
    contain-intrinsic-size: auto 200px;
}

.post-card h2 {
    font-size: 1.2rem;
    font-weight: 700;
    line-height: 1.35;
    margin-bottom: 8px;
}

.post-card h2 a {
    color: var(--text-main);
}

.post-card h2 a:hover {
    color: var(--primary-color);
    text-decoration: none;
}

.post-meta {
    font-size: 0.78rem;
    color: var(--text-muted);
    font-weight: 500;
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.post-excerpt {
    color: var(--text-muted);
    font-size: 0.9rem;
    margin-bottom: 16px;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.btn-readmore {
    display: inline-flex;
    align-items: center;
    color: var(--primary-color);
    font-size: 0.88rem;
    font-weight: 600;
}

.btn-readmore:hover {
    text-decoration: none;
    transform: translateX(3px);
    transition: transform 0.2s;
}

/* ---- POST DETAIL ---- */
.post-detail {
    background-color: var(--card-bg);
    border-radius: 16px;
    padding: 24px 20px;
    box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.05);
    border: 1px solid var(--border-color);
    content-visibility: auto;
    contain-intrinsic-size: auto 500px;
}

.post-detail h1 {
    font-size: 1.5rem;
    line-height: 1.3;
    font-weight: 800;
    margin-bottom: 12px;
    color: var(--text-main);
}

.post-content {
    font-size: 0.98rem;
    line-height: 1.7;
    color: #334155;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.post-content p {
    margin-bottom: 16px;
}

.post-content ul,
.post-content ol {
    margin-bottom: 16px;
    padding-left: 20px;
}

.post-content li {
    margin-bottom: 6px;
}

/* Responsive images inside content */
.post-content img {
    max-width: 100%;
    height: auto;
    border-radius: 8px;
    margin: 12px 0;
}

.post-content blockquote {
    border-left: 3px solid var(--primary-color);
    padding-left: 16px;
    margin: 16px 0;
    color: var(--text-muted);
    font-style: italic;
}

.post-content pre,
.post-content code {
    font-family: "SF Mono", "Fira Code", monospace;
    font-size: 0.85em;
    background: #f1f5f9;
    padding: 2px 6px;
    border-radius: 4px;
    overflow-x: auto;
}

.post-content pre {
    padding: 12px;
    margin: 16px 0;
    white-space: pre-wrap;
}

/* ---- BREADCRUMBS ---- */
.breadcrumbs {
    margin-bottom: 16px;
    font-size: 0.78rem;
}

.breadcrumbs ol {
    list-style: none;
    display: flex;
    flex-wrap: wrap;
    gap: 2px;
    padding: 0;
    margin: 0;
}

.breadcrumbs li {
    display: flex;
    align-items: center;
    gap: 2px;
    color: var(--text-muted);
}

.breadcrumbs li:not(:last-child)::after {
    content: '/';
    margin: 0 4px;
    color: var(--border-color);
    font-weight: 600;
}

.breadcrumbs a {
    color: var(--text-muted);
    font-weight: 500;
}

.breadcrumbs a:hover {
    color: var(--primary-color);
}

/* ---- POST FOOTER ---- */
.post-footer {
    margin-top: 24px;
    padding-top: 20px;
    border-top: 1px solid var(--border-color);
}

.post-footer .btn-back {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--text-muted);
}

.post-footer .btn-back:hover {
    color: var(--primary-color);
    text-decoration: none;
}

/* ---- BACK BUTTON (global fallback) ---- */
.btn-back {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 16px;
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--text-muted);
}

.btn-back:hover {
    color: var(--primary-color);
    text-decoration: none;
}

/* ---- PAGINATION ---- */
.pagination {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 24px;
}

.pagination-info {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-muted);
}

/* ---- BUTTONS ---- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background-color: var(--primary-color);
    color: white;
    padding: 10px 18px;
    border-radius: 10px;
    border: none;
    font-weight: 600;
    font-size: 0.9rem;
    cursor: pointer;
    text-align: center;
    transition: all 0.2s;
    font-family: inherit;
}

.btn:hover {
    background-color: var(--primary-hover);
    text-decoration: none;
    color: white;
}

.btn-secondary {
    background-color: #f1f5f9;
    color: #475569;
}

.btn-secondary:hover {
    background-color: #e2e8f0;
    color: #1e293b;
}

.btn-danger {
    background-color: #fee2e2;
    color: #ef4444;
    border: none;
}

.btn-danger:hover {
    background-color: #fca5a5;
    color: #b91c1c;
}

.btn-sm {
    padding: 6px 12px;
    font-size: 0.8rem;
    border-radius: 8px;
}

/* ---- FORMS ---- */
.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    font-weight: 600;
    margin-bottom: 6px;
    font-size: 0.88rem;
    color: #334155;
}

.form-control {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border-color);
    border-radius: 10px;
    font-family: inherit;
    font-size: 0.95rem;
    background-color: #f8fafc;
    outline: none;
    transition: all 0.2s;
}

.form-control:focus {
    border-color: var(--primary-color);
    background-color: #ffffff;
    box-shadow: 0 0 0 3px rgba(2, 132, 199, 0.12);
}

textarea.form-control {
    resize: vertical;
    min-height: 200px;
    line-height: 1.6;
}

/* ---- ALERTS ---- */
.alert {
    padding: 12px 16px;
    border-radius: 10px;
    margin-bottom: 16px;
    font-size: 0.88rem;
    font-weight: 500;
}

.alert-danger {
    background-color: #fee2e2;
    color: #991b1b;
    border: 1px solid #fca5a5;
}

.alert-success {
    background-color: #d1fae5;
    color: #065f46;
    border: 1px solid #6ee7b7;
}

/* ---- ADMIN LIST ---- */
.admin-post-item {
    background-color: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 14px 16px;
    margin-bottom: 10px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
}

.admin-post-info {
    flex: 1;
    min-width: 0;
}

.admin-post-info h3 {
    font-size: 0.95rem;
    font-weight: 700;
    margin-bottom: 4px;
    white-space: nowrap;
    text-overflow: ellipsis;
    overflow: hidden;
}

.admin-post-actions {
    display: flex;
    gap: 6px;
}

/* ---- FOOTER ---- */
footer {
    text-align: center;
    padding: 24px 16px;
    font-size: 0.78rem;
    color: var(--text-muted);
    border-top: 1px solid var(--border-color);
    margin-top: 40px;
    background-color: var(--card-bg);
}

/* ============================================================
   PRINT STYLES
   ============================================================ */
@media print {
    header,
    footer,
    .btn-back,
    .btn-readmore,
    .pagination,
    .nav-links,
    .post-footer {
        display: none !important;
    }

    body {
        background: white;
        color: black;
        font-size: 12pt;
        line-height: 1.5;
        padding: 0;
    }

    .container {
        max-width: 100%;
        margin: 0;
        padding: 0;
    }

    .post-card,
    .post-detail {
        box-shadow: none;
        border: none;
        padding: 0;
        border-radius: 0;
        content-visibility: visible;
    }

    .post-content {
        font-size: 11pt;
    }

    a {
        color: black;
        text-decoration: underline;
    }

    .post-detail h1 {
        font-size: 18pt;
        margin-bottom: 8pt;
    }

    .breadcrumbs {
        margin-bottom: 8pt;
    }

    a[href^="http"]::after,
    a[href^="/"]::after {
        content: " (" attr(href) ")";
        font-size: 0.8em;
        color: #666;
    }
}

/* ============================================================
   RESPONSIVE: Very small screens (< 360px)
   ============================================================ */
@media (max-width: 360px) {
    .header-container {
        flex-direction: column;
        gap: 6px;
    }

    .post-card {
        padding: 14px;
    }

    .post-card h2 {
        font-size: 1.05rem;
    }

    .post-detail {
        padding: 16px 14px;
    }

    .post-detail h1 {
        font-size: 1.25rem;
    }

    .admin-post-item {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }

    .admin-post-actions {
        width: 100%;
        justify-content: flex-end;
    }
}

/* ============================================================
   SEARCH FORM
   ============================================================ */
.search-form {
    margin-bottom: 20px;
}

.search-row {
    display: flex;
    gap: 6px;
    align-items: center;
    flex-wrap: wrap;
}

.search-input {
    flex: 1;
    min-width: 140px;
}

.search-select {
    width: auto;
    min-width: 130px;
    background-color: #fff;
}

.search-info {
    font-size: 0.82rem;
    color: var(--text-muted);
    margin-bottom: 16px;
    padding: 8px 12px;
    background: #f1f5f9;
    border-radius: 8px;
}

/* ============================================================
   CATEGORY TAGS (on post detail)
   ============================================================ */
.post-categories {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 8px;
    margin-bottom: 16px;
}

.category-tag {
    display: inline-block;
    padding: 4px 10px;
    background: #e0f2fe;
    color: #0369a1;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
    text-decoration: none;
    transition: all 0.2s;
}

.category-tag:hover {
    background: #bae6fd;
    color: #0284c7;
    text-decoration: none;
}

/* Category tags on post cards (smaller) */
.post-card-cats {
    display: inline-flex;
    gap: 4px;
    margin-left: 2px;
}

.category-tag-sm {
    display: inline-block;
    padding: 2px 8px;
    background: #f1f5f9;
    color: #64748b;
    border-radius: 12px;
    font-size: 0.7rem;
    font-weight: 600;
    text-decoration: none;
    transition: all 0.2s;
}

.category-tag-sm:hover {
    background: #e0f2fe;
    color: #0369a1;
    text-decoration: none;
}

/* ============================================================
   CATEGORY CHECKBOXES (admin form)
   ============================================================ */
.category-checkboxes {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.category-checkbox-label {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    background: #f8fafc;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
    user-select: none;
}

.category-checkbox-label:hover {
    border-color: var(--primary-color);
    background: #e0f2fe;
}

.category-checkbox-label input[type="checkbox"] {
    accent-color: var(--primary-color);
    width: 15px;
    height: 15px;
}

/* ============================================================
   DARK MODE
   ============================================================ */
[data-theme="dark"] {
    --primary-color: #38bdf8;
    --primary-hover: #7dd3fc;
    --bg-color: #0f172a;
    --card-bg: #1e293b;
    --text-main: #e2e8f0;
    --text-muted: #94a3b8;
    --border-color: #334155;
    --danger-color: #f87171;
    --danger-hover: #ef4444;
    --success-color: #34d399;
}

[data-theme="dark"] .form-control {
    background-color: #1e293b;
    color: #e2e8f0;
}

[data-theme="dark"] .btn-secondary {
    background-color: #334155;
    color: #cbd5e1;
}

[data-theme="dark"] .search-info {
    background: #1e293b;
}

[data-theme="dark"] .category-tag {
    background: #1e3a5f;
    color: #7dd3fc;
}

[data-theme="dark"] .category-tag-sm {
    background: #334155;
    color: #94a3b8;
}

/* Dark toggle button */
.dark-toggle {
    background: none;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 6px 8px;
    cursor: pointer;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    transition: all 0.2s;
}

.dark-toggle:hover {
    color: var(--primary-color);
    border-color: var(--primary-color);
}

.dark-toggle .moon-icon { display: none; }
.dark-toggle .sun-icon { display: inline; }
[data-theme="dark"] .dark-toggle .sun-icon { display: none; }
[data-theme="dark"] .dark-toggle .moon-icon { display: inline; }

/* ============================================================
   READING TIME
   ============================================================ */
.reading-time, .reading-time-sm {
    color: var(--text-muted);
    font-weight: 500;
}

/* ============================================================
   TABLE OF CONTENTS
   ============================================================ */
.toc {
    background: #f8fafc;
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 16px 20px;
    margin-bottom: 20px;
}

[data-theme="dark"] .toc {
    background: #0f172a;
}

.toc-title {
    font-size: 0.9rem;
    font-weight: 700;
    cursor: pointer;
    color: var(--text-main);
    list-style: none;
}

.toc-title::-webkit-details-marker { display: none; }

.toc-list {
    margin-top: 10px;
    padding-left: 20px;
    font-size: 0.88rem;
    line-height: 1.8;
}

.toc-item { margin-bottom: 2px; }
.toc-item a { color: var(--text-muted); }
.toc-item a:hover { color: var(--primary-color); text-decoration: none; }
.toc-h3 { padding-left: 16px; font-size: 0.82rem; }

/* ============================================================
   RELATED POSTS
   ============================================================ */
.related-posts {
    margin-top: 24px;
}

.related-title {
    font-size: 1rem;
    font-weight: 700;
    margin-bottom: 12px;
    color: var(--text-main);
}

.related-grid {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.related-card {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    text-decoration: none;
    transition: all 0.15s;
}

.related-card:hover {
    border-color: var(--primary-color);
    transform: translateX(3px);
    text-decoration: none;
}

.related-card-title {
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--text-main);
}

.related-card-date {
    font-size: 0.75rem;
    color: var(--text-muted);
    white-space: nowrap;
}

/* ============================================================
   SOCIAL SHARE BUTTONS
   ============================================================ */
.share-buttons {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 6px;
    padding: 14px 0;
    margin-top: 16px;
    border-top: 1px solid var(--border-color);
    border-bottom: 1px solid var(--border-color);
}

.share-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border-radius: 8px;
    color: #fff;
    transition: opacity 0.2s;
}

.share-btn:hover { opacity: 0.8; color: #fff; text-decoration: none; }
.share-tw  { background: #1da1f2; }
.share-wa  { background: #25d366; }
.share-tg  { background: #0088cc; }
.share-fb  { background: #1877f2; }

/* ============================================================
   POST ACTIONS (TTS + PRINT)
   ============================================================ */
.post-actions {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
}

.action-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    background: #f1f5f9;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.15s;
    font-family: inherit;
}

.action-btn:hover {
    background: var(--primary-color);
    color: #fff;
    border-color: var(--primary-color);
}

.tts-active {
    background: var(--primary-color);
    color: #fff;
    border-color: var(--primary-color);
}

[data-theme="dark"] .action-btn {
    background: #334155;
    border-color: #475569;
}

/* ============================================================
   POST NAVIGATION (prev/next)
   ============================================================ */
.post-navigation {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    margin-top: 24px;
}

.post-nav-link {
    flex: 1;
    max-width: 48%;
    padding: 14px 16px;
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    text-decoration: none;
    transition: all 0.15s;
}

.post-nav-link:hover {
    border-color: var(--primary-color);
    text-decoration: none;
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}

.post-nav-next {
    text-align: right;
    margin-left: auto;
}

.post-nav-label {
    display: block;
    font-size: 0.72rem;
    color: var(--text-muted);
    font-weight: 600;
    margin-bottom: 4px;
}

.post-nav-title {
    display: block;
    font-size: 0.88rem;
    font-weight: 700;
    color: var(--text-main);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* Subscribe section */
.subscribe-section { background:var(--card-bg); border-top:1px solid var(--border-color); margin-top:30px; }
.subscribe-form { display:flex; justify-content:center; gap:6px; flex-wrap:wrap; }
@media (max-width:400px) { .subscribe-form { flex-direction:column; align-items:center; } }

/* Tags */
.post-tags { display:flex; flex-wrap:wrap; gap:6px; margin-top:4px; margin-bottom:16px; }
.tag-link { display:inline-block; padding:2px 10px; background:#f1f5f9; color:#64748b; border-radius:12px; font-size:0.73rem; font-weight:600; text-decoration:none; transition:all 0.15s; }
.tag-link:hover { background:var(--primary-color); color:#fff; text-decoration:none; }
.tag-link-sm { font-size:0.68rem; padding:1px 7px; background:#f1f5f9; color:#64748b; border-radius:10px; font-weight:600; text-decoration:none; white-space:nowrap; }
.tag-link-sm:hover { background:var(--primary-color); color:#fff; text-decoration:none; }
[data-theme="dark"] .tag-link, [data-theme="dark"] .tag-link-sm { background:#334155; color:#94a3b8; }

/* Archive cloud */
.archive-cloud { display:flex; flex-wrap:wrap; gap:8px; align-items:baseline; }
.archive-tag, .archive-cat { display:inline-flex; align-items:center; gap:4px; padding:6px 14px; background:var(--card-bg); border:1px solid var(--border-color); border-radius:20px; text-decoration:none; color:var(--text-main); font-weight:600; transition:all 0.15s; }
.archive-tag:hover, .archive-cat:hover { border-color:var(--primary-color); color:var(--primary-color); text-decoration:none; transform:translateY(-1px); box-shadow:0 2px 8px rgba(0,0,0,0.06); }
.archive-count { font-size:0.7rem; color:var(--text-muted); background:#f1f5f9; padding:1px 8px; border-radius:10px; }
[data-theme="dark"] .archive-count { background:#334155; }

/* Dashboard stats */
.stats-grid { display:grid; grid-template-columns:repeat(auto-fit, minmax(100px, 1fr)); gap:10px; margin-bottom:20px; }
.stat-card { background:var(--card-bg); border:1px solid var(--border-color); border-radius:12px; padding:16px 12px; text-align:center; }
.stat-number { font-size:1.5rem; font-weight:800; color:var(--text-main); line-height:1.2; }
.stat-label { font-size:0.7rem; color:var(--text-muted); font-weight:600; margin-top:4px; text-transform:uppercase; letter-spacing:0.5px; }
.stat-published .stat-number { color:var(--success-color); }
.stat-draft .stat-number { color:#f59e0b; }
.stat-views .stat-number { color:var(--primary-color); }
.stat-comments .stat-number { color:#8b5cf6; }

/* Moderation */
.moderation-box { background:#fffbeb; border:1px solid #fde68a; border-radius:12px; padding:16px; margin-bottom:20px; }
[data-theme="dark"] .moderation-box { background:#1e1b4b; border-color:#4c1d95; }
.mod-item { display:flex; justify-content:space-between; align-items:flex-start; gap:12px; padding:10px 0; border-bottom:1px solid #fde68a; }
.mod-item:last-child { border-bottom:0; }
[data-theme="dark"] .mod-item { border-color:#4c1d95; }
