/* === DOCUMENT-BASE.CSS ===
 * Layout and structural styles for Interactive Document
 * NO hardcoded colors - only CSS variables
 * Atmospheric hover, blur, gradient text from originals
 * ~400 lines
 */

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

body {
    font-family: var(--font-body, 'Exo 2', sans-serif);
    background: var(--bg-primary);
    color: var(--text-primary);
    overflow-x: hidden;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body > * { position: relative; z-index: 1; }

/* --- Lucide icons global size limit --- */
.lucide, [data-lucide] {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
}

/* --- Sidebar --- */
.doc-sidebar {
    position: fixed;
    left: 0;
    top: 0;
    width: 260px;
    height: 100vh;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    z-index: 100;
    transition: transform 0.3s var(--ease-out-quart, ease);
}

.doc-sidebar-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px;
    border-bottom: 1px solid var(--border-color);
}

.doc-sidebar-title {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    line-height: 1.3;
    word-break: break-word;
}

.doc-sidebar-close {
    display: none;
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    margin-left: auto;
    padding: 4px;
}

.doc-sidebar-close:hover {
    color: var(--text-primary);
}

.doc-sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: 10px;
}

.doc-nav-link {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border-radius: var(--radius, 8px);
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 13px;
    border-left: 2px solid transparent;
    transition: background 0.2s, color 0.2s, border-color 0.2s;
}

.doc-nav-link:hover {
    background: var(--hover-bg, rgba(255, 255, 255, 0.05));
    color: var(--text-primary);
}

.doc-nav-link.active {
    color: var(--color-primary);
    border-left-color: var(--color-primary);
    background: var(--color-primary-dim, rgba(59, 130, 246, 0.1));
}

.doc-nav-link i,
.doc-nav-link svg {
    width: 15px;
    height: 15px;
    flex-shrink: 0;
}

.doc-nav-badge {
    font-size: 11px;
    background: var(--color-primary-dim);
    color: var(--color-primary);
    padding: 2px 6px;
    border-radius: 10px;
    margin-left: auto;
    font-family: var(--font-display);
    font-weight: 600;
}

/* --- Theme section --- */
.doc-theme-section {
    padding: 10px;
    border-top: 1px solid var(--border-color);
}

.doc-theme-switcher {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}

.doc-theme-chip {
    font-size: 10px;
    padding: 3px 8px;
    border-radius: 12px;
    border: 1px solid var(--border-color);
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    transition: border-color 0.2s, background 0.2s, color 0.2s;
    font-family: inherit;
}

.doc-theme-chip:hover {
    border-color: var(--color-primary);
    color: var(--text-primary);
}

.doc-theme-chip.active {
    background: var(--color-primary);
    color: var(--text-on-primary, #fff);
    border-color: var(--color-primary);
}

.doc-mode-toggle {
    background: none;
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    width: 32px;
    height: 32px;
    border-radius: var(--radius, 8px);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-top: 8px;
    transition: background 0.2s;
}

.doc-mode-toggle:hover {
    background: var(--hover-bg);
}

/* Theme toggle icons - inline SVG, NOT lucide */
.doc-icon-sun { display: none; }
.doc-icon-moon { display: inline; }
html.light-theme .doc-icon-sun { display: inline; }
html.light-theme .doc-icon-moon { display: none; }

/* --- Language switcher --- */
.doc-lang-switcher {
    display: flex;
    gap: 4px;
    margin-top: 8px;
}

.doc-lang-btn {
    font-size: 11px;
    padding: 3px 8px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    text-decoration: none;
    transition: background 0.2s, color 0.2s;
}

.doc-lang-btn:hover {
    color: var(--text-primary);
    border-color: var(--color-primary);
}

.doc-lang-btn.active {
    background: var(--color-primary);
    color: var(--text-on-primary, #fff);
    border-color: var(--color-primary);
}

/* --- Sidebar footer --- */
.doc-sidebar-footer {
    margin-top: auto;
    padding: 10px;
    font-size: 11px;
    color: var(--text-muted);
}

/* --- Main content --- */
.doc-main {
    margin-left: 260px;
    padding: 10px 20px;
    min-height: 100vh;
    transition: margin 0.3s var(--ease-out-quart, ease);
}

/* --- Hamburger (mobile) --- */
.doc-hamburger {
    display: none;
    position: fixed;
    top: 10px;
    left: 10px;
    z-index: 200;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 8px;
    cursor: pointer;
    color: var(--text-primary);
}

/* --- Sections as cards --- */
.doc-section {
    margin-bottom: 10px;
    background: var(--card-bg, var(--bg-secondary));
    border: 1px solid var(--border-color);
    border-radius: var(--radius, 8px);
    padding: 10px;
    transition: border-color 0.2s;
}

.doc-section-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 10px;
}

.doc-section-header h2 {
    font-size: 18px;
    font-family: var(--font-display);
    text-wrap: balance;
}

.doc-section-header i,
.doc-section-header svg {
    color: var(--color-primary);
    width: 20px;
    height: 20px;
    flex-shrink: 0;
}

/* Section color coding by keyword in id */
.doc-section[id*="kritich"],
.doc-section[id*="critical"] {
    border-left: 3px solid var(--color-danger, oklch(58% 0.22 25));
}

.doc-section[id*="kritich"] .doc-section-header h2,
.doc-section[id*="critical"] .doc-section-header h2 {
    color: var(--color-danger, oklch(58% 0.22 25));
}

.doc-section[id*="normal"],
.doc-section[id*="servis"] {
    border-left: 3px solid var(--color-warning, oklch(72% 0.18 80));
}

.doc-section[id*="laitov"],
.doc-section[id*="kosmetik"],
.doc-section[id*="cosmetic"] {
    border-left: 3px solid var(--color-success, oklch(70% 0.18 160));
}

/* --- Hero section (flat, no card nesting) --- */
.doc-hero {
    margin-bottom: 10px;
    padding: 10px 0;
}

.doc-hero h1,
.doc-hero-title {
    font-family: var(--font-display);
    font-size: clamp(1.4rem, 3vw, 2rem);
    margin-bottom: 10px;
    line-height: 1.2;
    text-wrap: balance;
}

.doc-hero-subtitle {
    font-size: 14px;
    color: var(--text-secondary);
    margin-bottom: 10px;
}

.doc-hero-stats {
    display: flex;
    gap: 10px;
    margin-bottom: 10px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding-bottom: 4px;
}

.doc-hero-stats::-webkit-scrollbar {
    display: none;
}

/* BUG FIX: both .doc-stat AND .doc-stat-card */
.doc-stat,
.doc-stat-card {
    flex: 0 0 auto;
    background: var(--card-bg, var(--bg-secondary));
    border: 1px solid var(--border-color);
    border-radius: var(--radius, 8px);
    padding: 10px;
    text-align: center;
    transition: transform 0.3s var(--ease-out-quart, ease), box-shadow 0.3s ease;
    min-width: 80px;
}

.doc-stat:hover,
.doc-stat-card:hover {
    transform: translateY(-4px) scale(1.02);
    box-shadow: var(--shadow-lg, 0 10px 20px rgba(0, 0, 0, 0.3));
}

.doc-stat-value {
    font-size: 24px;
    font-weight: 700;
    font-family: var(--font-display);
    color: var(--color-primary);
    display: block;
    line-height: 1;
}

/* Color variants for stat values */
.doc-stat-done { color: var(--color-success, oklch(70% 0.18 160)); }
.doc-stat-todo { color: var(--color-warning, oklch(72% 0.18 80)); }

.doc-stat-label {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 2px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.doc-hero-links {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.doc-hero-link {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    border-radius: var(--radius, 8px);
    background: var(--color-primary-dim, rgba(59, 130, 246, 0.1));
    color: var(--color-primary);
    text-decoration: none;
    font-size: 13px;
    transition: background 0.2s, color 0.2s;
}

.doc-hero-link:hover {
    background: var(--color-primary);
    color: var(--text-on-primary, #fff);
}

.doc-hero-link i,
.doc-hero-link svg {
    width: 14px;
    height: 14px;
}

/* --- Scroll animations --- */
[data-animate] {
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.6s var(--ease-out-expo, cubic-bezier(0.16, 1, 0.3, 1)),
                transform 0.6s var(--ease-out-expo, cubic-bezier(0.16, 1, 0.3, 1));
}

[data-animate].animated {
    opacity: 1;
    transform: translateY(0);
}

/* --- Stagger delay for cards --- */
[data-animate][data-delay] {
    transition-delay: calc(var(--stagger, 0) * 80ms);
}

/* --- Custom scrollbar --- */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--text-muted); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-secondary); }

/* --- Toast --- */
.toast {
    border-radius: var(--radius, 8px) !important;
}

/* --- Lightbox --- */
.doc-lightbox {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 1000;
    align-items: center;
    justify-content: center;
}

.doc-lightbox.active {
    display: flex;
}

.doc-lightbox-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(8px);
}

.doc-lightbox-content {
    position: relative;
    max-width: 90vw;
    max-height: 90vh;
    z-index: 1;
}

.doc-lightbox-content img {
    max-width: 90vw;
    max-height: 85vh;
    border-radius: var(--radius, 8px);
    object-fit: contain;
}

.doc-lightbox-close {
    position: absolute;
    top: -40px;
    right: 0;
    background: none;
    border: none;
    color: var(--text-on-primary, #fff);
    font-size: 28px;
    cursor: pointer;
    padding: 4px 8px;
    opacity: 0.8;
    transition: opacity 0.2s;
}

.doc-lightbox-close:hover { opacity: 1; }

.doc-lightbox-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(255, 255, 255, 0.15);
    border: none;
    color: var(--text-on-primary, #fff);
    font-size: 24px;
    padding: 10px 14px;
    cursor: pointer;
    border-radius: var(--radius, 8px);
    backdrop-filter: blur(4px);
    transition: background 0.2s;
    z-index: 2;
}

.doc-lightbox-nav:hover {
    background: rgba(255, 255, 255, 0.25);
}

.doc-lightbox-prev { left: 10px; }
.doc-lightbox-next { right: 10px; }

.doc-lightbox-caption {
    text-align: center;
    color: rgba(255, 255, 255, 0.7);
    font-size: 12px;
    margin-top: 8px;
}

/* --- Sidebar overlay (mobile) --- */
.doc-sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    z-index: 99;
}

.doc-sidebar-overlay.active {
    display: block;
}

/* --- Images: clickable cursor --- */
.doc-section-body img {
    cursor: zoom-in;
    transition: opacity 0.2s;
}

.doc-section-body img:hover {
    opacity: 0.9;
}

/* --- Responsive: tablet/mobile --- */
@media (max-width: 1024px) {
    .doc-sidebar {
        transform: translateX(-100%);
    }

    .doc-sidebar.open {
        transform: translateX(0);
    }

    .doc-main {
        margin-left: 0;
        padding: 10px;
        padding-top: 50px;
    }

    .doc-hamburger {
        display: block;
    }

    .doc-sidebar-close {
        display: block;
    }

}

@media (max-width: 640px) {
    .doc-stat,
    .doc-stat-card {
        min-width: 55px;
        padding: 6px;
        padding: 8px;
    }

    .doc-stat-value {
        font-size: 18px;
    }
}

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

    [data-animate] {
        opacity: 1;
        transform: none;
    }
}
