/*
Theme Name: Davis Tech
Theme URI: https://fan.hapi.lat
Author: Davis
Author URI: https://fan.hapi.lat
Description: A clean, modern technical blog theme with code syntax highlighting, table of contents, and one-click code copy.
Version: 1.0.0
Requires at least: 6.0
Tested up to: 6.8
Requires PHP: 8.0
License: GNU General Public License v2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html
Text Domain: davis-tech
Tags: blog, technology, code, syntax-highlighting, dark-mode
*/

/* ========== Reset & Base ========== */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --bg-primary: #0d1117;
    --bg-secondary: #161b22;
    --bg-tertiary: #21262d;
    --bg-card: #161b22;
    --text-primary: #e6edf3;
    --text-secondary: #8b949e;
    --text-muted: #6e7681;
    --accent: #58a6ff;
    --accent-hover: #79c0ff;
    --accent-dim: #1f6feb33;
    --border: #30363d;
    --border-light: #21262d;
    --success: #3fb950;
    --warning: #d29922;
    --danger: #f85149;
    --code-bg: #0d1117;
    --code-border: #30363d;
    --toc-bg: #161b22;
    --sidebar-width: 260px;
    --content-max: 780px;
    --header-height: 64px;
    --radius: 8px;
    --radius-sm: 4px;
    --shadow: 0 1px 3px rgba(0,0,0,0.3), 0 1px 2px rgba(0,0,0,0.2);
    --shadow-lg: 0 8px 24px rgba(0,0,0,0.4);
    --transition: 0.2s ease;
    --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans", Helvetica, Arial, sans-serif;
    --font-mono: "JetBrains Mono", "Fira Code", "Cascadia Code", "Source Code Pro", ui-monospace, monospace;
    --font-body: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans SC", "PingFang SC", "Microsoft YaHei", sans-serif;
}

html {
    scroll-behavior: smooth;
    font-size: 16px;
}

body {
    font-family: var(--font-body);
    background-color: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.7;
    min-height: 100vh;
    overflow-x: hidden;
}

a {
    color: var(--accent);
    text-decoration: none;
    transition: color var(--transition);
}

a:hover {
    color: var(--accent-hover);
}

img {
    max-width: 100%;
    height: auto;
}

::selection {
    background: var(--accent);
    color: #fff;
}

/* ========== Scrollbar ========== */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}
::-webkit-scrollbar-track {
    background: var(--bg-primary);
}
::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* ========== Header ========== */
.site-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--header-height);
    background: rgba(13, 17, 23, 0.85);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border);
    z-index: 1000;
    transition: transform 0.3s ease;
}

.site-header .container {
    max-width: 1280px;
    margin: 0 auto;
    padding: 0 24px;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.site-branding {
    display: flex;
    align-items: center;
    gap: 12px;
}

.site-branding .logo {
    width: 36px;
    height: 36px;
    background: linear-gradient(135deg, var(--accent), #a371f7);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 18px;
    color: #fff;
    font-family: var(--font-mono);
}

.site-branding .site-title {
    font-size: 18px;
    font-weight: 700;
    color: var(--text-primary);
    font-family: var(--font-sans);
}

.site-branding .site-title a {
    color: var(--text-primary);
}

.main-nav ul {
    list-style: none;
    display: flex;
    gap: 4px;
}

.main-nav a {
    display: block;
    padding: 8px 14px;
    color: var(--text-secondary);
    font-size: 14px;
    font-weight: 500;
    border-radius: var(--radius-sm);
    transition: all var(--transition);
}

.main-nav a:hover,
.main-nav .current-menu-item a {
    color: var(--text-primary);
    background: var(--bg-tertiary);
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.search-toggle,
.mobile-menu-toggle {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 8px;
    border-radius: var(--radius-sm);
    transition: all var(--transition);
    font-size: 18px;
}

.search-toggle:hover,
.mobile-menu-toggle:hover {
    color: var(--text-primary);
    background: var(--bg-tertiary);
}

.mobile-menu-toggle {
    display: none;
}

/* ========== Layout ========== */
.site-content {
    margin-top: var(--header-height);
    min-height: calc(100vh - var(--header-height));
}

.container {
    max-width: 1280px;
    margin: 0 auto;
    padding: 0 24px;
}

.content-area {
    display: flex;
    gap: 32px;
    padding: 32px 0;
    justify-content: center;
}

.main-content {
    flex: 1;
    min-width: 0;
    max-width: var(--content-max);
}

.single .main-content,
.page .main-content {
    max-width: 100%;
}

.sidebar {
    width: var(--sidebar-width);
    flex-shrink: 0;
    position: sticky;
    top: calc(var(--header-height) + 24px);
    align-self: flex-start;
    max-height: calc(100vh - var(--header-height) - 48px);
    overflow-y: auto;
}

.single .sidebar {
    display: none;
}

.single .content-area {
    justify-content: center;
}

/* ========== Search Overlay ========== */
.search-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    z-index: 2000;
    display: none;
    align-items: flex-start;
    justify-content: center;
    padding-top: 120px;
}

.search-overlay.active {
    display: flex;
}

.search-box {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    width: 90%;
    max-width: 580px;
    box-shadow: var(--shadow-lg);
}

.search-box input {
    width: 100%;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 12px 16px;
    color: var(--text-primary);
    font-size: 16px;
    outline: none;
}

.search-box input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-dim);
}

/* ========== Post Cards (Archive) ========== */
.posts-grid {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.post-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    transition: all var(--transition);
}

.post-card:hover {
    border-color: var(--accent);
    box-shadow: var(--shadow);
}

.post-card-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
    font-size: 13px;
    color: var(--text-muted);
}

.post-card-header .post-category {
    background: var(--accent-dim);
    color: var(--accent);
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 500;
}

.post-card h2 {
    font-size: 20px;
    font-weight: 600;
    margin-bottom: 8px;
    line-height: 1.4;
}

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

.post-card h2 a:hover {
    color: var(--accent);
}

.post-card-excerpt {
    color: var(--text-secondary);
    font-size: 14px;
    line-height: 1.6;
    margin-bottom: 12px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.post-card-footer {
    display: flex;
    align-items: center;
    gap: 16px;
    font-size: 13px;
    color: var(--text-muted);
}

.post-card-footer span {
    display: flex;
    align-items: center;
    gap: 4px;
}

.post-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 12px;
}

.post-tags a {
    font-size: 12px;
    padding: 2px 8px;
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-light);
}

.post-tags a:hover {
    color: var(--accent);
    border-color: var(--accent);
}

/* ========== Single Post ========== */
.single-post {
    max-width: 100%;
    width: 100%;
}

.post-header {
    margin-bottom: 32px;
    padding-bottom: 24px;
    border-bottom: 1px solid var(--border);
}

.post-header .post-meta {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 12px;
    font-size: 13px;
    color: var(--text-muted);
}

.post-header .post-category {
    background: var(--accent-dim);
    color: var(--accent);
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 500;
}

.post-header h1 {
    font-size: 32px;
    font-weight: 700;
    line-height: 1.3;
    margin-bottom: 12px;
    letter-spacing: -0.02em;
}

.post-header .post-excerpt {
    color: var(--text-secondary);
    font-size: 16px;
    line-height: 1.6;
}

/* ========== Post Content ========== */
.post-content {
    font-size: 16px;
    line-height: 1.8;
}

.post-content h2 {
    font-size: 24px;
    font-weight: 600;
    margin: 48px 0 16px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border);
    letter-spacing: -0.01em;
}

.post-content h3 {
    font-size: 20px;
    font-weight: 600;
    margin: 36px 0 12px;
}

.post-content h4 {
    font-size: 17px;
    font-weight: 600;
    margin: 28px 0 8px;
}

.post-content p {
    margin-bottom: 16px;
    color: var(--text-primary);
}

.post-content ul, .post-content ol {
    margin: 0 0 16px 24px;
}

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

.post-content blockquote {
    margin: 20px 0;
    padding: 16px 20px;
    border-left: 4px solid var(--accent);
    background: var(--bg-secondary);
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
    color: var(--text-secondary);
}

.post-content blockquote p:last-child {
    margin-bottom: 0;
}

.post-content img {
    border-radius: var(--radius);
    margin: 16px 0;
    border: 1px solid var(--border);
}

.post-content table {
    width: 100%;
    border-collapse: collapse;
    margin: 16px 0;
    font-size: 14px;
}

.post-content th, .post-content td {
    padding: 10px 14px;
    border: 1px solid var(--border);
    text-align: left;
}

.post-content th {
    background: var(--bg-tertiary);
    font-weight: 600;
}

.post-content hr {
    border: none;
    border-top: 1px solid var(--border);
    margin: 32px 0;
}

/* Inline code */
.post-content code:not([class*="language-"]):not([class*="lang-"]) {
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 2px 6px;
    font-size: 0.88em;
    font-family: var(--font-mono);
    color: #ff7b72;
}

/* ========== Code Blocks ========== */
.code-block-wrapper {
    position: relative;
    margin: 20px 0;
    border-radius: var(--radius);
    border: 1px solid var(--code-border);
    overflow: hidden;
}

.code-block-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 16px;
    background: var(--bg-tertiary);
    border-bottom: 1px solid var(--code-border);
    font-size: 13px;
}

.code-block-lang {
    color: var(--text-secondary);
    font-family: var(--font-mono);
    font-weight: 500;
    text-transform: lowercase;
}

.code-copy-btn {
    display: flex;
    align-items: center;
    gap: 4px;
    background: none;
    border: 1px solid var(--border);
    color: var(--text-secondary);
    cursor: pointer;
    padding: 4px 10px;
    border-radius: var(--radius-sm);
    font-size: 12px;
    font-family: var(--font-sans);
    transition: all var(--transition);
}

.code-copy-btn:hover {
    color: var(--text-primary);
    border-color: var(--text-muted);
    background: var(--bg-secondary);
}

.code-copy-btn.copied {
    color: var(--success);
    border-color: var(--success);
}

.code-block-wrapper pre {
    margin: 0;
    padding: 16px;
    overflow-x: auto;
    background: var(--code-bg) !important;
}

.code-block-wrapper pre code {
    font-family: var(--font-mono);
    font-size: 14px;
    line-height: 1.6;
    tab-size: 4;
}

/* Line numbers */
.line-numbers .line-numbers-rows {
    border-right: 1px solid var(--border);
}

/* ========== TOC (Table of Contents) ========== */
.toc-wrapper {
    position: sticky;
    top: calc(var(--header-height) + 24px);
    margin-bottom: 24px;
    max-height: calc(100vh - var(--header-height) - 48px);
    overflow-y: auto;
}

.toc-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
}

.toc-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.toc-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.toc-list li {
    margin: 0;
}

.toc-list a {
    display: block;
    padding: 5px 0 5px 12px;
    font-size: 13px;
    color: var(--text-secondary);
    border-left: 2px solid transparent;
    transition: all var(--transition);
    line-height: 1.4;
}

.toc-list a:hover {
    color: var(--text-primary);
    border-left-color: var(--text-muted);
}

.toc-list a.active {
    color: var(--accent);
    border-left-color: var(--accent);
}

.toc-list .toc-h3 {
    padding-left: 24px;
    font-size: 12px;
}

.toc-list .toc-h4 {
    padding-left: 36px;
    font-size: 12px;
}

/* ========== Sidebar ========== */
.sidebar-widget {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 20px;
}

.sidebar-widget h3 {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 12px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border);
}

.sidebar-widget ul {
    list-style: none;
}

.sidebar-widget li {
    padding: 6px 0;
    border-bottom: 1px solid var(--border-light);
}

.sidebar-widget li:last-child {
    border-bottom: none;
}

.sidebar-widget a {
    font-size: 14px;
    color: var(--text-secondary);
}

.sidebar-widget a:hover {
    color: var(--accent);
}

/* ========== Post Navigation ========== */
.post-navigation {
    display: flex;
    gap: 16px;
    margin-top: 48px;
    padding-top: 24px;
    border-top: 1px solid var(--border);
}

.post-navigation a {
    flex: 1;
    padding: 16px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    transition: all var(--transition);
}

.post-navigation a:hover {
    border-color: var(--accent);
}

.post-nav-label {
    font-size: 12px;
    color: var(--text-muted);
    margin-bottom: 4px;
}

.post-nav-title {
    font-size: 14px;
    font-weight: 500;
    color: var(--text-primary);
}

.post-navigation .next {
    text-align: right;
}

/* ========== Comments ========== */
.comments-area {
    margin-top: 48px;
    padding-top: 24px;
    border-top: 1px solid var(--border);
}

.comments-area h2 {
    font-size: 20px;
    margin-bottom: 20px;
}

.comment-list {
    list-style: none;
}

.comment {
    padding: 16px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 12px;
}

.comment-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
}

.comment-author {
    font-weight: 600;
    font-size: 14px;
}

.comment-date {
    font-size: 12px;
    color: var(--text-muted);
}

.comment-body {
    font-size: 14px;
    color: var(--text-secondary);
    line-height: 1.6;
}

.comment-respond {
    margin-top: 24px;
}

.comment-respond textarea,
.comment-respond input {
    width: 100%;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 10px 14px;
    color: var(--text-primary);
    font-size: 14px;
    font-family: var(--font-body);
    margin-bottom: 12px;
    outline: none;
    transition: border-color var(--transition);
}

.comment-respond textarea:focus,
.comment-respond input:focus {
    border-color: var(--accent);
}

.comment-respond textarea {
    min-height: 120px;
    resize: vertical;
}

/* ========== Buttons ========== */
.btn, .comment-respond input[type="submit"] {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 10px 20px;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition);
    font-family: var(--font-body);
}

.btn:hover, .comment-respond input[type="submit"]:hover {
    background: var(--accent-hover);
    color: #fff;
}

/* ========== Pagination ========== */
.pagination {
    display: flex;
    justify-content: center;
    gap: 6px;
    margin-top: 32px;
    padding: 16px 0;
}

.pagination a, .pagination span {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 36px;
    height: 36px;
    padding: 0 10px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 14px;
    color: var(--text-secondary);
    transition: all var(--transition);
}

.pagination a:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.pagination .current {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

/* ========== Footer ========== */
.site-footer {
    background: var(--bg-secondary);
    border-top: 1px solid var(--border);
    padding: 32px 0;
    margin-top: 48px;
}

.site-footer .container {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 13px;
    color: var(--text-muted);
}

.site-footer a {
    color: var(--text-secondary);
}

.site-footer a:hover {
    color: var(--accent);
}

/* ========== 404 ========== */
.error-404 {
    text-align: center;
    padding: 80px 0;
}

.error-404 h1 {
    font-size: 120px;
    font-weight: 700;
    color: var(--border);
    line-height: 1;
}

.error-404 p {
    font-size: 18px;
    color: var(--text-secondary);
    margin: 16px 0 24px;
}

/* ========== Reading Progress ========== */
.reading-progress {
    position: fixed;
    top: var(--header-height);
    left: 0;
    right: 0;
    height: 2px;
    background: transparent;
    z-index: 999;
}

.reading-progress-bar {
    height: 100%;
    background: linear-gradient(90deg, var(--accent), #a371f7);
    width: 0%;
    transition: width 0.1s linear;
}

/* ========== Back to Top ========== */
.back-to-top {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 40px;
    height: 40px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    opacity: 0;
    visibility: hidden;
    transition: all var(--transition);
    z-index: 100;
}

.back-to-top.visible {
    opacity: 1;
    visibility: visible;
}

.back-to-top:hover {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}

/* ========== Single Post Layout ========== */
.single-content-area {
    justify-content: center;
}

.single-main-content {
    max-width: 960px;
    width: 100%;
    margin: 0 auto;
}

.post-content-wrapper {
    display: flex;
    gap: 32px;
    align-items: flex-start;
}

.post-content-wrapper .post-content {
    flex: 1;
    min-width: 0;
}

.toc-sidebar {
    width: 220px;
    flex-shrink: 0;
    position: sticky;
    top: calc(var(--header-height) + 24px);
    max-height: calc(100vh - var(--header-height) - 48px);
    overflow-y: auto;
    order: -1;
}

.toc-sidebar .toc-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
}

@media (max-width: 900px) {
    .toc-sidebar {
        display: none;
    }
}

/* ========== Archives ========== */
.archive-header {
    margin-bottom: 24px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border);
}

.archive-header h1 {
    font-size: 24px;
    font-weight: 600;
}

.archive-header .archive-desc {
    color: var(--text-secondary);
    font-size: 14px;
    margin-top: 4px;
}

/* ========== Post Footer Meta ========== */
.post-footer {
    margin-top: 32px;
    padding-top: 24px;
    border-top: 1px solid var(--border);
}

.post-footer .post-tags {
    margin-bottom: 16px;
}

/* ========== Mobile Responsive ========== */
@media (max-width: 1024px) {
    .sidebar {
        display: none;
    }

    .content-area {
        justify-content: center;
    }

    .main-content {
        max-width: 100%;
    }
}

@media (max-width: 768px) {
    :root {
        --header-height: 56px;
    }

    .mobile-menu-toggle {
        display: block;
    }

    .main-nav {
        display: none;
        position: absolute;
        top: var(--header-height);
        left: 0;
        right: 0;
        background: var(--bg-secondary);
        border-bottom: 1px solid var(--border);
        padding: 16px;
    }

    .main-nav.active {
        display: block;
    }

    .main-nav ul {
        flex-direction: column;
    }

    .content-area {
        padding: 16px 0;
    }

    .post-header h1 {
        font-size: 24px;
    }

    .post-content h2 {
        font-size: 20px;
    }

    .post-content h3 {
        font-size: 17px;
    }

    .post-navigation {
        flex-direction: column;
    }

    .site-footer .container {
        flex-direction: column;
        gap: 8px;
        text-align: center;
    }

    .container {
        padding: 0 16px;
    }
}

/* ========== Prism.js Overrides ========== */
pre[class*="language-"],
code[class*="language-"] {
    background: var(--code-bg) !important;
    color: #e6edf3;
    font-family: var(--font-mono) !important;
    font-size: 14px !important;
}

pre[class*="language-"] {
    border: none !important;
    margin: 0 !important;
}

/* Prism token colors (GitHub Dark) */
.token.comment,
.token.prolog,
.token.doctype,
.token.cdata { color: #8b949e; }
.token.punctuation { color: #e6edf3; }
.token.property,
.token.tag,
.token.boolean,
.token.number,
.token.constant,
.token.symbol,
.token.deleted { color: #79c0ff; }
.token.selector,
.token.attr-name,
.token.string,
.token.char,
.token.builtin,
.token.inserted { color: #a5d6ff; }
.token.operator,
.token.entity,
.token.url { color: #d2a8ff; }
.token.atrule,
.token.attr-value,
.token.keyword { color: #ff7b72; }
.token.function,
.token.class-name { color: #d2a8ff; }
.token.regex,
.token.important,
.token.variable { color: #ffa657; }
.token.important,
.token.bold { font-weight: bold; }
.token.italic { font-style: italic; }
