/* STEP 274 — floating diagnostics widget. */

.diagnostics-widget {
    position: fixed;
    top: 40%;
    right: 12px;
    z-index: 105;
    display: flex;
    align-items: flex-start;
    gap: 4px;
    font-family: var(--font-interface, system-ui, sans-serif);
    font-size: 14px;
    line-height: 1.4;
    color: #28342e;
}

.diagnostics-widget *,
.diagnostics-widget *::before,
.diagnostics-widget *::after {
    box-sizing: border-box;
}

.diagnostics-widget__handle {
    width: 24px;
    min-height: 44px;
    padding: 0;
    border: 1px solid #d9e0d7;
    border-radius: 9px;
    background: #ffffff;
    color: #456950;
    font: inherit;
}

.diagnostics-widget__handle:disabled {
    opacity: 0.65;
    cursor: not-allowed;
}

.diagnostics-widget__details {
    position: relative;
}

.diagnostics-widget__tab {
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 44px;
    min-height: 126px;
    padding: 14px 10px;
    border: 1px solid #d9e0d7;
    border-radius: 12px;
    background: #456950;
    color: #ffffff;
    box-shadow: 0 4px 18px rgb(0 0 0 / 15%);
    cursor: pointer;
    writing-mode: vertical-rl;
    transform: rotate(180deg);
    list-style: none;
    font-family: var(--font-interface, system-ui, sans-serif);
    font-weight: 650;
    letter-spacing: 0.03em;
}

.diagnostics-widget__tab::-webkit-details-marker {
    display: none;
}

.diagnostics-widget__tab:hover {
    background: #304f39;
}

.diagnostics-widget__menu {
    position: absolute;
    top: 0;
    right: calc(100% + 8px);
    width: min(290px, calc(100vw - 100px));
    max-height: min(70vh, 420px);
    overflow-y: auto;
    padding: 16px;
    border: 1px solid #d9e0d7;
    border-radius: 14px;
    background: #ffffff;
    color: #28342e;
    box-shadow: 0 8px 28px rgb(0 0 0 / 17%);
}

.diagnostics-widget__title {
    margin: 0 0 12px;
    color: #28342e;
    font-size: 15px;
    font-weight: 700;
}

.diagnostics-widget__link {
    display: flex;
    flex-direction: column;
    gap: 5px;
    padding: 12px 10px;
    border-radius: 9px;
    color: #28342e;
    text-decoration: none;
    font-family: var(--font-interface, system-ui, sans-serif);
}

.diagnostics-widget__link + .diagnostics-widget__link {
    border-top: 1px solid #d9e0d7;
}

.diagnostics-widget__link:hover {
    background: #f4f7f1;
}

.diagnostics-widget__link strong {
    color: #28342e;
    font-weight: 700;
}

.diagnostics-widget__link span {
    color: #59655e;
    font-size: 13px;
}

.diagnostics-widget :focus-visible {
    outline: 3px solid #205eac;
    outline-offset: 3px;
}

@media (max-width: 600px) {
    .diagnostics-widget {
        top: 36%;
        right: 8px;
        gap: 3px;
    }

    .diagnostics-widget__menu {
        padding: 12px;
    }
}


/* STEP 275: drag and edge docking. */
.diagnostics-widget__handle {
    cursor: grab;
    touch-action: none;
    user-select: none;
    font-weight: 700;
}

.diagnostics-widget__handle:active {
    cursor: grabbing;
}

.diagnostics-widget[data-dragging="true"] {
    user-select: none;
}

.diagnostics-widget[data-side="left"] {
    right: auto;
}

.diagnostics-widget[data-side="left"]
.diagnostics-widget__menu {
    right: auto;
    left: calc(100% + 8px);
}

.diagnostics-widget[data-side="left"]
.diagnostics-widget__details {
    position: relative;
}

.diagnostics-widget__details[open]
.diagnostics-widget__tab {
    background: #304f39;
}

@media (prefers-reduced-motion: reduce) {
    .diagnostics-widget,
    .diagnostics-widget * {
        transition: none !important;
        animation: none !important;
    }
}

/* STEP 277: accessible drag handle */
.diagnostics-widget__handle {
    position: relative;
    z-index: 3;
    width: 34px;
    min-width: 34px;
    min-height: 48px;
    background: #ffffff;
    opacity: 1;
    touch-action: none;
}

.diagnostics-widget__menu {
    z-index: 1;
}

.diagnostics-widget__handle:hover {
    background: #f4f7f1;
    border-color: #456950;
}


/* STEP 279: four-side docking */
.diagnostics-widget[data-side="top"],
.diagnostics-widget[data-side="bottom"] {
    flex-direction: row;
    align-items: center;
}

.diagnostics-widget[data-side="top"] .diagnostics-widget__tab,
.diagnostics-widget[data-side="bottom"] .diagnostics-widget__tab {
    writing-mode: horizontal-tb;
    transform: none;
    min-width: 126px;
    min-height: 44px;
    padding: 10px 14px;
}

.diagnostics-widget[data-side="top"] .diagnostics-widget__menu,
.diagnostics-widget[data-side="bottom"] .diagnostics-widget__menu {
    left: 0;
    right: auto;
    top: calc(100% + 8px);
    bottom: auto;
    width: min(290px, calc(100vw - 24px));
    max-height: min(60vh, 420px);
}

.diagnostics-widget[data-side="top"][data-align="end"]
.diagnostics-widget__menu,
.diagnostics-widget[data-side="bottom"][data-align="end"]
.diagnostics-widget__menu {
    left: auto;
    right: 0;
}

.diagnostics-widget[data-side="bottom"]
.diagnostics-widget__menu {
    top: auto;
    bottom: calc(100% + 8px);
}

.diagnostics-widget[data-side="left"]
.diagnostics-widget__menu {
    top: 0;
    bottom: auto;
    left: calc(100% + 8px);
    right: auto;
}

.diagnostics-widget[data-side="right"]
.diagnostics-widget__menu {
    top: 0;
    bottom: auto;
    right: calc(100% + 8px);
    left: auto;
}

.diagnostics-widget[data-dragging="true"] {
    cursor: grabbing;
}


/* STEP 281: mirrored left dock */
.diagnostics-widget[data-side="left"] {
    flex-direction: row-reverse;
}

.diagnostics-widget[data-side="left"]
.diagnostics-widget__menu {
    left: calc(100% + 8px);
    right: auto;
}


/* STEP 292: unified mobile diagnostics bar */
@media (max-width: 600px) {

    .diagnostics-widget {
        position: fixed !important;
        top: auto !important;
        bottom: calc(
            12px + env(safe-area-inset-bottom, 0px)
        ) !important;
        left: max(
            8px,
            env(safe-area-inset-left, 0px)
        ) !important;
        right: auto !important;

        display: block !important;
        box-sizing: border-box;
        width: max-content !important;
        min-width: 0 !important;
        max-width: calc(100vw - 16px) !important;
        height: auto !important;
        margin: 0 !important;
        padding: 0 !important;
        transform: none !important;
        z-index: 130;
    }

    .diagnostics-widget__handle {
        display: none !important;
    }

    .diagnostics-widget__details {
        display: block;
        position: relative;
        box-sizing: border-box;
        width: max-content;
        max-width: 100%;
        min-width: 0;
        margin: 0;
        padding: 0;
    }

    .diagnostics-widget .diagnostics-widget__tab {
        display: flex !important;
        align-items: center;
        justify-content: center;

        box-sizing: border-box;
        width: auto !important;
        max-width: 100% !important;
        min-width: 0 !important;
        min-height: 48px;
        height: auto !important;

        padding: 10px clamp(8px, 3vw, 16px);
        border-radius: 12px;

        writing-mode: horizontal-tb !important;
        transform: none !important;
        text-align: center;
        overflow-wrap: anywhere;
        font-size: clamp(13px, 3.5vw, 15px);
    }

    .diagnostics-widget .diagnostics-widget__menu {
        position: absolute !important;
        top: auto !important;
        bottom: calc(100% + 8px) !important;
        left: 0 !important;
        right: auto !important;

        box-sizing: border-box;
        width: min(280px, calc(100vw - 16px)) !important;
        min-width: 0 !important;
        max-width: calc(100vw - 16px) !important;
        max-height: max(
            80px,
            min(55dvh, calc(100dvh - 110px))
        );

        margin: 0;
        padding: clamp(10px, 3vw, 16px);
        overflow-x: hidden;
        overflow-y: auto;
        border-radius: 12px;
    }

    .diagnostics-widget__link,
    .diagnostics-widget__title {
        min-width: 0;
        overflow-wrap: anywhere;
    }

    .diagnostics-widget__link {
        padding-inline: clamp(5px, 2vw, 10px);
    }
}

@media (max-width: 600px) and (max-height: 380px) {
    .diagnostics-widget {
        bottom: calc(
            6px + env(safe-area-inset-bottom, 0px)
        ) !important;
    }

    .diagnostics-widget .diagnostics-widget__menu {
        max-height: min(45dvh, 180px);
    }
}


/* STEP 318: mobile compact icon */
@media (max-width: 600px) {
    .diagnostics-widget .diagnostics-widget__tab {
        transition:
            background-color 180ms ease,
            border-radius 180ms ease;
    }

    .diagnostics-widget[data-compact="true"]
    .diagnostics-widget__tab {
        width: 44px !important;
        min-width: 44px !important;
        max-width: 44px !important;
        min-height: 44px !important;
        height: 44px !important;
        padding: 0 !important;
        border-radius: 12px;
        font-size: 0 !important;
        letter-spacing: 0;
        line-height: 1;
    }

    .diagnostics-widget[data-compact="true"]
    .diagnostics-widget__tab::before {
        content: "☷";
        display: inline-block;
        font-size: 23px;
        line-height: 1;
        color: #ffffff;
    }
}

@media (prefers-reduced-motion: reduce) {
    .diagnostics-widget .diagnostics-widget__tab {
        transition: none;
    }
}
