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

:root {
    --bg-color: #ffffff;
    --text-color: #333333;
    --border-color: #e0e0e0;
    --button-bg: #f5f5f5;
    --button-hover: #e5e5e5;
    --shadow: rgba(0, 0, 0, 0.1);
}

[data-theme="dark"] {
    --bg-color: #1a1a1a;
    --text-color: #e0e0e0;
    --border-color: #404040;
    --button-bg: #2a2a2a;
    --button-hover: #3a3a3a;
    --shadow: rgba(255, 255, 255, 0.1);
}

body {
    font-family: 'Montserrat', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    transition: all 0.3s ease;
    min-height: 100vh;
    display: flex;
}

.sidebar {
    width: 280px;
    background: var(--bg-color);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    transition: all 0.3s ease;
}

.sidebar.collapsed {
    width: 60px;
}

.sidebar-header {
    padding: 20px;
    height: 81px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    gap: 10px;
}

.sidebar.collapsed .sidebar-header {
    padding: 20px 10px;
    justify-content: center;
}

.sidebar-toggle {
    background: none;
    border: none;
    font-size: 18px;
    cursor: pointer;
    padding: 8px;
    border-radius: 4px;
    color: var(--text-color);
    transition: background 0.2s ease;
}

.sidebar-toggle:hover {
    background: var(--button-hover);
}

.sidebar-title {
    font-size: 18px;
    font-weight: 600;
    transition: opacity 0.3s ease;
}

.sidebar.collapsed .sidebar-title {
    opacity: 0;
    width: 0;
    overflow: hidden;
}

.new-tab-btn {
    flex: 1;
    background: var(--button-bg);
    border: 1px solid var(--border-color);
    color: var(--text-color);
    padding: 10px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    font-family: 'Montserrat', sans-serif;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: all 0.2s ease;
}

.sidebar.collapsed .new-tab-btn {
    width: 40px;
    height: 40px;
    padding: 8px;
    border-radius: 50%;
}

.sidebar.collapsed .new-tab-btn .btn-text {
    display: none;
}

.new-tab-btn:hover {
    background: var(--button-hover);
    box-shadow: 0 2px 4px var(--shadow);
}

.tabs-container {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
}

.sidebar.collapsed .tabs-container {
    padding: 20px 10px;
}

.tab-item {
    padding: 12px;
    margin-bottom: 8px;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: space-between;
    group: tab;
    position: relative;
}

.sidebar.collapsed .tab-item {
    width: 40px;
    height: 40px;
    padding: 8px;
    justify-content: center;
}

.tab-item:hover {
    background: var(--button-hover);
}

.tab-item.active {
    background: var(--button-bg);
    border: 1px solid var(--border-color);
}

.tab-content {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1;
    min-width: 0;
}

.tab-icon {
    font-size: 16px;
    color: var(--text-color);
    opacity: 0.7;
}

.tab-title {
    font-size: 14px;
    font-weight: 500;
    color: var(--text-color);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: opacity 0.3s ease;
}

.sidebar.collapsed .tab-title {
    display: none;
}

.tab-actions {
    display: flex;
    align-items: center;
    gap: 4px;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.tab-item:hover .tab-actions {
    opacity: 1;
}

.sidebar.collapsed .tab-actions {
    display: none;
}

.tab-action-btn {
    background: none;
    border: none;
    padding: 4px;
    border-radius: 3px;
    cursor: pointer;
    color: var(--text-color);
    opacity: 0.6;
    font-size: 12px;
    transition: all 0.2s ease;
}

.tab-action-btn:hover {
    opacity: 1;
    background: var(--border-color);
}

.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.header {
    padding: 20px;
    height: 81px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.header-row {
    display: flex;
    align-items: center;
    gap: 15px;
    flex: 1;
}

.header h1 {
    font-size: 24px;
    font-weight: 600;
    color: var(--text-color);
}

.controls-section {
    display: flex;
    gap: 15px;
    align-items: center;
    flex-wrap: wrap;
}

.format-controls {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 8px;
    background: var(--button-bg);
    border: 1px solid var(--border-color);
    border-radius: 6px;
}

.format-btn {
    background: none;
    border: none;
    padding: 6px 8px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    font-weight: bold;
    color: var(--text-color);
    transition: background 0.2s ease;
    min-width: 28px;
    text-align: center;
}

.format-btn:hover {
    background: var(--button-hover);
}

.format-btn.active {
    background: var(--border-color);
}

.color-picker {
    width: 30px;
    height: 24px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    background: var(--button-bg);
}

.font-size-picker {
    background: var(--button-bg);
    border: 1px solid var(--border-color);
    color: var(--text-color);
    padding: 4px 6px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    font-family: 'Montserrat', sans-serif;
    min-width: 60px;
    transition: background 0.2s ease;
}

.font-size-picker:hover {
    background: var(--button-hover);
}

.font-size-picker:focus {
    outline: none;
    border-color: var(--text-color);
}

.word-count {
    font-size: 14px;
    color: var(--text-color);
    opacity: 0.7;
}

.btn {
    padding: 8px 16px;
    border: 1px solid var(--border-color);
    background: var(--button-bg);
    color: var(--text-color);
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    font-family: 'Montserrat', sans-serif;
    transition: all 0.2s ease;
}

.btn:hover {
    background: var(--button-hover);
    box-shadow: 0 2px 4px var(--shadow);
}

.theme-toggle {
    background: none;
    border: none;
    font-size: 20px;
    cursor: pointer;
    padding: 8px;
    border-radius: 4px;
    transition: background 0.2s ease;
}

.theme-toggle:hover {
    background: var(--button-hover);
}

.mobile-menu-btn {
    display: none;
    background: none;
    border: none;
    font-size: 20px;
    cursor: pointer;
    padding: 8px;
    border-radius: 4px;
    color: var(--text-color);
    transition: background 0.2s ease;
}

.mobile-menu-btn:hover {
    background: var(--button-hover);
}

.editor-container {
    flex: 1;
    padding: 40px 20px;
    display: flex;
    justify-content: center;
    position: relative;
}

.editor-controls {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 20px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.editor-wrapper {
    width: 100%;
    max-width: 1000px;
    position: relative;
}

.editor {
    width: 100%;
    min-height: 500px;
    padding: 20px;
    border: none;
    outline: none;
    resize: vertical;
    font-family: 'Montserrat', sans-serif;
    font-size: 18px;
    line-height: 1.6;
    color: var(--text-color);
    background: transparent;
    border-radius: 8px;
    box-shadow: 0 2px 10px var(--shadow);
    background: var(--bg-color);
    border: 1px solid var(--border-color);
    transition: all 0.3s ease;
    overflow-y: auto;
}

.editor:focus {
    box-shadow: 0 4px 20px var(--shadow);
}

.editor:empty:before {
    /* content: "Bắt đầu viết ở đây... Nội dung sẽ được tự động lưu.\A\A💡 Mẹo:\A• Ctrl+B = in đậm\A• Ctrl+I = in nghiêng\A• Ctrl+U = gạch chân\A• Ctrl+Shift+S = gạch ngang\A• Chọn text và dùng dropdown để đổi cỡ chữ\A• Chọn text và dùng color picker để đổi màu\A• Gõ '* ' hoặc '1. ' rồi Enter để tạo list tự động"; */
    content: "Bắt đầu viết ở đây... Nội dung sẽ được tự động lưu.";
    white-space: pre-line;
    color: var(--text-color);
    opacity: 0.5;
    pointer-events: none;
}

.status-bar {
    padding: 15px 20px;
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 12px;
    color: var(--text-color);
    opacity: 0.7;
}

.auto-save-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
}

.save-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #4CAF50;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% {
        opacity: 1;
    }

    50% {
        opacity: 0.5;
    }

    100% {
        opacity: 1;
    }
}

.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    justify-content: center;
    align-items: center;
}

.modal-content {
    background: var(--bg-color);
    padding: 30px;
    border-radius: 8px;
    max-width: 400px;
    width: 90%;
    text-align: center;
    box-shadow: 0 10px 30px var(--shadow);
}

.modal-content h3 {
    margin-bottom: 15px;
    color: var(--text-color);
    font-weight: 600;
}

.modal-content p {
    margin-bottom: 20px;
    color: var(--text-color);
    opacity: 0.8;
}

.mobile-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 999;
}

.tab-title-input {
    background: transparent;
    border: none;
    outline: none;
    color: var(--text-color);
    font-size: 14px;
    font-weight: 500;
    font-family: 'Montserrat', sans-serif;
    width: 100%;
    padding: 2px 4px;
    border-radius: 3px;
}

.tab-title-input:focus {
    background: var(--bg-color);
    border: 1px solid var(--border-color);
}

/* Custom formatting styles cho editor */
.editor strong,
.editor b {
    font-weight: bold;
}

.editor em,
.editor i {
    font-style: italic;
}

.editor u {
    text-decoration: underline;
}

.editor s,
.editor strike {
    text-decoration: line-through;
}

.editor ul,
.editor ol {
    margin-left: 20px;
    margin-bottom: 10px;
}

.editor li {
    margin-bottom: 5px;
}

.editor br {
    display: block;
    margin: 5px 0;
}

/* MOBILE RESPONSIVE */
@media (max-width: 768px) {
    .sidebar-header {
        padding: 15px;
        height: auto;
    }

    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        height: 100vh;
        z-index: 1000;
        transform: translateX(-100%);
        transition: transform 0.3s ease;
        width: 280px;
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .sidebar.collapsed {
        width: 280px;
        transform: translateX(-100%);
    }

    .sidebar.collapsed.open {
        transform: translateX(0);
    }

    .mobile-menu-btn {
        display: inline-block;
    }

    .main-content {
        width: 100%;
    }

    .header {
        padding: 15px;
        height: auto;
        flex-wrap: wrap;
        gap: 10px;
    }

    .header-row {
        gap: 10px;
        flex: 1;
    }

    .header h1 {
        font-size: 18px;
    }

    .editor-controls {
        flex-direction: column;
        gap: 15px;
        align-items: center;
        margin-bottom: 15px;
    }

    .controls-section {
        gap: 8px;
        flex-wrap: wrap;
        justify-content: center;
    }

    .format-controls {
        flex-wrap: wrap;
        justify-content: center;
        gap: 6px;
    }

    .font-size-picker {
        min-width: 50px;
        font-size: 11px;
    }

    .editor {
        padding: 20px;
        font-size: 16px;
    }

    .mobile-overlay.active {
        display: block;
    }

    .sidebar.collapsed .sidebar-header {
        padding: 15px;
        height: auto;
        justify-content: flex-start;
    }

    .sidebar.collapsed .sidebar-title {
        opacity: 1;
        width: auto;
        overflow: visible;
    }

    .sidebar.collapsed .new-tab-btn {
        width: auto;
        height: auto;
        padding: 10px;
        border-radius: 6px;
    }

    .sidebar.collapsed .new-tab-btn .btn-text {
        display: inline;
    }

    .sidebar.collapsed .tabs-container {
        padding: 20px;
    }

    .sidebar.collapsed .tab-item {
        width: auto;
        height: auto;
        padding: 12px;
        justify-content: space-between;
    }

    .sidebar.collapsed .tab-title {
        display: block;
    }

    .sidebar.collapsed .tab-actions {
        display: flex;
    }

    .tab-actions {
        opacity: 1 !important;
    }

    .tab-action-btn {
        padding: 6px;
        font-size: 14px;
        border-radius: 4px;
        background: var(--button-bg);
        border: 1px solid var(--border-color);
    }

    .reset-format-btn {
        font-size: 11px;
        padding: 5px 8px;
    }
}

.reset-format-btn {
    background: var(--button-bg);
    border: 1px solid var(--border-color);
    color: var(--text-color);
    padding: 6px 10px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    font-weight: 500;
    font-family: 'Montserrat', sans-serif;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.reset-format-btn:hover {
    background: var(--button-hover);
    box-shadow: 0 2px 4px var(--shadow);
}