:root {
    --bg-primary: #0f172a;
    --bg-secondary: #1e293b;
    --bg-tertiary: #334155;
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --accent-primary: #3b82f6;
    --accent-hover: #2563eb;
    --success: #10b981;
    --border-color: #334155;
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Inter', -apple-system, sans-serif;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.5;
    min-height: 100vh;
}

.app-container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 2rem;
}

header {
    text-align: center;
    margin-bottom: 3rem;
}

header h1 {
    font-size: 2.5rem;
    font-weight: 700;
    background: linear-gradient(to right, #60a5fa, #a78bfa);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    margin-bottom: 0.5rem;
}

header p {
    color: var(--text-secondary);
    font-size: 1.1rem;
}

.main-content {
    display: grid;
    grid-template-columns: 1fr 400px;
    gap: 2rem;
}

@media (max-width: 1024px) {
    .main-content {
        grid-template-columns: 1fr;
    }
}

.editor-section {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.keywords-container {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
}

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

.input-group {
    background: var(--bg-secondary);
    padding: 1.5rem;
    border-radius: 12px;
    box-shadow: var(--shadow-md);
    border: 1px solid var(--border-color);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    display: flex;
    flex-direction: column;
}

/* Quill container does not trigger focus-within easily, but this is fine */
.input-group:focus-within {
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2);
}

.input-group label {
    display: block;
    font-size: 0.875rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
    margin-bottom: 1rem;
}

.input-group.editor-group {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
}

/* Quill Editor Styles */
.editor-wrapper {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    margin-top: 0.5rem;
}

.ql-toolbar.ql-snow {
    border: 1px solid var(--border-color);
    background: var(--bg-secondary);
    border-top-left-radius: 8px;
    border-top-right-radius: 8px;
    padding: 12px;
    font-family: 'Inter', sans-serif;
}

.ql-container.ql-snow {
    border: 1px solid var(--border-color);
    border-bottom-left-radius: 8px;
    border-bottom-right-radius: 8px;
    border-top: none;
    flex-grow: 1;
    font-family: 'Inter', sans-serif;
    font-size: 1rem;
    color: var(--text-primary);
    background: var(--bg-primary);
}

.ql-editor {
    min-height: 400px;
    padding: 1.5rem;
    line-height: 1.6;
}

/* Override Quill Light Mode defaults to match Dark Mode */
.ql-snow .ql-stroke {
    stroke: var(--text-secondary);
}

.ql-snow .ql-fill,
.ql-snow .ql-stroke.ql-fill {
    fill: var(--text-secondary);
}

.ql-snow .ql-picker {
    color: var(--text-secondary);
}

.ql-snow .ql-picker-options {
    background-color: var(--bg-secondary);
    border-color: var(--border-color);
}

.ql-snow.ql-toolbar button:hover .ql-stroke,
.ql-snow .ql-toolbar button:focus .ql-stroke,
.ql-snow .ql-toolbar button.ql-active .ql-stroke {
    stroke: var(--accent-primary);
}

.ql-snow.ql-toolbar button:hover .ql-fill,
.ql-snow .ql-toolbar button:focus .ql-fill,
.ql-snow .ql-toolbar button.ql-active .ql-fill {
    fill: var(--accent-primary);
}

.ql-snow .ql-picker.ql-expanded .ql-picker-label .ql-stroke {
    stroke: var(--accent-primary);
}

.ql-editor.ql-blank::before {
    color: var(--text-secondary);
    font-style: normal;
}

mark.highlight-invisible {
    background-color: #ef4444 !important;
    color: #fff !important;
    border-radius: 2px;
    padding: 0 0.1em;
    min-width: 6px;
    display: inline-block;
}

/* In-text Highlight Colors within Quill */
mark.highlight-main {
    background-color: rgba(96, 165, 250, 0.4);
    color: inherit;
    border-radius: 4px;
    padding: 0.1em 0;
}

mark.highlight-extra {
    background-color: rgba(167, 139, 250, 0.4);
    color: inherit;
    border-radius: 4px;
    padding: 0.1em 0;
}

/* Original input area components for Keywords */
textarea#main-keywords,
textarea#extra-keywords {
    width: 100%;
    flex-grow: 1;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-primary);
    padding: 1rem;
    font-family: 'Inter', sans-serif;
    font-size: 1rem;
    resize: vertical;
    transition: border-color 0.2s ease;
    min-height: 150px;
}

textarea#main-keywords:focus,
textarea#extra-keywords:focus {
    outline: none;
    border-color: var(--accent-primary);
}

label.main-label,
label.extra-label {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.badge {
    font-size: 0.65rem;
    padding: 0.2rem 0.6rem;
    border-radius: 999px;
    background: var(--bg-tertiary);
    color: var(--text-primary);
    font-weight: 700;
    letter-spacing: 0;
}

.main-label .badge {
    background: rgba(59, 130, 246, 0.2);
    color: #60a5fa;
    border: 1px solid rgba(59, 130, 246, 0.3);
}

.extra-label .badge {
    background: rgba(167, 139, 250, 0.2);
    color: #c084fc;
    border: 1px solid rgba(167, 139, 250, 0.3);
}

::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--bg-tertiary);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}

/* Results Section Details */
.results-section {
    background: var(--bg-secondary);
    border-radius: 12px;
    padding: 1.5rem;
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-lg);
    display: flex;
    flex-direction: column;
    max-height: calc(100vh - 4rem);
    position: sticky;
    top: 2rem;
}

.results-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border-color);
}

.results-header h2 {
    font-size: 1.25rem;
    font-weight: 600;
}

.stats {
    display: flex;
    gap: 1rem;
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.stats span {
    background: var(--bg-tertiary);
    padding: 0.25rem 0.75rem;
    border-radius: 999px;
}

.results-scroll-area {
    flex-grow: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 2rem;
    padding-right: 0.5rem;
}

.results-group {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.group-title {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 0.5rem;
    margin-bottom: 0.25rem;
}

.group-stats {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    padding: 0.15rem 0.5rem;
    border-radius: 999px;
    font-size: 0.75rem;
}

.results-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.empty-state {
    color: var(--text-secondary);
    text-align: center;
    padding: 2rem 1rem;
    font-style: italic;
    font-size: 0.9rem;
    background: rgba(15, 23, 42, 0.4);
    border-radius: 8px;
    border: 1px dashed var(--border-color);
}

.keyword-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.875rem 1rem;
    background: var(--bg-primary);
    border-radius: 8px;
    border: 1px solid var(--border-color);
    transition: all 0.2s ease;
}

.keyword-item:hover {
    border-color: var(--accent-primary);
    transform: translateY(-2px);
    box-shadow: var(--shadow-sm);
}

.keyword-text {
    font-weight: 500;
    word-break: break-all;
    padding-right: 1rem;
    font-size: 0.95rem;
}

.keyword-count {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    padding: 0.25rem 0.75rem;
    border-radius: 6px;
    font-weight: 600;
    font-size: 0.875rem;
    min-width: 3rem;
    text-align: center;
}

.keyword-count.has-matches {
    background: rgba(16, 185, 129, 0.2);
    color: var(--success);
    border: 1px solid rgba(16, 185, 129, 0.3);
}

/* Animations */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(5px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.keyword-item {
    animation: fadeIn 0.3s ease forwards;
}

/* 
 * CRITICAL FIX:
 * When users paste text from Word/Websites, Quill often preserves inline styles like "color: black; background: white;".
 * In a dark theme, this looks terrible. We force all text inside the editor to be readable, 
 * while preserving our custom highlights and code blocks. 
 */
.ql-editor,
.ql-editor * {
    color: var(--text-primary) !important;
}

.ql-editor *:not(mark):not(pre):not(code) {
    background-color: transparent !important;
}

/* Quality section */
.quality-section {
    margin-top: 2rem;
    background: var(--bg-secondary);
    border-radius: 12px;
    padding: 1.5rem;
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-lg);
}

.quality-section h2 {
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: 1.5rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border-color);
}

.checklist-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 1rem;
}

.rule-item {
    display: flex;
    align-items: center;
    gap: 1rem;
    background: var(--bg-primary);
    padding: 1rem;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.rule-item:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}

.traffic-light {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    flex-shrink: 0;
    box-shadow: 0 0 4px rgba(0, 0, 0, 0.5) inset;
}

.indicator-green {
    background-color: #10b981;
    box-shadow: 0 0 8px #10b981;
}

.indicator-yellow {
    background-color: #f59e0b;
    box-shadow: 0 0 8px #f59e0b;
}

.indicator-red {
    background-color: #ef4444;
    box-shadow: 0 0 8px #ef4444;
}

.rule-text {
    font-size: 0.9rem;
    color: var(--text-primary);
    font-weight: 500;
}

.rule-value {
    margin-top: 0.25rem;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
}

/* Frequency section */
.frequency-section {
    margin-top: 2rem;
    background: var(--bg-secondary);
    border-radius: 12px;
    padding: 1.5rem;
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-lg);
}

.frequency-section h2 {
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: 1.5rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border-color);
}

.freq-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 0.75rem;
}

.freq-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--bg-primary);
    padding: 0.75rem 1rem;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.freq-item:hover {
    border-color: var(--accent-primary);
    box-shadow: var(--shadow-sm);
    transform: translateY(-2px);
}

.freq-word {
    font-weight: 500;
    font-size: 0.95rem;
    color: var(--text-primary);
    word-break: break-all;
    padding-right: 0.5rem;
}

.freq-stats {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.freq-count {
    background: rgba(59, 130, 246, 0.2);
    color: #60a5fa;
    padding: 0.2rem 0.5rem;
    border-radius: 4px;
    font-weight: 600;
    font-size: 0.8rem;
}

.freq-pct {
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    padding: 0.2rem 0.5rem;
    border-radius: 4px;
    font-weight: 600;
    font-size: 0.8rem;
}

.freq-item.danger-word {
    border-color: rgba(239, 68, 68, 0.4);
    background: rgba(239, 68, 68, 0.05);
}

.freq-item.danger-word .freq-pct {
    background: rgba(239, 68, 68, 0.2);
    color: #ef4444;
}

.freq-item.danger-word .freq-word {
    color: #ef4444;
}