/* styles/tutorial.css */

/* --- Main Page Layout --- */
.tutorial-page-container {
    display: flex;
    max-width: 1800px;
    margin: 0px auto 2rem auto;
    padding: 1.5rem;
    gap: 1.5rem;
    min-height: calc(100vh - 200px);
    position: relative;
}

/* --- Mobile Sidebar Toggle Button --- */
.sidebar-toggle {
    display: none;
    position: fixed;
    bottom: 12vh;
    right: 20px;
    z-index: 1001;
    background-color: var(--accent-color);
    color: white;
    border: none;
    border-radius: 50%;
    width: 50px;
    height: 50px;
    box-shadow: var(--shadow);
    cursor: pointer;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
}

.sidebar-toggle:hover {
    transform: scale(1.1);
}

/* --- Left Sidebar (Table of Contents) --- */
.tutorial-sidebar {
    width: 260px;
    flex-shrink: 0;
    transition: transform 0.3s ease-in-out;
}

.sidebar-sticky {
    position: sticky;
    top: 0px; 
    height: calc(100vh - 140px); 
    overflow-y: auto;
    padding-right: 10px;
}

/* Mobile sidebar close button */
.sidebar-close {
    display: none;
    position: absolute;
    top: 15px;
    right: 15px;
    background: none;
    border: none;
    color: var(--text-color);
    font-size: 1.5rem;
    cursor: pointer;
    z-index: 1002;
}

/* Custom Scrollbar for Webkit browsers (Chrome, Safari) */
.sidebar-sticky::-webkit-scrollbar {
    width: 4px;
}

.sidebar-sticky::-webkit-scrollbar-track {
    background: transparent;
}

.sidebar-sticky::-webkit-scrollbar-thumb {
    background-color: #ccc;
    border-radius: 10px;
}

.dark-mode .sidebar-sticky::-webkit-scrollbar-thumb {
    background-color: #555;
}

.tutorial-sidebar h4 {
    font-size: 1.2rem;
    margin-bottom: 1rem;
    color: var(--secondary-color);
    padding-bottom: 0.5rem;
    border-bottom: 2px solid var(--accent-color);
}

.dark-mode .tutorial-sidebar h4 {
    color: #a5d6a7;
}

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

.toc-item {
    margin-bottom: 0.5rem;
}

.toc-link {
    display: flex;
    justify-content: space-between;
    align-items: center;
    text-decoration: none;
    color: var(--text-color);
    padding: 0.6rem 0.8rem;
    border-radius: 5px;
    transition: all 0.3s ease;
    font-weight: 500;
}

.toc-link:hover {
    background-color: var(--bg-color);
    color: var(--accent-color);
}

.dark-mode .toc-link:hover {
    background-color: var(--search-bg);
}

.toc-link.active {
    background-color: var(--accent-color);
    color: white;
}
.dark-mode .toc-link.active {
    background-color: var(--main-btn-bg);
}

.toc-link.parent i {
    transition: transform 0.3s ease;
}

.toc-link.parent.open i {
    transform: rotate(180deg);
}

.toc-submenu {
    list-style: none;
    padding-left: 1rem;
    margin-top: 0.5rem;
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.4s ease-in-out;
}

.toc-submenu a {
    padding: 0.5rem;
    font-size: 0.9rem;
    font-weight: 400;
}

.toc-submenu .active-link {
    color: var(--accent-color);
    font-weight: 600;
}

/* --- Main Content Area --- */
.tutorial-main-content {
    flex-grow: 1;
    position: sticky;
    background-color: var(--card-bg);
    padding: 2rem 2.5rem;
    border-radius: 10px;
    box-shadow: var(--shadow);
    border: 1px solid var(--border-color);
    min-width: 0; /* Prevents flex item overflow */
}

.content-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    flex-wrap: wrap; /* Allow wrapping on smaller screens */
    gap: 1rem;
}

.content-header h1 {
    font-size: 2.5rem;
    color: var(--primary-color);
    margin: 0;
}
.dark-mode .content-header h1 {
    color: #a5d6a7;
}

.share-btn {
    background: none;
    border: 1px solid var(--border-color);
    color: var(--text-color);
    width: 40px;
    height: 40px;
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.3s ease;
}
.share-btn:hover {
    background-color: var(--accent-color);
    color: white;
    border-color: var(--accent-color);
}

/* MODIFICATION: Hide mobile share button by default */
.mobile-share-btn {
    display: none;
    width: 40px;
    height: 40px;
    padding: 0;
    align-items: center;
    justify-content: center;
}

.page-navigation {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin: 1rem 0;
}

/* --- ENHANCED Code Example Block --- */
.code-example-container {
    border-radius: 12px;
    margin: 2.5rem 0;
    overflow: hidden;
    font-family: 'Fira Code', 'Courier New', monospace;
    transition: all 0.3s ease;
    position: relative;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.12);
}

.code-editor-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.85rem 1.25rem;
    transition: all 0.3s ease;
    position: relative;
}

.window-controls {
    display: flex;
    gap: 0.6rem;
}

.control-dot {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    transition: transform 0.2s ease;
}

.control-dot:hover {
    transform: scale(1.1);
}

.code-header-buttons {
    display: flex;
    align-items: center;
    gap: 0.85rem;
}

.copy-code-btn, .try-btn {
    padding: 0.6rem 1.1rem;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 600;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.copy-code-btn:hover, .try-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
}

.try-btn {
    background-color: var(--accent-color);
    color: white;
    border: 1px solid transparent;
    position: relative;
    overflow: hidden;
}

.try-btn::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 5px;
    height: 5px;
    background: rgba(255, 255, 255, 0.5);
    opacity: 0;
    border-radius: 100%;
    transform: scale(1, 1) translate(-50%);
    transform-origin: 50% 50%;
}

.try-btn:hover::after {
    animation: ripple 1s ease-out;
}

@keyframes ripple {
    0% {
        transform: scale(0, 0);
        opacity: 0.5;
    }
    100% {
        transform: scale(20, 20);
        opacity: 0;
    }
}

.code-editor-body {
    overflow-x: auto;
    transition: background-color 0.3s ease;
    position: relative;
}

.code-example-container pre {
    margin: 0;
    padding: 1.5rem;
    overflow-x: auto;
    flex-grow: 1;
    min-width: 0;
}

.code-example-container code {
    font-size: 0.95rem;
    line-height: 1.7;
    outline: none;
    white-space: pre;
    word-wrap: normal;
    font-family: 'Fira Code', 'Courier New', monospace;
    tab-size: 4;
    -moz-tab-size: 4;
}

/* Line numbers styling */
.hljs-ln {
    border-collapse: collapse;
    width: 100%;
}

.hljs-ln td {
    padding-left: 4;
    vertical-align: top;
}

.hljs-ln-line {
    padding-top: 0.25em;
    padding-bottom: 0.25em;
}

.hljs-ln-numbers {
    text-align: right;
    padding-right: 1.5em;
    padding-left: 0.5em;
    user-select: none;
    color: #8b949e;
    border-right: 1px solid rgba(255, 255, 255, 0.1);
}
.hljs-ln-n {
    width: 2px;
}

.hljs-ln-code {
    padding-left: 1.5em;
}

/* Code block focus effect */
.code-example-container:focus-within {
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15);
    transform: translateY(-2px);
}

/* Code selection styling */
.code-example-container ::selection {
    background-color: rgba(76, 175, 80, 0.3);
}

/* --- Code Block Theme: Light Mode --- */
body.light-mode .code-example-container {
    background-color: #f8f9fa;
    border: 1px solid #e9ecef;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}

body.light-mode .code-editor-header {
    background-color: #f1f3f5;
    border-bottom: 1px solid #e9ecef;
}

body.light-mode .control-dot:nth-child(1) { background-color: #ff5f56; }
body.light-mode .control-dot:nth-child(2) { background-color: #ffbd2e; }
body.light-mode .control-dot:nth-child(3) { background-color: #27c93f; }

body.light-mode .copy-code-btn {
    background-color: #ffffff;
    color: #495057;
    border: 1px solid #dee2e6;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

body.light-mode .copy-code-btn:hover {
    background-color: #f8f9fa;
    color: var(--accent-color);
    border-color: var(--accent-color);
}

body.light-mode .code-editor-body {
    background-color: #ffffff;
}

body.light-mode .code-example-container code {
    color: #24292e;
}

body.light-mode .hljs-ln-numbers {
    color: #6a737d;
    border-right: 1px solid #e1e4e8;
}

body.light-mode .hljs-comment { color: #6a737d; }
body.light-mode .hljs-keyword { color: #d73a49; font-weight: 600; }
body.light-mode .hljs-string { color: #032f62; }
body.light-mode .hljs-number { color: #005cc5; }
body.light-mode .hljs-built_in { color: #e36209; }
body.light-mode .hljs-function .hljs-title { color: #6f42c1; }
body.light-mode .hljs-params { color: #24292e; }
body.light-mode .hljs-attr { color: #005cc5; }

/* --- Code Block Theme: Dark Mode --- */
body.dark-mode .code-example-container {
    background-color: #1a1d21;
    border: 1px solid #2c303a;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
}

body.dark-mode .code-editor-header {
    background-color: #212529;
    border-bottom: 1px solid #2c303a;
}

body.dark-mode .control-dot:nth-child(1) { background-color: #ff5f56; }
body.dark-mode .control-dot:nth-child(2) { background-color: #ffbd2e; }
body.dark-mode .control-dot:nth-child(3) { background-color: #27c93f; }

body.dark-mode .copy-code-btn {
    background: #343a40;
    color: #adbac7;
    border: 1px solid #495057;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
}

body.dark-mode .copy-code-btn:hover {
    background: #495057;
    color: white;
}

body.dark-mode .code-editor-body {
    background-color: #1a1d21;
}

body.dark-mode .code-example-container code {
    color: #e9ecef;
}

body.dark-mode .hljs-ln-numbers {
    color: #6c757d;
    border-right: 1px solid #2c303a;
}

body.dark-mode .hljs-keyword { color: #ff7b72; font-weight: 600; }
body.dark-mode .hljs-string { color: #a5d6ff; }
body.dark-mode .hljs-comment { color: #8b949e; font-style: italic; }
body.dark-mode .hljs-number { color: #79c0ff; }
body.dark-mode .hljs-built_in { color: #ffa657; }
body.dark-mode .hljs-function .hljs-title { color: #d2a8ff; }
body.dark-mode .hljs-params { color: #e9ecef; }
body.dark-mode .hljs-attr { color: #79c0ff; }

/* Scrollbar styling for code block */
.code-editor-body::-webkit-scrollbar {
    height: 8px;
}

.code-editor-body::-webkit-scrollbar-track {
    background: transparent;
    margin: 0 1rem;
}

.code-editor-body::-webkit-scrollbar-thumb {
    background-color: #ced4da;
    border-radius: 4px;
}

body.dark-mode .code-editor-body::-webkit-scrollbar-thumb {
    background-color: #495057;
}

.code-editor-body::-webkit-scrollbar-thumb:hover {
    background-color: #adb5bd;
}

body.dark-mode .code-editor-body::-webkit-scrollbar-thumb:hover {
    background-color: #6c757d;
}

/* --- Article & Page Navigation Styles --- */
hr {
    border: 0;
    height: 1px;
    background-color: var(--border-color);
    margin: 2rem 0;
}

article section {
    margin-bottom: 2rem;
}

article h2, article h3 {
    margin-bottom: 1rem;
    color: var(--secondary-color);
}
.dark-mode article h2, .dark-mode article h3 {
    color: #8db8a2;
}

article p {
    line-height: 1.7;
    margin-bottom: 1rem;
}

article ul {
    padding-left: 20px;
    line-height: 1.8;
}

/* DRY Principle: Consolidating button styles */
.page-navigation .btn,
.page-navigation-footer .btn {
    background-color: var(--card-bg);
    color: var(--text-color);
    border: 1px solid var(--border-color);
    padding: 0.6rem 1.2rem;
    text-decoration: none;
    border-radius: 20px;
    transition: all 0.3s ease;
}

.page-navigation .btn:hover,
.page-navigation-footer .btn:hover {
    background-color: var(--accent-color);
    color: white;
    border-color: var(--accent-color);
    transform: translateY(-2px);
}

.page-navigation-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 2rem;
    flex-wrap: wrap;
    gap: 1rem;
}

.complete-btn {
    /* Styles are now inherited from the .btn class */
}

.complete-btn:hover {
    /* Hover styles are inherited from .btn:hover */
}

.complete-btn.completed {
    background-color: transparent;
    color: var(--accent-color);
    cursor: default;
    border-color: var(--accent-color);
}
.dark-mode .complete-btn.completed {
    color: var(--main-btn-bg);
    border-color: var(--main-btn-bg);
}

/* --- Ad Container Styles --- */
.tutorial-ad-container {
    width: 180px;
    flex-shrink: 0;
    display: none; /* Hidden by default, shown on large screens */
}

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

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

/* --- Share Modal Styles --- */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.6);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1001;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

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

.modal-content {
    background-color: var(--card-bg);
    padding: 1.5rem;
    border-radius: 12px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
    width: 90%;
    max-width: 400px;
    transform: scale(0.95);
    transition: transform 0.3s ease;
    text-align: center;
}

.modal-overlay.active .modal-content {
    transform: scale(1);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 1rem;
    margin-bottom: 1rem;
}

.modal-header h3 {
    margin: 0;
    color: var(--secondary-color);
}

.dark-mode .modal-header h3 {
    color: #a5d6a7;
}

.modal-close-btn {
    background: none;
    border: none;
    font-size: 1.8rem;
    cursor: pointer;
    color: var(--text-color);
    opacity: 0.7;
}

.modal-body p {
    margin-bottom: 0.75rem;
    font-size: 0.9rem;
    font-weight: 500;
}

.share-links {
    display: flex;
    justify-content: center;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.share-link {
    width: 45px;
    height: 45px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    border-radius: 50%;
    text-decoration: none;
    font-size: 1.2rem;
    transition: transform 0.2s ease;
}

.share-link:hover {
    transform: scale(1.1);
}

.share-link.facebook { background-color: #1877F2; }
.share-link.twitter { background-color: #1DA1F2; }
.share-link.linkedin { background-color: #0A66C2; }

.copy-link-container {
    display: flex;
    justify-content: center;
}

.copy-btn-modal {
    width: auto;
    padding: 0.8rem 1.5rem;
    font-size: 1rem;
    font-weight: 600;
}

.copy-btn-modal .fas {
    margin-right: 8px;
}

/* --- Highlight.js Customization --- */
.hljs {
    background: transparent !important;
    padding: 0 !important;
}

/* Styling for highlightjs-line-numbers plugin */
.hljs-ln {
    border-collapse: collapse;
    width: 100%;
}
.hljs-ln td {
    padding: 0 ;
    vertical-align: top;
}
.hljs-ln-line {
    padding-top: 0.25em;
    padding-bottom: 0.25em;
}
.hljs-ln-numbers {
    text-align: left;
    padding-right: 2em;
    padding-left: 1.5em;
    user-select: none;
}
.hljs-ln-code {
    padding-left: 6px;
}

/* Responsive adjustments for code block */
@media (max-width: 768px) {
    .code-editor-header {
        flex-wrap: wrap;
        gap: 0.75rem;
        padding: 0.75rem;
    }
    
    .code-header-buttons {
        width: 100%;
        justify-content: flex-end;
    }
    
    .code-example-container pre {
        padding: 1.25rem;
    }
    
    .code-example-container code {
        font-size: 0.85rem;
    }
    
    .hljs-ln-numbers {
        padding-right: 1rem;
    }
    
    .hljs-ln-code {
        padding-left: 1rem;
    }
}

@media (max-width: 480px) {
    .code-header-buttons {
        flex-direction: column;
        gap: 0.5rem;
    }
    
    .copy-code-btn, .try-btn {
        width: 100%;
        justify-content: center;
    }
    
    .code-example-container pre {
        padding: 1rem;
    }
    
    .code-example-container code {
        font-size: 0.8rem;
    }
}

/* Focus indicator for code block */
.code-example-container:focus {
    outline: 2px solid var(--accent-color);
    outline-offset: 2px;
}

/* Animation for code copy feedback */
@keyframes codeCopied {
    0% { transform: scale(1); }
    50% { transform: scale(1.05); }
    100% { transform: scale(1); }
}

.copy-code-btn.copied {
    animation: codeCopied 0.3s ease;
}

/* --- Responsive Design --- */

/* Show ads only on larger screens */
@media (min-width: 1280px) {
    .tutorial-ad-container {
        display: block;
    }
}

/* Tablet and smaller desktops */
@media (max-width: 992px) {
    .sidebar-toggle {
        display: flex;
    }
    
    .tutorial-sidebar {
        position: fixed;
        top: 0;
        left: -50%;
        width: 50%;
        height: 100%;
        z-index: 1000;
        background-color: var(--card-bg);
        overflow-y: auto;
        padding: 2rem 1rem;
        box-shadow: 5px 0 15px rgba(0, 0, 0, 0.1);
        transition: left 0.3s ease-in-out;
    }
    
    .tutorial-sidebar.active {
        left: 0;
    }
    
    .sidebar-sticky {
        position: static;
        height: auto;
    }
    
    .sidebar-close {
        display: block;
    }
    
    .tutorial-page-container {
        padding: 1rem;
    }
    
    .tutorial-main-content {
        padding: 1.5rem;
    }
}

/* Smaller tablets */
@media (max-width: 768px) {
    .content-header h1 {
        font-size: 2rem;
    }
    
    .page-navigation-footer {
        flex-direction: column;
        gap: 1rem;
    }
    
    .page-navigation-footer .btn {
        width: 100%;
        text-align: center;
    }
    
    .tutorial-sidebar {
        width: 70%;
        left: -70%;
    }
}

/* Mobile devices */
@media (max-width: 600px) {
    .tutorial-page-container {
        margin-top: 0px;
        padding: 0.5rem;
        gap: 0.5rem;
    }
    
    .tutorial-main-content {
        padding: 1rem;
        border-radius: 8px;
    }
    
    .content-header h1 {
        font-size: 1.6rem;
        line-height: 1.3;
    }
    
    /* MODIFICATION: Hide original share button and show mobile one */
    .content-header .share-btn {
        display: none;
    }
    .mobile-share-btn {
        display: flex;
    }
    
    .page-navigation {
        flex-direction: row; /* Keep it as a row */
        gap: 0.5rem;
        justify-content: space-between;
    }
    
    .page-navigation .btn {
        width: auto; /* Auto width for buttons */
        flex-grow: 1;
        text-align: center;
    }
    
    .code-editor-header {
        flex-wrap: wrap;
        gap: 0.5rem;
        padding: 0.5rem;
    }
    
    .code-example-container pre {
        padding: 0.75rem;
    }
    
    .code-example-container code {
        font-size: 0.8rem;
    }
    
    .hljs-ln-numbers {
        padding-right: 1em;
        padding-left: 1em;
    }
    .hljs-ln-code {
        padding-left: 1em;
    }
    
    article h2 {
        font-size: 1.4rem;
    }
    
    article h3 {
        font-size: 1.2rem;
    }
    
    .share-btn {
        width: 35px;
        height: 35px;
    }
    
    .tutorial-sidebar {
        width: 80%;
        left: -85%;
    }
}