.custom-graph {
    position: relative;
    padding: 130px 0 150px 45px;
}

@media screen and (max-width: 1200px) {
    .custom-graph {
        padding: 70px 0 70px 45px;
    }
}

.custom-graph__items {
    display: flex;
    flex-wrap: nowrap;
    justify-content: space-evenly;
    border-bottom: 6px solid var(--ls-alfa-color);
    border-radius: 0 0 8px 8px;
    align-items: stretch;
    height: min(382px, 30vh);
    padding-bottom: 60px;
    box-sizing: border-box;
    position: relative;
    box-shadow: 0 4px 8px rgba(22, 4, 73, 0.08);
    background: linear-gradient(to top, 
        rgba(81, 206, 236, 0.03) 0%, 
        transparent 100%);
}

.statistic .custom-graph__items {
    pointer-events: none;
}

/* Hide safezone by default (for non-statistic views like ubung-5) */
.custom-graph__safezone {
    display: none;
    visibility: hidden;
    position: absolute;
    width: 0;
    height: 0;
    opacity: 0;
    pointer-events: none;
}

/* Show and style safezone only for statistic views */
.statistic .custom-graph__safezone {
    content: " ";
    display: block;
    visibility: visible;
    position: absolute;
    border-radius: 10px;
    width: calc(100% - 6px);
    background-color: #9FE2BF;
    border: 1px solid #51ceec;
    z-index: 0;
    opacity: 1;
    pointer-events: auto;
}

.statistic .custom-graph__safezone-info {
    position: absolute;
    right: 10px;
    top: 10px;
    z-index: 4;
    font-size: 12px;
    color: #222;
}

.statistic .custom-graph__safezone-info summary {
    background: #ffffff;
    border: 1px solid #e2e2e2;
    border-radius: 8px;
    padding: 6px 10px;
    cursor: pointer;
    list-style: none;
}

.statistic .custom-graph__safezone-info summary::-webkit-details-marker {
    display: none;
}

.statistic .custom-graph__safezone-info-content {
    background: #ffffff;
    border: 1px solid #e2e2e2;
    border-radius: 8px;
    padding: 8px 10px;
    max-width: 260px;
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.12);
    position: absolute;
    right: 0;
    bottom: calc(100% + 6px);
    z-index: 5;
}

/* On mobile, hide the info button to avoid clipping issues - works for all contexts */
@media screen and (max-width: 768px) {
    .spannungsfelder details.custom-graph__safezone-info,
    .spannungsfelder .custom-graph__safezone-info,
    .spannungsfelder .statistic .custom-graph__safezone-info,
    .spannungsfelder .swiper-slide .custom-graph__safezone-info {
        display: none !important;
        visibility: hidden !important;
        opacity: 0 !important;
        pointer-events: none !important;
    }
}

@media screen and (min-width: 1201px) {
    .statistic .custom-graph__items {
        /* height: min(400px, 42vh); */
        /* margin-top: -30px; */
    }
}

@media (max-height: 763px) and (min-width: 1200px) {
    .statistic .custom-graph__items {
        height: min(400px, 30vh);
        margin-top: 0;
    }
}

.custom-graph__item {
    text-align: center;
    max-width: 138px;
    position: relative;
    display: flex;
    flex-direction: column-reverse;
    margin: 0 2px -33px;
}

.custom-graph__item input {
    position: absolute;
    width: min(382px, calc(30vh - 19px));
    transform: translateX(-50%) rotate(-90deg) translateX(calc(50% - 93px / 2));
    bottom: 0;
    left: 50%;
    padding: 0;
    margin: 0 0 0;
    -webkit-appearance: none;
    border: 0;
    transition: none;
    height: min(133px, 93px);
    background-color: transparent;
    cursor: pointer;
}

.custom-graph__item input:focus {
    outline: none;
}

.custom-graph__item input::-webkit-slider-runnable-track {
    width: 100%;
    height: 0;
    border: 0;
    cursor: pointer;
    box-shadow: none;
    background: transparent;
    border-radius: 0;
}

.custom-graph__item input::-moz-range-track {
    width: 100%;
    height: 0;
    border: 0;
    cursor: pointer;
    box-shadow: none;
    background: transparent;
    border-radius: 0;
}

.custom-graph__item input::-webkit-slider-thumb {
    box-shadow: none;
    height: 40px;
    width: 40px;
    border-radius: 50%;
    border: 0;
    background-color: transparent;
    cursor: pointer;
    -webkit-appearance: none;
    margin-top: -19px;
    margin-left: 0;
    pointer-events: none;
}

.custom-graph__item input::-moz-range-thumb {
    box-shadow: none;
    height: 40px;
    width: 40px;
    border-radius: 50%;
    border: 0;
    background-color: transparent;
    cursor: pointer;
    -webkit-appearance: none;
    margin-top: -19px;
    margin-left: 0;
    pointer-events: none;
}

.custom-graph__item input::-moz-focus-outer {
    border: 0;
}

.custom-graph__item:hover:before {
    opacity: 0.2;
}

.custom-graph__item:hover .custom-graph__item-circle {
    border-color: var(--ls-alfa-color);
}

.custom-graph__item:hover .custom-graph__item-polygon {
    border-style: dashed;
}

.custom-graph__item:hover.inactive .custom-graph__item-avatar {
    -webkit-animation-name: tada;
    animation-name: tada;
    -webkit-animation-duration: 0.6s;
    animation-duration: 0.6s;
    -webkit-animation-timing-function: ease;
    animation-timing-function: ease;
}

@media screen and (min-width: 1201px) {
    .custom-graph:not(.statistic) .custom-graph__item:after {
        content: " ";
        position: absolute;
        top: 0;
        left: 50%;
        transform: translateX(-50%);
        height: 100%;
        border-right: 2px dashed var(--ls-extra-color);
        pointer-events: none;
        opacity: 0.7;
    }
}

.custom-graph__item:before {
    content: " ";
    background: linear-gradient(to top, #51ceec, transparent);
    position: absolute;
    top: -15px;
    left: 0;
    width: 100%;
    height: calc(100% + 44px);
    z-index: -1;
    opacity: 0;
}

.custom-graph__item:last-child .custom-graph__item-line {
    display: none;
}

.custom-graph__item-head {
    position: absolute;
    transform: translateX(-50%);
    pointer-events: none;
    z-index: 1;
}

.custom-graph__item-polygon {
    position: absolute;
    top: 100%;
    border-right: 2px solid var(--ls-between-color);
    left: 50%;
    transform: translateX(-50%);
    z-index: -1;
}

/* Ensure polygons are behind avatars in statistic view */
.statistic .custom-graph__item-polygon {
    z-index: -1;
}

.custom-graph__item-foot {
    margin-bottom: -117px;
    position: relative;
    z-index: 2;
}

.custom-graph:not(.statistic) .custom-graph__item:not(.inactive) .custom-graph__item-foot {
    filter: grayscale(100%);
    cursor: pointer;
}

.custom-graph__item-circle {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    box-sizing: border-box;
    border: 2px solid var(--ls-accent-2-color);
    transition: var(--ls-transition);
    background-color: var(--ls-thin-color);
}

.custom-graph__item.effect .custom-graph__item-circle {
    -webkit-animation-name: pulse;
    animation-name: pulse;
    -webkit-animation-duration: 0.6s;
    animation-duration: 0.6s;
    -webkit-animation-timing-function: ease;
    animation-timing-function: ease;
}

.custom-graph__item-circle img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.custom-graph__item-count,
.custom-graph__item-side {
    color: #00b8ff;
    font-size: var(--ls-font-small);
    line-height: 36px;
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
}

.custom-graph__item-count {
    bottom: 100%;
}

.custom-graph__item-side[data-dependency]:before {
    position: absolute;
    content: attr(data-dependency);
    background-color: var(--ls-thin-color);
    width: 33px;
    height: 33px;
    top: 1px;
    left: -6px;
    border-radius: 50%;
}

.custom-graph__item-line {
    position: absolute;
    bottom: calc(50% + 16px);
    height: 4px;
    background-color: var(--ls-alfa-color);
    left: 50%;
    width: 0;
    top: 50%;
    z-index: 0;
    pointer-events: none;
}

/* Ensure lines are behind avatars in statistic view */
.statistic .custom-graph__item-line {
    z-index: -1;
}

.custom-graph__item-avatar {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background-color: var(--ls-between-color);
    margin: 0 auto 14px;
    position: relative;
    z-index: 3;
}

.custom-graph__item-avatar img {
    max-height: 60px;
}

.custom-graph__item-name {
    color: var(--ls-between-color);
    font-size: var(--ls-font-small);
    line-height: 22px;
    min-height: 44px;
}

.inactive .custom-graph__item-name {
    color: var(--ls-alfa-color);
}

.custom-graph__status {
    width: 10px;
    position: absolute;
    background: linear-gradient(to top, #fa5252 0%, #E29635 50%, #9FE2BF 100%);
    left: 75px;
    bottom: 0;
    top: 70px;
    height: calc(100% - 220px);
    border-radius: 5px;
    box-shadow: 0 2px 4px rgba(22, 4, 73, 0.1);
    transition: all 0.3s ease;
    z-index: 1;
}

.custom-graph__status-down,
.custom-graph__status-up {
    color: var(--ls-alfa-color);
    font-size: var(--ls-font-base);
    font-weight: 500;
    line-height: 1.4;
    position: absolute;
    right: calc(100% + 20px);
    background-color: var(--ls-thin-color);
    padding: 6px 12px;
    border-radius: 8px;
    box-shadow: 0 2px 6px rgba(22, 4, 73, 0.08);
    white-space: nowrap;
    transition: all 0.3s ease;
    border: 1px solid rgba(22, 4, 73, 0.1);
}

.custom-graph__status-down:hover,
.custom-graph__status-up:hover {
    box-shadow: 0 3px 8px rgba(22, 4, 73, 0.12);
    transform: translateX(-2px);
}

.custom-graph__status-down {
    bottom: -8px;
}

.custom-graph__status-up {
    top: -8px;
    margin-bottom: 30px;
}

.custom-graph__status-middle {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    color: var(--ls-alfa-color);
    font-size: var(--ls-font-small);
    font-weight: 600;
    background-color: var(--ls-thin-color);
    padding: 4px 10px;
    border-radius: 6px;
    box-shadow: 0 2px 4px rgba(22, 4, 73, 0.1);
    white-space: nowrap;
    border: 1px solid rgba(22, 4, 73, 0.15);
    z-index: 10;
}

.custom-graph__status-sub {
    font-size: 12px;
    line-height: 1.3;
    color: #626262;
    margin-top: 4px;
    word-break: break-word;
}

@media screen and (max-width: 1200px) {
    .custom-graph {
        padding-left: 0;
    }
    .custom-graph {
        margin-left: 26px;
    }
    .custom-graph__status {
        position: relative;
        width: 100%;
        height: 10px;
        background: linear-gradient(to right, #fa5252 0%, #E29635 50%, #9FE2BF 100%);
        top: 0;
        left: 0;
        border-radius: 5px;
        box-shadow: 0 2px 4px rgba(22, 4, 73, 0.1);
        z-index: 1;
    }
    .custom-graph__status-down {
        left: 0;
        bottom: calc(100% + 12px);
    }
    .custom-graph__status-up {
        top: calc(100% + 12px);
        right: 0;
        transform: translateX(0);
        z-index: 100;
        position: absolute;
        max-width: calc(100vw - 60px);
        white-space: normal;
        word-wrap: break-word;
        text-align: right;
    }
    .custom-graph__status:first-child .custom-graph__status-down,
    .custom-graph__status:first-child .custom-graph__status-up {
        bottom: calc(100% + 10px);
        top: auto;
    }
    .custom-graph__status:last-child .custom-graph__status-down,
    .custom-graph__status:last-child .custom-graph__status-up {
        top: calc(100% + 10px);
        bottom: auto;
    }
    .custom-graph__items {
        flex-direction: column;
        border-bottom: 0;
        height: auto;
        box-sizing: border-box;
        border-left: 6px solid var(--ls-alfa-color);
        border-radius: 8px 0 0 8px;
        padding-bottom: 0;
        padding-right: 140px;
        padding-top: 50px;
        box-shadow: 4px 0 8px rgba(22, 4, 73, 0.08);
        background: linear-gradient(to right, 
            rgba(81, 206, 236, 0.03) 0%, 
            transparent 100%);
        overflow: visible;
        position: relative;
    }
    /* Hide safezone by default in mobile view (for non-statistic views) */
    .custom-graph__safezone {
        display: none;
        visibility: hidden;
        position: absolute;
        width: 0;
        height: 0;
        opacity: 0;
        pointer-events: none;
    }
    
    /* Show and style safezone only for statistic views in mobile */
    .statistic .custom-graph__safezone {
        display: block;
        visibility: visible;
        /* Position and size will be set by JavaScript safeArea() */
        border-radius: 10px;
        z-index: 0;
        opacity: 1;
        pointer-events: auto;
    }
    .custom-graph__item {
        flex-direction: row;
        align-items: center;
        height: 80px;
        max-width: 100%;
        margin: 0 0 0 15px;
    }
    .custom-graph__item input {
        position: absolute;
        width: calc(100% + 60px);
        left: -30px;
        top: 50%;
        transform: translateY(-50%);
        height: 80%;
        will-change: auto;
        backface-visibility: hidden;
        padding: 0 30px;
        box-sizing: content-box;
    }
    .custom-graph__item:before {
        top: 50%;
        transform: translateY(-50%);
        height: 100%;
        left: -15px;
        background: linear-gradient(to right, #51ceec, transparent);
    }
    .custom-graph:not(.statistic) .custom-graph__item:after {
        content: "" !important;
        display: none !important;
        visibility: hidden !important;
        opacity: 0 !important;
        height: 0 !important;
        width: 0 !important;
        border: none !important;
        position: absolute !important;
        pointer-events: none !important;
    }
    .custom-graph__item:first-child {
        margin-top: 20px;
    }
    .custom-graph__item:last-child {
        margin-bottom: 20px;
    }
    .custom-graph__item-head {
        left: 0;
        top: 50%;
        transform: translateY(-50%);
    }
    .custom-graph__item-line {
        position: absolute;
        height: 2px;
        top: 50%;
        bottom: auto;
        left: 50%;
        width: 0;
        background-color: var(--ls-alfa-color);
        z-index: 0;
        pointer-events: none;
    }
    .custom-graph__item-polygon {
        transform: translateY(-50%);
        top: 50%;
        left: auto;
        right: calc(50% + 25px);
        width: calc(100% - 50px);
        border-right: 0;
        border-top: 2px solid var(--ls-between-color);
        z-index: 0;
        opacity: 0.6;
    }
    
    /* Ensure lines and polygons are behind avatars in statistic view (mobile) */
    .statistic .custom-graph__item-line,
    .statistic .custom-graph__item-polygon {
        z-index: -1;
    }
    .custom-graph__item-foot {
        margin: 0 0 0 -45px;
    }
    .custom-graph__item-avatar {
        margin: 0 auto;
        width: 50px;
        height: 50px;
        position: relative;
        flex-shrink: 0;
        z-index: 3;
    }
    .custom-graph__item-count,
    .custom-graph__item-side {
        position: absolute;
        left: calc(100% + 12px);
        top: 50%;
        transform: translateY(-50%);
        bottom: auto;
        white-space: nowrap;
        z-index: 10;
    }
    .custom-graph__item-name {
        display: none;
    }
    .custom-graph__item-name_mobile {
        color: Black;
        font-size: var(--ls-font-base);
        line-height: 22px;
        margin: auto;
    }
    .custom-graph__item-trace {
        border-top: 2px dashed var(--ls-extra-color);
        position: 272px;
        width: 100%;
        z-index: -1;
    }
}

.custom-graph-info {
    box-sizing: border-box;
    display: flex;
    flex-wrap: wrap;
}

.custom-graph-info__item {
    font-size: var(--ls-h-font-small);
    line-height: 92px;
    text-align: center;
    width: 100px;
    height: 100px;
    border-radius: 50%;
    border: 4px solid #3781ee;
    box-sizing: border-box;
    position: relative;
    margin-bottom: 60px;
}

@media screen and (max-width: 540px) {
    .custom-graph-info__item {
        width: 60px;
        height: 60px;
        line-height: 52px;
        font-size: 24px;
    }
}

.custom-graph-info__item.small {
    color: #ee6331;
}

.custom-graph-info__item.base {
    color: #d4f131;
    margin: 0 60px;
}

.custom-graph-info__item.large {
    color: #45fe39;
}

/* Tooltip icon positioned outside the circle */
.custom-graph-info__tooltip-icon {
    position: absolute;
    top: -12px;
    right: -12px;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background-color: #E29635;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    cursor: help;
    font-size: 16px;
    z-index: 10;
    transition: all 0.2s ease;
}

.custom-graph-info__tooltip-icon:hover {
    background-color: #c7852a;
    transform: scale(1.1);
}

.custom-graph-info__item:before {
    content: attr(data-text);
    color: var(--ls-alfa-color);
    font-size: var(--ls-font-large);
    line-height: 29px;
    position: absolute;
    top: calc(100% + 15px);
    left: 50%;
    transform: translateX(-50%);
}
