/* Syncing with desktop's premium design system */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap');

:root {
    --bg-primary: #ffffff;
    --bg-secondary: #f7f9fc;
    --bg-tertiary: #e5e9f0;
    --text-primary: #1a1d29;
    --text-secondary: #5e6580;
    --text-tertiary: #8b92ab;
    --accent-primary: #667eea;
    --accent-secondary: #764ba2;
    --accent-gradient: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    --border-color: #e1e4ed;
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.08);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.12);
    --glass-bg: rgba(255, 255, 255, 0.8);
    --glass-border: rgba(255, 255, 255, 0.25);
    --code-bg: #f6f8fa;
    --inline-code-bg: #e5e9f0;
    --inline-code-text: #667eea;
    --blockquote-bg: #f7f9fc;
    --blockquote-border: #667eea;
    --table-border: #e1e4ed;
    --table-header-bg: #f7f9fc;
    --scrollbar-thumb: #c5cad6;
    --scrollbar-track: #f7f9fc;
}

.dark-theme {
    --bg-primary: #1a1d29;
    --bg-secondary: #252838;
    --bg-tertiary: #2f3447;
    --text-primary: #f8f9fa;
    --text-secondary: #c5cad6;
    --text-tertiary: #8b92ab;
    --accent-primary: #7c8cfc;
    --accent-secondary: #8e5fb7;
    --accent-gradient: linear-gradient(135deg, #7c8cfc 0%, #8e5fb7 100%);
    --border-color: #3a3f55;
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.2);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.4);
    --glass-bg: rgba(37, 40, 56, 0.8);
    --glass-border: rgba(255, 255, 255, 0.1);
    --code-bg: #1e222e;
    --inline-code-bg: #2f3447;
    --inline-code-text: #7c8cfc;
    --blockquote-bg: #252838;
    --blockquote-border: #7c8cfc;
    --table-border: #3a3f55;
    --table-header-bg: #252838;
    --scrollbar-thumb: #3a3f55;
    --scrollbar-track: #252838;
}

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

body {
    font-family: 'Inter', sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: all 0.3s ease;
}

/* Custom Scrollbar */
::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

::-webkit-scrollbar-track {
    background: var(--scrollbar-track);
}

::-webkit-scrollbar-thumb {
    background: var(--scrollbar-thumb);
    border-radius: 5px;
    border: 2px solid var(--scrollbar-track);
}

::-webkit-scrollbar-thumb:hover {
    background: var(--accent-primary);
}

.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 24px;
    background: var(--glass-bg);
    backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--border-color);
    z-index: 100;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 16px;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

.file-info h1 {
    font-size: 16px;
    font-weight: 600;
    max-width: 300px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.file-info p {
    font-size: 11px;
    color: var(--text-tertiary);
    max-width: 300px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.icon-btn {
    width: 36px;
    height: 36px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.icon-btn:hover {
    background: var(--bg-tertiary);
    color: var(--accent-primary);
}

.icon-btn.active {
    background: var(--accent-gradient);
    color: white;
}

.primary-btn {
    padding: 8px 16px;
    background: var(--accent-gradient);
    color: white;
    border: none;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    box-shadow: var(--shadow-sm);
    display: flex;
    align-items: center;
    gap: 8px;
    transition: all 0.2s ease;
}

.primary-btn:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.export-group {
    position: relative;
}

.export-menu {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    background: var(--glass-bg);
    backdrop-filter: blur(20px);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 8px;
    min-width: 180px;
    display: none;
    flex-direction: column;
    box-shadow: var(--shadow-lg);
    z-index: 1000;
}

.export-menu.show {
    display: flex;
}

.export-option {
    padding: 10px 12px;
    background: transparent;
    border: none;
    color: var(--text-primary);
    text-align: left;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 14px;
    transition: all 0.2s ease;
}

.export-option:hover {
    background: var(--bg-tertiary);
    color: var(--accent-primary);
}

.tabs-bar {
    display: flex;
    height: 44px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    padding: 0 12px;
    gap: 4px;
    overflow-x: auto;
}

.tab {
    padding: 0 16px;
    height: 36px;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-bottom: none;
    border-radius: 8px 8px 0 0;
    font-size: 13px;
    margin-top: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    white-space: nowrap;
    transition: all 0.2s ease;
    color: var(--text-secondary);
}

.tab:hover {
    background: var(--bg-tertiary);
}

.tab.active {
    background: var(--bg-primary);
    color: var(--text-primary);
    border-top: 2px solid var(--accent-primary);
    font-weight: 500;
}

.tab-close {
    width: 18px;
    height: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    font-size: 14px;
}

.tab-close:hover {
    background: rgba(255, 0, 0, 0.1);
    color: #ff4d4d;
}

.main-container {
    display: flex;
    flex: 1;
    overflow: hidden;
    position: relative;
}

.toc-sidebar {
    width: 280px;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-color);
    display: none;
    flex-direction: column;
    z-index: 1000;
    position: relative;
    height: 100%;
}

.toc-sidebar.show {
    display: flex;
}

.toc-header {
    padding: 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
    background: var(--bg-secondary);
    z-index: 10;
}

.toc-header h3 {
    margin: 0 !important;
    font-size: 16px !important;
    font-weight: 600 !important;
    color: var(--text-primary) !important;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

#tocClose {
    background: transparent;
    border: none;
    color: var(--text-tertiary);
    font-size: 24px;
    cursor: pointer;
    line-height: 1;
    padding: 4px 8px;
    border-radius: 6px;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

#tocClose:hover {
    background: rgba(255, 0, 0, 0.1);
    color: #ff4d4d;
}

.toc-nav {
    flex: 1;
    overflow-y: auto;
    padding: 10px 0;
}

.toc-item {
    display: block !important;
    padding: 12px 20px !important;
    color: var(--text-secondary) !important;
    text-decoration: none !important;
    font-size: 13px !important;
    line-height: 1.4 !important;
    transition: all 0.2s ease;
    border-left: 3px solid transparent;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    width: 100%;
}

.toc-item:hover {
    background: var(--bg-tertiary) !important;
    color: var(--accent-primary) !important;
    padding-left: 25px !important;
}

.toc-item.active {
    background: rgba(102, 126, 234, 0.1);
    color: var(--accent-primary);
    border-left-color: var(--accent-primary);
    font-weight: 500;
}

.toc-item.h1 {
    font-weight: 600;
    padding-left: 20px !important;
}

.toc-item.h1:hover {
    padding-left: 25px !important;
}

.toc-item.h2 {
    padding-left: 35px !important;
    font-size: 13.5px;
}

.toc-item.h2:hover {
    padding-left: 40px !important;
}

.toc-item.h3 {
    padding-left: 50px !important;
    font-size: 13px;
    color: var(--text-tertiary) !important;
}

.toc-item.h3:hover {
    padding-left: 55px !important;
}

.content-area {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    position: relative;
    background: var(--bg-primary);
}

.markdown-content {
    max-width: 850px;
    margin: 0 auto;
    padding: 60px 80px;
    display: none;
    animation: fadeIn 0.4s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.markdown-content.show {
    display: block;
}

/* Premium Markdown Typography */
.markdown-content p {
    margin-bottom: 1.5em;
    line-height: 1.8;
    font-size: 1.05em;
    color: var(--text-secondary);
}

.markdown-content h1 {
    font-size: 2.8em;
    font-weight: 800;
    margin-bottom: 0.8em;
    padding-bottom: 0.3em;
    border-bottom: 2px solid var(--border-color);
    letter-spacing: -0.02em;
}

.markdown-content h2 {
    font-size: 1.8em;
    font-weight: 700;
    margin-top: 2em;
    margin-bottom: 0.8em;
    padding-bottom: 0.3em;
    border-bottom: 1px solid var(--border-color);
}

.markdown-content h3 {
    font-size: 1.4em;
    font-weight: 600;
    margin-top: 1.8em;
    margin-bottom: 0.6em;
}

.markdown-content ul,
.markdown-content ol {
    margin: 1.2em 0;
    padding-left: 2em;
    color: var(--text-secondary);
}

.markdown-content li {
    margin: 0.6em 0;
    line-height: 1.7;
}

.markdown-content li::marker {
    color: var(--accent-primary);
}

.markdown-content blockquote {
    margin: 2em 0;
    padding: 1.2em 2em;
    background: var(--bg-secondary);
    border-left: 4px solid var(--accent-primary);
    border-radius: 0 12px 12px 0;
    font-style: italic;
    color: var(--text-secondary);
    box-shadow: var(--shadow-sm);
}

.markdown-content pre {
    background: var(--code-bg);
    padding: 0;
    border-radius: 12px;
    margin: 2em 0;
    overflow-x: auto;
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-sm);
}

/* Block code inside pre */
.markdown-content pre code {
    display: block;
    padding: 24px;
    background: transparent;
    font-family: 'JetBrains Mono', monospace;
    font-size: 14.5px;
    line-height: 1.7;
}

/* Vivid Syntax Color Overrides */
.hljs-keyword,
.hljs-selector-tag,
.hljs-literal,
.hljs-section,
.hljs-link {
    color: #c678dd !important;
    /* Purple */
}

.hljs-function .hljs-title {
    color: #61afef !important;
    /* Blue */
}

.hljs-string,
.hljs-attribute,
.hljs-symbol,
.hljs-bullet,
.hljs-addition {
    color: #98c379 !important;
    /* Green */
}

.hljs-title,
.hljs-class .hljs-title {
    color: #e5c07b !important;
    /* Yellow */
}

.hljs-comment,
.hljs-quote {
    color: #5c6370 !important;
    font-style: italic;
}

.hljs-number,
.hljs-variable,
.hljs-template-variable,
.hljs-tag,
.hljs-name,
.hljs-selector-id,
.hljs-selector-class,
.hljs-regexp,
.hljs-deletion {
    color: #d19a66 !important;
    /* Orange */
}

/* Inline code */
.markdown-content :not(pre)>code {
    background: var(--inline-code-bg);
    color: var(--inline-code-text);
    padding: 3px 6px;
    border-radius: 6px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.92em;
    font-weight: 500;
}

.markdown-content table {
    width: 100%;
    margin: 2em 0;
    border-collapse: collapse;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--table-border);
}

.markdown-content th,
.markdown-content td {
    padding: 14px 18px;
    text-align: left;
    border-bottom: 1px solid var(--table-border);
}

.markdown-content th {
    background: var(--table-header-bg);
    font-weight: 600;
    color: var(--text-primary);
}

.markdown-content img {
    max-width: 100%;
    height: auto;
    border-radius: 12px;
    margin: 2em 0;
    box-shadow: var(--shadow-md);
    transition: transform 0.3s ease;
}

.markdown-content img:hover {
    transform: scale(1.02);
}

.markdown-content hr {
    margin: 3em 0;
    border: none;
    border-top: 2px solid var(--border-color);
}

.markdown-editor {
    display: none;
    flex: 1;
    padding: 50px 80px;
    border: none;
    outline: none;
    font-family: 'JetBrains Mono', monospace;
    font-size: 16px;
    line-height: 1.6;
    background: var(--bg-primary);
    color: var(--text-primary);
    resize: none;
}

.welcome-screen {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    text-align: center;
    background: var(--bg-secondary);
    position: relative;
}

.welcome-content {
    max-width: 500px;
    padding: 40px;
}

.welcome-icon {
    margin-bottom: 24px;
}

.welcome-screen h2 {
    font-size: 32px;
    margin-bottom: 12px;
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.welcome-screen p {
    color: var(--text-secondary);
    font-size: 18px;
    margin-bottom: 32px;
}

.welcome-btn {
    padding: 14px 32px;
    background: var(--accent-gradient);
    color: white;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    font-weight: 700;
    font-size: 16px;
    box-shadow: var(--shadow-md);
    transition: all 0.3s ease;
}

.welcome-btn:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.site-footer {
    position: absolute;
    bottom: 24px;
    left: 0;
    right: 0;
    text-align: center;
    font-size: 13px;
    color: var(--text-tertiary);
    pointer-events: none;
    font-family: 'Inter', sans-serif;
}

.privacy-note {
    margin-top: 32px;
    font-size: 14px;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 20px;
    max-width: fit-content;
    margin-left: auto;
    margin-right: auto;
    line-height: 1.6;
    background: var(--bg-primary);
    padding: 24px 48px 24px 40px;
    border-radius: 8px;
    border: 1px dashed rgba(102, 126, 234, 0.3);
}

.privacy-note span {
    text-align: center;
    max-width: 500px;
}

.privacy-note svg {
    flex-shrink: 0;
    color: var(--accent-primary);
}

#printFooter {
    display: none;
}

.toast {
    position: fixed;
    bottom: 30px;
    right: 30px;
    background: var(--glass-bg);
    backdrop-filter: blur(10px);
    padding: 14px 28px;
    border-radius: 12px;
    box-shadow: var(--shadow-lg);
    display: none;
    z-index: 2000;
    border-left: 4px solid var(--accent-primary);
    animation: slideIn 0.3s ease;
}

@keyframes slideIn {
    from {
        transform: translateX(50px);
        opacity: 0;
    }

    to {
        transform: translateX(0);
        opacity: 1;
    }
}

.search-bar {
    display: none;
    background: var(--bg-secondary);
    padding: 12px 24px;
    border-bottom: 1px solid var(--border-color);
    align-items: center;
    gap: 16px;
    animation: slideDown 0.2s ease;
}

@keyframes slideDown {
    from {
        transform: translateY(-100%);
    }

    to {
        transform: translateY(0);
    }
}

.search-bar.show {
    display: flex;
}

.search-bar input {
    flex: 1;
    padding: 10px 16px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 14px;
    outline: none;
}

.search-bar input:focus {
    border-color: var(--accent-primary);
}

.search-controls {
    display: flex;
    align-items: center;
    gap: 4px;
}

#searchResults {
    font-size: 13px;
    color: var(--text-tertiary);
    margin-right: 8px;
    white-space: nowrap;
}

.search-controls .icon-btn {
    width: 30px;
    height: 30px;
}

.search-controls .icon-btn:disabled {
    opacity: 0.4;
    cursor: default;
}

.search-controls .icon-btn:disabled:hover {
    background: transparent;
    color: var(--text-secondary);
}

mark.search-highlight {
    background: rgba(102, 126, 234, 0.4);
    color: inherit;
    border-radius: 3px;
    padding: 0 2px;
}

mark.search-highlight.current {
    background: var(--accent-primary);
    color: white;
}

/* Diagrams */
.mermaid,
.plantuml {
    background: var(--bg-secondary);
    padding: 30px;
    border-radius: 16px;
    margin: 2.5em 0;
    display: flex;
    justify-content: center;
    align-items: center;
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-sm);
    overflow-x: auto;
}

@media print {

    /* Force exact colors and light mode for beautiful printed PDFs */
    * {
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }

    body {
        --bg-primary: #ffffff !important;
        --bg-secondary: #f7f9fc !important;
        --bg-tertiary: #e5e9f0 !important;
        --text-primary: #1a1d29 !important;
        --text-secondary: #3b4252 !important;
        --text-tertiary: #8b92ab !important;
        --accent-primary: #667eea !important;
        --border-color: #e1e4ed !important;
        --code-bg: #f6f8fa !important;
        --inline-code-bg: #e5e9f0 !important;
        --inline-code-text: #667eea !important;
        --blockquote-bg: #f7f9fc !important;
        --blockquote-border: #667eea !important;
        --table-border: #e1e4ed !important;
        --table-header-bg: #f7f9fc !important;

        background-color: #ffffff !important;
        color: #1a1d29 !important;
    }

    .tabs-bar,
    .toc-sidebar,
    .search-bar,
    .welcome-screen,
    .markdown-editor {
        display: none !important;
    }

    .app-header {
        background: transparent !important;
        border-bottom: 1px solid var(--border-color) !important;
        padding: 0 0 20px 0 !important;
        margin-bottom: 20px !important;
    }

    .header-right,
    .app-logo {
        display: none !important;
    }

    .main-container,
    .content-area,
    .markdown-content {
        display: block !important;
        overflow: visible !important;
        background: transparent !important;
        height: auto !important;
    }

    #printFooter,
    .app-header {
        display: none !important;
    }

    @page {
        margin: 15mm 15mm;
    }

    .markdown-content {
        padding: 0 10px !important;
        width: 100% !important;
        max-width: none !important;
    }

    /* Print-specific typography mimicking the website */
    .markdown-content p,
    .markdown-content li {
        font-size: 0.95em !important;
        line-height: 1.6 !important;
    }

    .markdown-content h1 {
        font-size: 2.2em !important;
        font-weight: 800 !important;
        letter-spacing: -0.02em !important;
        border-bottom: 2px solid var(--border-color) !important;
        padding-bottom: 0.3em !important;
        margin-bottom: 0.8em !important;
    }

    .markdown-content h2 {
        font-size: 1.6em !important;
        font-weight: 700 !important;
        border-bottom: 1px solid var(--border-color) !important;
        padding-bottom: 0.3em !important;
        margin-bottom: 0.8em !important;
    }

    .markdown-content h3 {
        font-size: 1.3em !important;
        font-weight: 600 !important;
        margin-bottom: 0.6em !important;
    }

    .markdown-content blockquote {
        font-size: 0.95em !important;
        font-style: italic !important;
        padding: 1.2em 2em !important;
        border-left: 4px solid var(--accent-primary) !important;
        background: var(--bg-secondary) !important;
        border-radius: 0 12px 12px 0 !important;
        box-shadow: none !important;
    }

    .markdown-content pre code {
        font-size: 12.5px !important;
        line-height: 1.6 !important;
    }

    .markdown-content pre {
        border-radius: 12px !important;
        border: 1px solid var(--border-color) !important;
        box-shadow: none !important;
    }

    .markdown-content :not(pre)>code {
        font-size: 0.85em !important;
        padding: 3px 6px !important;
        background: var(--inline-code-bg) !important;
        border-radius: 6px !important;
    }

    /* Page breaks for clean layout */
    h1,
    h2,
    h3 {
        page-break-after: avoid;
    }

    pre,
    blockquote,
    img,
    table {
        page-break-inside: avoid;
    }
}

@media (max-width: 1024px) {

    .markdown-content,
    .markdown-editor {
        padding: 40px;
    }
}

@media (max-width: 768px) {

    .markdown-content,
    .markdown-editor {
        padding: 30px 20px;
    }

    .file-info {
        display: none;
    }
}