/**
 * Shared annotation toolbar chrome for PDF Editor + Screenshot Editor.
 * Change styles here to update both tools.
 */

.editor-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 16px;
    background: #fff;
    border-bottom: 1px solid #e2e8f0;
    position: sticky;
    top: 0;
    z-index: 40;
    min-height: 52px;
}

.toolbar-left {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

.toolbar-center {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 2px;
    padding: 0 8px;
    min-width: 0;
}

.toolbar-center > * {
    flex-shrink: 0;
}

.toolbar-right {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.toolbar-sep {
    width: 1px;
    height: 28px;
    background: #e2e8f0;
    margin: 0 2px;
}

/* ── Tool Buttons ── */
.tb-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px;
    border-radius: 9999px;
    border: 1px solid transparent;
    font-size: 13px;
    font-weight: 600;
    color: #475569;
    cursor: pointer;
    background: transparent;
    transition: all 0.15s;
    white-space: nowrap;
}

.tb-btn:hover {
    background: #f1f5f9;
    color: #1e293b;
}

.tb-btn.active {
    background: #2f76ff;
    color: #fff;
    border-color: #2f76ff;
}

.tb-btn svg {
    width: 19px;
    height: 19px;
    flex-shrink: 0;
    stroke-width: 2.5;
}

/* Arrow / Line: slightly larger icons; line stroke a bit thicker */
.editor-toolbar .toolbar-center .tb-btn[data-shape="arrow"] svg {
    width: 23px;
    height: 23px;
}

.editor-toolbar .toolbar-center .tb-btn[data-shape="line"] svg {
    width: 23px;
    height: 23px;
    stroke-width: 3.2;
}

/* Icon-only tool buttons (labels live in title tooltips) */
.editor-toolbar .toolbar-center .tb-btn > span {
    display: none;
}

.tb-btn.btn-download {
    background: #2f76ff;
    color: #fff;
    border-color: #2f76ff;
    font-weight: 700;
    padding-left: 20px;
    padding-right: 20px;
}

.tb-btn.btn-download:hover {
    background: #1d4ed8;
    border-color: #1d4ed8;
}

.tb-btn:disabled {
    opacity: 0.35;
    cursor: not-allowed;
    pointer-events: none;
}

/* Fabric IText caret mirror — never let it pull the fullscreen editor via scroll-into-view */
textarea[data-fabric-hiddentextarea] {
    position: fixed !important;
    left: 0 !important;
    top: 0 !important;
    opacity: 0 !important;
    pointer-events: none !important;
    z-index: -9999 !important;
    width: 1px !important;
    height: 1px !important;
    transform: none !important;
}

.tb-btn:disabled:hover {
    background: transparent;
    color: #475569;
}

.tb-btn.btn-download svg {
    color: #fff;
}

.tb-btn.btn-start-over {
    background: #f8fafc;
    color: #64748b;
    border: 1px solid #e2e8f0;
}

.tb-btn.btn-start-over:hover {
    background: #f1f5f9;
    color: #ef4444;
    border-color: #fee2e2;
}

/* Hide undo/redo/delete labels on desktop */
#btn-undo span,
#btn-redo span,
#btn-delete span {
    display: none;
}

/* ── Toolbar Options (inline / sub-toolbar) ── */
.tb-opts {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.tb-opts label {
    font-size: 12px;
    color: #64748b;
    font-weight: 600;
}

.tb-opts input[type="color"] {
    width: 28px;
    height: 28px;
    border: 2px solid #e2e8f0;
    border-radius: 6px;
    padding: 0;
    cursor: pointer;
    background: none;
}

.tb-opts input[type="color"]::-webkit-color-swatch-wrapper {
    padding: 1px;
}

.tb-opts input[type="color"]::-webkit-color-swatch {
    border: none;
    border-radius: 4px;
}

.tb-opts input[type="range"] {
    width: 80px;
    accent-color: #2f76ff;
}

/* Shared range style (sidebar + draw toolbars): blue fill, grey remainder, white thumb */
input[type="range"].se-range {
    --se-range-pct: 0%;
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 6px;
    background: linear-gradient(
        to right,
        #2f76ff 0%,
        #2f76ff var(--se-range-pct),
        #e2e8f0 var(--se-range-pct),
        #e2e8f0 100%
    );
    border: none;
    border-radius: 999px;
    outline: none;
    accent-color: #2f76ff;
}

.tb-opts input[type="range"].se-range {
    width: 80px;
}

input[type="range"].se-range:focus {
    outline: none;
}

input[type="range"].se-range::-webkit-slider-runnable-track {
    height: 6px;
    background: linear-gradient(
        to right,
        #2f76ff 0%,
        #2f76ff var(--se-range-pct),
        #e2e8f0 var(--se-range-pct),
        #e2e8f0 100%
    );
    border: none;
    border-radius: 999px;
}

input[type="range"].se-range::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 16px;
    height: 16px;
    margin-top: -5px;
    background: #ffffff;
    border: 1.5px solid #94a3b8;
    border-radius: 50%;
    box-shadow: none;
    cursor: pointer;
    transition: background-color 0.15s ease, border-color 0.15s ease;
}

input[type="range"].se-range::-webkit-slider-thumb:hover {
    background: #f1f5f9;
    border-color: #94a3b8;
}

input[type="range"].se-range:active::-webkit-slider-thumb,
input[type="range"].se-range::-webkit-slider-thumb:active {
    background: #e2e8f0;
    border-color: #94a3b8;
}

input[type="range"].se-range::-moz-range-track {
    height: 6px;
    background: #e2e8f0;
    border: none;
    border-radius: 999px;
}

input[type="range"].se-range::-moz-range-progress {
    height: 6px;
    background: #2f76ff;
    border: none;
    border-radius: 999px;
}

input[type="range"].se-range::-moz-range-thumb {
    width: 16px;
    height: 16px;
    background: #ffffff;
    border: 1.5px solid #94a3b8;
    border-radius: 50%;
    box-shadow: none;
    cursor: pointer;
    transition: background-color 0.15s ease, border-color 0.15s ease;
}

input[type="range"].se-range:hover::-moz-range-thumb {
    background: #f1f5f9;
}

input[type="range"].se-range:active::-moz-range-thumb {
    background: #e2e8f0;
}

.tb-opts input[type="number"] {
    width: 52px;
    padding: 4px 6px;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    font-size: 12px;
    background: #f8fafc;
    color: #334155;
    text-align: center;
}

.tb-opts input[type="checkbox"] {
    accent-color: #2f76ff;
}

.tb-opts .opt-val {
    font-size: 11px;
    color: #2f76ff;
    font-weight: 700;
    min-width: 20px;
}

.tb-opts-group {
    display: none;
}

/* ── Shape Sub-Selector ── */
.shape-dropdown {
    position: relative;
    display: inline-block;
}

.shape-menu {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
    padding: 6px;
    z-index: 50;
    min-width: 140px;
    margin-top: 4px;
}

.shape-menu.open {
    display: block;
}

.shape-menu-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 600;
    color: #475569;
    cursor: pointer;
    transition: all 0.1s;
}

.shape-menu-item:hover {
    background: #f1f5f9;
    color: #1e293b;
}

.shape-menu-item svg {
    width: 16px;
    height: 16px;
}

/* ── Floating Sub-Toolbar ── */
#sub-toolbar,
.sub-toolbar {
    position: fixed;
    top: 68px;
    left: 50%;
    transform: translateX(-50%);
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 9999px;
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.1);
    padding: 6px 16px;
    z-index: 90;
    display: none;
    align-items: center;
    gap: 12px;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    animation: editorSubToolbarSlideIn 0.3s ease-out;
}

@keyframes editorSubToolbarSlideIn {
    from {
        transform: translate(-50%, -10px);
        opacity: 0;
    }
    to {
        transform: translate(-50%, 0);
        opacity: 1;
    }
}

#sub-toolbar.active,
.sub-toolbar.active {
    display: flex;
}

.sub-toolbar .tb-opts {
    display: none;
    align-items: center;
    gap: 12px;
    white-space: nowrap;
}

.sub-toolbar label {
    font-size: 11px;
    font-weight: 700;
    color: #64748b;
    text-transform: uppercase;
    letter-spacing: 0.025em;
}

/* More menu (mobile overflow) */
.more-menu {
    display: none;
    position: absolute;
    top: 100%;
    right: 0;
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    padding: 8px;
    z-index: 110;
    min-width: 160px;
    margin-top: 8px;
    flex-direction: column;
    gap: 2px;
}

.more-menu.open,
.more-menu:not(.hidden) {
    display: flex;
}

.more-menu .tb-btn {
    width: 100%;
    justify-content: flex-start;
    border-radius: 8px;
}

.more-menu .tb-btn.active {
    background: #eff6ff;
    color: #2f76ff;
    border-color: transparent;
}

.more-menu .tb-btn span {
    display: inline !important;
}

@media (max-width: 1600px) {
    .toolbar-center .tb-btn span,
    .toolbar-center .shape-dropdown .tb-btn span {
        display: none;
    }

    .toolbar-center .tb-btn {
        padding: 8px 10px;
    }

    .toolbar-right .btn-start-over span,
    .toolbar-right .btn-download span,
    .toolbar-right #btn-copy span,
    .toolbar-right #btn-exit-editor span {
        display: none;
    }

    .toolbar-right .btn-start-over,
    .toolbar-right .btn-download,
    .toolbar-right #btn-copy,
    .toolbar-right #btn-exit-editor {
        padding: 8px 12px;
    }
}

/* Dedicated tools row under logo/actions (PDF + Screenshot) */
@media (max-width: 1024px) {
    .editor-toolbar {
        flex-wrap: wrap;
        height: auto;
        min-height: auto;
        padding: 8px 10px;
        align-content: flex-start;
    }

    .toolbar-center {
        position: static;
        transform: none;
        left: auto;
        order: 3;
        flex: 0 0 100%;
        width: 100%;
        max-width: 100vw;
        display: flex;
        justify-content: flex-start;
        overflow-x: auto;
        border-top: 1px solid #e2e8f0;
        padding: 8px 0 2px 0;
        margin-top: 8px;
        scrollbar-width: none;
    }

    .toolbar-center::-webkit-scrollbar {
        display: none;
    }

    /* Don't override Tailwind .hidden (e.g. crop Apply/Cancel when inactive) */
    .toolbar-center > .tool-item:not(.hidden) {
        display: inline-flex;
    }

    .toolbar-center > .tool-item.hidden {
        display: none !important;
    }

    .toolbar-center .tb-btn {
        padding: 6px 8px;
        gap: 4px;
        font-size: 12px;
    }

    .toolbar-center .tb-btn svg {
        width: 18px;
        height: 18px;
    }

    .toolbar-center .tb-btn[data-shape="arrow"] svg,
    .toolbar-center .tb-btn[data-shape="line"] svg {
        width: 22px;
        height: 22px;
    }

    .toolbar-center .tb-btn[data-shape="line"] svg {
        stroke-width: 3.2;
    }

    .toolbar-center .tb-btn span {
        display: none !important;
    }

    .toolbar-left .logo-text {
        display: none !important;
    }

    #sub-toolbar,
    .sub-toolbar {
        left: 10px;
        right: 10px;
        transform: none;
        width: auto;
        max-width: none;
        top: auto;
        bottom: 12px;
        border-radius: 12px;
        justify-content: flex-start;
        overflow-x: auto;
        scrollbar-width: none;
        animation: none;
    }

    #sub-toolbar::-webkit-scrollbar,
    .sub-toolbar::-webkit-scrollbar {
        display: none;
    }

    #sub-toolbar .tb-opts,
    .sub-toolbar .tb-opts {
        gap: 6px;
    }

    #sub-toolbar .opt-label-color,
    .sub-toolbar .opt-label-color {
        display: none !important;
    }

    #sub-toolbar .opt-val,
    .sub-toolbar .opt-val {
        display: none !important;
    }

    #sub-toolbar .tb-opts input[type="range"],
    .sub-toolbar .tb-opts input[type="range"] {
        width: 56px;
    }

    #sub-toolbar .tb-opts input[type="number"],
    .sub-toolbar .tb-opts input[type="number"] {
        width: 44px;
    }
}
