/*
 * UI6 — mikrointerakcje, komunikaty, modale i stany przejściowe.
 * Warstwa nie zmienia logiki biznesowej ani kontraktów backendu.
 */

:root {
    --ui-ease-spring: cubic-bezier(.2, .8, .2, 1);
    --ui-overlay: rgba(8, 18, 36, .56);
}

body.ui-ready .workspace > *:not(.app-topbar),
body.ui-ready .auth-shell,
body.ui-ready .map-workspace {
    animation: ui-page-in 360ms var(--ui-ease-spring) both;
}

@keyframes ui-page-in {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Pasek przejścia między stronami */
.ui-page-progress {
    position: fixed;
    z-index: 10000;
    top: 0;
    left: 0;
    width: 100%;
    height: 3px;
    pointer-events: none;
    opacity: 0;
    transform: scaleX(.08);
    transform-origin: left center;
    background: linear-gradient(90deg, #4d72ff, #6d58f5, #37b7dc);
    box-shadow: 0 1px 8px rgba(31, 111, 178, .35);
    transition: opacity 120ms ease, transform 900ms cubic-bezier(.1, .7, .1, 1);
}

body.ui-is-navigating .ui-page-progress {
    opacity: 1;
    transform: scaleX(.82);
}

/* Toasty */
.ui-toast-stack {
    position: fixed;
    z-index: 10100;
    top: 22px;
    right: 24px;
    display: grid;
    width: min(420px, calc(100vw - 32px));
    gap: 12px;
    pointer-events: none;
}

.ui-toast {
    position: relative;
    display: grid;
    grid-template-columns: 36px minmax(0, 1fr) 30px;
    align-items: start;
    gap: 12px;
    padding: 15px 14px;
    overflow: hidden;
    border: 1px solid rgba(202, 213, 228, .92);
    border-radius: 17px;
    background: rgba(255, 255, 255, .97);
    box-shadow: 0 20px 55px rgba(12, 28, 54, .18);
    backdrop-filter: blur(18px);
    pointer-events: auto;
    animation: ui-toast-in 280ms var(--ui-ease-spring) both;
}

.ui-toast.is-leaving { animation: ui-toast-out 180ms ease both; }

@keyframes ui-toast-in {
    from { opacity: 0; transform: translateX(24px) scale(.98); }
    to { opacity: 1; transform: translateX(0) scale(1); }
}

@keyframes ui-toast-out {
    to { opacity: 0; transform: translateX(18px) scale(.98); }
}

.ui-toast::after {
    content: "";
    position: absolute;
    right: 0;
    bottom: 0;
    left: 0;
    height: 3px;
    background: currentColor;
    opacity: .65;
    transform-origin: left center;
    animation: ui-toast-timer var(--toast-duration, 6000ms) linear both;
}

.ui-toast[data-persistent="true"]::after { display: none; }
@keyframes ui-toast-timer { to { transform: scaleX(0); } }

.ui-toast__icon {
    display: grid;
    width: 36px;
    height: 36px;
    place-items: center;
    border-radius: 11px;
    font-size: 18px;
    font-weight: 850;
}

.ui-toast__copy { min-width: 0; padding-top: 1px; }
.ui-toast__copy strong { display: block; margin-bottom: 3px; color: #132139; font-size: 14px; }
.ui-toast__copy p { margin: 0; color: #66758b; font-size: 13px; line-height: 1.45; }
.ui-toast__close {
    display: grid;
    width: 30px;
    height: 30px;
    padding: 0;
    place-items: center;
    border: 0;
    border-radius: 9px;
    color: #718097;
    background: transparent;
    cursor: pointer;
}
.ui-toast__close:hover { color: #15243b; background: #F1F6FA; }

.ui-toast--success { color: #17805a; }
.ui-toast--success .ui-toast__icon { color: #147650; background: #e8f8f0; }
.ui-toast--error { color: #c3433c; }
.ui-toast--error .ui-toast__icon { color: #b43b34; background: #fff0ee; }
.ui-toast--warning { color: #a96e10; }
.ui-toast--warning .ui-toast__icon { color: #95600d; background: #fff5dc; }
.ui-toast--info { color: #2e5bd7; }
.ui-toast--info .ui-toast__icon { color: #1F6FB2; background: #EAF4FB; }

/* Alerty inline po ulepszeniu */
.alert[data-ui-enhanced="true"] {
    padding-right: 52px;
}

.ui-alert-close {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 30px;
    height: 30px;
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: 9px;
    color: currentColor;
    background: transparent;
    opacity: .62;
    cursor: pointer;
}
.ui-alert-close:hover { opacity: 1; background: rgba(255,255,255,.55); }

/* Modal potwierdzenia */
.ui-modal[hidden] { display: none; }
.ui-modal {
    position: fixed;
    z-index: 10050;
    inset: 0;
    display: grid;
    padding: 24px;
    place-items: center;
}
.ui-modal__backdrop {
    position: absolute;
    inset: 0;
    background: var(--ui-overlay);
    backdrop-filter: blur(7px);
    animation: ui-fade-in 180ms ease both;
}
.ui-modal__card {
    position: relative;
    width: min(500px, 100%);
    padding: 26px;
    border: 1px solid rgba(255,255,255,.72);
    border-radius: 24px;
    background: #fff;
    box-shadow: 0 38px 110px rgba(7, 21, 44, .34);
    animation: ui-modal-in 240ms var(--ui-ease-spring) both;
}
@keyframes ui-fade-in { from { opacity: 0; } }
@keyframes ui-modal-in {
    from { opacity: 0; transform: translateY(14px) scale(.975); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}
.ui-modal__header { display: grid; grid-template-columns: 46px minmax(0, 1fr); gap: 15px; align-items: start; }
.ui-modal__icon {
    display: grid;
    width: 46px;
    height: 46px;
    place-items: center;
    border-radius: 15px;
    color: #a55e0b;
    background: #fff3d4;
    font-size: 21px;
    font-weight: 900;
}
.ui-modal--danger .ui-modal__icon { color: #b43b34; background: #fff0ee; }
.ui-modal--info .ui-modal__icon { color: #1F6FB2; background: #EAF4FB; }
.ui-modal__header h2 { margin: 1px 0 7px; font-size: 21px; letter-spacing: -.025em; }
.ui-modal__header p { margin: 0; color: #65748a; font-size: 14px; line-height: 1.55; }
.ui-modal__actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 25px; }
body.ui-modal-open { overflow: hidden; }

/* Stan wysyłania formularza */
.button.is-submitting,
button[aria-busy="true"] {
    position: relative;
    cursor: wait;
    pointer-events: none;
    opacity: .82;
}
.button.is-submitting::before,
button[aria-busy="true"]::before {
    content: "";
    width: 15px;
    height: 15px;
    flex: 0 0 15px;
    border: 2px solid currentColor;
    border-right-color: transparent;
    border-radius: 50%;
    animation: ui-spin .65s linear infinite;
}
@keyframes ui-spin { to { transform: rotate(360deg); } }

/* Niezapisane zmiany */
.ui-unsaved-bar {
    position: fixed;
    z-index: 9900;
    right: 28px;
    bottom: 24px;
    display: flex;
    align-items: center;
    gap: 14px;
    max-width: min(520px, calc(100vw - 40px));
    padding: 12px 14px 12px 17px;
    border: 1px solid #cbd7e7;
    border-radius: 17px;
    color: #26354b;
    background: rgba(255,255,255,.97);
    box-shadow: 0 20px 55px rgba(12, 28, 54, .2);
    backdrop-filter: blur(16px);
    animation: ui-unsaved-in 220ms var(--ui-ease-spring) both;
}
.ui-unsaved-bar[hidden] { display: none; }
@keyframes ui-unsaved-in { from { opacity: 0; transform: translateY(14px); } }
.ui-unsaved-bar__dot { width: 9px; height: 9px; border-radius: 999px; background: #e29a23; box-shadow: 0 0 0 5px rgba(226,154,35,.13); }
.ui-unsaved-bar strong { font-size: 13px; }
.ui-unsaved-bar span { color: #718097; font-size: 12px; }
.ui-unsaved-bar__copy { display: grid; gap: 1px; }
.ui-unsaved-bar .button { min-height: 36px; padding-inline: 12px; font-size: 12px; }

/* Skeletony mapy i list asynchronicznych */
.map-data-loading .map-project-list {
    min-height: 330px;
}
.map-data-loading .map-project-list::before {
    content: "";
    display: block;
    height: 316px;
    border-radius: 18px;
    background:
        linear-gradient(100deg, transparent 20%, rgba(255,255,255,.76) 42%, transparent 64%) 0 0 / 220% 100%,
        linear-gradient(#EAF2F7 0 0) 18px 18px / 74px 58px no-repeat,
        linear-gradient(#e1e8f2 0 0) 108px 20px / 58% 13px no-repeat,
        linear-gradient(#edf1f6 0 0) 108px 46px / 42% 10px no-repeat,
        linear-gradient(#EAF2F7 0 0) 18px 106px / 74px 58px no-repeat,
        linear-gradient(#e1e8f2 0 0) 108px 108px / 64% 13px no-repeat,
        linear-gradient(#edf1f6 0 0) 108px 134px / 38% 10px no-repeat,
        linear-gradient(#EAF2F7 0 0) 18px 194px / 74px 58px no-repeat,
        linear-gradient(#e1e8f2 0 0) 108px 196px / 52% 13px no-repeat,
        linear-gradient(#edf1f6 0 0) 108px 222px / 45% 10px no-repeat,
        #f7f9fc;
    animation: ui-shimmer 1.25s linear infinite;
}
.map-data-loading .map-project-list > * { visibility: hidden; }
@keyframes ui-shimmer { to { background-position: -220% 0, 18px 18px, 108px 20px, 108px 46px, 18px 106px, 108px 108px, 108px 134px, 18px 194px, 108px 196px, 108px 222px, 0 0; } }

/* Lepsze puste stany i interakcje kart */
.empty-state,
.empty-inline,
.map-list-empty {
    position: relative;
    overflow: hidden;
}
.empty-state::after,
.map-list-empty::after {
    content: "";
    position: absolute;
    width: 160px;
    height: 160px;
    right: -70px;
    bottom: -85px;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(31,111,178,.08), transparent 70%);
    pointer-events: none;
}

.project-card,
.client-card,
.import-card,
.dashboard-kpi,
.priority-item,
.quick-action-item,
.map-project-card {
    will-change: transform;
}

@media (hover: hover) {
    .project-card:hover,
    .client-card:hover,
    .import-card:hover,
    .dashboard-kpi:hover {
        transform: translateY(-3px);
    }
}

/* Tooltip dla elementów ikonowych */
[data-tooltip] { position: relative; }
[data-tooltip]::after {
    content: attr(data-tooltip);
    position: absolute;
    z-index: 12000;
    left: 50%;
    bottom: calc(100% + 9px);
    width: max-content;
    max-width: 230px;
    padding: 7px 9px;
    border-radius: 8px;
    color: #fff;
    background: #111d33;
    box-shadow: 0 8px 24px rgba(7,18,36,.22);
    font-size: 11px;
    line-height: 1.35;
    opacity: 0;
    pointer-events: none;
    transform: translate(-50%, 4px);
    transition: opacity 120ms ease, transform 120ms ease;
}
[data-tooltip]:hover::after,
[data-tooltip]:focus-visible::after { opacity: 1; transform: translate(-50%, 0); }

/* Przyjazne ograniczenie ruchu */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        scroll-behavior: auto !important;
        animation-duration: .01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: .01ms !important;
    }
}

@media (max-width: 800px) {
    .ui-toast-stack { top: 14px; right: 14px; width: calc(100vw - 28px); }
    .ui-modal { padding: 14px; }
    .ui-modal__card { padding: 21px; border-radius: 20px; }
    .ui-modal__actions { flex-direction: column-reverse; }
    .ui-modal__actions .button { width: 100%; }
    .ui-unsaved-bar { right: 14px; bottom: 14px; left: 14px; max-width: none; flex-wrap: wrap; }
}

/* ===== MVP20.8: tooltip awatara w topbarze wyświetlany pod kontrolką ===== */
.topbar-account[data-tooltip]::after,
.topbar-account[data-tooltip-placement="bottom"]::after {
    top: calc(100% + 10px);
    bottom: auto;
    transform: translate(-50%, -4px);
}

.topbar-account[data-tooltip]:hover::after,
.topbar-account[data-tooltip]:focus-visible::after,
.topbar-account[data-tooltip-placement="bottom"]:hover::after,
.topbar-account[data-tooltip-placement="bottom"]:focus-visible::after {
    transform: translate(-50%, 0);
}

/* Po otwarciu właściwego menu podpowiedź nie może nachodzić na dropdown. */
.topbar-account-menu[open] > .topbar-account::after {
    opacity: 0 !important;
    visibility: hidden;
}
