/* Reset and Base Styles */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body, button, select, input, textarea {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

body {
    background-color: #f4f7f6;
    color: #333;
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
}

/* Header */
header {
    background-color: #2c3e50;
    color: white;
    padding: 1rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}

.auth-btn {
    padding: 0.5rem 1rem;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-weight: 600;
    background-color: #3498db;
    color: white;
    transition: background 0.2s;
}

.auth-btn:hover {
    background-color: #2980b9;
}

/* Top Navigation (Main Projects) */
.top-tabs {
    background-color: #fff;
    border-bottom: 1px solid #ddd;
    display: flex;
    align-items: center;
    padding: 0 1rem;
    overflow-x: auto;
    white-space: nowrap;
}

#tabs-container {
    display: flex;
}

.tab {
    padding: 1rem 1.5rem;
    cursor: pointer;
    border-bottom: 3px solid transparent;
    transition: all 0.2s;
}

.tab.active {
    border-bottom-color: #3498db;
    color: #3498db;
    font-weight: bold;
}

.tab:hover {
    background-color: #f0f0f0;
}

#add-main-project {
    margin-left: 1rem;
    padding: 0.3rem 0.8rem;
    border: 1px dashed #3498db;
    background: transparent;
    color: #3498db;
    cursor: pointer;
    border-radius: 4px;
}

/* Main Layout */
.main-container {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* Sidebar (Sub-projects) */
aside {
    width: 250px;
    background-color: #fff;
    border-right: 1px solid #ddd;
    display: flex;
    flex-direction: column;
    padding: 1rem;
}

aside h3 {
    margin-bottom: 1rem;
    font-size: 0.9rem;
    text-transform: uppercase;
    color: #7f8c8d;
}

#sub-project-list {
    list-style: none;
    flex: 1;
    overflow-y: auto;
}

.sub-item {
    padding: 0.8rem;
    margin-bottom: 0.5rem;
    border-radius: 4px;
    cursor: pointer;
    transition: background 0.2s;
}

.sub-item.active {
    background-color: #e8f4fd;
    color: #3498db;
    font-weight: 600;
}

.sub-item-error {
    padding: 0.8rem;
    color: #e74c3c;
    font-size: 0.8rem;
    font-style: italic;
}

#add-sub-project {
    margin-top: 1rem;
    padding: 0.6rem;
    background: #ecf0f1;
    border: 1px dashed #bdc3c7;
    cursor: pointer;
    border-radius: 4px;
}

/* Content Area & Editor */
main {
    flex: 1;
    display: flex;
    flex-direction: column;
    background-color: white;
    position: relative;
    min-width: 0; /* Prevents flex item from expanding beyond container */
}

#editor-toolbar {
    padding: 0.5rem 1rem;
    border-bottom: 1px solid #ddd;
    background-color: #f9f9f9;
    display: flex;
    gap: 0.5rem;
    align-items: center;
    flex-wrap: wrap; /* Allows toolbar to wrap on small screens */
}

#editor-toolbar button, #editor-toolbar select {
    padding: 0.3rem 0.6rem;
    border: 1px solid #ccc;
    background: white;
    cursor: pointer;
    border-radius: 3px;
    height: 32px; /* Consistent height */
}

#editor-toolbar select {
    font-size: 0.9rem;
    outline: none;
}

.toolbar-right {
    margin-left: auto;
    display: flex;
    gap: 0.5rem;
}

.save-btn {
    background-color: #27ae60 !important;
    color: white !important;
    border: none !important;
}

.delete-btn {
    background-color: #e74c3c !important;
    color: white !important;
    border: none !important;
}

#editor {
    flex: 1;
    padding: 2rem;
    overflow-y: auto;
    overflow-x: hidden; /* Prevent horizontal scroll */
    outline: none;
    line-height: 1.6;
    word-wrap: break-word; /* IE/Edge */
    overflow-wrap: break-word; /* Standard */
    max-width: 100%;
    /* Remove global font override to allow execCommand's <font> or <span> tags to work */
}

#editor * {
    font-family: inherit;
}

#editor img {
    max-width: 100%; /* Ensure images don't overflow */
    height: auto;
}

.tab-error {
    color: #e74c3c;
    padding: 1rem;
    font-size: 0.8rem;
    font-style: italic;
}

/* Floating Action Button */
.floating-btn {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background-color: #e74c3c;
    color: white;
    border: none;
    box-shadow: 0 4px 10px rgba(0,0,0,0.3);
    cursor: pointer;
    font-size: 1.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s;
    z-index: 100;
}

.floating-btn:hover {
    transform: scale(1.1);
}

/* Responsive Design (Mobile) */
@media (max-width: 768px) {
    .main-container {
        flex-direction: column;
    }

    aside {
        width: 100%;
        height: auto;
        max-height: 200px;
        border-right: none;
        border-bottom: 1px solid #ddd;
    }

    #sub-project-list {
        display: flex;
        overflow-x: auto;
        gap: 0.5rem;
    }

    .sub-item {
        white-space: nowrap;
        margin-bottom: 0;
    }

    header h1 {
        font-size: 1.2rem;
    }
}
