/* ============================================
   CURSO SAAS FÁCIL — Graphite Terminal Theme
   ============================================ */

:root {
    /* Paleta Terminal (default) */
    --accent: #00f2ff;
    --accent-dim: #009cad;
    --accent-glow: rgba(0, 242, 255, 0.4);

    /* Superfícies (dark default) */
    --bg-base: #0a0b0d;
    --bg-surface: #12141a;
    --bg-elevated: #1c1f26;
    --bg-hover: rgba(255, 255, 255, 0.04);
    --border-subtle: #2d313d;
    --border-strong: #3d424f;

    /* Texto */
    --text-primary: #f4f4f5;
    --text-secondary: #a1a1aa;
    --text-muted: #71717a;
    --text-faint: #52525b;

    /* Status */
    --status-done: var(--accent);
    --status-active: var(--accent);
    --status-locked: #52525b;

    /* Layout */
    --sidebar-w: 320px;
    --header-h: 84px;

    /* Tipografia */
    --font-mono: 'IBM Plex Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

/* ===== PALETAS DE ACENTO ===== */
:root[data-color="terminal"] { --accent: #00f2ff; --accent-dim: #009cad; --accent-glow: rgba(0, 242, 255, 0.4); }
:root[data-color="orange"]   { --accent: #f97316; --accent-dim: #c2410c; --accent-glow: rgba(249, 115, 22, 0.4); }
:root[data-color="blue"]     { --accent: #3b82f6; --accent-dim: #1d4ed8; --accent-glow: rgba(59, 130, 246, 0.4); }
:root[data-color="green"]    { --accent: #22c55e; --accent-dim: #15803d; --accent-glow: rgba(34, 197, 94, 0.4); }
:root[data-color="purple"]   { --accent: #a855f7; --accent-dim: #7e22ce; --accent-glow: rgba(168, 85, 247, 0.4); }
:root[data-color="red"]      { --accent: #ef4444; --accent-dim: #b91c1c; --accent-glow: rgba(239, 68, 68, 0.4); }

/* ===== TEMA CLARO ===== */
:root[data-theme="light"] {
    --bg-base: #fafafa;
    --bg-surface: #ffffff;
    --bg-elevated: #f4f4f5;
    --bg-hover: rgba(0, 0, 0, 0.04);
    --border-subtle: #e4e4e7;
    --border-strong: #d4d4d8;
    --text-primary: #18181b;
    --text-secondary: #3f3f46;
    --text-muted: #71717a;
    --text-faint: #a1a1aa;
}

/* ===== RESET ===== */
* { box-sizing: border-box; }
html, body {
    height: 100%;
    width: 100%;
    overflow: hidden;
    position: relative;
}
body {
    margin: 0;
    font-family: var(--font-sans);
    background: var(--bg-base);
    color: var(--text-secondary);
    display: flex;
    -webkit-font-smoothing: antialiased;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    min-height: 0;
    min-width: 0;
}

/* ===== SCROLLBAR GLOBAL TEMATIZADA ===== */
html { scrollbar-color: var(--accent) var(--bg-base); scrollbar-width: thin; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: var(--bg-base); }
::-webkit-scrollbar-thumb { background: var(--accent); border-radius: 8px; border: 2px solid var(--bg-base); }
::-webkit-scrollbar-thumb:hover { background: var(--accent-dim); }
::-webkit-scrollbar-corner { background: var(--bg-base); }

/* ===== SIDEBAR ===== */
#sidebar {
    width: var(--sidebar-w);
    background: var(--bg-surface);
    border-right: 1px solid var(--border-subtle);
    display: flex;
    flex-direction: column;
    height: 100%;
    height: 100vh;
    height: 100dvh;
    max-height: 100%;
    max-height: 100vh;
    max-height: 100dvh;
    z-index: 1000;
    overscroll-behavior: contain;
    min-height: 0;
    flex-shrink: 0;
}

.sidebar-header {
    padding: 20px 18px 16px;
    border-bottom: 1px solid var(--border-subtle);
    position: relative;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 14px;
}

.brand-dot {
    width: 10px;
    height: 10px;
    background: var(--accent);
    box-shadow: 0 0 12px var(--accent-glow);
    animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.sidebar-brand h1 {
    margin: 0;
    font-family: var(--font-mono);
    font-size: 0.78rem;
    font-weight: 600;
    letter-spacing: -0.02em;
    text-transform: uppercase;
    color: var(--text-primary);
}

.header-actions {
    display: flex;
    gap: 8px;
    position: absolute;
    top: 18px;
    right: 16px;
}

.icon-btn {
    width: 32px;
    height: 32px;
    border-radius: 4px;
    border: 1px solid var(--border-subtle);
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    transition: all 0.15s ease;
}

.icon-btn:hover {
    background: var(--bg-elevated);
    border-color: var(--border-strong);
    color: var(--text-primary);
}

.icon-theme { display: none; color: var(--text-primary); }
:root[data-theme="dark"] .icon-moon { display: block; }
:root[data-theme="light"] .icon-sun { display: block; }

.color-orb {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent), #a855f7);
}

/* Color popup */
.color-popup {
    position: absolute;
    top: 56px;
    right: 16px;
    background: var(--bg-elevated);
    border: 1px solid var(--border-strong);
    border-radius: 8px;
    padding: 12px;
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.5);
    z-index: 1100;
    display: none;
    min-width: 160px;
}

.color-popup.open { display: block; }

.popup-label {
    display: block;
    font-family: var(--font-mono);
    font-size: 9px;
    font-weight: 600;
    letter-spacing: 0.1em;
    color: var(--text-muted);
    margin-bottom: 8px;
}

.color-grid {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 6px;
}

.color-swatch {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    border: 2px solid var(--border-subtle);
    cursor: pointer;
    padding: 0;
    transition: transform 0.15s, border-color 0.15s;
}
.color-swatch:hover { transform: scale(1.15); }
.color-swatch.active {
    border-color: var(--text-primary);
    box-shadow: 0 0 0 2px var(--bg-elevated), 0 0 0 3px var(--accent);
}
.color-swatch[data-color="terminal"] { background: #00f2ff; }
.color-swatch[data-color="orange"]   { background: #f97316; }
.color-swatch[data-color="blue"]     { background: #3b82f6; }
.color-swatch[data-color="green"]    { background: #22c55e; }
.color-swatch[data-color="purple"]   { background: #a855f7; }
.color-swatch[data-color="red"]      { background: #ef4444; }

/* ===== PROGRESS BAR ===== */
.sidebar-progress {
    padding: 12px 18px 14px;
    border-bottom: 1px solid var(--border-subtle);
    background: var(--bg-base);
}

.progress-info {
    display: flex;
    justify-content: space-between;
    font-family: var(--font-mono);
    font-size: 9px;
    font-weight: 600;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-bottom: 6px;
}

.progress-info span:last-child { color: var(--accent); }

.progress-bar {
    height: 3px;
    background: var(--bg-elevated);
    border-radius: 2px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    width: 0%;
    background: var(--accent);
    box-shadow: 0 0 8px var(--accent-glow);
    transition: width 0.4s ease;
}

/* ===== LESSON LIST (Modules + Lessons) ===== */
.lesson-list {
    list-style: none;
    padding: 12px 10px 40px;
    margin: 0;
    overflow-y: auto;
    flex-grow: 1;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    min-height: 0;
}

.lesson-list::-webkit-scrollbar { width: 8px; }
.lesson-list::-webkit-scrollbar-track { background: var(--bg-surface); }
.lesson-list::-webkit-scrollbar-thumb { background: var(--accent); border-radius: 6px; border: 2px solid var(--bg-surface); }
.lesson-list::-webkit-scrollbar-thumb:hover { background: var(--accent-dim); }

/* Module group */
.module-group {
    margin-bottom: 4px;
}

.module-toggle {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 10px 12px;
    background: transparent;
    border: 1px solid transparent;
    border-radius: 4px;
    color: var(--text-secondary);
    font-family: var(--font-sans);
    font-size: 13px;
    font-weight: 500;
    text-align: left;
    cursor: pointer;
    transition: all 0.15s ease;
}

.module-toggle:hover {
    background: var(--bg-elevated);
    border-color: var(--border-subtle);
    color: var(--text-primary);
}

.module-group.open .module-toggle {
    background: linear-gradient(135deg, var(--accent), var(--accent-dim));
    border-color: var(--accent-dim);
    color: #ffffff;
}

.module-group.open .module-toggle:hover {
    background: linear-gradient(135deg, var(--accent), var(--accent-dim));
    border-color: var(--accent-dim);
    color: #ffffff;
}

.module-toggle-left {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}

.module-num {
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--text-faint);
    font-weight: 500;
}

.module-title {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.module-arrow {
    font-family: var(--font-mono);
    font-size: 9px;
    color: var(--text-faint);
    transition: transform 0.2s ease;
}

.module-group.open .module-num,
.module-group.open .module-arrow {
    color: rgba(255, 255, 255, 0.88);
}

.module-group.open .module-arrow { transform: rotate(90deg); }

/* Sublist */
.sublist {
    list-style: none;
    padding: 4px 0 8px 4px;
    margin: 0;
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease;
}

.module-group.open .sublist {
    max-height: 2000px;
}

.sublist li a {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 8px 12px 8px 16px;
    border-left: 1px solid var(--border-subtle);
    text-decoration: none;
    color: var(--text-secondary);
    font-size: 12.5px;
    line-height: 1.4;
    transition: all 0.15s ease;
}

.sublist li a:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
    border-left-color: var(--border-strong);
}

.sublist li a.active {
    background: rgba(0, 242, 255, 0.06);
    border-left: 2px solid var(--accent);
    color: var(--accent);
    font-weight: 500;
    text-shadow: 0 0 8px var(--accent-glow);
    padding-left: 15px;
}

.sublist li a.completed .status-icon {
    color: var(--status-done);
}

.sublist li a.completed .status-icon::before {
    content: '[✓]';
}

.sublist li a.last-visited:not(.active) {
    background: var(--bg-elevated);
}

.status-icon {
    font-family: var(--font-mono);
    font-size: 10px;
    color: var(--text-faint);
    flex-shrink: 0;
    margin-top: 1px;
    min-width: 24px;
}

.status-icon::before { content: '[ ]'; }

.sublist li a.active .status-icon {
    color: var(--accent);
}

.sublist li a.active .status-icon::before {
    content: '[>]';
    animation: pulse 1.5s ease-in-out infinite;
}

.trail-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
    margin-top: 4px;
    box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.08);
}

.trail-common {
    background: #94a3b8;
}

.trail-saas {
    background: #94a3b8;
}

.trail-mini {
    background: #94a3b8;
}

.lesson-title {
    flex: 1;
    word-break: break-word;
}

/* ===== MAIN CONTENT ===== */
#content-area {
    flex-grow: 1;
    margin-top: var(--header-h);
    height: calc(100dvh - var(--header-h));
    background: var(--bg-base);
    min-height: 0;
}
@supports not (height: calc(100dvh - 0px)) {
    #content-area { height: calc(100vh - var(--header-h)); }
}

iframe {
    width: 100%;
    height: 100%;
    border: none;
    display: block;
}

/* ===== SITE HEADER ===== */
.site-header {
    position: fixed;
    top: 0;
    left: var(--sidebar-w);
    right: 0;
    background: var(--bg-base);
    border-bottom: 1px solid var(--border-subtle);
    height: var(--header-h);
    z-index: 800;
    display: flex;
    align-items: center;
}

.site-header .header-inner {
    max-width: 1200px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: center;
}

.site-header .site-logo {
    max-height: 56px;
    width: auto;
    height: auto;
    display: block;
}

/* ===== SIDEBAR HANDLE (mobile) ===== */
#sidebar-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(2px);
    display: none;
    z-index: 900;
}
#sidebar-overlay.show { display: block; }

.sidebar-handle {
    position: fixed;
    top: 50%;
    right: 0;
    transform: translateY(-50%);
    width: 28px;
    height: 64px;
    background: var(--bg-elevated);
    color: var(--text-primary);
    border: 1px solid var(--border-strong);
    border-right: none;
    border-radius: 8px 0 0 8px;
    box-shadow: -2px 4px 12px rgba(0, 0, 0, 0.4);
    cursor: pointer;
    display: none;
    z-index: 1100;
    font-size: 16px;
}

/* ===== RESPONSIVE ===== */
@media (max-width: 768px) {
    html, body {
        height: 100%;
        min-height: -webkit-fill-available;
    }
    #sidebar {
        position: fixed;
        right: 0;
        left: auto;
        top: 0;
        bottom: 0;
        height: auto;
        width: 86vw;
        max-width: 360px;
        transform: translateX(100%);
        transition: transform 0.25s ease;
        padding-top: env(safe-area-inset-top, 0);
        padding-bottom: env(safe-area-inset-bottom, 0);
        -webkit-box-sizing: border-box;
        box-sizing: border-box;
        max-height: none;
        overflow: hidden;
        display: flex;
        flex-direction: column;
    }
    .sidebar-header,
    .sidebar-progress {
        flex-shrink: 0;
    }
    .lesson-list {
        padding-bottom: calc(40px + env(safe-area-inset-bottom, 0));
        -webkit-overflow-scrolling: touch;
    }
    #sidebar.open { transform: translateX(0); }
    .site-header {
        left: 0;
        top: env(safe-area-inset-top, 0);
    }
    .sidebar-handle { display: block; }
    #content-area { margin-top: calc(var(--header-h) + env(safe-area-inset-top, 0)); }
}

@media (max-width: 600px) {
    .site-header .site-logo { max-height: 64px; }
    #sidebar { width: 92vw; }
    .header-actions { gap: 6px; }
    .icon-btn { width: 30px; height: 30px; }
}

/* ===== FOCUS ===== */
.module-toggle:focus-visible,
.sublist li a:focus-visible,
.icon-btn:focus-visible,
.color-swatch:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
    border-radius: 4px;
}
