/*
 * GPL Keyword Density Checker — tool-only UI.
 * Shared chrome (.gpl-tool, .mt-stat-card, .mt-results-card, .mt-dt-top, .mt-result-table,
 * .gpl-tag, form controls, buttons) comes from the GPL theme and is not duplicated here.
 * The mode switch, result tabs and toolbar layout match GPL Broken Link Checker.
 */

/* --- Mode switch (URL | text) --- */

.gplkdc-mode-switch {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 1em;
    margin: 0 0 1em !important;
    padding: 0;
    border: 0;
}

.gplkdc-mode-switch label {
    display: block;
    margin: 0;
    cursor: pointer;
}

.gplkdc-mode-switch input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.gplkdc-mode-switch span {
    position: relative;
    display: flex;
    min-height: 64px;
    padding: 1em 1em 1em 3.25em;
    flex-direction: column;
    justify-content: center;
    gap: 2px;
    border: 1px solid var(--gpl-tool-card-line, #e5e7eb);
    border-radius: var(--gpl-tool-radius, 8px);
    background: var(--gpl-tool-surface, #fff);
    text-align: left;
    transition: border-color .15s ease, background .15s ease;
}

.gplkdc-mode-switch span:hover {
    border-color: var(--gpl-tool-line-hover, #c5cad3);
}

.gplkdc-mode-switch span::before {
    content: "";
    position: absolute;
    left: 1em;
    top: 50%;
    width: 20px;
    height: 20px;
    border: 2px solid #1d2128;
    border-radius: 50%;
    background: #fff;
    transform: translateY(-50%);
    transition: border-color .15s ease, background .15s ease;
}

.gplkdc-mode-switch span:hover::before {
    border-color: #8c95a5;
}

.gplkdc-mode-switch input:checked + span {
    border-color: var(--gpl-tool-blue, #3e63dd);
    background: var(--gpl-tool-blue-bg, #f4f7ff);
}

.gplkdc-mode-switch input:checked + span::before {
    border-color: #1d2128;
    background: #1d2128;
}

.gplkdc-mode-switch input:checked + span::after {
    content: "";
    position: absolute;
    left: calc(1em + 2px);
    top: 50%;
    width: 16px;
    height: 16px;
    border: 2px solid #fff;
    border-radius: 50%;
    background: #1d2128;
    transform: translateY(-50%);
}

.gplkdc-mode-switch input:focus-visible + span {
    outline: 3px solid var(--gpl-tool-focus-ring, #93c5fd);
    outline-offset: 2px;
}

.gplkdc-mode-switch strong {
    color: var(--gpl-tool-ink, #1f2937);
    font-size: 1rem;
    font-weight: 600;
    line-height: 1.35;
}

.gplkdc-mode-switch small {
    color: var(--gpl-tool-text-soft, #6b7280);
    font-size: 0.875rem;
    line-height: 1.35;
}

/* --- Fields --- */

.gplkdc-fields {
    display: grid;
    gap: 1em;
}

.gplkdc-field.form-control {
    align-items: stretch;
    gap: 0.75em;
}

.gplkdc-field > label {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.5em;
    margin: 0;
}

.gplkdc-tool .gplkdc-field textarea {
    width: 100%;
    min-height: 220px;
    margin: 0;
    padding: 14px 16px;
    line-height: 1.6;
    resize: vertical;
}

.gplkdc-input-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1em;
    color: var(--gpl-tool-text-soft, #6b7280);
    font-size: 0.875rem;
}

.gplkdc-input-actions {
    display: inline-flex;
    flex: 0 0 auto;
    gap: 1em;
}

.gplkdc-tool .gplkdc-text-button {
    min-width: 0;
    height: auto;
    margin: 0;
    padding: 0 !important;
    border: 0 !important;
    background: transparent !important;
    box-shadow: none !important;
    color: var(--gpl-tool-blue, #3e63dd) !important;
    font: inherit;
    font-weight: 600;
    line-height: inherit;
    text-decoration: underline;
    text-transform: none;
    white-space: nowrap;
    cursor: pointer;
}

.gplkdc-tool .gplkdc-text-button:hover {
    text-decoration: none;
}

.gplkdc-options {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 0.75em 1.5em;
    flex-wrap: wrap;
    min-height: 50px;
    padding: 1em 0;
    font-size: 14px;
}

.gplkdc-check {
    display: inline-flex;
    align-items: center;
    gap: 0.5em;
    margin: 0;
    font-size: 14px;
    cursor: pointer;
}

.gplkdc-tool .motta-alert {
    margin-bottom: 10px;
    text-align: start;
}

/* --- Results --- */

.gplkdc-results {
    padding: 10px 0;
    color: var(--gpl-tool-ink, #1f2937);
    font-size: 14px;
    scroll-margin-top: 20px;
}

.gplkdc-results:focus {
    outline: none;
}

.gplkdc-source {
    margin: 6px 0 16px;
}

.gplkdc-source .gpl-tag {
    gap: 6px;
}

.gplkdc-source .gplkdc-source-url {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.gplkdc-note {
    margin: 0 0 16px;
    padding: 10px 16px;
    border: 1px solid #f5c78a;
    border-radius: 8px;
    background: #fff4e5;
    color: #92400e;
    font-size: 13px;
    line-height: 1.45;
}

/* --- Focus keyword + keyword cloud --- */

.gplkdc-insights {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 16px;
    margin: 0 0 18px;
}

.gplkdc-insights.has-focus {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
}

.gplkdc-card {
    padding: 16px;
}

.gplkdc-card-head {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 8px 12px;
    margin-bottom: 12px;
}

.gplkdc-tool .gplkdc-card-title {
    margin: 0;
    color: var(--gpl-tool-ink, #1f2937);
    font-size: 1rem;
    font-weight: 600;
    line-height: 1.35;
}

.gplkdc-focus-phrase {
    color: var(--gpl-tool-blue, #4166e1);
    word-break: break-word;
}

.gplkdc-card-hint,
.gplkdc-muted {
    margin: 0;
    color: var(--gpl-tool-muted, #6b7280);
    font-size: 13px;
}

.gplkdc-focus-stats {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 24px;
    font-size: 15px;
}

.gplkdc-focus-stats strong {
    font-weight: 600;
}

.gplkdc-focus-tip {
    margin: 8px 0 12px;
    color: var(--gpl-tool-text-soft, #666);
    font-size: 13px;
    line-height: 1.5;
}

.gplkdc-focus-where {
    margin: 0 0 8px;
    color: var(--gpl-tool-label, #374151);
    font-size: 13px;
    font-weight: 600;
}

.gplkdc-checks {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px 16px;
    margin: 0;
    padding: 0;
    list-style: none;
    font-size: 13px;
}

.gplkdc-checks li {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 0;
}

.gplkdc-checks li.is-yes i {
    color: var(--gpl-tool-green, #0f9a7b);
}

.gplkdc-checks li.is-no {
    color: var(--gpl-tool-muted, #6b7280);
}

.gplkdc-checks li.is-no i {
    color: #f21951;
}

.gplkdc-cloud {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
}

.gplkdc-tool .gplkdc-cloud-word {
    display: inline-flex;
    align-items: baseline;
    gap: 6px;
    width: auto;
    min-width: 0;
    height: auto;
    min-height: 0;
    margin: 0;
    padding: 4px 10px;
    border: 1px solid var(--gpl-tool-blue-line, #4166e140);
    border-radius: 3px;
    background: var(--gpl-tool-blue-tint, #4166e114);
    box-shadow: none;
    color: var(--gpl-tool-blue, #4166e1);
    font-family: inherit;
    font-weight: 500;
    line-height: 1.3;
    letter-spacing: normal;
    text-transform: none;
    cursor: pointer;
    transition: border-color .15s ease, background-color .15s ease;
}

.gplkdc-tool .gplkdc-cloud-word.is-size-1 { font-size: 12px; }
.gplkdc-tool .gplkdc-cloud-word.is-size-2 { font-size: 13.5px; }
.gplkdc-tool .gplkdc-cloud-word.is-size-3 { font-size: 15px; }
.gplkdc-tool .gplkdc-cloud-word.is-size-4 { font-size: 17px; font-weight: 600; }
.gplkdc-tool .gplkdc-cloud-word.is-size-5 { font-size: 19px; font-weight: 600; }

/* !important: the theme paints every button:hover with the primary fill. */
.gplkdc-tool .gplkdc-cloud-word:hover,
.gplkdc-tool .gplkdc-cloud-word:focus {
    border-color: var(--gpl-tool-blue, #4166e1) !important;
    background: rgba(65, 102, 225, .16) !important;
    box-shadow: none !important;
    color: #1f3fae !important;
}

.gplkdc-tool .gplkdc-cloud-word:focus-visible {
    outline: 3px solid var(--gpl-tool-focus-ring, rgba(65, 102, 225, .28));
    outline-offset: 2px;
}

.gplkdc-cloud-count {
    color: var(--gpl-tool-muted, #6b7280);
    font-size: 11px;
    font-weight: 500;
}

/* --- Result tabs: same design as the Domain Age / Broken Link checkers --- */

.gplkdc-views {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 28px 36px;
    padding: 16px 16px 0;
    border-bottom: 1px solid #ecf0f4;
    background: #fff;
}

.gplkdc-tool .gplkdc-view {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: 10px;
    width: auto;
    min-width: 0;
    height: auto;
    min-height: 0;
    margin: 0;
    padding: 0 0 6px;
    border: 0;
    border-radius: 0;
    background: transparent;
    box-shadow: none;
    color: #7c818b;
    font: inherit;
    font-size: 16px;
    font-weight: 500;
    line-height: 1.2;
    letter-spacing: 0;
    text-transform: none;
    white-space: nowrap;
    cursor: pointer;
    appearance: none;
    -webkit-appearance: none;
}

.gplkdc-view-label {
    display: inline-flex;
    align-items: baseline;
    gap: 6px;
}

.gplkdc-view-count {
    color: inherit;
    font-size: 12.8px;
    font-weight: 400;
    line-height: 1;
}

.gplkdc-tool .gplkdc-view::after {
    content: "";
    position: absolute;
    z-index: 1;
    bottom: -1px;
    left: 0;
    width: 0;
    height: 2px;
    background: #1d2128;
    transition: width .3s;
}

.gplkdc-tool .gplkdc-view:hover,
.gplkdc-tool .gplkdc-view:focus,
.gplkdc-tool .gplkdc-view:active,
.gplkdc-tool .gplkdc-view.is-active {
    border: 0 !important;
    background: transparent !important;
    box-shadow: none !important;
    color: #f97248 !important;
}

.gplkdc-tool .gplkdc-view:hover::after,
.gplkdc-tool .gplkdc-view:focus-visible::after,
.gplkdc-tool .gplkdc-view.is-active::after {
    width: 100%;
    background: #f97248;
}

.gplkdc-tool .gplkdc-view:focus-visible {
    outline: 2px solid #f97248;
    outline-offset: 2px;
}

/* --- Toolbar --- */

.gplkdc-tool .mt-dt-top input,
.gplkdc-tool .mt-dt-top select {
    min-height: 0;
    box-shadow: none;
}

.gplkdc-tool .mt-dt-top .dt-button {
    white-space: nowrap;
}

.gplkdc-tool .mt-dt-top .gplkdc-dt-left {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 16px;
    order: 0;
    margin-right: auto;
}

.gplkdc-tool .mt-dt-top .dt-buttons {
    order: 1;
}

.gplkdc-tool .mt-dt-top .mt-dt-top-right {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 12px;
    order: 2;
}

.gplkdc-tool .dt-button i.success {
    color: green !important;
}

/* --- Table --- */

.gplkdc-table th,
.gplkdc-table td {
    vertical-align: middle;
}

.gplkdc-table .gplkdc-col-index {
    width: 56px;
    color: var(--gpl-tool-muted, #6b7280);
}

.gplkdc-table td.gplkdc-keyword {
    font-weight: 500;
    word-break: break-word;
}

.gplkdc-table td.gplkdc-count {
    font-variant-numeric: tabular-nums;
}

.gplkdc-table .gplkdc-col-density {
    min-width: 170px;
}

.gplkdc-table .gplkdc-col-loc {
    width: 92px;
    text-align: center !important;
}

.gplkdc-table td.gplkdc-col-loc.is-yes {
    color: var(--gpl-tool-green, #0f9a7b);
}

.gplkdc-table td.gplkdc-col-loc.is-no {
    color: #c3c8d0;
}

.gplkdc-tool .gplkdc-sort {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    width: auto;
    min-width: 0;
    height: auto;
    min-height: 0;
    margin: 0;
    padding: 0;
    border: 0;
    background: transparent;
    box-shadow: none;
    color: inherit;
    font: inherit;
    font-weight: inherit;
    letter-spacing: inherit;
    text-transform: inherit;
    cursor: pointer;
}

.gplkdc-tool .gplkdc-sort:hover,
.gplkdc-tool .gplkdc-sort:focus {
    border: 0 !important;
    background: transparent !important;
    box-shadow: none !important;
    color: var(--gpl-tool-blue, #4166e1) !important;
}

.gplkdc-tool .gplkdc-sort:focus-visible {
    outline: 2px solid var(--gpl-tool-blue, #4166e1);
    outline-offset: 2px;
}

.gplkdc-sort i {
    color: #b0b6c0;
    font-size: 11px;
}

.gplkdc-sort.is-active i {
    color: inherit;
}

.gplkdc-density {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    width: 100%;
}

.gplkdc-bar {
    position: relative;
    flex: 0 1 120px;
    min-width: 40px;
    height: 6px;
    overflow: hidden;
    border-radius: 4px;
    background: #e6e9f1;
}

.gplkdc-bar span {
    display: block;
    height: 100%;
    border-radius: 4px;
    background: var(--gpl-tool-blue, #4166e1);
}

.gplkdc-density-value {
    min-width: 52px;
    font-variant-numeric: tabular-nums;
}

.gplkdc-table tr.is-warn .gplkdc-bar span {
    background: #edb200;
}

.gplkdc-table tr.is-warn .gplkdc-density-value {
    color: #b7860a;
    font-weight: 600;
}

.gplkdc-table tr.is-high .gplkdc-bar span {
    background: #f21951;
}

.gplkdc-table tr.is-high .gplkdc-density-value,
.gplkdc-table tr.is-high .gplkdc-density i {
    color: #f21951;
    font-weight: 600;
}

.gplkdc-no-row td {
    padding: 24px;
    color: var(--gpl-tool-muted, #6b7280);
    text-align: center !important;
}

/* --- Responsive --- */

@media (max-width: 1024px) {
    .gplkdc-insights.has-focus {
        grid-template-columns: minmax(0, 1fr);
    }
}

/* The theme gives every results table min-width: 960px below 1060px (DAPA has many columns).
   This table has 4 columns (text) or 8 (URL), so it only needs room for those. */
@media (max-width: 1060px) {
    .gplkdc-tool .mt-table-scroll .gplkdc-table {
        min-width: 0;
    }

    .gplkdc-tool .mt-table-scroll .gplkdc-table.is-url {
        min-width: 680px;
    }
}

@media (max-width: 820px) {
    .gplkdc-views {
        gap: 18px 24px;
        padding: 12px 12px 0;
    }

    .gplkdc-tool .gplkdc-view {
        font-size: 15px;
    }
}

@media (max-width: 640px) {
    .gplkdc-mode-switch {
        grid-template-columns: 1fr;
    }

    .gplkdc-options {
        align-items: flex-start;
        flex-direction: column;
        gap: 0.75em;
    }

    .gplkdc-checks {
        grid-template-columns: 1fr;
    }

    /* Phones: #, keyword, count and density fit on screen; the URL-mode check columns scroll. */
    .gplkdc-tool .gplkdc-table thead th,
    .gplkdc-tool .gplkdc-table tbody td {
        padding-right: 8px;
        padding-left: 8px;
    }

    .gplkdc-table .gplkdc-col-index {
        width: 36px;
    }

    .gplkdc-table .gplkdc-col-density {
        min-width: 0;
    }

    .gplkdc-table .gplkdc-col-loc {
        width: 72px;
    }

    .gplkdc-bar {
        display: none;
    }

    .gplkdc-density-value {
        min-width: 0;
    }

    .gplkdc-tool .mt-table-scroll .gplkdc-table.is-url {
        min-width: 600px;
    }
}

@media (max-width: 430px) {
    .gplkdc-input-meta {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5em;
    }
}

@media (prefers-reduced-motion: reduce) {
    .gplkdc-tool .gplkdc-view::after {
        transition: none;
    }
}
