/* Taskbar: session-open/pinned apps, close/pin controls, overflow arrows.
   Depends on tokens.css. Do not edit os-shell.css for these rules. */

.os-taskbar {
    box-sizing: border-box;
    width: 100%;
    max-width: 100vw;
}

/* ============ Apps wrapper (scroll container with overflow masks) ============ */
.taskbar-apps-wrapper {
    position: relative;
    flex: 1;
    min-width: 0;
    display: flex;
    align-items: center;
    height: 100%;
    overflow: hidden;
}

/* fade masks shown via JS-toggled classes */
.taskbar-apps-wrapper::before,
.taskbar-apps-wrapper::after {
    content: "";
    position: absolute;
    top: 0; bottom: 0;
    width: 32px;
    pointer-events: none;
    z-index: 1;
    opacity: 0;
    transition: opacity var(--duration-fast) var(--ease-default);
}
.taskbar-apps-wrapper::before {
    inset-inline-start: 0;
    background: linear-gradient(to right, var(--os-surface), transparent);
}
.taskbar-apps-wrapper::after {
    inset-inline-end: 0;
    background: linear-gradient(to left, var(--os-surface), transparent);
}
[dir="rtl"] .taskbar-apps-wrapper::before {
    background: linear-gradient(to left, var(--os-surface), transparent);
}
[dir="rtl"] .taskbar-apps-wrapper::after {
    background: linear-gradient(to right, var(--os-surface), transparent);
}
.taskbar-apps-wrapper.mask-start::before { opacity: 1; }
.taskbar-apps-wrapper.mask-end::after   { opacity: 1; }
.taskbar-apps-wrapper.mask-both::before,
.taskbar-apps-wrapper.mask-both::after  { opacity: 1; }

/* Scroll list: already styled in os-shell.css; extend here */
#taskbarApps.taskbar-apps {
    scroll-behavior: smooth;
    padding: 0 2px;
    flex: 1;
}

/* ============ Overflow nav arrows ============ */
.taskbar-nav-btn {
    flex-shrink: 0;
    width: 26px;
    height: 38px;
    display: none; /* shown by JS when overflow exists */
    align-items: center;
    justify-content: center;
    border-radius: var(--os-radius-xs);
    color: var(--os-text-muted);
    font-size: 0.8rem;
    transition: background var(--duration-fast) var(--ease-default),
                color var(--duration-fast) var(--ease-default);
    z-index: 2;
}
.taskbar-nav-btn.visible { display: flex; }
.taskbar-nav-btn:hover {
    background: rgba(255, 255, 255, 0.08);
    color: var(--os-text-main);
}
.taskbar-nav-btn:focus-visible {
    outline: 2px solid var(--os-accent);
    outline-offset: 1px;
}

/* ============ App item wrapper ============ */
.taskbar-app {
    --_brand: var(--app-brand, var(--os-accent));
    position: relative;
    display: inline-flex;
    align-items: center;
    flex-shrink: 0;
}

/* ============ App button ============ */
/* Extends .taskbar-btn from os-shell.css */
.taskbar-app .taskbar-btn {
    position: relative;
    overflow: visible; /* allow indicator overflow */
    /* label visible on wide screens, hidden narrow */
    padding: 0 0.6rem;
}

/* Label */
.taskbar-app .taskbar-btn .tb-label {
    display: block;
    max-width: 96px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    transition: max-width var(--duration-fast) var(--ease-default),
                opacity var(--duration-fast) var(--ease-default);
}

/* ============ Running indicator ============ */
.taskbar-app .taskbar-btn::after {
    content: "";
    position: absolute;
    bottom: 4px;
    left: 50%; transform: translateX(-50%);
    width: 4px; height: 4px;
    border-radius: var(--os-radius-full);
    background: var(--_brand);
    opacity: 0;
    transition: opacity var(--duration-fast) var(--ease-default),
                width var(--duration-fast) var(--ease-default);
}
.taskbar-app .taskbar-btn.is-running::after { opacity: 0.65; }
.taskbar-app .taskbar-btn.active::after     { width: 18px; opacity: 1; }

/* Active state: restrained brand highlight instead of filled rainbow */
.taskbar-app .taskbar-btn.active {
    background: color-mix(in srgb, var(--_brand) 14%, transparent) !important;
    border-color: color-mix(in srgb, var(--_brand) 35%, transparent) !important;
    color: #fff !important;
    box-shadow: none !important;
}
/* Fallback for browsers without color-mix */
@supports not (background: color-mix(in srgb, red 10%, blue)) {
    .taskbar-app .taskbar-btn.active {
        background: rgba(37, 99, 235, 0.14) !important;
        border-color: rgba(37, 99, 235, 0.35) !important;
    }
}

/* Hover: subtle brand glow instead of generic white */
.taskbar-app .taskbar-btn:hover:not(.active) {
    background: rgba(255, 255, 255, 0.07);
    border-color: rgba(255, 255, 255, 0.12);
    color: #fff;
}

/* Pinned marker: tiny top-left dot */
.taskbar-app .taskbar-btn[data-pinned="true"]::before {
    content: "";
    position: absolute;
    top: 5px; inset-inline-start: 5px;
    width: 4px; height: 4px;
    border-radius: var(--os-radius-full);
    background: var(--_brand);
    opacity: 0.7;
}

/* ============ Close / Pin controls ============ */
/* Container spans full app item so each button anchors to a specific corner */
.taskbar-app-controls {
    position: absolute;
    inset: 0;
    pointer-events: none;
    opacity: 0;
    transition: opacity var(--duration-fast) var(--ease-default);
    z-index: 10;
}
.taskbar-app:hover .taskbar-app-controls,
.taskbar-app:focus-within .taskbar-app-controls {
    opacity: 1;
}

/* Shared corner micro-button base */
.taskbar-app-close,
.taskbar-app-pin {
    position: absolute;
    top: 3px;
    width: 14px; height: 14px;
    border-radius: var(--os-radius-full);
    display: inline-flex; align-items: center; justify-content: center;
    font-size: 0.5rem;
    line-height: 1;
    pointer-events: auto;
    transition: background var(--duration-fast) var(--ease-default),
                color var(--duration-fast) var(--ease-default),
                transform var(--duration-fast) var(--ease-default),
                box-shadow var(--duration-fast) var(--ease-default);
    box-shadow: 0 1px 3px rgba(0,0,0,0.5), inset 0 1px 0 rgba(255,255,255,0.06);
}

/* Close button: top-right corner */
.taskbar-app-close {
    inset-inline-end: 3px;
    background: rgba(239, 68, 68, 0.22);
    color: #ff6b6b;
}
.taskbar-app-close:hover {
    background: rgba(239, 68, 68, 0.58);
    color: #fff;
    transform: scale(1.18);
    box-shadow: 0 2px 8px rgba(239, 68, 68, 0.45), inset 0 1px 0 rgba(255,255,255,0.1);
}

/* Pin button: top-left corner */
.taskbar-app-pin {
    inset-inline-start: 3px;
    background: rgba(255, 255, 255, 0.08);
    color: var(--os-text-muted);
}
.taskbar-app-pin:hover {
    background: color-mix(in srgb, var(--_brand, var(--os-accent)) 32%, transparent);
    color: #fff;
    transform: scale(1.18);
    box-shadow: 0 2px 8px color-mix(in srgb, var(--_brand, var(--os-accent)) 45%, transparent),
                inset 0 1px 0 rgba(255,255,255,0.1);
}
@supports not (background: color-mix(in srgb, red 10%, blue)) {
    .taskbar-app-pin:hover {
        background: rgba(37, 99, 235, 0.32);
        box-shadow: 0 2px 8px rgba(37, 99, 235, 0.4), inset 0 1px 0 rgba(255,255,255,0.1);
    }
}
.taskbar-app-pin[aria-pressed="true"] {
    background: color-mix(in srgb, var(--_brand, var(--os-accent)) 35%, transparent);
    color: #fff;
}
@supports not (background: color-mix(in srgb, red 10%, blue)) {
    .taskbar-app-pin[aria-pressed="true"] { background: rgba(37, 99, 235, 0.35); }
}

/* Focus rings */
.taskbar-app-close:focus-visible,
.taskbar-app-pin:focus-visible {
    outline: 2px solid var(--os-accent);
    outline-offset: 1px;
}

/* ============ App info bubble ============ */
/* Singleton fixed-position tooltip; escapes taskbar overflow:hidden */
#tbBubble {
    position: fixed;
    z-index: 9200;
    /* Center horizontally on `left`, shift upward by own height */
    transform: translateX(-50%) translateY(-100%);
    /* sizing */
    min-width: 120px;
    max-width: 240px;
    padding: 0.45rem 0.7rem 0.5rem;
    /* dark compact Weepsi OS style */
    background: #1a1f2e;
    border: 1px solid rgba(255, 255, 255, 0.09);
    border-top: 2px solid color-mix(in srgb, var(--_brand, #2563eb) 60%, transparent);
    border-radius: 8px;
    box-shadow: 0 8px 28px rgba(0, 0, 0, 0.55), 0 2px 8px rgba(0, 0, 0, 0.4);
    /* text */
    color: #e2e8f0;
    font-size: 0.78rem;
    line-height: 1.4;
    text-align: start;
    white-space: normal;
    word-break: break-word;
    /* hide / show */
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.14s ease;
    /* short appear delay; prevents flash on quick mouse-over */
    transition-delay: 0.18s;
}
#tbBubble::after {
    content: "";
    position: absolute;
    inset-inline-start: 50%;
    bottom: -6px;
    width: 10px;
    height: 10px;
    transform: translateX(-50%) rotate(45deg);
    background: #1a1f2e;
    border-inline-end: 1px solid rgba(255, 255, 255, 0.09);
    border-block-end: 1px solid rgba(255, 255, 255, 0.09);
}
@supports not (background: color-mix(in srgb, red 10%, blue)) {
    #tbBubble { border-top-color: rgba(37, 99, 235, 0.6); }
}
#tbBubble.visible {
    opacity: 1;
    transition-delay: 0.18s; /* keep delay on appear; hide is instant via scheduleBubbleHide */
}
/* Name row */
#tbBubble .tb-bubble-name {
    font-weight: 600;
    font-size: 0.8rem;
    color: #f1f5f9;
    margin-bottom: 0.18rem;
}
/* Description row */
#tbBubble .tb-bubble-desc {
    color: #94a3b8;
    font-size: 0.74rem;
    line-height: 1.45;
}

/* ============ Responsive: <=900px (narrow tablet/phone) ============ */
@media (max-width: 900px) {
    /* guard start and tray from shrinking and squeezing app rail */
    .start-btn   { flex-shrink: 0; }
    .taskbar-tray { flex-shrink: 0; }
    /* overflow nav arrows more visible/tappable on narrow viewports */
    .taskbar-nav-btn {
        width: 32px;
        height: 40px;
        font-size: 0.95rem;
    }
}

/* ============ Responsive: <=640px ============ */
@media (max-width: 640px) {
    .taskbar-app .taskbar-btn .tb-label {
        max-width: 0;
        opacity: 0;
        pointer-events: none;
    }
    .taskbar-app .taskbar-btn {
        padding: 0 0.45rem;
        min-width: 38px;
    }
    /* corner micro-buttons smaller on mobile */
    .taskbar-app-close,
    .taskbar-app-pin {
        width: 12px; height: 12px;
        font-size: 0.45rem;
        top: 2px;
    }
    .taskbar-app-close { inset-inline-end: 2px; }
    .taskbar-app-pin   { inset-inline-start: 2px; }
}

/* ============ Shield tray status indicator ============ */
#trayShieldStatus {
    position: relative;
    box-sizing: border-box;
    width: 30px;
    height: 30px;
    padding: 0;
    border-radius: var(--os-radius-full);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.9rem;
    flex-shrink: 0;
    border: 1.5px solid rgba(255, 255, 255, 0.10);
    background: transparent;
    transition: background var(--duration-fast) var(--ease-default),
                border-color var(--duration-fast) var(--ease-default),
                box-shadow var(--duration-fast) var(--ease-default),
                opacity var(--duration-fast) var(--ease-default);
}
#trayShieldStatus[data-state="ok"] {
    color: #86efac;
    border-color: rgba(134, 239, 172, 0.30);
    animation: tray-shield-glow-ok 3s ease-in-out infinite;
}
#trayShieldStatus[data-state="warn"] {
    color: #fbbf24;
    border-color: rgba(251, 191, 36, 0.32);
}
#trayShieldStatus[data-state="error"] {
    color: #fca5a5;
    border-color: rgba(252, 165, 165, 0.38);
    animation: tray-shield-pulse-error 1.8s ease-in-out infinite;
}
#trayShieldStatus[data-state="pending"] {
    color: var(--os-text-muted, #64748b);
    border-color: rgba(100, 116, 139, 0.20);
    opacity: 0.60;
}
#trayShieldStatus:hover {
    background: rgba(255, 255, 255, 0.07);
    border-color: rgba(255, 255, 255, 0.18);
    opacity: 1;
    animation: none;
}
#trayShieldStatus::after {
    content: attr(data-tip);
    position: absolute;
    inset-inline-end: 0;
    bottom: calc(100% + 10px);
    width: max-content;
    max-width: min(260px, calc(100vw - 24px));
    padding: 0.55rem 0.7rem;
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: var(--os-radius-sm);
    background: rgba(8, 13, 24, 0.96);
    color: var(--os-text-main, #f8fafc);
    box-shadow: 0 14px 32px rgba(0, 0, 0, 0.42);
    font-size: 0.72rem;
    line-height: 1.35;
    text-align: start;
    white-space: normal;
    pointer-events: none;
    opacity: 0;
    transform: translateY(4px);
    transition: opacity var(--duration-fast) var(--ease-default),
                transform var(--duration-fast) var(--ease-default);
    z-index: calc(var(--z-taskbar, 500) + 2);
}
#trayShieldStatus:hover::after,
#trayShieldStatus:focus-visible::after {
    opacity: 1;
    transform: translateY(0);
}
#trayShieldStatus:focus-visible {
    outline: 2px solid var(--os-accent, #2563eb);
    outline-offset: 2px;
}
/* badge: error count */
.tray-shield-badge {
    position: absolute;
    top: -4px;
    inset-inline-end: -4px;
    min-width: 16px;
    height: 16px;
    padding: 0 3px;
    border-radius: var(--os-radius-full);
    background: #ef4444;
    color: #fff;
    font-size: 0.58rem;
    font-weight: 700;
    line-height: 16px;
    text-align: center;
    white-space: nowrap;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.50);
    pointer-events: none;
}
@keyframes tray-shield-glow-ok {
    0%, 100% { box-shadow: 0 0 0 0 rgba(134, 239, 172, 0.00); }
    50%       { box-shadow: 0 0 7px 2px rgba(134, 239, 172, 0.22); }
}
@keyframes tray-shield-pulse-error {
    0%, 100% { box-shadow: 0 0 0 0 rgba(252, 165, 165, 0.00); }
    50%       { box-shadow: 0 0 9px 3px rgba(252, 165, 165, 0.30); }
}
@media (max-width: 640px) {
    #trayShieldStatus {
        width: 34px;
        height: 34px;
        min-width: 34px;
        min-height: 34px;
        font-size: 0.8rem;
    }
    .tray-shield-badge {
        top: -2px;
        inset-inline-end: -2px;
    }
}

/* ============ Touch / coarse pointer (phone, Fold cover, tablet) ============ */
/* Comfortable 44px+ touch targets; hover-only controls hidden until long-press. */
@media (hover: none) and (pointer: coarse) {
    .start-btn {
        min-height: 44px;
        min-width: 44px;
    }
    .taskbar-app .taskbar-btn {
        min-height: 44px;
        min-width: 44px;
        padding: 0 0.55rem;
    }
    .taskbar-nav-btn {
        width: 40px;
        height: 44px;
        font-size: 1rem;
    }
    /* Suppress hover/focus reveal of corner controls — handled by long-press */
    .taskbar-app:hover .taskbar-app-controls,
    .taskbar-app:focus-within .taskbar-app-controls {
        opacity: 0;
        pointer-events: none;
    }
    /* Long-press reveals controls with comfortable touch targets */
    .taskbar-app.show-controls .taskbar-app-controls {
        opacity: 1;
        pointer-events: auto;
    }
    .taskbar-app.show-controls .taskbar-app-close,
    .taskbar-app.show-controls .taskbar-app-pin {
        width: 32px;
        height: 32px;
        font-size: 0.85rem;
        top: -12px;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.6),
                    inset 0 1px 0 rgba(255, 255, 255, 0.12);
    }
    .taskbar-app.show-controls .taskbar-app-close { inset-inline-end: -10px; }
    .taskbar-app.show-controls .taskbar-app-pin   { inset-inline-start: -10px; }
    /* Active indicator a touch thicker so it reads on small screens */
    .taskbar-app .taskbar-btn.active::after { height: 5px; }
    /* Bubble would flicker on tap and offers no touch value — suppress */
    #tbBubble { display: none !important; }
    /* Shield: comfortable touch target */
    #trayShieldStatus {
        width: 42px;
        height: 42px;
        min-width: 42px;
        min-height: 42px;
    }
    #trayShieldStatus::after { display: none; }
}
