/* ==========================================================================
   Animation
   ========================================================================== */

@keyframes ts-button-loading {
    from {
        transform: translate(-50%, -50%) rotate(0deg);
    }
    to {
        transform: translate(-50%, -50%) rotate(360deg);
    }
}

/* ==========================================================================
   Variables
   ========================================================================== */

.ts-button {
    --horizontal-padding: 1.25em;
    --height: var(--ts-input-height-medium);

    --accent-color: initial;
    --accent-foreground-color: initial;

    --border-width: 2px;
    --icon-size: 1.1em;
}

/* ==========================================================================
   Base
   ========================================================================== */

.ts-button {
    position: relative;
    margin: 0;
    width: auto;
    font: inherit;
    outline: none;
    box-sizing: border-box;
    user-select: none;
    text-overflow: ellipsis;
    white-space: nowrap;
    height: var(--height);

    -webkit-font-smoothing: inherit;
    -moz-osx-font-smoothing: inherit;
    appearance: none;
    -webkit-appearance: none;
}

.ts-button:focus {
    outline: 0;
}

.ts-button {
    border: var(--border-width) solid var(--accent-color, var(--ts-gray-800));
    min-width: 75px;
    font-size: var(--ts-font-size-14px);
    line-height: 1.5;
    font-weight: 500;
    color: var(--accent-foreground-color, var(--ts-gray-50));
    background: var(--accent-color, var(--ts-gray-800));
    text-decoration: none;
    display: inline-flex;
    vertical-align: middle;
    justify-content: center;
    align-items: center;
    text-align: center;

    padding: 0 var(--horizontal-padding);
    border-radius: var(--ts-border-radius-element);
}

.ts-button .ts-icon {
    font-size: var(--icon-size);
}

/* ==========================================================================
   Variations
   ========================================================================== */

/**
 * Secondary
 */

.ts-button.is-secondary {
    color: var(--accent-color, var(--ts-gray-800));
    border-color: var(--ts-gray-100);
    background: var(--ts-gray-100);
}

/**
 * Outlined
 */

.ts-button.is-outlined {
    background: transparent;
    border: var(--border-width) solid var(--ts-gray-300);
    color: var(--accent-color, var(--ts-gray-800));
}

/**
 * Negative
 */

.ts-button.is-negative {
    color: white;
    border-color: var(--ts-negative-500);
    background: var(--ts-negative-500);
}

.ts-button.is-negative.is-outlined {
    color: var(--ts-negative-500);
    border-color: var(--ts-gray-300);
    background: transparent;
}

.ts-button.is-negative.is-secondary {
    color: var(--ts-negative-500);
    border-color: var(--ts-gray-100);
    background: var(--ts-gray-100);
}

.ts-button.is-ghost.is-negative {
    color: var(--ts-negative-500);
}

/**
 * Ghost
 */

.ts-button.is-ghost {
    background: transparent;
    color: var(--ts-gray-800);
    border: 2px solid transparent;
}

.ts-button.is-ghost:hover {
    background: var(--ts-gray-100);
}

/**
 * Loading
 */

.ts-button.is-loading,
.ts-button.is-loading.is-negative {
    color: transparent;
}

.ts-button.is-loading .ts-icon {
    visibility: hidden;
}

.ts-button.is-loading::after {
    font-family: "Icons";
    font-weight: normal;
    font-style: normal;
    display: inline;
    text-decoration: inherit;
    text-align: center;
    -webkit-font-smoothing: antialiased;
    backface-visibility: hidden;
    display: inline-block;
    animation: ts-button-loading 2s linear infinite;
    color: var(--ts-gray-50);
    font-size: 1.3em;
    content: "\f110";
    position: absolute;
    top: 50%;
    left: 50%;
}

.ts-button.is-loading:is(.is-outlined, .is-secondary, .is-ghost)::after {
    color: var(--ts-gray-800);
}

/**
 * Sizes
 */

.ts-button.is-small {
    --height: var(--ts-input-height-small);

    font-size: var(--ts-font-size-13px);
}

.ts-button.is-large {
    --height: var(--ts-input-height-large);

    font-size: var(--ts-font-size-16px);
}

/**
 * Disabled
 */

.ts-button:disabled,
.ts-button.is-disabled,
fieldset:disabled .ts-button {
    pointer-events: none;
    opacity: 0.5;
    user-select: none;
}

/**
 * Fluid
 */

.ts-button.is-fluid {
    width: 100%;
}

/**
 * Circular
 */

.ts-button.is-circular {
    border-radius: 100rem;
}

/**
 * Icon
 */

.ts-button.is-icon {
    --icon-size: 1.25em;

    padding: 0;
    min-width: 0;
    width: var(--height);
}

/**
 * Side Icon
 */

.ts-button:is(.is-start-icon, .is-end-icon) .ts-icon::before {
    display: inline-block;
    margin-top: 1px;
}

.ts-button.is-start-icon .ts-icon {
    margin-right: 0.5em;
}

.ts-button.is-end-icon .ts-icon {
    margin-left: 0.5em;
}

/**
 * Labeled Icon
 */

.ts-button:is(.is-start-labeled-icon, .is-end-labeled-icon) .ts-icon {
    position: absolute;
    top: calc(var(--border-width) * -1);
    bottom: calc(var(--border-width) * -1);
    background: rgb(0, 0, 0, 0.035);
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    height: calc(100% + var(--border-width) * 2);
    width: auto;
    aspect-ratio: 1 / 1;
}

.ts-button.is-start-labeled-icon {
    padding-left: calc(var(--horizontal-padding) + var(--height));
}

.ts-button.is-start-labeled-icon .ts-icon {
    left: calc(var(--border-width) * -1);
    border-radius: var(--ts-border-radius-element) 0 0 var(--ts-border-radius-element);
}

.ts-button.is-end-labeled-icon {
    padding-right: calc(var(--horizontal-padding) + var(--height));
}

.ts-button.is-end-labeled-icon .ts-icon {
    right: calc(var(--border-width) * -1);
    border-radius: 0 var(--ts-border-radius-element) var(--ts-border-radius-element) 0;
}

.ts-button.is-outlined:is(.is-start-labeled-icon, .is-end-labeled-icon) .ts-icon {
    background: transparent;
    border: var(--border-width) solid var(--ts-gray-300);
}

/**
 * Dense
 */

.ts-button.is-dense {
    --height: var(--ts-input-height-small);
}
.ts-button.is-dense.is-large {
    --height: var(--ts-input-height-medium);
}

/**
 * Relaxed
 */

.ts-button.is-relaxed {
    --height: var(--ts-input-height-large);
}

/**
 * Wide
 */

.ts-button.is-short {
    --horizontal-padding: 0.75em;

    min-width: 65px;
}
.ts-button.is-wide {
    --horizontal-padding: 2em;
}

/**
 * Buttons
 */

.ts-buttons {
    display: flex;
}

.ts-buttons .ts-button:first-child {
    border-top-right-radius: 0;
    border-bottom-right-radius: 0;
}

.ts-buttons .ts-button:not(:first-child):not(:last-child) {
    border-radius: 0;
}

.ts-buttons .ts-button:not(:first-child)::before {
    position: absolute;
    content: "";
    top: 50%;
    transform: translateY(-50%);
    left: -2px;
    height: 50%;
    background: var(--ts-gray-600);
    width: 1px;
}

.ts-buttons .ts-button.is-icon:not(:first-child) {
    width: calc(var(--height) * 1.1); /** divider visual balance */
}

.ts-buttons .ts-button.is-outlined::before {
    display: none;
}

.ts-buttons .ts-button.is-negative::before {
    background: var(--ts-negative-400);
}

.ts-buttons .ts-button.is-secondary::before {
    background: var(--ts-gray-400);
}

.ts-buttons .ts-button:last-child {
    border-bottom-left-radius: 0;
    border-top-left-radius: 0;
}

.ts-buttons .ts-button.is-outlined + .ts-button.is-outlined {
    border-left-color: transparent;
}
