/*
 * Main Stylesheet for KnowledgeMap
 */

/* --- 1. Global Reset & Variables --- */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

:root {
    --primary-color: #5A67D8; /* Indigo */
    --primary-light: #C3DAFE;
    --text-color: #2D3748; /* Gray-900 */
    --subtle-text: #718096; /* Gray-600 */
    --background-color: #F7FAFC; /* Gray-100 */
    --surface-color: #FFFFFF;
    --border-color: #E2E8F0; /* Gray-200 */
    --highlight-color: #F6AD55; /* Orange-400 */
    --suggested-link-color: #48BB78; /* Green-500 */
    --danger-color: #E53E3E; /* Red-600 */
}

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    margin: 0;
    padding: 0;
    background-color: #f4f4f4;
    color: var(--text-color);
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
}

button, input, textarea, select {
    font-family: inherit;
    font-size: 100%;
}

button {
    cursor: pointer;
    background: none;
    border: none;
}

/* --- 2. Loader & NoScript --- */
.app-loader {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100vh;
    color: var(--subtle-text);
}
.app-loader .spinner {
    width: 48px;
    height: 48px;
    border: 4px solid var(--primary-light);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 1rem;
}
@keyframes spin {
    to { transform: rotate(360deg); }
}

.no-script-warning {
    padding: 2rem;
    text-align: center;
}

/* --- 3. Auth Container (Login/Signup) --- */
.auth-container {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100vh;
    width: 100vw;
}
.auth-box {
    background: var(--surface-color);
    padding: 2.5rem 2rem;
    border-radius: 0.75rem;
    box-shadow: 0 10px 25px rgba(0,0,0,0.08);
    border: 1px solid var(--border-color);
    width: 100%;
    max-width: 400px;
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}
.auth-box h2 {
    color: var(--primary-color);
    text-align: center;
    font-size: 1.5rem;
    margin-bottom: 0.5rem;
}
.auth-box input[type="email"],
.auth-box input[type="password"],
.auth-box input[type="text"] {
    width: 100%;
    padding: 0.8rem 1rem;
    border: 1px solid var(--border-color);
    border-radius: 0.5rem;
    font-size: 0.95rem;
    color: var(--text-color);
    background-color: var(--background-color);
    transition: all 0.2s ease-in-out;
}
.auth-box input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px var(--primary-light);
    background-color: var(--surface-color);
}
.auth-box button {
    padding: 0.9rem 1.5rem;
    border-radius: 0.5rem;
    cursor: pointer;
    font-weight: 600;
    font-size: 1rem;
    transition: background-color 0.2s;
    background-color: var(--primary-color);
    color: var(--surface-color);
    border: 1px solid var(--primary-color);
}
.auth-box button:hover {
    background-color: #4A55B2;
}
.auth-box .error-message {
    color: var(--danger-color);
    font-size: 0.85rem;
    text-align: center;
    min-height: 1.2em;
}
.auth-box a {
    color: var(--primary-color);
    text-decoration: none;
    font-size: 0.9rem;
    text-align: center;
}
.auth-box a:hover {
    text-decoration: underline;
}

/* --- 4. Main App Shell --- */
#app {
    display: flex;
    flex-direction: column;
    height: 100vh;
}
.top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 1.5rem;
    z-index: 100;
    flex-shrink: 0;
}
.top-bar .logo {
    font-weight: 700;
    font-size: 1.25rem;
    color: var(--primary-color);
}
.search-bar {
    flex-grow: 1;
    margin: 0 2rem;
    position: relative;
}
.search-bar input {
    width: 100%;
    padding: 0.75rem 1rem 0.75rem 2.5rem; /* Space for icon */
    border: 1px solid var(--border-color);
    border-radius: 0.5rem;
    font-size: 0.9rem;
    color: var(--text-color);
    background-color: var(--background-color);
    transition: all 0.2s ease-in-out;
}
.search-bar input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px var(--primary-light);
    background-color: var(--surface-color);
}
.user-controls {
    display: flex;
    align-items: center;
    gap: 1rem;
}
.user-controls button {
    color: #000000;
    padding: 0.5rem;
    border-radius: 0.25rem;
    transition: background-color 0.2s;
}

.btn-manage-members {
    background-color: #71809600 !important;
}

.btn-invite {
    background-color: #5a67d800 !important;
}

.user-controls button:hover {
    background-color: var(--background-color);
}
.user-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background-color: var(--primary-color);
    color: var(--surface-color);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.9rem;
    cursor: pointer;
}

.main-content {
    flex-grow: 1;
    display: flex;
    position: relative;
    overflow: hidden;
}
.map-container {
    flex-grow: 1;
    position: relative;
    overflow: hidden;
}
#mapCanvas {
    position: absolute;
    top: 0;
    left: 0;
    background-color: #f4f4f4;
}

/* --- 5. Sidebar --- */
.sidebar {
    width: 500px;
    background-color: var(--surface-color);
    border-left: 1px solid var(--border-color);
    box-shadow: -1px 0 3px rgba(0,0,0,0.05);
    display: flex;
    flex-direction: column;
    z-index: 100;
    transform: translateX(100%);
    transition: transform 0.3s ease-in-out;
    
    /* --- FIXED POSITIONING --- */
    position: absolute;
    top: 0;
    right: 0;
    height: 100%;
}
.sidebar.open {
    transform: translateX(0);
}
.sidebar-header {
    display: flex;
    justify-content: flex-end;
    /*padding: 0.75rem 0.75rem 0 0.75rem;*/
}
.sidebar-close {
    font-size: 1.5rem;
    color: var(--subtle-text);
    transition: color 0.2s;
}
.sidebar-close:hover {
    color: var(--text-color);
}
.sidebar-content {
    flex-grow: 1;
    padding: 0 0.4rem 1.5rem;
    display: flex;
    flex-direction: column;
    /*gap: 1rem;*/
    overflow-y: auto;
    scrollbar-width: thin;
}
.sidebar-title-input {
    width: 100%;
    border: none;
    padding: 0.5rem;
    border-radius: 0.25rem;
    resize: none;
    font-size: 1.2rem;
    font-weight: 600;
    color: var(--primary-color);
}
.sidebar-title-input:focus {
    outline: none;
    background-color: var(--background-color);
    box-shadow: inset 0 0 0 2px var(--primary-light);
}

/* --- NEW: Sidebar Content Display --- */
.sidebar-content-display {
    flex-grow: 1;
    line-height: 1.6;
    padding: 0.5rem;
    overflow-y: auto;
    word-wrap: break-word;
    font-size: 0.9rem;
    border: 1px solid transparent;
    min-height: 200px;
    scrollbar-width: thin;
}
.sidebar-content-display[contenteditable="true"]:not(.readonly) {
    /*border: 1px solid var(--border-color);*/
    border: none !important;
    border-radius: 0.25rem;
    background-color: var(--surface-color);
}
.sidebar-content-display[contenteditable="true"]:not(.readonly):focus {
    border: none !important;
    outline: none;
    border-color: var(--primary-color);
    box-shadow: inset 0 0 0 2px var(--primary-light);
}
.sidebar-content-display.readonly,
.sidebar-title-input.readonly {
    background-color: var(--background-color);
    cursor: not-allowed;
    color: var(--subtle-text);
    border-color: transparent;
    box-shadow: none;
}
/* Display styles for HTML tags inside the sidebar content */
.sidebar-content-display p { margin-bottom: 0.75em; }
.sidebar-content-display ul, .sidebar-content-display ol { margin-left: 1.5em; padding-left: 1em; margin-bottom: 0.75em; }
.sidebar-content-display li { margin-bottom: 0.25em; }
.sidebar-content-display a { color: var(--primary-color); text-decoration: underline; }
.sidebar-content-display a:hover { color: #4A55B2; }
.sidebar-content-display strong, .sidebar-content-display b { font-weight: 600; }
.sidebar-content-display em, .sidebar-content-display i { font-style: italic; }
.sidebar-content-display u { text-decoration: underline; }

.ai-insights {
    border-top: 1px solid var(--border-color);
    padding-top: 1.5rem;
}
.ai-insights h4 {
    margin-top: 0;
    font-size: 1rem;
    color: var(--text-color);
}

/* --- 6. Modals --- */
.modal-overlay {
    position: fixed; /* Changed from absolute to cover whole screen */
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0,0,0,0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}
.modal-overlay.open {
    opacity: 1;
    visibility: visible;
}
.modal {
    background-color: var(--surface-color);
    padding: 2rem;
    border-radius: 0.75rem;
    box-shadow: 0 8px 20px rgba(0,0,0,0.15);
    width: 90%;
    max-width: 500px;
    transform: translateY(20px);
    opacity: 0;
    transition: transform 0.3s ease, opacity 0.3s ease;
}
.modal-overlay.open .modal {
    transform: translateY(0);
    opacity: 1;
}
.modal h2 {
    margin-top: 0;
    color: var(--primary-color);
    font-size: 1.5rem;
    margin-bottom: 1.5rem;
}
.modal label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    color: var(--text-color);
}
.modal input[type="text"] { /* Remove textarea from this rule */
    width: 100%;
    padding: 0.75rem 10px;
    border: 1px solid var(--border-color);
    border-radius: 0.5rem;
    margin-bottom: 1rem;
    font-size: 0.9rem;
    background-color: var(--background-color);
}
.modal .modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
    margin-top: 1.5rem;
}
.modal .btn-cancel {
    background-color: var(--background-color);
    color: var(--subtle-text);
    border: 1px solid var(--border-color);
    padding: 0.75rem 1.5rem;
    border-radius: 0.5rem;
    font-weight: 600;
}
.modal .btn-cancel:hover {
    background-color: var(--border-color);
}
.modal .btn-primary {
    background-color: var(--primary-color);
    color: var(--surface-color);
    border: 1px solid var(--primary-color);
    padding: 0.75rem 1.5rem;
    border-radius: 0.5rem;
    font-weight: 600;
}
.modal .btn-primary:hover {
    background-color: #4A55B2;
}

/* --- NEW: Editor Styles --- */
.editor-toolbar {
    border: 1px solid var(--border-color);
    border-bottom: none;
    border-radius: 0.5rem 0.5rem 0 0;
    padding: 0.5rem 0.75rem;
    background-color: #e5e3ff;
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 0;
}
.editor-toolbar button {
    background: none;
    border: none;
    padding: 0.25rem;
    cursor: pointer;
    color: var(--subtle-text);
    border-radius: 0.25rem;
    line-height: 1;
}
.editor-toolbar button:hover {
    background-color: var(--border-color);
    color: var(--text-color);
}
.editor-toolbar button .feather {
    width: 1rem;
    height: 1rem;
    vertical-align: middle;
}
.editor-toolbar button[data-command="insertOrderedList"] {
    font-weight: bold;
    font-size: 0.9em;
    position: relative;
    top: -1px;
}
.modal-content-editor {
    width: 100%;
    min-height: 150px;
    max-height: 40vh;
    overflow-y: auto;
    border: 1px solid var(--border-color);
    border-radius: 0 0 0.5rem 0.5rem;
    padding: 0.75rem 10px;
    font-size: 0.9rem;
    line-height: 1.5;
    background-color: var(--surface-color);
    margin-bottom: 1rem;
    outline: none;
}
.modal-content-editor:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px var(--primary-light);
}
.modal-content-editor:empty::before {
    content: attr(placeholder);
    color: var(--subtle-text);
    pointer-events: none;
    display: block;
}


/* --- 7. Floating Action Button (FAB) --- */
.fab {
    position: absolute;
    bottom: 2rem;
    right: 2rem;
    width: 60px;
    height: 60px;
    background-color: var(--primary-color);
    color: var(--surface-color);
    border-radius: 50%;
    font-size: 2rem;
    font-weight: 300;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 10px rgba(0,0,0,0.2);
    transition: transform 0.2s ease, background-color 0.2s;
    z-index: 50;
}
.fab:hover {
    background-color: #4A55B2;
    transform: translateY(-2px) scale(1.05);
}