@-moz-keyframes spin {
    100% {
        -moz-transform: rotate(360deg);
    }
}

@-webkit-keyframes spin {
    100% {
        -webkit-transform: rotate(360deg);
    }
}

@keyframes spin {
    100% {
        -webkit-transform: rotate(360deg);
        transform: rotate(360deg);
    }
}

.otys_page_otys_settings.otys_page_otys_settings .notice {
    position: sticky;
    top: 50px;
    z-index: 99;
}

.otys-dashboard {
    margin-block: 30px;
    display: grid;
    grid-template-columns: repeat(3, 1fr);

    &-w {
        background: #FFF;
        text-align: center;
        padding: 30px;
        border: 1px solid #c3c4c7;
        border-radius: 4px;
        font-size: 20px;

        label {
            margin-block-end: 10px;
            display: block;
        }

        &-text {
            font-weight: bold;
        }
    }
}

form p.submit:after {
    content: '';
    mask-image: url(../../images/admin/loader-solid.svg);
    -webkit-mask-image: url(../../images/admin/loader-solid.svg);
    width: 10px;
    height: 10px;
    background: #2271b1;
    display: block;
    display: inline-block;
    margin-left: 5px;
    opacity: 0;
    transition: .2s ease-in;
}

form.loading p.submit:after {
    opacity: 1;
    -webkit-animation: spin 2s linear infinite;
    -moz-animation: spin 2s linear infinite;
    animation: spin 2s linear infinite;
    width: 15px;
    height: 15px;
}

.otys-correct-api-key:before {
    content: '';
    margin-right: 5px;
    width: 8px;
    height: 8px;
    display: inline-block;
    background: #177f43;
    border-radius: 100%;
}

.otys-error-message {
    padding: 5px 10px;
    border: 1px solid #d63638;
    display: inline-block;
    margin: 10px 0 0 0;
    border-radius: 3px;
    background: #f6f7f7;
}

.otys-settings-tab-inner {
    max-width: 1000px;
    padding: 8px 16px 4px;
    box-sizing: border-box;
}

/* repeater */
.repeating-list {
    margin-block-start: 30px;

    .repeating-item {
        margin-top: 10px;
        margin-bottom: 10px;
        margin-block: 10px;
        display: flex;
        align-items: center;
        background: #FFF;
        padding: 5px 10px;
        border-radius: 3px;
        border: 1px solid #dcdcde;
        justify-content: space-between;
        white-space: nowrap;

        &-col {
            margin-inline: 5px;
            padding-block: 5px;

            &--url {
                padding-inline: 10px;
                border: 1px solid #dcdcdc;
                border-radius: 3px;
                margin-left: -5px;
                display: flex;
                align-items: center;
            }
        }
    }
}

/* instructions */
.otys-instructions {
    background: #FFF;
    border: 1px solid #dcdcde;
    border-collapse: collapse;
    width: 100%;
}

.otys-instructions th:first-child {
    width: 15%;
}

.otys-instructions th[colspan="2"] {
    width: 40%;
}

.otys-instructions th {
    width: 20%;
}

.otys-instructions~.otys-instructions {
    margin-top: 30px;
}

.otys-instructions tr:first-of-type th {
    background-color: #2c3338;
    color: #FFF;
}

.otys-instructions th {
    padding: 10px 10px;
    background: #f6f7f7;
    border-bottom: 1px solid #dcdcde;
    text-align: left;
}

.otys-instructions tr td {
    padding: 10px 10px;
}

.otys-instructions tr:not(:last-of-type) td {
    border-bottom: 1px solid #dcdcde;
}

.otys-instructions tr td code~code {
    margin-top: 4px;
    display: inline-block;
}

#instructions-iframe {
    width: 100%;
    height: 100vh;
}

/*
    Toggle
*/
.otys-sortable {
    background: #FFF;
    margin: 5px 0;
    width: 300px;
    display: flex;
    align-items: center;
    padding: 5px 60px 5px 10px;
    text-align: left;
    position: relative;
    cursor: move;
    cursor: grab;
    cursor: -moz-grab;
    cursor: -webkit-grab;
    transition: .1s ease-in-out;
    border: 1px solid #dcdcde;
    border-radius: 5px;

    input[type="hidden"] {
        display: none;
    }

    input[type="text"] {
        width: 100%;
    }
}

.otys-sortable.sortable-chosen {
    transform: scale(0.95) !important;
    box-shadow: rgb(0 0 0 / 16%) 0px 0px 4px 0px;
}

.otys-sortable svg {
    height: 22px;
    margin-inline-end: 10px;
    flex-shrink: 0;
}

.otys-sortable-list input[type=checkbox] {
    height: 0;
    width: 0;
    visibility: hidden;
}

.otys-sortable input[type=checkbox]:checked::before {
    display: none;
}

.otys-sortable-list.otys-sortable-list label {
    cursor: pointer;
    text-indent: -9999px;
    width: 40px;
    height: 21px;
    background: grey;
    display: block;
    border-radius: 100px;
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    margin: 0 !important;

    &[disabled] {
        cursor: not-allowed;
        opacity: 0.4;
      
    }
}

.otys-sortable-list label:after {
    content: '';
    position: absolute;
    top: 3px;
    left: 3px;
    width: 15px;
    height: 15px;
    background: #fff;
    border-radius: 90px;
    transition: 0.3s;
}

.otys-sortable-list input:checked+label {
    background: #3582c4;
}

input:checked+label:after {
    left: calc(100% - 3px);
    transform: translateX(-100%);
}

.otys-sortable-list label:active:after {
    width: 34px;
}

/*
* Settings tabs. Same chrome as the rate limits tabs.
*/
.otys-settings-tab-inner th:empty {
    display: none !important;
}

.otys-settings-tab-inner th:empty+td {
    padding: 0 !important;
}

.otys-settings-tabs button:disabled {
    color: #a7aaad;
    cursor: not-allowed;
}

.otys-settings-tab-count {
    background: #d63638;
    color: #fff;
}

/**
    Settings
**/
.otys-cb-image-preview img {
    height: auto !important;
}

.otys-admin-message {
    text-align: center;
    height: calc(100vh - 100px);
    display: flex;
    align-items: center;
    justify-content: center;
}

/*
 * Logs page
 */
.otys-logs-dashboard {
    grid-template-columns: repeat(6, 1fr);
}

.otys-logs-dashboard__item--error {
    border-top: 3px solid #d63638;
}

.otys-logs-dashboard__item--warning {
    border-top: 3px solid #dba617;
}

.otys-logs-dashboard__item--notice {
    border-top: 3px solid #c9a800;
}

.otys-logs-dashboard__item--info {
    border-top: 3px solid #2271b1;
}

.otys-logs-dashboard__item--debug {
    border-top: 3px solid #787c82;
}

.otys-logs-dashboard__item--total {
    border-top: 3px solid #2c3338;
}

.otys-logs-dashboard__item--size {
    border-top: 3px solid #8c8f94;
}

.otys-logs-toolbar {
    display: flex;
    justify-content: space-between;
    margin-bottom: 30px;
    align-items: center;
    gap: 16px;

    > .description {
        margin: 0;
        max-width: 720px;
    }
}

form.otys-logs-filters {
    display: flex;
    align-items: center;
    gap: 8px;

    select {
        min-width: 140px;
    }
}

.otys-logs-search {
    min-width: 220px;
}

.otys-logs-table {
    .otys-logs-table__col--level {
        width: 80px;
    }

    .otys-logs-table__col--category {
        width: 100px;
    }

    .otys-logs-table__col--source {
        width: 180px;
    }

    .otys-logs-table__col--status {
        width: 70px;
        text-align: center;
    }

    .otys-logs-table__col--remaining {
        width: 120px;
        text-align: center;
    }

    .otys-logs-table__col--time {
        width: 130px;
        white-space: nowrap;
    }

    .otys-logs-table__col--actions {
        width: 70px;
        text-align: center;
    }
}

.otys-log-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 3px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    line-height: 1.6;

    &--error {
        background: #fcf0f1;
        color: #d63638;
        border: 1px solid #d63638;
    }

    &--warning {
        background: #fcf9e8;
        color: #996800;
        border: 1px solid #dba617;
    }

    &--notice {
        background: #fef8e7;
        color: #8a6d00;
        border: 1px solid #c9a800;
    }

    &--info {
        background: #f0f6fc;
        color: #2271b1;
        border: 1px solid #2271b1;
    }

    &--debug {
        background: #f0f0f1;
        color: #50575e;
        border: 1px solid #8c8f94;
    }

    &--success {
        background: #e7f5e8;
        color: #1e4620;
        border: 1px solid #68b36b;
    }
}

.otys-log-category {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 3px;
    font-size: 11px;
    font-weight: 500;
    background: #f0f0f1;
    color: #2c3338;
    border: 1px solid #c3c4c7;

    &--webapi {
        background: #e7f5e8;
        color: #1e4620;
        border-color: #68b36b;
    }

    &--api {
        background: #f0f6fc;
        color: #1d4267;
        border-color: #72aee6;
    }

    &--webhook {
        background: #f5edfc;
        color: #4c2882;
        border-color: #a68bdb;
    }

    &--migration {
        background: #fef0e5;
        color: #6e3500;
        border-color: #e68a3f;
    }

    &--cache {
        background: #e5f5f5;
        color: #1a5252;
        border-color: #5bb5b5;
    }
}

.otys-log-status {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 3px;
    font-size: 11px;
    font-weight: 600;
    font-family: monospace;

    &--success {
        background: #e7f5e8;
        color: #1e4620;
    }

    &--warning {
        background: #fcf9e8;
        color: #996800;
    }

    &--error {
        background: #fcf0f1;
        color: #d63638;
    }

    &--none {
        color: #a7aaad;
    }
}

.otys-log-source {
    font-size: 12px;
    background: #f6f7f7;
    padding: 2px 6px;
    border-radius: 3px;
    word-break: break-all;
}

.otys-log-time-ago {
    display: block;
    font-size: 13px;
}

.otys-log-time-full {
    display: block;
    font-size: 11px;
    color: #787c82;
}

.otys-log-no-context {
    color: #a7aaad;
    text-align: center;
    display: block;
}

.otys-logs-row--error {
    border-left: 3px solid #d63638;
}

.otys-logs-row--warning {
    border-left: 3px solid #dba617;
}

.otys-logs-row--notice {
    border-left: 3px solid #c9a800;
}

td.otys-logs-context-cell {
    max-width: 100%;
    overflow: auto;
    padding: 12px 20px !important;
    background: #f6f7f7;
}

.otys-logs-context-section {
    max-width: 500px;
    margin-bottom: 12px;

    &:last-child {
        margin-bottom: 0;
    }

    strong {
        display: block;
        margin-bottom: 6px;
        font-size: 12px;
        text-transform: uppercase;
        letter-spacing: 0.3px;
        color: #50575e;
    }
}

.otys-logs-context-pre {
    background: #fff;
    border: 1px solid #dcdcde;
    border-radius: 3px;
    padding: 12px;
    margin: 0;
    font-size: 12px;
    line-height: 1.5;
    overflow-x: auto;
    max-height: 400px;
    overflow-y: auto;
    white-space: pre-wrap;
    word-break: break-word;
}

.otys-logs-empty {
    background: #fff;
    border: 1px solid #c3c4c7;
    border-radius: 4px;
    padding: 40px;
    text-align: center;
    color: #787c82;
    margin-top: 16px;
}

.otys-logs-toolbar-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.otys-logs-live-toggle {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.otys-logs-live-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #787c82;
    transition: background-color 0.2s ease;
}

.otys-logs-live-toggle--active .otys-logs-live-dot {
    background: #00a32a;
    animation: otys-logs-pulse 1.5s ease-in-out infinite;
}

@keyframes otys-logs-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

.otys-logs-live-indicator {
    font-size: 12px;
    color: #00a32a;
    font-style: italic;
}

@keyframes otys-logs-row-enter {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes otys-logs-cell-highlight {
    from {
        background-color: rgba(34, 113, 177, 0.1);
    }
    to {
        background-color: inherit;
    }
}

.otys-logs-row--new {
    animation: otys-logs-row-enter 0.35s ease-out;

    > td {
        animation: otys-logs-cell-highlight 2s ease-out;
    }
}

.otys-rate-limits-explainer {
    background: #fff;
    border: 1px solid #007aff;
    border-radius: 4px;
    margin-top: 16px;
    padding: 10px 16px 12px;

    h2 {
        margin: 0;
        font-size: 16px;
    }

    p {
        margin: 8px 0 0;
        color: #50575e;
    }

    &__toggle {
        display: flex;
        align-items: center;
        gap: 8px;
        width: 100%;
        margin: 0;
        padding: 0;
        border: 0;
        background: transparent;
        box-shadow: none;
        color: #1d2327;
        font: inherit;
        font-size: 16px;
        font-weight: 600;
        line-height: 1.3;
        text-align: left;
        cursor: pointer;

        .dashicons-info {
            color: #007aff;
            font-size: 20px;
            width: 20px;
            height: 20px;
        }

        &:focus-visible {
            outline: 2px solid #007aff;
            outline-offset: 2px;
        }
    }

    &__chevron {
        margin-left: auto;
        color: #646970;
        transition: transform 0.15s ease;
    }

    &.is-open &__chevron {
        transform: rotate(180deg);
    }

    &.is-open &__summary {
        display: none;
    }
}

@media (prefers-reduced-motion: reduce) {
    .otys-rate-limits-explainer__chevron {
        transition: none;
    }
}

.otys-rate-limits-dashboard {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
    margin-block: 16px 0;

    &--single {
        grid-template-columns: minmax(0, 1fr);
    }

    .otys-dashboard-w {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 16px;
        text-align: left;
        padding: 14px 18px;
        font-size: 13px;
    }

    .otys-rate-limits-stat {
        min-width: 0;

        label {
            margin: 0;
            font-size: 13px;
            font-weight: 600;
        }
    }

    .otys-dashboard-w-text {
        font-size: 22px;
        font-variant-numeric: tabular-nums;
        white-space: nowrap;
    }

    .description {
        font-size: 13px;
        font-weight: 400;
        color: #50575e;
        margin: 2px 0 0;
    }
}

.otys-rate-limits-panel,
.otys-settings-panel {
    margin-top: 16px;
    background: #fff;
    border: 1px solid #c3c4c7;
    border-radius: 4px;

    .otys-logs-toolbar {
        flex-wrap: wrap;
        margin: 0;
        padding: 12px 14px;
    }

    .otys-logs-empty {
        margin: 0;
        padding: 8px 14px 20px;
        border: 0;
        border-radius: 0;
        background: transparent;
    }

    .tablenav {
        display: flex;
        justify-content: flex-end;
        clear: both;
        height: auto;
        margin: 0;
        padding: 12px 14px;
        overflow: hidden;
    }

    .tablenav .tablenav-pages {
        float: none;
        margin: 0;
    }
}

.otys-rate-limits-tabs,
.otys-settings-tabs {
    display: flex;
    flex-wrap: wrap;
    padding: 8px 8px 0;
    border-bottom: 1px solid #c3c4c7;

    button {
        margin: 0 0 -1px;
        padding: 10px 12px;
        border: 1px solid transparent;
        border-bottom: 0;
        background: transparent;
        box-shadow: none;
        color: #2271b1;
        font-size: 13px;
        line-height: 1.4;
        cursor: pointer;

        &[aria-selected="true"] {
            background: #fff;
            border-color: #c3c4c7;
            border-bottom: 1px solid #fff;
            color: #1d2327;
            font-weight: 600;
        }

        &:focus-visible {
            outline: 2px solid #007aff;
            outline-offset: 2px;
        }
    }
}

.otys-rate-limits-count {
    display: inline-block;
    min-width: 1.4em;
    margin-left: 6px;
    padding: 0 6px;
    border-radius: 10px;
    background: #f0f0f1;
    color: #50575e;
    font-size: 11px;
    font-weight: 600;
    line-height: 18px;
    text-align: center;
}

.otys-rate-limits-scroll {
    max-height: 280px;
    margin: 0 14px 14px;
    overflow: auto;
    border: 1px solid #c3c4c7;
    border-radius: 4px;

    .wp-list-table {
        margin: 0;
        border: 0;
        border-collapse: separate;
        border-spacing: 0;
    }

    thead th {
        position: sticky;
        top: 0;
        z-index: 1;
        background: #f6f7f7;
    }

    .otys-logs-table__col--time .otys-log-time-full {
        display: none;
    }
}

.otys-rate-limits-meta {
    display: block;
    max-width: 220px;
    overflow: hidden;
    font-size: 12px;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.otys-rate-limits-blocked {
    color: #b32d2e;
    font-weight: 600;
}

.otys-rate-limits-mail {
    margin: 12px 0 0;
    color: #646970;
    font-size: 13px;

    .button {
        margin-left: 6px;
        vertical-align: baseline;
    }
}

.otys-admin-stats {
    grid-template-columns: minmax(0, 1fr);
    gap: 16px;
    margin-block: 16px 0;

    .otys-dashboard-w {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 16px;
        text-align: left;
        padding: 14px 18px;
        font-size: 13px;
    }

    .otys-admin-stat label {
        margin: 0;
        font-size: 13px;
        font-weight: 600;
    }

    .otys-dashboard-w-text {
        font-size: 22px;
        font-variant-numeric: tabular-nums;
        white-space: nowrap;
    }
}

.otys-admin-panel {
    margin-top: 16px;
    background: #fff;
    border: 1px solid #c3c4c7;
    border-radius: 4px;

    > h2 {
        margin: 0;
        padding: 14px 14px 12px;
        font-size: 16px;
    }

    > h2 + .otys-logs-toolbar {
        padding-top: 0;
    }

    .otys-logs-toolbar {
        flex-wrap: wrap;
        margin: 0;
        padding: 12px 14px;
    }

    .otys-logs-toolbar-actions {
        margin-left: auto;
    }

    .otys-logs-empty {
        margin: 0;
        padding: 4px 14px 20px;
        border: 0;
        border-radius: 0;
        background: transparent;
    }

    .tablenav {
        display: flex;
        justify-content: flex-end;
        clear: both;
        height: auto;
        margin: 0;
        padding: 12px 14px;
        overflow: hidden;
    }

    .tablenav .tablenav-pages {
        float: none;
        margin: 0;
    }

    > table.wp-list-table {
        margin: 0;
        border: 0;
        box-shadow: none;
    }

    > table.wp-list-table > thead > tr > th,
    > table.wp-list-table > tbody > tr > td,
    > table.wp-list-table > tfoot > tr > td {
        border-left: 0;
        border-right: 0;
    }

    &--form {
        padding: 4px 16px 8px;
    }

    &--message .otys-admin-message {
        height: auto;
        padding: 32px 16px;
    }
}

.otys-admin-scroll {
    max-height: 280px;
    margin: 0;
    overflow: auto;
    border: 0;
    border-radius: 0;

    .wp-list-table {
        margin: 0;
        border: 0;
        box-shadow: none;
        border-collapse: separate;
        border-spacing: 0;
    }

    .wp-list-table > thead > tr > th,
    .wp-list-table > tbody > tr > td,
    .wp-list-table > tfoot > tr > td {
        border-left: 0;
        border-right: 0;
    }

    thead th {
        position: sticky;
        top: 0;
        z-index: 1;
        background: #f6f7f7;
    }
}