/* ==========================================================================
   Keyword Density Checker — kdc-style.css
   Prefix: kdc-
   ========================================================================== */

/* --------------------------------------------------------------------------
   Reset / base
   -------------------------------------------------------------------------- */
.kdc-wrap *,
.kdc-wrap *::before,
.kdc-wrap *::after {
    box-sizing: border-box;
}

.kdc-wrap {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    font-size: 15px;
    line-height: 1.6;
    color: #2c3e50;
    max-width: 900px;
    margin: 0 auto;
    padding: 0 16px 40px;
    position: relative;
}

/* --------------------------------------------------------------------------
   Form section
   -------------------------------------------------------------------------- */
.kdc-form-section {
    background: #ffffff;
    border: 1px solid #dde3ea;
    border-radius: 10px;
    padding: 32px 36px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.kdc-title {
    font-size: 1.6rem;
    font-weight: 700;
    color: #1a1a2e;
    margin: 0 0 8px;
}

.kdc-subtitle {
    font-size: 0.95rem;
    color: #6b7280;
    margin: 0 0 28px;
}

/* --------------------------------------------------------------------------
   Fields
   -------------------------------------------------------------------------- */
.kdc-field {
    margin-bottom: 22px;
}

.kdc-field label {
    display: block;
    font-weight: 600;
    font-size: 0.9rem;
    color: #374151;
    margin-bottom: 7px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.kdc-required {
    color: #e53935;
}

.kdc-muted {
    color: #9ca3af;
    font-weight: 400;
    text-transform: none;
    letter-spacing: 0;
}

.kdc-field textarea {
    width: 100%;
    border: 1.5px solid #d1d5db;
    border-radius: 7px;
    padding: 12px 14px;
    font-size: 0.9rem;
    font-family: inherit;
    color: #1f2937;
    background: #fafafa;
    resize: vertical;
    transition: border-color 0.2s;
    min-height: 180px;
}

.kdc-field textarea:focus {
    outline: none;
    border-color: #2563eb;
    background: #fff;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

/* live word/char count below textarea */
.kdc-live-count {
    text-align: right;
    font-size: 0.8rem;
    color: #9ca3af;
    margin-top: 5px;
}

/* --------------------------------------------------------------------------
   Keyword grid
   -------------------------------------------------------------------------- */
.kdc-keywords-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

@media (max-width: 520px) {
    .kdc-keywords-grid {
        grid-template-columns: 1fr;
    }
}

.kdc-keyword {
    border: 1.5px solid #d1d5db;
    border-radius: 7px;
    padding: 10px 13px;
    font-size: 0.9rem;
    font-family: inherit;
    color: #1f2937;
    background: #fafafa;
    width: 100%;
    transition: border-color 0.2s;
}

.kdc-keyword:focus {
    outline: none;
    border-color: #2563eb;
    background: #fff;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

.kdc-keyword::placeholder {
    color: #c0c8d2;
}

/* colour swatches before each keyword input */
.kdc-keyword:nth-child(1) { border-left: 4px solid #f9a825; }
.kdc-keyword:nth-child(2) { border-left: 4px solid #43a047; }
.kdc-keyword:nth-child(3) { border-left: 4px solid #1e88e5; }
.kdc-keyword:nth-child(4) { border-left: 4px solid #fb8c00; }
.kdc-keyword:nth-child(5) { border-left: 4px solid #e91e8c; }

/* --------------------------------------------------------------------------
   Options row (checkboxes)
   -------------------------------------------------------------------------- */
.kdc-options-row {
    display: flex;
    flex-wrap: wrap;
    gap: 18px;
    margin-bottom: 22px;
}

.kdc-toggle {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.88rem;
    color: #4b5563;
    cursor: pointer;
    user-select: none;
}

.kdc-toggle input[type="checkbox"] {
    width: 16px;
    height: 16px;
    accent-color: #2563eb;
    cursor: pointer;
    flex-shrink: 0;
}

/* --------------------------------------------------------------------------
   Buttons
   -------------------------------------------------------------------------- */
.kdc-btn-row {
    display: flex;
    justify-content: flex-start;
    margin-bottom: 8px;
}

.kdc-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    padding: 11px 26px;
    font-size: 0.95rem;
    font-weight: 600;
    font-family: inherit;
    border-radius: 7px;
    border: 2px solid transparent;
    cursor: pointer;
    transition: background 0.2s, color 0.2s, border-color 0.2s, transform 0.1s;
    text-decoration: none;
}

.kdc-btn:active {
    transform: translateY(1px);
}

.kdc-btn-primary {
    background: #2563eb;
    color: #ffffff;
    border-color: #2563eb;
}

.kdc-btn-primary:hover {
    background: #1d4ed8;
    border-color: #1d4ed8;
}

.kdc-btn-secondary {
    background: #f3f4f6;
    color: #374151;
    border-color: #d1d5db;
}

.kdc-btn-secondary:hover {
    background: #e5e7eb;
    border-color: #9ca3af;
}

.kdc-btn-outline {
    background: transparent;
    color: #2563eb;
    border-color: #2563eb;
}

.kdc-btn-outline:hover {
    background: #eff6ff;
}

/* --------------------------------------------------------------------------
   Error message
   -------------------------------------------------------------------------- */
.kdc-error {
    background: #fef2f2;
    border: 1px solid #fca5a5;
    border-radius: 7px;
    color: #991b1b;
    padding: 10px 14px;
    font-size: 0.88rem;
    margin-top: 12px;
}

/* --------------------------------------------------------------------------
   Results wrapper
   -------------------------------------------------------------------------- */
.kdc-results {
    margin-top: 30px;
}

.kdc-section {
    background: #ffffff;
    border: 1px solid #dde3ea;
    border-radius: 10px;
    padding: 24px 28px;
    margin-bottom: 20px;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.04);
}

.kdc-section-title {
    font-size: 1.05rem;
    font-weight: 700;
    color: #1a1a2e;
    margin: 0 0 18px;
    padding-bottom: 10px;
    border-bottom: 2px solid #f0f2f5;
}

/* --------------------------------------------------------------------------
   Content overview stats
   -------------------------------------------------------------------------- */
.kdc-stats-row {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 14px;
}

@media (max-width: 600px) {
    .kdc-stats-row {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 380px) {
    .kdc-stats-row {
        grid-template-columns: 1fr;
    }
}

.kdc-stat-box {
    background: #f8faff;
    border: 1px solid #e0e7ff;
    border-radius: 8px;
    padding: 16px 14px;
    text-align: center;
}

.kdc-stat-value {
    display: block;
    font-size: 1.6rem;
    font-weight: 700;
    color: #2563eb;
    line-height: 1.2;
    margin-bottom: 4px;
}

.kdc-stat-label {
    display: block;
    font-size: 0.75rem;
    color: #6b7280;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* --------------------------------------------------------------------------
   Density legend bar
   -------------------------------------------------------------------------- */
.kdc-density-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 18px;
}

.kdc-legend-item {
    font-size: 0.78rem;
    font-weight: 600;
    padding: 4px 10px;
    border-radius: 20px;
    color: #fff;
    white-space: nowrap;
}

.kdc-legend-missing { background: #9e9e9e; }
.kdc-legend-low     { background: #f57c00; }
.kdc-legend-warning { background: #f9a825; color: #1a1a1a; }
.kdc-legend-good    { background: #43a047; }
.kdc-legend-danger  { background: #e53935; }

/* --------------------------------------------------------------------------
   Keyword cards
   -------------------------------------------------------------------------- */
.kdc-keyword-card {
    border: 1.5px solid #e5e7eb;
    border-radius: 9px;
    margin-bottom: 16px;
    overflow: hidden;
}

.kdc-keyword-card:last-child {
    margin-bottom: 0;
}

/* card accent stripe — coloured left border per keyword index */
.kdc-keyword-card[data-idx="0"] { border-left: 5px solid #f9a825; }
.kdc-keyword-card[data-idx="1"] { border-left: 5px solid #43a047; }
.kdc-keyword-card[data-idx="2"] { border-left: 5px solid #1e88e5; }
.kdc-keyword-card[data-idx="3"] { border-left: 5px solid #fb8c00; }
.kdc-keyword-card[data-idx="4"] { border-left: 5px solid #e91e8c; }

.kdc-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 10px;
    padding: 14px 18px;
    background: #fafbfc;
    border-bottom: 1px solid #f0f2f5;
}

.kdc-card-keyword {
    font-weight: 700;
    font-size: 1rem;
    color: #1f2937;
}

.kdc-card-status {
    font-size: 0.78rem;
    font-weight: 700;
    padding: 4px 12px;
    border-radius: 20px;
    color: #fff;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.kdc-status-missing { background: #9e9e9e; }
.kdc-status-low     { background: #f57c00; }
.kdc-status-warning { background: #f9a825; color: #1a1a1a; }
.kdc-status-good    { background: #43a047; }
.kdc-status-danger  { background: #e53935; }

.kdc-card-body {
    padding: 16px 18px;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

@media (max-width: 540px) {
    .kdc-card-body {
        grid-template-columns: 1fr;
    }
}

.kdc-card-info {
    font-size: 0.85rem;
    color: #4b5563;
    line-height: 1.8;
}

.kdc-card-info strong {
    color: #111827;
}

/* distribution across thirds */
.kdc-dist-label {
    font-size: 0.8rem;
    font-weight: 600;
    color: #6b7280;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: 8px;
}

.kdc-dist-thirds {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
}

.kdc-dist-third {
    background: #f3f4f6;
    border-radius: 6px;
    padding: 8px 6px;
    text-align: center;
}

.kdc-dist-third-label {
    display: block;
    font-size: 0.7rem;
    color: #9ca3af;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: 3px;
}

.kdc-dist-third-val {
    display: block;
    font-size: 1.05rem;
    font-weight: 700;
    color: #1f2937;
}

.kdc-card-recommendation {
    grid-column: 1 / -1;
    font-size: 0.85rem;
    color: #374151;
    background: #f0f9ff;
    border-left: 3px solid #38bdf8;
    border-radius: 0 6px 6px 0;
    padding: 10px 13px;
    line-height: 1.55;
}

/* --------------------------------------------------------------------------
   Highlighted text preview
   -------------------------------------------------------------------------- */
.kdc-highlight-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 14px;
}

.kdc-highlight-legend-item {
    display: flex;
    align-items: center;
    gap: 7px;
    font-size: 0.82rem;
    color: #374151;
}

.kdc-highlight-swatch {
    display: inline-block;
    width: 16px;
    height: 16px;
    border-radius: 3px;
    border: 1px solid rgba(0,0,0,0.1);
    flex-shrink: 0;
}

.kdc-highlighted-text {
    background: #fafafa;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    padding: 18px 20px;
    font-size: 0.9rem;
    line-height: 1.85;
    color: #1f2937;
    white-space: pre-wrap;
    word-break: break-word;
    max-height: 400px;
    overflow-y: auto;
}

.kdc-highlighted-text mark {
    border-radius: 3px;
    padding: 0 2px;
    font-style: normal;
    font-weight: inherit;
    color: inherit;
}

/* --------------------------------------------------------------------------
   Top words bar chart
   -------------------------------------------------------------------------- */
.kdc-note {
    font-size: 0.82rem;
    color: #9ca3af;
    margin: -10px 0 16px;
}

.kdc-top-words {
    display: flex;
    flex-direction: column;
    gap: 7px;
}

.kdc-word-row {
    display: grid;
    grid-template-columns: 110px 1fr 46px;
    align-items: center;
    gap: 10px;
}

.kdc-word-label {
    font-size: 0.85rem;
    font-weight: 600;
    color: #374151;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.kdc-word-bar-track {
    background: #f3f4f6;
    border-radius: 4px;
    height: 10px;
    overflow: hidden;
}

.kdc-word-bar {
    height: 100%;
    background: linear-gradient(90deg, #3b82f6, #2563eb);
    border-radius: 4px;
    transition: width 0.4s ease;
    min-width: 2px;
}

.kdc-word-count {
    font-size: 0.8rem;
    color: #6b7280;
    text-align: right;
    white-space: nowrap;
}

/* --------------------------------------------------------------------------
   Action buttons row
   -------------------------------------------------------------------------- */
.kdc-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    margin-top: 10px;
}

/* --------------------------------------------------------------------------
   Loading overlay
   -------------------------------------------------------------------------- */
.kdc-loading {
    position: absolute;
    inset: 0;
    background: rgba(255, 255, 255, 0.88);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 14px;
    border-radius: 10px;
    z-index: 10;
    backdrop-filter: blur(2px);
}

.kdc-loading p {
    font-size: 0.95rem;
    color: #4b5563;
    font-weight: 500;
    margin: 0;
}

.kdc-spinner {
    width: 42px;
    height: 42px;
    border: 4px solid #e5e7eb;
    border-top-color: #2563eb;
    border-radius: 50%;
    animation: kdc-spin 0.75s linear infinite;
}

@keyframes kdc-spin {
    to { transform: rotate(360deg); }
}

/* --------------------------------------------------------------------------
   Responsive tweaks
   -------------------------------------------------------------------------- */
@media (max-width: 640px) {
    .kdc-form-section {
        padding: 22px 18px;
    }

    .kdc-section {
        padding: 18px 16px;
    }

    .kdc-title {
        font-size: 1.3rem;
    }

    .kdc-btn {
        width: 100%;
    }

    .kdc-actions {
        flex-direction: column;
    }

    .kdc-word-row {
        grid-template-columns: 90px 1fr 40px;
    }
}
