/**
 * Wikibin UI Enhancements
 * Dark mode, TOC, deletion box, mobile polish
 */

/* ============================================
   CSS VARIABLES (Light Mode Default)
   ============================================ */
:root {
    --wiki-bg: #ffffff;
    --wiki-bg-alt: #f8f9fa;
    --wiki-text: #222222;
    --wiki-text-muted: #666666;
    --wiki-link: #0645ad;
    --wiki-link-hover: #0b0080;
    --wiki-link-visited: #0b0080;
    --wiki-border: #a2a9b1;
    --wiki-border-light: #eaecf0;
    --wiki-header-bg: #ffffff;
    --wiki-sidebar-bg: #f8f9fa;
    --wiki-code-bg: #f5f5f5;
    --wiki-deletion-bg: #fef6e7;
    --wiki-deletion-border: #fc3;
    --wiki-deletion-header: #705000;
    --wiki-toc-bg: #f8f9fa;
    --wiki-shadow: rgba(0, 0, 0, 0.1);
}

/* ============================================
   DARK MODE
   ============================================ */
[data-theme="dark"] {
    --wiki-bg: #1a1a1a;
    --wiki-bg-alt: #242424;
    --wiki-text: #e0e0e0;
    --wiki-text-muted: #a0a0a0;
    --wiki-link: #6b9eff;
    --wiki-link-hover: #8bb4ff;
    --wiki-link-visited: #a0b4ff;
    --wiki-border: #3a3a3a;
    --wiki-border-light: #2a2a2a;
    --wiki-header-bg: #1f1f1f;
    --wiki-sidebar-bg: #242424;
    --wiki-code-bg: #2d2d2d;
    --wiki-deletion-bg: #3d3520;
    --wiki-deletion-border: #a68c00;
    --wiki-deletion-header: #ffc107;
    --wiki-toc-bg: #242424;
    --wiki-shadow: rgba(0, 0, 0, 0.3);
}

/* Auto dark mode based on system preference */
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --wiki-bg: #1a1a1a;
        --wiki-bg-alt: #242424;
        --wiki-text: #e0e0e0;
        --wiki-text-muted: #a0a0a0;
        --wiki-link: #6b9eff;
        --wiki-link-hover: #8bb4ff;
        --wiki-link-visited: #a0b4ff;
        --wiki-border: #3a3a3a;
        --wiki-border-light: #2a2a2a;
        --wiki-header-bg: #1f1f1f;
        --wiki-sidebar-bg: #242424;
        --wiki-code-bg: #2d2d2d;
        --wiki-deletion-bg: #3d3520;
        --wiki-deletion-border: #a68c00;
        --wiki-deletion-header: #ffc107;
        --wiki-toc-bg: #242424;
        --wiki-shadow: rgba(0, 0, 0, 0.3);
    }
}

/* Apply variables */
body {
    background-color: var(--wiki-bg);
    color: var(--wiki-text);
}

a {
    color: var(--wiki-link);
}

a:hover {
    color: var(--wiki-link-hover);
}

a:visited {
    color: var(--wiki-link-visited);
}

.sp-megamenu-wrapper,
.sp-header {
    background-color: var(--wiki-header-bg) !important;
}

.article-details,
.com-content-article {
    background-color: var(--wiki-bg);
}

/* Sidebar */
.wiki-sidebar,
.sp-module {
    background-color: var(--wiki-sidebar-bg);
}

/* Cards and containers */
.card,
.well,
.module-inner {
    background-color: var(--wiki-bg-alt);
    border-color: var(--wiki-border);
}

/* Code blocks */
pre, code {
    background-color: var(--wiki-code-bg);
    color: var(--wiki-text);
}

/* ============================================
   THEME TOGGLE BUTTON
   ============================================ */
#wikibin-theme-toggle {
    background: transparent;
    border: 1px solid var(--wiki-border);
    border-radius: 4px;
    padding: 6px 10px;
    cursor: pointer;
    color: var(--wiki-text);
    font-size: 14px;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    transition: background-color 0.2s, border-color 0.2s;
}

#wikibin-theme-toggle:hover {
    background-color: var(--wiki-bg-alt);
    border-color: var(--wiki-link);
}

#wikibin-theme-toggle:focus {
    outline: 2px solid var(--wiki-link);
    outline-offset: 2px;
}

.theme-icon {
    font-size: 16px;
}

/* ============================================
   TABLE OF CONTENTS (Wikipedia-style)
   ============================================ */
.wiki-toc {
    background: var(--wiki-toc-bg);
    border: 1px solid var(--wiki-border);
    padding: 12px 16px;
    display: inline-block;
    margin: 1em 0;
    max-width: 320px;
    font-size: 0.9rem;
}

.wiki-toc .toc-header {
    font-weight: 600;
    text-align: center;
    margin-bottom: 10px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--wiki-border-light);
}

.wiki-toc .toc-title {
    font-size: 1rem;
}

.wiki-toc .toc-toggle {
    background: none;
    border: none;
    color: var(--wiki-link);
    cursor: pointer;
    font-size: 0.85em;
    margin-left: 8px;
}

.wiki-toc .toc-toggle:hover {
    text-decoration: underline;
}

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

.wiki-toc .toc-list li {
    margin: 6px 0;
    line-height: 1.4;
}

.wiki-toc .toc-list a {
    text-decoration: none;
}

.wiki-toc .toc-list a:hover {
    text-decoration: underline;
}

.wiki-toc .toc-h2 {
    padding-left: 0;
}

.wiki-toc .toc-h3 {
    padding-left: 1.2em;
}

.wiki-toc .toc-h4 {
    padding-left: 2.4em;
}

.wiki-toc .toc-number {
    margin-right: 0.5em;
    color: var(--wiki-text-muted);
}

/* ============================================
   DELETION INFO BOX
   ============================================ */
.deletion-info-box {
    background: var(--wiki-deletion-bg);
    border: 1px solid var(--wiki-deletion-border);
    border-left-width: 4px;
    padding: 12px 16px;
    margin: 1em 0;
    font-size: 0.9rem;
    border-radius: 2px;
}

.deletion-info-box .deletion-header {
    font-weight: 600;
    margin-bottom: 10px;
    color: var(--wiki-deletion-header);
    font-size: 0.95rem;
}

.deletion-info-box .deletion-meta {
    margin: 0;
}

.deletion-info-box .deletion-meta dt {
    font-weight: 600;
    display: inline;
    margin-right: 5px;
}

.deletion-info-box .deletion-meta dd {
    display: inline;
    margin: 0;
}

.deletion-info-box .deletion-meta dd::after {
    content: '';
    display: block;
    margin-bottom: 4px;
}

.deletion-info-box .deletion-meta dd:last-child::after {
    display: none;
    margin-bottom: 0;
}

/* ============================================
   ARTICLE CONTENT TYPOGRAPHY
   ============================================ */
.article-details,
.com-content-article {
    line-height: 1.65;
}

.article-details h2,
.com-content-article h2 {
    border-bottom: 1px solid var(--wiki-border);
    padding-bottom: 0.3em;
    margin-top: 1.5em;
}

.article-details h3,
.com-content-article h3 {
    margin-top: 1.25em;
}

/* ============================================
   ACCESSIBILITY ENHANCEMENTS
   ============================================ */
a:focus,
button:focus,
input:focus,
select:focus,
textarea:focus {
    outline: 2px solid var(--wiki-link);
    outline-offset: 2px;
}

/* Skip to content link */
.skip-link {
    position: absolute;
    top: -40px;
    left: 0;
    background: var(--wiki-link);
    color: #fff;
    padding: 8px 12px;
    z-index: 10000;
    text-decoration: none;
}

.skip-link:focus {
    top: 0;
}

/* Minimum tap targets on mobile */
@media (max-width: 768px) {
    .nav-link,
    .btn,
    a.btn {
        min-height: 44px;
        display: inline-flex;
        align-items: center;
    }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    a {
        text-decoration: underline;
    }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* ============================================
   MOBILE RESPONSIVENESS
   ============================================ */
@media (max-width: 767px) {
    /* TOC full width on mobile */
    .wiki-toc {
        width: 100%;
        max-width: none;
        display: block;
    }

    /* Smaller headings on mobile */
    .article-details h1,
    .com-content-article h1 {
        font-size: 1.75rem;
    }

    .article-details h2,
    .com-content-article h2 {
        font-size: 1.4rem;
    }

    .article-details h3,
    .com-content-article h3 {
        font-size: 1.2rem;
    }

    /* Deletion box full width */
    .deletion-info-box {
        margin-left: 0;
        margin-right: 0;
    }

    /* Better touch targets for sidebar */
    .wiki-sidebar .nav-link,
    .related-articles a {
        padding: 12px 15px;
        display: block;
    }

    /* Hide leaderboard ad on mobile */
    .leaderboard-row {
        display: none !important;
    }
}

/* Tablet adjustments */
@media (min-width: 768px) and (max-width: 991px) {
    .wiki-sidebar {
        margin-top: 2rem;
    }
}

/* ============================================
   READING PROGRESS BAR (Helix override)
   ============================================ */
.sp-reading-progress-bar {
    background: var(--wiki-link) !important;
}

/* ============================================
   BREADCRUMB STYLING
   ============================================ */
.breadcrumb {
    background: transparent;
    padding: 0.5rem 0;
    font-size: 0.85rem;
    color: var(--wiki-text-muted);
}

.breadcrumb a {
    color: var(--wiki-link);
}

/* ============================================
   SEARCH BOX WIKIPEDIA-STYLE
   ============================================ */
.wiki-search input[type="search"],
.sp-search-input input {
    border-radius: 2px;
    border: 1px solid var(--wiki-border);
    background: var(--wiki-bg);
    color: var(--wiki-text);
}

.wiki-search input[type="search"]:focus,
.sp-search-input input:focus {
    border-color: var(--wiki-link);
}

/* ============================================
   ARTICLE COUNT BADGE
   ============================================ */
.article-count-badge {
    font-size: 0.85rem;
    color: var(--wiki-text-muted);
    padding: 4px 8px;
    background: var(--wiki-bg-alt);
    border-radius: 4px;
    display: inline-block;
}

.article-count-badge strong {
    color: var(--wiki-text);
    font-weight: 600;
}
