/* --- CSS Variables --- */
:root {
    --bg: #faf9f7;
    --bg-elevated: #ffffff;
    --card: #ffffff;
    --border: #e5e3df;
    --border-hover: #d4d1cb;
    --fg: #1a1817;
    --muted: #6b6560;
    --accent: #6366f1;
    --accent-light: #e0e7ff;
    --accent-glow: rgba(99, 102, 241, 0.15);
    --secondary: #14b8a6;
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --input-bg: #ffffff;
    --pattern-opacity: 0.3;
    --code-bg: #1e1e2e;
    --code-text: #34d399;
    --highlight-color: rgba(239, 68, 68, 0.25);
}

[data-theme="dark"] {
    --bg: #0a0a0f;
    --bg-elevated: #12121a;
    --card: #16161f;
    --border: #2a2a3a;
    --border-hover: #3a3a4a;
    --fg: #e8e8ed;
    --muted: #6b6b7a;
    --accent: #818cf8;
    --accent-light: rgba(129, 140, 248, 0.15);
    --accent-glow: rgba(129, 140, 248, 0.2);
    --secondary: #2dd4bf;
    --success: #34d399;
    --warning: #fbbf24;
    --danger: #f87171;
    --input-bg: #0f0f14;
    --pattern-opacity: 0.05;
    --code-bg: #0f0f14;
    --code-text: #34d399;
    --highlight-color: rgba(248, 113, 113, 0.2);
}

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

body {
    font-family: 'Space Grotesk', -apple-system, BlinkMacSystemFont, sans-serif;
    background-color: var(--bg);
    color: var(--fg);
    min-height: 100vh;
    overflow-x: hidden;
    transition: background-color 0.4s ease, color 0.4s ease;
    line-height: 1.5;
}

/* --- Background --- */
.bg-decoration { position: fixed; inset: 0; z-index: -1; overflow: hidden; pointer-events: none; }
.bg-pattern { position: absolute; inset: 0; background-image: radial-gradient(circle, var(--muted) 1px, transparent 1px); background-size: 24px 24px; opacity: var(--pattern-opacity); }
.gradient-orb { position: absolute; border-radius: 50%; filter: blur(80px); opacity: 0.4; animation: float 20s ease-in-out infinite; }
.orb-1 { width: 500px; height: 500px; background: linear-gradient(135deg, #a5b4fc, #818cf8); top: -150px; right: -100px; }
.orb-2 { width: 400px; height: 400px; background: linear-gradient(135deg, #5eead4, #2dd4bf); bottom: -100px; left: -100px; animation-delay: -5s; }
[data-theme="dark"] .orb-1 { background: var(--accent); opacity: 0.15; }
[data-theme="dark"] .orb-2 { background: var(--secondary); opacity: 0.15; }
@keyframes float { 0%, 100% { transform: translate(0, 0) scale(1); } 50% { transform: translate(30px, 20px) scale(1.05); } }

/* --- Layout --- */
.container { max-width: 1200px; margin: 0 auto; padding: 2rem 1rem; }
.main-grid { display: grid; grid-template-columns: 1fr; gap: 1.5rem; }
@media (min-width: 900px) { .main-grid { grid-template-columns: 1fr 1fr; } }

/* --- Header --- */
header { text-align: center; margin-bottom: 2rem; }
.header-top { display: flex; justify-content: center; margin-bottom: 1rem; }
.status-badge { display: inline-flex; align-items: center; gap: 8px; padding: 8px 16px; border-radius: 50px; border: 1px solid var(--border); background: var(--card); font-size: 14px; color: var(--muted); }
.pulse-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--success); animation: pulse 2s infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.5; } }
h1 { font-size: 2.5rem; font-weight: 700; letter-spacing: -1px; margin-bottom: 0.5rem; }
h1 span { color: var(--accent); }
.subtitle { color: var(--muted); font-size: 1.1rem; }

/* --- Theme Toggle --- */
.theme-toggle { position: fixed; top: 1.5rem; right: 1.5rem; z-index: 100; width: 48px; height: 48px; border-radius: 50%; background: var(--card); border: 2px solid var(--border); cursor: pointer; display: flex; align-items: center; justify-content: center; transition: all 0.3s ease; box-shadow: 0 4px 12px rgba(0,0,0,0.05); }
.theme-toggle:hover { transform: rotate(15deg) scale(1.1); border-color: var(--accent); background: var(--accent-light); }
.theme-toggle svg { width: 24px; height: 24px; stroke: var(--fg); fill: none; stroke-width: 2; }

/* --- Panel --- */
.panel { background: var(--card); border: 1px solid var(--border); border-radius: 20px; padding: 1.5rem; box-shadow: 0 4px 24px rgba(0,0,0,0.03); display: flex; flex-direction: column; gap: 1rem; }
.panel-header { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 0.5rem; }
.label { display: flex; align-items: center; gap: 10px; font-size: 0.85rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px; color: var(--muted); }
.label svg { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 2; }

.word-count-badge { 
    display: inline-flex; 
    align-items: center; 
    gap: 6px; 
    padding: 6px 12px; 
    border-radius: 20px; 
    background: var(--bg); 
    border: 1px solid var(--border); 
    font-size: 0.8rem; 
    color: var(--muted); 
    font-family: 'JetBrains Mono', monospace; 
}
.word-count-badge svg { width: 14px; height: 14px; stroke: currentColor; fill: none; stroke-width: 2; }

/* --- Input Groups --- */
.input-group { display: flex; flex-direction: column; gap: 0.5rem; }
.input-group.full-height { flex: 1; }
.input-group label { display: flex; align-items: center; gap: 8px; font-size: 0.9rem; font-weight: 600; color: var(--fg); }
.input-group label svg { width: 16px; height: 16px; stroke: currentColor; fill: none; stroke-width: 2; }
.input-group label small { color: var(--muted); font-weight: 400; font-size: 0.8rem; }

.text-area { 
    width: 100%; 
    flex: 1; 
    min-height: 200px; 
    background: var(--input-bg); 
    border: 2px solid var(--border); 
    border-radius: 12px; 
    padding: 1rem; 
    font-size: 14px; 
    line-height: 1.6; 
    color: var(--fg); 
    resize: vertical; 
    font-family: inherit; 
    transition: all 0.2s; 
}
.text-area:focus { outline: none; border-color: var(--accent); }
.text-area::placeholder { color: var(--muted); opacity: 0.6; }

.input-area-small { 
    width: 100%; 
    background: var(--input-bg); 
    border: 2px solid var(--border); 
    border-radius: 12px; 
    padding: 10px; 
    font-size: 13px; 
    color: var(--fg); 
    resize: none; 
    font-family: inherit; 
    transition: all 0.2s; 
}
.input-area-small:focus { outline: none; border-color: var(--accent); }
.input-area-small::placeholder { color: var(--muted); opacity: 0.6; }

/* --- Options Section --- */
.options-section { background: var(--bg); border-radius: 12px; padding: 1rem; }
.option-title { font-size: 0.8rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 0.75rem; }
.options-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 0.5rem; }
@media (max-width: 600px) { .options-grid { grid-template-columns: 1fr; } }

.option-item { display: flex; align-items: center; gap: 10px; cursor: pointer; padding: 8px 12px; border-radius: 8px; transition: background 0.2s; user-select: none; }
.option-item:hover { background: var(--accent-light); }
.option-item input { display: none; }
.checkmark { 
    width: 20px; 
    height: 20px; 
    border: 2px solid var(--border); 
    border-radius: 6px; 
    display: flex; 
    align-items: center; 
    justify-content: center; 
    transition: all 0.2s; 
    flex-shrink: 0; 
    position: relative; 
}
.option-item input:checked + .checkmark { border-color: var(--accent); background: var(--accent); }
.option-item input:checked + .checkmark::after { 
    content: ''; 
    position: absolute;
    width: 5px; 
    height: 9px; 
    border: solid white;
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
    top: 3px;
}
.option-label { font-size: 0.85rem; color: var(--fg); }

/* --- Score Section --- */
.score-section { display: flex; align-items: center; gap: 1.5rem; padding: 1rem; background: var(--bg); border-radius: 16px; margin-bottom: 0.5rem; }
@media (max-width: 500px) { .score-section { flex-direction: column; } }

.score-circle { position: relative; width: 100px; height: 100px; flex-shrink: 0; }
.score-circle svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.score-bg { fill: none; stroke: var(--border); stroke-width: 8; }
.score-progress { fill: none; stroke: var(--success); stroke-width: 8; stroke-linecap: round; stroke-dasharray: 283; stroke-dashoffset: 283; transition: stroke-dashoffset 0.8s ease, stroke 0.3s; }
.score-progress.warning { stroke: var(--warning); }
.score-progress.danger { stroke: var(--danger); }
.score-value { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.score-value span:first-child { font-size: 1.8rem; font-weight: 700; font-family: 'JetBrains Mono', monospace; }
.score-label { font-size: 0.7rem; color: var(--muted); }

.score-details { flex: 1; display: flex; flex-direction: column; gap: 0.5rem; width: 100%; }
.score-item { display: flex; justify-content: space-between; align-items: center; padding: 6px 10px; background: var(--card); border-radius: 8px; }
.score-item-label { font-size: 0.8rem; color: var(--muted); }
.score-item-value { font-size: 1rem; font-weight: 600; font-family: 'JetBrains Mono', monospace; }

/* --- Stats Row --- */
.stats-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 0.5rem; }
.stat-box { background: var(--bg); border-radius: 12px; padding: 12px; text-align: center; }
.stat-label { font-size: 0.75rem; color: var(--muted); text-transform: uppercase; }
.stat-value { font-size: 1.3rem; font-weight: 700; font-family: 'JetBrains Mono', monospace; margin-top: 4px; color: var(--fg); }
.stat-value.danger { color: var(--danger); }
.stat-value.secondary { color: var(--secondary); }

/* --- Results --- */
.results-header { font-size: 0.85rem; font-weight: 600; color: var(--muted); margin-top: 0.5rem; margin-bottom: 0.5rem; }
.results-list { flex: 1; overflow-y: auto; max-height: 150px; margin-bottom: 0.5rem; }

.empty-state { text-align: center; padding: 1.5rem; color: var(--muted); opacity: 0.7; }
.empty-state svg { width: 40px; height: 40px; stroke: currentColor; fill: none; stroke-width: 1.5; margin-bottom: 0.5rem; }

.source-item { 
    display: flex; 
    align-items: center; 
    justify-content: space-between; 
    padding: 10px 12px; 
    background: var(--bg); 
    border-radius: 10px; 
    margin-bottom: 6px; 
    border-left: 3px solid var(--danger); 
    transition: all 0.2s; 
    gap: 0.5rem;
}
.source-item:hover { background: var(--accent-light); }
.source-item.warning { border-left-color: var(--warning); }
.source-info { flex: 1; min-width: 0; }
.source-info h4 { font-size: 0.85rem; margin-bottom: 2px; }
.source-info p { font-size: 0.7rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.source-match { 
    font-size: 0.85rem; 
    font-weight: 600; 
    font-family: 'JetBrains Mono', monospace; 
    color: var(--danger); 
    padding: 4px 8px; 
    background: rgba(239, 68, 68, 0.1); 
    border-radius: 6px; 
    white-space: nowrap;
}
.source-match.warning { color: var(--warning); background: rgba(245, 158, 11, 0.1); }

/* --- Highlight Box --- */
.highlight-box { 
    background: var(--input-bg); 
    border: 1px solid var(--border); 
    border-radius: 12px; 
    padding: 1rem; 
    min-height: 100px; 
    max-height: 150px; 
    overflow-y: auto; 
    font-size: 13px; 
    line-height: 1.7; 
}
.highlight-box .plagiarized { 
    background: var(--highlight-color); 
    border-radius: 3px; 
    padding: 1px 3px; 
}
.placeholder-text { color: var(--muted); text-align: center; margin-top: 1.5rem; font-size: 0.85rem; }

/* --- Buttons --- */
.actions-row { display: flex; gap: 1rem; margin-top: 1.5rem; flex-wrap: wrap; }

.btn-action { 
    flex: 1; 
    min-width: 200px; 
    padding: 14px; 
    background: var(--accent); 
    color: white; 
    border: none; 
    border-radius: 12px; 
    font-weight: 600; 
    font-size: 1rem; 
    cursor: pointer; 
    display: flex; 
    align-items: center; 
    justify-content: center; 
    gap: 8px; 
    transition: all 0.2s; 
    font-family: inherit;
}
.btn-action svg { width: 20px; height: 20px; stroke: currentColor; fill: none; stroke-width: 2; }
.btn-action:hover:not(:disabled) { transform: translateY(-2px); box-shadow: 0 8px 20px var(--accent-glow); filter: brightness(1.05); }
.btn-action:disabled { opacity: 0.6; cursor: not-allowed; transform: none; }

.btn-secondary { 
    padding: 14px 24px; 
    background: var(--bg); 
    color: var(--fg); 
    border: 2px solid var(--border); 
    border-radius: 12px; 
    font-weight: 600; 
    cursor: pointer; 
    display: flex; 
    align-items: center; 
    justify-content: center; 
    gap: 8px; 
    transition: all 0.2s; 
    font-family: inherit;
}
.btn-secondary svg { width: 20px; height: 20px; stroke: currentColor; fill: none; stroke-width: 2; }
.btn-secondary:hover { border-color: var(--accent); color: var(--accent); }

.btn-report { 
    padding: 14px 24px; 
    background: var(--secondary); 
    color: white; 
    border: none; 
    border-radius: 12px; 
    font-weight: 600; 
    cursor: pointer; 
    display: flex; 
    align-items: center; 
    justify-content: center; 
    gap: 8px; 
    transition: all 0.2s; 
    font-family: inherit;
}
.btn-report svg { width: 20px; height: 20px; stroke: currentColor; fill: none; stroke-width: 2; }
.btn-report:hover { filter: brightness(1.1); }

/* --- Loading Overlay --- */
.loading-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.7); backdrop-filter: blur(8px); display: flex; align-items: center; justify-content: center; z-index: 1000; }
.loading-content { background: var(--card); border-radius: 20px; padding: 2rem 3rem; text-align: center; max-width: 400px; width: 90%; }
.loading-spinner { width: 60px; height: 60px; border: 4px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin 1s linear infinite; margin: 0 auto 1rem; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading-text { font-size: 1.2rem; font-weight: 600; margin-bottom: 1rem; }
.loading-progress { width: 100%; height: 6px; background: var(--border); border-radius: 3px; overflow: hidden; margin-bottom: 1rem; }
.loading-progress-bar { height: 100%; background: linear-gradient(90deg, var(--accent), var(--secondary)); width: 0%; transition: width 0.3s; }
.loading-step { font-size: 0.9rem; color: var(--muted); }

/* --- Toast --- */
.toast { position: fixed; bottom: 2rem; right: 2rem; background: var(--card); border: 1px solid var(--accent); padding: 1rem 1.5rem; border-radius: 12px; display: flex; align-items: center; gap: 10px; box-shadow: 0 10px 30px rgba(0,0,0,0.15); transform: translateY(100px); opacity: 0; transition: all 0.4s cubic-bezier(0.68, -0.55, 0.265, 1.55); z-index: 1001; }
.toast.show { transform: translateY(0); opacity: 1; }
.toast svg { width: 20px; height: 20px; stroke: var(--accent); fill: none; flex-shrink: 0; }

/* Utility */
.hidden { display: none !important; }
.fade-in { animation: fadeIn 0.6s ease forwards; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: translateY(0); } }

@media (max-width: 768px) {
    .stats-row { grid-template-columns: repeat(3, 1fr); }
    h1 { font-size: 2rem; }
    .actions-row { flex-direction: column; }
    .btn-action, .btn-secondary, .btn-report { width: 100%; min-width: auto; }
    .toast { left: 1rem; right: 1rem; bottom: 1rem; }
}
