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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    line-height: 1.6;
    color: #333;
    background-color: #ffffff;
}

/* Overlay */
.overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 499;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.overlay.active {
    opacity: 1;
    visibility: visible;
}

/* Header */
.site-header {
    background-color: #fff;
    border-bottom: none;
    padding: 0;
    position: sticky;
    top: 0;
    z-index: 500;
    box-shadow: none;
}

/* Simple header for index page */
.site-header.simple-header {
    box-shadow: none;
    border-bottom: none;
}

.site-header.simple-header .header-container {
    justify-content: center;
}

.header-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 1.5rem;
    height: 64px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.logo a {
    text-decoration: none;
    color: #111;
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    transition: color 0.2s ease;
}

.logo a:hover {
    color: #2563eb;
}

.main-nav {
    display: flex;
}

.nav-list {
    list-style: none;
    display: flex;
    gap: 0.25rem;
    align-items: center;
}

.nav-item {
    position: relative;
}

.nav-link {
    text-decoration: none;
    color: #444;
    font-weight: 500;
    font-size: 0.95rem;
    padding: 0.5rem 0.875rem;
    border-radius: 6px;
    transition: all 0.2s ease;
    display: block;
}

.nav-link:hover {
    color: #2563eb;
    background-color: #f0f4ff;
}

.nav-link:active {
    background-color: #e0e9ff;
}

/* Hamburger Menu */
.hamburger {
    display: none;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    width: 40px;
    height: 40px;
    border: none;
    background: transparent;
    cursor: pointer;
    padding: 8px;
    border-radius: 6px;
    transition: background-color 0.2s ease;
}

.hamburger:hover {
    background-color: #f3f4f6;
}

.hamburger-line {
    display: block;
    width: 22px;
    height: 2px;
    background-color: #333;
    border-radius: 2px;
    transition: all 0.3s ease;
    margin: 3px 0;
}

.hamburger.active .hamburger-line:nth-child(1) {
    transform: translateY(8px) rotate(45deg);
}

.hamburger.active .hamburger-line:nth-child(2) {
    opacity: 0;
}

.hamburger.active .hamburger-line:nth-child(3) {
    transform: translateY(-8px) rotate(-45deg);
}

/* Mobile Menu */
.mobile-menu {
    position: fixed;
    top: 0;
    right: 0;
    width: 280px;
    max-width: 85vw;
    height: 100vh;
    background-color: #fff;
    z-index: 600;
    transform: translateX(100%);
    transition: transform 0.3s ease;
    box-shadow: -4px 0 20px rgba(0, 0, 0, 0.15);
    display: flex;
    flex-direction: column;
}

.mobile-menu.active {
    transform: translateX(0);
}

.mobile-menu-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.5rem;
    border-bottom: 1px solid #e8e8e8;
    height: 64px;
}

.mobile-menu-title {
    font-weight: 600;
    font-size: 1rem;
    color: #333;
}

.mobile-menu-close {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 36px;
    height: 36px;
    border: none;
    background: transparent;
    cursor: pointer;
    border-radius: 6px;
    color: #666;
    transition: all 0.2s ease;
}

.mobile-menu-close:hover {
    background-color: #f3f4f6;
    color: #333;
}

.mobile-nav {
    flex: 1;
    overflow-y: auto;
    padding: 1rem 0;
}

.mobile-nav-list {
    list-style: none;
    padding: 0;
}

.mobile-nav-item {
    margin: 0;
}

.mobile-nav-link {
    text-decoration: none;
    color: #333;
    font-weight: 500;
    font-size: 1rem;
    padding: 0.875rem 1.5rem;
    display: block;
    transition: all 0.2s ease;
    border-left: 3px solid transparent;
}

.mobile-nav-link:hover {
    background-color: #f9fafb;
    color: #2563eb;
    border-left-color: #2563eb;
}

/* Mobile Category Tree */
.mobile-category-tree {
    border-top: 1px solid #e8e8e8;
    margin-top: 0.5rem;
    padding-top: 0.5rem;
}

.mobile-category-item {
    margin: 0;
}

.mobile-category-header {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 0.75rem 1.5rem;
    cursor: pointer;
    transition: background-color 0.2s;
    user-select: none;
}

.mobile-category-header:hover {
    background-color: #f0f4ff;
}

.mobile-category-item.active > .mobile-category-header {
    background-color: #e0f2fe;
}

.mobile-category-item.active > .mobile-category-header .mobile-category-link {
    color: #2563eb;
    font-weight: 600;
}

.mobile-toggle-icon {
    font-size: 18px;
    color: #999;
    width: 20px;
    text-align: center;
    transition: transform 0.2s;
    flex-shrink: 0;
}

.mobile-category-item.expanded > .mobile-category-header .mobile-toggle-icon {
    transform: rotate(90deg);
}

.mobile-category-link {
    text-decoration: none;
    color: #333;
    flex: 1;
    font-weight: 500;
}

.mobile-article-count {
    font-size: 12px;
    color: #999;
    flex-shrink: 0;
}

.mobile-article-sublist {
    list-style: none;
    padding: 0;
    margin: 0;
    display: none;
    background-color: #fafafa;
}

.mobile-category-item.expanded > .mobile-article-sublist {
    display: block;
}

.mobile-article-sublist li {
    margin: 0;
}

.mobile-article-sublist li a {
    display: block;
    padding: 0.6rem 1.5rem 0.6rem 2.5rem;
    text-decoration: none;
    color: #555;
    font-size: 0.9rem;
    transition: all 0.2s;
    word-break: break-all;
}

.mobile-article-sublist li a:hover {
    background-color: #e8f0fe;
    color: #2563eb;
}

.mobile-article-sublist li a.current {
    background-color: #e0f2fe;
    color: #2563eb;
    font-weight: 500;
}

/* Main Content */
main {
    max-width: 1200px;
    margin: 3rem auto;
    padding: 0 2rem;
}

/* Articles Container */
.articles-container {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(350px, 1fr));
    gap: 2rem;
}

.article-card {
    background: #fff;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    transition: transform 0.3s, box-shadow 0.3s;
}

.article-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 5px 15px rgba(0,0,0,0.15);
}

.article-image img {
    width: 100%;
    height: 200px;
    object-fit: cover;
}

.article-content {
    padding: 1.5rem;
}

.article-title {
    font-size: 1.25rem;
    margin-bottom: 0.5rem;
}

.article-title a {
    text-decoration: none;
    color: #333;
    transition: color 0.3s;
}

.article-title a:hover {
    color: #2563eb;
}

.article-meta {
    display: flex;
    gap: 1rem;
    margin-bottom: 1rem;
    font-size: 0.875rem;
    color: #666;
}

.article-category {
    background-color: #e0f2fe;
    color: #0369a1;
    padding: 0.25rem 0.75rem;
    border-radius: 4px;
    font-size: 0.75rem;
}

.article-description {
    color: #666;
    font-size: 0.9rem;
    line-height: 1.6;
}

/* Article Detail */
.article-detail {
    display: grid;
    grid-template-columns: 180px 1fr 220px;
    gap: 3rem;
    max-width: 1400px;
    margin: 0 auto;
}

.sidebar {
    grid-column: 1;
    position: sticky;
    top: 100px;
    align-self: start;
    max-height: calc(100vh - 120px);
    overflow-y: auto;
}

.content {
    grid-column: 2;
    min-width: 0;
}

.toc {
    grid-column: 3;
    position: sticky;
    top: 100px;
    align-self: start;
    max-height: calc(100vh - 120px);
    overflow-y: auto;
    font-size: 13px;
}

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

.toc li {
    margin-bottom: 4px;
}

.toc li ul {
    margin-left: 16px;
    margin-top: 4px;
}

.toc a {
    color: #666;
    text-decoration: none;
    display: block;
    padding: 3px 0;
    transition: color 0.2s;
}

.toc a:hover {
    color: #2563eb;
}

.category-list h3, .toc h3 {
    margin-bottom: 1rem;
    color: #333;
}

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

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

.category-item {
    margin-bottom: 2px;
}

.category-header {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 10px;
    border-radius: 6px;
    cursor: pointer;
    transition: background-color 0.2s;
    user-select: none;
}

.category-header:hover {
    background-color: transparent;
}

.category-header:hover a {
    color: #2563eb;
}

.category-header.active {
    background-color: transparent;
    font-weight: 600;
}

.category-header a {
    text-decoration: none;
    color: #555;
    flex: 1;
}

.category-header.active a {
    color: #111;
}

.toggle-icon {
    font-size: 16px;
    color: #999;
    width: 18px;
    text-align: center;
    transition: transform 0.2s;
    flex-shrink: 0;
}

.category-item.expanded > .category-header .toggle-icon {
    transform: rotate(90deg);
}

.article-count {
    font-size: 12px;
    color: #999;
    flex-shrink: 0;
}

.article-sublist {
    list-style: none;
    padding: 0;
    margin: 0 0 0 24px;
    display: none;
}

.category-item.expanded > .article-sublist {
    display: block;
}

.article-sublist li {
    margin: 0;
}

.article-sublist li a {
    display: block;
    padding: 4px 0;
    text-decoration: none;
    color: #666;
    font-size: 13px;
    border-radius: 4px;
    transition: color 0.2s;
    word-break: break-all;
}

.article-sublist li a:hover {
    background-color: transparent;
    color: #2563eb;
}

.article-sublist li a.current {
    background-color: transparent;
    color: #111;
    font-weight: 600;
}

.category-list ul li a {
    text-decoration: none;
    color: #666;
    transition: color 0.3s;
}

.category-list ul li a:hover {
    color: #2563eb;
}

.content .article-title {
    font-size: clamp(1.8rem, 5vw, 2.8rem);
    margin-bottom: 1.5rem;
    font-weight: 700;
    line-height: 1.2;
}

.content .article-meta {
    margin-bottom: 2rem;
    padding-bottom: 1.5rem;
    border-bottom: 1px solid #eee;
    color: #666;
    font-size: 0.95rem;
}

.article-body {
    line-height: 2;
    color: #333;
    font-size: clamp(1rem, 2.5vw, 1.15rem);
}

.article-body h2 {
    margin-top: 3rem;
    margin-bottom: 1.5rem;
    color: #111;
    font-size: clamp(1.4rem, 4vw, 1.8rem);
    font-weight: 600;
}

.article-body h3 {
    margin-top: 2.5rem;
    margin-bottom: 1rem;
    color: #222;
    font-size: clamp(1.2rem, 3vw, 1.4rem);
    font-weight: 600;
}

.article-body p {
    margin-bottom: 0.5rem !important;
}

.article-body ul, .article-body ol {
    margin-left: 0;
    margin-bottom: 2rem;
    padding-left: 2.5rem;
}

.article-body li {
    margin-bottom: 0.8rem;
    line-height: 1.8;
}

.article-body ul {
    list-style-type: disc;
    list-style-position: outside;
}

.article-body ol {
    list-style-type: decimal;
    list-style-position: outside;
}

.article-body blockquote {
    border-left: 4px solid #2563eb;
    padding-left: 1.5rem;
    margin: 2rem 0;
    color: #555;
    font-style: italic;
    font-size: 1.15rem;
}

.article-body code {
    background-color: #f1f1f1;
    padding: 0.2rem 0.5rem;
    border-radius: 4px;
    font-family: 'SF Mono', 'Consolas', monospace;
    font-size: 0.95em;
}

.article-body pre {
    background-color: #1e293b;
    color: #e2e8f0;
    padding: 1.5rem;
    border-radius: 12px;
    overflow-x: auto;
    margin: 0;
    font-size: 0.95rem;
}

.article-body pre code {
    background: none;
    padding: 0;
    color: inherit;
}

.code-block-wrapper {
    position: relative;
    margin: 1rem 0;
}

.code-block-wrapper .copy-code-btn {
    position: absolute;
    top: 0;
    right: 0;
    background: rgba(255, 255, 255, 0.08);
    color: #94a3b8;
    border: none;
    border-left: 1px solid rgba(255, 255, 255, 0.1);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    border-bottom-left-radius: 6px;
    border-top-right-radius: 6px;
    padding: 3px 8px;
    font-size: 0.7rem;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.2s;
    z-index: 2;
    line-height: 1.4;
}

.code-block-wrapper:hover .copy-code-btn {
    opacity: 1;
}

.code-block-wrapper .copy-code-btn:hover {
    background: rgba(255, 255, 255, 0.15);
    color: #e2e8f0;
}

.copy-code-btn.copied {
    background: #16a34a !important;
    color: #fff !important;
}

.article-body img {
    max-width: 100%;
    height: auto;
    border-radius: 12px;
    margin: 2rem 0;
}

.article-body table {
    width: 100%;
    border-collapse: collapse;
    margin: 2rem 0;
    font-size: 0.95rem;
}

.article-body th, .article-body td {
    border: 1px solid #ddd;
    padding: 0.75rem;
    text-align: left;
}

.article-body th {
    background-color: #f8f9fa;
}

/* Footer */
footer {
    background-color: #333;
    color: #fff;
    text-align: center;
    padding: 2rem;
    margin-top: 4rem;
}

/* Login */
.login-container {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
}

.login-box {
    background: #fff;
    padding: 2rem;
    border-radius: 8px;
    box-shadow: 0 5px 20px rgba(0,0,0,0.1);
    width: 400px;
}

.login-box h2 {
    text-align: center;
    margin-bottom: 1.5rem;
    color: #333;
}

.login-box .error {
    color: #dc2626;
    text-align: center;
    margin-bottom: 1rem;
}

.login-box .hint {
    text-align: center;
    margin-top: 1rem;
    font-size: 0.875rem;
    color: #666;
}

.form-group {
    margin-bottom: 1rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
}

.form-group input,
.form-group select {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 1rem;
}

.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: #2563eb;
}

button {
    width: 100%;
    padding: 0.75rem;
    background-color: #2563eb;
    color: #fff;
    border: none;
    border-radius: 4px;
    font-size: 1rem;
    cursor: pointer;
    transition: background-color 0.3s;
}

button:hover {
    background-color: #1d4ed8;
}

/* Admin */
.admin-header {
    background-color: #1e293b;
    border-bottom: none;
}

.admin-header .logo a {
    color: #fff;
}

.admin-header nav ul li a {
    color: #e2e8f0;
}

.admin-header nav ul li a:hover {
    color: #fff;
}

.admin-main {
    padding: 2rem;
}

.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
}

.btn {
    padding: 0.5rem 1rem;
    text-decoration: none;
    border-radius: 4px;
    font-size: 0.9rem;
    font-weight: 500;
    transition: all 0.3s;
    display: inline-block;
}

.btn-primary {
    background-color: #2563eb;
    color: #fff;
}

.btn-primary:hover {
    background-color: #1d4ed8;
}

.btn-secondary {
    background-color: #6b7280;
    color: #fff;
}

.btn-secondary:hover {
    background-color: #4b5563;
}

.btn-edit {
    background-color: #f59e0b;
    color: #fff;
}

.btn-edit:hover {
    background-color: #d97706;
}

.btn-delete {
    background-color: #dc2626;
    color: #fff;
}

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

.btn-info {
    background-color: #06b6d4;
    color: #fff;
}

.btn-info:hover {
    background-color: #0891b2;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    background: #fff;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.data-table thead {
    background-color: #f8f9fa;
}

.data-table th,
.data-table td {
    padding: 1rem;
    text-align: left;
    border-bottom: 1px solid #eee;
}

.data-table th {
    font-weight: 600;
    color: #333;
}

.data-table tbody tr:hover {
    background-color: #f8f9fa;
}

.admin-stats {
    display: flex;
    gap: 2rem;
}

.stat-item {
    background: #fff;
    padding: 2rem;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    text-align: center;
    width: 200px;
}

.stat-item h3 {
    color: #666;
    margin-bottom: 0.5rem;
}

.stat-item p {
    font-size: 2rem;
    font-weight: 600;
    color: #2563eb;
}

.article-form, .category-form {
    background: #fff;
    padding: 2rem;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

/* Responsive */
@media (max-width: 768px) {
    .header-container {
        height: 60px;
        padding: 0 1rem;
    }

    .main-nav {
        display: none;
    }

    .hamburger {
        display: flex;
    }

    .logo a {
        font-size: 1.35rem;
    }

    .articles-container {
        grid-template-columns: 1fr;
    }

    .article-detail {
        grid-template-columns: 1fr !important;
        gap: 0;
        padding: 0 1rem;
    }

    .article-detail .sidebar {
        display: none !important;
    }

    .article-detail .content {
        grid-column: 1;
        padding: 0;
    }

    .article-detail .toc {
        display: none;
    }

    main {
        padding: 0 1rem;
        margin: 1.5rem auto;
    }
}
