/*
 * Keyword Difficulty Checker - tool-specific styles.
 *
 * Composes the shared primitives from code/assets/css/tools.css
 * (.tool-form-card, .input-form, .text-input, .primary-btn,
 * .results-region, .results-table, etc.). Only tool-specific overrides
 * and the difficulty-gauge bits live here.
 */

/* ----- form labels (every tool defines its own .field-label) ------ */

.field-label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--ink);
    margin: 14px 0 6px 0;
}
.field-label:first-child {
    margin-top: 0;
}

.form-hint {
    margin: 14px 0 0;
    padding: 10px 14px;
    border: 1px solid var(--ink-100);
    border-radius: var(--r-sm);
    background: var(--ink-50);
    color: var(--ink-700);
    font-size: 13px;
}
.form-hint a {
    color: var(--brand);
    font-weight: 600;
    text-decoration: none;
}
.form-hint a:hover {
    text-decoration: underline;
}

/* ----- form rows: stack label above input, full-width input ------ */

.kd-keyword-row,
.kd-location-row,
.kd-device-row,
.kd-submit-row {
    display: block;
}

.kd-keyword-row[hidden],
.kd-location-row[hidden],
.kd-device-row[hidden],
.kd-submit-row[hidden] {
    display: none;
}

/* Override the shared .text-input flex-basis (only valid inside an
 * .input-row flex parent) so single keyword + location inputs span
 * the full row width. */
.kd-keyword-row .text-input,
.kd-location-row .text-input {
    display: block;
    width: 100%;
    box-sizing: border-box;
}

.kd-submit-row {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
    margin-top: 18px;
}

.kd-submit-row .primary-btn {
    align-self: flex-start;
}

.kd-submit-row .form-hint {
    margin: 0;
}

/* ----- location autocomplete ------------------------------------- */

.kd-location-control {
    position: relative;
}

.kd-location-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    z-index: 30;
    background: #fff;
    border: 1px solid var(--ink-200, #e5e7eb);
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(15, 23, 42, 0.08);
    margin-top: 4px;
    max-height: 320px;
    overflow-y: auto;
}

.kd-location-dropdown[hidden] { display: none; }

.kd-location-option {
    display: flex;
    flex-direction: column;
    padding: 8px 12px;
    cursor: pointer;
    border-bottom: 1px solid var(--ink-100, #f3f4f6);
    transition: background 0.1s ease;
}

.kd-location-option:last-child { border-bottom: none; }

.kd-location-option:hover,
.kd-location-option.is-focused {
    background: var(--ink-50, #f9fafb);
}

.kd-location-option .kd-loc-name {
    color: var(--ink-900, #111827);
    font-weight: 500;
    font-size: 13px;
}

.kd-location-option .kd-loc-meta {
    color: var(--ink-500, #6b7280);
    font-size: 11px;
    margin-top: 2px;
}

.kd-location-option .kd-loc-type-pill {
    display: inline-block;
    background: var(--ink-100, #f3f4f6);
    color: var(--ink-700, #374151);
    border-radius: 4px;
    padding: 1px 6px;
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-right: 6px;
}

.kd-location-no-results {
    padding: 16px;
    text-align: center;
    color: var(--ink-500, #6b7280);
    font-size: 13px;
}

/* ----- device pill ----------------------------------------------- */

.kd-device-pill {
    display: inline-flex;
    background: var(--ink-100, #f3f4f6);
    border-radius: 999px;
    padding: 4px;
    gap: 4px;
}

.kd-device-btn {
    background: transparent;
    border: 0;
    border-radius: 999px;
    padding: 6px 14px;
    font-size: 13px;
    color: var(--ink-700, #374151);
    cursor: pointer;
    transition: background 0.1s ease, color 0.1s ease;
}

.kd-device-btn:hover {
    color: var(--ink-900, #111827);
}

.kd-device-btn.is-active {
    background: #fff;
    color: var(--brand-700, #1d4ed8);
    box-shadow: 0 1px 3px rgba(15, 23, 42, 0.08);
}

/* ----- focus-keyword stats card --------------------------------- */

.kd-keyword-stats-card {
    background: var(--brand-50, #eef2ff);
    border: 1px solid var(--brand-100, #e0e7ff);
    border-radius: 10px;
    padding: 14px 16px;
    margin-top: 16px;
}

.kd-keyword-stats-card[hidden] { display: none; }

.kd-keyword-stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 12px;
}

.kd-keyword-stats-cell {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.kd-keyword-stats-label {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--ink-500, #6b7280);
    font-weight: 600;
}

.kd-keyword-stats-value {
    font-size: 18px;
    font-weight: 600;
    color: var(--ink-900, #111827);
    font-variant-numeric: tabular-nums;
}

.kd-keyword-stats-value .muted { color: var(--ink-400, #9ca3af); font-weight: 400; }

.kd-keyword-stats-trend .kd-keyword-stats-value {
    min-height: 24px;
}

.kd-keyword-stats-trend svg {
    width: 100%;
    height: 24px;
    overflow: visible;
}

/* ----- difficulty gauge ----------------------------------------- */

.gauge-region {
    background: #fff;
    border: 1px solid var(--ink-200, #e5e7eb);
    border-radius: 12px;
    padding: 20px 22px;
    margin-top: 16px;
    /* The left accent strip is colored per difficulty band below. */
    border-left: 4px solid var(--ink-300, #d1d5db);
    box-shadow: 0 1px 3px rgba(15, 23, 42, 0.04);
    scroll-margin-top: 16px;
}

.gauge-region[hidden] { display: none; }

.gauge-head {
    display: flex;
    align-items: baseline;
    flex-wrap: wrap;
    gap: 6px 16px;
}

.gauge-score-wrap {
    display: flex;
    align-items: baseline;
    gap: 4px;
}

.gauge-score {
    font-size: 52px;
    line-height: 1;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    color: var(--ink-900, #111827);
}

.gauge-score.is-na {
    font-size: 30px;
    color: var(--ink-400, #9ca3af);
}

.gauge-score-max {
    font-size: 18px;
    font-weight: 600;
    color: var(--ink-400, #9ca3af);
}

.gauge-label-wrap {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.gauge-eyebrow {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    font-weight: 600;
    color: var(--ink-500, #6b7280);
}

.gauge-label {
    font-size: 20px;
    font-weight: 700;
    color: var(--ink-900, #111827);
}

/* ----- gauge bar (0-100, fill width = score, colored by band) --- */

.gauge-bar {
    margin-top: 16px;
}

.gauge-bar-track {
    position: relative;
    height: 12px;
    border-radius: 999px;
    /* The full green->red spectrum sits under the fill so the visible
     * fill (clipped to the score width) reads as "how far up the
     * difficulty range this keyword sits". */
    background: linear-gradient(90deg,
        #16a34a 0%,
        #4ade80 20%,
        #facc15 45%,
        #fb923c 70%,
        #ef4444 100%);
    opacity: 0.28;
    overflow: visible;
}

.gauge-bar-fill {
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
    border-radius: 999px;
    transition: width 0.45s ease;
    background: var(--ink-400, #9ca3af);
}

/* Band-colored fill so the solid portion matches the gauge accent. */
.gauge-bar-fill.band-very_easy { background: #16a34a; }
.gauge-bar-fill.band-easy      { background: #4ade80; }
.gauge-bar-fill.band-medium    { background: #eab308; }
.gauge-bar-fill.band-hard      { background: #f97316; }
.gauge-bar-fill.band-very_hard { background: #ef4444; }
.gauge-bar-fill.band-unknown   { background: var(--ink-300, #d1d5db); }

.gauge-bar-marker {
    position: absolute;
    top: 50%;
    width: 16px;
    height: 16px;
    margin-left: -8px;
    transform: translateY(-50%);
    background: #fff;
    border: 3px solid var(--ink-700, #374151);
    border-radius: 50%;
    box-shadow: 0 1px 3px rgba(15, 23, 42, 0.25);
}
.gauge-bar-marker[hidden] { display: none; }

.gauge-bar-scale {
    display: flex;
    justify-content: space-between;
    margin-top: 6px;
    font-size: 11px;
    color: var(--ink-400, #9ca3af);
    font-weight: 500;
}

/* The accent strip + label color track the difficulty band. */
.gauge-region.band-very_easy { border-left-color: #16a34a; }
.gauge-region.band-easy      { border-left-color: #4ade80; }
.gauge-region.band-medium    { border-left-color: #eab308; }
.gauge-region.band-hard      { border-left-color: #f97316; }
.gauge-region.band-very_hard { border-left-color: #ef4444; }
.gauge-region.band-unknown   { border-left-color: var(--ink-300, #d1d5db); }

.gauge-region.band-very_easy .gauge-label { color: #15803d; }
.gauge-region.band-easy      .gauge-label { color: #15803d; }
.gauge-region.band-medium    .gauge-label { color: #a16207; }
.gauge-region.band-hard      .gauge-label { color: #c2410c; }
.gauge-region.band-very_hard .gauge-label { color: #b91c1c; }
.gauge-region.band-unknown   .gauge-label { color: var(--ink-500, #6b7280); }

.gauge-interp {
    margin: 16px 0 0;
    color: var(--ink-800, #1f2937);
    font-size: 14px;
    line-height: 1.55;
}
.gauge-interp strong { color: var(--ink-900, #111827); }

.gauge-stats {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 14px;
    padding-top: 14px;
    border-top: 1px solid var(--ink-100, #f3f4f6);
}

.gauge-stat {
    display: inline-flex;
    flex-direction: column;
    gap: 2px;
    background: var(--ink-50, #f9fafb);
    border: 1px solid var(--ink-100, #f3f4f6);
    border-radius: 8px;
    padding: 8px 12px;
}

.gauge-stat-label {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--ink-500, #6b7280);
    font-weight: 600;
}

.gauge-stat-value {
    font-size: 14px;
    font-weight: 600;
    color: var(--ink-900, #111827);
    font-variant-numeric: tabular-nums;
}

/* ----- results subhead (Keyword / Location / Device chips) ------ */

.results-subhead {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 14px;
    padding: 10px 16px;
    background: var(--ink-50, #f9fafb);
    border-bottom: 1px solid var(--ink-100, #f3f4f6);
    color: var(--ink-700, #374151);
    font-size: 13px;
}

.results-subhead[hidden] { display: none; }

.kd-subhead-label {
    color: var(--ink-500, #6b7280);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 600;
    margin-right: 4px;
}

.kd-subhead-value {
    color: var(--ink-900, #111827);
    font-weight: 500;
}

.kd-subhead-sep {
    color: var(--ink-300, #d1d5db);
    margin: 0 4px;
    font-weight: 400;
}

/* ----- table cell variants -------------------------------------- */

/* The shared .results-table cell rule sets overflow:hidden +
 * text-overflow:ellipsis + white-space:nowrap on every cell. Combined
 * with `table-layout: fixed`, short content gets ellipsised whenever
 * the column shrinks. Override that for every short-content column so
 * "1" and "DA" render as themselves. URL is the only column that NEEDS
 * truncation (long content), and it wraps onto multiple lines. */
.results-table .rank-cell,
.results-table .da-cell,
.results-table .pr-cell,
.results-table .spam-cell,
.results-table .traffic-cell {
    overflow: visible;
    text-overflow: clip;
    white-space: nowrap;
}

.results-table .rank-cell {
    text-align: center;
    font-variant-numeric: tabular-nums;
    font-weight: 600;
    width: 64px;
    padding-left: 10px;
    padding-right: 10px;
}

.results-table .da-cell,
.results-table .pr-cell,
.results-table .spam-cell,
.results-table .traffic-cell {
    padding-left: 10px;
    padding-right: 10px;
}
.results-table .da-cell      { width: 64px; }
.results-table .pr-cell      { width: 60px; }
.results-table .spam-cell    { width: 76px; }
.results-table .traffic-cell { width: 108px; }
.results-table .domain-cell  { width: 200px; white-space: normal; word-break: break-word; }

/* URL wraps onto multiple lines so long URLs never get hidden. */
.results-table .url-cell {
    white-space: normal;
    overflow: hidden;
    text-overflow: clip;
    vertical-align: top;
    word-break: break-word;
    min-width: 260px;
}

.results-table .url-cell a {
    color: var(--brand-700, #1d4ed8);
    text-decoration: none;
    word-break: break-all;
}

.results-table .domain-cell {
    color: var(--ink-800, #1f2937);
    font-weight: 500;
}

.results-table .numeric-cell {
    text-align: right;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.results-table .badge-cell {
    text-align: center;
}

/* ----- rank badge ----------------------------------------------- */

.position-badge {
    display: inline-block;
    min-width: 28px;
    border-radius: 6px;
    padding: 2px 6px;
    font-size: 13px;
    text-align: center;
}

.position-badge.is-top3   { background: #dcfce7; color: #166534; }
.position-badge.is-top10  { background: #ecfdf5; color: #047857; }
.position-badge.is-deep   { background: #fee2e2; color: #b91c1c; }

/* ----- DA / Spam tiered badges ---------------------------------- */

.tier-badge {
    display: inline-block;
    min-width: 28px;
    border-radius: 6px;
    padding: 2px 6px;
    font-size: 12px;
    text-align: center;
    font-weight: 500;
}

/* DA badge: high DA = harder competitor = red; low DA = easier =
 * green (this inverts the usual good/bad mapping on purpose so the
 * table reads the same way as the difficulty gauge). */
.tier-badge.is-high   { background: #fee2e2; color: #b91c1c; }
.tier-badge.is-medium { background: #fef3c7; color: #92400e; }
.tier-badge.is-low    { background: #dcfce7; color: #166534; }
.tier-badge.is-muted  { background: transparent; color: var(--ink-400, #9ca3af); }

/* Spam badge: clean = green, medium = orange, spammy = red. */
.tier-badge.spam-tier.is-clean   { background: #dcfce7; color: #166534; }
.tier-badge.spam-tier.is-warnish { background: #fef3c7; color: #92400e; }
.tier-badge.spam-tier.is-spammy  { background: #fee2e2; color: #b91c1c; }

/* ----- responsive tweaks ---------------------------------------- */

@media (max-width: 720px) {
    .kd-keyword-stats-grid {
        grid-template-columns: 1fr 1fr;
    }
    .results-table .url-cell { min-width: 160px; }
    .results-table .domain-cell { width: 140px; }
    .results-subhead {
        gap: 8px;
        padding: 8px 12px;
    }
    .gauge-score { font-size: 44px; }
}

@media (max-width: 640px) {
    .gauge-region { padding: 16px; }
}
