/* --- Layout --- */
body {
    margin: 0;
    padding: 0;
    font-family: var(--pico-font-family);
    background: var(--pico-background-color);
    color: var(--pico-color);
    height: 100vh;
}

/* No scroll on body when app is visible */
#app {
    overflow: hidden;
}

/* --- Login --- */
#login-screen {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100vh;
}
.login-box {
    width: 100%;
    max-width: 360px;
    padding: 2rem;
}
.login-box h1 {
    text-align: center;
    margin-bottom: 1.5rem;
}
.error-msg {
    color: #e74c3c;
    font-size: 0.9rem;
    text-align: center;
}

/* --- Top bar --- */
.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.5rem 1rem;
    border-bottom: 1px solid var(--pico-muted-border-color);
    background: var(--pico-card-background-color);
    height: 48px;
    box-sizing: border-box;
}
.topbar-left, .topbar-right {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.topbar-center {
    flex: 1;
    text-align: center;
    color: var(--pico-muted-color);
    font-size: 0.9rem;
}
.topbar-right button {
    margin: 0;
    padding: 0.3rem 0.7rem;
    font-size: 0.8rem;
}
#user-badge {
    font-size: 0.8rem;
    color: var(--pico-muted-color);
    background: var(--pico-card-sectioning-background-color);
    padding: 0.2rem 0.6rem;
    border-radius: 4px;
}

/* --- Main layout --- */
.main-layout {
    display: flex;
    height: calc(100vh - 48px);
    overflow: hidden;
}

/* --- Sidebar --- */
#sidebar {
    width: 240px;
    min-width: 240px;
    border-right: 1px solid var(--pico-muted-border-color);
    background: var(--pico-card-background-color);
    overflow-y: auto;
    padding: 0.5rem 0;
}

/* --- Tree nodes --- */
.tree-item {
    display: flex;
    align-items: center;
    padding: 0.35rem 0.5rem;
    cursor: pointer;
    border-radius: 4px;
    margin: 1px 0.3rem;
    font-size: 0.85rem;
    user-select: none;
    gap: 0.3rem;
}
.tree-item:hover {
    background: var(--pico-primary-hover-background);
}
.tree-item.active {
    background: var(--pico-primary-background);
    color: var(--pico-primary-inverse);
}
.tree-item.folder {
    font-weight: 500;
}
.tree-icon {
    font-size: 1rem;
    width: 1.2rem;
    text-align: center;
    flex-shrink: 0;
}
.tree-children {
    padding-left: 1rem;
}
.tree-item.dragging {
    opacity: 0.4;
}
.tree-item.drop-target {
    background: var(--pico-primary-hover-background);
    outline: 2px dashed var(--pico-primary);
    outline-offset: -2px;
}

/* --- Content area --- */
#content-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    padding: 0;
    min-height: 0;
}
#welcome-msg {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--pico-muted-color);
}
#view-area {
    flex: 1;
    overflow-y: auto;
    min-height: 0;
}

/* --- Markdown rendered view --- */
#md-rendered {
    padding: 1.5rem 2rem;
    line-height: 1.7;
    max-width: 800px;
}
.inline-checkbox {
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    cursor: pointer;
    width: 18px;
    height: 18px;
    border: 2px solid var(--pico-muted-color);
    border-radius: 4px;
    vertical-align: middle;
    margin-right: 0.3rem;
    position: relative;
    background: transparent;
    transition: all 0.15s ease;
}
.inline-checkbox:hover {
    border-color: var(--pico-primary-hover-color);
}
.inline-checkbox:checked {
    background: var(--pico-primary-background);
    border-color: var(--pico-primary-background);
}
.inline-checkbox:checked::after {
    content: '✓';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: var(--pico-primary-inverse);
    font-size: 12px;
    font-weight: bold;
}
.markdown-body img {
    max-width: 100%;
    border-radius: 6px;
}
.markdown-body pre {
    background: var(--pico-card-sectioning-background-color);
    padding: 1rem;
    border-radius: 6px;
    overflow-x: auto;
}
.markdown-body table {
    width: 100%;
    border-collapse: collapse;
}
.markdown-body th, .markdown-body td {
    border: 1px solid var(--pico-muted-border-color);
    padding: 0.5rem;
}

/* --- Editor area --- */
#edit-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}
#milkdown-editor {
    flex: 1;
    overflow-y: auto;
    padding: 1rem 2rem;
    min-height: 0;
}
#milkdown-editor textarea {
    width: 100%;
    height: 100%;
    min-height: 300px;
    font-family: 'Fira Code', 'Consolas', monospace;
    font-size: 0.95rem;
    line-height: 1.6;
    border: none;
    resize: none;
    outline: none;
    background: transparent;
    color: inherit;
}
.edit-actions {
    display: flex;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    border-top: 1px solid var(--pico-muted-border-color);
    background: var(--pico-card-background-color);
}
.edit-actions button {
    margin: 0;
    font-size: 0.85rem;
}

/* --- Meta footer --- */
#meta-footer {
    padding: 0.3rem 1rem;
    border-top: 1px solid var(--pico-muted-border-color);
    background: var(--pico-card-background-color);
    font-size: 0.75rem;
    color: var(--pico-muted-color);
}

/* --- Responsive --- */
@media (max-width: 768px) {
    #sidebar {
        width: 180px;
        min-width: 180px;
    }
    .topbar-center { display: none; }
}
