/* Floating Toolbar - Premium Creative Style */
:root {
    --toolbar-bg: #ffffff;
    --toolbar-border: #e2e8f0;
    --toolbar-shadow: 0 12px 30px -4px rgba(0, 0, 0, 0.12), 0 4px 10px -2px rgba(0, 0, 0, 0.05);
    --toolbar-text: #1e293b;
    --toolbar-text-muted: #64748b;
    --toolbar-primary: #6366f1;
    --toolbar-primary-hover: #4f46e5;
    --toolbar-primary-soft: #e0e7ff;
    --toolbar-radius: 12px;
}

/* Container */
.floating-toolbar {
    position: absolute;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--toolbar-bg);
    padding: 6px 8px;
    border-radius: var(--toolbar-radius);
    box-shadow: var(--toolbar-shadow);
    display: flex;
    align-items: center;
    gap: 6px;
    z-index: 9999;
    width: max-content;
    border: 1px solid var(--toolbar-border);
    transition: all 0.25s cubic-bezier(0.2, 0.8, 0.2, 1);
    opacity: 1;
    backdrop-filter: blur(8px);
}

.toolbar-group {
    display: flex;
    align-items: center;
    gap: 6px;
}

.toolbar-group.hidden {
    display: none !important;
}

/* Text Button (like Replace) */
.toolbar-btn-text {
    height: 36px;
    padding: 0 12px;
    border: 1px solid var(--toolbar-border);
    background: #fff;
    border-radius: 8px;
    color: var(--toolbar-text);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.9rem;
    font-weight: 500;
    transition: all 0.2s ease;
}

.toolbar-btn-text:hover {
    background: #f8fafc;
    border-color: var(--toolbar-border);
}

.floating-toolbar.hidden {
    opacity: 0;
    pointer-events: none;
    transform: translate(-50%, 15px) scale(0.98);
}

/* Sections */
.toolbar-section {
    display: flex;
    align-items: center;
    gap: 4px;
}

.toolbar-divider {
    width: 1px;
    height: 20px;
    background: var(--toolbar-border);
    margin: 0 6px;
}

/* Buttons */
.toolbar-btn {
    width: 36px;
    height: 36px;
    border: none;
    background: transparent;
    border-radius: 8px;
    color: var(--toolbar-text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    font-size: 1.2rem;
    position: relative;
    overflow: hidden;
}

/* Select Dropdown */
.custom-select-wrapper {
    position: relative;
    display: flex;
    align-items: center;
}

.toolbar-select {
    height: 36px;
    padding: 0 28px 0 12px;
    border: 1px solid var(--toolbar-border);
    background: #fff;
    border-radius: 8px;
    color: var(--toolbar-text);
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 500;
    appearance: none;
    -webkit-appearance: none;
    outline: none;
    transition: all 0.2s ease;
}

.toolbar-select:hover {
    background: #f8fafc;
    border-color: var(--toolbar-border);
}

.select-icon {
    position: absolute;
    right: 10px;
    pointer-events: none;
    color: var(--toolbar-text-muted);
    font-size: 0.9rem;
}

.toolbar-btn:hover {
    background: #f1f5f9;
    color: var(--toolbar-text);
    transform: translateY(-1px);
}

.toolbar-btn:active {
    transform: translateY(0);
}

.toolbar-btn.active {
    background: var(--toolbar-primary-soft);
    color: var(--toolbar-primary);
}

.toolbar-btn.active::after {
    content: '';
    position: absolute;
    bottom: -2px;
    width: 12px;
    height: 2px;
    background: currentColor;
    border-radius: 2px;
    opacity: 0;
    /* Hidden for now, cleaner look without dot */
}

.toolbar-btn.danger {
    color: var(--toolbar-text-muted);
}

.toolbar-btn.danger:hover {
    background: #fef2f2;
    color: #ef4444;
}

/* Font Selector */
.toolbar-select {
    height: 36px;
    padding: 0 10px;
    border: 1px solid transparent;
    border-radius: 8px;
    background: transparent;
    color: var(--toolbar-text);
    font-size: 0.95rem;
    font-weight: 500;
    cursor: pointer;
    font-family: inherit;
    max-width: 130px;
    outline: none;
    transition: all 0.2s;
}

.toolbar-select:hover {
    background: #f8fafc;
    border-color: var(--toolbar-border);
}

.toolbar-select:focus {
    border-color: var(--toolbar-primary);
    background: white;
    box-shadow: 0 0 0 2px var(--toolbar-primary-soft);
}

/* Font Size */
.toolbar-input {
    width: 42px;
    height: 36px;
    border: 1px solid transparent;
    border-radius: 8px;
    text-align: center;
    background: transparent;
    color: var(--toolbar-text);
    font-size: 0.95rem;
    font-weight: 600;
    transition: all 0.2s;
    -moz-appearance: textfield;
}

.toolbar-input:hover {
    background: #f8fafc;
    border-color: var(--toolbar-border);
}

.toolbar-input:focus {
    background: white;
    border-color: var(--toolbar-primary);
    box-shadow: 0 0 0 2px var(--toolbar-primary-soft);
    outline: none;
}

.toolbar-input::-webkit-outer-spin-button,
.toolbar-input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

/* Color Picker */
.color-picker-wrapper {
    position: relative;
    width: 32px;
    height: 32px;
    border-radius: 8px;
    cursor: pointer;
    overflow: hidden;
    border: 2px solid white;
    box-shadow: 0 0 0 1px var(--toolbar-border);
    transition: all 0.2s;
}

.color-picker-wrapper:hover {
    transform: scale(1.05);
    box-shadow: 0 0 0 1px var(--toolbar-primary);
}

.toolbar-color {
    /* Hidden logic that allows programmtic click */
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    z-index: -1;
    pointer-events: none;
    margin: 0;
    padding: 0;
}

.color-preview {
    width: 100%;
    height: 100%;
    background-color: #000;
    border-radius: 6px;
    /* slightly smaller radius inner */
}

/* Icons Overrides */
i.ph {
    font-size: 1.1em;
    display: inline-block;
    vertical-align: middle;
}

/* Mobile Responsiveness */
@media (max-width: 768px) {
    .floating-toolbar {
        flex-wrap: wrap;
        justify-content: center;
        width: 90%;
        border-radius: 16px;
        padding: 8px;
    }

    .toolbar-divider {
        display: none;
    }

    .toolbar-section {
        margin: 2px 0;
    }
}

/* Custom Font Select Styles */
.custom-font-select {
    position: relative;
    width: 140px;
    height: 36px;
}

.font-select-trigger {
    height: 100%;
    width: 100%;
    padding: 0 10px;
    border: 1px solid transparent;
    border-radius: 8px;
    background: transparent;
    color: var(--toolbar-text);
    font-size: 0.95rem;
    font-weight: 500;
    cursor: pointer;
    font-family: inherit;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    white-space: nowrap;
    transition: all 0.2s;
}

.font-select-trigger:hover {
    background: #f8fafc;
    border-color: var(--toolbar-border);
}

.font-select-trigger span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 90px;
    display: inline-block;
}

/* Dropdown Container */
/* Dropdown Container */
.font-dropdown {
    position: absolute;
    /* Stick to parent */
    top: calc(100% + 8px);
    /* Below the button + gap */
    left: 0;
    background: #ffffff;
    /* Force white background */
    border: 1px solid var(--toolbar-border);
    border-radius: 12px;
    box-shadow: 0 16px 40px -5px rgba(0, 0, 0, 0.15);
    width: 280px;
    max-height: 350px;
    display: flex;
    flex-direction: column;
    z-index: 20000;
    /* Extremely high z-index */
    overflow: hidden;
    animation: dropdownFadeIn 0.2s cubic-bezier(0.16, 1, 0.3, 1);
    color: #1e293b;
    /* Force dark text color */
}

/* Ensure hidden state works */
.font-dropdown.hidden {
    display: none !important;
    /* Force hide */
}

@keyframes dropdownFadeIn {
    from {
        opacity: 0;
        transform: translateY(-5px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Search Bar */
.font-search-container {
    padding: 10px 12px;
    border-bottom: 1px solid var(--toolbar-border);
    display: flex;
    align-items: center;
    gap: 8px;
    background: #f8fafc;
    /* Slight gray for search area */
}

.font-search-container i {
    color: #64748b;
    /* Muted slate */
    font-size: 1rem;
}

#font-search-input {
    width: 100%;
    border: none;
    outline: none;
    background: transparent;
    font-size: 0.95rem;
    color: #1e293b;
    padding: 0;
    height: auto;
}

#font-search-input::placeholder {
    color: #94a3b8;
}

/* Font Options List */
.font-options {
    flex: 1;
    overflow-y: auto;
    padding: 4px;
    display: flex;
    flex-direction: column;
    gap: 1px;
    background: #ffffff;
}

.font-option {
    padding: 8px 12px;
    cursor: pointer;
    border-radius: 6px;
    color: #1e293b;
    /* Ensure readability */
    font-size: 1.05rem;
    display: flex;
    align-items: center;
    transition: background 0.1s;
    background: transparent;
}

.font-option:hover {
    background: #f1f5f9;
}

.font-option.selected {
    background: #e0e7ff;
    /* Primary soft */
    color: #4f46e5;
    /* Primary */
}

/* Scrollbar for font list */
.font-options::-webkit-scrollbar {
    width: 6px;
}

.font-options::-webkit-scrollbar-track {
    background: transparent;
}

.font-options::-webkit-scrollbar-thumb {
    background-color: #cbd5e1;
    border-radius: 10px;
}