:root {
    --toolbox-accent: #ed1c24;
    --toolbox-accent-dark: #b70404;
    --toolbox-blue: #1f6feb;
    --toolbox-surface: rgba(18, 20, 25, 0.97);
    --toolbox-surface-raised: rgba(31, 35, 43, 0.98);
    --toolbox-surface-soft: rgba(255, 255, 255, 0.06);
    --toolbox-border: rgba(255, 255, 255, 0.12);
    --toolbox-border-soft: rgba(255, 255, 255, 0.07);
    --toolbox-text: #f5f7fa;
    --toolbox-text-secondary: #aeb7c4;
    --toolbox-text-muted: #7c8795;
    --toolbox-shadow: 0 18px 50px rgba(0, 0, 0, 0.42), 0 3px 12px rgba(0, 0, 0, 0.24);
}

html:not(.dark) {
    --toolbox-surface: rgba(255, 255, 255, 0.98);
    --toolbox-surface-raised: #f7f8fa;
    --toolbox-surface-soft: rgba(15, 23, 42, 0.055);
    --toolbox-border: rgba(15, 23, 42, 0.13);
    --toolbox-border-soft: rgba(15, 23, 42, 0.08);
    --toolbox-text: #202938;
    --toolbox-text-secondary: #596673;
    --toolbox-text-muted: #7d8c9b;
    --toolbox-shadow: 0 18px 45px rgba(15, 23, 42, 0.18), 0 3px 12px rgba(15, 23, 42, 0.08);
}

.toolbox-shell {
    position: fixed;
    inset: 0;
    z-index: 10010;
    pointer-events: none;
    font-family: 'Inter', 'Segoe UI', sans-serif;
    color: var(--toolbox-text);
}

.toolbox-shell > * {
    pointer-events: auto;
}

.global-toolbox-btn {
    position: fixed;
    right: 18px;
    bottom: 18px;
    width: 52px;
    height: 52px;
    border: 1px solid rgba(255, 255, 255, 0.24);
    border-radius: 16px;
    background: linear-gradient(145deg, #f13b42, var(--toolbox-accent-dark));
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    cursor: pointer;
    box-shadow: 0 10px 24px rgba(237, 28, 36, 0.32), inset 0 1px 0 rgba(255, 255, 255, 0.35);
    transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
}

.global-toolbox-btn:hover {
    transform: translateY(-3px) scale(1.03);
    border-color: rgba(255, 255, 255, 0.5);
    box-shadow: 0 14px 30px rgba(237, 28, 36, 0.42), inset 0 1px 0 rgba(255, 255, 255, 0.45);
}

.global-toolbox-btn:active {
    transform: translateY(0) scale(0.98);
}

.global-toolbox-btn:focus-visible,
.toolbox-menu button:focus-visible,
.toolbox-window button:focus-visible,
.toolbox-window textarea:focus-visible,
.toolbox-taskbar-item:focus-visible {
    outline: 2px solid var(--toolbox-accent);
    outline-offset: 2px;
}

.toolbox-launcher-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    min-width: 19px;
    height: 19px;
    padding: 0 5px;
    border: 2px solid var(--toolbox-surface);
    border-radius: 999px;
    background: #fff;
    color: var(--toolbox-accent-dark);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.65rem;
    font-weight: 800;
}

.toolbox-menu {
    position: fixed;
    right: 18px;
    bottom: 82px;
    width: min(360px, calc(100vw - 24px));
    max-height: calc(100dvh - 104px);
    overflow-y: auto;
    padding: 16px;
    border: 1px solid var(--toolbox-border);
    border-radius: 18px;
    background: var(--toolbox-surface);
    box-shadow: var(--toolbox-shadow);
    -webkit-backdrop-filter: blur(24px);
    backdrop-filter: blur(24px);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transform: translateY(10px) scale(0.96);
    transform-origin: bottom right;
    transition: opacity 0.2s ease, visibility 0.2s ease, transform 0.2s ease;
}

.toolbox-menu.open {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transform: translateY(0) scale(1);
}

.toolbox-menu-header,
.toolbox-window-header,
.toolbox-menu-footer,
.toolbox-window-actions,
.toolbox-note-footer {
    display: flex;
    align-items: center;
}

.toolbox-menu-header {
    justify-content: space-between;
    gap: 12px;
    padding-bottom: 13px;
    border-bottom: 1px solid var(--toolbox-border-soft);
}

.toolbox-eyebrow {
    display: block;
    margin-bottom: 3px;
    color: var(--toolbox-text-muted);
    font-size: 0.62rem;
    font-weight: 700;
    letter-spacing: 0.14em;
    text-transform: uppercase;
}

.toolbox-menu h2 {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 0;
    color: var(--toolbox-text);
    font-size: 1.03rem;
    font-weight: 800;
    letter-spacing: -0.02em;
}

.toolbox-menu h2 i {
    color: var(--toolbox-accent);
}

.toolbox-menu-desc {
    margin: 13px 0 15px;
    color: var(--toolbox-text-secondary);
    font-size: 0.76rem;
    line-height: 1.5;
}

.toolbox-icon-button,
.toolbox-window-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    border: 1px solid transparent;
    background: transparent;
    color: var(--toolbox-text-muted);
    cursor: pointer;
    transition: color 0.18s ease, background 0.18s ease, border-color 0.18s ease;
}

.toolbox-icon-button {
    width: 30px;
    height: 30px;
    border-radius: 9px;
}

.toolbox-icon-button:hover,
.toolbox-window-button:hover {
    background: var(--toolbox-surface-soft);
    border-color: var(--toolbox-border-soft);
    color: var(--toolbox-text);
}

.toolbox-tool-grid {
    display: grid;
    gap: 8px;
}

.toolbox-tool-card {
    width: 100%;
    min-height: 62px;
    padding: 10px;
    display: flex;
    align-items: center;
    gap: 10px;
    border: 1px solid var(--toolbox-border-soft);
    border-radius: 13px;
    background: var(--toolbox-surface-raised);
    color: var(--toolbox-text);
    text-align: left;
    cursor: pointer;
    transition: transform 0.18s ease, border-color 0.18s ease, background 0.18s ease, box-shadow 0.18s ease;
}

.toolbox-tool-card:hover {
    transform: translateY(-2px);
    border-color: rgba(237, 28, 36, 0.42);
    background: var(--toolbox-surface-soft);
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.1);
}

.toolbox-tool-card:disabled {
    opacity: 0.48;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.toolbox-tool-icon {
    width: 36px;
    height: 36px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    border-radius: 11px;
    background: rgba(237, 28, 36, 0.12);
    color: var(--toolbox-accent);
    font-size: 0.95rem;
}

.toolbox-tool-card-note .toolbox-tool-icon {
    background: rgba(212, 168, 83, 0.16);
    color: #c08c24;
}

.toolbox-tool-card-ocr .toolbox-tool-icon {
    background: rgba(31, 111, 235, 0.14);
    color: var(--toolbox-blue);
}

.toolbox-tool-copy {
    min-width: 0;
    display: flex;
    flex: 1;
    flex-direction: column;
    gap: 3px;
}

.toolbox-tool-copy strong {
    font-size: 0.79rem;
    font-weight: 750;
}

.toolbox-tool-copy small {
    overflow: hidden;
    color: var(--toolbox-text-muted);
    font-size: 0.68rem;
    line-height: 1.25;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.toolbox-tool-arrow {
    color: var(--toolbox-text-muted);
    font-size: 0.68rem;
    transition: transform 0.18s ease, color 0.18s ease;
}

.toolbox-tool-card:hover .toolbox-tool-arrow {
    color: var(--toolbox-accent);
    transform: translateX(3px);
}

.toolbox-menu-footer {
    justify-content: space-between;
    gap: 8px;
    margin-top: 14px;
    padding-top: 12px;
    border-top: 1px solid var(--toolbox-border-soft);
    color: var(--toolbox-text-muted);
    font-size: 0.65rem;
}

.toolbox-menu-footer span {
    display: inline-flex;
    align-items: center;
    gap: 5px;
}

.toolbox-menu-footer i {
    color: var(--toolbox-accent);
}

.toolbox-local-badge i {
    color: #2eae68 !important;
}

.toolbox-taskbar {
    position: fixed;
    right: 82px;
    bottom: 18px;
    max-width: calc(100vw - 170px);
    padding: 5px;
    display: flex;
    align-items: center;
    gap: 5px;
    overflow-x: auto;
    border: 1px solid var(--toolbox-border);
    border-radius: 12px;
    background: var(--toolbox-surface);
    box-shadow: 0 8px 22px rgba(0, 0, 0, 0.18);
    -webkit-backdrop-filter: blur(18px);
    backdrop-filter: blur(18px);
}

.toolbox-taskbar-item {
    min-height: 32px;
    padding: 0 10px;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    flex: 0 0 auto;
    border: 1px solid transparent;
    border-radius: 8px;
    background: transparent;
    color: var(--toolbox-text-secondary);
    font-size: 0.68rem;
    font-weight: 650;
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.18s ease, color 0.18s ease, border-color 0.18s ease;
}

.toolbox-taskbar-item:hover {
    border-color: var(--toolbox-border-soft);
    background: var(--toolbox-surface-soft);
    color: var(--toolbox-text);
}

.toolbox-taskbar-item i {
    color: var(--toolbox-accent);
}

.toolbox-taskbar-ocr i {
    color: var(--toolbox-blue);
}

.toolbox-window {
    position: fixed;
    width: 360px;
    height: 300px;
    min-width: 260px;
    min-height: 190px;
    max-width: calc(100vw - 20px);
    max-height: calc(100dvh - 72px);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border: 1px solid var(--toolbox-border);
    border-radius: 14px;
    background: var(--toolbox-surface);
    box-shadow: var(--toolbox-shadow);
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
    contain: layout paint;
    isolation: isolate;
    resize: both;
    animation: toolbox-window-in 0.2s ease-out;
}

.toolbox-window-note {
    width: 330px;
    height: 250px;
}

.toolbox-window-ocr {
    width: 370px;
    height: 310px;
}

@keyframes toolbox-window-in {
    from {
        opacity: 0;
        transform: translateY(8px) scale(0.97);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.toolbox-window-header {
    justify-content: space-between;
    gap: 10px;
    min-height: 51px;
    padding: 8px 9px 8px 11px;
    flex: 0 0 auto;
    border-bottom: 1px solid var(--toolbox-border-soft);
    background: linear-gradient(180deg, var(--toolbox-surface-raised), transparent);
    cursor: grab;
    touch-action: none;
    user-select: none;
}

.toolbox-window-header:active {
    cursor: grabbing;
}

.toolbox-window-heading {
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 9px;
}

.toolbox-window-heading > div {
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.toolbox-window-heading strong {
    overflow: hidden;
    color: var(--toolbox-text);
    font-size: 0.77rem;
    font-weight: 750;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.toolbox-window-heading small {
    color: var(--toolbox-text-muted);
    font-size: 0.61rem;
}

.toolbox-window-icon {
    width: 29px;
    height: 29px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    border-radius: 9px;
    background: rgba(237, 28, 36, 0.13);
    color: var(--toolbox-accent);
    font-size: 0.78rem;
}

.toolbox-window-icon-ocr {
    background: rgba(31, 111, 235, 0.14);
    color: var(--toolbox-blue);
}

.toolbox-window-controls {
    display: flex;
    align-items: center;
    gap: 3px;
}

.toolbox-window-button {
    width: 27px;
    height: 27px;
    border-radius: 8px;
    font-size: 0.68rem;
}

.toolbox-window-button-close:hover {
    background: rgba(237, 28, 36, 0.14);
    border-color: rgba(237, 28, 36, 0.25);
    color: var(--toolbox-accent);
}

.toolbox-capture-body,
.toolbox-note-body,
.toolbox-ocr-body {
    min-height: 0;
    display: flex;
    flex: 1 1 auto;
    flex-direction: column;
}

.toolbox-capture-preview {
    min-height: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 1 1 auto;
    padding: 10px;
    overflow: hidden;
    background: #e9edf2;
    background-image: linear-gradient(45deg, rgba(0, 0, 0, 0.04) 25%, transparent 25%), linear-gradient(-45deg, rgba(0, 0, 0, 0.04) 25%, transparent 25%), linear-gradient(45deg, transparent 75%, rgba(0, 0, 0, 0.04) 75%), linear-gradient(-45deg, transparent 75%, rgba(0, 0, 0, 0.04) 75%);
    background-position: 0 0, 0 7px, 7px -7px, -7px 0;
    background-size: 14px 14px;
}

.toolbox-capture-preview img {
    display: block;
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    border: 1px solid rgba(15, 23, 42, 0.16);
    box-shadow: 0 5px 16px rgba(15, 23, 42, 0.18);
}

.toolbox-window-actions {
    flex: 0 0 auto;
    flex-wrap: wrap;
    gap: 6px;
    padding: 8px;
    border-top: 1px solid var(--toolbox-border-soft);
}

.toolbox-action-button {
    min-height: 29px;
    padding: 0 9px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    border: 1px solid var(--toolbox-border-soft);
    border-radius: 8px;
    background: var(--toolbox-surface-soft);
    color: var(--toolbox-text-secondary);
    font-size: 0.66rem;
    font-weight: 700;
    cursor: pointer;
    transition: background 0.18s ease, border-color 0.18s ease, color 0.18s ease, transform 0.18s ease;
}

.toolbox-action-button:hover:not(:disabled) {
    border-color: rgba(237, 28, 36, 0.35);
    color: var(--toolbox-text);
    transform: translateY(-1px);
}

.toolbox-action-button-primary {
    margin-left: auto;
    border-color: rgba(237, 28, 36, 0.35);
    background: rgba(237, 28, 36, 0.12);
    color: var(--toolbox-accent);
}

.toolbox-action-button:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.toolbox-note-body {
    background: #fff4ad;
}

.toolbox-note-editor,
.toolbox-ocr-editor {
    width: 100%;
    min-height: 0;
    flex: 1 1 auto;
    padding: 16px;
    border: 0;
    outline: 0;
    color: #30343a;
    font: 500 0.88rem/1.55 'Segoe UI', sans-serif;
    resize: none;
}

.toolbox-note-editor {
    background: #fff4ad;
}

.toolbox-note-editor::placeholder {
    color: rgba(48, 52, 58, 0.48);
}

.toolbox-note-footer {
    justify-content: flex-end;
    min-height: 28px;
    padding: 0 10px;
    color: rgba(48, 52, 58, 0.5);
    font-size: 0.6rem;
}

.toolbox-note-footer span {
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.toolbox-ocr-body {
    background: var(--toolbox-surface-raised);
}

.toolbox-ocr-editor {
    background: transparent;
    color: var(--toolbox-text);
}

.toolbox-ocr-editor::placeholder {
    color: var(--toolbox-text-muted);
}

.toolbox-ocr-actions {
    justify-content: flex-end;
}

.toolbox-ocr-loading {
    min-height: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 1;
    flex-direction: column;
    gap: 8px;
    padding: 20px;
    text-align: center;
}

.toolbox-ocr-loading strong {
    font-size: 0.77rem;
}

.toolbox-ocr-loading small {
    max-width: 230px;
    color: var(--toolbox-text-muted);
    font-size: 0.65rem;
    line-height: 1.4;
}

.toolbox-spinner {
    width: 27px;
    height: 27px;
    border: 3px solid rgba(31, 111, 235, 0.18);
    border-top-color: var(--toolbox-blue);
    border-radius: 50%;
    animation: toolbox-spin 0.8s linear infinite;
}

@keyframes toolbox-spin {
    to {
        transform: rotate(360deg);
    }
}

.toolbox-notice {
    position: fixed;
    right: 18px;
    bottom: 82px;
    max-width: min(300px, calc(100vw - 24px));
    min-height: 36px;
    padding: 8px 12px;
    display: flex;
    align-items: center;
    gap: 8px;
    border: 1px solid rgba(46, 174, 104, 0.34);
    border-radius: 10px;
    background: var(--toolbox-surface);
    box-shadow: 0 8px 22px rgba(0, 0, 0, 0.2);
    color: var(--toolbox-text-secondary);
    font-size: 0.69rem;
    animation: toolbox-notice-in 0.18s ease-out;
}

.toolbox-notice i {
    color: #2eae68;
}

@keyframes toolbox-notice-in {
    from {
        opacity: 0;
        transform: translateY(5px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

body.toolbox-is-selecting {
    cursor: crosshair !important;
    user-select: none !important;
}

.toolbox-selection-overlay {
    position: fixed;
    inset: 0;
    z-index: 100000;
    overflow: visible;
    cursor: crosshair;
    touch-action: none;
    overscroll-behavior: none;
}

.toolbox-selection-preview-viewport {
    position: absolute;
    inset: 0;
    z-index: 0;
    overflow: hidden;
    background: #11141b;
    pointer-events: none;
}

.toolbox-selection-preview {
    position: absolute;
    top: 0;
    left: 0;
    display: block;
    max-width: none;
    transform-origin: 0 0;
    pointer-events: none;
    user-select: none;
}

.toolbox-selection-help {
    position: absolute;
    top: 18px;
    left: 50%;
    padding: 8px 13px;
    border: 1px solid rgba(255, 255, 255, 0.18);
    border-radius: 999px;
    background: rgba(17, 20, 27, 0.88);
    color: #fff;
    font: 600 0.72rem/1.2 'Inter', 'Segoe UI', sans-serif;
    letter-spacing: 0.01em;
    pointer-events: none;
    transform: translateX(-50%);
    box-shadow: 0 7px 20px rgba(0, 0, 0, 0.25);
    z-index: 3;
}

.toolbox-selection-dimmer {
    position: absolute;
    z-index: 1;
    background: rgba(0, 0, 0, 0.56);
    pointer-events: auto;
}

.toolbox-selection-zoom-label {
    position: absolute;
    top: 18px;
    right: 18px;
    z-index: 3;
    padding: 7px 10px;
    border: 1px solid rgba(255, 255, 255, 0.18);
    border-radius: 7px;
    background: rgba(17, 20, 27, 0.88);
    color: #fff;
    font: 700 0.7rem/1 'Inter', 'Segoe UI', sans-serif;
    pointer-events: none;
    box-shadow: 0 7px 20px rgba(0, 0, 0, 0.25);
}

.toolbox-selection-box {
    position: absolute;
    display: none;
    z-index: 2;
    border: 2px solid #fff;
    outline: 1px solid var(--toolbox-accent);
    background: rgba(255, 255, 255, 0.05);
    box-shadow: 0 0 20px rgba(237, 28, 36, 0.42);
}

.toolbox-selection-box::before,
.toolbox-selection-box::after {
    content: '';
    position: absolute;
    width: 8px;
    height: 8px;
    border: 2px solid #fff;
    background: var(--toolbox-accent);
}

.toolbox-selection-box::before {
    top: -5px;
    left: -5px;
}

.toolbox-selection-box::after {
    right: -5px;
    bottom: -5px;
}

.toolbox-selection-size {
    position: absolute;
    right: 0;
    bottom: -27px;
    padding: 4px 7px;
    border-radius: 5px;
    background: rgba(17, 20, 27, 0.9);
    color: #fff;
    font: 600 0.64rem/1 'Inter', 'Segoe UI', sans-serif;
    white-space: nowrap;
}

@media (max-width: 700px) {
    .toolbox-menu {
        right: 12px;
        bottom: 76px;
    }

    .global-toolbox-btn {
        right: 12px;
        bottom: 12px;
    }

    .toolbox-taskbar {
        right: 72px;
        bottom: 12px;
        max-width: calc(100vw - 84px);
    }

    .toolbox-notice {
        right: 12px;
        bottom: 72px;
    }

    .toolbox-window,
    .toolbox-window-note,
    .toolbox-window-ocr {
        width: calc(100vw - 20px);
        max-width: calc(100vw - 20px);
    }

    .toolbox-window-ocr {
        right: 10px !important;
        top: 70px !important;
    }

    .toolbox-window-header {
        min-height: 47px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .global-toolbox-btn,
    .toolbox-menu,
    .toolbox-tool-card,
    .toolbox-window,
    .toolbox-window-button,
    .toolbox-action-button,
    .toolbox-spinner,
    .toolbox-notice {
        animation: none !important;
        transition-duration: 0s !important;
    }
}
