/* CSS Variables */
:root {
    --primary-color: #4f46e5;
    --primary-hover: #4338ca;
    --primary-light: #eef2ff;
    --secondary-color: #64748b;
    --secondary-hover: #475569;
    --success-color: #10b981;
    --warning-color: #f59e0b;
    --danger-color: #ef4444;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --text-muted: #94a3b8;
    --bg-primary: #ffffff;
    --bg-secondary: #f8fafc;
    --bg-tertiary: #f1f5f9;
    --border-color: #e2e8f0;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    --radius-sm: 6px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --transition: all 0.2s ease;
}

/* Reset & Base Styles */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
    scroll-behavior: smooth;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    color: var(--text-primary);
    line-height: 1.6;
}

/* App Container */
.app-container {
    max-width: 900px;
    margin: 0 auto;
    padding: 20px;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Header */
.header {
    text-align: center;
    padding: 30px 0;
    color: white;
}

.logo {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    margin-bottom: 8px;
}

.logo-img {
    width: 48px;
    height: 48px;
    border-radius: var(--radius-md);
}

.header h1 {
    font-size: 2rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.tagline {
    font-size: 1.1rem;
    opacity: 0.9;
    font-weight: 400;
}

/* Main Content */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 24px;
}

/* Input Section */
.input-section {
    background: var(--bg-primary);
    border-radius: var(--radius-lg);
    padding: 24px;
    box-shadow: var(--shadow-lg);
}

.input-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    flex-wrap: wrap;
    gap: 12px;
}

.input-header h2 {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-primary);
}

.word-count {
    font-size: 0.875rem;
    color: var(--text-secondary);
    background: var(--bg-tertiary);
    padding: 6px 12px;
    border-radius: var(--radius-sm);
}

#textInput {
    width: 100%;
    min-height: 200px;
    padding: 16px;
    border: 2px solid var(--border-color);
    border-radius: var(--radius-md);
    font-size: 1rem;
    font-family: inherit;
    resize: vertical;
    transition: var(--transition);
    line-height: 1.7;
}

#textInput:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px var(--primary-light);
}

#textInput::placeholder {
    color: var(--text-muted);
}

.input-actions {
    display: flex;
    gap: 12px;
    margin-top: 16px;
    flex-wrap: wrap;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 20px;
    font-size: 0.95rem;
    font-weight: 500;
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: var(--transition);
    font-family: inherit;
}

.btn-primary {
    background: var(--primary-color);
    color: white;
}

.btn-primary:hover {
    background: var(--primary-hover);
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.btn-secondary {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.btn-secondary:hover {
    background: var(--border-color);
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

/* Loading Section */
.loading-section {
    background: var(--bg-primary);
    border-radius: var(--radius-lg);
    padding: 48px 24px;
    text-align: center;
    box-shadow: var(--shadow-lg);
}

.loading-spinner {
    width: 48px;
    height: 48px;
    border: 4px solid var(--border-color);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 20px;
}

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

.loading-text {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 8px;
}

.loading-subtext {
    color: var(--text-secondary);
}

/* Results Section */
.results-section {
    display: flex;
    flex-direction: column;
    gap: 24px;
}

/* Results Summary */
.results-summary {
    background: var(--bg-primary);
    border-radius: var(--radius-lg);
    padding: 24px;
    box-shadow: var(--shadow-lg);
    display: flex;
    gap: 32px;
    align-items: center;
    flex-wrap: wrap;
}

.score-circle {
    position: relative;
    width: 140px;
    height: 140px;
    flex-shrink: 0;
}

.score-circle svg {
    transform: rotate(-90deg);
    width: 100%;
    height: 100%;
}

.score-bg {
    fill: none;
    stroke: var(--bg-tertiary);
    stroke-width: 8;
}

.score-progress {
    fill: none;
    stroke: var(--success-color);
    stroke-width: 8;
    stroke-linecap: round;
    stroke-dasharray: 283;
    stroke-dashoffset: 283;
    transition: stroke-dashoffset 1s ease-out, stroke 0.3s ease;
}

.score-text {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
}

.score-value {
    display: block;
    font-size: 2rem;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1;
}

.score-label {
    display: block;
    font-size: 0.75rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-top: 4px;
}

.summary-details {
    flex: 1;
    min-width: 200px;
}

.summary-details h3 {
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: 16px;
    color: var(--text-primary);
}

.summary-stats {
    display: flex;
    gap: 24px;
    flex-wrap: wrap;
    margin-bottom: 16px;
}

.stat {
    display: flex;
    flex-direction: column;
}

.stat-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1.2;
}

.stat-label {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.originality-badge {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    border-radius: var(--radius-md);
    font-weight: 500;
    font-size: 0.9rem;
}

.originality-badge.excellent {
    background: #d1fae5;
    color: #065f46;
}

.originality-badge.good {
    background: #fef3c7;
    color: #92400e;
}

.originality-badge.warning {
    background: #fee2e2;
    color: #991b1b;
}

/* Highlighted Text Section */
.highlighted-text-section {
    background: var(--bg-primary);
    border-radius: var(--radius-lg);
    padding: 24px;
    box-shadow: var(--shadow-lg);
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 16px;
    flex-wrap: wrap;
    gap: 12px;
}

.section-header h3 {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-primary);
}

.legend {
    display: flex;
    gap: 16px;
    flex-wrap: wrap;
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 6px;
}

.legend-color {
    width: 14px;
    height: 14px;
    border-radius: 3px;
}

.legend-color.high-match {
    background: #fca5a5;
}

.legend-color.medium-match {
    background: #fcd34d;
}

.legend-color.low-match {
    background: #bfdbfe;
}

.highlighted-content {
    padding: 20px;
    background: var(--bg-secondary);
    border-radius: var(--radius-md);
    line-height: 1.8;
    font-size: 1rem;
    max-height: 400px;
    overflow-y: auto;
}

.highlighted-content .match {
    padding: 2px 4px;
    border-radius: 3px;
    cursor: pointer;
    transition: var(--transition);
}

.highlighted-content .match:hover {
    opacity: 0.8;
}

.highlighted-content .match.high {
    background: #fca5a5;
    color: #7f1d1d;
}

.highlighted-content .match.medium {
    background: #fcd34d;
    color: #78350f;
}

.highlighted-content .match.low {
    background: #bfdbfe;
    color: #1e40af;
}

/* Sources Section */
.sources-section {
    background: var(--bg-primary);
    border-radius: var(--radius-lg);
    padding: 24px;
    box-shadow: var(--shadow-lg);
}

.sources-section h3 {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 16px;
}

.sources-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.source-item {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 16px;
    background: var(--bg-secondary);
    border-radius: var(--radius-md);
    border-left: 4px solid var(--primary-color);
    transition: var(--transition);
}

.source-item:hover {
    background: var(--bg-tertiary);
}

.source-match-badge {
    flex-shrink: 0;
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
    font-weight: 700;
    font-size: 0.9rem;
}

.source-match-badge.high {
    background: #fee2e2;
    color: #991b1b;
}

.source-match-badge.medium {
    background: #fef3c7;
    color: #92400e;
}

.source-match-badge.low {
    background: #dbeafe;
    color: #1e40af;
}

.source-info {
    flex: 1;
    min-width: 0;
}

.source-title {
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 4px;
    word-break: break-word;
}

.source-url {
    font-size: 0.85rem;
    color: var(--primary-color);
    text-decoration: none;
    word-break: break-all;
}

.source-url:hover {
    text-decoration: underline;
}

.source-excerpt {
    margin-top: 8px;
    font-size: 0.9rem;
    color: var(--text-secondary);
    font-style: italic;
}

.no-sources {
    text-align: center;
    padding: 32px;
    color: var(--text-secondary);
}

.no-sources svg {
    width: 48px;
    height: 48px;
    margin-bottom: 12px;
    opacity: 0.5;
}

/* Results Actions */
.results-actions {
    display: flex;
    gap: 12px;
    justify-content: center;
    flex-wrap: wrap;
}

/* Footer */
.footer {
    text-align: center;
    padding: 24px 0;
    margin-top: auto;
}

.footer p {
    color: rgba(255, 255, 255, 0.8);
    font-size: 0.9rem;
}

.footer a {
    color: white;
    text-decoration: none;
    font-weight: 500;
    transition: var(--transition);
}

.footer a:hover {
    text-decoration: underline;
    opacity: 0.9;
}

/* Utility Classes */
.hidden {
    display: none !important;
}

/* Responsive Design */
@media (max-width: 768px) {
    .app-container {
        padding: 16px;
    }

    .header {
        padding: 20px 0;
    }

    .header h1 {
        font-size: 1.5rem;
    }

    .tagline {
        font-size: 0.95rem;
    }

    .input-section,
    .results-summary,
    .highlighted-text-section,
    .sources-section {
        padding: 16px;
    }

    .input-header {
        flex-direction: column;
        align-items: flex-start;
    }

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

    .btn {
        width: 100%;
    }

    .results-summary {
        flex-direction: column;
        text-align: center;
    }

    .summary-stats {
        justify-content: center;
    }

    .section-header {
        flex-direction: column;
    }

    .legend {
        justify-content: flex-start;
    }

    .source-item {
        flex-direction: column;
    }

    .source-match-badge {
        width: auto;
        height: auto;
        padding: 6px 12px;
    }

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

@media (max-width: 480px) {
    .header h1 {
        font-size: 1.3rem;
    }

    .logo-img {
        width: 36px;
        height: 36px;
    }

    #textInput {
        min-height: 150px;
        padding: 12px;
    }

    .score-circle {
        width: 120px;
        height: 120px;
    }

    .score-value {
        font-size: 1.75rem;
    }

    .summary-stats {
        gap: 16px;
    }

    .stat-value {
        font-size: 1.25rem;
    }
}

/* Animation for results appearing */
@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.results-section > * {
    animation: fadeInUp 0.5s ease forwards;
}

.results-section > *:nth-child(1) { animation-delay: 0s; }
.results-section > *:nth-child(2) { animation-delay: 0.1s; }
.results-section > *:nth-child(3) { animation-delay: 0.2s; }
.results-section > *:nth-child(4) { animation-delay: 0.3s; }

/* Custom Scrollbar */
.highlighted-content::-webkit-scrollbar {
    width: 8px;
}

.highlighted-content::-webkit-scrollbar-track {
    background: var(--bg-tertiary);
    border-radius: 4px;
}

.highlighted-content::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 4px;
}

.highlighted-content::-webkit-scrollbar-thumb:hover {
    background: var(--secondary-color);
}

/* Print Styles */
@media print {
    body {
        background: white;
    }

    .app-container {
        max-width: 100%;
    }

    .header {
        color: var(--text-primary);
    }

    .input-section,
    .loading-section,
    .results-actions {
        display: none !important;
    }

    .results-section {
        display: block !important;
    }

    .results-summary,
    .highlighted-text-section,
    .sources-section {
        box-shadow: none;
        border: 1px solid var(--border-color);
        page-break-inside: avoid;
    }

    .footer {
        color: var(--text-secondary);
    }

    .footer a {
        color: var(--text-primary);
    }
}
