.toolbar {
    display: inline-flex;
    align-items: center;
    gap: 2px;
    background: #ffffff;
    border: 0.5px solid rgba(0, 0, 0, 0.12);
    border-radius: 999px;
    padding: 5px 8px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    position: fixed;
    z-index: 2147483640; /* Đủ cao để vượt extension nhưng thấp hơn modal của hệ thống */
    visibility: hidden;
    opacity: 0;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    transform: translateY(10px);
    pointer-events: none;
}

/* Chặn menu native của Safari/Chrome trên di động */
.toolbar-enabled {
    -webkit-touch-callout: none; /* Chặn menu "Copy/Lookup" của iOS */
    -webkit-user-select: text;   /* Giữ khả năng chọn văn bản */
    user-select: text;
}

.toolbar.show {
    visibility: visible;
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
}

/* Arrow at the bottom */
.toolbar::after {
    content: '';
    position: absolute;
    bottom: -6px;
    left: 50%;
    transform: translateX(-50%);
    border-left: 6px solid transparent;
    border-right: 6px solid transparent;
    border-top: 6px solid #fff;
    filter: drop-shadow(0 2px 2px rgba(0, 0, 0, 0.1));
}

.toolbar.top-to-bottom::after {
    bottom: auto;
    top: -6px;
    border-top: none;
    border-bottom: 6px solid #fff;
}

/* Ẩn mũi tên khi ở chế độ mobile bottom */
.toolbar.is-mobile::after {
    display: none;
}

.toolbar.is-mobile {
    transform: translateX(-50%) translateY(20px);
    bottom: 15px;
    top: auto !important;
    left: 50% !important;
    right: auto !important;
    margin: 0 !important;
    width: max-content;
    max-width: 90vw; /* Đảm bảo không quá rộng trên màn hình nhỏ */
    padding: 8px 12px;
}

.toolbar.is-mobile.show {
    transform: translateX(-50%) translateY(0);
}

/* Icon buttons (circle) */
.tb-btn {
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border: none;
    background: transparent;
    border-radius: 50%;
    cursor: pointer;
    color: #888;
    transition: background 0.15s, color 0.15s, transform 0.1s;
}

.tb-btn:hover {
    background: #f0eeea;
    color: #222;
}

.tb-btn:active {
    transform: scale(0.92);
}

.tb-btn.active {
    background: #1a1a1a;
    color: #fff;
}

.tb-btn:disabled,
.tb-disabled {
    opacity: 0.3;
    cursor: not-allowed;
    pointer-events: none;
}

.tb-btn svg {
    width: 18px;
    height: 18px;
}

/* Divider */
.tb-divider {
    width: 0.5px;
    height: 20px;
    background: rgba(0, 0, 0, 0.1);
    margin: 0 4px;
}

/* Pill buttons */
.tb-pill {
    display: flex;
    align-items: center;
    gap: 7px;
    height: 34px;
    padding: 0 14px;
    border: 0.5px solid transparent;
    border-radius: 999px;
    font-family: 'DM Sans', sans-serif;
    font-size: 13.5px;
    font-weight: 500;
    cursor: pointer;
    background: transparent;
    color: #888;
    transition: background 0.15s, color 0.15s, border-color 0.15s, transform 0.1s;
    letter-spacing: -0.01em;
}

.tb-pill:hover {
    background: #f0eeea;
    color: #333;
}

.tb-pill:active {
    transform: scale(0.96);
}

.tb-pill svg {
    width: 14px;
    height: 14px;
    flex-shrink: 0;
}

/* Active states */
.tb-pill.active-highlight {
    background: #FFF3CD;
    color: #7C5500;
    border-color: #F0C040;
}

.tb-pill.active-note {
    background: #E8F4FF;
    color: #0A56A0;
    border-color: #90C4F0;
}

.status {
    font-size: 12px;
    color: #aaa;
}

.tb-highlight-popup {
    position: absolute;
    top: calc(100% + 10px);
    left: 50%;
    transform: translateX(-50%);
    background: #fff;
    border: 0.5px solid rgba(0, 0, 0, 0.12);
    border-radius: 12px;
    padding: 12px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.12);
    display: none;
    flex-direction: column;
    gap: 12px;
    min-width: 200px;
    z-index: 2147483641;
}

/* Hiển thị popup lên phía trên khi ở mobile hoặc khi toolbar nằm dưới vùng chọn */
.is-mobile .tb-highlight-popup,
.toolbar.top-to-bottom .tb-highlight-popup {
    top: auto;
    bottom: calc(100% + 12px);
}

.tb-highlight-popup.show {
    display: flex;
}

.tb-highlight-popup::before {
    content: '';
    position: absolute;
    top: -6px;
    left: 50%;
    transform: translateX(-50%);
    border-left: 6px solid transparent;
    border-right: 6px solid transparent;
    border-bottom: 6px solid #fff;
}

.is-mobile .tb-highlight-popup::before,
.toolbar.top-to-bottom .tb-highlight-popup::before {
    top: auto;
    bottom: -6px;
    border-bottom: none;
    border-top: 6px solid #fff;
}

.tb-color-list {
    display: flex;
    gap: 8px;
    justify-content: center;
    align-items: center;
}

.tb-color-btn {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    border: 1px solid rgba(0, 0, 0, 0.1);
    cursor: pointer;
    transition: transform 0.1s;
    padding: 0;
}

.tb-color-btn:hover {
    transform: scale(1.2);
}

#custom-color {
    width: 28px;
    height: 28px;
    padding: 0;
    border: none;
    background: transparent;
    cursor: pointer;
}

.tb-popup-actions {
    display: flex;
    gap: 8px;
    border-top: 1px solid #eee;
    padding-top: 10px;
}

.tb-action-btn {
    flex: 1;
    padding: 6px 0;
    border-radius: 6px;
    border: none;
    font-size: 15px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s;
}

.tb-action-btn.delete {
    background: #fff0f0;
    color: #d32f2f;
}

.tb-action-btn.cancel {
    background: #f5f5f5;
    color: #666;
}

.tb-action-btn.save {
    background: #1a1a1a;
    color: #fff;
}

.tb-action-btn:hover {
    filter: brightness(0.95);
}

/* The actual highlight class */
.user-highlight {
    background-color: #fff3cd;
    border-radius: 2px;
    padding: 1px 0;
}

/* ── NOTE POPUP ── */
.tb-note-popup {
    position: absolute;
    top: calc(100% + 10px);
    left: 50%;
    transform: translateX(-50%);
    background: #fff;
    border: 0.5px solid rgba(0, 0, 0, 0.12);
    border-radius: 12px;
    padding: 12px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.12);
    display: none;
    flex-direction: column;
    gap: 12px;
    min-width: 250px;
    z-index: 2147483641;
}

.tb-note-popup.show {
    display: flex;
}

.tb-note-popup::before {
    content: '';
    position: absolute;
    top: -6px;
    left: 50%;
    transform: translateX(-50%);
    border-left: 6px solid transparent;
    border-right: 6px solid transparent;
    border-bottom: 6px solid #fff;
}

.tb-note-field {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.tb-note-field label {
    font-size: 11px;
    font-weight: 700;
    color: #888;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

#tb-note-text,
#tb-note-selected-text {
    width: 100%;
    min-height: 60px;
    padding: 8px 10px;
    border: 1px solid #eee;
    border-radius: 8px;
    font-family: inherit;
    font-size: 13px;
    resize: vertical;
    outline: none;
    background: #fff;
}

#tb-note-selected-text {
    background: #fcfcfc;
    color: #444;
}

#tb-note-text:focus,
#tb-note-selected-text:focus {
    border-color: #0A56A0;
}

/* The actual note class */
.user-note {
    border-bottom: 2px dashed #0A56A0;
    background-color: rgba(10, 86, 160, 0.1);
    cursor: help;
}

.user-note:hover {
    background-color: rgba(10, 86, 160, 0.2);
}

/* ── DICTIONARY MODAL ── */
.dictionary-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.4);
    z-index: 2147483646;
    display: none;
    backdrop-filter: blur(2px);
}

.dictionary-modal {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 90%;
    max-width: 450px;
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
    z-index: 2147483647;
    display: none;
    flex-direction: column;
    overflow: hidden;
    animation: modalFadeIn 0.3s ease-out;
}

@keyframes modalFadeIn {
    from {
        opacity: 0;
        transform: translate(-50%, -45%);
    }

    to {
        opacity: 1;
        transform: translate(-50%, -50%);
    }
}

.dictionary-modal.active,
.dictionary-modal-overlay.active,
#translateModal.active,
#translateModalOverlay.active {
    display: flex;
}

.translate-modal-footer {
    padding: 12px 20px;
    border-top: 1px solid #eee;
    background: #f8f9fa;
    display: flex;
    justify-content: center;
    gap: 10px;
}

.dictionary-modal-header {
    padding: 16px 20px;
    background: #f8f9fa;
    border-bottom: 1px solid #eee;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.dictionary-modal-icon {
    font-weight: 700;
    font-size: 16px;
    color: #1a1a1a;
}

.dictionary-modal-close {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: #888;
    line-height: 1;
}

.dictionary-modal-body {
    padding: 24px;
    max-height: 450px;
    overflow-y: auto;
}

.dictionary-word {
    font-size: 24px;
    font-weight: 800;
    color: #1a1a1a;
    margin-bottom: 4px;
    text-transform: capitalize;
}

.dictionary-phonetic {
    font-size: 16px;
    color: #0A56A0;
    margin-bottom: 16px;
    font-style: italic;
}

.dictionary-meaning {
    margin-bottom: 20px;
}

.dictionary-part-of-speech {
    display: inline-block;
    padding: 2px 8px;
    background: #eef;
    color: #0A56A0;
    border-radius: 4px;
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    margin-bottom: 8px;
}

.dictionary-definition-text {
    font-size: 15px;
    line-height: 1.5;
    color: #333;
    margin-bottom: 4px;
}

.dictionary-example {
    font-size: 14px;
    color: #666;
    font-style: italic;
    border-left: 2px solid #ddd;
    padding-left: 10px;
    margin-top: 4px;
}

.dictionary-loading {
    text-align: center;
    padding: 40px 0;
}

.spinner {
    width: 30px;
    height: 30px;
    border: 3px solid #f3f3f3;
    border-top: 3px solid #1a1a1a;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 15px;
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}