/**
 * toolbar.css
 * ──────────────────────────────────────────────────────────────────────
 * Floating formatting toolbar — all styles.
 * Position variants: toolbar-bottom (default), toolbar-top, toolbar-left, toolbar-right
 *
 * Key rule: dropdowns are position:fixed and appear DIRECTLY ADJACENT to
 * their trigger button — never far away, never off-screen.
 * ──────────────────────────────────────────────────────────────────────
 */

/* ── Base container ──────────────────────────────────────────────────── */
.floating-toolbar {
    position: absolute;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 5px 7px;
    display: flex;
    align-items: center;
    gap: 2px;
    box-shadow:
        0 4px 24px rgba(0,0,0,0.14),
        0 1px 4px rgba(0,0,0,0.08),
        inset 0 1px 0 rgba(255,255,255,0.06);
    z-index: 40;
    transition: opacity 0.18s, transform 0.18s;
    flex-wrap: nowrap;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}

.floating-toolbar.hidden {
    opacity: 0;
    pointer-events: none;
    transform: translateY(4px);
}

/* ── Position variants ───────────────────────────────────────────────── */
.floating-toolbar.toolbar-bottom {
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
}
.floating-toolbar.toolbar-bottom.hidden {
    transform: translateX(-50%) translateY(4px);
}

.floating-toolbar.toolbar-top {
    top: 60px;
    left: 50%;
    transform: translateX(-50%);
}
.floating-toolbar.toolbar-top.hidden {
    transform: translateX(-50%) translateY(-4px);
}

.floating-toolbar.toolbar-left {
    top: 50%;
    left: 16px;
    transform: translateY(-50%);
    flex-direction: column;
    padding: 7px 5px;
}
.floating-toolbar.toolbar-left.hidden {
    transform: translateY(-50%) translateX(-4px);
}

.floating-toolbar.toolbar-right {
    top: 50%;
    right: 16px;
    transform: translateY(-50%);
    flex-direction: column;
    padding: 7px 5px;
}
.floating-toolbar.toolbar-right.hidden {
    transform: translateY(-50%) translateX(4px);
}

/* ── Toolbar buttons ─────────────────────────────────────────────────── */
.toolbar-btn {
    min-width: 30px;
    height: 30px;
    border-radius: 7px;
    border: 1px solid transparent;
    background: transparent;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    transition: background 0.12s, color 0.12s, border-color 0.12s, transform 0.1s;
    font-family: 'Nunito', sans-serif;
    padding: 0 6px;
    white-space: nowrap;
    flex-shrink: 0;
}

.toolbar-btn:hover {
    background: var(--hover);
    color: var(--text);
    transform: scale(1.06);
}

/* Active: accent fill */
.toolbar-btn.active {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}

/* Vertical layout */
.toolbar-left .toolbar-btn,
.toolbar-right .toolbar-btn {
    width: 32px;
    min-width: 32px;
    padding: 0;
}

/* Dividers */
.tb-divider {
    width: 1px;
    height: 18px;
    background: var(--border);
    margin: 0 2px;
    flex-shrink: 0;
    opacity: 0.6;
}
.toolbar-left .tb-divider,
.toolbar-right .tb-divider {
    width: 18px;
    height: 1px;
    margin: 2px 0;
}

/* ── Dropdowns ───────────────────────────────────────────────────────── */
/*
 * Dropdowns are position:fixed and positioned by ToolbarWorker._positionDropdown()
 * which runs after two rAF frames so layout is complete.
 * They open ADJACENT to their trigger button, never far away.
 */
.toolbar-dropdown {
    position: fixed;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 10px;
    box-shadow:
        0 8px 28px rgba(0,0,0,0.16),
        0 2px 6px rgba(0,0,0,0.08);
    padding: 5px;
    z-index: 10000;
    display: flex;
    flex-direction: column;
    gap: 1px;
    min-width: 160px;
    max-height: 320px;
    overflow-y: auto;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    animation: tbDropIn 0.14s cubic-bezier(0.34,1.4,0.64,1);
}

.toolbar-dropdown.hidden {
    display: none !important;
}

@keyframes tbDropIn {
    from { opacity: 0; transform: scale(0.92) translateY(-4px); }
    to   { opacity: 1; transform: scale(1)    translateY(0);    }
}

/* Dropdown items */
.td-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 7px 10px;
    border-radius: 7px;
    cursor: pointer;
    font-family: 'Nunito', sans-serif;
    font-size: 13px;
    color: var(--text);
    transition: background 0.1s, color 0.1s;
    white-space: nowrap;
    flex-shrink: 0;
}
.td-item:hover       { background: var(--hover); }
.td-item.active      { color: var(--accent); }
.td-item.td-muted    { opacity: 0.45; pointer-events: none; }
.td-item-icon        { font-size: 15px; width: 20px; text-align: center; flex-shrink: 0; }
.td-item-label       { font-weight: 600; }
.td-item-hint        { font-size: 11px; color: var(--text-secondary); margin-left: auto; }
.td-separator        { height: 1px; background: var(--border); margin: 3px 0; opacity: 0.5; }

/* Color swatches grid */
.td-colors {
    display: grid;
    grid-template-columns: repeat(6, 24px);
    gap: 4px;
    padding: 4px 2px;
}
.td-color {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    border: 2px solid transparent;
    cursor: pointer;
    transition: transform 0.1s, border-color 0.1s;
}
.td-color:hover { transform: scale(1.2); border-color: var(--border); }

/* ── Position toggle grid ────────────────────────────────────────────── */
.toolbar-position-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 4px;
    padding: 2px;
}
.toolbar-pos-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 7px 8px;
    border: 1px solid var(--border);
    border-radius: 7px;
    cursor: pointer;
    font-family: 'Nunito', sans-serif;
    font-size: 12px;
    color: var(--text-secondary);
    background: transparent;
    transition: all 0.12s;
    white-space: nowrap;
}
.toolbar-pos-btn:hover  { border-color: var(--accent); color: var(--text); }
.toolbar-pos-btn.active { border-color: var(--accent); background: var(--hover); color: var(--accent); }


/* ── Prevent toolbar from stealing focus on click ─────────────────── */
/* JS (ToolbarWorker) calls _saveSelection() on mousedown.
   CSS cannot prevent focus steal but we mark the toolbar as non-focusable hint. */
.toolbar-btn { -webkit-user-select: none; user-select: none; }

/* ── Align button active state ────────────────────────────────────── */
.toolbar-btn[data-action="align"].active { background: var(--accent); color: #fff; }

/* ── Ribbon swatch active state ───────────────────────────────────── */
.td-color.active { transform: scale(1.2); box-shadow: 0 0 0 2px var(--accent); }