/* ============================================================
   CodeLens — Learn
   ============================================================ */

:root {
    --bg-dark: #1a1a2e;
    --bg-card: #16213e;
    --bg-code: #0d0d1a;
    --border: #2a2a4a;
    --text: #e0e0e0;
    --text-muted: #75715e;
    --html: #e94560;
    --css: #53d8fb;
    --js: #fd971f;
}

* { margin: 0; padding: 0; box-sizing: border-box; font-family: 'Segoe UI', Tahoma, sans-serif; }

body {
    background: var(--bg-dark);
    color: var(--text);
    min-height: 100vh;
    line-height: 1.7;
}

/* ====== HEADER ====== */
.header {
    background: var(--bg-card);
    padding: 12px 25px;
    border-bottom: 2px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    position: sticky;
    top: 0;
    z-index: 100;
    gap: 10px;
}
.header .brand { color: var(--html); font-size: 1.2rem; font-weight: bold; }
.header .brand span { color: var(--css); font-weight: 300; font-size: 0.85rem; }
.header .nav-links { display: flex; gap: 6px; flex-wrap: wrap; }
.header .nav-links a {
    color: #c4c4d4;
    text-decoration: none;
    padding: 7px 14px;
    border-radius: 6px;
    font-size: 0.85rem;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 5px;
}
.header .nav-links a:hover { background: #2a3a5e; color: #fff; }
.header .nav-links a.active { background: #2a3a5e; color: var(--html); }

.container-main { padding: 20px; max-width: 1400px; margin: 0 auto; }

/* ====== MODULE HEADER ====== */
.module-header {
    background: linear-gradient(135deg, var(--bg-card), var(--bg-dark));
    border-radius: 16px;
    padding: 25px 30px;
    border: 1px solid var(--border);
    margin-bottom: 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 15px;
}
.module-header h1 {
    font-size: 1.5rem;
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 0;
}
.module-header .module-icon {
    width: 50px;
    height: 50px;
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.6rem;
}

.module-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.action-btn {
    padding: 10px 18px;
    border-radius: 8px;
    border: none;
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 600;
    font-family: inherit;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: all 0.25s;
}

.action-btn:hover { transform: translateY(-2px); }

.action-btn.btn-save     { background: #a6e22e; color: var(--bg-dark); }
.action-btn.btn-save:hover { background: #8cc41a; }

.action-btn.btn-undo     { background: var(--js); color: var(--bg-dark); }
.action-btn.btn-undo:hover { background: #e0861a; }

.action-btn.btn-history  { background: #6c5ce7; color: #fff; }
.action-btn.btn-history:hover { background: #5b4bc4; }

.action-btn.btn-reset    { background: #ff6b6b; color: #fff; }
.action-btn.btn-reset:hover { background: #e05555; }

.action-btn.btn-preview  { background: var(--css); color: var(--bg-dark); }
.action-btn.btn-preview:hover { background: #3ac0e0; }

.action-btn.btn-show     { background: rgba(166, 226, 46, 0.15); color: #a6e22e; border: 1px solid rgba(166, 226, 46, 0.3); }
.action-btn.btn-show:hover { background: #a6e22e; color: var(--bg-dark); }

/* ====== LAYOUT ====== */
.learn-layout {
    display: grid;
    grid-template-columns: 280px 1fr;
    gap: 15px;
    min-height: calc(100vh - 200px);
}

/* ====== SIDEBAR ====== */
.sidebar {
    background: var(--bg-card);
    border-radius: 12px;
    border: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    max-height: calc(100vh - 160px);
    position: sticky;
    top: 80px;
}
.sidebar-header {
    padding: 15px 18px;
    border-bottom: 1px solid var(--border);
    color: var(--css);
    font-size: 0.95rem;
    display: flex;
    align-items: center;
    gap: 8px;
}
.sidebar-header .count {
    margin-right: auto;
    background: rgba(83, 216, 251, 0.15);
    color: var(--css);
    padding: 2px 10px;
    border-radius: 10px;
    font-size: 0.7rem;
}

.section-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}
.section-item {
    padding: 10px 12px;
    border-radius: 8px;
    cursor: pointer;
    color: #c4c4d4;
    font-size: 0.85rem;
    margin-bottom: 4px;
    display: flex;
    align-items: center;
    gap: 10px;
    transition: all 0.2s;
    border-right: 3px solid transparent;
}
.section-item:hover { background: #2a3a5e; color: #fff; }
.section-item.active {
    background: rgba(83, 216, 251, 0.12);
    color: #fff;
    border-right-color: var(--css);
}
.section-item i { width: 18px; text-align: center; }

/* ====== MAIN PANEL ====== */
.main-panel {
    display: flex;
    flex-direction: column;
    gap: 15px;
    min-width: 0;
}

.editor-box {
    background: var(--bg-card);
    border-radius: 12px;
    border: 1px solid var(--border);
    overflow: hidden;
}
.editor-header {
    padding: 12px 18px;
    background: var(--bg-code);
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.editor-header .title {
    font-size: 0.95rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
}

.CodeMirror {
    height: 350px !important;
    font-family: 'Courier New', monospace;
    font-size: 14px;
    line-height: 1.7;
    background: var(--bg-code) !important;
    direction: ltr;
    text-align: left;
}
.CodeMirror-gutters { background: var(--bg-code) !important; border-right: 1px solid var(--border) !important; }
.CodeMirror-linenumber { color: var(--text-muted) !important; }

/* ====== EXPLANATION ====== */
.explanation-box {
    background: var(--bg-card);
    border-radius: 12px;
    border: 1px solid var(--border);
    border-right: 4px solid var(--css);
    padding: 20px 25px;
    font-size: 0.92rem;
    line-height: 1.9;
}
.explanation-box h3 {
    color: var(--css);
    margin-bottom: 12px;
    font-size: 1.1rem;
    display: flex;
    align-items: center;
    gap: 8px;
}
.explanation-box p { color: #c4c4d4; margin-bottom: 10px; }
.explanation-box ul { padding-right: 25px; margin: 10px 0; }
.explanation-box li { color: #c4c4d4; margin: 6px 0; }
.explanation-box code {
    background: var(--bg-code);
    color: #e6db74;
    padding: 2px 8px;
    border-radius: 4px;
    font-family: 'Courier New', monospace;
    font-size: 0.85em;
    direction: ltr;
    display: inline-block;
}
.explanation-box pre {
    background: var(--bg-code);
    padding: 12px 15px;
    border-radius: 8px;
    border-right: 3px solid var(--css);
    overflow-x: auto;
    margin: 10px 0;
    direction: ltr;
    text-align: left;
}
.explanation-box pre code {
    background: transparent;
    padding: 0;
    color: #f8f8f2;
    display: block;
}
.explanation-box .tip-box {
    background: rgba(253, 151, 31, 0.08);
    border-right: 3px solid var(--js);
    padding: 12px 15px;
    border-radius: 8px;
    margin: 15px 0;
    font-size: 0.88rem;
}

/* ====== MODALER ====== */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.85);
    z-index: 10000;
    justify-content: center;
    align-items: center;
    padding: 20px;
    backdrop-filter: blur(6px);
}
.modal-overlay.show { display: flex; }

.modal-content {
    background: var(--bg-card);
    border-radius: 14px;
    border: 1px solid var(--border);
    max-width: 900px;
    width: 100%;
    max-height: 88vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 60px rgba(0,0,0,0.8);
}
.modal-header {
    padding: 15px 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.modal-header h3 {
    color: var(--css);
    font-size: 1.05rem;
    margin: 0;
    display: flex;
    align-items: center;
    gap: 8px;
}
.modal-close {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.6rem;
    cursor: pointer;
    line-height: 1;
    transition: all 0.3s;
}
.modal-close:hover { color: var(--html); transform: rotate(90deg); }
.modal-body {
    padding: 18px 20px;
    overflow: auto;
    flex: 1;
}

/* Historikk-item */
.history-item {
    padding: 12px 15px;
    background: var(--bg-code);
    border: 1px solid var(--border);
    border-radius: 8px;
    margin-bottom: 8px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
}
.history-item .info { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.history-item .ver {
    background: rgba(83, 216, 251, 0.15);
    color: var(--css);
    padding: 2px 10px;
    border-radius: 10px;
    font-size: 0.72rem;
    font-weight: 600;
    width: fit-content;
}
.history-item .date { color: var(--text-muted); font-size: 0.75rem; }
.history-item .preview { color: #c4c4d4; font-size: 0.82rem; }

.btn-restore {
    padding: 6px 14px;
    background: #a6e22e;
    color: var(--bg-dark);
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.78rem;
    font-weight: 600;
    font-family: inherit;
}
.btn-restore:hover { background: #8cc41a; }

/* Popup kode-visning */
.code-viewer {
    background: var(--bg-code);
    color: #f8f8f2;
    padding: 20px;
    border-radius: 8px;
    font-family: 'Courier New', monospace;
    font-size: 0.82rem;
    line-height: 1.7;
    direction: ltr;
    text-align: left;
    white-space: pre;
    overflow: auto;
    max-height: 65vh;
    border: 1px solid var(--border);
}

/* ====== TOAST ====== */
.toast {
    position: fixed;
    bottom: 25px;
    left: 25px;
    background: #2a3a5e;
    color: var(--text);
    padding: 14px 24px;
    border-radius: 10px;
    border: 1px solid var(--border);
    z-index: 99999;
    transform: translateY(100px);
    opacity: 0;
    transition: all 0.4s ease;
    max-width: 400px;
    box-shadow: 0 8px 30px rgba(0,0,0,0.5);
    font-size: 0.9rem;
}
.toast.show { transform: translateY(0); opacity: 1; }
.toast.success { background: #2d5a4e; }
.toast.error { background: #5a2a4e; }
.toast.info { background: #2a4a5e; }

/* ===== AKTIV PROSJEKT-KORT NEDERST ===== */
.active-project-card {
    display: flex;
    align-items: center;
    gap: 18px;
    background: var(--bg-code);
    border: 2px solid #a6e22e;
    border-radius: 14px;
    padding: 18px 22px;
    margin-top: 20px;
    position: relative;
    background: linear-gradient(160deg, var(--bg-code), rgba(166, 226, 46, 0.08));
    flex-wrap: wrap;
}

.apc-badge {
    position: absolute;
    top: 10px;
    right: 12px;
    background: #a6e22e;
    color: var(--bg-dark);
    padding: 3px 10px;
    border-radius: 10px;
    font-size: 0.65rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 4px;
}

.apc-icon {
    width: 55px;
    height: 55px;
    border-radius: 14px;
    background: rgba(166, 226, 46, 0.15);
    color: #a6e22e;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.6rem;
    flex-shrink: 0;
}

.apc-info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.apc-info h3 {
    color: #fff;
    font-family: 'Courier New', monospace;
    font-size: 1.2rem;
    direction: ltr;
    text-align: right;
    margin: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-weight: 700;
}

.apc-files {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.file-chip {
    padding: 3px 10px;
    border-radius: 8px;
    font-size: 0.68rem;
    font-family: 'Courier New', monospace;
    direction: ltr;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.file-chip.present {
    background: rgba(166, 226, 46, 0.15);
    color: #a6e22e;
}

.file-chip.missing {
    background: rgba(117, 113, 94, 0.15);
    color: rgba(117, 113, 94, 0.7);
    text-decoration: line-through;
}

.apc-btn-result {
    padding: 13px 28px;
    background: linear-gradient(135deg, #a6e22e, #8cc41a);
    color: #1a1a2e;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 700;
    font-family: inherit;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    transition: all 0.25s;
    box-shadow: 0 6px 20px rgba(166, 226, 46, 0.3);
    flex-shrink: 0;
}

.apc-btn-result:hover {
    transform: translateY(-3px);
    box-shadow: 0 12px 30px rgba(166, 226, 46, 0.5);
}

.apc-btn-result i {
    font-size: 1rem;
}

/* ===== LIVE PREVIEW AV PROSJEKTET ===== */
.project-preview-section {
    background: var(--bg-card);
    border-radius: 16px;
    border: 1px solid var(--border);
    overflow: hidden;
    margin-top: 20px;
}

.preview-header {
    padding: 15px 22px;
    background: linear-gradient(135deg, var(--bg-code), var(--bg-dark));
    border-bottom: 2px solid #6c5ce7;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
}

.preview-header h3 {
    color: #fff;
    font-size: 1rem;
    margin: 0;
    display: flex;
    align-items: center;
    gap: 10px;
}

.preview-header h3 i {
    color: #a29bfe;
}

.preview-header code {
    background: rgba(108, 92, 231, 0.2);
    color: #a29bfe;
    padding: 3px 12px;
    border-radius: 8px;
    font-family: 'Courier New', monospace;
    direction: ltr;
    font-size: 0.85rem;
}

.btn-preview-action {
    padding: 8px 16px;
    background: rgba(83, 216, 251, 0.15);
    color: #53d8fb;
    border: 1px solid rgba(83, 216, 251, 0.3);
    border-radius: 8px;
    text-decoration: none;
    font-size: 0.82rem;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: all 0.3s;
    cursor: pointer;
    font-family: inherit;
}

.btn-preview-action:hover {
    background: #53d8fb;
    color: var(--bg-dark);
    transform: translateY(-2px);
}

.btn-preview-action.green {
    background: rgba(166, 226, 46, 0.15);
    color: #a6e22e;
    border-color: rgba(166, 226, 46, 0.3);
}

.btn-preview-action.green:hover {
    background: #a6e22e;
    color: var(--bg-dark);
}

.preview-iframe-wrapper {
    background: #fff;
    height: 500px;
}

.preview-iframe-wrapper iframe {
    width: 100%;
    height: 100%;
    border: none;
    display: block;
}

.preview-empty {
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    background: #f8f9fa;
    padding: 30px;
}

.preview-empty i {
    font-size: 3rem;
    color: #ccc;
    margin-bottom: 15px;
}

.preview-empty p {
    font-size: 0.95rem;
}

.preview-empty code {
    background: #e0e0e0;
    color: #333;
    padding: 2px 8px;
    border-radius: 4px;
    font-family: 'Courier New', monospace;
    direction: ltr;
    display: inline-block;
}

@media (max-width: 768px) {
    .preview-header {
        flex-direction: column;
        align-items: stretch;
    }
    .preview-header h3 {
        justify-content: center;
    }
    .btn-preview-action {
        flex: 1;
        justify-content: center;
    }
    .preview-iframe-wrapper {
        height: 350px;
    }
    .active-project-card {
        padding: 15px;
        gap: 12px;
    }
    .apc-icon {
        width: 45px;
        height: 45px;
        font-size: 1.3rem;
    }
    .apc-info h3 {
        font-size: 1rem;
    }
    .apc-btn-result {
        width: 100%;
        justify-content: center;
    }
}

/* ====== RESPONSIVE ====== */
@media (max-width: 900px) {
    .learn-layout { grid-template-columns: 1fr; }
    .sidebar { position: static; max-height: 300px; }
}
@media (max-width: 768px) {
    .header { flex-direction: column; align-items: flex-start; }
    .container-main { padding: 12px; }
    .module-header { padding: 18px; }
    .module-actions { width: 100%; }
    .action-btn { flex: 1; justify-content: center; font-size: 0.78rem; padding: 8px 12px; }
}