#toolbar {
    position: absolute; padding: 8px; border-radius: 14px; z-index: 90; width: auto;
    max-height: 70vh; overflow-y: scroll; overflow-x: hidden;
    -webkit-overflow-scrolling: touch; touch-action: pan-y pan-x;
    scrollbar-width: none; -ms-overflow-style: none;
    transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}
#toolbar::-webkit-scrollbar { width: 0; height: 0; background: transparent; }

/* --- Toolbar buttons (icon + label) --- */
.tool-opt {
    padding: 12px 8px; border-radius: 12px; color: var(--text);
    cursor: pointer; transition: background 0.15s ease, transform 0.1s ease, box-shadow 0.15s ease;
    display: flex; flex-direction: column; align-items: center; gap: 4px;
    opacity: 0.55; width: 60px; flex-shrink: 0;
    position: relative; overflow: hidden;
}
.tool-opt:hover { opacity: 0.85; background: rgba(255,255,255,0.15); }
.tool-opt:active { transform: scale(0.92); }
.tool-opt.selected {
    opacity: 1; color: var(--primary);
    background: rgba(255,255,255,0.55);
    box-shadow: 0 4px 12px rgba(0,0,0,0.08), inset 0 1px 0 rgba(255,255,255,0.8);
    border: 1px solid rgba(255,255,255,0.5);
    backdrop-filter: blur(10px);
}
.tool-opt.disabled { opacity: 0.25; cursor: not-allowed; filter: grayscale(100%); }
.tool-icon { display: flex; align-items: center; justify-content: center; }
.tool-label { font-size: 0.65rem; font-weight: 700; line-height: 1; white-space: nowrap; }

/* --- Gear button to open tool manager --- */
.tool-manager-btn {
    width: 60px; height: 60px; border-radius: 12px;
    display: flex; align-items: center; justify-content: center;
    background: rgba(255,255,255,0.15); color: var(--text);
    border: 1px solid rgba(255,255,255,0.2); cursor: pointer;
    margin: 8px auto 0 auto; flex-shrink: 0;
    transition: background 0.15s ease, transform 0.1s ease;
    opacity: 0.5; outline: none;
}
.tool-manager-btn:hover { opacity: 0.8; background: rgba(255,255,255,0.25); border-color: var(--primary); color: var(--primary); }
.tool-manager-btn:focus { outline: none; }
.tool-manager-btn:active { transform: scale(0.92); }

/* ============================================
   Tool Manager Modal (new design)
   ============================================ */

/* --- Search bar --- */
.tm-search-wrap {
    position: relative; margin-bottom: 14px;
}
.tm-search {
    width: 100%; padding: 10px 14px 10px 36px; border-radius: 14px;
    border: 1px solid var(--border); background: rgba(255,255,255,0.4);
    font-size: 0.85rem; font-weight: 500; color: var(--text);
    outline: none; transition: border-color 0.15s;
    font-family: inherit;
}
.tm-search:focus { border-color: var(--primary); }
.tm-search::placeholder { opacity: 0.4; }
.tm-search-icon {
    position: absolute; left: 12px; top: 50%; transform: translateY(-50%);
    opacity: 0.35; pointer-events: none; display: flex; align-items: center;
}

/* --- Active count badge --- */
.tm-count {
    display: inline-block; font-size: 0.7rem; font-weight: 700;
    color: var(--primary); background: rgba(0,122,255,0.08);
    padding: 4px 10px; border-radius: 8px; margin-bottom: 14px;
}

/* --- Tool list --- */
.tool-manager-list {
    display: flex; flex-direction: column; gap: 4px;
    margin: 0; max-height: 55vh; overflow-y: scroll;
    overscroll-behavior: contain; -webkit-overflow-scrolling: touch;
    padding-right: 4px; scrollbar-width: none; -ms-overflow-style: none;
}
.tool-manager-list::-webkit-scrollbar { width: 0; height: 0; background: transparent; }

/* --- Group header --- */
.tm-group-header {
    display: flex; align-items: center; gap: 8px;
    padding: 14px 6px 6px 6px; font-size: 0.65rem; font-weight: 800;
    text-transform: uppercase; letter-spacing: 1px; opacity: 0.5;
}
.tm-group-dot { width: 6px; height: 6px; border-radius: 50%; flex-shrink: 0; }
.tm-group-title { flex: 1; }
.tm-group-count {
    font-size: 0.6rem; font-weight: 600; opacity: 0.6;
    background: rgba(0,0,0,0.06); padding: 2px 6px; border-radius: 6px;
}

/* --- Tool row --- */
.tm-row {
    display: flex; align-items: center; gap: 12px;
    padding: 14px 16px; border-radius: 10px; border: 1.5px solid transparent;
    background: rgba(255,255,255,0.35); transition: all 0.2s ease;
    cursor: default; user-select: none;
}
.tm-row:hover { background: rgba(255,255,255,0.55); }
.tm-row.active { border-color: var(--primary); background: rgba(0,122,255,0.04); }
.tm-row.dragging { opacity: 0.4; transform: scale(0.97); box-shadow: 0 8px 24px rgba(0,0,0,0.15); }

/* Drag handle */
.tm-drag {
    opacity: 0.2; cursor: grab; user-select: none; flex-shrink: 0;
    display: flex; align-items: center; transition: opacity 0.15s;
}
.tm-row:hover .tm-drag { opacity: 0.45; }
.tm-row.dragging .tm-drag { cursor: grabbing; }

/* Tool icon */
.tm-icon-wrap {
    width: 42px; height: 42px; border-radius: 12px;
    display: flex; align-items: center; justify-content: center;
    background: rgba(255,255,255,0.5); border: 1px solid var(--border);
    flex-shrink: 0; transition: background 0.15s;
}
.tm-row.active .tm-icon-wrap { background: rgba(0,122,255,0.1); border-color: rgba(0,122,255,0.2); }

/* Tool info */
.tm-info { display: flex; flex-direction: column; gap: 2px; min-width: 0; flex: 1; }
.tm-label { font-size: 0.95rem; font-weight: 700; color: var(--text); }
.tm-desc { font-size: 0.78rem; font-weight: 500; opacity: 0.45; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* --- Toggle switch --- */
.tm-toggle {
    position: relative; width: 48px; height: 28px; flex-shrink: 0; cursor: pointer;
}
.tm-toggle input { opacity: 0; width: 0; height: 0; position: absolute; }
.tm-track {
    position: absolute; inset: 0; border-radius: 14px;
    background: rgba(0,0,0,0.12); transition: background 0.2s ease;
}
.tm-track::after {
    content: ''; position: absolute; left: 3px; top: 3px;
    width: 22px; height: 22px; border-radius: 50%;
    background: white; box-shadow: 0 2px 6px rgba(0,0,0,0.15);
    transition: transform 0.2s ease;
}
.tm-toggle input:checked + .tm-track { background: var(--primary); }
.tm-toggle input:checked + .tm-track::after { transform: translateX(20px); }

/* --- Help text --- */
.tool-manager-help {
    font-size: 0.72rem; opacity: 0.45; margin-bottom: 10px;
    color: var(--text); text-align: left; line-height: 1.5;
}
